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/site_instance_impl.h" | 5 #include "content/browser/site_instance_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "content/browser/browsing_instance.h" | 8 #include "content/browser/browsing_instance.h" |
9 #include "content/browser/child_process_security_policy_impl.h" | 9 #include "content/browser/child_process_security_policy_impl.h" |
| 10 #include "content/browser/frame_host/debug_urls.h" |
10 #include "content/browser/renderer_host/render_process_host_impl.h" | 11 #include "content/browser/renderer_host/render_process_host_impl.h" |
11 #include "content/browser/storage_partition_impl.h" | 12 #include "content/browser/storage_partition_impl.h" |
12 #include "content/public/browser/content_browser_client.h" | 13 #include "content/public/browser/content_browser_client.h" |
13 #include "content/public/browser/render_process_host_factory.h" | 14 #include "content/public/browser/render_process_host_factory.h" |
14 #include "content/public/browser/web_ui_controller_factory.h" | 15 #include "content/public/browser/web_ui_controller_factory.h" |
15 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
16 #include "content/public/common/url_constants.h" | 17 #include "content/public/common/url_constants.h" |
17 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 18 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
18 | 19 |
19 namespace content { | 20 namespace content { |
20 | 21 |
21 static bool IsURLSameAsAnySiteInstance(const GURL& url) { | |
22 if (!url.is_valid()) | |
23 return false; | |
24 | |
25 // We treat javascript: as the same site as any URL since it is actually | |
26 // a modifier on existing pages. | |
27 if (url.SchemeIs(kJavaScriptScheme)) | |
28 return true; | |
29 | |
30 return url == GURL(kChromeUICrashURL) || | |
31 url == GURL(kChromeUIKillURL) || | |
32 url == GURL(kChromeUIHangURL) || | |
33 url == GURL(kChromeUIShorthangURL); | |
34 } | |
35 | |
36 const RenderProcessHostFactory* | 22 const RenderProcessHostFactory* |
37 SiteInstanceImpl::g_render_process_host_factory_ = NULL; | 23 SiteInstanceImpl::g_render_process_host_factory_ = NULL; |
38 int32 SiteInstanceImpl::next_site_instance_id_ = 1; | 24 int32 SiteInstanceImpl::next_site_instance_id_ = 1; |
39 | 25 |
40 SiteInstanceImpl::SiteInstanceImpl(BrowsingInstance* browsing_instance) | 26 SiteInstanceImpl::SiteInstanceImpl(BrowsingInstance* browsing_instance) |
41 : id_(next_site_instance_id_++), | 27 : id_(next_site_instance_id_++), |
42 active_view_count_(0), | 28 active_view_count_(0), |
43 browsing_instance_(browsing_instance), | 29 browsing_instance_(browsing_instance), |
44 process_(NULL), | 30 process_(NULL), |
45 has_site_(false) { | 31 has_site_(false) { |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 // Having no process isn't a problem, since we'll assign it correctly. | 189 // Having no process isn't a problem, since we'll assign it correctly. |
204 // Note that HasProcess() may return true if process_ is null, in | 190 // Note that HasProcess() may return true if process_ is null, in |
205 // process-per-site cases where there's an existing process available. | 191 // process-per-site cases where there's an existing process available. |
206 // We want to use such a process in the IsSuitableHost check, so we | 192 // We want to use such a process in the IsSuitableHost check, so we |
207 // may end up assigning process_ in the GetProcess() call below. | 193 // may end up assigning process_ in the GetProcess() call below. |
208 if (!HasProcess()) | 194 if (!HasProcess()) |
209 return false; | 195 return false; |
210 | 196 |
211 // If the URL to navigate to can be associated with any site instance, | 197 // If the URL to navigate to can be associated with any site instance, |
212 // we want to keep it in the same process. | 198 // we want to keep it in the same process. |
213 if (IsURLSameAsAnySiteInstance(url)) | 199 if (IsRendererDebugURL(url)) |
214 return false; | 200 return false; |
215 | 201 |
216 // If the site URL is an extension (e.g., for hosted apps or WebUI) but the | 202 // If the site URL is an extension (e.g., for hosted apps or WebUI) but the |
217 // process is not (or vice versa), make sure we notice and fix it. | 203 // process is not (or vice versa), make sure we notice and fix it. |
218 GURL site_url = GetSiteForURL(browsing_instance_->browser_context(), url); | 204 GURL site_url = GetSiteForURL(browsing_instance_->browser_context(), url); |
219 return !RenderProcessHostImpl::IsSuitableHost( | 205 return !RenderProcessHostImpl::IsSuitableHost( |
220 GetProcess(), browsing_instance_->browser_context(), site_url); | 206 GetProcess(), browsing_instance_->browser_context(), site_url); |
221 } | 207 } |
222 | 208 |
223 void SiteInstanceImpl::set_render_process_host_factory( | 209 void SiteInstanceImpl::set_render_process_host_factory( |
(...skipping 28 matching lines...) Expand all Loading... |
252 GURL url2 = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url2); | 238 GURL url2 = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url2); |
253 | 239 |
254 // We infer web site boundaries based on the registered domain name of the | 240 // We infer web site boundaries based on the registered domain name of the |
255 // top-level page and the scheme. We do not pay attention to the port if | 241 // top-level page and the scheme. We do not pay attention to the port if |
256 // one is present, because pages served from different ports can still | 242 // one is present, because pages served from different ports can still |
257 // access each other if they change their document.domain variable. | 243 // access each other if they change their document.domain variable. |
258 | 244 |
259 // Some special URLs will match the site instance of any other URL. This is | 245 // Some special URLs will match the site instance of any other URL. This is |
260 // done before checking both of them for validity, since we want these URLs | 246 // done before checking both of them for validity, since we want these URLs |
261 // to have the same site instance as even an invalid one. | 247 // to have the same site instance as even an invalid one. |
262 if (IsURLSameAsAnySiteInstance(url1) || IsURLSameAsAnySiteInstance(url2)) | 248 if (IsRendererDebugURL(url1) || IsRendererDebugURL(url2)) |
263 return true; | 249 return true; |
264 | 250 |
265 // If either URL is invalid, they aren't part of the same site. | 251 // If either URL is invalid, they aren't part of the same site. |
266 if (!url1.is_valid() || !url2.is_valid()) | 252 if (!url1.is_valid() || !url2.is_valid()) |
267 return false; | 253 return false; |
268 | 254 |
269 // If the schemes differ, they aren't part of the same site. | 255 // If the schemes differ, they aren't part of the same site. |
270 if (url1.scheme() != url2.scheme()) | 256 if (url1.scheme() != url2.scheme()) |
271 return false; | 257 return false; |
272 | 258 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 323 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
338 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) || | 324 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) || |
339 command_line.HasSwitch(switches::kSitePerProcess)) { | 325 command_line.HasSwitch(switches::kSitePerProcess)) { |
340 ChildProcessSecurityPolicyImpl* policy = | 326 ChildProcessSecurityPolicyImpl* policy = |
341 ChildProcessSecurityPolicyImpl::GetInstance(); | 327 ChildProcessSecurityPolicyImpl::GetInstance(); |
342 policy->LockToOrigin(process_->GetID(), site_); | 328 policy->LockToOrigin(process_->GetID(), site_); |
343 } | 329 } |
344 } | 330 } |
345 | 331 |
346 } // namespace content | 332 } // namespace content |
OLD | NEW |