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/command_line.h" | |
5 #include "chrome/browser/extensions/extension_process_manager.h" | 6 #include "chrome/browser/extensions/extension_process_manager.h" |
6 | 7 |
7 #include "chrome/browser/ui/browser_window.h" | 8 #include "chrome/browser/ui/browser_window.h" |
8 #include "content/browser/browsing_instance.h" | 9 #include "content/browser/browsing_instance.h" |
9 #if defined(OS_MACOSX) | 10 #if defined(OS_MACOSX) |
10 #include "chrome/browser/extensions/extension_host_mac.h" | 11 #include "chrome/browser/extensions/extension_host_mac.h" |
11 #endif | 12 #endif |
12 #include "chrome/browser/extensions/extension_host.h" | 13 #include "chrome/browser/extensions/extension_host.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
18 #include "chrome/common/chrome_switches.h" | |
17 #include "chrome/common/extensions/extension.h" | 19 #include "chrome/common/extensions/extension.h" |
18 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
19 #include "content/browser/site_instance.h" | 21 #include "content/browser/site_instance.h" |
20 #include "content/browser/tab_contents/tab_contents.h" | 22 #include "content/browser/tab_contents/tab_contents.h" |
21 #include "content/common/notification_service.h" | 23 #include "content/common/notification_service.h" |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 // Incognito profiles use this process manager. It is mostly a shim that decides | 27 // Incognito profiles use this process manager. It is mostly a shim that decides |
26 // whether to fall back on the original profile's ExtensionProcessManager based | 28 // whether to fall back on the original profile's ExtensionProcessManager based |
(...skipping 21 matching lines...) Expand all Loading... | |
48 // Returns the extension for an URL, which can either be a chrome-extension | 50 // Returns the extension for an URL, which can either be a chrome-extension |
49 // URL or a web app URL. | 51 // URL or a web app URL. |
50 const Extension* GetExtensionOrAppByURL(const GURL& url); | 52 const Extension* GetExtensionOrAppByURL(const GURL& url); |
51 | 53 |
52 // Returns true if the extension is allowed to run in incognito mode. | 54 // Returns true if the extension is allowed to run in incognito mode. |
53 bool IsIncognitoEnabled(const Extension* extension); | 55 bool IsIncognitoEnabled(const Extension* extension); |
54 | 56 |
55 ExtensionProcessManager* original_manager_; | 57 ExtensionProcessManager* original_manager_; |
56 }; | 58 }; |
57 | 59 |
58 static void CreateBackgroundHost( | 60 static void CreateBackgroundHostForExtensionLoad( |
59 ExtensionProcessManager* manager, const Extension* extension) { | 61 ExtensionProcessManager* manager, const Extension* extension) { |
60 // Start the process for the master page, if it exists. | 62 // Start the process for the master page, if it exists and we're not lazy. |
61 if (extension->background_url().is_valid()) | 63 if (extension->background_url().is_valid()) |
62 manager->CreateBackgroundHost(extension, extension->background_url()); | 64 manager->CreateBackgroundHost(extension, extension->background_url()); |
63 } | 65 } |
64 | 66 |
65 static void CreateBackgroundHosts( | 67 static void CreateBackgroundHostsForProfileStartup( |
66 ExtensionProcessManager* manager, const ExtensionList* extensions) { | 68 ExtensionProcessManager* manager, const ExtensionList* extensions) { |
67 for (ExtensionList::const_iterator extension = extensions->begin(); | 69 for (ExtensionList::const_iterator extension = extensions->begin(); |
68 extension != extensions->end(); ++extension) { | 70 extension != extensions->end(); ++extension) { |
69 CreateBackgroundHost(manager, *extension); | 71 CreateBackgroundHostForExtensionLoad(manager, *extension); |
70 } | 72 } |
71 } | 73 } |
72 | 74 |
73 } // namespace | 75 } // namespace |
74 | 76 |
75 extern bool g_log_bug53991; | 77 extern bool g_log_bug53991; |
76 | 78 |
77 // | 79 // |
78 // ExtensionProcessManager | 80 // ExtensionProcessManager |
79 // | 81 // |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
281 | 283 |
282 bool ExtensionProcessManager::HasExtensionHost(ExtensionHost* host) const { | 284 bool ExtensionProcessManager::HasExtensionHost(ExtensionHost* host) const { |
283 return all_hosts_.find(host) != all_hosts_.end(); | 285 return all_hosts_.find(host) != all_hosts_.end(); |
284 } | 286 } |
285 | 287 |
286 void ExtensionProcessManager::Observe(int type, | 288 void ExtensionProcessManager::Observe(int type, |
287 const NotificationSource& source, | 289 const NotificationSource& source, |
288 const NotificationDetails& details) { | 290 const NotificationDetails& details) { |
289 switch (type) { | 291 switch (type) { |
290 case chrome::NOTIFICATION_EXTENSIONS_READY: { | 292 case chrome::NOTIFICATION_EXTENSIONS_READY: { |
291 CreateBackgroundHosts(this, | 293 if (CommandLine::ForCurrentProcess()->HasSwitch( |
Aaron Boodman
2011/08/23 22:41:16
As discussed in chat, try moving these to CreateBa
Tessa MacDuff
2011/08/24 00:34:23
Done.
| |
294 switches::kEnableLazyBackgroundPages)) | |
295 break; | |
296 CreateBackgroundHostsForProfileStartup(this, | |
292 Source<Profile>(source).ptr()->GetExtensionService()->extensions()); | 297 Source<Profile>(source).ptr()->GetExtensionService()->extensions()); |
293 break; | 298 break; |
294 } | 299 } |
295 | 300 |
296 case chrome::NOTIFICATION_EXTENSION_LOADED: { | 301 case chrome::NOTIFICATION_EXTENSION_LOADED: { |
302 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
303 switches::kEnableLazyBackgroundPages)) | |
304 break; | |
297 ExtensionService* service = | 305 ExtensionService* service = |
298 Source<Profile>(source).ptr()->GetExtensionService(); | 306 Source<Profile>(source).ptr()->GetExtensionService(); |
299 if (service->is_ready()) { | 307 if (service->is_ready()) { |
300 const Extension* extension = Details<const Extension>(details).ptr(); | 308 const Extension* extension = Details<const Extension>(details).ptr(); |
301 ::CreateBackgroundHost(this, extension); | 309 ::CreateBackgroundHostForExtensionLoad(this, extension); |
302 } | 310 } |
303 break; | 311 break; |
304 } | 312 } |
305 | 313 |
306 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { | 314 case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
307 const Extension* extension = | 315 const Extension* extension = |
308 Details<UnloadedExtensionInfo>(details)->extension; | 316 Details<UnloadedExtensionInfo>(details)->extension; |
309 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); | 317 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); |
310 iter != background_hosts_.end(); ++iter) { | 318 iter != background_hosts_.end(); ++iter) { |
311 ExtensionHost* host = *iter; | 319 ExtensionHost* host = *iter; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
463 ExtensionService* service = profile->GetExtensionService(); | 471 ExtensionService* service = profile->GetExtensionService(); |
464 return service && service->IsIncognitoEnabled(extension->id()); | 472 return service && service->IsIncognitoEnabled(extension->id()); |
465 } | 473 } |
466 | 474 |
467 void IncognitoExtensionProcessManager::Observe( | 475 void IncognitoExtensionProcessManager::Observe( |
468 int type, | 476 int type, |
469 const NotificationSource& source, | 477 const NotificationSource& source, |
470 const NotificationDetails& details) { | 478 const NotificationDetails& details) { |
471 switch (type) { | 479 switch (type) { |
472 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { | 480 case chrome::NOTIFICATION_BROWSER_WINDOW_READY: { |
481 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
482 switches::kEnableLazyBackgroundPages)) | |
483 break; | |
473 // We want to spawn our background hosts as soon as the user opens an | 484 // We want to spawn our background hosts as soon as the user opens an |
474 // incognito window. Watch for new browsers and create the hosts if | 485 // incognito window. Watch for new browsers and create the hosts if |
475 // it matches our profile. | 486 // it matches our profile. |
476 Browser* browser = Source<Browser>(source).ptr(); | 487 Browser* browser = Source<Browser>(source).ptr(); |
477 if (browser->profile() == browsing_instance_->browser_context()) { | 488 if (browser->profile() == browsing_instance_->browser_context()) { |
478 // On Chrome OS, a login screen is implemented as a browser. | 489 // On Chrome OS, a login screen is implemented as a browser. |
479 // This browser has no extension service. In this case, | 490 // This browser has no extension service. In this case, |
480 // service will be NULL. | 491 // service will be NULL. |
481 Profile* profile = | 492 Profile* profile = |
482 Profile::FromBrowserContext(browsing_instance_->browser_context()); | 493 Profile::FromBrowserContext(browsing_instance_->browser_context()); |
483 ExtensionService* service = profile->GetExtensionService(); | 494 ExtensionService* service = profile->GetExtensionService(); |
484 if (service && service->is_ready()) | 495 if (service && service->is_ready()) |
485 CreateBackgroundHosts(this, service->extensions()); | 496 CreateBackgroundHostsForProfileStartup(this, service->extensions()); |
486 } | 497 } |
487 break; | 498 break; |
488 } | 499 } |
489 default: | 500 default: |
490 ExtensionProcessManager::Observe(type, source, details); | 501 ExtensionProcessManager::Observe(type, source, details); |
491 break; | 502 break; |
492 } | 503 } |
493 } | 504 } |
OLD | NEW |