blob: 79e111b7291445c4921ab42232c6b54488b36476 [file] [log] [blame]
[email protected]e6893672014-05-01 17:29:131// 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 Reformata30d4232018-04-07 15:31:069#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]e6893672014-05-01 17:29:1311
12namespace extensions {
13
14UserGesturesNativeHandler::UserGesturesNativeHandler(ScriptContext* context)
Devlin Cronind9ea8342018-01-27 06:00:0415 : ObjectBackedNativeHandler(context) {}
16
17void 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]e6893672014-05-01 17:29:1326}
27
28void UserGesturesNativeHandler::IsProcessingUserGesture(
29 const v8::FunctionCallbackInfo<v8::Value>& args) {
Mustaq Ahmede473e4352017-11-04 01:04:2530 args.GetReturnValue().Set(
31 v8::Boolean::New(args.GetIsolate(),
32 blink::WebUserGestureIndicator::IsProcessingUserGesture(
33 context()->web_frame())));
[email protected]e6893672014-05-01 17:29:1334}
35
36void UserGesturesNativeHandler::RunWithUserGesture(
37 const v8::FunctionCallbackInfo<v8::Value>& args) {
japhet26ce3122016-10-25 21:30:0638 blink::WebScopedUserGesture user_gesture(context()->web_frame());
[email protected]e6893672014-05-01 17:29:1339 CHECK_EQ(args.Length(), 1);
40 CHECK(args[0]->IsFunction());
rdevlin.cronin57d211682016-11-04 06:00:1641 context()->SafeCallFunction(v8::Local<v8::Function>::Cast(args[0]), 0,
42 nullptr);
[email protected]e6893672014-05-01 17:29:1343}
44
[email protected]e6893672014-05-01 17:29:1345} // namespace extensions