| 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 "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/extensions/extension_event_router.h" | 9 #include "chrome/browser/extensions/extension_event_router.h" |
| 10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
| 11 #if defined(OS_MACOSX) | 11 #if defined(OS_MACOSX) |
| 12 #include "chrome/browser/extensions/extension_host_mac.h" | 12 #include "chrome/browser/extensions/extension_host_mac.h" |
| 13 #endif | 13 #endif |
| 14 #include "chrome/browser/extensions/extension_host.h" | 14 #include "chrome/browser/extensions/extension_host.h" |
| 15 #include "chrome/browser/extensions/extension_info_map.h" | 15 #include "chrome/browser/extensions/extension_info_map.h" |
| 16 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/common/chrome_notification_types.h" | 19 #include "chrome/common/chrome_notification_types.h" |
| 20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/chrome_view_type.h" | 21 #include "chrome/common/chrome_view_type.h" |
| 22 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
| 23 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 24 #include "content/browser/renderer_host/render_view_host.h" | 24 #include "content/browser/renderer_host/render_view_host.h" |
| 25 #include "content/browser/site_instance.h" | |
| 26 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 28 #include "content/public/browser/render_process_host.h" | 27 #include "content/public/browser/render_process_host.h" |
| 29 #include "content/public/browser/render_view_host_delegate.h" | 28 #include "content/public/browser/render_view_host_delegate.h" |
| 29 #include "content/public/browser/site_instance.h" |
| 30 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 31 #include "content/public/common/renderer_preferences.h" | 31 #include "content/public/common/renderer_preferences.h" |
| 32 | 32 |
| 33 using content::BrowserThread; | 33 using content::BrowserThread; |
| 34 using content::OpenURLParams; | 34 using content::OpenURLParams; |
| 35 using content::Referrer; | 35 using content::Referrer; |
| 36 using content::SiteInstance; |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 // Incognito profiles use this process manager. It is mostly a shim that decides | 40 // Incognito profiles use this process manager. It is mostly a shim that decides |
| 40 // whether to fall back on the original profile's ExtensionProcessManager based | 41 // whether to fall back on the original profile's ExtensionProcessManager based |
| 41 // on whether a given extension uses "split" or "spanning" incognito behavior. | 42 // on whether a given extension uses "split" or "spanning" incognito behavior. |
| 42 class IncognitoExtensionProcessManager : public ExtensionProcessManager { | 43 class IncognitoExtensionProcessManager : public ExtensionProcessManager { |
| 43 public: | 44 public: |
| 44 explicit IncognitoExtensionProcessManager(Profile* profile); | 45 explicit IncognitoExtensionProcessManager(Profile* profile); |
| 45 virtual ~IncognitoExtensionProcessManager() {} | 46 virtual ~IncognitoExtensionProcessManager() {} |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 // | 88 // |
| 88 | 89 |
| 89 // static | 90 // static |
| 90 ExtensionProcessManager* ExtensionProcessManager::Create(Profile* profile) { | 91 ExtensionProcessManager* ExtensionProcessManager::Create(Profile* profile) { |
| 91 return (profile->IsOffTheRecord()) ? | 92 return (profile->IsOffTheRecord()) ? |
| 92 new IncognitoExtensionProcessManager(profile) : | 93 new IncognitoExtensionProcessManager(profile) : |
| 93 new ExtensionProcessManager(profile); | 94 new ExtensionProcessManager(profile); |
| 94 } | 95 } |
| 95 | 96 |
| 96 ExtensionProcessManager::ExtensionProcessManager(Profile* profile) | 97 ExtensionProcessManager::ExtensionProcessManager(Profile* profile) |
| 97 : site_instance_(SiteInstance::CreateSiteInstance(profile)) { | 98 : site_instance_(SiteInstance::Create(profile)) { |
| 98 Profile* original_profile = profile->GetOriginalProfile(); | 99 Profile* original_profile = profile->GetOriginalProfile(); |
| 99 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 100 registrar_.Add(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
| 100 content::Source<Profile>(original_profile)); | 101 content::Source<Profile>(original_profile)); |
| 101 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 102 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 102 content::Source<Profile>(original_profile)); | 103 content::Source<Profile>(original_profile)); |
| 103 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, | 104 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
| 104 content::Source<Profile>(original_profile)); | 105 content::Source<Profile>(original_profile)); |
| 105 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 106 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 106 content::Source<Profile>(profile)); | 107 content::Source<Profile>(profile)); |
| 107 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, | 108 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 RenderViewHost* render_view_host, | 274 RenderViewHost* render_view_host, |
| 274 const Extension* extension) { | 275 const Extension* extension) { |
| 275 all_extension_views_.insert(render_view_host); | 276 all_extension_views_.insert(render_view_host); |
| 276 } | 277 } |
| 277 | 278 |
| 278 void ExtensionProcessManager::UnregisterRenderViewHost( | 279 void ExtensionProcessManager::UnregisterRenderViewHost( |
| 279 RenderViewHost* render_view_host) { | 280 RenderViewHost* render_view_host) { |
| 280 all_extension_views_.erase(render_view_host); | 281 all_extension_views_.erase(render_view_host); |
| 281 } | 282 } |
| 282 | 283 |
| 283 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(const GURL& url) { | 284 SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL( |
| 285 const GURL& url) { |
| 284 return site_instance_->GetRelatedSiteInstance(url); | 286 return site_instance_->GetRelatedSiteInstance(url); |
| 285 } | 287 } |
| 286 | 288 |
| 287 bool ExtensionProcessManager::HasExtensionHost(ExtensionHost* host) const { | 289 bool ExtensionProcessManager::HasExtensionHost(ExtensionHost* host) const { |
| 288 return all_hosts_.find(host) != all_hosts_.end(); | 290 return all_hosts_.find(host) != all_hosts_.end(); |
| 289 } | 291 } |
| 290 | 292 |
| 291 void ExtensionProcessManager::OnExtensionIdle(const std::string& extension_id) { | 293 void ExtensionProcessManager::OnExtensionIdle(const std::string& extension_id) { |
| 292 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); | 294 ExtensionHost* host = GetBackgroundHostForExtension(extension_id); |
| 293 if (host && !HasVisibleViews(extension_id)) { | 295 if (host && !HasVisibleViews(extension_id)) { |
| 294 Profile* profile = GetProfile(); | 296 Profile* profile = GetProfile(); |
| 295 if (!profile->GetExtensionEventRouter()->HasInFlightEvents(extension_id)) | 297 if (!profile->GetExtensionEventRouter()->HasInFlightEvents(extension_id)) |
| 296 CloseBackgroundHost(host); | 298 CloseBackgroundHost(host); |
| 297 } | 299 } |
| 298 } | 300 } |
| 299 | 301 |
| 300 bool ExtensionProcessManager::HasVisibleViews(const std::string& extension_id) { | 302 bool ExtensionProcessManager::HasVisibleViews(const std::string& extension_id) { |
| 301 const std::set<RenderViewHost*>& views = | 303 const std::set<RenderViewHost*>& views = |
| 302 GetRenderViewHostsForExtension(extension_id); | 304 GetRenderViewHostsForExtension(extension_id); |
| 303 for (std::set<RenderViewHost*>::const_iterator it = views.begin(); | 305 for (std::set<RenderViewHost*>::const_iterator it = views.begin(); |
| 304 it != views.end(); ++it) { | 306 it != views.end(); ++it) { |
| 305 const RenderViewHost* host = *it; | 307 const RenderViewHost* host = *it; |
| 306 if (host->site_instance()->site().host() == extension_id && | 308 if (host->site_instance()->GetSite().host() == extension_id && |
| 307 host->delegate()->GetRenderViewType() != | 309 host->delegate()->GetRenderViewType() != |
| 308 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { | 310 chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE) { |
| 309 return true; | 311 return true; |
| 310 } | 312 } |
| 311 } | 313 } |
| 312 return false; | 314 return false; |
| 313 } | 315 } |
| 314 | 316 |
| 315 void ExtensionProcessManager::Observe( | 317 void ExtensionProcessManager::Observe( |
| 316 int type, | 318 int type, |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 if (service && service->is_ready()) | 493 if (service && service->is_ready()) |
| 492 CreateBackgroundHostsForProfileStartup(this, service->extensions()); | 494 CreateBackgroundHostsForProfileStartup(this, service->extensions()); |
| 493 } | 495 } |
| 494 break; | 496 break; |
| 495 } | 497 } |
| 496 default: | 498 default: |
| 497 ExtensionProcessManager::Observe(type, source, details); | 499 ExtensionProcessManager::Observe(type, source, details); |
| 498 break; | 500 break; |
| 499 } | 501 } |
| 500 } | 502 } |
| OLD | NEW |