| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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_WEBPLUGIN_IMPL_H_ | 5 #ifndef WEBKIT_GLUE_WEBPLUGIN_IMPL_H_ |
| 6 #define WEBKIT_GLUE_WEBPLUGIN_IMPL_H_ | 6 #define WEBKIT_GLUE_WEBPLUGIN_IMPL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "Widget.h" | |
| 13 | |
| 14 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 15 #include "base/gfx/native_widget_types.h" | 13 #include "base/gfx/native_widget_types.h" |
| 16 #include "base/linked_ptr.h" | 14 #include "base/linked_ptr.h" |
| 15 #include "base/task.h" |
| 16 #include "base/weak_ptr.h" |
| 17 #include "googleurl/src/gurl.h" |
| 17 #include "webkit/api/public/WebPlugin.h" | 18 #include "webkit/api/public/WebPlugin.h" |
| 19 #include "webkit/api/public/WebString.h" |
| 18 #include "webkit/api/public/WebURLLoaderClient.h" | 20 #include "webkit/api/public/WebURLLoaderClient.h" |
| 19 #include "webkit/api/public/WebURLRequest.h" | 21 #include "webkit/api/public/WebURLRequest.h" |
| 20 #include "webkit/glue/webframe_impl.h" | 22 #include "webkit/api/public/WebVector.h" |
| 21 #include "webkit/glue/webplugin.h" | 23 #include "webkit/glue/webplugin.h" |
| 22 | 24 |
| 23 | 25 class WebViewDelegate; |
| 24 class WebFrameImpl; | |
| 25 class WebPluginDelegate; | |
| 26 | |
| 27 namespace WebCore { | |
| 28 class Event; | |
| 29 class Frame; | |
| 30 class HTMLPlugInElement; | |
| 31 class IntRect; | |
| 32 class KeyboardEvent; | |
| 33 class KURL; | |
| 34 class MouseEvent; | |
| 35 class ResourceError; | |
| 36 class ResourceResponse; | |
| 37 class ScrollView; | |
| 38 class String; | |
| 39 class Widget; | |
| 40 } | |
| 41 | 26 |
| 42 namespace WebKit { | 27 namespace WebKit { |
| 28 class WebFrame; |
| 43 class WebPluginContainer; | 29 class WebPluginContainer; |
| 44 class WebURLResponse; | 30 class WebURLResponse; |
| 45 class WebURLLoader; | 31 class WebURLLoader; |
| 46 } | 32 } |
| 47 | 33 |
| 48 namespace webkit_glue { | 34 namespace webkit_glue { |
| 35 |
| 49 class MultipartResponseDelegate; | 36 class MultipartResponseDelegate; |
| 50 } | 37 class WebPluginDelegate; |
| 38 class WebPluginPageDelegate; |
| 51 | 39 |
| 52 // This is the WebKit side of the plugin implementation that forwards calls, | 40 // This is the WebKit side of the plugin implementation that forwards calls, |
| 53 // after changing out of WebCore types, to a delegate. The delegate may | 41 // after changing out of WebCore types, to a delegate. The delegate may |
| 54 // be in a different process. | 42 // be in a different process. |
| 55 class WebPluginImpl : public WebPlugin, | 43 class WebPluginImpl : public WebPlugin, |
| 56 public WebKit::WebPlugin, | 44 public WebKit::WebPlugin, |
| 57 public WebKit::WebURLLoaderClient { | 45 public WebKit::WebURLLoaderClient { |
| 58 public: | 46 public: |
| 59 // Creates a WebPlugin instance, as long as the delegate's initialization | 47 WebPluginImpl( |
| 60 // succeeds. If it fails, the delegate is deleted and NULL is returned. | 48 WebKit::WebFrame* frame, |
| 61 // Note that argn and argv are UTF8. | 49 const WebKit::WebPluginParams& params, |
| 62 static PassRefPtr<WebCore::Widget> Create(const GURL& url, | 50 const base::WeakPtr<WebPluginPageDelegate>& page_delegate); |
| 63 char** argn, | 51 ~WebPluginImpl(); |
| 64 char** argv, | |
| 65 int argc, | |
| 66 WebCore::HTMLPlugInElement* element, | |
| 67 WebFrameImpl* frame, | |
| 68 WebPluginDelegate* delegate, | |
| 69 bool load_manually, | |
| 70 const std::string& mime_type); | |
| 71 virtual ~WebPluginImpl(); | |
| 72 | 52 |
| 73 // Helper function for sorting post data. | 53 // Helper function for sorting post data. |
| 74 static bool SetPostData(WebKit::WebURLRequest* request, | 54 static bool SetPostData(WebKit::WebURLRequest* request, |
| 75 const char* buf, | 55 const char* buf, |
| 76 uint32 length); | 56 uint32 length); |
| 77 | 57 |
| 78 private: | 58 private: |
| 79 WebPluginImpl( | |
| 80 WebFrameImpl* frame, WebPluginDelegate* delegate, const GURL& plugin_url, | |
| 81 bool load_manually, const std::string& mime_type, int arg_count, | |
| 82 char** arg_names, char** arg_values); | |
| 83 | |
| 84 // WebKit::WebPlugin methods: | 59 // WebKit::WebPlugin methods: |
| 60 virtual bool initialize( |
| 61 WebKit::WebPluginContainer* container); |
| 85 virtual void destroy(); | 62 virtual void destroy(); |
| 86 virtual NPObject* scriptableObject(); | 63 virtual NPObject* scriptableObject(); |
| 87 virtual void paint( | 64 virtual void paint( |
| 88 WebKit::WebCanvas* canvas, const WebKit::WebRect& paint_rect); | 65 WebKit::WebCanvas* canvas, const WebKit::WebRect& paint_rect); |
| 89 virtual void updateGeometry( | 66 virtual void updateGeometry( |
| 90 const WebKit::WebRect& frame_rect, const WebKit::WebRect& clip_rect, | 67 const WebKit::WebRect& frame_rect, const WebKit::WebRect& clip_rect, |
| 91 const WebKit::WebVector<WebKit::WebRect>& cut_outs, bool is_visible); | 68 const WebKit::WebVector<WebKit::WebRect>& cut_outs, bool is_visible); |
| 92 virtual void updateFocus(bool focused); | 69 virtual void updateFocus(bool focused); |
| 93 virtual void updateVisibility(bool visible); | 70 virtual void updateVisibility(bool visible); |
| 94 virtual bool acceptsInputEvents(); | 71 virtual bool acceptsInputEvents(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 116 | 93 |
| 117 // Executes the script passed in. The notify_needed and notify_data arguments | 94 // Executes the script passed in. The notify_needed and notify_data arguments |
| 118 // are passed in by the plugin process. These indicate whether the plugin | 95 // are passed in by the plugin process. These indicate whether the plugin |
| 119 // expects a notification on script execution. We pass them back to the | 96 // expects a notification on script execution. We pass them back to the |
| 120 // plugin as is. This avoids having to track the notification arguments in | 97 // plugin as is. This avoids having to track the notification arguments in |
| 121 // the plugin process. | 98 // the plugin process. |
| 122 bool ExecuteScript(const std::string& url, const std::wstring& script, | 99 bool ExecuteScript(const std::string& url, const std::wstring& script, |
| 123 bool notify_needed, intptr_t notify_data, | 100 bool notify_needed, intptr_t notify_data, |
| 124 bool popups_allowed); | 101 bool popups_allowed); |
| 125 | 102 |
| 103 enum RoutingStatus { |
| 104 ROUTED, |
| 105 NOT_ROUTED, |
| 106 INVALID_URL, |
| 107 GENERAL_FAILURE |
| 108 }; |
| 109 |
| 126 // Given a download request, check if we need to route the output to a frame. | 110 // Given a download request, check if we need to route the output to a frame. |
| 127 // Returns ROUTED if the load is done and routed to a frame, NOT_ROUTED or | 111 // Returns ROUTED if the load is done and routed to a frame, NOT_ROUTED or |
| 128 // corresponding error codes otherwise. | 112 // corresponding error codes otherwise. |
| 129 RoutingStatus RouteToFrame(const char* method, bool is_javascript_url, | 113 RoutingStatus RouteToFrame(const char* method, bool is_javascript_url, |
| 130 const char* target, unsigned int len, | 114 const char* target, unsigned int len, |
| 131 const char* buf, bool is_file_data, | 115 const char* buf, bool is_file_data, |
| 132 bool notify_needed, intptr_t notify_data, | 116 bool notify_needed, intptr_t notify_data, |
| 133 const char* url, GURL* completeURL); | 117 const char* url); |
| 134 | 118 |
| 135 // Cancels a pending request. | 119 // Cancels a pending request. |
| 136 void CancelResource(int id); | 120 void CancelResource(int id); |
| 137 | 121 |
| 138 // Returns the next avaiable resource id. | 122 // Returns the next avaiable resource id. |
| 139 int GetNextResourceId(); | 123 int GetNextResourceId(); |
| 140 | 124 |
| 141 // Initiates HTTP GET/POST requests. | 125 // Initiates HTTP GET/POST requests. |
| 142 // Returns true on success. | 126 // Returns true on success. |
| 143 bool InitiateHTTPRequest(int resource_id, WebPluginResourceClient* client, | 127 bool InitiateHTTPRequest(int resource_id, WebPluginResourceClient* client, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 virtual void didFail(WebKit::WebURLLoader* loader, const WebKit::WebURLError&)
; | 172 virtual void didFail(WebKit::WebURLLoader* loader, const WebKit::WebURLError&)
; |
| 189 | 173 |
| 190 // Helper function to remove the stored information about a resource | 174 // Helper function to remove the stored information about a resource |
| 191 // request given its index in m_clients. | 175 // request given its index in m_clients. |
| 192 void RemoveClient(size_t i); | 176 void RemoveClient(size_t i); |
| 193 | 177 |
| 194 // Helper function to remove the stored information about a resource | 178 // Helper function to remove the stored information about a resource |
| 195 // request given a handle. | 179 // request given a handle. |
| 196 void RemoveClient(WebKit::WebURLLoader* loader); | 180 void RemoveClient(WebKit::WebURLLoader* loader); |
| 197 | 181 |
| 198 WebCore::Frame* frame() { return webframe_ ? webframe_->frame() : NULL; } | |
| 199 | |
| 200 void HandleURLRequest(const char *method, | 182 void HandleURLRequest(const char *method, |
| 201 bool is_javascript_url, | 183 bool is_javascript_url, |
| 202 const char* target, unsigned int len, | 184 const char* target, unsigned int len, |
| 203 const char* buf, bool is_file_data, | 185 const char* buf, bool is_file_data, |
| 204 bool notify, const char* url, | 186 bool notify, const char* url, |
| 205 intptr_t notify_data, bool popups_allowed); | 187 intptr_t notify_data, bool popups_allowed); |
| 206 | 188 |
| 207 void CancelDocumentLoad(); | 189 void CancelDocumentLoad(); |
| 208 | 190 |
| 209 void InitiateHTTPRangeRequest(const char* url, const char* range_info, | 191 void InitiateHTTPRangeRequest(const char* url, const char* range_info, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 224 const char* target, unsigned int len, | 206 const char* target, unsigned int len, |
| 225 const char* buf, bool is_file_data, | 207 const char* buf, bool is_file_data, |
| 226 bool notify, const char* url, | 208 bool notify, const char* url, |
| 227 intptr_t notify_data, bool popups_allowed, | 209 intptr_t notify_data, bool popups_allowed, |
| 228 bool use_plugin_src_as_referrer); | 210 bool use_plugin_src_as_referrer); |
| 229 | 211 |
| 230 // Tears down the existing plugin instance and creates a new plugin instance | 212 // Tears down the existing plugin instance and creates a new plugin instance |
| 231 // to handle the response identified by the loader parameter. | 213 // to handle the response identified by the loader parameter. |
| 232 bool ReinitializePluginForResponse(WebKit::WebURLLoader* loader); | 214 bool ReinitializePluginForResponse(WebKit::WebURLLoader* loader); |
| 233 | 215 |
| 234 // Helper functions to convert an array of names/values to a vector. | |
| 235 static void ArrayToVector(int total_values, char** values, | |
| 236 std::vector<std::string>* value_vector); | |
| 237 | |
| 238 // Delayed task for downloading the plugin source URL. | 216 // Delayed task for downloading the plugin source URL. |
| 239 void OnDownloadPluginSrcUrl(); | 217 void OnDownloadPluginSrcUrl(); |
| 240 | 218 |
| 241 // Returns the WebViewDelegate associated with webframe_; | |
| 242 WebViewDelegate* GetWebViewDelegate(); | |
| 243 | |
| 244 struct ClientInfo { | 219 struct ClientInfo { |
| 245 int id; | 220 int id; |
| 246 WebPluginResourceClient* client; | 221 WebPluginResourceClient* client; |
| 247 WebKit::WebURLRequest request; | 222 WebKit::WebURLRequest request; |
| 248 bool pending_failure_notification; | 223 bool pending_failure_notification; |
| 249 linked_ptr<WebKit::WebURLLoader> loader; | 224 linked_ptr<WebKit::WebURLLoader> loader; |
| 250 }; | 225 }; |
| 251 | 226 |
| 252 // Helper functions | 227 // Helper functions |
| 253 WebPluginResourceClient* GetClientFromLoader(WebKit::WebURLLoader* loader); | 228 WebPluginResourceClient* GetClientFromLoader(WebKit::WebURLLoader* loader); |
| 254 ClientInfo* GetClientInfoFromLoader(WebKit::WebURLLoader* loader); | 229 ClientInfo* GetClientInfoFromLoader(WebKit::WebURLLoader* loader); |
| 255 | 230 |
| 256 std::vector<ClientInfo> clients_; | 231 std::vector<ClientInfo> clients_; |
| 257 | 232 |
| 258 bool windowless_; | 233 bool windowless_; |
| 259 gfx::PluginWindowHandle window_; | 234 gfx::PluginWindowHandle window_; |
| 260 WebFrameImpl* webframe_; | 235 base::WeakPtr<WebPluginPageDelegate> page_delegate_; |
| 236 WebKit::WebFrame* webframe_; |
| 261 | 237 |
| 262 WebPluginDelegate* delegate_; | 238 WebPluginDelegate* delegate_; |
| 263 | 239 |
| 264 // This is just a weak reference. | 240 // This is just a weak reference. |
| 265 WebKit::WebPluginContainer* container_; | 241 WebKit::WebPluginContainer* container_; |
| 266 | 242 |
| 267 typedef std::map<WebPluginResourceClient*, | 243 typedef std::map<WebPluginResourceClient*, |
| 268 webkit_glue::MultipartResponseDelegate*> | 244 webkit_glue::MultipartResponseDelegate*> |
| 269 MultiPartResponseHandlerMap; | 245 MultiPartResponseHandlerMap; |
| 270 // Tracks HTTP multipart response handlers instantiated for | 246 // Tracks HTTP multipart response handlers instantiated for |
| (...skipping 12 matching lines...) Expand all Loading... |
| 283 // Set to true if the next response error should be ignored. | 259 // Set to true if the next response error should be ignored. |
| 284 bool ignore_response_error_; | 260 bool ignore_response_error_; |
| 285 | 261 |
| 286 // The current plugin geometry and clip rectangle. | 262 // The current plugin geometry and clip rectangle. |
| 287 gfx::Rect window_rect_; | 263 gfx::Rect window_rect_; |
| 288 gfx::Rect clip_rect_; | 264 gfx::Rect clip_rect_; |
| 289 | 265 |
| 290 // The mime type of the plugin. | 266 // The mime type of the plugin. |
| 291 std::string mime_type_; | 267 std::string mime_type_; |
| 292 | 268 |
| 293 // Holds the list of argument names passed to the plugin. | 269 // Holds the list of argument names and values passed to the plugin. We keep |
| 294 std::vector<std::string> arg_names_; | 270 // these so that we can re-initialize the plugin if we need to. |
| 295 | 271 char** arg_names_; |
| 296 // Holds the list of argument values passed to the plugin. | 272 char** arg_values_; |
| 297 std::vector<std::string> arg_values_; | 273 size_t arg_count_; |
| 298 | 274 |
| 299 ScopedRunnableMethodFactory<WebPluginImpl> method_factory_; | 275 ScopedRunnableMethodFactory<WebPluginImpl> method_factory_; |
| 300 | 276 |
| 301 DISALLOW_COPY_AND_ASSIGN(WebPluginImpl); | 277 DISALLOW_COPY_AND_ASSIGN(WebPluginImpl); |
| 302 }; | 278 }; |
| 303 | 279 |
| 280 } // namespace webkit_glue |
| 281 |
| 304 #endif // #ifndef WEBKIT_GLUE_WEBPLUGIN_IMPL_H_ | 282 #endif // #ifndef WEBKIT_GLUE_WEBPLUGIN_IMPL_H_ |
| OLD | NEW |