[email protected] | 144a810 | 2012-01-14 01:05:31 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 5 | #include "content/browser/site_instance_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 7 | #include "base/command_line.h" |
[email protected] | 3936521 | 2011-02-24 01:01:00 | [diff] [blame] | 8 | #include "content/browser/browsing_instance.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 9 | #include "content/browser/child_process_security_policy_impl.h" |
[email protected] | c02f1ba | 2014-02-03 06:53:53 | [diff] [blame] | 10 | #include "content/browser/frame_host/debug_urls.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 11 | #include "content/browser/renderer_host/render_process_host_impl.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 12 | #include "content/browser/storage_partition_impl.h" |
[email protected] | 87f3c08 | 2011-10-19 18:07:44 | [diff] [blame] | 13 | #include "content/public/browser/content_browser_client.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 14 | #include "content/public/browser/render_process_host_factory.h" |
[email protected] | 41fb79a5 | 2012-06-29 16:34:33 | [diff] [blame] | 15 | #include "content/public/browser/web_ui_controller_factory.h" |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 16 | #include "content/public/common/content_switches.h" |
[email protected] | a1d2916 | 2011-10-14 17:14:03 | [diff] [blame] | 17 | #include "content/public/common/url_constants.h" |
[email protected] | be28b5f4 | 2012-07-20 11:31:25 | [diff] [blame] | 18 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 20 | namespace content { |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 21 | |
[email protected] | 3059caa | 2013-06-06 03:48:41 | [diff] [blame] | 22 | const RenderProcessHostFactory* |
| 23 | SiteInstanceImpl::g_render_process_host_factory_ = NULL; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 24 | int32 SiteInstanceImpl::next_site_instance_id_ = 1; |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 25 | |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 26 | SiteInstanceImpl::SiteInstanceImpl(BrowsingInstance* browsing_instance) |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 27 | : id_(next_site_instance_id_++), |
[email protected] | cee12ab | 2013-07-12 01:53:07 | [diff] [blame] | 28 | active_view_count_(0), |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 29 | browsing_instance_(browsing_instance), |
[email protected] | 4566f13 | 2009-03-12 01:55:13 | [diff] [blame] | 30 | process_(NULL), |
[email protected] | 4566f13 | 2009-03-12 01:55:13 | [diff] [blame] | 31 | has_site_(false) { |
| 32 | DCHECK(browsing_instance); |
[email protected] | 4566f13 | 2009-03-12 01:55:13 | [diff] [blame] | 33 | } |
| 34 | |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 35 | SiteInstanceImpl::~SiteInstanceImpl() { |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 36 | GetContentClient()->browser()->SiteInstanceDeleting(this); |
[email protected] | 056ad2a | 2011-07-12 02:13:55 | [diff] [blame] | 37 | |
[email protected] | 40bfaf3 | 2013-11-19 01:35:43 | [diff] [blame] | 38 | if (process_) |
| 39 | process_->RemoveObserver(this); |
| 40 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 41 | // Now that no one is referencing us, we can safely remove ourselves from |
| 42 | // the BrowsingInstance. Any future visits to a page from this site |
| 43 | // (within the same BrowsingInstance) can safely create a new SiteInstance. |
| 44 | if (has_site_) |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 45 | browsing_instance_->UnregisterSiteInstance( |
| 46 | static_cast<SiteInstance*>(this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 47 | } |
| 48 | |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 49 | int32 SiteInstanceImpl::GetId() { |
| 50 | return id_; |
| 51 | } |
| 52 | |
| 53 | bool SiteInstanceImpl::HasProcess() const { |
[email protected] | 41fb79a5 | 2012-06-29 16:34:33 | [diff] [blame] | 54 | if (process_ != NULL) |
| 55 | return true; |
| 56 | |
| 57 | // If we would use process-per-site for this site, also check if there is an |
| 58 | // existing process that we would use if GetProcess() were called. |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 59 | BrowserContext* browser_context = |
[email protected] | 41fb79a5 | 2012-06-29 16:34:33 | [diff] [blame] | 60 | browsing_instance_->browser_context(); |
| 61 | if (has_site_ && |
[email protected] | 1ae93fb1 | 2013-06-14 03:38:56 | [diff] [blame] | 62 | RenderProcessHost::ShouldUseProcessPerSite(browser_context, site_) && |
[email protected] | 41fb79a5 | 2012-06-29 16:34:33 | [diff] [blame] | 63 | RenderProcessHostImpl::GetProcessHostForSite(browser_context, site_)) { |
| 64 | return true; |
| 65 | } |
| 66 | |
| 67 | return false; |
[email protected] | 5ab79b0 | 2010-04-26 16:47:11 | [diff] [blame] | 68 | } |
| 69 | |
[email protected] | 41fb79a5 | 2012-06-29 16:34:33 | [diff] [blame] | 70 | RenderProcessHost* SiteInstanceImpl::GetProcess() { |
[email protected] | 08c8ec7e | 2010-07-11 17:14:48 | [diff] [blame] | 71 | // TODO(erikkay) It would be nice to ensure that the renderer type had been |
| 72 | // properly set before we get here. The default tab creation case winds up |
| 73 | // with no site set at this point, so it will default to TYPE_NORMAL. This |
| 74 | // may not be correct, so we'll wind up potentially creating a process that |
| 75 | // we then throw away, or worse sharing a process with the wrong process type. |
| 76 | // See crbug.com/43448. |
| 77 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 78 | // Create a new process if ours went away or was reused. |
[email protected] | 4566f13 | 2009-03-12 01:55:13 | [diff] [blame] | 79 | if (!process_) { |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 80 | BrowserContext* browser_context = browsing_instance_->browser_context(); |
[email protected] | 41fb79a5 | 2012-06-29 16:34:33 | [diff] [blame] | 81 | |
| 82 | // If we should use process-per-site mode (either in general or for the |
| 83 | // given site), then look for an existing RenderProcessHost for the site. |
| 84 | bool use_process_per_site = has_site_ && |
[email protected] | 1ae93fb1 | 2013-06-14 03:38:56 | [diff] [blame] | 85 | RenderProcessHost::ShouldUseProcessPerSite(browser_context, site_); |
[email protected] | 41fb79a5 | 2012-06-29 16:34:33 | [diff] [blame] | 86 | if (use_process_per_site) { |
| 87 | process_ = RenderProcessHostImpl::GetProcessHostForSite(browser_context, |
| 88 | site_); |
| 89 | } |
| 90 | |
| 91 | // If not (or if none found), see if we should reuse an existing process. |
| 92 | if (!process_ && RenderProcessHostImpl::ShouldTryToUseExistingProcessHost( |
| 93 | browser_context, site_)) { |
| 94 | process_ = RenderProcessHostImpl::GetExistingProcessHost(browser_context, |
| 95 | site_); |
| 96 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 97 | |
| 98 | // Otherwise (or if that fails), create a new one. |
[email protected] | 4566f13 | 2009-03-12 01:55:13 | [diff] [blame] | 99 | if (!process_) { |
[email protected] | 3059caa | 2013-06-06 03:48:41 | [diff] [blame] | 100 | if (g_render_process_host_factory_) { |
| 101 | process_ = g_render_process_host_factory_->CreateRenderProcessHost( |
[email protected] | f681b07 | 2013-06-06 21:53:12 | [diff] [blame] | 102 | browser_context, this); |
[email protected] | a6df511 | 2009-01-21 23:50:15 | [diff] [blame] | 103 | } else { |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 104 | StoragePartitionImpl* partition = |
| 105 | static_cast<StoragePartitionImpl*>( |
| 106 | BrowserContext::GetStoragePartition(browser_context, this)); |
[email protected] | 6eb1a11e | 2013-10-09 00:54:37 | [diff] [blame] | 107 | process_ = new RenderProcessHostImpl(browser_context, |
| 108 | partition, |
[email protected] | 6eb1a11e | 2013-10-09 00:54:37 | [diff] [blame] | 109 | site_.SchemeIs(kGuestScheme)); |
[email protected] | a6df511 | 2009-01-21 23:50:15 | [diff] [blame] | 110 | } |
| 111 | } |
[email protected] | 41fb79a5 | 2012-06-29 16:34:33 | [diff] [blame] | 112 | CHECK(process_); |
[email protected] | 40bfaf3 | 2013-11-19 01:35:43 | [diff] [blame] | 113 | process_->AddObserver(this); |
[email protected] | 41fb79a5 | 2012-06-29 16:34:33 | [diff] [blame] | 114 | |
| 115 | // If we are using process-per-site, we need to register this process |
| 116 | // for the current site so that we can find it again. (If no site is set |
| 117 | // at this time, we will register it in SetSite().) |
| 118 | if (use_process_per_site) { |
| 119 | RenderProcessHostImpl::RegisterProcessHostForSite(browser_context, |
| 120 | process_, site_); |
| 121 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 122 | |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 123 | GetContentClient()->browser()->SiteInstanceGotProcess(this); |
[email protected] | 6f37144 | 2011-11-09 06:45:46 | [diff] [blame] | 124 | |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 125 | if (has_site_) |
| 126 | LockToOrigin(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 127 | } |
[email protected] | 4566f13 | 2009-03-12 01:55:13 | [diff] [blame] | 128 | DCHECK(process_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 129 | |
[email protected] | 4566f13 | 2009-03-12 01:55:13 | [diff] [blame] | 130 | return process_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 131 | } |
| 132 | |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 133 | void SiteInstanceImpl::SetSite(const GURL& url) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 134 | // A SiteInstance's site should not change. |
| 135 | // TODO(creis): When following links or script navigations, we can currently |
| 136 | // render pages from other sites in this SiteInstance. This will eventually |
| 137 | // be fixed, but until then, we should still not set the site of a |
| 138 | // SiteInstance more than once. |
| 139 | DCHECK(!has_site_); |
| 140 | |
| 141 | // Remember that this SiteInstance has been used to load a URL, even if the |
| 142 | // URL is invalid. |
| 143 | has_site_ = true; |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 144 | BrowserContext* browser_context = browsing_instance_->browser_context(); |
[email protected] | 41fb79a5 | 2012-06-29 16:34:33 | [diff] [blame] | 145 | site_ = GetSiteForURL(browser_context, url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 146 | |
| 147 | // Now that we have a site, register it with the BrowsingInstance. This |
| 148 | // ensures that we won't create another SiteInstance for this site within |
| 149 | // the same BrowsingInstance, because all same-site pages within a |
| 150 | // BrowsingInstance can script each other. |
| 151 | browsing_instance_->RegisterSiteInstance(this); |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 152 | |
[email protected] | 41fb79a5 | 2012-06-29 16:34:33 | [diff] [blame] | 153 | if (process_) { |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 154 | LockToOrigin(); |
[email protected] | 41fb79a5 | 2012-06-29 16:34:33 | [diff] [blame] | 155 | |
| 156 | // Ensure the process is registered for this site if necessary. |
[email protected] | 1ae93fb1 | 2013-06-14 03:38:56 | [diff] [blame] | 157 | if (RenderProcessHost::ShouldUseProcessPerSite(browser_context, site_)) { |
[email protected] | 41fb79a5 | 2012-06-29 16:34:33 | [diff] [blame] | 158 | RenderProcessHostImpl::RegisterProcessHostForSite( |
| 159 | browser_context, process_, site_); |
| 160 | } |
| 161 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 162 | } |
| 163 | |
[email protected] | 77ab1731 | 2012-09-28 15:34:59 | [diff] [blame] | 164 | const GURL& SiteInstanceImpl::GetSiteURL() const { |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 165 | return site_; |
| 166 | } |
| 167 | |
| 168 | bool SiteInstanceImpl::HasSite() const { |
| 169 | return has_site_; |
| 170 | } |
| 171 | |
| 172 | bool SiteInstanceImpl::HasRelatedSiteInstance(const GURL& url) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 173 | return browsing_instance_->HasSiteInstance(url); |
| 174 | } |
| 175 | |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 176 | SiteInstance* SiteInstanceImpl::GetRelatedSiteInstance(const GURL& url) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 177 | return browsing_instance_->GetSiteInstanceForURL(url); |
| 178 | } |
| 179 | |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 180 | bool SiteInstanceImpl::IsRelatedSiteInstance(const SiteInstance* instance) { |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 181 | return browsing_instance_.get() == static_cast<const SiteInstanceImpl*>( |
| 182 | instance)->browsing_instance_.get(); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 183 | } |
| 184 | |
[email protected] | d5072a8 | 2014-05-15 05:50:18 | [diff] [blame] | 185 | size_t SiteInstanceImpl::GetRelatedActiveContentsCount() { |
| 186 | return browsing_instance_->active_contents_count(); |
| 187 | } |
| 188 | |
[email protected] | f88628d0 | 2012-11-11 17:58:59 | [diff] [blame] | 189 | bool SiteInstanceImpl::HasWrongProcessForURL(const GURL& url) { |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 190 | // Having no process isn't a problem, since we'll assign it correctly. |
[email protected] | f88628d0 | 2012-11-11 17:58:59 | [diff] [blame] | 191 | // Note that HasProcess() may return true if process_ is null, in |
| 192 | // process-per-site cases where there's an existing process available. |
| 193 | // We want to use such a process in the IsSuitableHost check, so we |
| 194 | // may end up assigning process_ in the GetProcess() call below. |
| 195 | if (!HasProcess()) |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 196 | return false; |
| 197 | |
[email protected] | 144a810 | 2012-01-14 01:05:31 | [diff] [blame] | 198 | // If the URL to navigate to can be associated with any site instance, |
| 199 | // we want to keep it in the same process. |
[email protected] | c02f1ba | 2014-02-03 06:53:53 | [diff] [blame] | 200 | if (IsRendererDebugURL(url)) |
[email protected] | 144a810 | 2012-01-14 01:05:31 | [diff] [blame] | 201 | return false; |
| 202 | |
[email protected] | 88aae97 | 2011-12-16 01:14:18 | [diff] [blame] | 203 | // If the site URL is an extension (e.g., for hosted apps or WebUI) but the |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 204 | // process is not (or vice versa), make sure we notice and fix it. |
[email protected] | 2a5221b | 2011-09-27 23:07:31 | [diff] [blame] | 205 | GURL site_url = GetSiteForURL(browsing_instance_->browser_context(), url); |
[email protected] | 88aae97 | 2011-12-16 01:14:18 | [diff] [blame] | 206 | return !RenderProcessHostImpl::IsSuitableHost( |
[email protected] | f88628d0 | 2012-11-11 17:58:59 | [diff] [blame] | 207 | GetProcess(), browsing_instance_->browser_context(), site_url); |
[email protected] | d292d8a | 2011-05-25 03:47:11 | [diff] [blame] | 208 | } |
| 209 | |
[email protected] | d5072a8 | 2014-05-15 05:50:18 | [diff] [blame] | 210 | void SiteInstanceImpl::IncrementRelatedActiveContentsCount() { |
| 211 | browsing_instance_->increment_active_contents_count(); |
| 212 | } |
| 213 | |
| 214 | void SiteInstanceImpl::DecrementRelatedActiveContentsCount() { |
| 215 | browsing_instance_->decrement_active_contents_count(); |
| 216 | } |
| 217 | |
[email protected] | 3059caa | 2013-06-06 03:48:41 | [diff] [blame] | 218 | void SiteInstanceImpl::set_render_process_host_factory( |
| 219 | const RenderProcessHostFactory* rph_factory) { |
| 220 | g_render_process_host_factory_ = rph_factory; |
| 221 | } |
| 222 | |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 223 | BrowserContext* SiteInstanceImpl::GetBrowserContext() const { |
[email protected] | 72daaa9 | 2012-01-18 13:39:02 | [diff] [blame] | 224 | return browsing_instance_->browser_context(); |
| 225 | } |
| 226 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 227 | /*static*/ |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 228 | SiteInstance* SiteInstance::Create(BrowserContext* browser_context) { |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 229 | return new SiteInstanceImpl(new BrowsingInstance(browser_context)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | /*static*/ |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 233 | SiteInstance* SiteInstance::CreateForURL(BrowserContext* browser_context, |
| 234 | const GURL& url) { |
[email protected] | 633fbc4 | 2009-05-07 23:39:47 | [diff] [blame] | 235 | // This BrowsingInstance may be deleted if it returns an existing |
| 236 | // SiteInstance. |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 237 | scoped_refptr<BrowsingInstance> instance( |
| 238 | new BrowsingInstance(browser_context)); |
[email protected] | 633fbc4 | 2009-05-07 23:39:47 | [diff] [blame] | 239 | return instance->GetSiteInstanceForURL(url); |
[email protected] | d8a9662 | 2009-05-07 19:21:16 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | /*static*/ |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 243 | bool SiteInstance::IsSameWebSite(BrowserContext* browser_context, |
[email protected] | 855d7d57 | 2014-08-02 11:18:17 | [diff] [blame^] | 244 | const GURL& real_src_url, |
| 245 | const GURL& real_dest_url) { |
| 246 | GURL src_url = SiteInstanceImpl::GetEffectiveURL(browser_context, |
| 247 | real_src_url); |
| 248 | GURL dest_url = SiteInstanceImpl::GetEffectiveURL(browser_context, |
| 249 | real_dest_url); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 250 | |
| 251 | // We infer web site boundaries based on the registered domain name of the |
| 252 | // top-level page and the scheme. We do not pay attention to the port if |
| 253 | // one is present, because pages served from different ports can still |
| 254 | // access each other if they change their document.domain variable. |
| 255 | |
| 256 | // Some special URLs will match the site instance of any other URL. This is |
| 257 | // done before checking both of them for validity, since we want these URLs |
| 258 | // to have the same site instance as even an invalid one. |
[email protected] | 855d7d57 | 2014-08-02 11:18:17 | [diff] [blame^] | 259 | if (IsRendererDebugURL(src_url) || IsRendererDebugURL(dest_url)) |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 260 | return true; |
| 261 | |
| 262 | // If either URL is invalid, they aren't part of the same site. |
[email protected] | 855d7d57 | 2014-08-02 11:18:17 | [diff] [blame^] | 263 | if (!src_url.is_valid() || !dest_url.is_valid()) |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 264 | return false; |
| 265 | |
[email protected] | 855d7d57 | 2014-08-02 11:18:17 | [diff] [blame^] | 266 | // If the destination url is just a blank page, we treat them as part of the |
| 267 | // same site. |
| 268 | GURL blank_page(url::kAboutBlankURL); |
| 269 | if (dest_url == blank_page) |
| 270 | return true; |
| 271 | |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 272 | // If the schemes differ, they aren't part of the same site. |
[email protected] | 855d7d57 | 2014-08-02 11:18:17 | [diff] [blame^] | 273 | if (src_url.scheme() != dest_url.scheme()) |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 274 | return false; |
| 275 | |
[email protected] | ed32c21 | 2013-05-14 20:49:29 | [diff] [blame] | 276 | return net::registry_controlled_domains::SameDomainOrHost( |
[email protected] | 855d7d57 | 2014-08-02 11:18:17 | [diff] [blame^] | 277 | src_url, |
| 278 | dest_url, |
[email protected] | aabe179 | 2014-01-30 21:37:46 | [diff] [blame] | 279 | net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
[email protected] | 399583b | 2012-12-11 09:33:42 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | /*static*/ |
| 283 | GURL SiteInstance::GetSiteForURL(BrowserContext* browser_context, |
| 284 | const GURL& real_url) { |
[email protected] | 25a9e8e53 | 2012-06-22 06:16:28 | [diff] [blame] | 285 | // TODO(fsamuel, creis): For some reason appID is not recognized as a host. |
[email protected] | 6eb1a11e | 2013-10-09 00:54:37 | [diff] [blame] | 286 | if (real_url.SchemeIs(kGuestScheme)) |
[email protected] | 25a9e8e53 | 2012-06-22 06:16:28 | [diff] [blame] | 287 | return real_url; |
| 288 | |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 289 | GURL url = SiteInstanceImpl::GetEffectiveURL(browser_context, real_url); |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 290 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 291 | // URLs with no host should have an empty site. |
| 292 | GURL site; |
| 293 | |
| 294 | // TODO(creis): For many protocols, we should just treat the scheme as the |
[email protected] | 76a010b | 2008-12-07 23:48:03 | [diff] [blame] | 295 | // site, since there is no host. e.g., file:, about:, chrome: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 296 | |
| 297 | // If the url has a host, then determine the site. |
| 298 | if (url.has_host()) { |
[email protected] | 6705b23 | 2008-11-26 00:16:51 | [diff] [blame] | 299 | // Only keep the scheme and registered domain as given by GetOrigin. This |
| 300 | // may also include a port, which we need to drop. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 301 | site = url.GetOrigin(); |
| 302 | |
[email protected] | 6705b23 | 2008-11-26 00:16:51 | [diff] [blame] | 303 | // Remove port, if any. |
| 304 | if (site.has_port()) { |
| 305 | GURL::Replacements rep; |
| 306 | rep.ClearPort(); |
| 307 | site = site.ReplaceComponents(rep); |
| 308 | } |
| 309 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 310 | // If this URL has a registered domain, we only want to remember that part. |
| 311 | std::string domain = |
[email protected] | ed32c21 | 2013-05-14 20:49:29 | [diff] [blame] | 312 | net::registry_controlled_domains::GetDomainAndRegistry( |
| 313 | url, |
[email protected] | aabe179 | 2014-01-30 21:37:46 | [diff] [blame] | 314 | net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 315 | if (!domain.empty()) { |
| 316 | GURL::Replacements rep; |
| 317 | rep.SetHostStr(domain); |
| 318 | site = site.ReplaceComponents(rep); |
| 319 | } |
| 320 | } |
| 321 | return site; |
| 322 | } |
| 323 | |
| 324 | /*static*/ |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 325 | GURL SiteInstanceImpl::GetEffectiveURL(BrowserContext* browser_context, |
| 326 | const GURL& url) { |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 327 | return GetContentClient()->browser()-> |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 328 | GetEffectiveURL(browser_context, url); |
[email protected] | 3a8eecb | 2010-04-22 23:56:30 | [diff] [blame] | 329 | } |
| 330 | |
[email protected] | 40bfaf3 | 2013-11-19 01:35:43 | [diff] [blame] | 331 | void SiteInstanceImpl::RenderProcessHostDestroyed(RenderProcessHost* host) { |
| 332 | DCHECK_EQ(process_, host); |
| 333 | process_->RemoveObserver(this); |
| 334 | process_ = NULL; |
[email protected] | 4566f13 | 2009-03-12 01:55:13 | [diff] [blame] | 335 | } |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 336 | |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 337 | void SiteInstanceImpl::LockToOrigin() { |
[email protected] | c6f2e67 | 2012-11-15 01:47:02 | [diff] [blame] | 338 | // We currently only restrict this process to a particular site if the |
| 339 | // --enable-strict-site-isolation or --site-per-process flags are present. |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 340 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
[email protected] | c6f2e67 | 2012-11-15 01:47:02 | [diff] [blame] | 341 | if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation) || |
| 342 | command_line.HasSwitch(switches::kSitePerProcess)) { |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 343 | ChildProcessSecurityPolicyImpl* policy = |
| 344 | ChildProcessSecurityPolicyImpl::GetInstance(); |
[email protected] | 313b80bd | 2011-11-23 03:49:10 | [diff] [blame] | 345 | policy->LockToOrigin(process_->GetID(), site_); |
| 346 | } |
| 347 | } |
[email protected] | 4648832 | 2012-10-30 03:22:20 | [diff] [blame] | 348 | |
| 349 | } // namespace content |