Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(523)

Side by Side Diff: content/browser/site_instance.cc

Issue 7464009: Removal of Profile from content part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: slight tweaking for comments Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/site_instance.h ('k') | content/browser/site_instance_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/content_browser_client.h" 8 #include "content/browser/content_browser_client.h"
9 #include "content/browser/renderer_host/browser_render_process_host.h" 9 #include "content/browser/renderer_host/browser_render_process_host.h"
10 #include "content/browser/webui/web_ui_factory.h" 10 #include "content/browser/webui/web_ui_factory.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // with no site set at this point, so it will default to TYPE_NORMAL. This 64 // with no site set at this point, so it will default to TYPE_NORMAL. This
65 // may not be correct, so we'll wind up potentially creating a process that 65 // may not be correct, so we'll wind up potentially creating a process that
66 // we then throw away, or worse sharing a process with the wrong process type. 66 // we then throw away, or worse sharing a process with the wrong process type.
67 // See crbug.com/43448. 67 // See crbug.com/43448.
68 68
69 // Create a new process if ours went away or was reused. 69 // Create a new process if ours went away or was reused.
70 if (!process_) { 70 if (!process_) {
71 // See if we should reuse an old process 71 // See if we should reuse an old process
72 if (RenderProcessHost::ShouldTryToUseExistingProcessHost()) 72 if (RenderProcessHost::ShouldTryToUseExistingProcessHost())
73 process_ = RenderProcessHost::GetExistingProcessHost( 73 process_ = RenderProcessHost::GetExistingProcessHost(
74 browsing_instance_->profile(), GetRendererType()); 74 browsing_instance_->browser_context(), GetRendererType());
75 75
76 // Otherwise (or if that fails), create a new one. 76 // Otherwise (or if that fails), create a new one.
77 if (!process_) { 77 if (!process_) {
78 if (render_process_host_factory_) { 78 if (render_process_host_factory_) {
79 process_ = render_process_host_factory_->CreateRenderProcessHost( 79 process_ = render_process_host_factory_->CreateRenderProcessHost(
80 browsing_instance_->profile()); 80 browsing_instance_->browser_context());
81 } else { 81 } else {
82 process_ = new BrowserRenderProcessHost(browsing_instance_->profile()); 82 process_ =
83 new BrowserRenderProcessHost(browsing_instance_->browser_context());
83 } 84 }
84 } 85 }
85 86
86 // Make sure the process starts at the right max_page_id 87 // Make sure the process starts at the right max_page_id
87 process_->UpdateMaxPageID(max_page_id_); 88 process_->UpdateMaxPageID(max_page_id_);
88 } 89 }
89 DCHECK(process_); 90 DCHECK(process_);
90 91
91 return process_; 92 return process_;
92 } 93 }
93 94
94 void SiteInstance::SetSite(const GURL& url) { 95 void SiteInstance::SetSite(const GURL& url) {
95 // A SiteInstance's site should not change. 96 // A SiteInstance's site should not change.
96 // TODO(creis): When following links or script navigations, we can currently 97 // TODO(creis): When following links or script navigations, we can currently
97 // render pages from other sites in this SiteInstance. This will eventually 98 // render pages from other sites in this SiteInstance. This will eventually
98 // be fixed, but until then, we should still not set the site of a 99 // be fixed, but until then, we should still not set the site of a
99 // SiteInstance more than once. 100 // SiteInstance more than once.
100 DCHECK(!has_site_); 101 DCHECK(!has_site_);
101 102
102 // Remember that this SiteInstance has been used to load a URL, even if the 103 // Remember that this SiteInstance has been used to load a URL, even if the
103 // URL is invalid. 104 // URL is invalid.
104 has_site_ = true; 105 has_site_ = true;
105 site_ = GetSiteForURL(browsing_instance_->profile(), url); 106 site_ = GetSiteForURL(browsing_instance_->browser_context(), url);
106 107
107 // Now that we have a site, register it with the BrowsingInstance. This 108 // Now that we have a site, register it with the BrowsingInstance. This
108 // ensures that we won't create another SiteInstance for this site within 109 // ensures that we won't create another SiteInstance for this site within
109 // the same BrowsingInstance, because all same-site pages within a 110 // the same BrowsingInstance, because all same-site pages within a
110 // BrowsingInstance can script each other. 111 // BrowsingInstance can script each other.
111 browsing_instance_->RegisterSiteInstance(this); 112 browsing_instance_->RegisterSiteInstance(this);
112 } 113 }
113 114
114 bool SiteInstance::HasRelatedSiteInstance(const GURL& url) { 115 bool SiteInstance::HasRelatedSiteInstance(const GURL& url) {
115 return browsing_instance_->HasSiteInstance(url); 116 return browsing_instance_->HasSiteInstance(url);
116 } 117 }
117 118
118 SiteInstance* SiteInstance::GetRelatedSiteInstance(const GURL& url) { 119 SiteInstance* SiteInstance::GetRelatedSiteInstance(const GURL& url) {
119 return browsing_instance_->GetSiteInstanceForURL(url); 120 return browsing_instance_->GetSiteInstanceForURL(url);
120 } 121 }
121 122
122 bool SiteInstance::HasWrongProcessForURL(const GURL& url) const { 123 bool SiteInstance::HasWrongProcessForURL(const GURL& url) const {
123 // Having no process isn't a problem, since we'll assign it correctly. 124 // Having no process isn't a problem, since we'll assign it correctly.
124 if (!HasProcess()) 125 if (!HasProcess())
125 return false; 126 return false;
126 127
127 // If the effective URL is an extension (e.g., for hosted apps) but the 128 // If the effective URL is an extension (e.g., for hosted apps) but the
128 // process is not (or vice versa), make sure we notice and fix it. 129 // process is not (or vice versa), make sure we notice and fix it.
129 GURL effective_url = GetEffectiveURL(browsing_instance_->profile(), url); 130 GURL effective_url = GetEffectiveURL(browsing_instance_->browser_context(),
131 url);
130 return effective_url.SchemeIs(chrome::kExtensionScheme) != 132 return effective_url.SchemeIs(chrome::kExtensionScheme) !=
131 process_->is_extension_process(); 133 process_->is_extension_process();
132 } 134 }
133 135
134 /*static*/ 136 /*static*/
135 SiteInstance* SiteInstance::CreateSiteInstance(Profile* profile) { 137 SiteInstance* SiteInstance::CreateSiteInstance(
136 return new SiteInstance(new BrowsingInstance(profile)); 138 content::BrowserContext* browser_context) {
139 return new SiteInstance(new BrowsingInstance(browser_context));
137 } 140 }
138 141
139 /*static*/ 142 /*static*/
140 SiteInstance* SiteInstance::CreateSiteInstanceForURL(Profile* profile, 143 SiteInstance* SiteInstance::CreateSiteInstanceForURL(
141 const GURL& url) { 144 content::BrowserContext* browser_context, const GURL& url) {
142 // This BrowsingInstance may be deleted if it returns an existing 145 // This BrowsingInstance may be deleted if it returns an existing
143 // SiteInstance. 146 // SiteInstance.
144 scoped_refptr<BrowsingInstance> instance(new BrowsingInstance(profile)); 147 scoped_refptr<BrowsingInstance> instance(
148 new BrowsingInstance(browser_context));
145 return instance->GetSiteInstanceForURL(url); 149 return instance->GetSiteInstanceForURL(url);
146 } 150 }
147 151
148 /*static*/ 152 /*static*/
149 GURL SiteInstance::GetSiteForURL(Profile* profile, const GURL& real_url) { 153 GURL SiteInstance::GetSiteForURL(content::BrowserContext* browser_context,
150 GURL url = GetEffectiveURL(profile, real_url); 154 const GURL& real_url) {
155 GURL url = GetEffectiveURL(browser_context, real_url);
151 156
152 // URLs with no host should have an empty site. 157 // URLs with no host should have an empty site.
153 GURL site; 158 GURL site;
154 159
155 // TODO(creis): For many protocols, we should just treat the scheme as the 160 // TODO(creis): For many protocols, we should just treat the scheme as the
156 // site, since there is no host. e.g., file:, about:, chrome: 161 // site, since there is no host. e.g., file:, about:, chrome:
157 162
158 // If the url has a host, then determine the site. 163 // If the url has a host, then determine the site.
159 if (url.has_host()) { 164 if (url.has_host()) {
160 // Only keep the scheme and registered domain as given by GetOrigin. This 165 // Only keep the scheme and registered domain as given by GetOrigin. This
(...skipping 13 matching lines...) Expand all
174 if (!domain.empty()) { 179 if (!domain.empty()) {
175 GURL::Replacements rep; 180 GURL::Replacements rep;
176 rep.SetHostStr(domain); 181 rep.SetHostStr(domain);
177 site = site.ReplaceComponents(rep); 182 site = site.ReplaceComponents(rep);
178 } 183 }
179 } 184 }
180 return site; 185 return site;
181 } 186 }
182 187
183 /*static*/ 188 /*static*/
184 bool SiteInstance::IsSameWebSite(Profile* profile, 189 bool SiteInstance::IsSameWebSite(content::BrowserContext* browser_context,
185 const GURL& real_url1, const GURL& real_url2) { 190 const GURL& real_url1, const GURL& real_url2) {
186 GURL url1 = GetEffectiveURL(profile, real_url1); 191 GURL url1 = GetEffectiveURL(browser_context, real_url1);
187 GURL url2 = GetEffectiveURL(profile, real_url2); 192 GURL url2 = GetEffectiveURL(browser_context, real_url2);
188 193
189 // We infer web site boundaries based on the registered domain name of the 194 // We infer web site boundaries based on the registered domain name of the
190 // top-level page and the scheme. We do not pay attention to the port if 195 // top-level page and the scheme. We do not pay attention to the port if
191 // one is present, because pages served from different ports can still 196 // one is present, because pages served from different ports can still
192 // access each other if they change their document.domain variable. 197 // access each other if they change their document.domain variable.
193 198
194 // Some special URLs will match the site instance of any other URL. This is 199 // Some special URLs will match the site instance of any other URL. This is
195 // done before checking both of them for validity, since we want these URLs 200 // done before checking both of them for validity, since we want these URLs
196 // to have the same site instance as even an invalid one. 201 // to have the same site instance as even an invalid one.
197 if (IsURLSameAsAnySiteInstance(url1) || IsURLSameAsAnySiteInstance(url2)) 202 if (IsURLSameAsAnySiteInstance(url1) || IsURLSameAsAnySiteInstance(url2))
198 return true; 203 return true;
199 204
200 // If either URL is invalid, they aren't part of the same site. 205 // If either URL is invalid, they aren't part of the same site.
201 if (!url1.is_valid() || !url2.is_valid()) 206 if (!url1.is_valid() || !url2.is_valid())
202 return false; 207 return false;
203 208
204 // If the schemes differ, they aren't part of the same site. 209 // If the schemes differ, they aren't part of the same site.
205 if (url1.scheme() != url2.scheme()) 210 if (url1.scheme() != url2.scheme())
206 return false; 211 return false;
207 212
208 return net::RegistryControlledDomainService::SameDomainOrHost(url1, url2); 213 return net::RegistryControlledDomainService::SameDomainOrHost(url1, url2);
209 } 214 }
210 215
211 /*static*/ 216 /*static*/
212 GURL SiteInstance::GetEffectiveURL(Profile* profile, const GURL& url) { 217 GURL SiteInstance::GetEffectiveURL(content::BrowserContext* browser_context,
213 return content::GetContentClient()->browser()->GetEffectiveURL(profile, url); 218 const GURL& url) {
219 return content::GetContentClient()->browser()->
220 GetEffectiveURL(browser_context, url);
214 } 221 }
215 222
216 /*static*/ 223 /*static*/
217 RenderProcessHost::Type SiteInstance::RendererTypeForURL(const GURL& url) { 224 RenderProcessHost::Type SiteInstance::RendererTypeForURL(const GURL& url) {
218 if (!url.is_valid()) 225 if (!url.is_valid())
219 return RenderProcessHost::TYPE_NORMAL; 226 return RenderProcessHost::TYPE_NORMAL;
220 227
221 if (url.SchemeIs(chrome::kExtensionScheme)) 228 if (url.SchemeIs(chrome::kExtensionScheme))
222 return RenderProcessHost::TYPE_EXTENSION; 229 return RenderProcessHost::TYPE_EXTENSION;
223 230
(...skipping 14 matching lines...) Expand all
238 } 245 }
239 246
240 void SiteInstance::Observe(int type, 247 void SiteInstance::Observe(int type,
241 const NotificationSource& source, 248 const NotificationSource& source,
242 const NotificationDetails& details) { 249 const NotificationDetails& details) {
243 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_TERMINATED); 250 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_TERMINATED);
244 RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr(); 251 RenderProcessHost* rph = Source<RenderProcessHost>(source).ptr();
245 if (rph == process_) 252 if (rph == process_)
246 process_ = NULL; 253 process_ = NULL;
247 } 254 }
OLDNEW
« no previous file with comments | « content/browser/site_instance.h ('k') | content/browser/site_instance_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698