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/renderer_host/render_process_host_impl.h" | 10 #include "content/browser/renderer_host/render_process_host_impl.h" |
11 #include "content/browser/storage_partition_impl.h" | 11 #include "content/browser/storage_partition_impl.h" |
12 #include "content/public/browser/content_browser_client.h" | 12 #include "content/public/browser/content_browser_client.h" |
13 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
14 #include "content/public/browser/notification_types.h" | 14 #include "content/public/browser/notification_types.h" |
15 #include "content/public/browser/render_process_host_factory.h" | 15 #include "content/public/browser/render_process_host_factory.h" |
16 #include "content/public/browser/web_ui_controller_factory.h" | 16 #include "content/public/browser/web_ui_controller_factory.h" |
17 #include "content/public/common/content_switches.h" | 17 #include "content/public/common/content_switches.h" |
18 #include "content/public/common/url_constants.h" | 18 #include "content/public/common/url_constants.h" |
19 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 19 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
20 | 20 |
21 using content::BrowserContext; | 21 namespace content { |
22 using content::RenderProcessHost; | |
23 using content::RenderProcessHostImpl; | |
24 using content::SiteInstance; | |
25 using content::StoragePartitionImpl; | |
26 using content::WebUIControllerFactory; | |
27 | 22 |
28 static bool IsURLSameAsAnySiteInstance(const GURL& url) { | 23 static bool IsURLSameAsAnySiteInstance(const GURL& url) { |
29 if (!url.is_valid()) | 24 if (!url.is_valid()) |
30 return false; | 25 return false; |
31 | 26 |
32 // We treat javascript: as the same site as any URL since it is actually | 27 // We treat javascript: as the same site as any URL since it is actually |
33 // a modifier on existing pages. | 28 // a modifier on existing pages. |
34 if (url.SchemeIs(chrome::kJavaScriptScheme)) | 29 if (url.SchemeIs(chrome::kJavaScriptScheme)) |
35 return true; | 30 return true; |
36 | 31 |
37 return url == GURL(chrome::kChromeUICrashURL) || | 32 return url == GURL(chrome::kChromeUICrashURL) || |
38 url == GURL(chrome::kChromeUIKillURL) || | 33 url == GURL(chrome::kChromeUIKillURL) || |
39 url == GURL(chrome::kChromeUIHangURL) || | 34 url == GURL(chrome::kChromeUIHangURL) || |
40 url == GURL(chrome::kChromeUIShorthangURL); | 35 url == GURL(chrome::kChromeUIShorthangURL); |
41 } | 36 } |
42 | 37 |
43 int32 SiteInstanceImpl::next_site_instance_id_ = 1; | 38 int32 SiteInstanceImpl::next_site_instance_id_ = 1; |
44 | 39 |
45 SiteInstanceImpl::SiteInstanceImpl(BrowsingInstance* browsing_instance) | 40 SiteInstanceImpl::SiteInstanceImpl(BrowsingInstance* browsing_instance) |
46 : id_(next_site_instance_id_++), | 41 : id_(next_site_instance_id_++), |
47 browsing_instance_(browsing_instance), | 42 browsing_instance_(browsing_instance), |
48 render_process_host_factory_(NULL), | 43 render_process_host_factory_(NULL), |
49 process_(NULL), | 44 process_(NULL), |
50 has_site_(false) { | 45 has_site_(false) { |
51 DCHECK(browsing_instance); | 46 DCHECK(browsing_instance); |
52 | 47 |
53 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 48 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
54 content::NotificationService::AllBrowserContextsAndSources()); | 49 NotificationService::AllBrowserContextsAndSources()); |
55 } | 50 } |
56 | 51 |
57 SiteInstanceImpl::~SiteInstanceImpl() { | 52 SiteInstanceImpl::~SiteInstanceImpl() { |
58 content::GetContentClient()->browser()->SiteInstanceDeleting(this); | 53 GetContentClient()->browser()->SiteInstanceDeleting(this); |
59 | 54 |
60 // Now that no one is referencing us, we can safely remove ourselves from | 55 // Now that no one is referencing us, we can safely remove ourselves from |
61 // the BrowsingInstance. Any future visits to a page from this site | 56 // the BrowsingInstance. Any future visits to a page from this site |
62 // (within the same BrowsingInstance) can safely create a new SiteInstance. | 57 // (within the same BrowsingInstance) can safely create a new SiteInstance. |
63 if (has_site_) | 58 if (has_site_) |
64 browsing_instance_->UnregisterSiteInstance( | 59 browsing_instance_->UnregisterSiteInstance( |
65 static_cast<SiteInstance*>(this)); | 60 static_cast<SiteInstance*>(this)); |
66 } | 61 } |
67 | 62 |
68 int32 SiteInstanceImpl::GetId() { | 63 int32 SiteInstanceImpl::GetId() { |
69 return id_; | 64 return id_; |
70 } | 65 } |
71 | 66 |
72 bool SiteInstanceImpl::HasProcess() const { | 67 bool SiteInstanceImpl::HasProcess() const { |
73 if (process_ != NULL) | 68 if (process_ != NULL) |
74 return true; | 69 return true; |
75 | 70 |
76 // If we would use process-per-site for this site, also check if there is an | 71 // If we would use process-per-site for this site, also check if there is an |
77 // existing process that we would use if GetProcess() were called. | 72 // existing process that we would use if GetProcess() were called. |
78 content::BrowserContext* browser_context = | 73 BrowserContext* browser_context = |
79 browsing_instance_->browser_context(); | 74 browsing_instance_->browser_context(); |
80 if (has_site_ && | 75 if (has_site_ && |
81 RenderProcessHostImpl::ShouldUseProcessPerSite(browser_context, site_) && | 76 RenderProcessHostImpl::ShouldUseProcessPerSite(browser_context, site_) && |
82 RenderProcessHostImpl::GetProcessHostForSite(browser_context, site_)) { | 77 RenderProcessHostImpl::GetProcessHostForSite(browser_context, site_)) { |
83 return true; | 78 return true; |
84 } | 79 } |
85 | 80 |
86 return false; | 81 return false; |
87 } | 82 } |
88 | 83 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 CHECK(process_); | 126 CHECK(process_); |
132 | 127 |
133 // If we are using process-per-site, we need to register this process | 128 // If we are using process-per-site, we need to register this process |
134 // for the current site so that we can find it again. (If no site is set | 129 // for the current site so that we can find it again. (If no site is set |
135 // at this time, we will register it in SetSite().) | 130 // at this time, we will register it in SetSite().) |
136 if (use_process_per_site) { | 131 if (use_process_per_site) { |
137 RenderProcessHostImpl::RegisterProcessHostForSite(browser_context, | 132 RenderProcessHostImpl::RegisterProcessHostForSite(browser_context, |
138 process_, site_); | 133 process_, site_); |
139 } | 134 } |
140 | 135 |
141 content::GetContentClient()->browser()->SiteInstanceGotProcess(this); | 136 GetContentClient()->browser()->SiteInstanceGotProcess(this); |
142 | 137 |
143 if (has_site_) | 138 if (has_site_) |
144 LockToOrigin(); | 139 LockToOrigin(); |
145 } | 140 } |
146 DCHECK(process_); | 141 DCHECK(process_); |
147 | 142 |
148 return process_; | 143 return process_; |
149 } | 144 } |
150 | 145 |
151 void SiteInstanceImpl::SetSite(const GURL& url) { | 146 void SiteInstanceImpl::SetSite(const GURL& url) { |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 // If the schemes differ, they aren't part of the same site. | 297 // If the schemes differ, they aren't part of the same site. |
303 if (url1.scheme() != url2.scheme()) | 298 if (url1.scheme() != url2.scheme()) |
304 return false; | 299 return false; |
305 | 300 |
306 return net::RegistryControlledDomainService::SameDomainOrHost(url1, url2); | 301 return net::RegistryControlledDomainService::SameDomainOrHost(url1, url2); |
307 } | 302 } |
308 | 303 |
309 /*static*/ | 304 /*static*/ |
310 GURL SiteInstanceImpl::GetEffectiveURL(BrowserContext* browser_context, | 305 GURL SiteInstanceImpl::GetEffectiveURL(BrowserContext* browser_context, |
311 const GURL& url) { | 306 const GURL& url) { |
312 return content::GetContentClient()->browser()-> | 307 return GetContentClient()->browser()-> |
313 GetEffectiveURL(browser_context, url); | 308 GetEffectiveURL(browser_context, url); |
314 } | 309 } |
315 | 310 |
316 void SiteInstanceImpl::Observe(int type, | 311 void SiteInstanceImpl::Observe(int type, |
317 const content::NotificationSource& source, | 312 const NotificationSource& source, |
318 const content::NotificationDetails& details) { | 313 const NotificationDetails& details) { |
319 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_TERMINATED); | 314 DCHECK(type == NOTIFICATION_RENDERER_PROCESS_TERMINATED); |
tfarina
2012/10/30 22:19:06
DCHECK_EQ
| |
320 RenderProcessHost* rph = content::Source<RenderProcessHost>(source).ptr(); | 315 RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr(); |
321 if (rph == process_) | 316 if (rph == process_) |
322 process_ = NULL; | 317 process_ = NULL; |
323 } | 318 } |
324 | 319 |
325 void SiteInstanceImpl::LockToOrigin() { | 320 void SiteInstanceImpl::LockToOrigin() { |
326 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 321 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
327 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation)) { | 322 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation)) { |
328 ChildProcessSecurityPolicyImpl* policy = | 323 ChildProcessSecurityPolicyImpl* policy = |
329 ChildProcessSecurityPolicyImpl::GetInstance(); | 324 ChildProcessSecurityPolicyImpl::GetInstance(); |
330 policy->LockToOrigin(process_->GetID(), site_); | 325 policy->LockToOrigin(process_->GetID(), site_); |
331 } | 326 } |
332 } | 327 } |
328 | |
329 } // namespace content | |
OLD | NEW |