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 "chrome/browser/extensions/extension_prefs.h" |
11 #include "content/public/browser/notification_observer.h" | 12 #include "content/public/browser/notification_observer.h" |
12 #include "content/public/browser/notification_registrar.h" | 13 #include "content/public/browser/notification_registrar.h" |
13 | 14 |
14 class Browser; | 15 class Browser; |
15 class ExtensionService; | 16 class ExtensionService; |
16 class PrefService; | 17 class PrefService; |
17 | 18 |
18 // Model for the browser actions toolbar. | 19 // Model for the browser actions toolbar. |
19 class ExtensionToolbarModel : public content::NotificationObserver { | 20 class ExtensionToolbarModel : public content::NotificationObserver { |
20 public: | 21 public: |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 GURL* popup_url_out); | 67 GURL* popup_url_out); |
67 // If count == size(), this will set the visible icon count to -1, meaning | 68 // If count == size(), this will set the visible icon count to -1, meaning |
68 // "show all actions". | 69 // "show all actions". |
69 void SetVisibleIconCount(int count); | 70 void SetVisibleIconCount(int count); |
70 // As above, a return value of -1 represents "show all actions". | 71 // As above, a return value of -1 represents "show all actions". |
71 int GetVisibleIconCount() const { return visible_icon_count_; } | 72 int GetVisibleIconCount() const { return visible_icon_count_; } |
72 | 73 |
73 bool extensions_initialized() const { return extensions_initialized_; } | 74 bool extensions_initialized() const { return extensions_initialized_; } |
74 | 75 |
75 size_t size() const { | 76 size_t size() const { |
76 return toolitems_.size(); | 77 return toolbar_items_.size(); |
77 } | 78 } |
78 | 79 |
79 extensions::ExtensionList::iterator begin() { | 80 extensions::ExtensionList::iterator begin() { |
80 return toolitems_.begin(); | 81 return toolbar_items_.begin(); |
81 } | 82 } |
82 | 83 |
83 extensions::ExtensionList::iterator end() { | 84 extensions::ExtensionList::iterator end() { |
84 return toolitems_.end(); | 85 return toolbar_items_.end(); |
85 } | 86 } |
86 | 87 |
87 const extensions::Extension* GetExtensionByIndex(int index) const; | 88 const extensions::Extension* toolbar_item_by_index(int index) const { |
| 89 return toolbar_items_[index]; |
| 90 } |
88 | 91 |
89 // Utility functions for converting between an index into the list of | 92 // Utility functions for converting between an index into the list of |
90 // incognito-enabled browser actions, and the list of all browser actions. | 93 // incognito-enabled browser actions, and the list of all browser actions. |
91 int IncognitoIndexToOriginal(int incognito_index); | 94 int IncognitoIndexToOriginal(int incognito_index); |
92 int OriginalIndexToIncognito(int original_index); | 95 int OriginalIndexToIncognito(int original_index); |
93 | 96 |
| 97 size_t action_box_extensions_size() { |
| 98 return action_box_menu_items_.size(); |
| 99 } |
| 100 |
| 101 const extensions::Extension* action_box_menu_item_by_index(int index) const { |
| 102 return action_box_menu_items_[index]; |
| 103 } |
| 104 |
94 private: | 105 private: |
95 // content::NotificationObserver implementation. | 106 // content::NotificationObserver implementation. |
96 virtual void Observe(int type, | 107 virtual void Observe(int type, |
97 const content::NotificationSource& source, | 108 const content::NotificationSource& source, |
98 const content::NotificationDetails& details) OVERRIDE; | 109 const content::NotificationDetails& details) OVERRIDE; |
99 | 110 |
100 // To be called after the extension service is ready; gets loaded extensions | 111 // 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 | 112 // from the extension service and their saved order from the pref service |
102 // and constructs |toolitems_| from these data. | 113 // and constructs |toolbar_items_| and |action_box_items_| from these data. |
103 void InitializeExtensionList(); | 114 void InitializeExtensionLists(); |
| 115 void PopulateForActionBoxMode(); |
| 116 void PopulateForNonActionBoxMode(); |
| 117 |
| 118 // Fills |list| with extensions based on provided |order|. |
| 119 void FillExtensionList( |
| 120 const extensions::ExtensionPrefs::ExtensionIdSet& order, |
| 121 extensions::ExtensionList* list); |
104 | 122 |
105 // Save the model to prefs. | 123 // Save the model to prefs. |
106 void UpdatePrefs(); | 124 void UpdatePrefs(); |
107 | 125 |
108 // Our observers. | 126 // Our observers. |
109 ObserverList<Observer> observers_; | 127 ObserverList<Observer> observers_; |
110 | 128 |
111 void AddExtension(const extensions::Extension* extension); | 129 void AddExtension(const extensions::Extension* extension, |
112 void RemoveExtension(const extensions::Extension* extension); | 130 extensions::ExtensionList* list); |
| 131 void RemoveExtension(const extensions::Extension* extension, |
| 132 extensions::ExtensionList* list); |
| 133 |
| 134 // Searches for the given |extension| in |toolbar_items_| and |
| 135 // |action_box_menu_items_| and returns pointer to the list with it |
| 136 // or NULL if not found. |
| 137 extensions::ExtensionList* FindListWithExtension( |
| 138 const extensions::Extension* extension); |
113 | 139 |
114 // Our ExtensionService, guaranteed to outlive us. | 140 // Our ExtensionService, guaranteed to outlive us. |
115 ExtensionService* service_; | 141 ExtensionService* service_; |
116 | 142 |
117 PrefService* prefs_; | 143 PrefService* prefs_; |
118 | 144 |
119 // True if we've handled the initial EXTENSIONS_READY notification. | 145 // True if we've handled the initial EXTENSIONS_READY notification. |
120 bool extensions_initialized_; | 146 bool extensions_initialized_; |
121 | 147 |
122 // Ordered list of browser action buttons. | 148 // Ordered list of browser action buttons. |
123 extensions::ExtensionList toolitems_; | 149 extensions::ExtensionList toolbar_items_; |
| 150 |
| 151 // List of browser action buttons visible in an action box menu. |
| 152 extensions::ExtensionList action_box_menu_items_; |
124 | 153 |
125 // Keeps track of what the last extension to get disabled was. | 154 // Keeps track of what the last extension to get disabled was. |
126 std::string last_extension_removed_; | 155 std::string last_extension_removed_; |
127 | 156 |
128 // Keeps track of where the last extension to get disabled was in the list. | 157 // Keeps track of where the last extension to get disabled was in the list. |
129 size_t last_extension_removed_index_; | 158 size_t last_extension_removed_index_; |
130 | 159 |
131 // The number of icons visible (the rest should be hidden in the overflow | 160 // The number of icons visible (the rest should be hidden in the overflow |
132 // chevron). | 161 // chevron). |
133 int visible_icon_count_; | 162 int visible_icon_count_; |
134 | 163 |
135 content::NotificationRegistrar registrar_; | 164 content::NotificationRegistrar registrar_; |
136 | 165 |
137 DISALLOW_COPY_AND_ASSIGN(ExtensionToolbarModel); | 166 DISALLOW_COPY_AND_ASSIGN(ExtensionToolbarModel); |
138 }; | 167 }; |
139 | 168 |
140 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ | 169 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ |
OLD | NEW |