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" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #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" | 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 using content::SiteInstance; |
37 | 37 |
38 namespace events { | |
39 const char kOnInstalled[] = "experimental.extension.onInstalled"; | |
40 }; // namespace events | |
41 | |
42 namespace { | 38 namespace { |
43 | 39 |
44 // 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 |
45 // whether to fall back on the original profile's ExtensionProcessManager based | 41 // whether to fall back on the original profile's ExtensionProcessManager based |
46 // on whether a given extension uses "split" or "spanning" incognito behavior. | 42 // on whether a given extension uses "split" or "spanning" incognito behavior. |
47 class IncognitoExtensionProcessManager : public ExtensionProcessManager { | 43 class IncognitoExtensionProcessManager : public ExtensionProcessManager { |
48 public: | 44 public: |
49 explicit IncognitoExtensionProcessManager(Profile* profile); | 45 explicit IncognitoExtensionProcessManager(Profile* profile); |
50 virtual ~IncognitoExtensionProcessManager() {} | 46 virtual ~IncognitoExtensionProcessManager() {} |
51 virtual ExtensionHost* CreateViewHost( | 47 virtual ExtensionHost* CreateViewHost( |
(...skipping 12 matching lines...) Expand all Loading... |
64 const content::NotificationDetails& details); | 60 const content::NotificationDetails& details); |
65 | 61 |
66 // Returns true if the extension is allowed to run in incognito mode. | 62 // Returns true if the extension is allowed to run in incognito mode. |
67 bool IsIncognitoEnabled(const Extension* extension); | 63 bool IsIncognitoEnabled(const Extension* extension); |
68 | 64 |
69 ExtensionProcessManager* original_manager_; | 65 ExtensionProcessManager* original_manager_; |
70 }; | 66 }; |
71 | 67 |
72 static void CreateBackgroundHostForExtensionLoad( | 68 static void CreateBackgroundHostForExtensionLoad( |
73 ExtensionProcessManager* manager, const Extension* extension) { | 69 ExtensionProcessManager* manager, const Extension* extension) { |
74 if (extension->has_background_page()) { | 70 if (extension->has_background_page() && |
75 if (extension->background_page_persists()) { | 71 extension->background_page_persists()) { |
76 manager->CreateBackgroundHost(extension, extension->GetBackgroundURL()); | 72 manager->CreateBackgroundHost(extension, extension->GetBackgroundURL()); |
77 } else { | |
78 // TODO(mpcomplete): Only call this on install once we persist event | |
79 // registration. Also call this for regular background pages. | |
80 manager->DispatchExtensionInstalledEvent(extension); | |
81 } | |
82 } | 73 } |
83 } | 74 } |
84 | 75 |
85 static void CreateBackgroundHostsForProfileStartup( | 76 static void CreateBackgroundHostsForProfileStartup( |
86 ExtensionProcessManager* manager, const ExtensionSet* extensions) { | 77 ExtensionProcessManager* manager, const ExtensionSet* extensions) { |
87 for (ExtensionSet::const_iterator extension = extensions->begin(); | 78 for (ExtensionSet::const_iterator extension = extensions->begin(); |
88 extension != extensions->end(); ++extension) { | 79 extension != extensions->end(); ++extension) { |
89 CreateBackgroundHostForExtensionLoad(manager, *extension); | 80 CreateBackgroundHostForExtensionLoad(manager, *extension); |
90 } | 81 } |
91 } | 82 } |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 } | 402 } |
412 | 403 |
413 void ExtensionProcessManager::CloseBackgroundHosts() { | 404 void ExtensionProcessManager::CloseBackgroundHosts() { |
414 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); | 405 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); |
415 iter != background_hosts_.end(); ) { | 406 iter != background_hosts_.end(); ) { |
416 ExtensionHostSet::iterator current = iter++; | 407 ExtensionHostSet::iterator current = iter++; |
417 delete *current; | 408 delete *current; |
418 } | 409 } |
419 } | 410 } |
420 | 411 |
421 void ExtensionProcessManager::DispatchExtensionInstalledEvent( | |
422 const Extension* extension) { | |
423 ExtensionEventRouter* router = GetProfile()->GetExtensionEventRouter(); | |
424 router->AddLazyEventListener(events::kOnInstalled, extension->id()); | |
425 router->DispatchEventToExtension( | |
426 extension->id(), events::kOnInstalled, "[]", NULL, GURL()); | |
427 } | |
428 | |
429 // | 412 // |
430 // IncognitoExtensionProcessManager | 413 // IncognitoExtensionProcessManager |
431 // | 414 // |
432 | 415 |
433 IncognitoExtensionProcessManager::IncognitoExtensionProcessManager( | 416 IncognitoExtensionProcessManager::IncognitoExtensionProcessManager( |
434 Profile* profile) | 417 Profile* profile) |
435 : ExtensionProcessManager(profile), | 418 : ExtensionProcessManager(profile), |
436 original_manager_(profile->GetOriginalProfile()-> | 419 original_manager_(profile->GetOriginalProfile()-> |
437 GetExtensionProcessManager()) { | 420 GetExtensionProcessManager()) { |
438 DCHECK(profile->IsOffTheRecord()); | 421 DCHECK(profile->IsOffTheRecord()); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 if (service && service->is_ready()) | 493 if (service && service->is_ready()) |
511 CreateBackgroundHostsForProfileStartup(this, service->extensions()); | 494 CreateBackgroundHostsForProfileStartup(this, service->extensions()); |
512 } | 495 } |
513 break; | 496 break; |
514 } | 497 } |
515 default: | 498 default: |
516 ExtensionProcessManager::Observe(type, source, details); | 499 ExtensionProcessManager::Observe(type, source, details); |
517 break; | 500 break; |
518 } | 501 } |
519 } | 502 } |
OLD | NEW |