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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 public: | 21 public: |
22 explicit ExtensionToolbarModel(ExtensionService* service); | 22 explicit ExtensionToolbarModel(ExtensionService* service); |
23 virtual ~ExtensionToolbarModel(); | 23 virtual ~ExtensionToolbarModel(); |
24 | 24 |
25 // A class which is informed of changes to the model; represents the view of | 25 // A class which is informed of changes to the model; represents the view of |
26 // MVC. | 26 // MVC. |
27 class Observer { | 27 class Observer { |
28 public: | 28 public: |
29 // An extension with a browser action button has been added, and should go | 29 // An extension with a browser action button has been added, and should go |
30 // in the toolbar at |index|. | 30 // in the toolbar at |index|. |
31 virtual void BrowserActionAdded(const Extension* extension, int index) {} | 31 virtual void BrowserActionAdded(const extensions::Extension* extension, |
| 32 int index) {} |
32 | 33 |
33 // The browser action button for |extension| should no longer show. | 34 // The browser action button for |extension| should no longer show. |
34 virtual void BrowserActionRemoved(const Extension* extension) {} | 35 virtual void BrowserActionRemoved(const extensions::Extension* extension) {} |
35 | 36 |
36 // The browser action button for |extension| has been moved to |index|. | 37 // The browser action button for |extension| has been moved to |index|. |
37 virtual void BrowserActionMoved(const Extension* extension, int index) {} | 38 virtual void BrowserActionMoved(const extensions::Extension* extension, |
| 39 int index) {} |
38 | 40 |
39 // The browser action button for |extension_id| (which was not a popup) was | 41 // The browser action button for |extension_id| (which was not a popup) was |
40 // clicked, executing it. | 42 // clicked, executing it. |
41 virtual void BrowserActionExecuted(const std::string& extension_id, | 43 virtual void BrowserActionExecuted(const std::string& extension_id, |
42 Browser* browser) {} | 44 Browser* browser) {} |
43 | 45 |
44 // Called when the model has finished loading. | 46 // Called when the model has finished loading. |
45 virtual void ModelLoaded() {} | 47 virtual void ModelLoaded() {} |
46 | 48 |
47 protected: | 49 protected: |
48 virtual ~Observer() {} | 50 virtual ~Observer() {} |
49 }; | 51 }; |
50 | 52 |
51 // Functions called by the view. | 53 // Functions called by the view. |
52 void AddObserver(Observer* observer); | 54 void AddObserver(Observer* observer); |
53 void RemoveObserver(Observer* observer); | 55 void RemoveObserver(Observer* observer); |
54 void MoveBrowserAction(const Extension* extension, int index); | 56 void MoveBrowserAction(const extensions::Extension* extension, int index); |
55 void ExecuteBrowserAction(const std::string& extension_id, Browser* browser); | 57 void ExecuteBrowserAction(const std::string& extension_id, Browser* browser); |
56 // If count == size(), this will set the visible icon count to -1, meaning | 58 // If count == size(), this will set the visible icon count to -1, meaning |
57 // "show all actions". | 59 // "show all actions". |
58 void SetVisibleIconCount(int count); | 60 void SetVisibleIconCount(int count); |
59 // As above, a return value of -1 represents "show all actions". | 61 // As above, a return value of -1 represents "show all actions". |
60 int GetVisibleIconCount() { return visible_icon_count_; } | 62 int GetVisibleIconCount() { return visible_icon_count_; } |
61 | 63 |
62 bool extensions_initialized() const { return extensions_initialized_; } | 64 bool extensions_initialized() const { return extensions_initialized_; } |
63 | 65 |
64 size_t size() const { | 66 size_t size() const { |
65 return toolitems_.size(); | 67 return toolitems_.size(); |
66 } | 68 } |
67 | 69 |
68 ExtensionList::iterator begin() { | 70 extensions::ExtensionList::iterator begin() { |
69 return toolitems_.begin(); | 71 return toolitems_.begin(); |
70 } | 72 } |
71 | 73 |
72 ExtensionList::iterator end() { | 74 extensions::ExtensionList::iterator end() { |
73 return toolitems_.end(); | 75 return toolitems_.end(); |
74 } | 76 } |
75 | 77 |
76 const Extension* GetExtensionByIndex(int index) const; | 78 const extensions::Extension* GetExtensionByIndex(int index) const; |
77 | 79 |
78 // Utility functions for converting between an index into the list of | 80 // Utility functions for converting between an index into the list of |
79 // incognito-enabled browser actions, and the list of all browser actions. | 81 // incognito-enabled browser actions, and the list of all browser actions. |
80 int IncognitoIndexToOriginal(int incognito_index); | 82 int IncognitoIndexToOriginal(int incognito_index); |
81 int OriginalIndexToIncognito(int original_index); | 83 int OriginalIndexToIncognito(int original_index); |
82 | 84 |
83 private: | 85 private: |
84 // content::NotificationObserver implementation. | 86 // content::NotificationObserver implementation. |
85 virtual void Observe(int type, | 87 virtual void Observe(int type, |
86 const content::NotificationSource& source, | 88 const content::NotificationSource& source, |
87 const content::NotificationDetails& details) OVERRIDE; | 89 const content::NotificationDetails& details) OVERRIDE; |
88 | 90 |
89 // To be called after the extension service is ready; gets loaded extensions | 91 // To be called after the extension service is ready; gets loaded extensions |
90 // from the extension service and their saved order from the pref service | 92 // from the extension service and their saved order from the pref service |
91 // and constructs |toolitems_| from these data. | 93 // and constructs |toolitems_| from these data. |
92 void InitializeExtensionList(); | 94 void InitializeExtensionList(); |
93 | 95 |
94 // Save the model to prefs. | 96 // Save the model to prefs. |
95 void UpdatePrefs(); | 97 void UpdatePrefs(); |
96 | 98 |
97 // Our observers. | 99 // Our observers. |
98 ObserverList<Observer> observers_; | 100 ObserverList<Observer> observers_; |
99 | 101 |
100 void AddExtension(const Extension* extension); | 102 void AddExtension(const extensions::Extension* extension); |
101 void RemoveExtension(const Extension* extension); | 103 void RemoveExtension(const extensions::Extension* extension); |
102 | 104 |
103 // Our ExtensionService, guaranteed to outlive us. | 105 // Our ExtensionService, guaranteed to outlive us. |
104 ExtensionService* service_; | 106 ExtensionService* service_; |
105 | 107 |
106 PrefService* prefs_; | 108 PrefService* prefs_; |
107 | 109 |
108 // True if we've handled the initial EXTENSIONS_READY notification. | 110 // True if we've handled the initial EXTENSIONS_READY notification. |
109 bool extensions_initialized_; | 111 bool extensions_initialized_; |
110 | 112 |
111 // Ordered list of browser action buttons. | 113 // Ordered list of browser action buttons. |
112 ExtensionList toolitems_; | 114 extensions::ExtensionList toolitems_; |
113 | 115 |
114 // Keeps track of what the last extension to get disabled was. | 116 // Keeps track of what the last extension to get disabled was. |
115 std::string last_extension_removed_; | 117 std::string last_extension_removed_; |
116 | 118 |
117 // Keeps track of where the last extension to get disabled was in the list. | 119 // Keeps track of where the last extension to get disabled was in the list. |
118 size_t last_extension_removed_index_; | 120 size_t last_extension_removed_index_; |
119 | 121 |
120 // The number of icons visible (the rest should be hidden in the overflow | 122 // The number of icons visible (the rest should be hidden in the overflow |
121 // chevron). | 123 // chevron). |
122 int visible_icon_count_; | 124 int visible_icon_count_; |
123 | 125 |
124 content::NotificationRegistrar registrar_; | 126 content::NotificationRegistrar registrar_; |
125 }; | 127 }; |
126 | 128 |
127 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ | 129 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ |
OLD | NEW |