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 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 5 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "content/browser/browser_plugin/browser_plugin_embedder.h" | 12 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
13 #include "content/browser/browser_plugin/browser_plugin_guest_manager.h" | |
14 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 13 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
15 #include "content/browser/browser_thread_impl.h" | 14 #include "content/browser/browser_thread_impl.h" |
16 #include "content/browser/child_process_security_policy_impl.h" | 15 #include "content/browser/child_process_security_policy_impl.h" |
17 #include "content/browser/frame_host/render_frame_host_impl.h" | 16 #include "content/browser/frame_host/render_frame_host_impl.h" |
18 #include "content/browser/frame_host/render_widget_host_view_guest.h" | 17 #include "content/browser/frame_host/render_widget_host_view_guest.h" |
19 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 18 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
20 #include "content/browser/renderer_host/render_view_host_impl.h" | 19 #include "content/browser/renderer_host/render_view_host_impl.h" |
21 #include "content/browser/renderer_host/render_widget_host_impl.h" | 20 #include "content/browser/renderer_host/render_widget_host_impl.h" |
22 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 21 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
23 #include "content/browser/web_contents/web_contents_impl.h" | 22 #include "content/browser/web_contents/web_contents_impl.h" |
24 #include "content/browser/web_contents/web_contents_view_guest.h" | 23 #include "content/browser/web_contents/web_contents_view_guest.h" |
25 #include "content/common/browser_plugin/browser_plugin_constants.h" | 24 #include "content/common/browser_plugin/browser_plugin_constants.h" |
26 #include "content/common/browser_plugin/browser_plugin_messages.h" | 25 #include "content/common/browser_plugin/browser_plugin_messages.h" |
27 #include "content/common/content_constants_internal.h" | 26 #include "content/common/content_constants_internal.h" |
28 #include "content/common/drag_messages.h" | 27 #include "content/common/drag_messages.h" |
29 #include "content/common/input_messages.h" | 28 #include "content/common/input_messages.h" |
30 #include "content/common/view_messages.h" | 29 #include "content/common/view_messages.h" |
31 #include "content/port/browser/render_view_host_delegate_view.h" | 30 #include "content/port/browser/render_view_host_delegate_view.h" |
32 #include "content/public/browser/browser_context.h" | 31 #include "content/public/browser/browser_context.h" |
32 #include "content/public/browser/browser_plugin_guest_manager_delegate.h" | |
33 #include "content/public/browser/content_browser_client.h" | 33 #include "content/public/browser/content_browser_client.h" |
34 #include "content/public/browser/navigation_controller.h" | 34 #include "content/public/browser/navigation_controller.h" |
35 #include "content/public/browser/render_widget_host_view.h" | 35 #include "content/public/browser/render_widget_host_view.h" |
36 #include "content/public/browser/user_metrics.h" | 36 #include "content/public/browser/user_metrics.h" |
37 #include "content/public/browser/web_contents_observer.h" | 37 #include "content/public/browser/web_contents_observer.h" |
38 #include "content/public/common/context_menu_params.h" | 38 #include "content/public/common/context_menu_params.h" |
39 #include "content/public/common/drop_data.h" | 39 #include "content/public/common/drop_data.h" |
40 #include "content/public/common/media_stream_request.h" | 40 #include "content/public/common/media_stream_request.h" |
41 #include "content/public/common/result_codes.h" | 41 #include "content/public/common/result_codes.h" |
42 #include "content/public/common/url_constants.h" | 42 #include "content/public/common/url_constants.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 embedder_render_process_id, | 104 embedder_render_process_id, |
105 base::Bind(&BrowserPluginGuest::NewWindowRequest::RespondInternal, | 105 base::Bind(&BrowserPluginGuest::NewWindowRequest::RespondInternal, |
106 base::Unretained(this), | 106 base::Unretained(this), |
107 should_allow)); | 107 should_allow)); |
108 } | 108 } |
109 | 109 |
110 private: | 110 private: |
111 virtual ~NewWindowRequest() {} | 111 virtual ~NewWindowRequest() {} |
112 | 112 |
113 void RespondInternal(bool should_allow, | 113 void RespondInternal(bool should_allow, |
114 BrowserPluginGuest* guest) { | 114 WebContents* guest_web_contents) { |
115 if (!guest) { | 115 if (!guest_web_contents) { |
116 VLOG(0) << "Guest not found. Instance ID: " << instance_id_; | 116 VLOG(0) << "Guest not found. Instance ID: " << instance_id_; |
117 return; | 117 return; |
118 } | 118 } |
119 | 119 |
120 BrowserPluginGuest* guest = | |
121 static_cast<WebContentsImpl*>(guest_web_contents)-> | |
122 GetBrowserPluginGuest(); | |
lazyboy
2014/05/05 21:40:54
DCHECK(guest)?
Fady Samuel
2014/05/07 17:32:59
Done.
| |
120 // If we do not destroy the guest then we allow the new window. | 123 // If we do not destroy the guest then we allow the new window. |
121 if (!should_allow) | 124 if (!should_allow) |
122 guest->Destroy(); | 125 guest->Destroy(); |
123 } | 126 } |
124 | 127 |
125 int instance_id_; | 128 int instance_id_; |
126 }; | 129 }; |
127 | 130 |
128 namespace { | 131 namespace { |
129 std::string WindowOpenDispositionToString( | 132 std::string WindowOpenDispositionToString( |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 BrowserPluginGuestDelegate::PermissionResponseCallback callback = | 302 BrowserPluginGuestDelegate::PermissionResponseCallback callback = |
300 base::Bind(&BrowserPluginGuest::RespondToPermissionRequest, | 303 base::Bind(&BrowserPluginGuest::RespondToPermissionRequest, |
301 AsWeakPtr(), | 304 AsWeakPtr(), |
302 request_id); | 305 request_id); |
303 delegate_->RequestPermission( | 306 delegate_->RequestPermission( |
304 permission_type, request_info, callback, request->AllowedByDefault()); | 307 permission_type, request_info, callback, request->AllowedByDefault()); |
305 } | 308 } |
306 | 309 |
307 BrowserPluginGuest* BrowserPluginGuest::CreateNewGuestWindow( | 310 BrowserPluginGuest* BrowserPluginGuest::CreateNewGuestWindow( |
308 const OpenURLParams& params) { | 311 const OpenURLParams& params) { |
309 BrowserPluginGuestManager* guest_manager = GetBrowserPluginGuestManager(); | 312 BrowserPluginGuestManagerDelegate* guest_manager = |
313 GetBrowserPluginGuestManager(); | |
310 | 314 |
311 // Allocate a new instance ID for the new guest. | 315 // Allocate a new instance ID for the new guest. |
312 int instance_id = guest_manager->GetNextInstanceID(); | 316 int instance_id = guest_manager->GetNextInstanceID(); |
313 | 317 |
314 // Set the attach params to use the same partition as the opener. | 318 // Set the attach params to use the same partition as the opener. |
315 // We pull the partition information from the site's URL, which is of the form | 319 // We pull the partition information from the site's URL, which is of the form |
316 // guest://site/{persist}?{partition_name}. | 320 // guest://site/{persist}?{partition_name}. |
317 const GURL& site_url = GetWebContents()->GetSiteInstance()->GetSiteURL(); | 321 const GURL& site_url = GetWebContents()->GetSiteInstance()->GetSiteURL(); |
318 | 322 |
319 // The new guest gets a copy of this guest's extra params so that the content | 323 // The new guest gets a copy of this guest's extra params so that the content |
320 // embedder exposes the same API for this guest as its opener. | 324 // embedder exposes the same API for this guest as its opener. |
321 scoped_ptr<base::DictionaryValue> extra_params( | 325 scoped_ptr<base::DictionaryValue> extra_params( |
322 extra_attach_params_->DeepCopy()); | 326 extra_attach_params_->DeepCopy()); |
323 StorageInfo storage_info; | 327 StorageInfo storage_info; |
324 storage_info.partition_id = site_url.query(); | 328 storage_info.partition_id = site_url.query(); |
325 storage_info.persist = | 329 storage_info.persist = |
326 site_url.path().find("persist") != std::string::npos; | 330 site_url.path().find("persist") != std::string::npos; |
327 BrowserPluginGuest* new_guest = | 331 WebContents* new_guest_web_contents = |
328 guest_manager->CreateGuest(GetWebContents()->GetSiteInstance(), | 332 guest_manager->CreateGuest(GetWebContents()->GetSiteInstance(), |
329 instance_id, | 333 instance_id, |
330 storage_info, | 334 storage_info, |
331 extra_params.Pass()); | 335 extra_params.Pass()); |
336 BrowserPluginGuest* new_guest = | |
337 static_cast<WebContentsImpl*>(new_guest_web_contents)-> | |
338 GetBrowserPluginGuest(); | |
332 if (new_guest->delegate_) | 339 if (new_guest->delegate_) |
333 new_guest->delegate_->SetOpener(GetWebContents()); | 340 new_guest->delegate_->SetOpener(GetWebContents()); |
334 | 341 |
335 // Take ownership of |new_guest|. | 342 // Take ownership of |new_guest|. |
336 pending_new_windows_.insert( | 343 pending_new_windows_.insert( |
337 std::make_pair(new_guest, NewWindowInfo(params.url, std::string()))); | 344 std::make_pair(new_guest, NewWindowInfo(params.url, std::string()))); |
338 | 345 |
339 // Request permission to show the new window. | 346 // Request permission to show the new window. |
340 RequestNewWindowPermission(params.disposition, gfx::Rect(), | 347 RequestNewWindowPermission(params.disposition, gfx::Rect(), |
341 params.user_gesture, new_guest->GetWebContents()); | 348 params.user_gesture, new_guest->GetWebContents()); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
567 void BrowserPluginGuest::CopyFromCompositingSurface( | 574 void BrowserPluginGuest::CopyFromCompositingSurface( |
568 gfx::Rect src_subrect, | 575 gfx::Rect src_subrect, |
569 gfx::Size dst_size, | 576 gfx::Size dst_size, |
570 const base::Callback<void(bool, const SkBitmap&)>& callback) { | 577 const base::Callback<void(bool, const SkBitmap&)>& callback) { |
571 copy_request_callbacks_.insert(std::make_pair(++copy_request_id_, callback)); | 578 copy_request_callbacks_.insert(std::make_pair(++copy_request_id_, callback)); |
572 SendMessageToEmbedder( | 579 SendMessageToEmbedder( |
573 new BrowserPluginMsg_CopyFromCompositingSurface(instance_id(), | 580 new BrowserPluginMsg_CopyFromCompositingSurface(instance_id(), |
574 copy_request_id_, src_subrect, dst_size)); | 581 copy_request_id_, src_subrect, dst_size)); |
575 } | 582 } |
576 | 583 |
577 BrowserPluginGuestManager* | 584 BrowserPluginGuestManagerDelegate* |
578 BrowserPluginGuest::GetBrowserPluginGuestManager() const { | 585 BrowserPluginGuest::GetBrowserPluginGuestManager() const { |
579 return BrowserPluginGuestManager::FromBrowserContext( | 586 return GetWebContents()->GetBrowserContext()->GetGuestManagerDelegate(); |
580 GetWebContents()->GetBrowserContext()); | |
581 } | 587 } |
582 | 588 |
583 // screen. | 589 // screen. |
584 gfx::Rect BrowserPluginGuest::ToGuestRect(const gfx::Rect& bounds) { | 590 gfx::Rect BrowserPluginGuest::ToGuestRect(const gfx::Rect& bounds) { |
585 gfx::Rect guest_rect(bounds); | 591 gfx::Rect guest_rect(bounds); |
586 guest_rect.Offset(guest_window_rect_.OffsetFromOrigin()); | 592 guest_rect.Offset(guest_window_rect_.OffsetFromOrigin()); |
587 return guest_rect; | 593 return guest_rect; |
588 } | 594 } |
589 | 595 |
590 void BrowserPluginGuest::EmbedderVisibilityChanged(bool visible) { | 596 void BrowserPluginGuest::EmbedderVisibilityChanged(bool visible) { |
(...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1555 const GURL& url) { | 1561 const GURL& url) { |
1556 if (!url.is_valid()) { | 1562 if (!url.is_valid()) { |
1557 callback.Run(false); | 1563 callback.Run(false); |
1558 return; | 1564 return; |
1559 } | 1565 } |
1560 | 1566 |
1561 delegate_->CanDownload(request_method, url, callback); | 1567 delegate_->CanDownload(request_method, url, callback); |
1562 } | 1568 } |
1563 | 1569 |
1564 } // namespace content | 1570 } // namespace content |
OLD | NEW |