blob: 73b3d43eef191313785fb46da4c66a64358d828d [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)));
26 RouteHandlerFunction(
27 "RunWithoutUserGesture", "test",
28 base::Bind(&UserGesturesNativeHandler::RunWithoutUserGesture,
29 base::Unretained(this)));
[email protected]e6893672014-05-01 17:29:1330}
31
32void UserGesturesNativeHandler::IsProcessingUserGesture(
33 const v8::FunctionCallbackInfo<v8::Value>& args) {
Mustaq Ahmede473e4352017-11-04 01:04:2534 args.GetReturnValue().Set(
35 v8::Boolean::New(args.GetIsolate(),
36 blink::WebUserGestureIndicator::IsProcessingUserGesture(
37 context()->web_frame())));
[email protected]e6893672014-05-01 17:29:1338}
39
40void UserGesturesNativeHandler::RunWithUserGesture(
41 const v8::FunctionCallbackInfo<v8::Value>& args) {
japhet26ce3122016-10-25 21:30:0642 blink::WebScopedUserGesture user_gesture(context()->web_frame());
[email protected]e6893672014-05-01 17:29:1343 CHECK_EQ(args.Length(), 1);
44 CHECK(args[0]->IsFunction());
rdevlin.cronin57d211682016-11-04 06:00:1645 context()->SafeCallFunction(v8::Local<v8::Function>::Cast(args[0]), 0,
46 nullptr);
[email protected]e6893672014-05-01 17:29:1347}
48
49void UserGesturesNativeHandler::RunWithoutUserGesture(
50 const v8::FunctionCallbackInfo<v8::Value>& args) {
Mustaq Ahmede473e4352017-11-04 01:04:2551 blink::WebUserGestureIndicator::ConsumeUserGesture(context()->web_frame());
[email protected]e6893672014-05-01 17:29:1352 CHECK_EQ(args.Length(), 1);
53 CHECK(args[0]->IsFunction());
tfarinaf85316f2015-04-29 17:03:4054 v8::Local<v8::Value> no_args;
rdevlin.cronin57d211682016-11-04 06:00:1655 context()->SafeCallFunction(v8::Local<v8::Function>::Cast(args[0]), 0,
56 nullptr);
[email protected]e6893672014-05-01 17:29:1357}
58
59} // namespace extensions