OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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.h" | 5 #include "content/browser/site_instance.h" |
6 | 6 |
7 #include "content/browser/browsing_instance.h" | 7 #include "content/browser/browsing_instance.h" |
8 #include "content/browser/renderer_host/browser_render_process_host.h" | 8 #include "content/browser/renderer_host/browser_render_process_host.h" |
9 #include "content/browser/webui/web_ui_factory.h" | 9 #include "content/browser/webui/web_ui_factory.h" |
10 #include "content/common/notification_service.h" | |
11 #include "content/public/browser/content_browser_client.h" | 10 #include "content/public/browser/content_browser_client.h" |
| 11 #include "content/public/browser/notification_service.h" |
12 #include "content/public/browser/notification_types.h" | 12 #include "content/public/browser/notification_types.h" |
13 #include "content/public/common/url_constants.h" | 13 #include "content/public/common/url_constants.h" |
14 #include "net/base/registry_controlled_domain.h" | 14 #include "net/base/registry_controlled_domain.h" |
15 | 15 |
16 static bool IsURLSameAsAnySiteInstance(const GURL& url) { | 16 static bool IsURLSameAsAnySiteInstance(const GURL& url) { |
17 if (!url.is_valid()) | 17 if (!url.is_valid()) |
18 return false; | 18 return false; |
19 | 19 |
20 // We treat javascript: as the same site as any URL since it is actually | 20 // We treat javascript: as the same site as any URL since it is actually |
21 // a modifier on existing pages. | 21 // a modifier on existing pages. |
22 if (url.SchemeIs(chrome::kJavaScriptScheme)) | 22 if (url.SchemeIs(chrome::kJavaScriptScheme)) |
23 return true; | 23 return true; |
24 | 24 |
25 return | 25 return |
26 content::GetContentClient()->browser()->IsURLSameAsAnySiteInstance(url); | 26 content::GetContentClient()->browser()->IsURLSameAsAnySiteInstance(url); |
27 } | 27 } |
28 | 28 |
29 int32 SiteInstance::next_site_instance_id_ = 1; | 29 int32 SiteInstance::next_site_instance_id_ = 1; |
30 | 30 |
31 SiteInstance::SiteInstance(BrowsingInstance* browsing_instance) | 31 SiteInstance::SiteInstance(BrowsingInstance* browsing_instance) |
32 : id_(next_site_instance_id_++), | 32 : id_(next_site_instance_id_++), |
33 browsing_instance_(browsing_instance), | 33 browsing_instance_(browsing_instance), |
34 render_process_host_factory_(NULL), | 34 render_process_host_factory_(NULL), |
35 process_(NULL), | 35 process_(NULL), |
36 max_page_id_(-1), | 36 max_page_id_(-1), |
37 has_site_(false) { | 37 has_site_(false) { |
38 DCHECK(browsing_instance); | 38 DCHECK(browsing_instance); |
39 | 39 |
40 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, | 40 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
41 NotificationService::AllBrowserContextsAndSources()); | 41 content::NotificationService::AllBrowserContextsAndSources()); |
42 } | 42 } |
43 | 43 |
44 SiteInstance::~SiteInstance() { | 44 SiteInstance::~SiteInstance() { |
45 NotificationService::current()->Notify( | 45 content::NotificationService::current()->Notify( |
46 content::NOTIFICATION_SITE_INSTANCE_DELETED, | 46 content::NOTIFICATION_SITE_INSTANCE_DELETED, |
47 content::Source<SiteInstance>(this), | 47 content::Source<SiteInstance>(this), |
48 NotificationService::NoDetails()); | 48 content::NotificationService::NoDetails()); |
49 | 49 |
50 // Now that no one is referencing us, we can safely remove ourselves from | 50 // Now that no one is referencing us, we can safely remove ourselves from |
51 // the BrowsingInstance. Any future visits to a page from this site | 51 // the BrowsingInstance. Any future visits to a page from this site |
52 // (within the same BrowsingInstance) can safely create a new SiteInstance. | 52 // (within the same BrowsingInstance) can safely create a new SiteInstance. |
53 if (has_site_) | 53 if (has_site_) |
54 browsing_instance_->UnregisterSiteInstance(this); | 54 browsing_instance_->UnregisterSiteInstance(this); |
55 } | 55 } |
56 | 56 |
57 bool SiteInstance::HasProcess() const { | 57 bool SiteInstance::HasProcess() const { |
58 return (process_ != NULL); | 58 return (process_ != NULL); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 } | 221 } |
222 | 222 |
223 void SiteInstance::Observe(int type, | 223 void SiteInstance::Observe(int type, |
224 const content::NotificationSource& source, | 224 const content::NotificationSource& source, |
225 const content::NotificationDetails& details) { | 225 const content::NotificationDetails& details) { |
226 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_TERMINATED); | 226 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_TERMINATED); |
227 RenderProcessHost* rph = content::Source<RenderProcessHost>(source).ptr(); | 227 RenderProcessHost* rph = content::Source<RenderProcessHost>(source).ptr(); |
228 if (rph == process_) | 228 if (rph == process_) |
229 process_ = NULL; | 229 process_ = NULL; |
230 } | 230 } |
OLD | NEW |