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