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 // We use the src URL passed by the webview tag to allow us to group |
| 80 params.storage_partition_id, false); | 83 // same site iframes in the same process when running in --site-per-process |
|
Charlie Reis
2013/01/17 19:44:54
Can you change this comment a bit? We're not tech
nasko
2013/01/17 22:19:13
Done.
| |
| 84 // model. | |
| 85 guest_site_instance = | |
| 86 web_contents()->GetSiteInstance()->GetRelatedSiteInstance( | |
| 87 GURL(params.src)); | |
| 88 } else { | |
| 89 const std::string& host = | |
| 90 render_view_host_->GetSiteInstance()->GetSiteURL().host(); | |
| 91 std::string url_encoded_partition = net::EscapeQueryParamValue( | |
| 92 params.storage_partition_id, false); | |
| 81 | 93 |
| 82 SiteInstance* guest_site_instance = NULL; | 94 if (guest_opener) { |
| 83 if (guest_opener) { | 95 guest_site_instance = guest_opener->GetWebContents()->GetSiteInstance(); |
| 84 guest_site_instance = guest_opener->GetWebContents()->GetSiteInstance(); | 96 } else { |
| 85 } else { | 97 // 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 | 98 // a guest process in addition to which platform application the tag |
| 87 // guest process in addition to which platform application the tag belongs | 99 // 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 | 100 // that the tag is being navigated to. |
| 89 // is being navigated to. | 101 GURL guest_site( |
| 90 GURL guest_site( | 102 base::StringPrintf("%s://%s/%s?%s", chrome::kGuestScheme, |
| 91 base::StringPrintf("%s://%s/%s?%s", chrome::kGuestScheme, | 103 host.c_str(), |
| 92 host.c_str(), params.persist_storage ? "persist" : "", | 104 params.persist_storage ? "persist" : "", |
| 93 url_encoded_partition.c_str())); | 105 url_encoded_partition.c_str())); |
| 94 | 106 |
| 95 // If we already have a webview tag in the same app using the same storage | 107 // 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 | 108 // partition, we should use the same SiteInstance so the existing tag and |
| 97 // the new tag can script each other. | 109 // the new tag can script each other. |
| 98 for (ContainerInstanceMap::const_iterator it = | 110 for (ContainerInstanceMap::const_iterator it = |
| 99 guest_web_contents_by_instance_id_.begin(); | 111 guest_web_contents_by_instance_id_.begin(); |
| 100 it != guest_web_contents_by_instance_id_.end(); ++it) { | 112 it != guest_web_contents_by_instance_id_.end(); ++it) { |
| 101 if (it->second->GetSiteInstance()->GetSiteURL() == guest_site) { | 113 if (it->second->GetSiteInstance()->GetSiteURL() == guest_site) { |
| 102 guest_site_instance = it->second->GetSiteInstance(); | 114 guest_site_instance = it->second->GetSiteInstance(); |
| 103 break; | 115 break; |
| 116 } | |
| 117 } | |
| 118 if (!guest_site_instance) { | |
| 119 // Create the SiteInstance in a new BrowsingInstance, which will ensure | |
| 120 // that webview tags are also not allowed to send messages across | |
| 121 // different partitions. | |
| 122 guest_site_instance = SiteInstance::CreateForURL( | |
| 123 web_contents()->GetBrowserContext(), guest_site); | |
| 104 } | 124 } |
| 105 } | 125 } |
| 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 } | 126 } |
| 127 | |
| 114 WebContentsImpl* opener_web_contents = static_cast<WebContentsImpl*>( | 128 WebContentsImpl* opener_web_contents = static_cast<WebContentsImpl*>( |
| 115 guest_opener ? guest_opener->GetWebContents() : NULL); | 129 guest_opener ? guest_opener->GetWebContents() : NULL); |
| 116 guest_web_contents = WebContentsImpl::CreateGuest( | 130 guest_web_contents = WebContentsImpl::CreateGuest( |
| 117 web_contents()->GetBrowserContext(), | 131 web_contents()->GetBrowserContext(), |
| 118 guest_site_instance, | 132 guest_site_instance, |
| 119 routing_id, | 133 routing_id, |
| 120 opener_web_contents, | 134 opener_web_contents, |
| 121 instance_id, | 135 instance_id, |
| 122 params); | 136 params); |
| 123 | 137 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 146 AddGuest(instance_id, guest_web_contents); | 160 AddGuest(instance_id, guest_web_contents); |
| 147 guest_web_contents->SetDelegate(guest); | 161 guest_web_contents->SetDelegate(guest); |
| 148 | 162 |
| 149 // Create a swapped out RenderView for the guest in the embedder render | 163 // Create a swapped out RenderView for the guest in the embedder render |
| 150 // process, so that the embedder can access the guest's window object. | 164 // process, so that the embedder can access the guest's window object. |
| 151 int guest_routing_id = | 165 int guest_routing_id = |
| 152 static_cast<WebContentsImpl*>(guest->GetWebContents())-> | 166 static_cast<WebContentsImpl*>(guest->GetWebContents())-> |
| 153 CreateSwappedOutRenderView(web_contents()->GetSiteInstance()); | 167 CreateSwappedOutRenderView(web_contents()->GetSiteInstance()); |
| 154 render_view_host_->Send(new BrowserPluginMsg_GuestContentWindowReady( | 168 render_view_host_->Send(new BrowserPluginMsg_GuestContentWindowReady( |
| 155 render_view_host_->GetRoutingID(), instance_id, guest_routing_id)); | 169 render_view_host_->GetRoutingID(), instance_id, guest_routing_id)); |
| 156 | |
|
Charlie Reis
2013/01/17 19:44:54
No need for this change.
nasko
2013/01/17 22:19:13
Done.
| |
| 157 guest->Initialize(params, guest_web_contents->GetRenderViewHost()); | 170 guest->Initialize(params, guest_web_contents->GetRenderViewHost()); |
| 158 } | 171 } |
| 159 | 172 |
| 160 BrowserPluginGuest* BrowserPluginEmbedder::GetGuestByInstanceID( | 173 BrowserPluginGuest* BrowserPluginEmbedder::GetGuestByInstanceID( |
| 161 int instance_id) const { | 174 int instance_id) const { |
| 162 ContainerInstanceMap::const_iterator it = | 175 ContainerInstanceMap::const_iterator it = |
| 163 guest_web_contents_by_instance_id_.find(instance_id); | 176 guest_web_contents_by_instance_id_.find(instance_id); |
| 164 if (it != guest_web_contents_by_instance_id_.end()) | 177 if (it != guest_web_contents_by_instance_id_.end()) |
| 165 return static_cast<WebContentsImpl*>(it->second)->GetBrowserPluginGuest(); | 178 return static_cast<WebContentsImpl*>(it->second)->GetBrowserPluginGuest(); |
| 166 return NULL; | 179 return NULL; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 355 uint32 sync_point) { | 368 uint32 sync_point) { |
| 356 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; | 369 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; |
| 357 ack_params.mailbox_name = mailbox_name; | 370 ack_params.mailbox_name = mailbox_name; |
| 358 ack_params.sync_point = sync_point; | 371 ack_params.sync_point = sync_point; |
| 359 RenderWidgetHostImpl::AcknowledgeBufferPresent(route_id, | 372 RenderWidgetHostImpl::AcknowledgeBufferPresent(route_id, |
| 360 gpu_host_id, | 373 gpu_host_id, |
| 361 ack_params); | 374 ack_params); |
| 362 } | 375 } |
| 363 | 376 |
| 364 } // namespace content | 377 } // namespace content |
| OLD | NEW |