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

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

Issue 8496027: Enhance --enable-strict-site-isolation to prevent a site-isolated renderer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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/public/common/content_switches.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 "base/command_line.h"
7 #include "content/browser/browsing_instance.h" 8 #include "content/browser/browsing_instance.h"
9 #include "content/browser/child_process_security_policy.h"
8 #include "content/browser/renderer_host/render_process_host_impl.h" 10 #include "content/browser/renderer_host/render_process_host_impl.h"
9 #include "content/browser/webui/web_ui_factory.h" 11 #include "content/browser/webui/web_ui_factory.h"
10 #include "content/public/browser/content_browser_client.h" 12 #include "content/public/browser/content_browser_client.h"
11 #include "content/public/browser/notification_service.h" 13 #include "content/public/browser/notification_service.h"
12 #include "content/public/browser/notification_types.h" 14 #include "content/public/browser/notification_types.h"
13 #include "content/public/browser/render_process_host_factory.h" 15 #include "content/public/browser/render_process_host_factory.h"
16 #include "content/public/common/content_switches.h"
14 #include "content/public/common/url_constants.h" 17 #include "content/public/common/url_constants.h"
15 #include "net/base/registry_controlled_domain.h" 18 #include "net/base/registry_controlled_domain.h"
16 19
17 static bool IsURLSameAsAnySiteInstance(const GURL& url) { 20 static bool IsURLSameAsAnySiteInstance(const GURL& url) {
18 if (!url.is_valid()) 21 if (!url.is_valid())
19 return false; 22 return false;
20 23
21 // We treat javascript: as the same site as any URL since it is actually 24 // We treat javascript: as the same site as any URL since it is actually
22 // a modifier on existing pages. 25 // a modifier on existing pages.
23 if (url.SchemeIs(chrome::kJavaScriptScheme)) 26 if (url.SchemeIs(chrome::kJavaScriptScheme))
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 process_ = 83 process_ =
81 new RenderProcessHostImpl(browsing_instance_->browser_context()); 84 new RenderProcessHostImpl(browsing_instance_->browser_context());
82 } 85 }
83 } 86 }
84 87
85 content::GetContentClient()->browser()->SiteInstanceGotProcess(this); 88 content::GetContentClient()->browser()->SiteInstanceGotProcess(this);
86 89
87 // Make sure the process starts at the right max_page_id, and ensure that 90 // Make sure the process starts at the right max_page_id, and ensure that
88 // we send an update to the renderer process. 91 // we send an update to the renderer process.
89 process_->UpdateAndSendMaxPageID(max_page_id_); 92 process_->UpdateAndSendMaxPageID(max_page_id_);
93
94 if (has_site_)
95 LockToOrigin();
90 } 96 }
91 DCHECK(process_); 97 DCHECK(process_);
92 98
93 return process_; 99 return process_;
94 } 100 }
95 101
96 void SiteInstance::SetSite(const GURL& url) { 102 void SiteInstance::SetSite(const GURL& url) {
97 // A SiteInstance's site should not change. 103 // A SiteInstance's site should not change.
98 // TODO(creis): When following links or script navigations, we can currently 104 // TODO(creis): When following links or script navigations, we can currently
99 // render pages from other sites in this SiteInstance. This will eventually 105 // render pages from other sites in this SiteInstance. This will eventually
100 // be fixed, but until then, we should still not set the site of a 106 // be fixed, but until then, we should still not set the site of a
101 // SiteInstance more than once. 107 // SiteInstance more than once.
102 DCHECK(!has_site_); 108 DCHECK(!has_site_);
103 109
104 // Remember that this SiteInstance has been used to load a URL, even if the 110 // Remember that this SiteInstance has been used to load a URL, even if the
105 // URL is invalid. 111 // URL is invalid.
106 has_site_ = true; 112 has_site_ = true;
107 site_ = GetSiteForURL(browsing_instance_->browser_context(), url); 113 site_ = GetSiteForURL(browsing_instance_->browser_context(), url);
108 114
109 // Now that we have a site, register it with the BrowsingInstance. This 115 // Now that we have a site, register it with the BrowsingInstance. This
110 // ensures that we won't create another SiteInstance for this site within 116 // ensures that we won't create another SiteInstance for this site within
111 // the same BrowsingInstance, because all same-site pages within a 117 // the same BrowsingInstance, because all same-site pages within a
112 // BrowsingInstance can script each other. 118 // BrowsingInstance can script each other.
113 browsing_instance_->RegisterSiteInstance(this); 119 browsing_instance_->RegisterSiteInstance(this);
120
121 if (process_)
122 LockToOrigin();
114 } 123 }
115 124
116 bool SiteInstance::HasRelatedSiteInstance(const GURL& url) { 125 bool SiteInstance::HasRelatedSiteInstance(const GURL& url) {
117 return browsing_instance_->HasSiteInstance(url); 126 return browsing_instance_->HasSiteInstance(url);
118 } 127 }
119 128
120 SiteInstance* SiteInstance::GetRelatedSiteInstance(const GURL& url) { 129 SiteInstance* SiteInstance::GetRelatedSiteInstance(const GURL& url) {
121 return browsing_instance_->GetSiteInstanceForURL(url); 130 return browsing_instance_->GetSiteInstanceForURL(url);
122 } 131 }
123 132
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 232
224 void SiteInstance::Observe(int type, 233 void SiteInstance::Observe(int type,
225 const content::NotificationSource& source, 234 const content::NotificationSource& source,
226 const content::NotificationDetails& details) { 235 const content::NotificationDetails& details) {
227 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_TERMINATED); 236 DCHECK(type == content::NOTIFICATION_RENDERER_PROCESS_TERMINATED);
228 content::RenderProcessHost* rph = 237 content::RenderProcessHost* rph =
229 content::Source<content::RenderProcessHost>(source).ptr(); 238 content::Source<content::RenderProcessHost>(source).ptr();
230 if (rph == process_) 239 if (rph == process_)
231 process_ = NULL; 240 process_ = NULL;
232 } 241 }
242
243 void SiteInstance::LockToOrigin() {
244 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
245 if (command_line.HasSwitch(switches::kEnableStrictSiteIsolation)) {
246 ChildProcessSecurityPolicy* policy =
247 ChildProcessSecurityPolicy::GetInstance();
248 policy->LockToOrigin(process_->GetID(), site_);
249 }
250 }
251
OLDNEW
« no previous file with comments | « content/browser/site_instance.h ('k') | content/public/common/content_switches.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698