Chromium Code Reviews| 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 "chrome/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
| 11 #include "content/public/browser/notification_observer.h" | 11 #include "content/public/browser/notification_observer.h" |
| 12 #include "content/public/browser/notification_registrar.h" | 12 #include "content/public/browser/notification_registrar.h" |
| 13 | 13 |
| 14 class Browser; | 14 class Browser; |
| 15 class ExtensionService; | 15 class ExtensionService; |
| 16 class PrefService; | 16 class PrefService; |
| 17 | 17 |
| 18 // Model for the browser actions toolbar. | 18 // Model for the browser actions toolbar. |
| 19 class ExtensionToolbarModel : public content::NotificationObserver { | 19 class ExtensionToolbarModel : public content::NotificationObserver { |
| 20 public: | 20 public: |
| 21 typedef std::vector<std::string> VectorOfStrings; | |
|
Peter Kasting
2012/07/21 01:55:13
Nit: As noted in extension_prefs.h, if you change
yefimt
2012/07/23 23:47:52
Done.
| |
| 22 | |
| 21 explicit ExtensionToolbarModel(ExtensionService* service); | 23 explicit ExtensionToolbarModel(ExtensionService* service); |
| 22 virtual ~ExtensionToolbarModel(); | 24 virtual ~ExtensionToolbarModel(); |
| 23 | 25 |
| 24 // The action that should be taken as a result of clicking a browser action. | 26 // The action that should be taken as a result of clicking a browser action. |
| 25 enum Action { | 27 enum Action { |
| 26 ACTION_NONE, | 28 ACTION_NONE, |
| 27 ACTION_SHOW_POPUP, | 29 ACTION_SHOW_POPUP, |
| 28 // Unlike LocationBarController there is no ACTION_SHOW_CONTEXT_MENU, | 30 // Unlike LocationBarController there is no ACTION_SHOW_CONTEXT_MENU, |
| 29 // because UI implementations tend to handle this themselves at a higher | 31 // because UI implementations tend to handle this themselves at a higher |
| 30 // level. | 32 // level. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 GURL* popup_url_out); | 68 GURL* popup_url_out); |
| 67 // If count == size(), this will set the visible icon count to -1, meaning | 69 // If count == size(), this will set the visible icon count to -1, meaning |
| 68 // "show all actions". | 70 // "show all actions". |
| 69 void SetVisibleIconCount(int count); | 71 void SetVisibleIconCount(int count); |
| 70 // As above, a return value of -1 represents "show all actions". | 72 // As above, a return value of -1 represents "show all actions". |
| 71 int GetVisibleIconCount() const { return visible_icon_count_; } | 73 int GetVisibleIconCount() const { return visible_icon_count_; } |
| 72 | 74 |
| 73 bool extensions_initialized() const { return extensions_initialized_; } | 75 bool extensions_initialized() const { return extensions_initialized_; } |
| 74 | 76 |
| 75 size_t size() const { | 77 size_t size() const { |
| 76 return toolitems_.size(); | 78 return toolbar_items_.size(); |
| 77 } | 79 } |
| 78 | 80 |
| 79 extensions::ExtensionList::iterator begin() { | 81 extensions::ExtensionList::iterator begin() { |
| 80 return toolitems_.begin(); | 82 return toolbar_items_.begin(); |
| 81 } | 83 } |
| 82 | 84 |
| 83 extensions::ExtensionList::iterator end() { | 85 extensions::ExtensionList::iterator end() { |
| 84 return toolitems_.end(); | 86 return toolbar_items_.end(); |
| 85 } | 87 } |
| 86 | 88 |
| 87 const extensions::Extension* GetExtensionByIndex(int index) const; | 89 const extensions::Extension* GetExtensionByIndex(int index) const { |
|
Peter Kasting
2012/07/21 01:55:13
Nit: Inlined functions should be named unix_hacker
yefimt
2012/07/23 23:47:52
Yes, but they not returning a member variable but
Peter Kasting
2012/07/24 04:27:29
That's what we have trybots for. Please do at lea
| |
| 90 return toolbar_items_[index]; | |
| 91 } | |
| 88 | 92 |
| 89 // Utility functions for converting between an index into the list of | 93 // Utility functions for converting between an index into the list of |
| 90 // incognito-enabled browser actions, and the list of all browser actions. | 94 // incognito-enabled browser actions, and the list of all browser actions. |
| 91 int IncognitoIndexToOriginal(int incognito_index); | 95 int IncognitoIndexToOriginal(int incognito_index); |
| 92 int OriginalIndexToIncognito(int original_index); | 96 int OriginalIndexToIncognito(int original_index); |
| 93 | 97 |
| 98 size_t action_box_extensions_size() { | |
| 99 return action_box_menu_items_.size(); | |
| 100 } | |
| 101 | |
| 102 const extensions::Extension* GetActionBoxExtensionByIndex(int index) const { | |
| 103 return action_box_menu_items_[index]; | |
| 104 } | |
| 105 | |
| 94 private: | 106 private: |
| 95 // content::NotificationObserver implementation. | 107 // content::NotificationObserver implementation. |
| 96 virtual void Observe(int type, | 108 virtual void Observe(int type, |
| 97 const content::NotificationSource& source, | 109 const content::NotificationSource& source, |
| 98 const content::NotificationDetails& details) OVERRIDE; | 110 const content::NotificationDetails& details) OVERRIDE; |
| 99 | 111 |
| 100 // To be called after the extension service is ready; gets loaded extensions | 112 // To be called after the extension service is ready; gets loaded extensions |
| 101 // from the extension service and their saved order from the pref service | 113 // from the extension service and their saved order from the pref service |
| 102 // and constructs |toolitems_| from these data. | 114 // and constructs |toolbar_items_| and |action_box_items_| from these data. |
| 103 void InitializeExtensionList(); | 115 void InitializeExtensionLists(); |
| 116 void PopulateForActionBoxMode(); | |
| 117 void PopulateForNonActionBoxMode(); | |
| 118 | |
| 119 // A couple helper functions to populate lists. | |
| 120 void AddToProperList(const extensions::Extension* extension, | |
| 121 const VectorOfStrings& order, | |
| 122 extensions::ExtensionList* sorted, | |
| 123 extensions::ExtensionList* unsorted); | |
| 124 void MergeLists(const extensions::ExtensionList& sorted, | |
| 125 const extensions::ExtensionList& unsorted, | |
| 126 extensions::ExtensionList* result_list); | |
| 127 void FillExtensionList(const VectorOfStrings& order, | |
| 128 extensions::ExtensionList* result_list); | |
| 104 | 129 |
| 105 // Save the model to prefs. | 130 // Save the model to prefs. |
| 106 void UpdatePrefs(); | 131 void UpdatePrefs(); |
| 107 | 132 |
| 108 // Our observers. | 133 // Our observers. |
| 109 ObserverList<Observer> observers_; | 134 ObserverList<Observer> observers_; |
| 110 | 135 |
| 111 void AddExtension(const extensions::Extension* extension); | 136 void AddExtension(const extensions::Extension* extension); |
| 112 void RemoveExtension(const extensions::Extension* extension); | 137 void RemoveExtension(const extensions::Extension* extension); |
| 113 | 138 |
| 114 // Our ExtensionService, guaranteed to outlive us. | 139 // Our ExtensionService, guaranteed to outlive us. |
| 115 ExtensionService* service_; | 140 ExtensionService* service_; |
| 116 | 141 |
| 117 PrefService* prefs_; | 142 PrefService* prefs_; |
| 118 | 143 |
| 119 // True if we've handled the initial EXTENSIONS_READY notification. | 144 // True if we've handled the initial EXTENSIONS_READY notification. |
| 120 bool extensions_initialized_; | 145 bool extensions_initialized_; |
| 121 | 146 |
| 122 // Ordered list of browser action buttons. | 147 // Ordered list of browser action buttons. |
| 123 extensions::ExtensionList toolitems_; | 148 extensions::ExtensionList toolbar_items_; |
| 149 | |
| 150 // List of browser action buttons visible in an action box menu. | |
| 151 extensions::ExtensionList action_box_menu_items_; | |
| 124 | 152 |
| 125 // Keeps track of what the last extension to get disabled was. | 153 // Keeps track of what the last extension to get disabled was. |
| 126 std::string last_extension_removed_; | 154 std::string last_extension_removed_; |
| 127 | 155 |
| 128 // Keeps track of where the last extension to get disabled was in the list. | 156 // Keeps track of where the last extension to get disabled was in the list. |
| 129 size_t last_extension_removed_index_; | 157 size_t last_extension_removed_index_; |
| 130 | 158 |
| 131 // The number of icons visible (the rest should be hidden in the overflow | 159 // The number of icons visible (the rest should be hidden in the overflow |
| 132 // chevron). | 160 // chevron). |
| 133 int visible_icon_count_; | 161 int visible_icon_count_; |
| 134 | 162 |
| 135 content::NotificationRegistrar registrar_; | 163 content::NotificationRegistrar registrar_; |
| 136 | 164 |
| 137 DISALLOW_COPY_AND_ASSIGN(ExtensionToolbarModel); | 165 DISALLOW_COPY_AND_ASSIGN(ExtensionToolbarModel); |
| 138 }; | 166 }; |
| 139 | 167 |
| 140 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ | 168 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ |
| OLD | NEW |