| 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_TOOLBAR_MODEL_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/observer_list.h" | 9 #include "base/observer_list.h" |
| 10 #include "base/prefs/pref_change_registrar.h" | 10 #include "base/prefs/pref_change_registrar.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 namespace extensions { | 23 namespace extensions { |
| 24 class ExtensionRegistry; | 24 class ExtensionRegistry; |
| 25 class ExtensionSet; | 25 class ExtensionSet; |
| 26 | 26 |
| 27 // Model for the browser actions toolbar. | 27 // Model for the browser actions toolbar. |
| 28 class ExtensionToolbarModel : public ExtensionActionAPI::Observer, | 28 class ExtensionToolbarModel : public ExtensionActionAPI::Observer, |
| 29 public ExtensionRegistryObserver, | 29 public ExtensionRegistryObserver, |
| 30 public KeyedService { | 30 public KeyedService { |
| 31 public: | 31 public: |
| 32 // The different options for highlighting. |
| 33 enum HighlightType { |
| 34 HIGHLIGHT_NONE, |
| 35 HIGHLIGHT_INFO, |
| 36 HIGHLIGHT_WARNING, |
| 37 }; |
| 38 |
| 32 ExtensionToolbarModel(Profile* profile, ExtensionPrefs* extension_prefs); | 39 ExtensionToolbarModel(Profile* profile, ExtensionPrefs* extension_prefs); |
| 33 ~ExtensionToolbarModel() override; | 40 ~ExtensionToolbarModel() override; |
| 34 | 41 |
| 35 // A class which is informed of changes to the model; represents the view of | 42 // A class which is informed of changes to the model; represents the view of |
| 36 // MVC. Also used for signaling view changes such as showing extension popups. | 43 // MVC. Also used for signaling view changes such as showing extension popups. |
| 37 // TODO(devlin): Should this really be an observer? It acts more like a | 44 // TODO(devlin): Should this really be an observer? It acts more like a |
| 38 // delegate. | 45 // delegate. |
| 39 class Observer { | 46 class Observer { |
| 40 public: | 47 public: |
| 41 // Signals that an |extension| has been added to the toolbar at |index|. | 48 // Signals that an |extension| has been added to the toolbar at |index|. |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 toolbar_items().size() : | 118 toolbar_items().size() : |
| 112 std::min(static_cast<size_t>(visible_icon_count_), | 119 std::min(static_cast<size_t>(visible_icon_count_), |
| 113 toolbar_items().size()); | 120 toolbar_items().size()); |
| 114 } | 121 } |
| 115 | 122 |
| 116 bool all_icons_visible() const { return visible_icon_count_ == -1; } | 123 bool all_icons_visible() const { return visible_icon_count_ == -1; } |
| 117 | 124 |
| 118 bool extensions_initialized() const { return extensions_initialized_; } | 125 bool extensions_initialized() const { return extensions_initialized_; } |
| 119 | 126 |
| 120 const ExtensionList& toolbar_items() const { | 127 const ExtensionList& toolbar_items() const { |
| 121 return is_highlighting_ ? highlighted_items_ : toolbar_items_; | 128 return is_highlighting() ? highlighted_items_ : toolbar_items_; |
| 122 } | 129 } |
| 123 | 130 |
| 124 bool is_highlighting() const { return is_highlighting_; } | 131 bool is_highlighting() const { return highlight_type_ != HIGHLIGHT_NONE; } |
| 132 HighlightType highlight_type() const { return highlight_type_; } |
| 125 | 133 |
| 126 void OnExtensionToolbarPrefChange(); | 134 void OnExtensionToolbarPrefChange(); |
| 127 | 135 |
| 128 // Returns the index of the given |id|, or -1 if the id wasn't found. | 136 // Returns the index of the given |id|, or -1 if the id wasn't found. |
| 129 int GetIndexForId(const std::string& id) const; | 137 int GetIndexForId(const std::string& id) const; |
| 130 | 138 |
| 131 // Finds the Observer associated with |browser| and tells it to display a | 139 // Finds the Observer associated with |browser| and tells it to display a |
| 132 // popup for the given |extension|. If |grant_active_tab| is true, this | 140 // popup for the given |extension|. If |grant_active_tab| is true, this |
| 133 // grants active tab permissions to the |extension|; only do this because of | 141 // grants active tab permissions to the |extension|; only do this because of |
| 134 // a direct user action. | 142 // a direct user action. |
| 135 bool ShowExtensionActionPopup(const Extension* extension, | 143 bool ShowExtensionActionPopup(const Extension* extension, |
| 136 Browser* browser, | 144 Browser* browser, |
| 137 bool grant_active_tab); | 145 bool grant_active_tab); |
| 138 | 146 |
| 139 // Ensures that the extensions in the |extension_ids| list are visible on the | 147 // Ensures that the extensions in the |extension_ids| list are visible on the |
| 140 // toolbar. This might mean they need to be moved to the front (if they are in | 148 // toolbar. This might mean they need to be moved to the front (if they are in |
| 141 // the overflow bucket). | 149 // the overflow bucket). |
| 142 void EnsureVisibility(const ExtensionIdList& extension_ids); | 150 void EnsureVisibility(const ExtensionIdList& extension_ids); |
| 143 | 151 |
| 144 // Highlights the extensions specified by |extension_ids|. This will cause | 152 // Highlights the extensions specified by |extension_ids|. This will cause |
| 145 // the ToolbarModel to only display those extensions. | 153 // the ToolbarModel to only display those extensions. |
| 146 // Highlighting mode is only entered if there is at least one extension to | 154 // Highlighting mode is only entered if there is at least one extension to |
| 147 // be shown. | 155 // be shown. |
| 148 // Returns true if highlighting mode is entered, false otherwise. | 156 // Returns true if highlighting mode is entered, false otherwise. |
| 149 bool HighlightExtensions(const ExtensionIdList& extension_ids); | 157 bool HighlightExtensions(const ExtensionIdList& extension_ids, |
| 158 HighlightType type); |
| 150 | 159 |
| 151 // Stop highlighting extensions. All extensions can be shown again, and the | 160 // Stop highlighting extensions. All extensions can be shown again, and the |
| 152 // number of visible icons will be reset to what it was before highlighting. | 161 // number of visible icons will be reset to what it was before highlighting. |
| 153 void StopHighlighting(); | 162 void StopHighlighting(); |
| 154 | 163 |
| 155 // Returns true if the toolbar model is running with the redesign and is | 164 // Returns true if the toolbar model is running with the redesign and is |
| 156 // showing new icons as a result. | 165 // showing new icons as a result. |
| 157 bool RedesignIsShowingNewIcons() const; | 166 bool RedesignIsShowingNewIcons() const; |
| 158 | 167 |
| 159 private: | 168 private: |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 // If true, we include all extensions in the toolbar model. If false, we only | 235 // If true, we include all extensions in the toolbar model. If false, we only |
| 227 // include browser actions. | 236 // include browser actions. |
| 228 bool include_all_extensions_; | 237 bool include_all_extensions_; |
| 229 | 238 |
| 230 // Ordered list of browser action buttons. | 239 // Ordered list of browser action buttons. |
| 231 ExtensionList toolbar_items_; | 240 ExtensionList toolbar_items_; |
| 232 | 241 |
| 233 // List of browser action buttons which should be highlighted. | 242 // List of browser action buttons which should be highlighted. |
| 234 ExtensionList highlighted_items_; | 243 ExtensionList highlighted_items_; |
| 235 | 244 |
| 236 // Indication whether or not we are currently in highlight mode; typically, | 245 // The current type of highlight (with HIGHLIGHT_NONE indicating no current |
| 237 // this is equivalent to !highlighted_items_.empty(), but can be different | 246 // highlight). |
| 238 // if we are exiting highlight mode due to no longer having highlighted items. | 247 HighlightType highlight_type_; |
| 239 bool is_highlighting_; | |
| 240 | |
| 241 // The number of icons which were visible before highlighting a subset, in | |
| 242 // order to restore the count when finished. | |
| 243 int old_visible_icon_count_; | |
| 244 | 248 |
| 245 ExtensionIdList last_known_positions_; | 249 ExtensionIdList last_known_positions_; |
| 246 | 250 |
| 247 // The number of icons visible (the rest should be hidden in the overflow | 251 // The number of icons visible (the rest should be hidden in the overflow |
| 248 // chevron). A value of -1 indicates that all icons should be visible. | 252 // chevron). A value of -1 indicates that all icons should be visible. |
| 249 // Instead of using this variable directly, use visible_icon_count() if | 253 // Instead of using this variable directly, use visible_icon_count() if |
| 250 // possible. | 254 // possible. |
| 251 // TODO(devlin): Make a new variable to indicate that all icons should be | 255 // TODO(devlin): Make a new variable to indicate that all icons should be |
| 252 // visible, instead of overloading this one. | 256 // visible, instead of overloading this one. |
| 253 int visible_icon_count_; | 257 int visible_icon_count_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 264 base::Closure pref_change_callback_; | 268 base::Closure pref_change_callback_; |
| 265 | 269 |
| 266 base::WeakPtrFactory<ExtensionToolbarModel> weak_ptr_factory_; | 270 base::WeakPtrFactory<ExtensionToolbarModel> weak_ptr_factory_; |
| 267 | 271 |
| 268 DISALLOW_COPY_AND_ASSIGN(ExtensionToolbarModel); | 272 DISALLOW_COPY_AND_ASSIGN(ExtensionToolbarModel); |
| 269 }; | 273 }; |
| 270 | 274 |
| 271 } // namespace extensions | 275 } // namespace extensions |
| 272 | 276 |
| 273 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ | 277 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ |
| OLD | NEW |