| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "extensions/browser/process_manager.h" | 5 #include "extensions/browser/process_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 // Incognito profiles use this process manager. It is mostly a shim that decides | 92 // Incognito profiles use this process manager. It is mostly a shim that decides |
| 93 // whether to fall back on the original profile's ProcessManager based | 93 // whether to fall back on the original profile's ProcessManager based |
| 94 // on whether a given extension uses "split" or "spanning" incognito behavior. | 94 // on whether a given extension uses "split" or "spanning" incognito behavior. |
| 95 class IncognitoProcessManager : public ProcessManager { | 95 class IncognitoProcessManager : public ProcessManager { |
| 96 public: | 96 public: |
| 97 IncognitoProcessManager(BrowserContext* incognito_context, | 97 IncognitoProcessManager(BrowserContext* incognito_context, |
| 98 BrowserContext* original_context, | 98 BrowserContext* original_context, |
| 99 ProcessManager* original_manager); | 99 ProcessManager* original_manager); |
| 100 virtual ~IncognitoProcessManager() {} | 100 virtual ~IncognitoProcessManager() {} |
| 101 virtual bool CreateBackgroundHost(const Extension* extension, | 101 virtual bool CreateBackgroundHost(const Extension* extension, |
| 102 const GURL& url) OVERRIDE; | 102 const GURL& url, |
| 103 const base::Closure& continuation) OVERRIDE; |
| 103 virtual SiteInstance* GetSiteInstanceForURL(const GURL& url) OVERRIDE; | 104 virtual SiteInstance* GetSiteInstanceForURL(const GURL& url) OVERRIDE; |
| 104 | 105 |
| 105 private: | 106 private: |
| 106 ProcessManager* original_manager_; | 107 ProcessManager* original_manager_; |
| 107 | 108 |
| 108 DISALLOW_COPY_AND_ASSIGN(IncognitoProcessManager); | 109 DISALLOW_COPY_AND_ASSIGN(IncognitoProcessManager); |
| 109 }; | 110 }; |
| 110 | 111 |
| 111 static void CreateBackgroundHostForExtensionLoad( | 112 static void CreateBackgroundHostForExtensionLoad( |
| 112 ProcessManager* manager, const Extension* extension) { | 113 ProcessManager* manager, const Extension* extension) { |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 | 285 |
| 285 void ProcessManager::AddObserver(ProcessManagerObserver* observer) { | 286 void ProcessManager::AddObserver(ProcessManagerObserver* observer) { |
| 286 observer_list_.AddObserver(observer); | 287 observer_list_.AddObserver(observer); |
| 287 } | 288 } |
| 288 | 289 |
| 289 void ProcessManager::RemoveObserver(ProcessManagerObserver* observer) { | 290 void ProcessManager::RemoveObserver(ProcessManagerObserver* observer) { |
| 290 observer_list_.RemoveObserver(observer); | 291 observer_list_.RemoveObserver(observer); |
| 291 } | 292 } |
| 292 | 293 |
| 293 bool ProcessManager::CreateBackgroundHost(const Extension* extension, | 294 bool ProcessManager::CreateBackgroundHost(const Extension* extension, |
| 294 const GURL& url) { | 295 const GURL& url, |
| 296 const base::Closure& continuation) { |
| 295 // Hosted apps are taken care of from BackgroundContentsService. Ignore them | 297 // Hosted apps are taken care of from BackgroundContentsService. Ignore them |
| 296 // here. | 298 // here. |
| 297 if (extension->is_hosted_app() || | 299 if (extension->is_hosted_app() || |
| 298 !ExtensionsBrowserClient::Get()-> | 300 !ExtensionsBrowserClient::Get()-> |
| 299 IsBackgroundPageAllowed(GetBrowserContext())) { | 301 IsBackgroundPageAllowed(GetBrowserContext())) { |
| 300 return false; | 302 return false; |
| 301 } | 303 } |
| 302 | 304 |
| 303 // Don't create multiple background hosts for an extension. | 305 // Don't create multiple background hosts for an extension. |
| 304 if (GetBackgroundHostForExtension(extension->id())) | 306 if (GetBackgroundHostForExtension(extension->id())) { |
| 307 if (!continuation.is_null()) |
| 308 continuation.Run(); |
| 305 return true; // TODO(kalman): return false here? It might break things... | 309 return true; // TODO(kalman): return false here? It might break things... |
| 310 } |
| 306 | 311 |
| 307 ExtensionHost* host = | 312 ExtensionHost* host = |
| 308 new ExtensionHost(extension, GetSiteInstanceForURL(url), url, | 313 new ExtensionHost(extension, GetSiteInstanceForURL(url), url, |
| 309 VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); | 314 VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); |
| 310 host->CreateRenderViewSoon(); | 315 host->CreateRenderViewSoon(continuation); |
| 311 OnBackgroundHostCreated(host); | 316 OnBackgroundHostCreated(host); |
| 312 return true; | 317 return true; |
| 313 } | 318 } |
| 314 | 319 |
| 315 ExtensionHost* ProcessManager::GetBackgroundHostForExtension( | 320 ExtensionHost* ProcessManager::GetBackgroundHostForExtension( |
| 316 const std::string& extension_id) { | 321 const std::string& extension_id) { |
| 317 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); | 322 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); |
| 318 iter != background_hosts_.end(); ++iter) { | 323 iter != background_hosts_.end(); ++iter) { |
| 319 ExtensionHost* host = *iter; | 324 ExtensionHost* host = *iter; |
| 320 if (host->extension_id() == extension_id) | 325 if (host->extension_id() == extension_id) |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 // The original profile will have its own ProcessManager to | 897 // The original profile will have its own ProcessManager to |
| 893 // load the background pages of the spanning extensions. This process | 898 // load the background pages of the spanning extensions. This process |
| 894 // manager need only worry about the split mode extensions, which is handled | 899 // manager need only worry about the split mode extensions, which is handled |
| 895 // in the NOTIFICATION_BROWSER_WINDOW_READY notification handler. | 900 // in the NOTIFICATION_BROWSER_WINDOW_READY notification handler. |
| 896 registrar_.Remove(this, chrome::NOTIFICATION_EXTENSIONS_READY, | 901 registrar_.Remove(this, chrome::NOTIFICATION_EXTENSIONS_READY, |
| 897 content::Source<BrowserContext>(original_context)); | 902 content::Source<BrowserContext>(original_context)); |
| 898 registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_CREATED, | 903 registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_CREATED, |
| 899 content::Source<BrowserContext>(original_context)); | 904 content::Source<BrowserContext>(original_context)); |
| 900 } | 905 } |
| 901 | 906 |
| 902 bool IncognitoProcessManager::CreateBackgroundHost(const Extension* extension, | 907 bool IncognitoProcessManager::CreateBackgroundHost( |
| 903 const GURL& url) { | 908 const Extension* extension, |
| 909 const GURL& url, |
| 910 const base::Closure& continuation) { |
| 904 if (IncognitoInfo::IsSplitMode(extension)) { | 911 if (IncognitoInfo::IsSplitMode(extension)) { |
| 905 if (ExtensionsBrowserClient::Get()->IsExtensionIncognitoEnabled( | 912 if (ExtensionsBrowserClient::Get()->IsExtensionIncognitoEnabled( |
| 906 extension->id(), GetBrowserContext())) | 913 extension->id(), GetBrowserContext())) |
| 907 return ProcessManager::CreateBackgroundHost(extension, url); | 914 return ProcessManager::CreateBackgroundHost(extension, url, continuation); |
| 908 } else { | 915 } else { |
| 909 // Do nothing. If an extension is spanning, then its original-profile | 916 // Do nothing. If an extension is spanning, then its original-profile |
| 910 // background page is shared with incognito, so we don't create another. | 917 // background page is shared with incognito, so we don't create another. |
| 911 } | 918 } |
| 912 return false; | 919 return false; |
| 913 } | 920 } |
| 914 | 921 |
| 915 SiteInstance* IncognitoProcessManager::GetSiteInstanceForURL(const GURL& url) { | 922 SiteInstance* IncognitoProcessManager::GetSiteInstanceForURL(const GURL& url) { |
| 916 ExtensionRegistry* registry = ExtensionRegistry::Get(GetBrowserContext()); | 923 ExtensionRegistry* registry = ExtensionRegistry::Get(GetBrowserContext()); |
| 917 if (registry) { | 924 if (registry) { |
| 918 const Extension* extension = | 925 const Extension* extension = |
| 919 registry->enabled_extensions().GetExtensionOrAppByURL(url); | 926 registry->enabled_extensions().GetExtensionOrAppByURL(url); |
| 920 if (extension && !IncognitoInfo::IsSplitMode(extension)) { | 927 if (extension && !IncognitoInfo::IsSplitMode(extension)) { |
| 921 return original_manager_->GetSiteInstanceForURL(url); | 928 return original_manager_->GetSiteInstanceForURL(url); |
| 922 } | 929 } |
| 923 } | 930 } |
| 924 return ProcessManager::GetSiteInstanceForURL(url); | 931 return ProcessManager::GetSiteInstanceForURL(url); |
| 925 } | 932 } |
| 926 | 933 |
| 927 } // namespace extensions | 934 } // namespace extensions |
| OLD | NEW |