Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: webkit/plugins/ppapi/ppapi_plugin_instance.cc

Issue 7764002: Require a user gesture to display the PPAPI file chooser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 5 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/linked_ptr.h" 10 #include "base/memory/linked_ptr.h"
(...skipping 1227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 // container isn't ready yet, don't do anything more). 1238 // container isn't ready yet, don't do anything more).
1239 if (fullscreen == IsFullscreenOrPending()) 1239 if (fullscreen == IsFullscreenOrPending())
1240 return false; 1240 return false;
1241 1241
1242 // Check whether we are trying to switch while the state is in transition. 1242 // Check whether we are trying to switch while the state is in transition.
1243 // The 2nd request gets dropped while messing up the internal state, so 1243 // The 2nd request gets dropped while messing up the internal state, so
1244 // disallow this. 1244 // disallow this.
1245 if (view_data_.is_fullscreen != desired_fullscreen_state_) 1245 if (view_data_.is_fullscreen != desired_fullscreen_state_)
1246 return false; 1246 return false;
1247 1247
1248 if (fullscreen && !HasUserGesture()) 1248 if (fullscreen && !IsProcessingUserGesture())
1249 return false; 1249 return false;
1250 1250
1251 VLOG(1) << "Setting fullscreen to " << (fullscreen ? "on" : "off"); 1251 VLOG(1) << "Setting fullscreen to " << (fullscreen ? "on" : "off");
1252 desired_fullscreen_state_ = fullscreen; 1252 desired_fullscreen_state_ = fullscreen;
1253 1253
1254 if (fullscreen) { 1254 if (fullscreen) {
1255 // Create the user gesture in case we're processing one that's pending. 1255 // Create the user gesture in case we're processing one that's pending.
1256 WebScopedUserGesture user_gesture; 1256 WebScopedUserGesture user_gesture;
1257 // WebKit does not resize the plugin to fill the screen in fullscreen mode, 1257 // WebKit does not resize the plugin to fill the screen in fullscreen mode,
1258 // so we will tweak plugin's attributes to support the expected behavior. 1258 // so we will tweak plugin's attributes to support the expected behavior.
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1661 // Don't actually verify that the object is in the set since during module 1661 // Don't actually verify that the object is in the set since during module
1662 // deletion we'll be in the process of freeing them. 1662 // deletion we'll be in the process of freeing them.
1663 live_plugin_objects_.erase(plugin_object); 1663 live_plugin_objects_.erase(plugin_object);
1664 } 1664 }
1665 1665
1666 bool PluginInstance::IsFullPagePlugin() const { 1666 bool PluginInstance::IsFullPagePlugin() const {
1667 WebFrame* frame = container()->element().document().frame(); 1667 WebFrame* frame = container()->element().document().frame();
1668 return frame->view()->mainFrame()->document().isPluginDocument(); 1668 return frame->view()->mainFrame()->document().isPluginDocument();
1669 } 1669 }
1670 1670
1671 bool PluginInstance::IsProcessingUserGesture() {
1672 PP_TimeTicks now =
1673 ::ppapi::TimeTicksToPPTimeTicks(base::TimeTicks::Now());
1674 // Give a lot of slack so tests won't be flaky. Well behaved plugins will
1675 // close the user gesture.
1676 const PP_TimeTicks kUserGestureDurationInSeconds = 10.0;
1677 return (now - pending_user_gesture_ < kUserGestureDurationInSeconds);
1678 }
1679
1671 void PluginInstance::OnLockMouseACK(bool succeeded) { 1680 void PluginInstance::OnLockMouseACK(bool succeeded) {
1672 if (!lock_mouse_callback_.func) { 1681 if (!lock_mouse_callback_.func) {
1673 NOTREACHED(); 1682 NOTREACHED();
1674 return; 1683 return;
1675 } 1684 }
1676 PP_RunAndClearCompletionCallback(&lock_mouse_callback_, 1685 PP_RunAndClearCompletionCallback(&lock_mouse_callback_,
1677 succeeded ? PP_OK : PP_ERROR_FAILED); 1686 succeeded ? PP_OK : PP_ERROR_FAILED);
1678 } 1687 }
1679 1688
1680 void PluginInstance::OnMouseLockLost() { 1689 void PluginInstance::OnMouseLockLost() {
(...skipping 28 matching lines...) Expand all
1709 1718
1710 void PluginInstance::ClosePendingUserGesture(PP_Instance instance, 1719 void PluginInstance::ClosePendingUserGesture(PP_Instance instance,
1711 PP_TimeTicks timestamp) { 1720 PP_TimeTicks timestamp) {
1712 // Close the pending user gesture if the plugin had a chance to respond. 1721 // Close the pending user gesture if the plugin had a chance to respond.
1713 // Don't close the pending user gesture if the timestamps are equal since 1722 // Don't close the pending user gesture if the timestamps are equal since
1714 // there may be multiple input events with the same timestamp. 1723 // there may be multiple input events with the same timestamp.
1715 if (timestamp > pending_user_gesture_) 1724 if (timestamp > pending_user_gesture_)
1716 pending_user_gesture_ = 0.0; 1725 pending_user_gesture_ = 0.0;
1717 } 1726 }
1718 1727
1719 bool PluginInstance::HasUserGesture() {
1720 PP_TimeTicks now =
1721 ::ppapi::TimeTicksToPPTimeTicks(base::TimeTicks::Now());
1722 // Give a lot of slack so tests won't be flaky. Well behaved plugins will
1723 // close the user gesture.
1724 const PP_TimeTicks kUserGestureDurationInSeconds = 10.0;
1725 return (now - pending_user_gesture_ < kUserGestureDurationInSeconds);
1726 }
1727
1728 PPB_Instance_FunctionAPI* PluginInstance::AsPPB_Instance_FunctionAPI() { 1728 PPB_Instance_FunctionAPI* PluginInstance::AsPPB_Instance_FunctionAPI() {
1729 return this; 1729 return this;
1730 } 1730 }
1731 1731
1732 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, 1732 PP_Bool PluginInstance::BindGraphics(PP_Instance instance,
1733 PP_Resource device) { 1733 PP_Resource device) {
1734 if (bound_graphics_.get()) { 1734 if (bound_graphics_.get()) {
1735 if (GetBoundGraphics2D()) { 1735 if (GetBoundGraphics2D()) {
1736 GetBoundGraphics2D()->BindToInstance(NULL); 1736 GetBoundGraphics2D()->BindToInstance(NULL);
1737 } else if (GetBoundGraphics3D()) { 1737 } else if (GetBoundGraphics3D()) {
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
2107 screen_size_for_fullscreen_ = gfx::Size(); 2107 screen_size_for_fullscreen_ = gfx::Size();
2108 WebElement element = container_->element(); 2108 WebElement element = container_->element();
2109 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); 2109 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_);
2110 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); 2110 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_);
2111 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); 2111 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_);
2112 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); 2112 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_);
2113 } 2113 }
2114 2114
2115 } // namespace ppapi 2115 } // namespace ppapi
2116 } // namespace webkit 2116 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppapi_plugin_instance.h ('k') | webkit/plugins/ppapi/ppb_file_chooser_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698