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 "content/browser/browsing_instance.h" | 7 #include "content/browser/browsing_instance.h" |
| 8 #include "content/browser/child_process_launcher.h" |
8 #include "content/browser/child_process_security_policy_impl.h" | 9 #include "content/browser/child_process_security_policy_impl.h" |
9 #include "content/browser/frame_host/debug_urls.h" | 10 #include "content/browser/frame_host/debug_urls.h" |
10 #include "content/browser/frame_host/frame_tree_node.h" | 11 #include "content/browser/frame_host/frame_tree_node.h" |
11 #include "content/browser/renderer_host/render_process_host_impl.h" | 12 #include "content/browser/renderer_host/render_process_host_impl.h" |
12 #include "content/browser/storage_partition_impl.h" | 13 #include "content/browser/storage_partition_impl.h" |
13 #include "content/common/site_isolation_policy.h" | 14 #include "content/common/site_isolation_policy.h" |
14 #include "content/public/browser/content_browser_client.h" | 15 #include "content/public/browser/content_browser_client.h" |
15 #include "content/public/browser/render_process_host_factory.h" | 16 #include "content/public/browser/render_process_host_factory.h" |
16 #include "content/public/browser/web_ui_controller_factory.h" | 17 #include "content/public/browser/web_ui_controller_factory.h" |
17 #include "content/public/common/url_constants.h" | 18 #include "content/public/common/url_constants.h" |
(...skipping 22 matching lines...) Expand all Loading... |
40 process_->RemoveObserver(this); | 41 process_->RemoveObserver(this); |
41 | 42 |
42 // Now that no one is referencing us, we can safely remove ourselves from | 43 // Now that no one is referencing us, we can safely remove ourselves from |
43 // the BrowsingInstance. Any future visits to a page from this site | 44 // the BrowsingInstance. Any future visits to a page from this site |
44 // (within the same BrowsingInstance) can safely create a new SiteInstance. | 45 // (within the same BrowsingInstance) can safely create a new SiteInstance. |
45 if (has_site_) | 46 if (has_site_) |
46 browsing_instance_->UnregisterSiteInstance(this); | 47 browsing_instance_->UnregisterSiteInstance(this); |
47 } | 48 } |
48 | 49 |
49 scoped_refptr<SiteInstanceImpl> SiteInstanceImpl::Create( | 50 scoped_refptr<SiteInstanceImpl> SiteInstanceImpl::Create( |
50 BrowserContext* browser_context) { | 51 BrowserContext* browser_context, |
51 return make_scoped_refptr( | 52 int child_process_param_id) { |
52 new SiteInstanceImpl(new BrowsingInstance(browser_context))); | 53 return make_scoped_refptr(new SiteInstanceImpl( |
| 54 new BrowsingInstance(browser_context, child_process_param_id))); |
53 } | 55 } |
54 | 56 |
55 scoped_refptr<SiteInstanceImpl> SiteInstanceImpl::CreateForURL( | 57 scoped_refptr<SiteInstanceImpl> SiteInstanceImpl::CreateForURL( |
56 BrowserContext* browser_context, | 58 BrowserContext* browser_context, |
57 const GURL& url) { | 59 const GURL& url, |
| 60 int child_process_param_id) { |
58 // This will create a new SiteInstance and BrowsingInstance. | 61 // This will create a new SiteInstance and BrowsingInstance. |
59 scoped_refptr<BrowsingInstance> instance( | 62 scoped_refptr<BrowsingInstance> instance( |
60 new BrowsingInstance(browser_context)); | 63 new BrowsingInstance(browser_context, child_process_param_id)); |
61 return instance->GetSiteInstanceForURL(url); | 64 return instance->GetSiteInstanceForURL(url); |
62 } | 65 } |
63 | 66 |
64 int32_t SiteInstanceImpl::GetId() { | 67 int32_t SiteInstanceImpl::GetId() { |
65 return id_; | 68 return id_; |
66 } | 69 } |
67 | 70 |
68 bool SiteInstanceImpl::HasProcess() const { | 71 bool SiteInstanceImpl::HasProcess() const { |
69 if (process_ != NULL) | 72 if (process_ != NULL) |
70 return true; | 73 return true; |
(...skipping 18 matching lines...) Expand all Loading... |
89 | 92 |
90 class DefaultSubframeProcessHostHolder : public base::SupportsUserData::Data, | 93 class DefaultSubframeProcessHostHolder : public base::SupportsUserData::Data, |
91 public RenderProcessHostObserver { | 94 public RenderProcessHostObserver { |
92 public: | 95 public: |
93 explicit DefaultSubframeProcessHostHolder(BrowserContext* browser_context) | 96 explicit DefaultSubframeProcessHostHolder(BrowserContext* browser_context) |
94 : browser_context_(browser_context) {} | 97 : browser_context_(browser_context) {} |
95 ~DefaultSubframeProcessHostHolder() override {} | 98 ~DefaultSubframeProcessHostHolder() override {} |
96 | 99 |
97 // Gets the correct render process to use for this SiteInstance. | 100 // Gets the correct render process to use for this SiteInstance. |
98 RenderProcessHost* GetProcessHost(SiteInstance* site_instance, | 101 RenderProcessHost* GetProcessHost(SiteInstance* site_instance, |
99 bool is_for_guests_only) { | 102 bool is_for_guests_only, |
| 103 int child_process_param_id) { |
100 StoragePartition* default_partition = | 104 StoragePartition* default_partition = |
101 BrowserContext::GetDefaultStoragePartition(browser_context_); | 105 BrowserContext::GetDefaultStoragePartition(browser_context_); |
102 StoragePartition* partition = | 106 StoragePartition* partition = |
103 BrowserContext::GetStoragePartition(browser_context_, site_instance); | 107 BrowserContext::GetStoragePartition(browser_context_, site_instance); |
104 | 108 |
105 // Is this the default storage partition? If it isn't, then just give it its | 109 // Is this the default storage partition? If it isn't, then just give it its |
106 // own non-shared process. | 110 // own non-shared process. |
107 if (partition != default_partition || is_for_guests_only) { | 111 if (partition != default_partition || is_for_guests_only) { |
108 RenderProcessHostImpl* host = new RenderProcessHostImpl( | 112 RenderProcessHostImpl* host = new RenderProcessHostImpl( |
109 browser_context_, static_cast<StoragePartitionImpl*>(partition), | 113 browser_context_, static_cast<StoragePartitionImpl*>(partition), |
110 is_for_guests_only); | 114 is_for_guests_only, child_process_param_id); |
111 host->SetIsNeverSuitableForReuse(); | 115 host->SetIsNeverSuitableForReuse(); |
112 return host; | 116 return host; |
113 } | 117 } |
114 | 118 |
115 if (host_) { | 119 if (host_) { |
116 // If we already have a shared host for the default storage partition, use | 120 // If we already have a shared host for the default storage partition, use |
117 // it. | 121 // it. |
118 return host_; | 122 return host_; |
119 } | 123 } |
120 | 124 |
121 host_ = new RenderProcessHostImpl( | 125 host_ = new RenderProcessHostImpl( |
122 browser_context_, static_cast<StoragePartitionImpl*>(partition), | 126 browser_context_, static_cast<StoragePartitionImpl*>(partition), |
123 false /* for guests only */); | 127 false /* for guests only */, child_process_param_id); |
124 host_->SetIsNeverSuitableForReuse(); | 128 host_->SetIsNeverSuitableForReuse(); |
125 host_->AddObserver(this); | 129 host_->AddObserver(this); |
126 | 130 |
127 return host_; | 131 return host_; |
128 } | 132 } |
129 | 133 |
130 void RenderProcessHostDestroyed(RenderProcessHost* host) override { | 134 void RenderProcessHostDestroyed(RenderProcessHost* host) override { |
131 DCHECK_EQ(host_, host); | 135 DCHECK_EQ(host_, host); |
132 host_->RemoveObserver(this); | 136 host_->RemoveObserver(this); |
133 host_ = nullptr; | 137 host_ = nullptr; |
(...skipping 13 matching lines...) Expand all Loading... |
147 BrowserContext* browser_context, | 151 BrowserContext* browser_context, |
148 bool is_for_guests_only) { | 152 bool is_for_guests_only) { |
149 DefaultSubframeProcessHostHolder* holder = | 153 DefaultSubframeProcessHostHolder* holder = |
150 static_cast<DefaultSubframeProcessHostHolder*>( | 154 static_cast<DefaultSubframeProcessHostHolder*>( |
151 browser_context->GetUserData(&kDefaultSubframeProcessHostHolderKey)); | 155 browser_context->GetUserData(&kDefaultSubframeProcessHostHolderKey)); |
152 if (!holder) { | 156 if (!holder) { |
153 holder = new DefaultSubframeProcessHostHolder(browser_context); | 157 holder = new DefaultSubframeProcessHostHolder(browser_context); |
154 browser_context->SetUserData(kDefaultSubframeProcessHostHolderKey, holder); | 158 browser_context->SetUserData(kDefaultSubframeProcessHostHolderKey, holder); |
155 } | 159 } |
156 | 160 |
157 return holder->GetProcessHost(this, is_for_guests_only); | 161 return holder->GetProcessHost(this, is_for_guests_only, |
| 162 browsing_instance_->child_process_param_id()); |
158 } | 163 } |
159 | 164 |
160 RenderProcessHost* SiteInstanceImpl::GetProcess() { | 165 RenderProcessHost* SiteInstanceImpl::GetProcess() { |
161 // TODO(erikkay) It would be nice to ensure that the renderer type had been | 166 // TODO(erikkay) It would be nice to ensure that the renderer type had been |
162 // properly set before we get here. The default tab creation case winds up | 167 // properly set before we get here. The default tab creation case winds up |
163 // with no site set at this point, so it will default to TYPE_NORMAL. This | 168 // with no site set at this point, so it will default to TYPE_NORMAL. This |
164 // may not be correct, so we'll wind up potentially creating a process that | 169 // may not be correct, so we'll wind up potentially creating a process that |
165 // we then throw away, or worse sharing a process with the wrong process type. | 170 // we then throw away, or worse sharing a process with the wrong process type. |
166 // See crbug.com/43448. | 171 // See crbug.com/43448. |
167 | 172 |
(...skipping 26 matching lines...) Expand all Loading... |
194 | 199 |
195 // Otherwise (or if that fails), create a new one. | 200 // Otherwise (or if that fails), create a new one. |
196 if (!process_) { | 201 if (!process_) { |
197 if (g_render_process_host_factory_) { | 202 if (g_render_process_host_factory_) { |
198 process_ = g_render_process_host_factory_->CreateRenderProcessHost( | 203 process_ = g_render_process_host_factory_->CreateRenderProcessHost( |
199 browser_context, this); | 204 browser_context, this); |
200 } else { | 205 } else { |
201 StoragePartitionImpl* partition = | 206 StoragePartitionImpl* partition = |
202 static_cast<StoragePartitionImpl*>( | 207 static_cast<StoragePartitionImpl*>( |
203 BrowserContext::GetStoragePartition(browser_context, this)); | 208 BrowserContext::GetStoragePartition(browser_context, this)); |
204 process_ = new RenderProcessHostImpl(browser_context, partition, | 209 process_ = new RenderProcessHostImpl( |
205 is_for_guests_only); | 210 browser_context, partition, is_for_guests_only, |
| 211 browsing_instance_->child_process_param_id()); |
206 } | 212 } |
207 } | 213 } |
208 CHECK(process_); | 214 CHECK(process_); |
209 process_->AddObserver(this); | 215 process_->AddObserver(this); |
210 | 216 |
211 // If we are using process-per-site, we need to register this process | 217 // If we are using process-per-site, we need to register this process |
212 // for the current site so that we can find it again. (If no site is set | 218 // for the current site so that we can find it again. (If no site is set |
213 // at this time, we will register it in SetSite().) | 219 // at this time, we will register it in SetSite().) |
214 if (use_process_per_site) { | 220 if (use_process_per_site) { |
215 RenderProcessHostImpl::RegisterProcessHostForSite(browser_context, | 221 RenderProcessHostImpl::RegisterProcessHostForSite(browser_context, |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 const RenderProcessHostFactory* rph_factory) { | 361 const RenderProcessHostFactory* rph_factory) { |
356 g_render_process_host_factory_ = rph_factory; | 362 g_render_process_host_factory_ = rph_factory; |
357 } | 363 } |
358 | 364 |
359 BrowserContext* SiteInstanceImpl::GetBrowserContext() const { | 365 BrowserContext* SiteInstanceImpl::GetBrowserContext() const { |
360 return browsing_instance_->browser_context(); | 366 return browsing_instance_->browser_context(); |
361 } | 367 } |
362 | 368 |
363 // static | 369 // static |
364 scoped_refptr<SiteInstance> SiteInstance::Create( | 370 scoped_refptr<SiteInstance> SiteInstance::Create( |
365 BrowserContext* browser_context) { | 371 BrowserContext* browser_context, |
366 return SiteInstanceImpl::Create(browser_context); | 372 int child_process_param_id) { |
| 373 return SiteInstanceImpl::Create(browser_context, child_process_param_id); |
367 } | 374 } |
368 | 375 |
369 // static | 376 // static |
370 scoped_refptr<SiteInstance> SiteInstance::CreateForURL( | 377 scoped_refptr<SiteInstance> SiteInstance::CreateForURL( |
371 BrowserContext* browser_context, | 378 BrowserContext* browser_context, |
372 const GURL& url) { | 379 const GURL& url) { |
373 return SiteInstanceImpl::CreateForURL(browser_context, url); | 380 return SiteInstanceImpl::CreateForURL(browser_context, url, |
| 381 ChildProcessLauncher::DEFAULT_PARAM_ID); |
374 } | 382 } |
375 | 383 |
376 // static | 384 // static |
377 bool SiteInstance::IsSameWebSite(BrowserContext* browser_context, | 385 bool SiteInstance::IsSameWebSite(BrowserContext* browser_context, |
378 const GURL& real_src_url, | 386 const GURL& real_src_url, |
379 const GURL& real_dest_url) { | 387 const GURL& real_dest_url) { |
380 GURL src_url = SiteInstanceImpl::GetEffectiveURL(browser_context, | 388 GURL src_url = SiteInstanceImpl::GetEffectiveURL(browser_context, |
381 real_src_url); | 389 real_src_url); |
382 GURL dest_url = SiteInstanceImpl::GetEffectiveURL(browser_context, | 390 GURL dest_url = SiteInstanceImpl::GetEffectiveURL(browser_context, |
383 real_dest_url); | 391 real_dest_url); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 browsing_instance_->browser_context(), site_)) | 529 browsing_instance_->browser_context(), site_)) |
522 return; | 530 return; |
523 | 531 |
524 ChildProcessSecurityPolicyImpl* policy = | 532 ChildProcessSecurityPolicyImpl* policy = |
525 ChildProcessSecurityPolicyImpl::GetInstance(); | 533 ChildProcessSecurityPolicyImpl::GetInstance(); |
526 policy->LockToOrigin(process_->GetID(), site_); | 534 policy->LockToOrigin(process_->GetID(), site_); |
527 } | 535 } |
528 } | 536 } |
529 | 537 |
530 } // namespace content | 538 } // namespace content |
OLD | NEW |