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" | |
14 #include "content/public/browser/notification_types.h" | |
15 #include "content/public/browser/render_process_host_factory.h" | 13 #include "content/public/browser/render_process_host_factory.h" |
16 #include "content/public/browser/web_ui_controller_factory.h" | 14 #include "content/public/browser/web_ui_controller_factory.h" |
17 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
18 #include "content/public/common/url_constants.h" | 16 #include "content/public/common/url_constants.h" |
19 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 17 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
20 | 18 |
21 namespace content { | 19 namespace content { |
22 | 20 |
23 static bool IsURLSameAsAnySiteInstance(const GURL& url) { | 21 static bool IsURLSameAsAnySiteInstance(const GURL& url) { |
24 if (!url.is_valid()) | 22 if (!url.is_valid()) |
(...skipping 14 matching lines...) Expand all Loading... | |
39 SiteInstanceImpl::g_render_process_host_factory_ = NULL; | 37 SiteInstanceImpl::g_render_process_host_factory_ = NULL; |
40 int32 SiteInstanceImpl::next_site_instance_id_ = 1; | 38 int32 SiteInstanceImpl::next_site_instance_id_ = 1; |
41 | 39 |
42 SiteInstanceImpl::SiteInstanceImpl(BrowsingInstance* browsing_instance) | 40 SiteInstanceImpl::SiteInstanceImpl(BrowsingInstance* browsing_instance) |
43 : id_(next_site_instance_id_++), | 41 : id_(next_site_instance_id_++), |
44 active_view_count_(0), | 42 active_view_count_(0), |
45 browsing_instance_(browsing_instance), | 43 browsing_instance_(browsing_instance), |
46 process_(NULL), | 44 process_(NULL), |
47 has_site_(false) { | 45 has_site_(false) { |
48 DCHECK(browsing_instance); | 46 DCHECK(browsing_instance); |
49 | |
50 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_TERMINATED, | |
51 NotificationService::AllBrowserContextsAndSources()); | |
52 } | 47 } |
53 | 48 |
54 SiteInstanceImpl::~SiteInstanceImpl() { | 49 SiteInstanceImpl::~SiteInstanceImpl() { |
55 GetContentClient()->browser()->SiteInstanceDeleting(this); | 50 GetContentClient()->browser()->SiteInstanceDeleting(this); |
56 | 51 |
52 if (process_) | |
53 process_->RemoveObserver(this); | |
54 | |
57 // 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 |
58 // the BrowsingInstance. Any future visits to a page from this site | 56 // the BrowsingInstance. Any future visits to a page from this site |
59 // (within the same BrowsingInstance) can safely create a new SiteInstance. | 57 // (within the same BrowsingInstance) can safely create a new SiteInstance. |
60 if (has_site_) | 58 if (has_site_) |
61 browsing_instance_->UnregisterSiteInstance( | 59 browsing_instance_->UnregisterSiteInstance( |
62 static_cast<SiteInstance*>(this)); | 60 static_cast<SiteInstance*>(this)); |
63 } | 61 } |
64 | 62 |
65 int32 SiteInstanceImpl::GetId() { | 63 int32 SiteInstanceImpl::GetId() { |
66 return id_; | 64 return id_; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 BrowserContext::GetStoragePartition(browser_context, this)); | 120 BrowserContext::GetStoragePartition(browser_context, this)); |
123 bool supports_browser_plugin = GetContentClient()->browser()-> | 121 bool supports_browser_plugin = GetContentClient()->browser()-> |
124 SupportsBrowserPlugin(browser_context, site_); | 122 SupportsBrowserPlugin(browser_context, site_); |
125 process_ = new RenderProcessHostImpl(browser_context, | 123 process_ = new RenderProcessHostImpl(browser_context, |
126 partition, | 124 partition, |
127 supports_browser_plugin, | 125 supports_browser_plugin, |
128 site_.SchemeIs(kGuestScheme)); | 126 site_.SchemeIs(kGuestScheme)); |
129 } | 127 } |
130 } | 128 } |
131 CHECK(process_); | 129 CHECK(process_); |
130 if (!process_->HasObserver(this)) | |
131 process_->AddObserver(this); | |
Avi (use Gerrit)
2013/11/14 03:32:27
Yeah, that's bogus. I'll fix that tomorrow.
| |
132 | 132 |
133 // If we are using process-per-site, we need to register this process | 133 // 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 | 134 // 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().) | 135 // at this time, we will register it in SetSite().) |
136 if (use_process_per_site) { | 136 if (use_process_per_site) { |
137 RenderProcessHostImpl::RegisterProcessHostForSite(browser_context, | 137 RenderProcessHostImpl::RegisterProcessHostForSite(browser_context, |
138 process_, site_); | 138 process_, site_); |
139 } | 139 } |
140 | 140 |
141 GetContentClient()->browser()->SiteInstanceGotProcess(this); | 141 GetContentClient()->browser()->SiteInstanceGotProcess(this); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 return site; | 319 return site; |
320 } | 320 } |
321 | 321 |
322 /*static*/ | 322 /*static*/ |
323 GURL SiteInstanceImpl::GetEffectiveURL(BrowserContext* browser_context, | 323 GURL SiteInstanceImpl::GetEffectiveURL(BrowserContext* browser_context, |
324 const GURL& url) { | 324 const GURL& url) { |
325 return GetContentClient()->browser()-> | 325 return GetContentClient()->browser()-> |
326 GetEffectiveURL(browser_context, url); | 326 GetEffectiveURL(browser_context, url); |
327 } | 327 } |
328 | 328 |
329 void SiteInstanceImpl::Observe(int type, | 329 void SiteInstanceImpl::RenderProcessHostDestroyed(RenderProcessHost* host) { |
330 const NotificationSource& source, | 330 DCHECK_EQ(process_, host); |
331 const NotificationDetails& details) { | 331 process_->RemoveObserver(this); |
332 DCHECK(type == NOTIFICATION_RENDERER_PROCESS_TERMINATED); | 332 process_ = NULL; |
333 RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr(); | |
334 if (rph == process_) | |
335 process_ = NULL; | |
336 } | 333 } |
337 | 334 |
338 void SiteInstanceImpl::LockToOrigin() { | 335 void SiteInstanceImpl::LockToOrigin() { |
339 // We currently only restrict this process to a particular site if the | 336 // We currently only restrict this process to a particular site if the |
340 // --enable-strict-site-isolation or --site-per-process flags are present. | 337 // --enable-strict-site-isolation or --site-per-process flags are present. |
341 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 338 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
342 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) || | 339 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) || |
343 command_line.HasSwitch(switches::kSitePerProcess)) { | 340 command_line.HasSwitch(switches::kSitePerProcess)) { |
344 ChildProcessSecurityPolicyImpl* policy = | 341 ChildProcessSecurityPolicyImpl* policy = |
345 ChildProcessSecurityPolicyImpl::GetInstance(); | 342 ChildProcessSecurityPolicyImpl::GetInstance(); |
346 policy->LockToOrigin(process_->GetID(), site_); | 343 policy->LockToOrigin(process_->GetID(), site_); |
347 } | 344 } |
348 } | 345 } |
349 | 346 |
350 } // namespace content | 347 } // namespace content |
OLD | NEW |