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

Side by Side Diff: extensions/browser/process_manager.cc

Issue 182253010: Register a Service Worker when an extension is enabled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Test passes! Don't know if it's right though Created 6 years, 9 months 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 | « extensions/browser/process_manager.h ('k') | extensions/browser/service_worker_manager.h » ('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 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
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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 ViewSet result; 277 ViewSet result;
277 for (ExtensionRenderViews::const_iterator iter = 278 for (ExtensionRenderViews::const_iterator iter =
278 all_extension_views_.begin(); 279 all_extension_views_.begin();
279 iter != all_extension_views_.end(); ++iter) { 280 iter != all_extension_views_.end(); ++iter) {
280 result.insert(iter->first); 281 result.insert(iter->first);
281 } 282 }
282 return result; 283 return result;
283 } 284 }
284 285
285 bool ProcessManager::CreateBackgroundHost(const Extension* extension, 286 bool ProcessManager::CreateBackgroundHost(const Extension* extension,
286 const GURL& url) { 287 const GURL& url,
288 const base::Closure& continuation) {
287 // Hosted apps are taken care of from BackgroundContentsService. Ignore them 289 // Hosted apps are taken care of from BackgroundContentsService. Ignore them
288 // here. 290 // here.
289 if (extension->is_hosted_app() || 291 if (extension->is_hosted_app() ||
290 !ExtensionsBrowserClient::Get()-> 292 !ExtensionsBrowserClient::Get()->
291 IsBackgroundPageAllowed(GetBrowserContext())) { 293 IsBackgroundPageAllowed(GetBrowserContext())) {
292 return false; 294 return false;
293 } 295 }
294 296
295 // Don't create multiple background hosts for an extension. 297 // Don't create multiple background hosts for an extension.
296 if (GetBackgroundHostForExtension(extension->id())) 298 if (GetBackgroundHostForExtension(extension->id())) {
299 if (!continuation.is_null())
300 continuation.Run();
297 return true; // TODO(kalman): return false here? It might break things... 301 return true; // TODO(kalman): return false here? It might break things...
302 }
298 303
299 ExtensionHost* host = 304 ExtensionHost* host =
300 new ExtensionHost(extension, GetSiteInstanceForURL(url), url, 305 new ExtensionHost(extension, GetSiteInstanceForURL(url), url,
301 VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); 306 VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
302 host->CreateRenderViewSoon(); 307 host->CreateRenderViewSoon(continuation);
303 OnBackgroundHostCreated(host); 308 OnBackgroundHostCreated(host);
304 return true; 309 return true;
305 } 310 }
306 311
307 ExtensionHost* ProcessManager::GetBackgroundHostForExtension( 312 ExtensionHost* ProcessManager::GetBackgroundHostForExtension(
308 const std::string& extension_id) { 313 const std::string& extension_id) {
309 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); 314 for (ExtensionHostSet::iterator iter = background_hosts_.begin();
310 iter != background_hosts_.end(); ++iter) { 315 iter != background_hosts_.end(); ++iter) {
311 ExtensionHost* host = *iter; 316 ExtensionHost* host = *iter;
312 if (host->extension_id() == extension_id) 317 if (host->extension_id() == extension_id)
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 // The original profile will have its own ProcessManager to 888 // The original profile will have its own ProcessManager to
884 // load the background pages of the spanning extensions. This process 889 // load the background pages of the spanning extensions. This process
885 // manager need only worry about the split mode extensions, which is handled 890 // manager need only worry about the split mode extensions, which is handled
886 // in the NOTIFICATION_BROWSER_WINDOW_READY notification handler. 891 // in the NOTIFICATION_BROWSER_WINDOW_READY notification handler.
887 registrar_.Remove(this, chrome::NOTIFICATION_EXTENSIONS_READY, 892 registrar_.Remove(this, chrome::NOTIFICATION_EXTENSIONS_READY,
888 content::Source<BrowserContext>(original_context)); 893 content::Source<BrowserContext>(original_context));
889 registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_CREATED, 894 registrar_.Remove(this, chrome::NOTIFICATION_PROFILE_CREATED,
890 content::Source<BrowserContext>(original_context)); 895 content::Source<BrowserContext>(original_context));
891 } 896 }
892 897
893 bool IncognitoProcessManager::CreateBackgroundHost(const Extension* extension, 898 bool IncognitoProcessManager::CreateBackgroundHost(
894 const GURL& url) { 899 const Extension* extension,
900 const GURL& url,
901 const base::Closure& continuation) {
895 if (IncognitoInfo::IsSplitMode(extension)) { 902 if (IncognitoInfo::IsSplitMode(extension)) {
896 if (ExtensionsBrowserClient::Get()->IsExtensionIncognitoEnabled( 903 if (ExtensionsBrowserClient::Get()->IsExtensionIncognitoEnabled(
897 extension->id(), GetBrowserContext())) 904 extension->id(), GetBrowserContext()))
898 return ProcessManager::CreateBackgroundHost(extension, url); 905 return ProcessManager::CreateBackgroundHost(extension, url, continuation);
899 } else { 906 } else {
900 // Do nothing. If an extension is spanning, then its original-profile 907 // Do nothing. If an extension is spanning, then its original-profile
901 // background page is shared with incognito, so we don't create another. 908 // background page is shared with incognito, so we don't create another.
902 } 909 }
903 return false; 910 return false;
904 } 911 }
905 912
906 SiteInstance* IncognitoProcessManager::GetSiteInstanceForURL(const GURL& url) { 913 SiteInstance* IncognitoProcessManager::GetSiteInstanceForURL(const GURL& url) {
907 ExtensionRegistry* registry = ExtensionRegistry::Get(GetBrowserContext()); 914 ExtensionRegistry* registry = ExtensionRegistry::Get(GetBrowserContext());
908 if (registry) { 915 if (registry) {
909 const Extension* extension = 916 const Extension* extension =
910 registry->enabled_extensions().GetExtensionOrAppByURL(url); 917 registry->enabled_extensions().GetExtensionOrAppByURL(url);
911 if (extension && !IncognitoInfo::IsSplitMode(extension)) { 918 if (extension && !IncognitoInfo::IsSplitMode(extension)) {
912 return original_manager_->GetSiteInstanceForURL(url); 919 return original_manager_->GetSiteInstanceForURL(url);
913 } 920 }
914 } 921 }
915 return ProcessManager::GetSiteInstanceForURL(url); 922 return ProcessManager::GetSiteInstanceForURL(url);
916 } 923 }
917 924
918 } // namespace extensions 925 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/process_manager.h ('k') | extensions/browser/service_worker_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698