| OLD | NEW |
| 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" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 #include "base/time.h" |
| 13 #include "base/utf_offset_string_conversions.h" | 14 #include "base/utf_offset_string_conversions.h" |
| 14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 15 #include "ppapi/c/dev/ppb_find_dev.h" | 16 #include "ppapi/c/dev/ppb_find_dev.h" |
| 16 #include "ppapi/c/dev/ppb_zoom_dev.h" | 17 #include "ppapi/c/dev/ppb_zoom_dev.h" |
| 17 #include "ppapi/c/dev/ppp_find_dev.h" | 18 #include "ppapi/c/dev/ppp_find_dev.h" |
| 18 #include "ppapi/c/dev/ppp_selection_dev.h" | 19 #include "ppapi/c/dev/ppp_selection_dev.h" |
| 19 #include "ppapi/c/dev/ppp_zoom_dev.h" | 20 #include "ppapi/c/dev/ppp_zoom_dev.h" |
| 20 #include "ppapi/c/pp_rect.h" | 21 #include "ppapi/c/pp_rect.h" |
| 21 #include "ppapi/c/ppb_audio_config.h" | 22 #include "ppapi/c/ppb_audio_config.h" |
| 22 #include "ppapi/c/ppb_core.h" | 23 #include "ppapi/c/ppb_core.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 41 #include "third_party/skia/include/core/SkRect.h" | 42 #include "third_party/skia/include/core/SkRect.h" |
| 42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
| 43 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli
ne.h" | 44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli
ne.h" |
| 44 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| 45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 46 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 47 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 48 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 48 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.
h" | 49 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGamepads.
h" |
| 49 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 50 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 50 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 51 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 52 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScopedUserGesture.
h" |
| 51 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 53 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
| 52 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 54 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 53 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" | 55 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
| 54 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" | 56 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLReques
t.h" |
| 55 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 57 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 56 #include "webkit/plugins/ppapi/common.h" | 58 #include "webkit/plugins/ppapi/common.h" |
| 57 #include "webkit/plugins/ppapi/event_conversion.h" | 59 #include "webkit/plugins/ppapi/event_conversion.h" |
| 58 #include "webkit/plugins/ppapi/fullscreen_container.h" | 60 #include "webkit/plugins/ppapi/fullscreen_container.h" |
| 59 #include "webkit/plugins/ppapi/gfx_conversion.h" | 61 #include "webkit/plugins/ppapi/gfx_conversion.h" |
| 60 #include "webkit/plugins/ppapi/host_globals.h" | 62 #include "webkit/plugins/ppapi/host_globals.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 using ppapi::ViewData; | 111 using ppapi::ViewData; |
| 110 using WebKit::WebBindings; | 112 using WebKit::WebBindings; |
| 111 using WebKit::WebCanvas; | 113 using WebKit::WebCanvas; |
| 112 using WebKit::WebCursorInfo; | 114 using WebKit::WebCursorInfo; |
| 113 using WebKit::WebDocument; | 115 using WebKit::WebDocument; |
| 114 using WebKit::WebElement; | 116 using WebKit::WebElement; |
| 115 using WebKit::WebFrame; | 117 using WebKit::WebFrame; |
| 116 using WebKit::WebInputEvent; | 118 using WebKit::WebInputEvent; |
| 117 using WebKit::WebPlugin; | 119 using WebKit::WebPlugin; |
| 118 using WebKit::WebPluginContainer; | 120 using WebKit::WebPluginContainer; |
| 121 using WebKit::WebScopedUserGesture; |
| 119 using WebKit::WebString; | 122 using WebKit::WebString; |
| 120 using WebKit::WebURLRequest; | 123 using WebKit::WebURLRequest; |
| 121 using WebKit::WebView; | 124 using WebKit::WebView; |
| 122 | 125 |
| 123 namespace webkit { | 126 namespace webkit { |
| 124 namespace ppapi { | 127 namespace ppapi { |
| 125 | 128 |
| 126 #if defined(OS_WIN) | 129 #if defined(OS_WIN) |
| 127 // Exported by pdf.dll | 130 // Exported by pdf.dll |
| 128 typedef bool (*RenderPDFPageToDCProc)( | 131 typedef bool (*RenderPDFPageToDCProc)( |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 flash_fullscreen_(false), | 296 flash_fullscreen_(false), |
| 294 desired_fullscreen_state_(false), | 297 desired_fullscreen_state_(false), |
| 295 message_channel_(NULL), | 298 message_channel_(NULL), |
| 296 sad_plugin_(NULL), | 299 sad_plugin_(NULL), |
| 297 input_event_mask_(0), | 300 input_event_mask_(0), |
| 298 filtered_input_event_mask_(0), | 301 filtered_input_event_mask_(0), |
| 299 text_input_type_(kPluginDefaultTextInputType), | 302 text_input_type_(kPluginDefaultTextInputType), |
| 300 text_input_caret_(0, 0, 0, 0), | 303 text_input_caret_(0, 0, 0, 0), |
| 301 text_input_caret_bounds_(0, 0, 0, 0), | 304 text_input_caret_bounds_(0, 0, 0, 0), |
| 302 text_input_caret_set_(false), | 305 text_input_caret_set_(false), |
| 303 lock_mouse_callback_(PP_BlockUntilComplete()) { | 306 lock_mouse_callback_(PP_BlockUntilComplete()), |
| 307 pending_user_gesture_(0.0) { |
| 304 pp_instance_ = HostGlobals::Get()->AddInstance(this); | 308 pp_instance_ = HostGlobals::Get()->AddInstance(this); |
| 305 | 309 |
| 306 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); | 310 memset(¤t_print_settings_, 0, sizeof(current_print_settings_)); |
| 307 DCHECK(delegate); | 311 DCHECK(delegate); |
| 308 module_->InstanceCreated(this); | 312 module_->InstanceCreated(this); |
| 309 delegate_->InstanceCreated(this); | 313 delegate_->InstanceCreated(this); |
| 310 message_channel_.reset(new MessageChannel(this)); | 314 message_channel_.reset(new MessageChannel(this)); |
| 311 | 315 |
| 312 view_data_.is_page_visible = delegate->IsPageVisible(); | 316 view_data_.is_page_visible = delegate->IsPageVisible(); |
| 313 } | 317 } |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 PP_InputEvent_Class event_class = ClassifyInputEvent(event.type); | 678 PP_InputEvent_Class event_class = ClassifyInputEvent(event.type); |
| 675 if (!event_class) | 679 if (!event_class) |
| 676 return false; | 680 return false; |
| 677 | 681 |
| 678 if ((filtered_input_event_mask_ & event_class) || | 682 if ((filtered_input_event_mask_ & event_class) || |
| 679 (input_event_mask_ & event_class)) { | 683 (input_event_mask_ & event_class)) { |
| 680 // Actually send the event. | 684 // Actually send the event. |
| 681 std::vector< ::ppapi::InputEventData > events; | 685 std::vector< ::ppapi::InputEventData > events; |
| 682 CreateInputEventData(event, &events); | 686 CreateInputEventData(event, &events); |
| 683 | 687 |
| 688 // Allow the user gesture to be pending after the plugin handles the |
| 689 // event. This allows out-of-process plugins to respond to the user |
| 690 // gesture after processing has finished here. |
| 691 WebFrame* frame = container_->element().document().frame(); |
| 692 if (frame->isProcessingUserGesture()) { |
| 693 pending_user_gesture_ = |
| 694 ::ppapi::EventTimeToPPTimeTicks(event.timeStampSeconds); |
| 695 } |
| 696 |
| 684 // Each input event may generate more than one PP_InputEvent. | 697 // Each input event may generate more than one PP_InputEvent. |
| 685 for (size_t i = 0; i < events.size(); i++) { | 698 for (size_t i = 0; i < events.size(); i++) { |
| 686 if (filtered_input_event_mask_ & event_class) | 699 if (filtered_input_event_mask_ & event_class) |
| 687 events[i].is_filtered = true; | 700 events[i].is_filtered = true; |
| 688 else | 701 else |
| 689 rv = true; // Unfiltered events are assumed to be handled. | 702 rv = true; // Unfiltered events are assumed to be handled. |
| 690 scoped_refptr<PPB_InputEvent_Shared> event_resource( | 703 scoped_refptr<PPB_InputEvent_Shared> event_resource( |
| 691 new PPB_InputEvent_Shared(::ppapi::OBJECT_IS_IMPL, | 704 new PPB_InputEvent_Shared(::ppapi::OBJECT_IS_IMPL, |
| 692 pp_instance(), events[i])); | 705 pp_instance(), events[i])); |
| 693 | 706 |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1225 // container isn't ready yet, don't do anything more). | 1238 // container isn't ready yet, don't do anything more). |
| 1226 if (fullscreen == IsFullscreenOrPending()) | 1239 if (fullscreen == IsFullscreenOrPending()) |
| 1227 return false; | 1240 return false; |
| 1228 | 1241 |
| 1229 // 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. |
| 1230 // 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 |
| 1231 // disallow this. | 1244 // disallow this. |
| 1232 if (view_data_.is_fullscreen != desired_fullscreen_state_) | 1245 if (view_data_.is_fullscreen != desired_fullscreen_state_) |
| 1233 return false; | 1246 return false; |
| 1234 | 1247 |
| 1235 // The browser will allow us to go into fullscreen mode only when processing | 1248 if (fullscreen && !HasUserGesture()) |
| 1236 // a user gesture. This is guaranteed to work with in-process plugins and | |
| 1237 // out-of-process syncronous proxies, but might be an issue with Flash when | |
| 1238 // it switches over from PPB_FlashFullscreen. | |
| 1239 // TODO(polina, bbudge): make this work with asynchronous proxies. | |
| 1240 WebFrame* frame = container_->element().document().frame(); | |
| 1241 if (fullscreen && !frame->isProcessingUserGesture()) | |
| 1242 return false; | 1249 return false; |
| 1243 | 1250 |
| 1244 VLOG(1) << "Setting fullscreen to " << (fullscreen ? "on" : "off"); | 1251 VLOG(1) << "Setting fullscreen to " << (fullscreen ? "on" : "off"); |
| 1245 desired_fullscreen_state_ = fullscreen; | 1252 desired_fullscreen_state_ = fullscreen; |
| 1246 | 1253 |
| 1247 if (fullscreen) { | 1254 if (fullscreen) { |
| 1255 // Create the user gesture in case we're processing one that's pending. |
| 1256 WebScopedUserGesture user_gesture; |
| 1248 // 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, |
| 1249 // 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. |
| 1250 KeepSizeAttributesBeforeFullscreen(); | 1259 KeepSizeAttributesBeforeFullscreen(); |
| 1251 SetSizeAttributesForFullscreen(); | 1260 SetSizeAttributesForFullscreen(); |
| 1252 container_->element().requestFullScreen(); | 1261 container_->element().requestFullScreen(); |
| 1253 } else { | 1262 } else { |
| 1254 container_->element().document().cancelFullScreen(); | 1263 container_->element().document().cancelFullScreen(); |
| 1255 } | 1264 } |
| 1256 return true; | 1265 return true; |
| 1257 } | 1266 } |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1691 CreateSimulatedWebInputEvents( | 1700 CreateSimulatedWebInputEvents( |
| 1692 input_event, | 1701 input_event, |
| 1693 view_data_.rect.point.x + view_data_.rect.size.width / 2, | 1702 view_data_.rect.point.x + view_data_.rect.size.width / 2, |
| 1694 view_data_.rect.point.y + view_data_.rect.size.height / 2); | 1703 view_data_.rect.point.y + view_data_.rect.size.height / 2); |
| 1695 for (std::vector<linked_ptr<WebInputEvent> >::iterator it = events.begin(); | 1704 for (std::vector<linked_ptr<WebInputEvent> >::iterator it = events.begin(); |
| 1696 it != events.end(); ++it) { | 1705 it != events.end(); ++it) { |
| 1697 web_view->handleInputEvent(*it->get()); | 1706 web_view->handleInputEvent(*it->get()); |
| 1698 } | 1707 } |
| 1699 } | 1708 } |
| 1700 | 1709 |
| 1710 void PluginInstance::ClosePendingUserGesture(PP_Instance instance, |
| 1711 PP_TimeTicks timestamp) { |
| 1712 // 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 |
| 1714 // there may be multiple input events with the same timestamp. |
| 1715 if (timestamp > pending_user_gesture_) |
| 1716 pending_user_gesture_ = 0.0; |
| 1717 } |
| 1718 |
| 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 |
| 1701 PPB_Instance_FunctionAPI* PluginInstance::AsPPB_Instance_FunctionAPI() { | 1728 PPB_Instance_FunctionAPI* PluginInstance::AsPPB_Instance_FunctionAPI() { |
| 1702 return this; | 1729 return this; |
| 1703 } | 1730 } |
| 1704 | 1731 |
| 1705 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, | 1732 PP_Bool PluginInstance::BindGraphics(PP_Instance instance, |
| 1706 PP_Resource device) { | 1733 PP_Resource device) { |
| 1707 if (bound_graphics_.get()) { | 1734 if (bound_graphics_.get()) { |
| 1708 if (GetBoundGraphics2D()) { | 1735 if (GetBoundGraphics2D()) { |
| 1709 GetBoundGraphics2D()->BindToInstance(NULL); | 1736 GetBoundGraphics2D()->BindToInstance(NULL); |
| 1710 } else if (GetBoundGraphics3D()) { | 1737 } else if (GetBoundGraphics3D()) { |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2080 screen_size_for_fullscreen_ = gfx::Size(); | 2107 screen_size_for_fullscreen_ = gfx::Size(); |
| 2081 WebElement element = container_->element(); | 2108 WebElement element = container_->element(); |
| 2082 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); | 2109 element.setAttribute(WebString::fromUTF8(kWidth), width_before_fullscreen_); |
| 2083 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); | 2110 element.setAttribute(WebString::fromUTF8(kHeight), height_before_fullscreen_); |
| 2084 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); | 2111 element.setAttribute(WebString::fromUTF8(kBorder), border_before_fullscreen_); |
| 2085 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); | 2112 element.setAttribute(WebString::fromUTF8(kStyle), style_before_fullscreen_); |
| 2086 } | 2113 } |
| 2087 | 2114 |
| 2088 } // namespace ppapi | 2115 } // namespace ppapi |
| 2089 } // namespace webkit | 2116 } // namespace webkit |
| OLD | NEW |