From d7e2df1d26c084d299feec37695aacd211dae073 Mon Sep 17 00:00:00 2001 From: "stuartmorgan@chromium.org" Date: Thu, 11 Feb 2010 23:25:26 +0000 Subject: Make the plugin popup handling code cross-platform Factors the code to allow popups from plugins if they are triggered by user action into a cross-platform method. Also moves some Windows-only code in the header into ifdefs. BUG=none TEST=Click on a plugin that should open a popup window. Without this patch, it worked only every other time on the Mac. Review URL: http://codereview.chromium.org/593055 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38853 0039d316-1c4b-4281-b951-d872f2087c98 --- webkit/glue/plugins/webplugin_delegate_impl.cc | 32 ++++++++++++++ webkit/glue/plugins/webplugin_delegate_impl.h | 23 +++++----- webkit/glue/plugins/webplugin_delegate_impl_gtk.cc | 5 +-- webkit/glue/plugins/webplugin_delegate_impl_mac.mm | 13 +++--- webkit/glue/plugins/webplugin_delegate_impl_win.cc | 51 +++++++++------------- 5 files changed, 72 insertions(+), 52 deletions(-) diff --git a/webkit/glue/plugins/webplugin_delegate_impl.cc b/webkit/glue/plugins/webplugin_delegate_impl.cc index 1b033f6..3511eee 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl.cc +++ b/webkit/glue/plugins/webplugin_delegate_impl.cc @@ -213,6 +213,38 @@ void WebPluginDelegateImpl::WindowedUpdateGeometry( } } +bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event, + WebCursorInfo* cursor_info) { + DCHECK(windowless_) << "events should only be received in windowless mode"; + + bool pop_user_gesture = false; + if (IsUserGesture(event)) { + pop_user_gesture = true; + instance()->PushPopupsEnabledState(true); + } + + bool handled = PlatformHandleInputEvent(event, cursor_info); + + if (pop_user_gesture) { + instance()->PopPopupsEnabledState(); + } + + return handled; +} + +bool WebPluginDelegateImpl::IsUserGesture(const WebInputEvent& event) { + switch (event.type) { + case WebInputEvent::MouseDown: + case WebInputEvent::MouseUp: + case WebInputEvent::KeyDown: + case WebInputEvent::KeyUp: + return true; + default: + return false; + } + return false; +} + WebPluginResourceClient* WebPluginDelegateImpl::CreateResourceClient( unsigned long resource_id, const GURL& url, int notify_id) { return instance()->CreateStream( diff --git a/webkit/glue/plugins/webplugin_delegate_impl.h b/webkit/glue/plugins/webplugin_delegate_impl.h index 940a2a6..a11baa6 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl.h +++ b/webkit/glue/plugins/webplugin_delegate_impl.h @@ -77,7 +77,7 @@ class WebPluginDelegateImpl : public webkit_glue::WebPluginDelegate { virtual void Print(gfx::NativeDrawingContext context); virtual void SetFocus(); virtual bool HandleInputEvent(const WebKit::WebInputEvent& event, - WebKit::WebCursorInfo* cursor); + WebKit::WebCursorInfo* cursor_info); virtual NPObject* GetPluginScriptableObject(); virtual void DidFinishLoadWithReason( const GURL& url, NPReason reason, int notify_id); @@ -229,6 +229,11 @@ class WebPluginDelegateImpl : public webkit_glue::WebPluginDelegate { //----------------------------------------- // used for windowed and windowless plugins + // Does platform-specific event handling. Arguments and return are identical + // to HandleInputEvent. + bool PlatformHandleInputEvent(const WebKit::WebInputEvent& event, + WebKit::WebCursorInfo* cursor_info); + NPAPI::PluginInstance* instance() { return instance_.get(); } // Closes down and destroys our plugin instance. @@ -375,35 +380,33 @@ class WebPluginDelegateImpl : public webkit_glue::WebPluginDelegate { void OnModalLoopEntered(); // Returns true if the message passed in corresponds to a user gesture. - static bool IsUserGestureMessage(unsigned int message); - - // Indicates the end of a user gesture period. - void OnUserGestureEnd(); + static bool IsUserGesture(const WebKit::WebInputEvent& event); // The url with which the plugin was instantiated. std::string plugin_url_; #if defined(OS_WIN) + // Indicates the end of a user gesture period. + void OnUserGestureEnd(); + // Handle to the message filter hook HHOOK handle_event_message_filter_hook_; // Event which is set when the plugin enters a modal loop in the course // of a NPP_HandleEvent call. HANDLE handle_event_pump_messages_event_; -#endif - - // Holds the depth of the HandleEvent callstack. - int handle_event_depth_; // This flag indicates whether we started tracking a user gesture message. bool user_gesture_message_posted_; // Runnable Method Factory used to invoke the OnUserGestureEnd method // asynchronously. -#if !defined(USE_X11) ScopedRunnableMethodFactory user_gesture_msg_factory_; #endif + // Holds the depth of the HandleEvent callstack. + int handle_event_depth_; + // Holds the current cursor set by the windowless plugin. WebCursor current_windowless_cursor_; diff --git a/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc b/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc index 6fc1d3e..3e4f607 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc +++ b/webkit/glue/plugins/webplugin_delegate_impl_gtk.cc @@ -683,9 +683,8 @@ static bool NPEventFromWebInputEvent(const WebInputEvent& event, } } -bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event, - WebCursorInfo* cursor_info) { - DCHECK(windowless_) << "events should only be received in windowless mode"; +bool WebPluginDelegateImpl::PlatformHandleInputEvent( + const WebInputEvent& event, WebCursorInfo* cursor_info) { if (first_event_time_ < 0.0) first_event_time_ = event.timeStampSeconds; diff --git a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm index fa89506..58e3b3d 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl_mac.mm +++ b/webkit/glue/plugins/webplugin_delegate_impl_mac.mm @@ -182,9 +182,7 @@ WebPluginDelegateImpl::WebPluginDelegateImpl( initial_window_focus_(false), container_is_visible_(false), have_called_set_window_(false), - handle_event_depth_(0), - user_gesture_message_posted_(this), - user_gesture_msg_factory_(this) { + handle_event_depth_(0) { memset(&window_, 0, sizeof(window_)); #ifndef NP_NO_CARBON memset(&cg_context_, 0, sizeof(cg_context_)); @@ -917,10 +915,9 @@ static bool NPCocoaEventFromWebInputEvent(const WebInputEvent& event, return false; } -bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event, - WebCursorInfo* cursor) { - DCHECK(windowless_) << "events should only be received in windowless mode"; - DCHECK(cursor != NULL); +bool WebPluginDelegateImpl::PlatformHandleInputEvent( + const WebInputEvent& event, WebCursorInfo* cursor_info) { + DCHECK(cursor_info != NULL); #ifndef NP_NO_CARBON if (instance()->event_model() == NPEventModelCarbon && @@ -945,7 +942,7 @@ bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event, SetContentAreaOrigin(content_area_origin_); } - current_windowless_cursor_.GetCursorInfo(cursor); + current_windowless_cursor_.GetCursorInfo(cursor_info); } // if we do not currently have focus and this is a mouseDown, trigger a diff --git a/webkit/glue/plugins/webplugin_delegate_impl_win.cc b/webkit/glue/plugins/webplugin_delegate_impl_win.cc index 3d19b06..66c9558 100644 --- a/webkit/glue/plugins/webplugin_delegate_impl_win.cc +++ b/webkit/glue/plugins/webplugin_delegate_impl_win.cc @@ -243,10 +243,10 @@ WebPluginDelegateImpl::WebPluginDelegateImpl( dummy_window_for_activation_(NULL), handle_event_message_filter_hook_(NULL), handle_event_pump_messages_event_(NULL), - handle_event_depth_(0), user_gesture_message_posted_(false), #pragma warning(suppress: 4355) // can use this - user_gesture_msg_factory_(this) { + user_gesture_msg_factory_(this), + handle_event_depth_(0) { memset(&window_, 0, sizeof(window_)); const WebPluginInfo& plugin_info = instance_->plugin_lib()->plugin_info(); @@ -792,6 +792,22 @@ LRESULT CALLBACK WebPluginDelegateImpl::DummyWindowProc( return DefWindowProc(hWnd, message, wParam, lParam); } +// Returns true if the message passed in corresponds to a user gesture. +static bool IsUserGestureMessage(unsigned int message) { + switch (message) { + case WM_LBUTTONUP: + case WM_RBUTTONUP: + case WM_MBUTTONUP: + case WM_KEYUP: + return true; + + default: + break; + } + + return false; +} + LRESULT CALLBACK WebPluginDelegateImpl::NativeWndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam) { WebPluginDelegateImpl* delegate = reinterpret_cast( @@ -1084,9 +1100,8 @@ static bool NPEventFromWebInputEvent(const WebInputEvent& event, } } -bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event, - WebCursorInfo* cursor_info) { - DCHECK(windowless_) << "events should only be received in windowless mode"; +bool WebPluginDelegateImpl::PlatformHandleInputEvent( + const WebInputEvent& event, WebCursorInfo* cursor_info) { DCHECK(cursor_info != NULL); NPEvent np_event; @@ -1119,13 +1134,6 @@ bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event, handle_event_depth_++; - bool pop_user_gesture = false; - - if (IsUserGestureMessage(np_event.event)) { - pop_user_gesture = true; - instance()->PushPopupsEnabledState(true); - } - bool ret = instance()->NPP_HandleEvent(&np_event) != 0; if (np_event.event == WM_MOUSEMOVE) { @@ -1135,10 +1143,6 @@ bool WebPluginDelegateImpl::HandleInputEvent(const WebInputEvent& event, current_windowless_cursor_.GetCursorInfo(cursor_info); } - if (pop_user_gesture) { - instance()->PopPopupsEnabledState(); - } - handle_event_depth_--; g_current_plugin_instance = last_plugin_instance; @@ -1172,21 +1176,6 @@ bool WebPluginDelegateImpl::ShouldTrackEventForModalLoops(NPEvent* event) { return false; } -bool WebPluginDelegateImpl::IsUserGestureMessage(unsigned int message) { - switch (message) { - case WM_LBUTTONUP: - case WM_RBUTTONUP: - case WM_MBUTTONUP: - case WM_KEYUP: - return true; - - default: - break; - } - - return false; -} - void WebPluginDelegateImpl::OnUserGestureEnd() { user_gesture_message_posted_ = false; instance()->PopPopupsEnabledState(); -- cgit v1.1