[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))); |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | void UserGesturesNativeHandler::IsProcessingUserGesture( |
| 29 | const v8::FunctionCallbackInfo<v8::Value>& args) { |
Mustaq Ahmed | e473e435 | 2017-11-04 01:04:25 | [diff] [blame] | 30 | args.GetReturnValue().Set( |
| 31 | v8::Boolean::New(args.GetIsolate(), |
| 32 | blink::WebUserGestureIndicator::IsProcessingUserGesture( |
| 33 | context()->web_frame()))); |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | void UserGesturesNativeHandler::RunWithUserGesture( |
| 37 | const v8::FunctionCallbackInfo<v8::Value>& args) { |
japhet | 26ce312 | 2016-10-25 21:30:06 | [diff] [blame] | 38 | blink::WebScopedUserGesture user_gesture(context()->web_frame()); |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 39 | CHECK_EQ(args.Length(), 1); |
| 40 | CHECK(args[0]->IsFunction()); |
rdevlin.cronin | 57d21168 | 2016-11-04 06:00:16 | [diff] [blame] | 41 | context()->SafeCallFunction(v8::Local<v8::Function>::Cast(args[0]), 0, |
| 42 | nullptr); |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 43 | } |
| 44 | |
[email protected] | e689367 | 2014-05-01 17:29:13 | [diff] [blame] | 45 | } // namespace extensions |