OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef WEBKIT_GLUE_WEBPLUGIN_IMPL_H_ | |
6 #define WEBKIT_GLUE_WEBPLUGIN_IMPL_H_ | |
7 | |
8 #include <string> | |
9 #include <map> | |
10 #include <vector> | |
11 | |
12 #include "base/basictypes.h" | |
13 #include "base/file_path.h" | |
14 #include "base/task.h" | |
15 #include "base/weak_ptr.h" | |
16 #include "gfx/native_widget_types.h" | |
17 #include "googleurl/src/gurl.h" | |
18 #include "third_party/WebKit/WebKit/chromium/public/WebPlugin.h" | |
19 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" | |
20 #include "third_party/WebKit/WebKit/chromium/public/WebString.h" | |
21 #include "third_party/WebKit/WebKit/chromium/public/WebURLLoaderClient.h" | |
22 #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" | |
23 #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" | |
24 #include "webkit/glue/plugins/webplugin.h" | |
25 | |
26 class WebViewDelegate; | |
27 | |
28 namespace WebKit { | |
29 class WebDevToolsAgent; | |
30 class WebFrame; | |
31 class WebPluginContainer; | |
32 class WebURLResponse; | |
33 class WebURLLoader; | |
34 class WebURLRequest; | |
35 } | |
36 | |
37 namespace webkit_glue { | |
38 | |
39 class MultipartResponseDelegate; | |
40 class WebPluginDelegate; | |
41 class WebPluginPageDelegate; | |
42 | |
43 // This is the WebKit side of the plugin implementation that forwards calls, | |
44 // after changing out of WebCore types, to a delegate. The delegate may | |
45 // be in a different process. | |
46 class WebPluginImpl : public WebPlugin, | |
47 public WebKit::WebPlugin, | |
48 public WebKit::WebURLLoaderClient { | |
49 public: | |
50 WebPluginImpl( | |
51 WebKit::WebFrame* frame, | |
52 const WebKit::WebPluginParams& params, | |
53 const FilePath& file_path, | |
54 const std::string& mime_type, | |
55 const base::WeakPtr<WebPluginPageDelegate>& page_delegate); | |
56 virtual ~WebPluginImpl(); | |
57 | |
58 // Helper function for sorting post data. | |
59 static bool SetPostData(WebKit::WebURLRequest* request, | |
60 const char* buf, | |
61 uint32 length); | |
62 | |
63 virtual WebPluginDelegate* delegate(); | |
64 | |
65 private: | |
66 // WebKit::WebPlugin methods: | |
67 virtual bool initialize( | |
68 WebKit::WebPluginContainer* container); | |
69 virtual void destroy(); | |
70 virtual NPObject* scriptableObject(); | |
71 virtual void paint( | |
72 WebKit::WebCanvas* canvas, const WebKit::WebRect& paint_rect); | |
73 virtual void updateGeometry( | |
74 const WebKit::WebRect& frame_rect, const WebKit::WebRect& clip_rect, | |
75 const WebKit::WebVector<WebKit::WebRect>& cut_outs, bool is_visible); | |
76 virtual unsigned getBackingTextureId(); | |
77 virtual void updateFocus(bool focused); | |
78 virtual void updateVisibility(bool visible); | |
79 virtual bool acceptsInputEvents(); | |
80 virtual bool handleInputEvent( | |
81 const WebKit::WebInputEvent& event, WebKit::WebCursorInfo& cursor_info); | |
82 virtual void didReceiveResponse(const WebKit::WebURLResponse& response); | |
83 virtual void didReceiveData(const char* data, int data_length); | |
84 virtual void didFinishLoading(); | |
85 virtual void didFailLoading(const WebKit::WebURLError& error); | |
86 virtual void didFinishLoadingFrameRequest( | |
87 const WebKit::WebURL& url, void* notify_data); | |
88 virtual void didFailLoadingFrameRequest( | |
89 const WebKit::WebURL& url, void* notify_data, | |
90 const WebKit::WebURLError& error); | |
91 virtual bool supportsPaginatedPrint(); | |
92 virtual int printBegin(const WebKit::WebRect& printable_area, | |
93 int printer_dpi); | |
94 virtual bool printPage(int page_number, WebKit::WebCanvas* canvas); | |
95 virtual void printEnd(); | |
96 virtual bool hasSelection() const; | |
97 virtual WebKit::WebString selectionAsText() const; | |
98 virtual WebKit::WebString selectionAsMarkup() const; | |
99 virtual void setZoomFactor(float scale, bool text_only); | |
100 virtual bool startFind(const WebKit::WebString& search_text, | |
101 bool case_sensitive, | |
102 int identifier); | |
103 virtual void selectFindResult(bool forward); | |
104 virtual void stopFind(); | |
105 | |
106 // WebPlugin implementation: | |
107 virtual void SetWindow(gfx::PluginWindowHandle window); | |
108 virtual void SetAcceptsInputEvents(bool accepts); | |
109 virtual void WillDestroyWindow(gfx::PluginWindowHandle window); | |
110 #if defined(OS_WIN) | |
111 void SetWindowlessPumpEvent(HANDLE pump_messages_event) { } | |
112 #endif | |
113 virtual void CancelResource(unsigned long id); | |
114 virtual void Invalidate(); | |
115 virtual void InvalidateRect(const gfx::Rect& rect); | |
116 virtual NPObject* GetWindowScriptNPObject(); | |
117 virtual NPObject* GetPluginElement(); | |
118 virtual void SetCookie(const GURL& url, | |
119 const GURL& first_party_for_cookies, | |
120 const std::string& cookie); | |
121 virtual std::string GetCookies(const GURL& url, | |
122 const GURL& first_party_for_cookies); | |
123 virtual void ShowModalHTMLDialog(const GURL& url, int width, int height, | |
124 const std::string& json_arguments, | |
125 std::string* json_retval); | |
126 virtual void OnMissingPluginStatus(int status); | |
127 | |
128 virtual void URLRedirectResponse(bool allow, int resource_id); | |
129 | |
130 // Given a (maybe partial) url, completes using the base url. | |
131 GURL CompleteURL(const char* url); | |
132 | |
133 // Executes the script passed in. The notify_needed and notify_data arguments | |
134 // are passed in by the plugin process. These indicate whether the plugin | |
135 // expects a notification on script execution. We pass them back to the | |
136 // plugin as is. This avoids having to track the notification arguments in | |
137 // the plugin process. | |
138 bool ExecuteScript(const std::string& url, const std::wstring& script, | |
139 bool notify_needed, intptr_t notify_data, | |
140 bool popups_allowed); | |
141 | |
142 enum RoutingStatus { | |
143 ROUTED, | |
144 NOT_ROUTED, | |
145 INVALID_URL, | |
146 GENERAL_FAILURE | |
147 }; | |
148 | |
149 // Determines the referrer value sent along with outgoing HTTP requests | |
150 // issued by plugins. | |
151 enum Referrer { | |
152 PLUGIN_SRC, | |
153 DOCUMENT_URL, | |
154 NO_REFERRER | |
155 }; | |
156 | |
157 // Given a download request, check if we need to route the output to a frame. | |
158 // Returns ROUTED if the load is done and routed to a frame, NOT_ROUTED or | |
159 // corresponding error codes otherwise. | |
160 RoutingStatus RouteToFrame(const char* url, | |
161 bool is_javascript_url, | |
162 const char* method, | |
163 const char* target, | |
164 const char* buf, | |
165 unsigned int len, | |
166 int notify_id, | |
167 Referrer referrer_flag); | |
168 | |
169 // Returns the next avaiable resource id. Returns 0 if the operation fails. | |
170 // It may fail if the page has already been closed. | |
171 unsigned long GetNextResourceId(); | |
172 | |
173 // Initiates HTTP GET/POST requests. | |
174 // Returns true on success. | |
175 bool InitiateHTTPRequest(unsigned long resource_id, | |
176 WebPluginResourceClient* client, | |
177 const GURL& url, | |
178 const char* method, | |
179 const char* buf, | |
180 int len, | |
181 const char* range_info, | |
182 Referrer referrer_flag, | |
183 bool notify_redirects); | |
184 | |
185 gfx::Rect GetWindowClipRect(const gfx::Rect& rect); | |
186 | |
187 // Sets the actual Widget for the plugin. | |
188 void SetContainer(WebKit::WebPluginContainer* container); | |
189 | |
190 // Destroys the plugin instance. | |
191 // The response_handle_to_ignore parameter if not NULL indicates the | |
192 // resource handle to be left valid during plugin shutdown. | |
193 void TearDownPluginInstance(WebKit::WebURLLoader* loader_to_ignore); | |
194 | |
195 // WebURLLoaderClient implementation. We implement this interface in the | |
196 // renderer process, and then use the simple WebPluginResourceClient interface | |
197 // to relay the callbacks to the plugin. | |
198 virtual void willSendRequest(WebKit::WebURLLoader* loader, | |
199 WebKit::WebURLRequest& request, | |
200 const WebKit::WebURLResponse& response); | |
201 virtual void didSendData(WebKit::WebURLLoader* loader, | |
202 unsigned long long bytes_sent, | |
203 unsigned long long total_bytes_to_be_sent); | |
204 virtual void didReceiveResponse(WebKit::WebURLLoader* loader, | |
205 const WebKit::WebURLResponse& response); | |
206 virtual void didReceiveData(WebKit::WebURLLoader* loader, const char *buffer, | |
207 int length); | |
208 virtual void didFinishLoading(WebKit::WebURLLoader* loader, | |
209 double finishTime); | |
210 virtual void didFail(WebKit::WebURLLoader* loader, | |
211 const WebKit::WebURLError& error); | |
212 | |
213 // Helper function to remove the stored information about a resource | |
214 // request given its index in m_clients. | |
215 void RemoveClient(size_t i); | |
216 | |
217 // Helper function to remove the stored information about a resource | |
218 // request given a handle. | |
219 void RemoveClient(WebKit::WebURLLoader* loader); | |
220 | |
221 virtual void HandleURLRequest(const char* url, | |
222 const char *method, | |
223 const char* target, | |
224 const char* buf, | |
225 unsigned int len, | |
226 int notify_id, | |
227 bool popups_allowed, | |
228 bool notify_redirects); | |
229 | |
230 virtual void CancelDocumentLoad(); | |
231 | |
232 virtual void InitiateHTTPRangeRequest( | |
233 const char* url, const char* range_info, int pending_request_id); | |
234 | |
235 virtual void SetDeferResourceLoading(unsigned long resource_id, bool defer); | |
236 | |
237 // Ignore in-process plugins mode for this flag. | |
238 virtual bool IsOffTheRecord(); | |
239 | |
240 // Handles HTTP multipart responses, i.e. responses received with a HTTP | |
241 // status code of 206. | |
242 void HandleHttpMultipartResponse(const WebKit::WebURLResponse& response, | |
243 WebPluginResourceClient* client); | |
244 | |
245 void HandleURLRequestInternal(const char* url, | |
246 const char* method, | |
247 const char* target, | |
248 const char* buf, | |
249 unsigned int len, | |
250 int notify_id, | |
251 bool popups_allowed, | |
252 Referrer referrer_flag, | |
253 bool notify_redirects); | |
254 | |
255 // Tears down the existing plugin instance and creates a new plugin instance | |
256 // to handle the response identified by the loader parameter. | |
257 bool ReinitializePluginForResponse(WebKit::WebURLLoader* loader); | |
258 | |
259 // Delayed task for downloading the plugin source URL. | |
260 void OnDownloadPluginSrcUrl(); | |
261 | |
262 struct ClientInfo; | |
263 | |
264 // Helper functions | |
265 WebPluginResourceClient* GetClientFromLoader(WebKit::WebURLLoader* loader); | |
266 ClientInfo* GetClientInfoFromLoader(WebKit::WebURLLoader* loader); | |
267 | |
268 // Helper function to set the referrer on the request passed in. | |
269 void SetReferrer(WebKit::WebURLRequest* request, Referrer referrer_flag); | |
270 | |
271 // Returns DevToolsAgent for the frame or 0. | |
272 WebKit::WebDevToolsAgent* GetDevToolsAgent(); | |
273 | |
274 // Check for invalid chars like @, ;, \ before the first / (in path). | |
275 bool IsValidUrl(const GURL& url, Referrer referrer_flag); | |
276 | |
277 std::vector<ClientInfo> clients_; | |
278 | |
279 bool windowless_; | |
280 gfx::PluginWindowHandle window_; | |
281 bool accepts_input_events_; | |
282 base::WeakPtr<WebPluginPageDelegate> page_delegate_; | |
283 WebKit::WebFrame* webframe_; | |
284 | |
285 WebPluginDelegate* delegate_; | |
286 | |
287 // This is just a weak reference. | |
288 WebKit::WebPluginContainer* container_; | |
289 | |
290 typedef std::map<WebPluginResourceClient*, | |
291 webkit_glue::MultipartResponseDelegate*> | |
292 MultiPartResponseHandlerMap; | |
293 // Tracks HTTP multipart response handlers instantiated for | |
294 // a WebPluginResourceClient instance. | |
295 MultiPartResponseHandlerMap multi_part_response_map_; | |
296 | |
297 // The plugin source URL. | |
298 GURL plugin_url_; | |
299 | |
300 // Indicates if the download would be initiated by the plugin or us. | |
301 bool load_manually_; | |
302 | |
303 // Indicates if this is the first geometry update received by the plugin. | |
304 bool first_geometry_update_; | |
305 | |
306 // Set to true if the next response error should be ignored. | |
307 bool ignore_response_error_; | |
308 | |
309 // The current plugin geometry and clip rectangle. | |
310 WebPluginGeometry geometry_; | |
311 | |
312 // The location of the plugin on disk. | |
313 FilePath file_path_; | |
314 | |
315 // The mime type of the plugin. | |
316 std::string mime_type_; | |
317 | |
318 // Holds the list of argument names and values passed to the plugin. We keep | |
319 // these so that we can re-initialize the plugin if we need to. | |
320 std::vector<std::string> arg_names_; | |
321 std::vector<std::string> arg_values_; | |
322 | |
323 ScopedRunnableMethodFactory<WebPluginImpl> method_factory_; | |
324 | |
325 DISALLOW_COPY_AND_ASSIGN(WebPluginImpl); | |
326 }; | |
327 | |
328 } // namespace webkit_glue | |
329 | |
330 #endif // #ifndef WEBKIT_GLUE_WEBPLUGIN_IMPL_H_ | |
OLD | NEW |