| 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_BROWSER_PLUGIN_BROWSER_PLUGIN_H_ | 5 #ifndef CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_ |
| 6 #define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_ | 6 #define CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_ |
| 7 | 7 |
| 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" | 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/process_util.h" | 12 #include "base/process_util.h" |
| 13 #include "base/sequenced_task_runner_helpers.h" | 13 #include "base/sequenced_task_runner_helpers.h" |
| 14 #if defined(OS_WIN) | 14 #if defined(OS_WIN) |
| 15 #include "base/shared_memory.h" | 15 #include "base/shared_memory.h" |
| 16 #endif | 16 #endif |
| 17 #include "content/common/browser_plugin_message_enums.h" |
| 17 #include "content/renderer/browser_plugin/browser_plugin_backing_store.h" | 18 #include "content/renderer/browser_plugin/browser_plugin_backing_store.h" |
| 18 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" | 19 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" |
| 19 #include "content/renderer/render_view_impl.h" | 20 #include "content/renderer/render_view_impl.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragStatus.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragStatus.h" |
| 21 | 22 |
| 22 struct BrowserPluginHostMsg_AutoSize_Params; | 23 struct BrowserPluginHostMsg_AutoSize_Params; |
| 23 struct BrowserPluginHostMsg_ResizeGuest_Params; | 24 struct BrowserPluginHostMsg_ResizeGuest_Params; |
| 24 struct BrowserPluginMsg_LoadCommit_Params; | 25 struct BrowserPluginMsg_LoadCommit_Params; |
| 25 struct BrowserPluginMsg_UpdateRect_Params; | 26 struct BrowserPluginMsg_UpdateRect_Params; |
| 26 | 27 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 void Back(); | 108 void Back(); |
| 108 // Tells the BrowserPlugin to tell the guest to navigate to the next | 109 // Tells the BrowserPlugin to tell the guest to navigate to the next |
| 109 // navigation entry in the navigation history. | 110 // navigation entry in the navigation history. |
| 110 void Forward(); | 111 void Forward(); |
| 111 // Tells the BrowserPlugin to tell the guest to navigate to a position | 112 // Tells the BrowserPlugin to tell the guest to navigate to a position |
| 112 // relative to the current index in its navigation history. | 113 // relative to the current index in its navigation history. |
| 113 void Go(int relativeIndex); | 114 void Go(int relativeIndex); |
| 114 // Tells the BrowserPlugin to terminate the guest process. | 115 // Tells the BrowserPlugin to terminate the guest process. |
| 115 void TerminateGuest(); | 116 void TerminateGuest(); |
| 116 | 117 |
| 117 // A request from Javascript has been made to stop the loading of the page. | 118 // A request from JavaScript has been made to stop the loading of the page. |
| 118 void Stop(); | 119 void Stop(); |
| 119 // A request from Javascript has been made to reload the page. | 120 // A request from JavaScript has been made to reload the page. |
| 120 void Reload(); | 121 void Reload(); |
| 121 // A request to enable hardware compositing. | 122 // A request to enable hardware compositing. |
| 122 void EnableCompositing(bool enable); | 123 void EnableCompositing(bool enable); |
| 124 // A request from content client to track lifetime of a JavaScript object |
| 125 // related to a permission request object. |
| 126 // This is used to clean up hanging permission request objects. |
| 127 void PersistRequestObject(const NPVariant* request, |
| 128 const std::string& type, |
| 129 int id); |
| 123 | 130 |
| 124 // Returns true if |point| lies within the bounds of the plugin rectangle. | 131 // Returns true if |point| lies within the bounds of the plugin rectangle. |
| 125 // Not OK to use this function for making security-sensitive decision since it | 132 // Not OK to use this function for making security-sensitive decision since it |
| 126 // can return false positives when the plugin has rotation transformation | 133 // can return false positives when the plugin has rotation transformation |
| 127 // applied. | 134 // applied. |
| 128 bool InBounds(const gfx::Point& point) const; | 135 bool InBounds(const gfx::Point& point) const; |
| 129 | 136 |
| 130 gfx::Point ToLocalCoordinates(const gfx::Point& point) const; | 137 gfx::Point ToLocalCoordinates(const gfx::Point& point) const; |
| 138 // Called by browser plugin binding. |
| 139 void OnEmbedderDecidedPermission(int request_id, bool allow); |
| 140 |
| 131 | 141 |
| 132 // WebKit::WebPlugin implementation. | 142 // WebKit::WebPlugin implementation. |
| 133 virtual WebKit::WebPluginContainer* container() const OVERRIDE; | 143 virtual WebKit::WebPluginContainer* container() const OVERRIDE; |
| 134 virtual bool initialize(WebKit::WebPluginContainer* container) OVERRIDE; | 144 virtual bool initialize(WebKit::WebPluginContainer* container) OVERRIDE; |
| 135 virtual void destroy() OVERRIDE; | 145 virtual void destroy() OVERRIDE; |
| 136 virtual NPObject* scriptableObject() OVERRIDE; | 146 virtual NPObject* scriptableObject() OVERRIDE; |
| 137 virtual bool supportsKeyboardFocus() const OVERRIDE; | 147 virtual bool supportsKeyboardFocus() const OVERRIDE; |
| 138 virtual bool canProcessDrag() const OVERRIDE; | 148 virtual bool canProcessDrag() const OVERRIDE; |
| 139 virtual void paint( | 149 virtual void paint( |
| 140 WebKit::WebCanvas* canvas, | 150 WebKit::WebCanvas* canvas, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 void GetDamageBufferWithSizeParams( | 248 void GetDamageBufferWithSizeParams( |
| 239 BrowserPluginHostMsg_AutoSize_Params* auto_size_params, | 249 BrowserPluginHostMsg_AutoSize_Params* auto_size_params, |
| 240 BrowserPluginHostMsg_ResizeGuest_Params* resize_guest_params); | 250 BrowserPluginHostMsg_ResizeGuest_Params* resize_guest_params); |
| 241 | 251 |
| 242 // Informs the guest of an updated autosize state. | 252 // Informs the guest of an updated autosize state. |
| 243 void UpdateGuestAutoSizeState(bool current_auto_size); | 253 void UpdateGuestAutoSizeState(bool current_auto_size); |
| 244 | 254 |
| 245 // Informs the BrowserPlugin that guest has changed its size in autosize mode. | 255 // Informs the BrowserPlugin that guest has changed its size in autosize mode. |
| 246 void SizeChangedDueToAutoSize(const gfx::Size& old_view_size); | 256 void SizeChangedDueToAutoSize(const gfx::Size& old_view_size); |
| 247 | 257 |
| 258 bool HasEventListeners(const std::string& event_name); |
| 259 |
| 248 // Indicates whether a damage buffer was used by the guest process for the | 260 // Indicates whether a damage buffer was used by the guest process for the |
| 249 // provided |params|. | 261 // provided |params|. |
| 250 static bool UsesDamageBuffer( | 262 static bool UsesDamageBuffer( |
| 251 const BrowserPluginMsg_UpdateRect_Params& params); | 263 const BrowserPluginMsg_UpdateRect_Params& params); |
| 252 | 264 |
| 253 // Indicates whether the |pending_damage_buffer_| was used to copy over pixels | 265 // Indicates whether the |pending_damage_buffer_| was used to copy over pixels |
| 254 // given the provided |params|. | 266 // given the provided |params|. |
| 255 bool UsesPendingDamageBuffer( | 267 bool UsesPendingDamageBuffer( |
| 256 const BrowserPluginMsg_UpdateRect_Params& params); | 268 const BrowserPluginMsg_UpdateRect_Params& params); |
| 257 | 269 |
| 258 // Sets the instance ID of the BrowserPlugin and requests a guest from the | 270 // Sets the instance ID of the BrowserPlugin and requests a guest from the |
| 259 // browser process. | 271 // browser process. |
| 260 void SetInstanceID(int instance_id); | 272 void SetInstanceID(int instance_id); |
| 261 | 273 |
| 274 // Requests media access permission from the embedder. |
| 275 void RequestMediaPermission(int request_id, |
| 276 const base::DictionaryValue& request_info); |
| 277 // Informs the BrowserPlugin that the guest's permission request has been |
| 278 // allowed or denied by the embedder. |
| 279 void RespondPermission(BrowserPluginPermissionType permission_type, |
| 280 int request_id, |
| 281 bool allow); |
| 282 |
| 283 // If the request with id |request_id| is pending then informs the |
| 284 // BrowserPlugin that the guest's permission request has been allowed or |
| 285 // denied by the embedder. |
| 286 void RespondPermissionIfRequestIsPending(int request_id, bool allow); |
| 287 // Cleans up pending permission request once the associated event.request |
| 288 // object goes out of scope in JavaScript. |
| 289 void OnRequestObjectGarbageCollected(int request_id); |
| 290 // V8 garbage collection callback for |object|. |
| 291 static void WeakCallbackForPersistObject(v8::Persistent<v8::Value> object, |
| 292 void* param); |
| 293 |
| 262 // IPC message handlers. | 294 // IPC message handlers. |
| 263 // Please keep in alphabetical order. | 295 // Please keep in alphabetical order. |
| 264 void OnAdvanceFocus(int instance_id, bool reverse); | 296 void OnAdvanceFocus(int instance_id, bool reverse); |
| 265 void OnBuffersSwapped(int instance_id, | 297 void OnBuffersSwapped(int instance_id, |
| 266 const gfx::Size& size, | 298 const gfx::Size& size, |
| 267 std::string mailbox_name, | 299 std::string mailbox_name, |
| 268 int gpu_route_id, | 300 int gpu_route_id, |
| 269 int gpu_host_id); | 301 int gpu_host_id); |
| 270 void OnGuestContentWindowReady(int instance_id, | 302 void OnGuestContentWindowReady(int instance_id, |
| 271 int content_window_routing_id); | 303 int content_window_routing_id); |
| 272 void OnGuestGone(int instance_id, int process_id, int status); | 304 void OnGuestGone(int instance_id, int process_id, int status); |
| 273 void OnGuestResponsive(int instance_id, int process_id); | 305 void OnGuestResponsive(int instance_id, int process_id); |
| 274 void OnGuestUnresponsive(int instance_id, int process_id); | 306 void OnGuestUnresponsive(int instance_id, int process_id); |
| 275 void OnLoadAbort(int instance_id, | 307 void OnLoadAbort(int instance_id, |
| 276 const GURL& url, | 308 const GURL& url, |
| 277 bool is_top_level, | 309 bool is_top_level, |
| 278 const std::string& type); | 310 const std::string& type); |
| 279 void OnLoadCommit(int instance_id, | 311 void OnLoadCommit(int instance_id, |
| 280 const BrowserPluginMsg_LoadCommit_Params& params); | 312 const BrowserPluginMsg_LoadCommit_Params& params); |
| 281 void OnLoadRedirect(int instance_id, | 313 void OnLoadRedirect(int instance_id, |
| 282 const GURL& old_url, | 314 const GURL& old_url, |
| 283 const GURL& new_url, | 315 const GURL& new_url, |
| 284 bool is_top_level); | 316 bool is_top_level); |
| 285 void OnLoadStart(int instance_id, const GURL& url, bool is_top_level); | 317 void OnLoadStart(int instance_id, const GURL& url, bool is_top_level); |
| 286 void OnLoadStop(int instance_id); | 318 void OnLoadStop(int instance_id); |
| 319 // Requests permission from the embedder. |
| 320 void OnRequestPermission(int instance_id, |
| 321 BrowserPluginPermissionType permission_type, |
| 322 int request_id, |
| 323 const base::DictionaryValue& request_info); |
| 287 void OnSetCursor(int instance_id, const WebCursor& cursor); | 324 void OnSetCursor(int instance_id, const WebCursor& cursor); |
| 288 void OnShouldAcceptTouchEvents(int instance_id, bool accept); | 325 void OnShouldAcceptTouchEvents(int instance_id, bool accept); |
| 289 void OnUpdatedName(int instance_id, const std::string& name); | 326 void OnUpdatedName(int instance_id, const std::string& name); |
| 290 void OnUpdateRect(int instance_id, | 327 void OnUpdateRect(int instance_id, |
| 291 const BrowserPluginMsg_UpdateRect_Params& params); | 328 const BrowserPluginMsg_UpdateRect_Params& params); |
| 292 | 329 |
| 293 int instance_id_; | 330 int instance_id_; |
| 294 base::WeakPtr<RenderViewImpl> render_view_; | 331 base::WeakPtr<RenderViewImpl> render_view_; |
| 295 // We cache the |render_view_|'s routing ID because we need it on destruction. | 332 // We cache the |render_view_|'s routing ID because we need it on destruction. |
| 296 // If the |render_view_| is destroyed before the BrowserPlugin is destroyed | 333 // If the |render_view_| is destroyed before the BrowserPlugin is destroyed |
| (...skipping 24 matching lines...) Expand all Loading... |
| 321 // Tracks the visibility of the browser plugin regardless of the whole | 358 // Tracks the visibility of the browser plugin regardless of the whole |
| 322 // embedder RenderView's visibility. | 359 // embedder RenderView's visibility. |
| 323 bool visible_; | 360 bool visible_; |
| 324 | 361 |
| 325 WebCursor cursor_; | 362 WebCursor cursor_; |
| 326 | 363 |
| 327 gfx::Size last_view_size_; | 364 gfx::Size last_view_size_; |
| 328 bool size_changed_in_flight_; | 365 bool size_changed_in_flight_; |
| 329 bool allocate_instance_id_sent_; | 366 bool allocate_instance_id_sent_; |
| 330 | 367 |
| 368 // Each permission request item in the map is a pair of request id and |
| 369 // permission type. |
| 370 typedef std::map<int, std::pair<int, BrowserPluginPermissionType> > |
| 371 PendingPermissionRequests; |
| 372 PendingPermissionRequests pending_permission_requests_; |
| 373 |
| 374 typedef std::pair<int, base::WeakPtr<BrowserPlugin> > |
| 375 AliveV8PermissionRequestItem; |
| 376 std::map<int, AliveV8PermissionRequestItem*> |
| 377 alive_v8_permission_request_objects_; |
| 378 |
| 331 // BrowserPlugin outlives RenderViewImpl in Chrome Apps and so we need to | 379 // BrowserPlugin outlives RenderViewImpl in Chrome Apps and so we need to |
| 332 // store the BrowserPlugin's BrowserPluginManager in a member variable to | 380 // store the BrowserPlugin's BrowserPluginManager in a member variable to |
| 333 // avoid accessing the RenderViewImpl. | 381 // avoid accessing the RenderViewImpl. |
| 334 scoped_refptr<BrowserPluginManager> browser_plugin_manager_; | 382 scoped_refptr<BrowserPluginManager> browser_plugin_manager_; |
| 335 | 383 |
| 336 // Important: Do not add more history state here. | 384 // Important: Do not add more history state here. |
| 337 // We strongly discourage storing additional history state (such as page IDs) | 385 // We strongly discourage storing additional history state (such as page IDs) |
| 338 // in the embedder process, at the risk of having incorrect information that | 386 // in the embedder process, at the risk of having incorrect information that |
| 339 // can lead to broken back/forward logic in apps. | 387 // can lead to broken back/forward logic in apps. |
| 340 // It's also important that this state does not get modified by any logic in | 388 // It's also important that this state does not get modified by any logic in |
| 341 // the embedder process. It should only be updated in response to navigation | 389 // the embedder process. It should only be updated in response to navigation |
| 342 // events in the guest. No assumptions should be made about how the index | 390 // events in the guest. No assumptions should be made about how the index |
| 343 // will change after a navigation (e.g., for back, forward, or go), because | 391 // will change after a navigation (e.g., for back, forward, or go), because |
| 344 // the changes are not always obvious. For example, there is a maximum | 392 // the changes are not always obvious. For example, there is a maximum |
| 345 // number of entries and earlier ones will automatically be pruned. | 393 // number of entries and earlier ones will automatically be pruned. |
| 346 int current_nav_entry_index_; | 394 int current_nav_entry_index_; |
| 347 int nav_entry_count_; | 395 int nav_entry_count_; |
| 348 | 396 |
| 349 // Used for HW compositing. | 397 // Used for HW compositing. |
| 350 bool compositing_enabled_; | 398 bool compositing_enabled_; |
| 351 scoped_refptr<BrowserPluginCompositingHelper> compositing_helper_; | 399 scoped_refptr<BrowserPluginCompositingHelper> compositing_helper_; |
| 352 | 400 |
| 401 // Weak factory used in v8 |MakeWeak| callback, since the v8 callback might |
| 402 // get called after BrowserPlugin has been destroyed. |
| 403 base::WeakPtrFactory<BrowserPlugin> weak_ptr_factory_; |
| 404 |
| 353 DISALLOW_COPY_AND_ASSIGN(BrowserPlugin); | 405 DISALLOW_COPY_AND_ASSIGN(BrowserPlugin); |
| 354 }; | 406 }; |
| 355 | 407 |
| 356 } // namespace content | 408 } // namespace content |
| 357 | 409 |
| 358 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_ | 410 #endif // CONTENT_RENDERER_BROWSER_PLUGIN_BROWSER_PLUGIN_H_ |
| OLD | NEW |