[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" |
Istiaque Ahmed | 96f50609 | 2019-07-08 23:40:57 | [diff] [blame] | 8 | #include "extensions/renderer/extension_interaction_provider.h" |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 9 | #include "extensions/renderer/script_context.h" |
Mustaq Ahmed | 4baa9a6e8 | 2019-12-20 23:43:46 | [diff] [blame] | 10 | #include "third_party/blink/public/web/web_local_frame.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", |
Devlin Cronin | cc02a0c | 2019-01-03 22:15:07 | [diff] [blame] | 20 | base::BindRepeating(&UserGesturesNativeHandler::IsProcessingUserGesture, |
| 21 | base::Unretained(this))); |
Devlin Cronin | d9ea834 | 2018-01-27 06:00:04 | [diff] [blame] | 22 | RouteHandlerFunction( |
| 23 | "RunWithUserGesture", "test", |
Mustaq Ahmed | fb1ddbbd | 2020-02-27 18:32:50 | [diff] [blame^] | 24 | base::BindRepeating( |
| 25 | &UserGesturesNativeHandler::RunWithUserActivationForTest, |
| 26 | base::Unretained(this))); |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | void UserGesturesNativeHandler::IsProcessingUserGesture( |
| 30 | const v8::FunctionCallbackInfo<v8::Value>& args) { |
Istiaque Ahmed | 96f50609 | 2019-07-08 23:40:57 | [diff] [blame] | 31 | args.GetReturnValue().Set(v8::Boolean::New( |
| 32 | args.GetIsolate(), |
| 33 | ExtensionInteractionProvider::HasActiveExtensionInteraction( |
| 34 | context()->v8_context()))); |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 35 | } |
| 36 | |
Mustaq Ahmed | fb1ddbbd | 2020-02-27 18:32:50 | [diff] [blame^] | 37 | void UserGesturesNativeHandler::RunWithUserActivationForTest( |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 38 | const v8::FunctionCallbackInfo<v8::Value>& args) { |
Istiaque Ahmed | 91d6987c | 2019-06-25 00:09:33 | [diff] [blame] | 39 | // TODO(lazyboy): This won't work for Service Workers. Address this once we're |
| 40 | // certain that we need this for workers. |
Mustaq Ahmed | 4baa9a6e8 | 2019-12-20 23:43:46 | [diff] [blame] | 41 | if (context()->web_frame()) |
| 42 | context()->web_frame()->NotifyUserActivation(); |
[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 | |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 49 | } // namespace extensions |