[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 | ecb5c38e | 2020-07-29 00:34:30 | [diff] [blame] | 10 | #include "third_party/blink/public/mojom/frame/user_activation_notification_type.mojom.h" |
Mustaq Ahmed | 4baa9a6e8 | 2019-12-20 23:43:46 | [diff] [blame] | 11 | #include "third_party/blink/public/web/web_local_frame.h" |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 12 | |
| 13 | namespace extensions { |
| 14 | |
| 15 | UserGesturesNativeHandler::UserGesturesNativeHandler(ScriptContext* context) |
Devlin Cronin | d9ea834 | 2018-01-27 06:00:04 | [diff] [blame] | 16 | : ObjectBackedNativeHandler(context) {} |
| 17 | |
| 18 | void UserGesturesNativeHandler::AddRoutes() { |
| 19 | RouteHandlerFunction( |
| 20 | "IsProcessingUserGesture", "test", |
Devlin Cronin | cc02a0c | 2019-01-03 22:15:07 | [diff] [blame] | 21 | base::BindRepeating(&UserGesturesNativeHandler::IsProcessingUserGesture, |
| 22 | base::Unretained(this))); |
Devlin Cronin | d9ea834 | 2018-01-27 06:00:04 | [diff] [blame] | 23 | RouteHandlerFunction( |
| 24 | "RunWithUserGesture", "test", |
Mustaq Ahmed | fb1ddbbd | 2020-02-27 18:32:50 | [diff] [blame] | 25 | base::BindRepeating( |
| 26 | &UserGesturesNativeHandler::RunWithUserActivationForTest, |
| 27 | base::Unretained(this))); |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | void UserGesturesNativeHandler::IsProcessingUserGesture( |
| 31 | const v8::FunctionCallbackInfo<v8::Value>& args) { |
Istiaque Ahmed | 96f50609 | 2019-07-08 23:40:57 | [diff] [blame] | 32 | args.GetReturnValue().Set(v8::Boolean::New( |
| 33 | args.GetIsolate(), |
| 34 | ExtensionInteractionProvider::HasActiveExtensionInteraction( |
| 35 | context()->v8_context()))); |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 36 | } |
| 37 | |
Mustaq Ahmed | fb1ddbbd | 2020-02-27 18:32:50 | [diff] [blame] | 38 | void UserGesturesNativeHandler::RunWithUserActivationForTest( |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 39 | const v8::FunctionCallbackInfo<v8::Value>& args) { |
Istiaque Ahmed | 91d6987c | 2019-06-25 00:09:33 | [diff] [blame] | 40 | // TODO(lazyboy): This won't work for Service Workers. Address this once we're |
| 41 | // certain that we need this for workers. |
Mustaq Ahmed | ecb5c38e | 2020-07-29 00:34:30 | [diff] [blame] | 42 | if (context()->web_frame()) { |
| 43 | context()->web_frame()->NotifyUserActivation( |
| 44 | blink::mojom::UserActivationNotificationType::kTest); |
| 45 | } |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 46 | CHECK_EQ(args.Length(), 1); |
| 47 | CHECK(args[0]->IsFunction()); |
rdevlin.cronin | 57d21168 | 2016-11-04 06:00:16 | [diff] [blame] | 48 | context()->SafeCallFunction(v8::Local<v8::Function>::Cast(args[0]), 0, |
| 49 | nullptr); |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 50 | } |
| 51 | |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 52 | } // namespace extensions |