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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "chrome/browser/extensions/extension_process_manager.h" | 7 #include "chrome/browser/extensions/extension_process_manager.h" |
8 | 8 |
9 #include "chrome/browser/ui/browser_window.h" | 9 #include "chrome/browser/ui/browser_window.h" |
10 #include "content/browser/browsing_instance.h" | 10 #include "content/browser/browsing_instance.h" |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 232 |
233 void ExtensionProcessManager::RegisterExtensionSiteInstance( | 233 void ExtensionProcessManager::RegisterExtensionSiteInstance( |
234 SiteInstance* site_instance, | 234 SiteInstance* site_instance, |
235 const Extension* extension) { | 235 const Extension* extension) { |
236 if (!site_instance->HasProcess()) { | 236 if (!site_instance->HasProcess()) { |
237 NOTREACHED(); | 237 NOTREACHED(); |
238 return; | 238 return; |
239 } | 239 } |
240 | 240 |
241 int site_instance_id = site_instance->id(); | 241 int site_instance_id = site_instance->id(); |
242 int host_id = site_instance->GetProcess()->id(); | 242 int render_process_id = site_instance->GetProcess()->id(); |
243 process_ids_[host_id].insert(site_instance_id); | 243 process_ids_[render_process_id].insert(site_instance_id); |
244 | 244 |
245 // Register process hosting extensions that have access to extension bindings | 245 // Register process hosting extensions that have access to extension bindings |
246 // with the ExtensionInfoMap on the IO thread. | 246 // with the ExtensionInfoMap on the IO thread. |
247 Profile* profile = | 247 Profile* profile = |
248 Profile::FromBrowserContext(browsing_instance_->browser_context()); | 248 Profile::FromBrowserContext(browsing_instance_->browser_context()); |
249 ExtensionService* service = profile->GetExtensionService(); | 249 ExtensionService* service = profile->GetExtensionService(); |
250 if (service->ExtensionBindingsAllowed(extension->url())) { | 250 if (service->ExtensionBindingsAllowed(extension->url())) { |
251 Profile* profile = Profile::FromBrowserContext( | 251 Profile* profile = Profile::FromBrowserContext( |
252 site_instance->GetProcess()->browser_context()); | 252 site_instance->GetProcess()->browser_context()); |
253 BrowserThread::PostTask( | 253 BrowserThread::PostTask( |
254 BrowserThread::IO, FROM_HERE, | 254 BrowserThread::IO, FROM_HERE, |
255 base::Bind(&ExtensionInfoMap::BindingsEnabledForProcess, | 255 base::Bind(&ExtensionInfoMap::BindingsEnabledForProcess, |
256 profile->GetExtensionInfoMap(), | 256 profile->GetExtensionInfoMap(), |
257 host_id)); | 257 render_process_id)); |
258 } | 258 } |
259 | 259 |
260 SiteInstanceIDMap::const_iterator it = extension_ids_.find(site_instance_id); | 260 SiteInstanceIDMap::const_iterator it = extension_ids_.find(site_instance_id); |
261 if (it != extension_ids_.end() && (*it).second == extension->id()) | 261 if (it != extension_ids_.end() && (*it).second == extension->id()) |
262 return; | 262 return; |
263 | 263 |
264 // SiteInstance ids should get removed from the map before the extension ids | 264 // SiteInstance ids should get removed from the map before the extension ids |
265 // get used for a new SiteInstance. | 265 // get used for a new SiteInstance. |
266 DCHECK(it == extension_ids_.end()); | 266 DCHECK(it == extension_ids_.end()); |
267 extension_ids_[site_instance_id] = extension->id(); | 267 extension_ids_[site_instance_id] = extension->id(); |
268 } | 268 } |
269 | 269 |
270 void ExtensionProcessManager::UnregisterExtensionSiteInstance( | 270 void ExtensionProcessManager::UnregisterExtensionSiteInstance( |
271 SiteInstance* site_instance) { | 271 SiteInstance* site_instance) { |
272 int site_instance_id = site_instance->id(); | 272 int site_instance_id = site_instance->id(); |
273 SiteInstanceIDMap::iterator it = extension_ids_.find(site_instance_id); | 273 SiteInstanceIDMap::iterator it = extension_ids_.find(site_instance_id); |
274 if (it != extension_ids_.end()) { | 274 if (it != extension_ids_.end()) { |
275 extension_ids_.erase(it++); | 275 extension_ids_.erase(it++); |
276 } | 276 } |
277 if (site_instance->HasProcess()) { | 277 if (site_instance->HasProcess()) { |
278 int host_id = site_instance->GetProcess()->id(); | 278 int render_process_id = site_instance->GetProcess()->id(); |
279 ProcessIDMap::iterator host = process_ids_.find(host_id); | 279 ProcessIDMap::iterator host = process_ids_.find(render_process_id); |
280 if (host != process_ids_.end()) { | 280 if (host != process_ids_.end()) { |
281 host->second.erase(site_instance_id); | 281 host->second.erase(site_instance_id); |
282 if (host->second.empty()) { | 282 if (host->second.empty()) { |
283 process_ids_.erase(host++); | 283 process_ids_.erase(host++); |
284 Profile* profile = Profile::FromBrowserContext( | 284 Profile* profile = Profile::FromBrowserContext( |
285 site_instance->GetProcess()->browser_context()); | 285 site_instance->GetProcess()->browser_context()); |
286 BrowserThread::PostTask( | 286 BrowserThread::PostTask( |
287 BrowserThread::IO, FROM_HERE, | 287 BrowserThread::IO, FROM_HERE, |
288 base::Bind(&ExtensionInfoMap::BindingsDisabledForProcess, | 288 base::Bind(&ExtensionInfoMap::BindingsDisabledForProcess, |
289 profile->GetExtensionInfoMap(), | 289 profile->GetExtensionInfoMap(), |
290 host_id)); | 290 render_process_id)); |
291 } | 291 } |
292 } | 292 } |
293 } | 293 } |
294 } | 294 } |
295 | 295 |
296 bool ExtensionProcessManager::AreBindingsEnabledForProcess(int host_id) { | 296 bool ExtensionProcessManager::IsExtensionProcess(int render_process_id) { |
297 ProcessIDMap::iterator it = process_ids_.find(host_id); | 297 return process_ids_.find(render_process_id) != process_ids_.end(); |
298 if (process_ids_.find(host_id) == process_ids_.end()) | 298 } |
| 299 |
| 300 bool ExtensionProcessManager::AreBindingsEnabledForProcess( |
| 301 int render_process_id) { |
| 302 ProcessIDMap::iterator it = process_ids_.find(render_process_id); |
| 303 if (it == process_ids_.end()) |
299 return false; | 304 return false; |
300 | 305 |
301 Profile* profile = | 306 Profile* profile = |
302 Profile::FromBrowserContext(browsing_instance_->browser_context()); | 307 Profile::FromBrowserContext(browsing_instance_->browser_context()); |
303 ExtensionService* service = profile->GetExtensionService(); | 308 ExtensionService* service = profile->GetExtensionService(); |
304 for (std::set<int>::iterator site_instance_id = it->second.begin(); | 309 for (std::set<int>::iterator site_instance_id = it->second.begin(); |
305 site_instance_id != it->second.end(); ++site_instance_id) { | 310 site_instance_id != it->second.end(); ++site_instance_id) { |
306 const Extension* extension = | 311 const Extension* extension = |
307 GetExtensionForSiteInstance(*site_instance_id); | 312 GetExtensionForSiteInstance(*site_instance_id); |
308 if (extension == NULL) | 313 if (extension == NULL) |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 if (service && service->is_ready()) | 571 if (service && service->is_ready()) |
567 CreateBackgroundHostsForProfileStartup(this, service->extensions()); | 572 CreateBackgroundHostsForProfileStartup(this, service->extensions()); |
568 } | 573 } |
569 break; | 574 break; |
570 } | 575 } |
571 default: | 576 default: |
572 ExtensionProcessManager::Observe(type, source, details); | 577 ExtensionProcessManager::Observe(type, source, details); |
573 break; | 578 break; |
574 } | 579 } |
575 } | 580 } |
OLD | NEW |