| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 CONTENT_RENDERER_NPAPI_WEBPLUGIN_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_NPAPI_WEBPLUGIN_IMPL_H_ |
| 6 #define CONTENT_RENDERER_NPAPI_WEBPLUGIN_IMPL_H_ | 6 #define CONTENT_RENDERER_NPAPI_WEBPLUGIN_IMPL_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <map> | 11 #include <map> |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "content/child/npapi/webplugin.h" | 20 #include "content/child/npapi/webplugin.h" |
| 21 #include "content/common/content_export.h" | 21 #include "content/common/content_export.h" |
| 22 #include "content/common/webplugin_geometry.h" | 22 #include "content/common/webplugin_geometry.h" |
| 23 #include "third_party/WebKit/public/platform/WebRect.h" | 23 #include "third_party/WebKit/public/platform/WebRect.h" |
| 24 #include "third_party/WebKit/public/platform/WebString.h" | 24 #include "third_party/WebKit/public/platform/WebString.h" |
| 25 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" | |
| 26 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 25 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 27 #include "third_party/WebKit/public/platform/WebVector.h" | 26 #include "third_party/WebKit/public/platform/WebVector.h" |
| 28 #include "third_party/WebKit/public/web/WebPlugin.h" | 27 #include "third_party/WebKit/public/web/WebPlugin.h" |
| 29 #include "ui/gfx/native_widget_types.h" | 28 #include "ui/gfx/native_widget_types.h" |
| 30 #include "url/gurl.h" | 29 #include "url/gurl.h" |
| 31 | 30 |
| 32 namespace cc { | 31 namespace cc { |
| 33 class IOSurfaceLayer; | 32 class IOSurfaceLayer; |
| 34 } | 33 } |
| 35 | 34 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 void didReceiveResponse(const blink::WebURLResponse& response) override {} | 92 void didReceiveResponse(const blink::WebURLResponse& response) override {} |
| 94 void didReceiveData(const char* data, int data_length) override {} | 93 void didReceiveData(const char* data, int data_length) override {} |
| 95 void didFinishLoading() override {} | 94 void didFinishLoading() override {} |
| 96 void didFailLoading(const blink::WebURLError& error) override {} | 95 void didFailLoading(const blink::WebURLError& error) override {} |
| 97 bool isPlaceholder() override; | 96 bool isPlaceholder() override; |
| 98 | 97 |
| 99 // WebPlugin implementation: | 98 // WebPlugin implementation: |
| 100 void SetWindow(gfx::PluginWindowHandle window) override; | 99 void SetWindow(gfx::PluginWindowHandle window) override; |
| 101 void SetAcceptsInputEvents(bool accepts) override; | 100 void SetAcceptsInputEvents(bool accepts) override; |
| 102 void WillDestroyWindow(gfx::PluginWindowHandle window) override; | 101 void WillDestroyWindow(gfx::PluginWindowHandle window) override; |
| 103 void CancelResource(unsigned long id) override; | |
| 104 void Invalidate() override; | 102 void Invalidate() override; |
| 105 void InvalidateRect(const gfx::Rect& rect) override; | 103 void InvalidateRect(const gfx::Rect& rect) override; |
| 106 NPObject* GetWindowScriptNPObject() override; | 104 NPObject* GetWindowScriptNPObject() override; |
| 107 NPObject* GetPluginElement() override; | 105 NPObject* GetPluginElement() override; |
| 108 bool FindProxyForUrl(const GURL& url, std::string* proxy_list) override; | 106 bool FindProxyForUrl(const GURL& url, std::string* proxy_list) override; |
| 109 void SetCookie(const GURL& url, | 107 void SetCookie(const GURL& url, |
| 110 const GURL& first_party_for_cookies, | 108 const GURL& first_party_for_cookies, |
| 111 const std::string& cookie) override; | 109 const std::string& cookie) override; |
| 112 std::string GetCookies(const GURL& url, | 110 std::string GetCookies(const GURL& url, |
| 113 const GURL& first_party_for_cookies) override; | 111 const GURL& first_party_for_cookies) override; |
| 114 void CancelDocumentLoad() override; | 112 void CancelDocumentLoad() override; |
| 115 void DidStartLoading() override; | 113 void DidStartLoading() override; |
| 116 void DidStopLoading() override; | 114 void DidStopLoading() override; |
| 117 bool IsOffTheRecord() override; | 115 bool IsOffTheRecord() override; |
| 118 void SetDeferResourceLoading(unsigned long resource_id, bool defer) override; | |
| 119 void URLRedirectResponse(bool allow, int resource_id) override; | |
| 120 #if defined(OS_WIN) | 116 #if defined(OS_WIN) |
| 121 void SetWindowlessData(HANDLE pump_messages_event, | 117 void SetWindowlessData(HANDLE pump_messages_event, |
| 122 gfx::NativeViewId dummy_activation_window) override {} | 118 gfx::NativeViewId dummy_activation_window) override {} |
| 123 void ReparentPluginWindow(HWND window, HWND parent) { } | 119 void ReparentPluginWindow(HWND window, HWND parent) { } |
| 124 void ReportExecutableMemory(size_t size) { } | 120 void ReportExecutableMemory(size_t size) { } |
| 125 #endif | 121 #endif |
| 126 #if defined(OS_MACOSX) | 122 #if defined(OS_MACOSX) |
| 127 WebPluginAcceleratedSurface* GetAcceleratedSurface( | 123 WebPluginAcceleratedSurface* GetAcceleratedSurface( |
| 128 gfx::GpuPreference gpu_preference) override; | 124 gfx::GpuPreference gpu_preference) override; |
| 129 void AcceleratedPluginEnabledRendering() override; | 125 void AcceleratedPluginEnabledRendering() override; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 gfx::Rect GetWindowClipRect(const gfx::Rect& rect); | 167 gfx::Rect GetWindowClipRect(const gfx::Rect& rect); |
| 172 | 168 |
| 173 // Sets the actual Widget for the plugin. | 169 // Sets the actual Widget for the plugin. |
| 174 void SetContainer(blink::WebPluginContainer* container); | 170 void SetContainer(blink::WebPluginContainer* container); |
| 175 | 171 |
| 176 // Destroys the plugin instance. | 172 // Destroys the plugin instance. |
| 177 // The response_handle_to_ignore parameter if not NULL indicates the | 173 // The response_handle_to_ignore parameter if not NULL indicates the |
| 178 // resource handle to be left valid during plugin shutdown. | 174 // resource handle to be left valid during plugin shutdown. |
| 179 void TearDownPluginInstance(blink::WebURLLoader* loader_to_ignore); | 175 void TearDownPluginInstance(blink::WebURLLoader* loader_to_ignore); |
| 180 | 176 |
| 181 // WebURLLoaderClient implementation. We implement this interface in the | |
| 182 // renderer process, and then use the simple WebPluginResourceClient interface | |
| 183 // to relay the callbacks to the plugin. | |
| 184 void willFollowRedirect(blink::WebURLLoader* loader, | |
| 185 blink::WebURLRequest& new_request, | |
| 186 const blink::WebURLResponse& response); | |
| 187 void didSendData(blink::WebURLLoader* loader, | |
| 188 unsigned long long bytes_sent, | |
| 189 unsigned long long total_bytes_to_be_sent); | |
| 190 void didReceiveResponse(blink::WebURLLoader* loader, | |
| 191 const blink::WebURLResponse& response); | |
| 192 | |
| 193 void didReceiveData(blink::WebURLLoader* loader, const char *buffer, | |
| 194 int data_length, int encoded_data_length); | |
| 195 void didFinishLoading(blink::WebURLLoader* loader, | |
| 196 double finishTime); | |
| 197 void didFail(blink::WebURLLoader* loader, | |
| 198 const blink::WebURLError& error); | |
| 199 | |
| 200 // Helper function to remove the stored information about a resource | |
| 201 // request given its index in m_clients. | |
| 202 void RemoveClient(size_t i); | |
| 203 | |
| 204 // Helper function to remove the stored information about a resource | |
| 205 // request given a handle. | |
| 206 void RemoveClient(blink::WebURLLoader* loader); | |
| 207 | |
| 208 // Handles HTTP multipart responses, i.e. responses received with a HTTP | |
| 209 // status code of 206. | |
| 210 // Returns false if response is not multipart (may be if we requested | |
| 211 // single range). | |
| 212 bool HandleHttpMultipartResponse(const blink::WebURLResponse& response, | |
| 213 WebPluginResourceClient* client); | |
| 214 | |
| 215 // Tears down the existing plugin instance and creates a new plugin instance | 177 // Tears down the existing plugin instance and creates a new plugin instance |
| 216 // to handle the response identified by the loader parameter. | 178 // to handle the response identified by the loader parameter. |
| 217 bool ReinitializePluginForResponse(blink::WebURLLoader* loader); | 179 bool ReinitializePluginForResponse(blink::WebURLLoader* loader); |
| 218 | 180 |
| 219 struct ClientInfo; | |
| 220 | |
| 221 // Helper functions | |
| 222 WebPluginResourceClient* GetClientFromLoader(blink::WebURLLoader* loader); | |
| 223 ClientInfo* GetClientInfoFromLoader(blink::WebURLLoader* loader); | |
| 224 | 181 |
| 225 // Helper function to set the referrer on the request passed in. | 182 // Helper function to set the referrer on the request passed in. |
| 226 void SetReferrer(blink::WebURLRequest* request, ReferrerValue referrer_flag); | 183 void SetReferrer(blink::WebURLRequest* request, ReferrerValue referrer_flag); |
| 227 | 184 |
| 228 // Check for invalid chars like @, ;, \ before the first / (in path). | 185 // Check for invalid chars like @, ;, \ before the first / (in path). |
| 229 bool IsValidUrl(const GURL& url, ReferrerValue referrer_flag); | 186 bool IsValidUrl(const GURL& url, ReferrerValue referrer_flag); |
| 230 | 187 |
| 231 std::vector<ClientInfo> clients_; | |
| 232 | |
| 233 bool windowless_; | 188 bool windowless_; |
| 234 gfx::PluginWindowHandle window_; | 189 gfx::PluginWindowHandle window_; |
| 235 #if defined(OS_MACOSX) | 190 #if defined(OS_MACOSX) |
| 236 bool next_io_surface_allocated_; | 191 bool next_io_surface_allocated_; |
| 237 int32_t next_io_surface_width_; | 192 int32_t next_io_surface_width_; |
| 238 int32_t next_io_surface_height_; | 193 int32_t next_io_surface_height_; |
| 239 uint32_t next_io_surface_id_; | 194 uint32_t next_io_surface_id_; |
| 240 scoped_refptr<cc::IOSurfaceLayer> io_surface_layer_; | 195 scoped_refptr<cc::IOSurfaceLayer> io_surface_layer_; |
| 241 scoped_ptr<blink::WebLayer> web_layer_; | 196 scoped_ptr<blink::WebLayer> web_layer_; |
| 242 #endif | 197 #endif |
| 243 bool accepts_input_events_; | 198 bool accepts_input_events_; |
| 244 RenderFrameImpl* render_frame_; | 199 RenderFrameImpl* render_frame_; |
| 245 base::WeakPtr<RenderViewImpl> render_view_; | 200 base::WeakPtr<RenderViewImpl> render_view_; |
| 246 blink::WebFrame* webframe_; | 201 blink::WebFrame* webframe_; |
| 247 | 202 |
| 248 WebPluginDelegateProxy* delegate_; | 203 WebPluginDelegateProxy* delegate_; |
| 249 | 204 |
| 250 // This is just a weak reference. | 205 // This is just a weak reference. |
| 251 blink::WebPluginContainer* container_; | 206 blink::WebPluginContainer* container_; |
| 252 | 207 |
| 253 // Unique identifier for this plugin, used to track script objects. | 208 // Unique identifier for this plugin, used to track script objects. |
| 254 struct _NPP* npp_; | 209 struct _NPP* npp_; |
| 255 | 210 |
| 256 typedef std::map<WebPluginResourceClient*, MultipartResponseDelegate*> | |
| 257 MultiPartResponseHandlerMap; | |
| 258 // Tracks HTTP multipart response handlers instantiated for | |
| 259 // a WebPluginResourceClient instance. | |
| 260 MultiPartResponseHandlerMap multi_part_response_map_; | |
| 261 | |
| 262 // The plugin source URL. | 211 // The plugin source URL. |
| 263 GURL plugin_url_; | 212 GURL plugin_url_; |
| 264 | 213 |
| 265 // Indicates if the download would be initiated by the plugin or us. | 214 // Indicates if the download would be initiated by the plugin or us. |
| 266 bool load_manually_; | 215 bool load_manually_; |
| 267 | 216 |
| 268 // Indicates if this is the first geometry update received by the plugin. | 217 // Indicates if this is the first geometry update received by the plugin. |
| 269 bool first_geometry_update_; | 218 bool first_geometry_update_; |
| 270 | 219 |
| 271 // Set to true if the next response error should be ignored. | 220 // Set to true if the next response error should be ignored. |
| 272 bool ignore_response_error_; | 221 bool ignore_response_error_; |
| 273 | 222 |
| 274 // The current plugin geometry and clip rectangle. | 223 // The current plugin geometry and clip rectangle. |
| 275 WebPluginGeometry geometry_; | 224 WebPluginGeometry geometry_; |
| 276 | 225 |
| 277 // The location of the plugin on disk. | 226 // The location of the plugin on disk. |
| 278 base::FilePath file_path_; | 227 base::FilePath file_path_; |
| 279 | 228 |
| 280 // The mime type of the plugin. | 229 // The mime type of the plugin. |
| 281 std::string mime_type_; | 230 std::string mime_type_; |
| 282 | 231 |
| 283 // Holds the list of argument names and values passed to the plugin. We keep | 232 // Holds the list of argument names and values passed to the plugin. We keep |
| 284 // these so that we can re-initialize the plugin if we need to. | 233 // these so that we can re-initialize the plugin if we need to. |
| 285 std::vector<std::string> arg_names_; | 234 std::vector<std::string> arg_names_; |
| 286 std::vector<std::string> arg_values_; | 235 std::vector<std::string> arg_values_; |
| 287 | 236 |
| 288 class LoaderClient : public blink::WebURLLoaderClient { | |
| 289 public: | |
| 290 LoaderClient(WebPluginImpl*); | |
| 291 | |
| 292 void willFollowRedirect(blink::WebURLLoader*, | |
| 293 blink::WebURLRequest&, | |
| 294 const blink::WebURLResponse&) override; | |
| 295 void didSendData(blink::WebURLLoader*, | |
| 296 unsigned long long bytesSent, | |
| 297 unsigned long long totalBytesToBeSent) override; | |
| 298 void didReceiveResponse(blink::WebURLLoader*, | |
| 299 const blink::WebURLResponse&) override; | |
| 300 void didDownloadData(blink::WebURLLoader*, | |
| 301 int dataLength, | |
| 302 int encodedDataLength) override; | |
| 303 void didReceiveData(blink::WebURLLoader*, | |
| 304 const char* data, | |
| 305 int dataLength, | |
| 306 int encodedDataLength) override; | |
| 307 void didReceiveCachedMetadata(blink::WebURLLoader*, | |
| 308 const char* data, | |
| 309 int dataLength) override; | |
| 310 void didFinishLoading(blink::WebURLLoader*, | |
| 311 double finishTime, | |
| 312 int64_t total_encoded_data_length) override; | |
| 313 void didFail(blink::WebURLLoader*, const blink::WebURLError&) override; | |
| 314 | |
| 315 private: | |
| 316 WebPluginImpl* parent_; | |
| 317 }; | |
| 318 | |
| 319 LoaderClient loader_client_; | |
| 320 | |
| 321 DISALLOW_COPY_AND_ASSIGN(WebPluginImpl); | 237 DISALLOW_COPY_AND_ASSIGN(WebPluginImpl); |
| 322 }; | 238 }; |
| 323 | 239 |
| 324 } // namespace content | 240 } // namespace content |
| 325 | 241 |
| 326 #endif // CONTENT_RENDERER_NPAPI_WEBPLUGIN_IMPL_H_ | 242 #endif // CONTENT_RENDERER_NPAPI_WEBPLUGIN_IMPL_H_ |
| OLD | NEW |