| 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_MANAGER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_MANAGER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 class ExtensionActionManager : public KeyedService, | 26 class ExtensionActionManager : public KeyedService, |
| 27 public ExtensionRegistryObserver { | 27 public ExtensionRegistryObserver { |
| 28 public: | 28 public: |
| 29 explicit ExtensionActionManager(Profile* profile); | 29 explicit ExtensionActionManager(Profile* profile); |
| 30 virtual ~ExtensionActionManager(); | 30 virtual ~ExtensionActionManager(); |
| 31 | 31 |
| 32 // Returns this profile's ExtensionActionManager. One instance is | 32 // Returns this profile's ExtensionActionManager. One instance is |
| 33 // shared between a profile and its incognito version. | 33 // shared between a profile and its incognito version. |
| 34 static ExtensionActionManager* Get(content::BrowserContext* browser_context); | 34 static ExtensionActionManager* Get(content::BrowserContext* browser_context); |
| 35 | 35 |
| 36 // Retrieves the page action, or browser action for |extension|. | 36 // Retrieves the page action, browser action, or system indicator for |
| 37 // |extension|. |
| 37 // If the result is not NULL, it remains valid until the extension is | 38 // If the result is not NULL, it remains valid until the extension is |
| 38 // unloaded. | 39 // unloaded. |
| 39 ExtensionAction* GetPageAction(const extensions::Extension& extension) const; | 40 ExtensionAction* GetPageAction(const Extension& extension) const; |
| 40 ExtensionAction* GetBrowserAction( | 41 ExtensionAction* GetBrowserAction(const Extension& extension) const; |
| 41 const extensions::Extension& extension) const; | 42 ExtensionAction* GetSystemIndicator(const Extension& extension) const; |
| 42 ExtensionAction* GetSystemIndicator( | 43 |
| 43 const extensions::Extension& extension) const; | 44 // Returns either the PageAction or BrowserAction for |extension|, or NULL if |
| 45 // none exists. Since an extension can only declare one of Browser|PageAction, |
| 46 // this is okay to use anywhere you need a generic "ExtensionAction". |
| 47 // Since SystemIndicators are used differently and don't follow this |
| 48 // rule of mutual exclusion, they are not checked or returned. |
| 49 ExtensionAction* GetExtensionAction(const Extension& extension) const; |
| 44 | 50 |
| 45 // Gets the best fit ExtensionAction for the given |extension|. This takes | 51 // Gets the best fit ExtensionAction for the given |extension|. This takes |
| 46 // into account |extension|'s browser or page actions, if any, along with its | 52 // into account |extension|'s browser or page actions, if any, along with its |
| 47 // name and any declared icons. | 53 // name and any declared icons. |
| 48 scoped_ptr<ExtensionAction> GetBestFitAction( | 54 scoped_ptr<ExtensionAction> GetBestFitAction( |
| 49 const extensions::Extension& extension, | 55 const Extension& extension, ActionInfo::Type type) const; |
| 50 extensions::ActionInfo::Type type) const; | |
| 51 | 56 |
| 52 private: | 57 private: |
| 53 // Implement ExtensionRegistryObserver. | 58 // Implement ExtensionRegistryObserver. |
| 54 virtual void OnExtensionUnloaded(content::BrowserContext* browser_context, | 59 virtual void OnExtensionUnloaded(content::BrowserContext* browser_context, |
| 55 const Extension* extension, | 60 const Extension* extension, |
| 56 UnloadedExtensionInfo::Reason reason) | 61 UnloadedExtensionInfo::Reason reason) |
| 57 OVERRIDE; | 62 OVERRIDE; |
| 58 | 63 |
| 59 Profile* profile_; | 64 Profile* profile_; |
| 60 | 65 |
| 61 // Listen to extension unloaded notifications. | 66 // Listen to extension unloaded notifications. |
| 62 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> | 67 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 63 extension_registry_observer_; | 68 extension_registry_observer_; |
| 64 | 69 |
| 65 // Keyed by Extension ID. These maps are populated lazily when their | 70 // Keyed by Extension ID. These maps are populated lazily when their |
| 66 // ExtensionAction is first requested, and the entries are removed when the | 71 // ExtensionAction is first requested, and the entries are removed when the |
| 67 // extension is unloaded. Not every extension has a page action or browser | 72 // extension is unloaded. Not every extension has a page action or browser |
| 68 // action. | 73 // action. |
| 69 typedef std::map<std::string, linked_ptr<ExtensionAction> > ExtIdToActionMap; | 74 typedef std::map<std::string, linked_ptr<ExtensionAction> > ExtIdToActionMap; |
| 70 mutable ExtIdToActionMap page_actions_; | 75 mutable ExtIdToActionMap page_actions_; |
| 71 mutable ExtIdToActionMap browser_actions_; | 76 mutable ExtIdToActionMap browser_actions_; |
| 72 mutable ExtIdToActionMap system_indicators_; | 77 mutable ExtIdToActionMap system_indicators_; |
| 73 }; | 78 }; |
| 74 | 79 |
| 75 } // namespace extensions | 80 } // namespace extensions |
| 76 | 81 |
| 77 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_MANAGER_H_ | 82 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_ACTION_MANAGER_H_ |
| OLD | NEW |