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 |
38 namespace { | 42 namespace { |
39 | 43 |
40 // Incognito profiles use this process manager. It is mostly a shim that decides | 44 // Incognito profiles use this process manager. It is mostly a shim that decides |
41 // whether to fall back on the original profile's ExtensionProcessManager based | 45 // whether to fall back on the original profile's ExtensionProcessManager based |
42 // on whether a given extension uses "split" or "spanning" incognito behavior. | 46 // on whether a given extension uses "split" or "spanning" incognito behavior. |
43 class IncognitoExtensionProcessManager : public ExtensionProcessManager { | 47 class IncognitoExtensionProcessManager : public ExtensionProcessManager { |
44 public: | 48 public: |
45 explicit IncognitoExtensionProcessManager(Profile* profile); | 49 explicit IncognitoExtensionProcessManager(Profile* profile); |
46 virtual ~IncognitoExtensionProcessManager() {} | 50 virtual ~IncognitoExtensionProcessManager() {} |
47 virtual ExtensionHost* CreateViewHost( | 51 virtual ExtensionHost* CreateViewHost( |
(...skipping 12 matching lines...) Expand all Loading... |
60 const content::NotificationDetails& details); | 64 const content::NotificationDetails& details); |
61 | 65 |
62 // Returns true if the extension is allowed to run in incognito mode. | 66 // Returns true if the extension is allowed to run in incognito mode. |
63 bool IsIncognitoEnabled(const Extension* extension); | 67 bool IsIncognitoEnabled(const Extension* extension); |
64 | 68 |
65 ExtensionProcessManager* original_manager_; | 69 ExtensionProcessManager* original_manager_; |
66 }; | 70 }; |
67 | 71 |
68 static void CreateBackgroundHostForExtensionLoad( | 72 static void CreateBackgroundHostForExtensionLoad( |
69 ExtensionProcessManager* manager, const Extension* extension) { | 73 ExtensionProcessManager* manager, const Extension* extension) { |
70 if (extension->has_background_page() && | 74 if (extension->has_background_page()) { |
71 extension->background_page_persists()) { | 75 if (extension->background_page_persists()) { |
72 manager->CreateBackgroundHost(extension, extension->GetBackgroundURL()); | 76 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 } |
73 } | 82 } |
74 } | 83 } |
75 | 84 |
76 static void CreateBackgroundHostsForProfileStartup( | 85 static void CreateBackgroundHostsForProfileStartup( |
77 ExtensionProcessManager* manager, const ExtensionSet* extensions) { | 86 ExtensionProcessManager* manager, const ExtensionSet* extensions) { |
78 for (ExtensionSet::const_iterator extension = extensions->begin(); | 87 for (ExtensionSet::const_iterator extension = extensions->begin(); |
79 extension != extensions->end(); ++extension) { | 88 extension != extensions->end(); ++extension) { |
80 CreateBackgroundHostForExtensionLoad(manager, *extension); | 89 CreateBackgroundHostForExtensionLoad(manager, *extension); |
81 } | 90 } |
82 } | 91 } |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 } | 411 } |
403 | 412 |
404 void ExtensionProcessManager::CloseBackgroundHosts() { | 413 void ExtensionProcessManager::CloseBackgroundHosts() { |
405 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); | 414 for (ExtensionHostSet::iterator iter = background_hosts_.begin(); |
406 iter != background_hosts_.end(); ) { | 415 iter != background_hosts_.end(); ) { |
407 ExtensionHostSet::iterator current = iter++; | 416 ExtensionHostSet::iterator current = iter++; |
408 delete *current; | 417 delete *current; |
409 } | 418 } |
410 } | 419 } |
411 | 420 |
| 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 |
412 // | 429 // |
413 // IncognitoExtensionProcessManager | 430 // IncognitoExtensionProcessManager |
414 // | 431 // |
415 | 432 |
416 IncognitoExtensionProcessManager::IncognitoExtensionProcessManager( | 433 IncognitoExtensionProcessManager::IncognitoExtensionProcessManager( |
417 Profile* profile) | 434 Profile* profile) |
418 : ExtensionProcessManager(profile), | 435 : ExtensionProcessManager(profile), |
419 original_manager_(profile->GetOriginalProfile()-> | 436 original_manager_(profile->GetOriginalProfile()-> |
420 GetExtensionProcessManager()) { | 437 GetExtensionProcessManager()) { |
421 DCHECK(profile->IsOffTheRecord()); | 438 DCHECK(profile->IsOffTheRecord()); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 if (service && service->is_ready()) | 510 if (service && service->is_ready()) |
494 CreateBackgroundHostsForProfileStartup(this, service->extensions()); | 511 CreateBackgroundHostsForProfileStartup(this, service->extensions()); |
495 } | 512 } |
496 break; | 513 break; |
497 } | 514 } |
498 default: | 515 default: |
499 ExtensionProcessManager::Observe(type, source, details); | 516 ExtensionProcessManager::Observe(type, source, details); |
500 break; | 517 break; |
501 } | 518 } |
502 } | 519 } |
OLD | NEW |