Index: chrome/browser/extensions/extension_service.cc |
diff --git a/chrome/browser/extensions/extension_service.cc b/chrome/browser/extensions/extension_service.cc |
index 03c05633a45b6a9f565be199a828a759791e86de..ba4e3612f6eceba245a44520ad58876fb557481f 100644 |
--- a/chrome/browser/extensions/extension_service.cc |
+++ b/chrome/browser/extensions/extension_service.cc |
@@ -350,6 +350,10 @@ ExtensionService::ExtensionService(Profile* profile, |
registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, |
content::NotificationService::AllBrowserContextsAndSources()); |
+ registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
+ content::NotificationService::AllBrowserContextsAndSources()); |
+ registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, |
+ content::NotificationService::AllBrowserContextsAndSources()); |
registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED, |
content::NotificationService::AllBrowserContextsAndSources()); |
registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
@@ -1858,6 +1862,10 @@ void ExtensionService::UnloadAllExtensions() { |
terminated_extensions_.Clear(); |
extension_runtime_data_.clear(); |
+ STLDeleteValues(&page_actions_); |
Jeffrey Yasskin
2012/09/14 19:18:33
Need to double-check if there are other places tha
|
+ STLDeleteValues(&browser_actions_); |
+ STLDeleteValues(&script_badges_); |
+ |
// TODO(erikkay) should there be a notification for this? We can't use |
// EXTENSION_UNLOADED since that implies that the extension has been disabled |
// or uninstalled, and UnloadAll is just part of shutdown. |
@@ -2292,6 +2300,22 @@ gfx::Image ExtensionService::GetOmniboxPopupIcon( |
return gfx::Image(omnibox_popup_icon_manager_.GetIcon(extension_id)); |
} |
+ExtensionAction* ExtensionService::GetPageAction( |
+ const Extension& extension) const { |
+ return ContainsKey(page_actions_, extension.id()) ? |
+ page_actions_.find(extension.id())->second : NULL; |
+} |
+ExtensionAction* ExtensionService::GetBrowserAction( |
+ const Extension& extension) const { |
+ return ContainsKey(browser_actions_, extension.id()) ? |
+ browser_actions_.find(extension.id())->second : NULL; |
+} |
+ExtensionAction* ExtensionService::GetScriptBadge( |
+ const Extension& extension) const { |
+ return ContainsKey(script_badges_, extension.id()) ? |
+ script_badges_.find(extension.id())->second : NULL; |
+} |
+ |
bool ExtensionService::OnExternalExtensionFileFound( |
const std::string& id, |
const Version* version, |
@@ -2395,6 +2419,52 @@ void ExtensionService::Observe(int type, |
const content::NotificationSource& source, |
const content::NotificationDetails& details) { |
switch (type) { |
+ case chrome::NOTIFICATION_EXTENSION_LOADED: { |
Aaron Boodman
2012/09/16 01:42:50
This is the kind of code I'm trying to keep out of
not at google - send to devlin
2012/09/27 00:46:10
Not that this solves the LOADED/UNLOADED problem,
|
+ if (profile_ != |
+ content::Source<Profile>(source).ptr()->GetOriginalProfile()) { |
+ break; |
+ } |
+ |
+ const Extension* extension = |
+ content::Details<const Extension>(details).ptr(); |
+ if (extension->page_action() && |
+ !ContainsKey(page_actions_, extension->id())) { |
+ page_actions_[extension->id()] = |
+ new ExtensionAction(extension->id(), *extension->page_action()); |
+ } |
+ if (extension->browser_action() && |
+ !ContainsKey(browser_actions_, extension->id())) { |
+ browser_actions_[extension->id()] = |
+ new ExtensionAction(extension->id(), *extension->browser_action()); |
+ } |
+ DCHECK(extension->script_badge()); |
+ if (!ContainsKey(script_badges_, extension->id())) { |
+ script_badges_[extension->id()] = |
+ new ExtensionAction(extension->id(), *extension->script_badge()); |
+ } |
+ break; |
+ } |
+ case chrome::NOTIFICATION_EXTENSION_UNLOADED: { |
+ if (profile_ != |
+ content::Source<Profile>(source).ptr()->GetOriginalProfile()) { |
+ break; |
+ } |
+ |
+ const Extension* extension = |
+ content::Details<UnloadedExtensionInfo>(details)->extension; |
+ if (ContainsKey(page_actions_, extension->id())) { |
+ delete page_actions_[extension->id()]; |
+ page_actions_.erase(extension->id()); |
+ } |
+ if (ContainsKey(browser_actions_, extension->id())) { |
+ delete browser_actions_[extension->id()]; |
+ browser_actions_.erase(extension->id()); |
+ } |
+ if (ContainsKey(script_badges_, extension->id())) { |
+ script_badges_.erase(extension->id()); |
+ } |
+ break; |
+ } |
case chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: { |
if (profile_ != |
content::Source<Profile>(source).ptr()->GetOriginalProfile()) { |