blob: 88e04ca7c4ff0047bbe4b0216a1f197d7eeab0b1 [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"
Istiaque Ahmed96f506092019-07-08 23:40:578#include "extensions/renderer/extension_interaction_provider.h"
[email protected]e6893672014-05-01 17:29:139#include "extensions/renderer/script_context.h"
Mustaq Ahmedecb5c38e2020-07-29 00:34:3010#include "third_party/blink/public/mojom/frame/user_activation_notification_type.mojom.h"
Mustaq Ahmed4baa9a6e82019-12-20 23:43:4611#include "third_party/blink/public/web/web_local_frame.h"
[email protected]e6893672014-05-01 17:29:1312
13namespace extensions {
14
15UserGesturesNativeHandler::UserGesturesNativeHandler(ScriptContext* context)
Devlin Cronind9ea8342018-01-27 06:00:0416 : ObjectBackedNativeHandler(context) {}
17
18void UserGesturesNativeHandler::AddRoutes() {
19 RouteHandlerFunction(
20 "IsProcessingUserGesture", "test",
Devlin Cronincc02a0c2019-01-03 22:15:0721 base::BindRepeating(&UserGesturesNativeHandler::IsProcessingUserGesture,
22 base::Unretained(this)));
Devlin Cronind9ea8342018-01-27 06:00:0423 RouteHandlerFunction(
24 "RunWithUserGesture", "test",
Mustaq Ahmedfb1ddbbd2020-02-27 18:32:5025 base::BindRepeating(
26 &UserGesturesNativeHandler::RunWithUserActivationForTest,
27 base::Unretained(this)));
[email protected]e6893672014-05-01 17:29:1328}
29
30void UserGesturesNativeHandler::IsProcessingUserGesture(
31 const v8::FunctionCallbackInfo<v8::Value>& args) {
Istiaque Ahmed96f506092019-07-08 23:40:5732 args.GetReturnValue().Set(v8::Boolean::New(
33 args.GetIsolate(),
34 ExtensionInteractionProvider::HasActiveExtensionInteraction(
35 context()->v8_context())));
[email protected]e6893672014-05-01 17:29:1336}
37
Mustaq Ahmedfb1ddbbd2020-02-27 18:32:5038void UserGesturesNativeHandler::RunWithUserActivationForTest(
[email protected]e6893672014-05-01 17:29:1339 const v8::FunctionCallbackInfo<v8::Value>& args) {
Istiaque Ahmed91d6987c2019-06-25 00:09:3340 // TODO(lazyboy): This won't work for Service Workers. Address this once we're
41 // certain that we need this for workers.
Mustaq Ahmedecb5c38e2020-07-29 00:34:3042 if (context()->web_frame()) {
43 context()->web_frame()->NotifyUserActivation(
44 blink::mojom::UserActivationNotificationType::kTest);
45 }
[email protected]e6893672014-05-01 17:29:1346 CHECK_EQ(args.Length(), 1);
47 CHECK(args[0]->IsFunction());
rdevlin.cronin57d211682016-11-04 06:00:1648 context()->SafeCallFunction(v8::Local<v8::Function>::Cast(args[0]), 0,
49 nullptr);
[email protected]e6893672014-05-01 17:29:1350}
51
[email protected]e6893672014-05-01 17:29:1352} // namespace extensions