diff options
author | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-18 15:29:53 +0000 |
---|---|---|
committer | jochen@chromium.org <jochen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-18 15:29:53 +0000 |
commit | 7598787c6c5141d8babfa7023605738e4628b5bd (patch) | |
tree | c9b51301d3d113d123e8b9a2ac148c9f338dcf7f /webkit/plugins/ppapi | |
parent | e8f35bc96b5344c751bfde36d5a26a42bbfc4d31 (diff) | |
download | chromium_src-7598787c6c5141d8babfa7023605738e4628b5bd.zip chromium_src-7598787c6c5141d8babfa7023605738e4628b5bd.tar.gz chromium_src-7598787c6c5141d8babfa7023605738e4628b5bd.tar.bz2 |
Remember and use user gesture tokens in the PPAPI to manage user gesture state
Before, the PPAPI would indicate up to 10s after the last user gesture that
we're processing a user gesture. This is done so out of process plugins have
a chance to respond to a user gesture/
By using a user gesture token, we can make sure that the user gesture can only
be consumed once within the 10s timeframe
BUG=181500
TEST=none
R=dmichael@chromium.org
Review URL: https://codereview.chromium.org/12700004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188743 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/plugins/ppapi')
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.cc | 20 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppapi_plugin_instance.h | 6 | ||||
-rw-r--r-- | webkit/plugins/ppapi/ppb_var_deprecated_impl.cc | 3 |
3 files changed, 23 insertions, 6 deletions
diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.cc b/webkit/plugins/ppapi/ppapi_plugin_instance.cc index efc6d43..3ed7aa5 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.cc +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.cc @@ -136,6 +136,7 @@ using WebKit::WebScopedUserGesture; using WebKit::WebString; using WebKit::WebURLRequest; using WebKit::WebUserGestureIndicator; +using WebKit::WebUserGestureToken; using WebKit::WebView; namespace webkit { @@ -781,6 +782,8 @@ bool PluginInstance::HandleInputEvent(const WebKit::WebInputEvent& event, if (WebUserGestureIndicator::isProcessingUserGesture()) { pending_user_gesture_ = ::ppapi::EventTimeToPPTimeTicks(event.timeStampSeconds); + pending_user_gesture_token_ = + WebUserGestureIndicator::currentUserGestureToken(); } // Each input event may generate more than one PP_InputEvent. @@ -1442,7 +1445,7 @@ bool PluginInstance::SetFullscreen(bool fullscreen) { if (fullscreen) { // Create the user gesture in case we're processing one that's pending. - WebScopedUserGesture user_gesture; + WebScopedUserGesture user_gesture(CurrentUserGestureToken()); // WebKit does not resize the plugin to fill the screen in fullscreen mode, // so we will tweak plugin's attributes to support the expected behavior. KeepSizeAttributesBeforeFullscreen(); @@ -1515,7 +1518,7 @@ void PluginInstance::UpdateFlashFullscreenState(bool flash_fullscreen) { } else { // Open a user gesture here so the Webkit user gesture checks will succeed // for out-of-process plugins. - WebScopedUserGesture user_gesture; + WebScopedUserGesture user_gesture(CurrentUserGestureToken()); if (!delegate()->LockMouse(this)) lock_mouse_callback_->Run(PP_ERROR_FAILED); } @@ -1749,7 +1752,14 @@ bool PluginInstance::IsProcessingUserGesture() { ::ppapi::TimeTicksToPPTimeTicks(base::TimeTicks::Now()); // Give a lot of slack so tests won't be flaky. const PP_TimeTicks kUserGestureDurationInSeconds = 10.0; - return (now - pending_user_gesture_ < kUserGestureDurationInSeconds); + return pending_user_gesture_token_.hasGestures() && + (now - pending_user_gesture_ < kUserGestureDurationInSeconds); +} + +WebUserGestureToken PluginInstance::CurrentUserGestureToken() { + if (!IsProcessingUserGesture()) + pending_user_gesture_token_ = WebUserGestureToken(); + return pending_user_gesture_token_; } void PluginInstance::OnLockMouseACK(bool succeeded) { @@ -1967,7 +1977,7 @@ PP_Var PluginInstance::ExecuteScript(PP_Instance instance, NPVariant result; bool ok = false; if (IsProcessingUserGesture()) { - WebKit::WebScopedUserGesture user_gesture; + WebKit::WebScopedUserGesture user_gesture(CurrentUserGestureToken()); ok = WebBindings::evaluate(NULL, frame->windowObject(), &np_script, &result); } else { @@ -2239,7 +2249,7 @@ int32_t PluginInstance::LockMouse(PP_Instance instance, if (!FlashIsFullscreenOrPending() || flash_fullscreen()) { // Open a user gesture here so the Webkit user gesture checks will succeed // for out-of-process plugins. - WebScopedUserGesture user_gesture; + WebScopedUserGesture user_gesture(CurrentUserGestureToken()); if (!delegate()->LockMouse(this)) return PP_ERROR_FAILED; } diff --git a/webkit/plugins/ppapi/ppapi_plugin_instance.h b/webkit/plugins/ppapi/ppapi_plugin_instance.h index f91272b..6ba5904 100644 --- a/webkit/plugins/ppapi/ppapi_plugin_instance.h +++ b/webkit/plugins/ppapi/ppapi_plugin_instance.h @@ -47,6 +47,7 @@ #include "third_party/WebKit/Source/Platform/chromium/public/WebCanvas.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebUserGestureToken.h" #include "third_party/skia/include/core/SkRefCnt.h" #include "ui/base/ime/text_input_type.h" #include "ui/gfx/rect.h" @@ -330,6 +331,10 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : // Returns true if the plugin is processing a user gesture. bool IsProcessingUserGesture(); + // Returns the user gesture token to use for creating a WebScopedUserGesture, + // if IsProcessingUserGesture returned true. + WebKit::WebUserGestureToken CurrentUserGestureToken(); + // A mouse lock request was pending and this reports success or failure. void OnLockMouseACK(bool succeeded); // A mouse lock was in place, but has been lost. @@ -763,6 +768,7 @@ class WEBKIT_PLUGINS_EXPORT PluginInstance : // Track pending user gestures so out-of-process plugins can respond to // a user gesture after it has been processed. PP_TimeTicks pending_user_gesture_; + WebKit::WebUserGestureToken pending_user_gesture_token_; // We store the arguments so we can re-send them if we are reset to talk to // NaCl via the IPC NaCl proxy. diff --git a/webkit/plugins/ppapi/ppb_var_deprecated_impl.cc b/webkit/plugins/ppapi/ppb_var_deprecated_impl.cc index 5f59c45..e7373a3 100644 --- a/webkit/plugins/ppapi/ppb_var_deprecated_impl.cc +++ b/webkit/plugins/ppapi/ppb_var_deprecated_impl.cc @@ -334,7 +334,8 @@ PP_Var CallDeprecated(PP_Var var, return PP_MakeUndefined(); PluginInstance* plugin = accessor.GetPluginInstance(); if (plugin && plugin->IsProcessingUserGesture()) { - WebKit::WebScopedUserGesture user_gesture; + WebKit::WebScopedUserGesture user_gesture( + plugin->CurrentUserGestureToken()); return InternalCallDeprecated(&accessor, method_name, argc, argv, exception); } |