Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: webkit/plugins/npapi/webplugin_impl.h

Issue 19761007: Move NPAPI implementation out of webkit/plugins/npapi and into content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix mac Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef WEBKIT_PLUGINS_NPAPI_WEBPLUGIN_IMPL_H_
6 #define WEBKIT_PLUGINS_NPAPI_WEBPLUGIN_IMPL_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "third_party/WebKit/public/platform/WebRect.h"
17 #include "third_party/WebKit/public/platform/WebString.h"
18 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
19 #include "third_party/WebKit/public/platform/WebURLRequest.h"
20 #include "third_party/WebKit/public/platform/WebVector.h"
21 #include "third_party/WebKit/public/web/WebPlugin.h"
22 #include "ui/gfx/native_widget_types.h"
23 #include "url/gurl.h"
24 #include "webkit/plugins/npapi/webplugin.h"
25 #include "webkit/plugins/webkit_plugins_export.h"
26
27 namespace cc {
28 class IOSurfaceLayer;
29 }
30
31 namespace WebKit {
32 class WebFrame;
33 class WebLayer;
34 class WebPluginContainer;
35 class WebURLResponse;
36 class WebURLLoader;
37 class WebURLRequest;
38 }
39
40 namespace webkit_glue {
41 class MultipartResponseDelegate;
42 } // namespace webkit_glue
43
44 namespace webkit {
45 namespace npapi {
46
47 class WebPluginDelegate;
48 class WebPluginPageDelegate;
49
50 // This is the WebKit side of the plugin implementation that forwards calls,
51 // after changing out of WebCore types, to a delegate. The delegate may
52 // be in a different process.
53 class WEBKIT_PLUGINS_EXPORT WebPluginImpl :
54 NON_EXPORTED_BASE(public WebPlugin),
55 NON_EXPORTED_BASE(public WebKit::WebPlugin),
56 NON_EXPORTED_BASE(public WebKit::WebURLLoaderClient) {
57 public:
58 WebPluginImpl(
59 WebKit::WebFrame* frame,
60 const WebKit::WebPluginParams& params,
61 const base::FilePath& file_path,
62 const base::WeakPtr<WebPluginPageDelegate>& page_delegate);
63 virtual ~WebPluginImpl();
64
65 // Helper function for sorting post data.
66 static bool SetPostData(WebKit::WebURLRequest* request,
67 const char* buf,
68 uint32 length);
69
70 virtual WebPluginDelegate* delegate();
71
72 private:
73 // WebKit::WebPlugin methods:
74 virtual bool initialize(
75 WebKit::WebPluginContainer* container);
76 virtual void destroy();
77 virtual NPObject* scriptableObject();
78 virtual struct _NPP* pluginNPP();
79 virtual bool getFormValue(WebKit::WebString& value);
80 virtual void paint(
81 WebKit::WebCanvas* canvas, const WebKit::WebRect& paint_rect);
82 virtual void updateGeometry(
83 const WebKit::WebRect& frame_rect, const WebKit::WebRect& clip_rect,
84 const WebKit::WebVector<WebKit::WebRect>& cut_outs, bool is_visible);
85 virtual void updateFocus(bool focused);
86 virtual void updateVisibility(bool visible);
87 virtual bool acceptsInputEvents();
88 virtual bool handleInputEvent(
89 const WebKit::WebInputEvent& event, WebKit::WebCursorInfo& cursor_info);
90 virtual void didReceiveResponse(const WebKit::WebURLResponse& response);
91 virtual void didReceiveData(const char* data, int data_length);
92 virtual void didFinishLoading();
93 virtual void didFailLoading(const WebKit::WebURLError& error);
94 virtual void didFinishLoadingFrameRequest(
95 const WebKit::WebURL& url, void* notify_data);
96 virtual void didFailLoadingFrameRequest(
97 const WebKit::WebURL& url, void* notify_data,
98 const WebKit::WebURLError& error);
99 virtual bool isPlaceholder() OVERRIDE;
100
101 // WebPlugin implementation:
102 virtual void SetWindow(gfx::PluginWindowHandle window) OVERRIDE;
103 virtual void SetAcceptsInputEvents(bool accepts) OVERRIDE;
104 virtual void WillDestroyWindow(gfx::PluginWindowHandle window) OVERRIDE;
105 #if defined(OS_WIN)
106 void SetWindowlessData(HANDLE pump_messages_event,
107 gfx::NativeViewId dummy_activation_window) { }
108 void ReparentPluginWindow(HWND window, HWND parent) { }
109 void ReportExecutableMemory(size_t size) { }
110 #endif
111 virtual void CancelResource(unsigned long id) OVERRIDE;
112 virtual void Invalidate() OVERRIDE;
113 virtual void InvalidateRect(const gfx::Rect& rect) OVERRIDE;
114 virtual NPObject* GetWindowScriptNPObject() OVERRIDE;
115 virtual NPObject* GetPluginElement() OVERRIDE;
116 virtual bool FindProxyForUrl(const GURL& url,
117 std::string* proxy_list) OVERRIDE;
118 virtual void SetCookie(const GURL& url,
119 const GURL& first_party_for_cookies,
120 const std::string& cookie) OVERRIDE;
121 virtual std::string GetCookies(const GURL& url,
122 const GURL& first_party_for_cookies) OVERRIDE;
123 virtual void URLRedirectResponse(bool allow, int resource_id) OVERRIDE;
124 #if defined(OS_MACOSX)
125 virtual WebPluginAcceleratedSurface* GetAcceleratedSurface(
126 gfx::GpuPreference gpu_preference) OVERRIDE;
127 virtual void AcceleratedPluginEnabledRendering() OVERRIDE;
128 virtual void AcceleratedPluginAllocatedIOSurface(int32 width,
129 int32 height,
130 uint32 surface_id) OVERRIDE;
131 virtual void AcceleratedPluginSwappedIOSurface() OVERRIDE;
132 #endif
133
134 // Given a (maybe partial) url, completes using the base url.
135 GURL CompleteURL(const char* url);
136
137 enum RoutingStatus {
138 ROUTED,
139 NOT_ROUTED,
140 INVALID_URL,
141 GENERAL_FAILURE
142 };
143
144 // Determines the referrer value sent along with outgoing HTTP requests
145 // issued by plugins.
146 enum Referrer {
147 PLUGIN_SRC,
148 DOCUMENT_URL,
149 NO_REFERRER
150 };
151
152 // Given a download request, check if we need to route the output to a frame.
153 // Returns ROUTED if the load is done and routed to a frame, NOT_ROUTED or
154 // corresponding error codes otherwise.
155 RoutingStatus RouteToFrame(const char* url,
156 bool is_javascript_url,
157 bool popups_allowed,
158 const char* method,
159 const char* target,
160 const char* buf,
161 unsigned int len,
162 int notify_id,
163 Referrer referrer_flag);
164
165 // Returns the next avaiable resource id. Returns 0 if the operation fails.
166 // It may fail if the page has already been closed.
167 unsigned long GetNextResourceId();
168
169 // Initiates HTTP GET/POST requests.
170 // Returns true on success.
171 bool InitiateHTTPRequest(unsigned long resource_id,
172 WebPluginResourceClient* client,
173 const GURL& url,
174 const char* method,
175 const char* buf,
176 int len,
177 const char* range_info,
178 Referrer referrer_flag,
179 bool notify_redirects,
180 bool check_mixed_scripting);
181
182 gfx::Rect GetWindowClipRect(const gfx::Rect& rect);
183
184 // Sets the actual Widget for the plugin.
185 void SetContainer(WebKit::WebPluginContainer* container);
186
187 // Destroys the plugin instance.
188 // The response_handle_to_ignore parameter if not NULL indicates the
189 // resource handle to be left valid during plugin shutdown.
190 void TearDownPluginInstance(WebKit::WebURLLoader* loader_to_ignore);
191
192 // WebURLLoaderClient implementation. We implement this interface in the
193 // renderer process, and then use the simple WebPluginResourceClient interface
194 // to relay the callbacks to the plugin.
195 virtual void willSendRequest(WebKit::WebURLLoader* loader,
196 WebKit::WebURLRequest& request,
197 const WebKit::WebURLResponse& response);
198 virtual void didSendData(WebKit::WebURLLoader* loader,
199 unsigned long long bytes_sent,
200 unsigned long long total_bytes_to_be_sent);
201 virtual void didReceiveResponse(WebKit::WebURLLoader* loader,
202 const WebKit::WebURLResponse& response);
203
204 virtual void didReceiveData(WebKit::WebURLLoader* loader, const char *buffer,
205 int data_length, int encoded_data_length);
206 virtual void didFinishLoading(WebKit::WebURLLoader* loader,
207 double finishTime);
208 virtual void didFail(WebKit::WebURLLoader* loader,
209 const WebKit::WebURLError& error);
210
211 // Helper function to remove the stored information about a resource
212 // request given its index in m_clients.
213 void RemoveClient(size_t i);
214
215 // Helper function to remove the stored information about a resource
216 // request given a handle.
217 void RemoveClient(WebKit::WebURLLoader* loader);
218
219 virtual void HandleURLRequest(const char* url,
220 const char *method,
221 const char* target,
222 const char* buf,
223 unsigned int len,
224 int notify_id,
225 bool popups_allowed,
226 bool notify_redirects) OVERRIDE;
227
228 virtual void CancelDocumentLoad() OVERRIDE;
229
230 virtual void InitiateHTTPRangeRequest(const char* url,
231 const char* range_info,
232 int pending_request_id) OVERRIDE;
233
234 virtual void SetDeferResourceLoading(unsigned long resource_id,
235 bool defer) OVERRIDE;
236
237 // Ignore in-process plugins mode for this flag.
238 virtual bool IsOffTheRecord() OVERRIDE;
239
240 // Handles HTTP multipart responses, i.e. responses received with a HTTP
241 // status code of 206.
242 // Returns false if response is not multipart (may be if we requested
243 // single range).
244 bool HandleHttpMultipartResponse(const WebKit::WebURLResponse& response,
245 WebPluginResourceClient* client);
246
247 void HandleURLRequestInternal(const char* url,
248 const char* method,
249 const char* target,
250 const char* buf,
251 unsigned int len,
252 int notify_id,
253 bool popups_allowed,
254 Referrer referrer_flag,
255 bool notify_redirects,
256 bool check_mixed_scripting);
257
258 // Tears down the existing plugin instance and creates a new plugin instance
259 // to handle the response identified by the loader parameter.
260 bool ReinitializePluginForResponse(WebKit::WebURLLoader* loader);
261
262 // Delayed task for downloading the plugin source URL.
263 void OnDownloadPluginSrcUrl();
264
265 struct ClientInfo;
266
267 // Helper functions
268 WebPluginResourceClient* GetClientFromLoader(WebKit::WebURLLoader* loader);
269 ClientInfo* GetClientInfoFromLoader(WebKit::WebURLLoader* loader);
270
271 // Helper function to set the referrer on the request passed in.
272 void SetReferrer(WebKit::WebURLRequest* request, Referrer referrer_flag);
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 #if defined(OS_MACOSX)
282 bool next_io_surface_allocated_;
283 int32 next_io_surface_width_;
284 int32 next_io_surface_height_;
285 uint32 next_io_surface_id_;
286 scoped_refptr<cc::IOSurfaceLayer> io_surface_layer_;
287 scoped_ptr<WebKit::WebLayer> web_layer_;
288 #endif
289 bool accepts_input_events_;
290 base::WeakPtr<WebPluginPageDelegate> page_delegate_;
291 WebKit::WebFrame* webframe_;
292
293 WebPluginDelegate* delegate_;
294
295 // This is just a weak reference.
296 WebKit::WebPluginContainer* container_;
297
298 // Unique identifier for this plugin, used to track script objects.
299 struct _NPP* npp_;
300
301 typedef std::map<WebPluginResourceClient*,
302 webkit_glue::MultipartResponseDelegate*>
303 MultiPartResponseHandlerMap;
304 // Tracks HTTP multipart response handlers instantiated for
305 // a WebPluginResourceClient instance.
306 MultiPartResponseHandlerMap multi_part_response_map_;
307
308 // The plugin source URL.
309 GURL plugin_url_;
310
311 // Indicates if the download would be initiated by the plugin or us.
312 bool load_manually_;
313
314 // Indicates if this is the first geometry update received by the plugin.
315 bool first_geometry_update_;
316
317 // Set to true if the next response error should be ignored.
318 bool ignore_response_error_;
319
320 // The current plugin geometry and clip rectangle.
321 WebPluginGeometry geometry_;
322
323 // The location of the plugin on disk.
324 base::FilePath file_path_;
325
326 // The mime type of the plugin.
327 std::string mime_type_;
328
329 // Holds the list of argument names and values passed to the plugin. We keep
330 // these so that we can re-initialize the plugin if we need to.
331 std::vector<std::string> arg_names_;
332 std::vector<std::string> arg_values_;
333
334 base::WeakPtrFactory<WebPluginImpl> weak_factory_;
335
336 DISALLOW_COPY_AND_ASSIGN(WebPluginImpl);
337 };
338
339 } // namespace npapi
340 } // namespace webkit
341
342 #endif // WEBKIT_PLUGINS_NPAPI_WEBPLUGIN_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698