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" 9#include "third_party/WebKit/public/web/WebScopedUserGesture.h" 10#include "third_party/WebKit/public/web/WebUserGestureIndicator.h" 11 12namespace extensions { 13 14UserGesturesNativeHandler::UserGesturesNativeHandler(ScriptContext* context) 15 : ObjectBackedNativeHandler(context) { 16 RouteFunction("IsProcessingUserGesture", 17 base::Bind(&UserGesturesNativeHandler::IsProcessingUserGesture, 18 base::Unretained(this))); 19 RouteFunction("RunWithUserGesture", 20 base::Bind(&UserGesturesNativeHandler::RunWithUserGesture, 21 base::Unretained(this))); 22 RouteFunction("RunWithoutUserGesture", 23 base::Bind(&UserGesturesNativeHandler::RunWithoutUserGesture, 24 base::Unretained(this))); 25} 26 27void UserGesturesNativeHandler::IsProcessingUserGesture( 28 const v8::FunctionCallbackInfo<v8::Value>& args) { 29 args.GetReturnValue().Set(v8::Boolean::New( 30 args.GetIsolate(), 31 blink::WebUserGestureIndicator::isProcessingUserGesture())); 32} 33 34void UserGesturesNativeHandler::RunWithUserGesture( 35 const v8::FunctionCallbackInfo<v8::Value>& args) { 36 blink::WebScopedUserGesture user_gesture; 37 CHECK_EQ(args.Length(), 1); 38 CHECK(args[0]->IsFunction()); 39 v8::Handle<v8::Value> no_args; 40 context()->CallFunction(v8::Handle<v8::Function>::Cast(args[0]), 0, &no_args); 41} 42 43void UserGesturesNativeHandler::RunWithoutUserGesture( 44 const v8::FunctionCallbackInfo<v8::Value>& args) { 45 blink::WebUserGestureIndicator::consumeUserGesture(); 46 CHECK_EQ(args.Length(), 1); 47 CHECK(args[0]->IsFunction()); 48 v8::Handle<v8::Value> no_args; 49 context()->CallFunction(v8::Handle<v8::Function>::Cast(args[0]), 0, &no_args); 50} 51 52} // namespace extensions 53