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 // A BrowserPluginGuest is the browser side of a browser <--> embedder | 5 // A BrowserPluginGuest is the browser side of a browser <--> embedder |
6 // renderer channel. A BrowserPlugin (a WebPlugin) is on the embedder | 6 // renderer channel. A BrowserPlugin (a WebPlugin) is on the embedder |
7 // renderer side of browser <--> embedder renderer communication. | 7 // renderer side of browser <--> embedder renderer communication. |
8 // | 8 // |
9 // BrowserPluginGuest lives on the UI thread of the browser process. Any | 9 // BrowserPluginGuest lives on the UI thread of the browser process. Any |
10 // messages about the guest render process that the embedder might be interested | 10 // messages about the guest render process that the embedder might be interested |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 // embedder needs to be aware of |guest_site_instance| on the guest's | 95 // embedder needs to be aware of |guest_site_instance| on the guest's |
96 // construction and so we pass it in here. | 96 // construction and so we pass it in here. |
97 static BrowserPluginGuest* Create( | 97 static BrowserPluginGuest* Create( |
98 int instance_id, | 98 int instance_id, |
99 SiteInstance* guest_site_instance, | 99 SiteInstance* guest_site_instance, |
100 WebContentsImpl* web_contents, | 100 WebContentsImpl* web_contents, |
101 scoped_ptr<base::DictionaryValue> extra_params); | 101 scoped_ptr<base::DictionaryValue> extra_params); |
102 | 102 |
103 static BrowserPluginGuest* CreateWithOpener( | 103 static BrowserPluginGuest* CreateWithOpener( |
104 int instance_id, | 104 int instance_id, |
| 105 bool has_render_view, |
105 WebContentsImpl* web_contents, | 106 WebContentsImpl* web_contents, |
106 BrowserPluginGuest* opener, | 107 BrowserPluginGuest* opener); |
107 bool has_render_view); | |
108 | 108 |
109 // Called when the embedder WebContents is destroyed to give the | 109 // Called when the embedder WebContents is destroyed to give the |
110 // BrowserPluginGuest an opportunity to clean up after itself. | 110 // BrowserPluginGuest an opportunity to clean up after itself. |
111 void EmbedderDestroyed(); | 111 void EmbedderDestroyed(); |
112 | 112 |
113 // Called when the embedder WebContents changes visibility. | 113 // Called when the embedder WebContents changes visibility. |
114 void EmbedderVisibilityChanged(bool visible); | 114 void EmbedderVisibilityChanged(bool visible); |
115 | 115 |
116 // Destroys the guest WebContents and all its associated state, including | 116 // Destroys the guest WebContents and all its associated state, including |
117 // this BrowserPluginGuest, and its new unattached windows. | 117 // this BrowserPluginGuest, and its new unattached windows. |
118 void Destroy(); | 118 void Destroy(); |
119 | 119 |
120 // Returns the identifier that uniquely identifies a browser plugin guest | 120 // Returns the identifier that uniquely identifies a browser plugin guest |
121 // within an embedder. | 121 // within an embedder. |
122 int instance_id() const { return instance_id_; } | 122 int instance_id() const { return instance_id_; } |
123 | 123 |
124 // Overrides factory for testing. Default (NULL) value indicates regular | |
125 // (non-test) environment. | |
126 static void set_factory_for_testing(BrowserPluginHostFactory* factory) { | |
127 BrowserPluginGuest::factory_ = factory; | |
128 } | |
129 | |
130 bool OnMessageReceivedFromEmbedder(const IPC::Message& message); | 124 bool OnMessageReceivedFromEmbedder(const IPC::Message& message); |
131 | 125 |
132 void Initialize(WebContentsImpl* embedder_web_contents, | 126 void Initialize(const BrowserPluginHostMsg_Attach_Params& params, |
133 const BrowserPluginHostMsg_Attach_Params& params); | 127 WebContentsImpl* embedder_web_contents); |
134 | |
135 void set_guest_hang_timeout_for_testing(const base::TimeDelta& timeout) { | |
136 guest_hang_timeout_ = timeout; | |
137 } | |
138 | 128 |
139 WebContentsImpl* embedder_web_contents() const { | 129 WebContentsImpl* embedder_web_contents() const { |
140 return embedder_web_contents_; | 130 return embedder_web_contents_; |
141 } | 131 } |
142 | 132 |
143 RenderWidgetHostView* GetEmbedderRenderWidgetHostView(); | 133 RenderWidgetHostView* GetEmbedderRenderWidgetHostView(); |
144 | 134 |
145 bool focused() const { return focused_; } | 135 bool focused() const { return focused_; } |
146 bool visible() const { return guest_visible_; } | 136 bool visible() const { return guest_visible_; } |
147 void clear_damage_buffer() { damage_buffer_.reset(); } | 137 void clear_damage_buffer() { damage_buffer_.reset(); } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 233 |
244 gfx::Point GetScreenCoordinates(const gfx::Point& relative_position) const; | 234 gfx::Point GetScreenCoordinates(const gfx::Point& relative_position) const; |
245 | 235 |
246 // Helper to send messages to embedder. This methods fills the message with | 236 // Helper to send messages to embedder. This methods fills the message with |
247 // the correct routing id. | 237 // the correct routing id. |
248 // Overridden in test implementation since we want to intercept certain | 238 // Overridden in test implementation since we want to intercept certain |
249 // messages for testing. | 239 // messages for testing. |
250 virtual void SendMessageToEmbedder(IPC::Message* msg); | 240 virtual void SendMessageToEmbedder(IPC::Message* msg); |
251 | 241 |
252 // Returns whether the guest is attached to an embedder. | 242 // Returns whether the guest is attached to an embedder. |
253 bool attached() const { return !!embedder_web_contents_; } | 243 bool attached() const { return embedder_web_contents_ != NULL; } |
254 | 244 |
255 // Attaches this BrowserPluginGuest to the provided |embedder_web_contents| | 245 // Attaches this BrowserPluginGuest to the provided |embedder_web_contents| |
256 // and initializes the guest with the provided |params|. Attaching a guest | 246 // and initializes the guest with the provided |params|. Attaching a guest |
257 // to an embedder implies that this guest's lifetime is no longer managed | 247 // to an embedder implies that this guest's lifetime is no longer managed |
258 // by its opener, and it can begin loading resources. |extra_params| are | 248 // by its opener, and it can begin loading resources. |extra_params| are |
259 // parameters passed into BrowserPlugin from JavaScript to be forwarded to | 249 // parameters passed into BrowserPlugin from JavaScript to be forwarded to |
260 // the content embedder. | 250 // the content embedder. |
261 void Attach(WebContentsImpl* embedder_web_contents, | 251 void Attach(WebContentsImpl* embedder_web_contents, |
262 BrowserPluginHostMsg_Attach_Params params, | 252 BrowserPluginHostMsg_Attach_Params params, |
263 const base::DictionaryValue& extra_params); | 253 const base::DictionaryValue& extra_params); |
(...skipping 26 matching lines...) Expand all Loading... |
290 // Called when the drag started by this guest ends at an OS-level. | 280 // Called when the drag started by this guest ends at an OS-level. |
291 void EndSystemDrag(); | 281 void EndSystemDrag(); |
292 | 282 |
293 // |this| takes ownership of |delegate|. | 283 // |this| takes ownership of |delegate|. |
294 void SetDelegate(BrowserPluginGuestDelegate* delegate); | 284 void SetDelegate(BrowserPluginGuestDelegate* delegate); |
295 | 285 |
296 void RespondToPermissionRequest(int request_id, | 286 void RespondToPermissionRequest(int request_id, |
297 bool should_allow, | 287 bool should_allow, |
298 const std::string& user_input); | 288 const std::string& user_input); |
299 | 289 |
| 290 // Overrides factory for testing. Default (NULL) value indicates regular |
| 291 // (non-test) environment. |
| 292 static void set_factory_for_testing(BrowserPluginHostFactory* factory) { |
| 293 BrowserPluginGuest::factory_ = factory; |
| 294 } |
| 295 |
300 private: | 296 private: |
301 class EmbedderWebContentsObserver; | 297 class EmbedderWebContentsObserver; |
302 friend class TestBrowserPluginGuest; | 298 friend class TestBrowserPluginGuest; |
303 | 299 |
304 class DownloadRequest; | 300 class DownloadRequest; |
305 class GeolocationRequest; | 301 class GeolocationRequest; |
306 class JavaScriptDialogRequest; | 302 class JavaScriptDialogRequest; |
307 // MediaRequest because of naming conflicts with MediaStreamRequest. | 303 // MediaRequest because of naming conflicts with MediaStreamRequest. |
308 class MediaRequest; | 304 class MediaRequest; |
309 class NewWindowRequest; | 305 class NewWindowRequest; |
310 class PermissionRequest; | 306 class PermissionRequest; |
311 class PointerLockRequest; | 307 class PointerLockRequest; |
312 | 308 |
| 309 // Tracks the name, and target URL of the new window and whether or not it has |
| 310 // changed since the WebContents has been created and before the new window |
| 311 // has been attached to a BrowserPlugin. Once the first navigation commits, we |
| 312 // no longer track this information. |
| 313 struct NewWindowInfo { |
| 314 bool changed; |
| 315 GURL url; |
| 316 std::string name; |
| 317 NewWindowInfo(const GURL& url, const std::string& name) : |
| 318 changed(false), |
| 319 url(url), |
| 320 name(name) {} |
| 321 }; |
| 322 |
| 323 // BrowserPluginGuest is a WebContentsObserver of |web_contents| and |
| 324 // |web_contents| has to stay valid for the lifetime of BrowserPluginGuest. |
313 BrowserPluginGuest(int instance_id, | 325 BrowserPluginGuest(int instance_id, |
| 326 bool has_render_view, |
314 WebContentsImpl* web_contents, | 327 WebContentsImpl* web_contents, |
315 BrowserPluginGuest* opener, | 328 BrowserPluginGuest* opener); |
316 bool has_render_view); | |
317 | 329 |
318 // Destroy unattached new windows that have been opened by this | 330 // Destroy unattached new windows that have been opened by this |
319 // BrowserPluginGuest. | 331 // BrowserPluginGuest. |
320 void DestroyUnattachedWindows(); | 332 void DestroyUnattachedWindows(); |
321 | 333 |
322 void LoadURLWithParams(WebContents* web_contents, | 334 void LoadURLWithParams(const GURL& url, |
323 const GURL& url, | |
324 const Referrer& referrer, | 335 const Referrer& referrer, |
325 PageTransition transition_type); | 336 PageTransition transition_type, |
| 337 WebContents* web_contents); |
326 | 338 |
327 // Bridge IDs correspond to a geolocation request. This method will remove | 339 // Bridge IDs correspond to a geolocation request. This method will remove |
328 // the bookkeeping for a particular geolocation request associated with the | 340 // the bookkeeping for a particular geolocation request associated with the |
329 // provided |bridge_id|. It returns the request ID of the geolocation request. | 341 // provided |bridge_id|. It returns the request ID of the geolocation request. |
330 int RemoveBridgeID(int bridge_id); | 342 int RemoveBridgeID(int bridge_id); |
331 | 343 |
332 // Returns the |request_id| generated for the |request| provided. | 344 // Returns the |request_id| generated for the |request| provided. |
333 int RequestPermission( | 345 int RequestPermission( |
334 BrowserPluginPermissionType permission_type, | 346 BrowserPluginPermissionType permission_type, |
335 scoped_refptr<BrowserPluginGuest::PermissionRequest> request, | 347 scoped_refptr<BrowserPluginGuest::PermissionRequest> request, |
336 const base::DictionaryValue& request_info); | 348 const base::DictionaryValue& request_info); |
337 | 349 |
338 // Creates a new guest window, and BrowserPluginGuest that is owned by this | 350 // Creates a new guest window, and BrowserPluginGuest that is owned by this |
339 // BrowserPluginGuest. | 351 // BrowserPluginGuest. |
340 BrowserPluginGuest* CreateNewGuestWindow(const OpenURLParams& params); | 352 BrowserPluginGuest* CreateNewGuestWindow(const OpenURLParams& params); |
341 | 353 |
342 base::SharedMemory* damage_buffer() const { return damage_buffer_.get(); } | 354 base::SharedMemory* damage_buffer() const { return damage_buffer_.get(); } |
343 const gfx::Size& damage_view_size() const { return damage_view_size_; } | 355 const gfx::Size& damage_view_size() const { return damage_view_size_; } |
344 float damage_buffer_scale_factor() const { | 356 float damage_buffer_scale_factor() const { |
345 return damage_buffer_scale_factor_; | 357 return damage_buffer_scale_factor_; |
346 } | 358 } |
347 // Returns the damage buffer corresponding to the handle in resize |params|. | 359 // Returns the damage buffer corresponding to the handle in resize |params|. |
348 base::SharedMemory* GetDamageBufferFromEmbedder( | 360 base::SharedMemory* GetDamageBufferFromEmbedder( |
349 const BrowserPluginHostMsg_ResizeGuest_Params& params); | 361 const BrowserPluginHostMsg_ResizeGuest_Params& params); |
350 | 362 |
351 bool InAutoSizeBounds(const gfx::Size& size) const; | 363 bool InAutoSizeBounds(const gfx::Size& size) const; |
352 | 364 |
353 void RequestNewWindowPermission(WebContentsImpl* new_contents, | 365 void RequestNewWindowPermission(WindowOpenDisposition disposition, |
354 WindowOpenDisposition disposition, | |
355 const gfx::Rect& initial_bounds, | 366 const gfx::Rect& initial_bounds, |
356 bool user_gesture); | 367 bool user_gesture, |
| 368 WebContentsImpl* new_contents); |
357 | 369 |
358 // Message handlers for messages from embedder. | 370 // Message handlers for messages from embedder. |
359 | 371 |
360 void OnCompositorFrameACK(int instance_id, | 372 void OnCompositorFrameACK(int instance_id, |
361 int route_id, | 373 int route_id, |
362 uint32 output_surface_id, | 374 uint32 output_surface_id, |
363 int renderer_host_id, | 375 int renderer_host_id, |
364 const cc::CompositorFrameAck& ack); | 376 const cc::CompositorFrameAck& ack); |
365 | 377 |
366 // Handles drag events from the embedder. | 378 // Handles drag events from the embedder. |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 bool focused_; | 510 bool focused_; |
499 bool mouse_locked_; | 511 bool mouse_locked_; |
500 bool pending_lock_request_; | 512 bool pending_lock_request_; |
501 bool guest_visible_; | 513 bool guest_visible_; |
502 bool embedder_visible_; | 514 bool embedder_visible_; |
503 std::string name_; | 515 std::string name_; |
504 bool auto_size_enabled_; | 516 bool auto_size_enabled_; |
505 gfx::Size max_auto_size_; | 517 gfx::Size max_auto_size_; |
506 gfx::Size min_auto_size_; | 518 gfx::Size min_auto_size_; |
507 | 519 |
508 // Tracks the name, and target URL of the new window and whether or not it has | |
509 // changed since the WebContents has been created and before the new window | |
510 // has been attached to a BrowserPlugin. Once the first navigation commits, we | |
511 // no longer track this information. | |
512 struct NewWindowInfo { | |
513 bool changed; | |
514 GURL url; | |
515 std::string name; | |
516 NewWindowInfo(const GURL& url, const std::string& name) : | |
517 changed(false), | |
518 url(url), | |
519 name(name) {} | |
520 }; | |
521 typedef std::map<BrowserPluginGuest*, NewWindowInfo> PendingWindowMap; | 520 typedef std::map<BrowserPluginGuest*, NewWindowInfo> PendingWindowMap; |
522 PendingWindowMap pending_new_windows_; | 521 PendingWindowMap pending_new_windows_; |
523 base::WeakPtr<BrowserPluginGuest> opener_; | 522 base::WeakPtr<BrowserPluginGuest> opener_; |
524 // A counter to generate a unique request id for a permission request. | 523 // A counter to generate a unique request id for a permission request. |
525 // We only need the ids to be unique for a given BrowserPluginGuest. | 524 // We only need the ids to be unique for a given BrowserPluginGuest. |
526 int next_permission_request_id_; | 525 int next_permission_request_id_; |
527 | 526 |
528 // A map to store relevant info for a request keyed by the request's id. | 527 // A map to store relevant info for a request keyed by the request's id. |
529 typedef std::map<int, scoped_refptr<PermissionRequest> > RequestMap; | 528 typedef std::map<int, scoped_refptr<PermissionRequest> > RequestMap; |
530 RequestMap permission_request_map_; | 529 RequestMap permission_request_map_; |
(...skipping 19 matching lines...) Expand all Loading... |
550 // These are parameters passed from JavaScript on attachment to the content | 549 // These are parameters passed from JavaScript on attachment to the content |
551 // embedder. | 550 // embedder. |
552 scoped_ptr<base::DictionaryValue> extra_attach_params_; | 551 scoped_ptr<base::DictionaryValue> extra_attach_params_; |
553 | 552 |
554 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); | 553 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); |
555 }; | 554 }; |
556 | 555 |
557 } // namespace content | 556 } // namespace content |
558 | 557 |
559 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ | 558 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |
OLD | NEW |