Chromium Code Reviews| 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_embedder.h" | 5 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | |
| 7 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 8 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 9 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 9 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 10 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 10 #include "content/browser/renderer_host/render_view_host_impl.h" | 11 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 11 #include "content/browser/web_contents/web_contents_impl.h" | 12 #include "content/browser/web_contents/web_contents_impl.h" |
| 12 #include "content/common/browser_plugin_messages.h" | 13 #include "content/common/browser_plugin_messages.h" |
| 13 #include "content/common/gpu/gpu_messages.h" | 14 #include "content/common/gpu/gpu_messages.h" |
| 14 #include "content/public/browser/notification_details.h" | 15 #include "content/public/browser/notification_details.h" |
| 15 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 16 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
| 17 #include "content/public/browser/notification_types.h" | 18 #include "content/public/browser/notification_types.h" |
| 18 #include "content/public/browser/user_metrics.h" | 19 #include "content/public/browser/user_metrics.h" |
| 20 #include "content/public/common/content_switches.h" | |
| 19 #include "content/public/common/result_codes.h" | 21 #include "content/public/common/result_codes.h" |
| 20 #include "content/public/common/url_constants.h" | 22 #include "content/public/common/url_constants.h" |
| 21 #include "net/base/escape.h" | 23 #include "net/base/escape.h" |
| 22 | 24 |
| 23 namespace content { | 25 namespace content { |
| 24 | 26 |
| 25 // static | 27 // static |
| 26 BrowserPluginHostFactory* BrowserPluginEmbedder::factory_ = NULL; | 28 BrowserPluginHostFactory* BrowserPluginEmbedder::factory_ = NULL; |
| 27 | 29 |
| 28 BrowserPluginEmbedder::BrowserPluginEmbedder( | 30 BrowserPluginEmbedder::BrowserPluginEmbedder( |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 53 } | 55 } |
| 54 return new BrowserPluginEmbedder(web_contents, render_view_host); | 56 return new BrowserPluginEmbedder(web_contents, render_view_host); |
| 55 } | 57 } |
| 56 | 58 |
| 57 void BrowserPluginEmbedder::CreateGuest( | 59 void BrowserPluginEmbedder::CreateGuest( |
| 58 int instance_id, | 60 int instance_id, |
| 59 int routing_id, | 61 int routing_id, |
| 60 BrowserPluginGuest* guest_opener, | 62 BrowserPluginGuest* guest_opener, |
| 61 const BrowserPluginHostMsg_CreateGuest_Params& params) { | 63 const BrowserPluginHostMsg_CreateGuest_Params& params) { |
| 62 WebContentsImpl* guest_web_contents = NULL; | 64 WebContentsImpl* guest_web_contents = NULL; |
| 65 SiteInstance* guest_site_instance = NULL; | |
| 63 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); | 66 BrowserPluginGuest* guest = GetGuestByInstanceID(instance_id); |
| 64 CHECK(!guest); | 67 CHECK(!guest); |
| 65 | 68 |
| 66 // Validate that the partition id coming from the renderer is valid UTF-8, | 69 // Validate that the partition id coming from the renderer is valid UTF-8, |
| 67 // since we depend on this in other parts of the code, such as FilePath | 70 // since we depend on this in other parts of the code, such as FilePath |
| 68 // creation. If the validation fails, treat it as a bad message and kill the | 71 // creation. If the validation fails, treat it as a bad message and kill the |
| 69 // renderer process. | 72 // renderer process. |
| 70 if (!IsStringUTF8(params.storage_partition_id)) { | 73 if (!IsStringUTF8(params.storage_partition_id)) { |
| 71 content::RecordAction(UserMetricsAction("BadMessageTerminate_BPE")); | 74 content::RecordAction(UserMetricsAction("BadMessageTerminate_BPE")); |
| 72 base::KillProcess(render_view_host_->GetProcess()->GetHandle(), | 75 base::KillProcess(render_view_host_->GetProcess()->GetHandle(), |
| 73 content::RESULT_CODE_KILLED_BAD_MESSAGE, false); | 76 content::RESULT_CODE_KILLED_BAD_MESSAGE, false); |
| 74 return; | 77 return; |
| 75 } | 78 } |
| 76 | 79 |
| 77 const std::string& host = | 80 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 78 render_view_host_->GetSiteInstance()->GetSiteURL().host(); | 81 if (command_line.HasSwitch(switches::kSitePerProcess)) { |
| 79 std::string url_encoded_partition = net::EscapeQueryParamValue( | 82 // When --site-per-process is specified, the behavior of BrowserPlugin |
| 80 params.storage_partition_id, false); | 83 // as <webview> is broken and we use it for rendering out-of-process |
| 84 // iframes instead. We use the src URL sent by the renderer to find the | |
| 85 // right process in which to place this instance. | |
| 86 // Note: Since BrowserPlugin doesn't support cross-process navigation, | |
| 87 // the instance will stay in the initially assigned process, regardless | |
| 88 // of the site it is navigated to. | |
| 89 // TODO(nasko): Fix this, and such that cross-process navigations are | |
| 90 // supported. | |
| 91 guest_site_instance = | |
| 92 web_contents()->GetSiteInstance()->GetRelatedSiteInstance( | |
|
Charlie Reis
2013/01/23 00:17:37
nit: 2 more spaces needed here.
| |
| 93 GURL(params.src)); | |
| 94 } else { | |
| 95 const std::string& host = | |
| 96 render_view_host_->GetSiteInstance()->GetSiteURL().host(); | |
| 97 std::string url_encoded_partition = net::EscapeQueryParamValue( | |
| 98 params.storage_partition_id, false); | |
| 81 | 99 |
| 82 SiteInstance* guest_site_instance = NULL; | 100 if (guest_opener) { |
| 83 if (guest_opener) { | 101 guest_site_instance = guest_opener->GetWebContents()->GetSiteInstance(); |
| 84 guest_site_instance = guest_opener->GetWebContents()->GetSiteInstance(); | 102 } else { |
| 85 } else { | 103 // The SiteInstance of a given webview tag is based on the fact that it's |
| 86 // The SiteInstance of a given webview tag is based on the fact that it's a | 104 // a guest process in addition to which platform application the tag |
| 87 // guest process in addition to which platform application the tag belongs | 105 // belongs to and what storage partition is in use, rather than the URL |
| 88 // to and what storage partition is in use, rather than the URL that the tag | 106 // that the tag is being navigated to. |
| 89 // is being navigated to. | 107 GURL guest_site( |
| 90 GURL guest_site( | 108 base::StringPrintf("%s://%s/%s?%s", chrome::kGuestScheme, |
| 91 base::StringPrintf("%s://%s/%s?%s", chrome::kGuestScheme, | 109 host.c_str(), |
| 92 host.c_str(), params.persist_storage ? "persist" : "", | 110 params.persist_storage ? "persist" : "", |
| 93 url_encoded_partition.c_str())); | 111 url_encoded_partition.c_str())); |
| 94 | 112 |
| 95 // If we already have a webview tag in the same app using the same storage | 113 // If we already have a webview tag in the same app using the same storage |
| 96 // partition, we should use the same SiteInstance so the existing tag and | 114 // partition, we should use the same SiteInstance so the existing tag and |
| 97 // the new tag can script each other. | 115 // the new tag can script each other. |
| 98 for (ContainerInstanceMap::const_iterator it = | 116 for (ContainerInstanceMap::const_iterator it = |
| 99 guest_web_contents_by_instance_id_.begin(); | 117 guest_web_contents_by_instance_id_.begin(); |
| 100 it != guest_web_contents_by_instance_id_.end(); ++it) { | 118 it != guest_web_contents_by_instance_id_.end(); ++it) { |
| 101 if (it->second->GetSiteInstance()->GetSiteURL() == guest_site) { | 119 if (it->second->GetSiteInstance()->GetSiteURL() == guest_site) { |
| 102 guest_site_instance = it->second->GetSiteInstance(); | 120 guest_site_instance = it->second->GetSiteInstance(); |
| 103 break; | 121 break; |
| 122 } | |
| 123 } | |
| 124 if (!guest_site_instance) { | |
| 125 // Create the SiteInstance in a new BrowsingInstance, which will ensure | |
| 126 // that webview tags are also not allowed to send messages across | |
| 127 // different partitions. | |
| 128 guest_site_instance = SiteInstance::CreateForURL( | |
| 129 web_contents()->GetBrowserContext(), guest_site); | |
| 104 } | 130 } |
| 105 } | 131 } |
| 106 if (!guest_site_instance) { | |
| 107 // Create the SiteInstance in a new BrowsingInstance, which will ensure | |
| 108 // that webview tags are also not allowed to send messages across | |
| 109 // different partitions. | |
| 110 guest_site_instance = SiteInstance::CreateForURL( | |
| 111 web_contents()->GetBrowserContext(), guest_site); | |
| 112 } | |
| 113 } | 132 } |
| 133 | |
| 114 WebContentsImpl* opener_web_contents = static_cast<WebContentsImpl*>( | 134 WebContentsImpl* opener_web_contents = static_cast<WebContentsImpl*>( |
| 115 guest_opener ? guest_opener->GetWebContents() : NULL); | 135 guest_opener ? guest_opener->GetWebContents() : NULL); |
| 116 guest_web_contents = WebContentsImpl::CreateGuest( | 136 guest_web_contents = WebContentsImpl::CreateGuest( |
| 117 web_contents()->GetBrowserContext(), | 137 web_contents()->GetBrowserContext(), |
| 118 guest_site_instance, | 138 guest_site_instance, |
| 119 routing_id, | 139 routing_id, |
| 120 opener_web_contents, | 140 opener_web_contents, |
| 121 instance_id, | 141 instance_id, |
| 122 params); | 142 params); |
| 123 | 143 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 uint32 sync_point) { | 348 uint32 sync_point) { |
| 329 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; | 349 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; |
| 330 ack_params.mailbox_name = mailbox_name; | 350 ack_params.mailbox_name = mailbox_name; |
| 331 ack_params.sync_point = sync_point; | 351 ack_params.sync_point = sync_point; |
| 332 RenderWidgetHostImpl::AcknowledgeBufferPresent(route_id, | 352 RenderWidgetHostImpl::AcknowledgeBufferPresent(route_id, |
| 333 gpu_host_id, | 353 gpu_host_id, |
| 334 ack_params); | 354 ack_params); |
| 335 } | 355 } |
| 336 | 356 |
| 337 } // namespace content | 357 } // namespace content |
| OLD | NEW |