[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "extensions/renderer/user_gestures_native_handler.h" |
| 6 | |
| 7 | #include "base/bind.h" |
| 8 | #include "extensions/renderer/script_context.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame^] | 9 | #include "third_party/blink/public/web/web_scoped_user_gesture.h" |
| 10 | #include "third_party/blink/public/web/web_user_gesture_indicator.h" |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 11 | |
| 12 | namespace extensions { |
| 13 | |
| 14 | UserGesturesNativeHandler::UserGesturesNativeHandler(ScriptContext* context) |
Devlin Cronin | d9ea834 | 2018-01-27 06:00:04 | [diff] [blame] | 15 | : ObjectBackedNativeHandler(context) {} |
| 16 | |
| 17 | void UserGesturesNativeHandler::AddRoutes() { |
| 18 | RouteHandlerFunction( |
| 19 | "IsProcessingUserGesture", "test", |
| 20 | base::Bind(&UserGesturesNativeHandler::IsProcessingUserGesture, |
| 21 | base::Unretained(this))); |
| 22 | RouteHandlerFunction( |
| 23 | "RunWithUserGesture", "test", |
| 24 | base::Bind(&UserGesturesNativeHandler::RunWithUserGesture, |
| 25 | base::Unretained(this))); |
| 26 | RouteHandlerFunction( |
| 27 | "RunWithoutUserGesture", "test", |
| 28 | base::Bind(&UserGesturesNativeHandler::RunWithoutUserGesture, |
| 29 | base::Unretained(this))); |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | void UserGesturesNativeHandler::IsProcessingUserGesture( |
| 33 | const v8::FunctionCallbackInfo<v8::Value>& args) { |
Mustaq Ahmed | e473e435 | 2017-11-04 01:04:25 | [diff] [blame] | 34 | args.GetReturnValue().Set( |
| 35 | v8::Boolean::New(args.GetIsolate(), |
| 36 | blink::WebUserGestureIndicator::IsProcessingUserGesture( |
| 37 | context()->web_frame()))); |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void UserGesturesNativeHandler::RunWithUserGesture( |
| 41 | const v8::FunctionCallbackInfo<v8::Value>& args) { |
japhet | 26ce312 | 2016-10-25 21:30:06 | [diff] [blame] | 42 | blink::WebScopedUserGesture user_gesture(context()->web_frame()); |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 43 | CHECK_EQ(args.Length(), 1); |
| 44 | CHECK(args[0]->IsFunction()); |
rdevlin.cronin | 57d21168 | 2016-11-04 06:00:16 | [diff] [blame] | 45 | context()->SafeCallFunction(v8::Local<v8::Function>::Cast(args[0]), 0, |
| 46 | nullptr); |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | void UserGesturesNativeHandler::RunWithoutUserGesture( |
| 50 | const v8::FunctionCallbackInfo<v8::Value>& args) { |
Mustaq Ahmed | e473e435 | 2017-11-04 01:04:25 | [diff] [blame] | 51 | blink::WebUserGestureIndicator::ConsumeUserGesture(context()->web_frame()); |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 52 | CHECK_EQ(args.Length(), 1); |
| 53 | CHECK(args[0]->IsFunction()); |
tfarina | f85316f | 2015-04-29 17:03:40 | [diff] [blame] | 54 | v8::Local<v8::Value> no_args; |
rdevlin.cronin | 57d21168 | 2016-11-04 06:00:16 | [diff] [blame] | 55 | context()->SafeCallFunction(v8::Local<v8::Function>::Cast(args[0]), 0, |
| 56 | nullptr); |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | } // namespace extensions |