| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #ifndef WEBKIT_GLUE_PLUGIN_WEBPLUGIN_DELEGATE_IMPL_H__ | 5 #ifndef WEBKIT_GLUE_PLUGIN_WEBPLUGIN_DELEGATE_IMPL_H__ |
| 6 #define WEBKIT_GLUE_PLUGIN_WEBPLUGIN_DELEGATE_IMPL_H__ | 6 #define WEBKIT_GLUE_PLUGIN_WEBPLUGIN_DELEGATE_IMPL_H__ |
| 7 | 7 |
| 8 #include "build/build_config.h" |
| 9 |
| 8 #include <string> | 10 #include <string> |
| 9 #include <list> | 11 #include <list> |
| 10 | 12 |
| 11 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 12 #include "base/gfx/native_widget_types.h" | 14 #include "base/gfx/native_widget_types.h" |
| 13 #include "base/ref_counted.h" | 15 #include "base/ref_counted.h" |
| 14 #include "base/task.h" | 16 #include "base/task.h" |
| 15 #include "third_party/npapi/bindings/npapi.h" | 17 #include "third_party/npapi/bindings/npapi.h" |
| 16 #include "webkit/glue/webplugin_delegate.h" | 18 #include "webkit/glue/webplugin_delegate.h" |
| 17 #include "webkit/glue/webcursor.h" | 19 #include "webkit/glue/webcursor.h" |
| 18 | 20 |
| 19 namespace NPAPI { | 21 namespace NPAPI { |
| 20 class PluginInstance; | 22 class PluginInstance; |
| 21 }; | 23 }; |
| 22 | 24 |
| 23 // An implementation of WebPluginDelegate that proxies all calls to | 25 // An implementation of WebPluginDelegate that proxies all calls to |
| 24 // the plugin process. | 26 // the plugin process. |
| 25 class WebPluginDelegateImpl : public WebPluginDelegate { | 27 class WebPluginDelegateImpl : public WebPluginDelegate { |
| 26 public: | 28 public: |
| 27 static WebPluginDelegateImpl* Create(const FilePath& filename, | 29 static WebPluginDelegateImpl* Create(const FilePath& filename, |
| 28 const std::string& mime_type, | 30 const std::string& mime_type, |
| 29 gfx::NativeView containing_view); | 31 gfx::NativeView containing_view); |
| 32 #if defined(OS_WIN) |
| 30 static bool IsPluginDelegateWindow(HWND window); | 33 static bool IsPluginDelegateWindow(HWND window); |
| 31 static bool GetPluginNameFromWindow(HWND window, std::wstring *plugin_name); | 34 static bool GetPluginNameFromWindow(HWND window, std::wstring *plugin_name); |
| 32 | 35 |
| 33 // Returns true if the window handle passed in is that of the dummy | 36 // Returns true if the window handle passed in is that of the dummy |
| 34 // activation window for windowless plugins. | 37 // activation window for windowless plugins. |
| 35 static bool IsDummyActivationWindow(HWND window); | 38 static bool IsDummyActivationWindow(HWND window); |
| 39 #endif // OS_WIN) |
| 36 | 40 |
| 37 // WebPluginDelegate implementation | 41 // WebPluginDelegate implementation |
| 38 virtual void PluginDestroyed(); | 42 virtual void PluginDestroyed(); |
| 39 virtual bool Initialize(const GURL& url, | 43 virtual bool Initialize(const GURL& url, |
| 40 char** argn, | 44 char** argn, |
| 41 char** argv, | 45 char** argv, |
| 42 int argc, | 46 int argc, |
| 43 WebPlugin* plugin, | 47 WebPlugin* plugin, |
| 44 bool load_manually); | 48 bool load_manually); |
| 45 virtual void UpdateGeometry(const gfx::Rect& window_rect, | 49 virtual void UpdateGeometry(const gfx::Rect& window_rect, |
| 46 const gfx::Rect& clip_rect); | 50 const gfx::Rect& clip_rect); |
| 51 #if defined(OS_WIN) |
| 47 virtual void Paint(HDC hdc, const gfx::Rect& rect); | 52 virtual void Paint(HDC hdc, const gfx::Rect& rect); |
| 48 virtual void Print(HDC hdc); | 53 virtual void Print(HDC hdc); |
| 54 #else |
| 55 // TODO(port): temporary workaround. |
| 56 virtual void Paint(void* dc, const gfx::Rect& rect); |
| 57 virtual void Print(void* dc); |
| 58 #endif |
| 49 virtual void SetFocus(); // only called when windowless | 59 virtual void SetFocus(); // only called when windowless |
| 50 // only called when windowless | 60 // only called when windowless |
| 51 virtual bool HandleEvent(NPEvent* event, | 61 virtual bool HandleEvent(NPEvent* event, |
| 52 WebCursor* cursor); | 62 WebCursor* cursor); |
| 53 virtual NPObject* GetPluginScriptableObject(); | 63 virtual NPObject* GetPluginScriptableObject(); |
| 54 virtual void DidFinishLoadWithReason(NPReason reason); | 64 virtual void DidFinishLoadWithReason(NPReason reason); |
| 55 virtual int GetProcessId(); | 65 virtual int GetProcessId(); |
| 56 | 66 |
| 57 virtual void FlushGeometryUpdates() { | 67 virtual void FlushGeometryUpdates() { |
| 58 } | 68 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 75 bool notify_needed, | 85 bool notify_needed, |
| 76 void *notify_data, | 86 void *notify_data, |
| 77 void* stream); | 87 void* stream); |
| 78 | 88 |
| 79 virtual void URLRequestRouted(const std::string&url, bool notify_needed, | 89 virtual void URLRequestRouted(const std::string&url, bool notify_needed, |
| 80 void* notify_data); | 90 void* notify_data); |
| 81 bool windowless() const { return windowless_ ; } | 91 bool windowless() const { return windowless_ ; } |
| 82 gfx::Rect rect() const { return window_rect_; } | 92 gfx::Rect rect() const { return window_rect_; } |
| 83 gfx::Rect clip_rect() const { return clip_rect_; } | 93 gfx::Rect clip_rect() const { return clip_rect_; } |
| 84 | 94 |
| 95 #if defined(OS_WIN) |
| 85 enum PluginQuirks { | 96 enum PluginQuirks { |
| 86 PLUGIN_QUIRK_SETWINDOW_TWICE = 1, | 97 PLUGIN_QUIRK_SETWINDOW_TWICE = 1, |
| 87 PLUGIN_QUIRK_THROTTLE_WM_USER_PLUS_ONE = 2, | 98 PLUGIN_QUIRK_THROTTLE_WM_USER_PLUS_ONE = 2, |
| 88 PLUGIN_QUIRK_DONT_CALL_WND_PROC_RECURSIVELY = 4, | 99 PLUGIN_QUIRK_DONT_CALL_WND_PROC_RECURSIVELY = 4, |
| 89 PLUGIN_QUIRK_DONT_SET_NULL_WINDOW_HANDLE_ON_DESTROY = 8, | 100 PLUGIN_QUIRK_DONT_SET_NULL_WINDOW_HANDLE_ON_DESTROY = 8, |
| 90 PLUGIN_QUIRK_DONT_ALLOW_MULTIPLE_INSTANCES = 16, | 101 PLUGIN_QUIRK_DONT_ALLOW_MULTIPLE_INSTANCES = 16, |
| 91 PLUGIN_QUIRK_DIE_AFTER_UNLOAD = 32, | 102 PLUGIN_QUIRK_DIE_AFTER_UNLOAD = 32, |
| 92 PLUGIN_QUIRK_PATCH_TRACKPOPUP_MENU = 64, | 103 PLUGIN_QUIRK_PATCH_TRACKPOPUP_MENU = 64, |
| 93 PLUGIN_QUIRK_PATCH_SETCURSOR = 128, | 104 PLUGIN_QUIRK_PATCH_SETCURSOR = 128, |
| 94 PLUGIN_QUIRK_BLOCK_NONSTANDARD_GETURL_REQUESTS = 256, | 105 PLUGIN_QUIRK_BLOCK_NONSTANDARD_GETURL_REQUESTS = 256, |
| 95 }; | 106 }; |
| 107 #endif |
| 96 | 108 |
| 97 int quirks() { return quirks_; } | 109 int quirks() { return quirks_; } |
| 98 | 110 |
| 99 private: | 111 private: |
| 100 WebPluginDelegateImpl(gfx::NativeView containing_view, | 112 WebPluginDelegateImpl(gfx::NativeView containing_view, |
| 101 NPAPI::PluginInstance *instance); | 113 NPAPI::PluginInstance *instance); |
| 102 ~WebPluginDelegateImpl(); | 114 ~WebPluginDelegateImpl(); |
| 103 | 115 |
| 104 //-------------------------- | 116 //-------------------------- |
| 105 // used for windowed plugins | 117 // used for windowed plugins |
| 106 void WindowedUpdateGeometry(const gfx::Rect& window_rect, | 118 void WindowedUpdateGeometry(const gfx::Rect& window_rect, |
| 107 const gfx::Rect& clip_rect); | 119 const gfx::Rect& clip_rect); |
| 108 // Create the native window. | 120 // Create the native window. |
| 109 // Returns true if the window is created (or already exists). | 121 // Returns true if the window is created (or already exists). |
| 110 // Returns false if unable to create the window. | 122 // Returns false if unable to create the window. |
| 111 bool WindowedCreatePlugin(); | 123 bool WindowedCreatePlugin(); |
| 112 | 124 |
| 113 // Destroy the native window. | 125 // Destroy the native window. |
| 114 void WindowedDestroyWindow(); | 126 void WindowedDestroyWindow(); |
| 115 | 127 |
| 116 // Reposition the native window to be in sync with the given geometry. | 128 // Reposition the native window to be in sync with the given geometry. |
| 117 // Returns true if the native window has moved or been clipped differently. | 129 // Returns true if the native window has moved or been clipped differently. |
| 118 bool WindowedReposition(const gfx::Rect& window_rect, | 130 bool WindowedReposition(const gfx::Rect& window_rect, |
| 119 const gfx::Rect& clip_rect); | 131 const gfx::Rect& clip_rect); |
| 120 | 132 |
| 121 // Tells the plugin about the current state of the window. | 133 // Tells the plugin about the current state of the window. |
| 122 // See NPAPI NPP_SetWindow for more information. | 134 // See NPAPI NPP_SetWindow for more information. |
| 123 void WindowedSetWindow(); | 135 void WindowedSetWindow(); |
| 124 | 136 |
| 137 #if defined(OS_WIN) |
| 125 // Registers the window class for our window | 138 // Registers the window class for our window |
| 126 ATOM RegisterNativeWindowClass(); | 139 ATOM RegisterNativeWindowClass(); |
| 127 | 140 |
| 128 // Our WndProc functions. | 141 // Our WndProc functions. |
| 129 static LRESULT CALLBACK DummyWindowProc( | 142 static LRESULT CALLBACK DummyWindowProc( |
| 130 HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); | 143 HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); |
| 131 static LRESULT CALLBACK NativeWndProc( | 144 static LRESULT CALLBACK NativeWndProc( |
| 132 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); | 145 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); |
| 133 static LRESULT CALLBACK FlashWindowlessWndProc( | 146 static LRESULT CALLBACK FlashWindowlessWndProc( |
| 134 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); | 147 HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam); |
| 135 | 148 |
| 136 // Used for throttling Flash messages. | 149 // Used for throttling Flash messages. |
| 137 static void ClearThrottleQueueForWindow(HWND window); | 150 static void ClearThrottleQueueForWindow(HWND window); |
| 138 static void OnThrottleMessage(); | 151 static void OnThrottleMessage(); |
| 139 static void ThrottleMessage(WNDPROC proc, HWND hwnd, UINT message, | 152 static void ThrottleMessage(WNDPROC proc, HWND hwnd, UINT message, |
| 140 WPARAM wParam, LPARAM lParam); | 153 WPARAM wParam, LPARAM lParam); |
| 154 #endif |
| 141 | 155 |
| 142 //---------------------------- | 156 //---------------------------- |
| 143 // used for windowless plugins | 157 // used for windowless plugins |
| 144 void WindowlessUpdateGeometry(const gfx::Rect& window_rect, | 158 void WindowlessUpdateGeometry(const gfx::Rect& window_rect, |
| 145 const gfx::Rect& clip_rect); | 159 const gfx::Rect& clip_rect); |
| 160 #if defined(OS_WIN) |
| 146 void WindowlessPaint(HDC hdc, const gfx::Rect& rect); | 161 void WindowlessPaint(HDC hdc, const gfx::Rect& rect); |
| 162 #else |
| 163 // TODO(port): implement. |
| 164 void WindowlessPaint(void* dc, const gfx::Rect& rect); |
| 165 #endif |
| 147 | 166 |
| 148 // Tells the plugin about the current state of the window. | 167 // Tells the plugin about the current state of the window. |
| 149 // See NPAPI NPP_SetWindow for more information. | 168 // See NPAPI NPP_SetWindow for more information. |
| 150 void WindowlessSetWindow(bool force_set_window); | 169 void WindowlessSetWindow(bool force_set_window); |
| 151 | 170 |
| 152 | 171 |
| 153 //----------------------------------------- | 172 //----------------------------------------- |
| 154 // used for windowed and windowless plugins | 173 // used for windowed and windowless plugins |
| 155 | 174 |
| 156 NPAPI::PluginInstance* instance() { return instance_.get(); } | 175 NPAPI::PluginInstance* instance() { return instance_.get(); } |
| 157 | 176 |
| 158 // Closes down and destroys our plugin instance. | 177 // Closes down and destroys our plugin instance. |
| 159 void DestroyInstance(); | 178 void DestroyInstance(); |
| 160 | 179 |
| 161 // used for windowed plugins | 180 // used for windowed plugins |
| 162 HWND windowed_handle_; | 181 gfx::NativeView windowed_handle_; |
| 182 #if defined(OS_WIN) |
| 163 bool windowed_did_set_window_; | 183 bool windowed_did_set_window_; |
| 164 gfx::Rect windowed_last_pos_; | 184 gfx::Rect windowed_last_pos_; |
| 185 #endif |
| 165 | 186 |
| 187 #if defined(OS_WIN) |
| 166 // this is an optimization to avoid calling SetWindow to the plugin | 188 // this is an optimization to avoid calling SetWindow to the plugin |
| 167 // when it is not necessary. Initially, we need to call SetWindow, | 189 // when it is not necessary. Initially, we need to call SetWindow, |
| 168 // and after that we only need to call it when the geometry changes. | 190 // and after that we only need to call it when the geometry changes. |
| 169 // use this flag to indicate whether we really need it or not. | 191 // use this flag to indicate whether we really need it or not. |
| 170 bool windowless_needs_set_window_; | 192 bool windowless_needs_set_window_; |
| 193 #endif |
| 171 | 194 |
| 172 // used by windowed and windowless plugins | 195 // used by windowed and windowless plugins |
| 173 bool windowless_; | 196 bool windowless_; |
| 174 | 197 |
| 175 WebPlugin* plugin_; | 198 WebPlugin* plugin_; |
| 176 scoped_refptr<NPAPI::PluginInstance> instance_; | 199 scoped_refptr<NPAPI::PluginInstance> instance_; |
| 177 | 200 |
| 201 #if defined(OS_WIN) |
| 178 // Original wndproc before we subclassed. | 202 // Original wndproc before we subclassed. |
| 179 WNDPROC plugin_wnd_proc_; | 203 WNDPROC plugin_wnd_proc_; |
| 180 | 204 |
| 181 // Used to throttle WM_USER+1 messages in Flash. | 205 // Used to throttle WM_USER+1 messages in Flash. |
| 182 uint32 last_message_; | 206 uint32 last_message_; |
| 183 bool is_calling_wndproc; | 207 bool is_calling_wndproc; |
| 208 #endif // OS_WIN |
| 184 | 209 |
| 185 HWND parent_; | 210 gfx::NativeView parent_; |
| 186 NPWindow window_; | 211 NPWindow window_; |
| 187 gfx::Rect window_rect_; | 212 gfx::Rect window_rect_; |
| 188 gfx::Rect clip_rect_; | 213 gfx::Rect clip_rect_; |
| 189 std::vector<gfx::Rect> cutout_rects_; | 214 std::vector<gfx::Rect> cutout_rects_; |
| 190 int quirks_; | 215 int quirks_; |
| 191 | 216 |
| 217 #if defined(OS_WIN) |
| 192 // Windowless plugins don't have keyboard focus causing issues with the | 218 // Windowless plugins don't have keyboard focus causing issues with the |
| 193 // plugin not receiving keyboard events if the plugin enters a modal | 219 // plugin not receiving keyboard events if the plugin enters a modal |
| 194 // loop like TrackPopupMenuEx or MessageBox, etc. | 220 // loop like TrackPopupMenuEx or MessageBox, etc. |
| 195 // This is a basic issue with windows activation and focus arising due to | 221 // This is a basic issue with windows activation and focus arising due to |
| 196 // the fact that these windows are created by different threads. Activation | 222 // the fact that these windows are created by different threads. Activation |
| 197 // and focus are thread specific states, and if the browser has focus, | 223 // and focus are thread specific states, and if the browser has focus, |
| 198 // the plugin may not have focus. | 224 // the plugin may not have focus. |
| 199 // To fix a majority of these activation issues we create a dummy visible | 225 // To fix a majority of these activation issues we create a dummy visible |
| 200 // child window to which we set focus whenever the windowless plugin | 226 // child window to which we set focus whenever the windowless plugin |
| 201 // receives a WM_LBUTTONDOWN/WM_RBUTTONDOWN message via NPP_HandleEvent. | 227 // receives a WM_LBUTTONDOWN/WM_RBUTTONDOWN message via NPP_HandleEvent. |
| 202 HWND dummy_window_for_activation_; | 228 HWND dummy_window_for_activation_; |
| 203 bool CreateDummyWindowForActivation(); | 229 bool CreateDummyWindowForActivation(); |
| 204 | 230 |
| 205 // Returns true if the event passed in needs to be tracked for a potential | 231 // Returns true if the event passed in needs to be tracked for a potential |
| 206 // modal loop. | 232 // modal loop. |
| 207 static bool ShouldTrackEventForModalLoops(NPEvent* event); | 233 static bool ShouldTrackEventForModalLoops(NPEvent* event); |
| 208 | 234 |
| 209 // The message filter hook procedure, which tracks modal loops entered by | 235 // The message filter hook procedure, which tracks modal loops entered by |
| 210 // a plugin in the course of a NPP_HandleEvent call. | 236 // a plugin in the course of a NPP_HandleEvent call. |
| 211 static LRESULT CALLBACK HandleEventMessageFilterHook(int code, WPARAM wParam, | 237 static LRESULT CALLBACK HandleEventMessageFilterHook(int code, WPARAM wParam, |
| 212 LPARAM lParam); | 238 LPARAM lParam); |
| 213 | 239 #endif |
| 214 // Called by the message filter hook when the plugin enters a modal loop. | 240 // Called by the message filter hook when the plugin enters a modal loop. |
| 215 void OnModalLoopEntered(); | 241 void OnModalLoopEntered(); |
| 216 | 242 |
| 217 // Returns true if the message passed in corresponds to a user gesture. | 243 // Returns true if the message passed in corresponds to a user gesture. |
| 218 static bool IsUserGestureMessage(unsigned int message); | 244 static bool IsUserGestureMessage(unsigned int message); |
| 219 | 245 |
| 220 // Indicates the end of a user gesture period. | 246 // Indicates the end of a user gesture period. |
| 221 void OnUserGestureEnd(); | 247 void OnUserGestureEnd(); |
| 222 | 248 |
| 249 // The url with which the plugin was instantiated. |
| 250 std::string plugin_url_; |
| 251 |
| 252 #if defined(OS_WIN) |
| 223 // Handle to the message filter hook | 253 // Handle to the message filter hook |
| 224 HHOOK handle_event_message_filter_hook_; | 254 HHOOK handle_event_message_filter_hook_; |
| 225 | 255 |
| 226 // Event which is set when the plugin enters a modal loop in the course | 256 // Event which is set when the plugin enters a modal loop in the course |
| 227 // of a NPP_HandleEvent call. | 257 // of a NPP_HandleEvent call. |
| 228 HANDLE handle_event_pump_messages_event_; | 258 HANDLE handle_event_pump_messages_event_; |
| 229 | 259 |
| 230 // Holds the depth of the HandleEvent callstack. | 260 // Holds the depth of the HandleEvent callstack. |
| 231 int handle_event_depth_; | 261 int handle_event_depth_; |
| 232 | 262 |
| 233 // This flag indicates whether we started tracking a user gesture message. | 263 // This flag indicates whether we started tracking a user gesture message. |
| 234 bool user_gesture_message_posted_; | 264 bool user_gesture_message_posted_; |
| 235 | 265 |
| 236 // Runnable Method Factory used to invoke the OnUserGestureEnd method | 266 // Runnable Method Factory used to invoke the OnUserGestureEnd method |
| 237 // asynchronously. | 267 // asynchronously. |
| 238 ScopedRunnableMethodFactory<WebPluginDelegateImpl> user_gesture_msg_factory_; | 268 ScopedRunnableMethodFactory<WebPluginDelegateImpl> user_gesture_msg_factory_; |
| 239 | 269 |
| 240 // The url with which the plugin was instantiated. | |
| 241 std::string plugin_url_; | |
| 242 | |
| 243 // The plugin module handle. | 270 // The plugin module handle. |
| 244 HMODULE plugin_module_handle_; | 271 HMODULE plugin_module_handle_; |
| 245 | 272 |
| 246 // TrackPopupMenu interceptor. Parameters are the same as the Win32 function | 273 // TrackPopupMenu interceptor. Parameters are the same as the Win32 function |
| 247 // TrackPopupMenu. | 274 // TrackPopupMenu. |
| 248 static BOOL WINAPI TrackPopupMenuPatch(HMENU menu, unsigned int flags, int x, | 275 static BOOL WINAPI TrackPopupMenuPatch(HMENU menu, unsigned int flags, int x, |
| 249 int y, int reserved, HWND window, | 276 int y, int reserved, HWND window, |
| 250 const RECT* rect); | 277 const RECT* rect); |
| 251 | 278 |
| 252 // SetCursor interceptor for windowless plugins. | 279 // SetCursor interceptor for windowless plugins. |
| 253 static HCURSOR WINAPI SetCursorPatch(HCURSOR cursor); | 280 static HCURSOR WINAPI SetCursorPatch(HCURSOR cursor); |
| 254 | 281 |
| 255 // Holds the current cursor set by the windowless plugin. | 282 // Holds the current cursor set by the windowless plugin. |
| 256 WebCursor current_windowless_cursor_; | 283 WebCursor current_windowless_cursor_; |
| 284 #endif |
| 257 | 285 |
| 258 DISALLOW_EVIL_CONSTRUCTORS(WebPluginDelegateImpl); | 286 DISALLOW_EVIL_CONSTRUCTORS(WebPluginDelegateImpl); |
| 259 }; | 287 }; |
| 260 | 288 |
| 261 #endif // #ifndef WEBKIT_GLUE_PLUGIN_WEBPLUGIN_DELEGATE_IMPL_H__ | 289 #endif // #ifndef WEBKIT_GLUE_PLUGIN_WEBPLUGIN_DELEGATE_IMPL_H__ |
| 262 | 290 |
| OLD | NEW |