Chromium Code Reviews| Index: chrome/browser/ui/toolbar/toolbar_actions_model.h |
| diff --git a/chrome/browser/extensions/extension_toolbar_model.h b/chrome/browser/ui/toolbar/toolbar_actions_model.h |
| similarity index 51% |
| rename from chrome/browser/extensions/extension_toolbar_model.h |
| rename to chrome/browser/ui/toolbar/toolbar_actions_model.h |
| index 2093ac85578af8ce1479b4799f4a26946b90c497..a649dfa4c8812f9ce9c424d6ea4b72789995941b 100644 |
| --- a/chrome/browser/extensions/extension_toolbar_model.h |
| +++ b/chrome/browser/ui/toolbar/toolbar_actions_model.h |
| @@ -2,8 +2,8 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ |
| -#define CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ |
| +#ifndef CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_MODEL_H_ |
| +#define CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_MODEL_H_ |
| #include "base/compiler_specific.h" |
| #include "base/observer_list.h" |
| @@ -19,15 +19,25 @@ |
| class Browser; |
| class PrefService; |
| class Profile; |
| +class ToolbarActionsBar; |
| +class ToolbarActionViewController; |
| namespace extensions { |
| class ExtensionRegistry; |
| class ExtensionSet; |
| +} // namespace extensions |
|
Devlin
2015/07/29 18:04:04
nitty nit: probably don't need the // namespace ex
apacible
2015/07/30 22:53:21
Done.
|
| + |
| +// Unique ID for a browser action, which could be an extension action or |
| +// a component action. |
| +typedef std::string ActionId; |
|
Devlin
2015/07/29 18:04:04
two thoughts:
- I'm not really keen on typedefing
apacible
2015/07/30 22:53:21
I see, thanks for bringing this up! Switched to st
|
| + |
| +typedef ScopedVector<ToolbarActionViewController> ActionList; |
|
Devlin
2015/07/29 18:04:04
(This typedef's fine, because it makes it more rea
apacible
2015/07/30 22:53:21
Done.
|
| +typedef std::vector<ActionId> ActionIdList; |
| // Model for the browser actions toolbar. |
| -class ExtensionToolbarModel : public ExtensionActionAPI::Observer, |
| - public ExtensionRegistryObserver, |
| - public KeyedService { |
| +class ToolbarActionsModel : public extensions::ExtensionActionAPI::Observer, |
| + public extensions::ExtensionRegistryObserver, |
| + public KeyedService { |
| public: |
| // The different options for highlighting. |
| enum HighlightType { |
| @@ -36,8 +46,9 @@ class ExtensionToolbarModel : public ExtensionActionAPI::Observer, |
| HIGHLIGHT_WARNING, |
| }; |
| - ExtensionToolbarModel(Profile* profile, ExtensionPrefs* extension_prefs); |
| - ~ExtensionToolbarModel() override; |
| + ToolbarActionsModel(Profile* profile, |
| + extensions::ExtensionPrefs* extension_prefs); |
| + ~ToolbarActionsModel() override; |
| // A class which is informed of changes to the model; represents the view of |
| // MVC. Also used for signaling view changes such as showing extension popups. |
| @@ -45,42 +56,42 @@ class ExtensionToolbarModel : public ExtensionActionAPI::Observer, |
| // delegate. |
| class Observer { |
| public: |
| - // Signals that an |extension| has been added to the toolbar at |index|. |
| - // This will *only* be called after the toolbar model has been initialized. |
| - virtual void OnToolbarExtensionAdded(const Extension* extension, |
| - int index) = 0; |
| - |
| - // Signals that the given |extension| has been removed from the toolbar. |
| - virtual void OnToolbarExtensionRemoved(const Extension* extension) = 0; |
| - |
| - // Signals that the given |extension| has been moved to |index|. |index| is |
| - // the desired *final* index of the extension (that is, in the adjusted |
| - // order, extension should be at |index|). |
| - virtual void OnToolbarExtensionMoved(const Extension* extension, |
| - int index) = 0; |
| - |
| - // Signals that the browser action for the given |extension| has been |
| - // updated. |
| - virtual void OnToolbarExtensionUpdated(const Extension* extension) = 0; |
| - |
| - // Signals the |extension| to show the popup now in the active window. |
| - // If |grant_active_tab| is true, then active tab permissions should be |
| - // given to the extension (only do this if this is through a user action). |
| - // Returns true if a popup was slated to be shown. |
| - virtual bool ShowExtensionActionPopup(const Extension* extension, |
| - bool grant_active_tab) = 0; |
| + // Signals that an action with id |id| has been added to the toolbar at |
|
Devlin
2015/07/29 18:04:04
... with |id| has been...
apacible
2015/07/30 22:53:21
Done.
|
| + // |index|. This will *only* be called after the toolbar model has been |
| + // initialized. |
| + virtual void OnToolbarActionAdded(const ActionId id, int index) = 0; |
|
Devlin
2015/07/29 18:04:04
const &, not just const. (Everywhere)
apacible
2015/07/30 22:53:22
Done.
|
| + |
| + // Signals that the given action with id |id| has been removed from the |
| + // toolbar. |
| + virtual void OnToolbarActionRemoved(const ActionId id) = 0; |
| + |
| + // Signals that the given action with id |id| has been moved to |index|. |
| + // |index| is the desired *final* index of the action (that is, in the |
| + // adjusted order, action should be at |index|). |
| + virtual void OnToolbarActionMoved(const ActionId id, int index) = 0; |
| + |
| + // Signals that the browser action with id |id| has been updated. |
| + virtual void OnToolbarActionUpdated(const ActionId id) = 0; |
| + |
| + // Signals the action with id |id| to show the popup now in the active |
| + // window. If |grant_active_tab| is true, then active tab permissions |
| + // should be given to the action (only do this if this is through a user |
| + // action). Returns true if a popup was slated to be shown. |
| + virtual bool ShowToolbarActionPopup(const ActionId id, |
| + bool grant_active_tab) = 0; |
| // Signals when the container needs to be redrawn because of a size change, |
| // and when the model has finished loading. |
| virtual void OnToolbarVisibleCountChanged() = 0; |
| // Signals that the model has entered or exited highlighting mode, or that |
| - // the extensions being highlighted have (probably*) changed. Highlighting |
| - // mode indicates that only a subset of the extensions are actively |
| - // displayed, and those extensions should be highlighted for extra emphasis. |
| + // the actions being highlighted have (probably*) changed. Highlighting |
| + // mode indicates that only a subset of the toolbar actions are actively |
| + // displayed, and those actions should be highlighted for extra emphasis. |
| + // No component actions will be displayed. |
| // * probably, because if we are in highlight mode and receive a call to |
| - // highlight a new set of extensions, we do not compare the current set |
| - // with the new set (and just assume the new set is different). |
| + // highlight a new set of actions, we do not compare the current set with |
| + // the new set (and just assume the new set is different). |
| virtual void OnToolbarHighlightModeChanged(bool is_highlighting) = 0; |
| // Signals that the toolbar model has been initialized, so that if any |
| @@ -95,17 +106,17 @@ class ExtensionToolbarModel : public ExtensionActionAPI::Observer, |
| virtual ~Observer() {} |
| }; |
| - // Convenience function to get the ExtensionToolbarModel for a Profile. |
| - static ExtensionToolbarModel* Get(Profile* profile); |
| + // Convenience function to get the ToolbarActionsModel for a Profile. |
| + static ToolbarActionsModel* Get(Profile* profile); |
| // Adds or removes an observer. |
| void AddObserver(Observer* observer); |
| void RemoveObserver(Observer* observer); |
| - // Moves the given |extension|'s icon to the given |index|. |
| - void MoveExtensionIcon(const std::string& id, size_t index); |
| + // Moves the given action with id |id|'s icon to the given |index|. |
| + void MoveActionIcon(const ActionId& id, size_t index); |
| - // Sets the number of extension icons that should be visible. |
| + // Sets the number of action icons that should be visible. |
| // If count == size(), this will set the visible icon count to -1, meaning |
| // "show all actions". |
| void SetVisibleIconCount(size_t count); |
| @@ -122,42 +133,45 @@ class ExtensionToolbarModel : public ExtensionActionAPI::Observer, |
| bool all_icons_visible() const { return visible_icon_count_ == -1; } |
| - bool extensions_initialized() const { return extensions_initialized_; } |
| + bool actions_initialized() const { return actions_initialized_; } |
| + |
| + ActionList GetActions(Browser* browser, ToolbarActionsBar* bar); |
| - const ExtensionList& toolbar_items() const { |
| + const ActionIdList& toolbar_items() const { |
| return is_highlighting() ? highlighted_items_ : toolbar_items_; |
| } |
| bool is_highlighting() const { return highlight_type_ != HIGHLIGHT_NONE; } |
| HighlightType highlight_type() const { return highlight_type_; } |
| - void OnExtensionToolbarPrefChange(); |
| + void OnActionToolbarPrefChange(); |
| - // Returns the index of the given |id|, or -1 if the id wasn't found. |
| - int GetIndexForId(const std::string& id) const; |
| + // Returns the index of the given action with id |id|, or -1 if the id |
| + // wasn't found. |
| + int GetIndexForId(const ActionId& id) const; |
| // Finds the Observer associated with |browser| and tells it to display a |
| - // popup for the given |extension|. If |grant_active_tab| is true, this |
| - // grants active tab permissions to the |extension|; only do this because of |
| + // popup for the given action with id |id|. If |grant_active_tab| is true, |
| + // this grants active tab permissions to the action; only do this because of |
| // a direct user action. |
| - bool ShowExtensionActionPopup(const Extension* extension, |
| - Browser* browser, |
| - bool grant_active_tab); |
| + bool ShowToolbarActionPopup(const ActionId id, |
| + Browser* browser, |
| + bool grant_active_tab); |
| - // Ensures that the extensions in the |extension_ids| list are visible on the |
| + // Ensures that the actions in the |action_ids| list are visible on the |
| // toolbar. This might mean they need to be moved to the front (if they are in |
| // the overflow bucket). |
| - void EnsureVisibility(const ExtensionIdList& extension_ids); |
| + void EnsureVisibility(const ActionIdList& action_ids); |
| - // Highlights the extensions specified by |extension_ids|. This will cause |
| - // the ToolbarModel to only display those extensions. |
| - // Highlighting mode is only entered if there is at least one extension to |
| - // be shown. |
| + // Highlights the actions specified by |action_ids|. This will cause |
| + // the ToolbarModel to only display those actions. |
| + // Highlighting mode is only entered if there is at least one action to be |
| + // shown. |
| // Returns true if highlighting mode is entered, false otherwise. |
| - bool HighlightExtensions(const ExtensionIdList& extension_ids, |
| + bool HighlightActions(const ActionIdList& action_ids, |
| HighlightType type); |
|
Devlin
2015/07/29 18:04:04
nit: indentation
apacible
2015/07/30 22:53:21
Done.
|
| - // Stop highlighting extensions. All extensions can be shown again, and the |
| + // Stop highlighting actions. All actions can be shown again, and the |
| // number of visible icons will be reset to what it was before highlighting. |
| void StopHighlighting(); |
| @@ -166,17 +180,18 @@ class ExtensionToolbarModel : public ExtensionActionAPI::Observer, |
| bool RedesignIsShowingNewIcons() const; |
| private: |
| - // Callback when extensions are ready. |
| + // Callback when actions are ready. |
| void OnReady(); |
| // ExtensionRegistryObserver: |
| void OnExtensionLoaded(content::BrowserContext* browser_context, |
| - const Extension* extension) override; |
| + const extensions::Extension* extension) override; |
| void OnExtensionUnloaded(content::BrowserContext* browser_context, |
| - const Extension* extension, |
| - UnloadedExtensionInfo::Reason reason) override; |
| + const extensions::Extension* extension, |
| + extensions::UnloadedExtensionInfo::Reason reason) |
| + override; |
| void OnExtensionUninstalled(content::BrowserContext* browser_context, |
| - const Extension* extension, |
| + const extensions::Extension* extension, |
| extensions::UninstallReason reason) override; |
| // ExtensionActionAPI::Observer: |
| @@ -184,7 +199,7 @@ class ExtensionToolbarModel : public ExtensionActionAPI::Observer, |
| ExtensionAction* extension_action, |
| content::WebContents* web_contents, |
| content::BrowserContext* browser_context) override; |
| - void OnExtensionActionVisibilityChanged(const std::string& extension_id, |
| + void OnExtensionActionVisibilityChanged(const ActionId& extension_id, |
|
Devlin
2015/07/29 18:04:04
nit: this relates to extensions, so this shouldn't
apacible
2015/07/30 22:53:21
Done.
|
| bool is_now_visible) override; |
| // To be called after the extension service is ready; gets loaded extensions |
| @@ -192,30 +207,31 @@ class ExtensionToolbarModel : public ExtensionActionAPI::Observer, |
| // and constructs |toolbar_items_| from these data. IncognitoPopulate() |
| // takes the shortcut - looking at the regular model's content and modifying |
| // it. |
| - void InitializeExtensionList(); |
| - void Populate(ExtensionIdList* positions); |
| + void InitializeActionList(); |
| + void Populate(ActionIdList* positions); |
| void IncognitoPopulate(); |
| // Save the model to prefs. |
| void UpdatePrefs(); |
| - // Updates |extension|'s browser action visibility pref if the browser action |
| - // is in the overflow menu and should be considered hidden. |
| - void MaybeUpdateVisibilityPref(const Extension* extension, size_t index); |
| + // Updates action with id |id|'s browser action visibility pref if the |
|
Devlin
2015/07/29 18:04:04
nit: with |id|'s...
apacible
2015/07/30 22:53:21
Done.
|
| + // browser action is in the overflow menu and should be considered hidden. |
| + void MaybeUpdateVisibilityPref(const ActionId id, size_t index); |
| - // Calls MaybeUpdateVisibilityPref() for each extension in |toolbar_items|. |
| + // Calls MaybeUpdateVisibilityPref() for each action in |toolbar_items|. |
| void MaybeUpdateVisibilityPrefs(); |
| // Finds the last known visible position of the icon for an |extension|. The |
| // value returned is a zero-based index into the vector of visible items. |
| - size_t FindNewPositionFromLastKnownGood(const Extension* extension); |
| + size_t FindNewPositionFromLastKnownGood( |
| + const extensions::Extension* extension); |
| // Returns true if the given |extension| should be added to the toolbar. |
| - bool ShouldAddExtension(const Extension* extension); |
| + bool ShouldAddExtension(const extensions::Extension* extension); |
| // Adds or removes the given |extension| from the toolbar model. |
| - void AddExtension(const Extension* extension); |
| - void RemoveExtension(const Extension* extension); |
| + void AddExtension(const extensions::Extension* extension); |
| + void RemoveExtension(const extensions::Extension* extension); |
| // Our observers. |
| base::ObserverList<Observer> observers_; |
| @@ -223,30 +239,35 @@ class ExtensionToolbarModel : public ExtensionActionAPI::Observer, |
| // The Profile this toolbar model is for. |
| Profile* profile_; |
| - ExtensionPrefs* extension_prefs_; |
| + extensions::ExtensionPrefs* extension_prefs_; |
| PrefService* prefs_; |
| // The ExtensionActionAPI object, cached for convenience. |
| - ExtensionActionAPI* extension_action_api_; |
| + extensions::ExtensionActionAPI* extension_action_api_; |
| // True if we've handled the initial EXTENSIONS_READY notification. |
| - bool extensions_initialized_; |
| + bool actions_initialized_; |
| - // If true, we include all extensions in the toolbar model. If false, we only |
| + // If true, we include all actions in the toolbar model. If false, we only |
| // include browser actions. |
| - bool include_all_extensions_; |
| + bool include_all_actions_; |
| - // Ordered list of browser action buttons. |
| - ExtensionList toolbar_items_; |
| + // Ordered list of browser action ids. |
| + ActionIdList toolbar_items_; |
| - // List of browser action buttons which should be highlighted. |
| - ExtensionList highlighted_items_; |
| + // List of browser action ids which should be highlighted. |
| + ActionIdList highlighted_items_; |
| + |
| + // List of component action ids. This is used to check against individual |
| + // ActionIds to determine if it is an extension or component action. |
| + std::vector<std::string> component_ids_; |
| // The current type of highlight (with HIGHLIGHT_NONE indicating no current |
| // highlight). |
| HighlightType highlight_type_; |
| - ExtensionIdList last_known_positions_; |
| + // The last known positions for a list of actions. |
| + ActionIdList last_known_positions_; |
| // The number of icons visible (the rest should be hidden in the overflow |
| // chevron). A value of -1 indicates that all icons should be visible. |
| @@ -256,22 +277,20 @@ class ExtensionToolbarModel : public ExtensionActionAPI::Observer, |
| // visible, instead of overloading this one. |
| int visible_icon_count_; |
| - ScopedObserver<ExtensionActionAPI, ExtensionActionAPI::Observer> |
| - extension_action_observer_; |
| + ScopedObserver<extensions::ExtensionActionAPI, |
| + extensions::ExtensionActionAPI::Observer> extension_action_observer_; |
| // Listen to extension load, unloaded notifications. |
| - ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| + ScopedObserver<extensions::ExtensionRegistry, ExtensionRegistryObserver> |
| extension_registry_observer_; |
| // For observing change of toolbar order preference by external entity (sync). |
| PrefChangeRegistrar pref_change_registrar_; |
| base::Closure pref_change_callback_; |
| - base::WeakPtrFactory<ExtensionToolbarModel> weak_ptr_factory_; |
| + base::WeakPtrFactory<ToolbarActionsModel> weak_ptr_factory_; |
| - DISALLOW_COPY_AND_ASSIGN(ExtensionToolbarModel); |
| + DISALLOW_COPY_AND_ASSIGN(ToolbarActionsModel); |
| }; |
| -} // namespace extensions |
| - |
| -#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ |
| +#endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTIONS_MODEL_H_ |