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 19 matching lines...) Expand all Loading... |
30 class ExtensionToolbarModel : public content::NotificationObserver, | 30 class ExtensionToolbarModel : public content::NotificationObserver, |
31 public ExtensionActionAPI::Observer, | 31 public ExtensionActionAPI::Observer, |
32 public ExtensionRegistryObserver, | 32 public ExtensionRegistryObserver, |
33 public KeyedService { | 33 public KeyedService { |
34 public: | 34 public: |
35 ExtensionToolbarModel(Profile* profile, ExtensionPrefs* extension_prefs); | 35 ExtensionToolbarModel(Profile* profile, ExtensionPrefs* extension_prefs); |
36 virtual ~ExtensionToolbarModel(); | 36 virtual ~ExtensionToolbarModel(); |
37 | 37 |
38 // A class which is informed of changes to the model; represents the view of | 38 // A class which is informed of changes to the model; represents the view of |
39 // MVC. Also used for signaling view changes such as showing extension popups. | 39 // MVC. Also used for signaling view changes such as showing extension popups. |
40 // TODO(devlin): Should this really be an observer? There should probably be | 40 // TODO(devlin): Should this really be an observer? It acts more like a |
41 // only one (aka a Delegate)... | 41 // delegate. |
42 class Observer { | 42 class Observer { |
43 public: | 43 public: |
44 // An extension has been added to the toolbar and should go at |index|. | 44 // An extension has been added to the toolbar and should go at |index|. |
45 virtual void ToolbarExtensionAdded(const Extension* extension, | 45 virtual void ToolbarExtensionAdded(const Extension* extension, |
46 int index) = 0; | 46 int index) = 0; |
47 | 47 |
48 // The given |extension| should be removed from the toolbar. | 48 // The given |extension| should be removed from the toolbar. |
49 virtual void ToolbarExtensionRemoved(const Extension* extension) = 0; | 49 virtual void ToolbarExtensionRemoved(const Extension* extension) = 0; |
50 | 50 |
51 // The given |extension| has been moved to |index|. |index| is the desired | 51 // The given |extension| has been moved to |index|. |index| is the desired |
52 // *final* index of the extension (that is, in the adjusted order, extension | 52 // *final* index of the extension (that is, in the adjusted order, extension |
53 // should be at |index|). | 53 // should be at |index|). |
54 virtual void ToolbarExtensionMoved(const Extension* extension, | 54 virtual void ToolbarExtensionMoved(const Extension* extension, |
55 int index) = 0; | 55 int index) = 0; |
56 | 56 |
57 // Signals that the browser action for the given |extension| has been | 57 // Signals that the browser action for the given |extension| has been |
58 // updated. | 58 // updated. |
59 virtual void ToolbarExtensionUpdated(const Extension* extension) = 0; | 59 virtual void ToolbarExtensionUpdated(const Extension* extension) = 0; |
60 | 60 |
61 // Signal the |extension| to show the popup now in the active window. | 61 // Signal the |extension| to show the popup now in the active window. |
| 62 // If |grant_active_tab| is true, then active tab permissions should be |
| 63 // given to the extension (only do this if this is through a user action). |
62 // Returns true if a popup was slated to be shown. | 64 // Returns true if a popup was slated to be shown. |
63 virtual bool ShowExtensionActionPopup(const Extension* extension) = 0; | 65 virtual bool ShowExtensionActionPopup(const Extension* extension, |
| 66 bool grant_active_tab) = 0; |
64 | 67 |
65 // Signal when the container needs to be redrawn because of a size change, | 68 // Signal when the container needs to be redrawn because of a size change, |
66 // and when the model has finished loading. | 69 // and when the model has finished loading. |
67 virtual void ToolbarVisibleCountChanged() = 0; | 70 virtual void ToolbarVisibleCountChanged() = 0; |
68 | 71 |
69 // Signal that the model has entered or exited highlighting mode, or that | 72 // Signal that the model has entered or exited highlighting mode, or that |
70 // the extensions being highlighted have (probably*) changed. Highlighting | 73 // the extensions being highlighted have (probably*) changed. Highlighting |
71 // mode indicates that only a subset of the extensions are actively | 74 // mode indicates that only a subset of the extensions are actively |
72 // displayed, and those extensions should be highlighted for extra emphasis. | 75 // displayed, and those extensions should be highlighted for extra emphasis. |
73 // * probably, because if we are in highlight mode and receive a call to | 76 // * probably, because if we are in highlight mode and receive a call to |
74 // highlight a new set of extensions, we do not compare the current set | 77 // highlight a new set of extensions, we do not compare the current set |
75 // with the new set (and just assume the new set is different). | 78 // with the new set (and just assume the new set is different). |
76 virtual void ToolbarHighlightModeChanged(bool is_highlighting) = 0; | 79 virtual void ToolbarHighlightModeChanged(bool is_highlighting) = 0; |
77 | 80 |
| 81 // Returns the browser associated with the Observer. |
| 82 virtual Browser* GetBrowser() = 0; |
| 83 |
78 protected: | 84 protected: |
79 virtual ~Observer() {} | 85 virtual ~Observer() {} |
80 }; | 86 }; |
81 | 87 |
82 // Convenience function to get the ExtensionToolbarModel for a Profile. | 88 // Convenience function to get the ExtensionToolbarModel for a Profile. |
83 static ExtensionToolbarModel* Get(Profile* profile); | 89 static ExtensionToolbarModel* Get(Profile* profile); |
84 | 90 |
85 // Add or remove an observer. | 91 // Add or remove an observer. |
86 void AddObserver(Observer* observer); | 92 void AddObserver(Observer* observer); |
87 void RemoveObserver(Observer* observer); | 93 void RemoveObserver(Observer* observer); |
(...skipping 17 matching lines...) Expand all Loading... |
105 | 111 |
106 bool is_highlighting() const { return is_highlighting_; } | 112 bool is_highlighting() const { return is_highlighting_; } |
107 | 113 |
108 // Utility functions for converting between an index into the list of | 114 // Utility functions for converting between an index into the list of |
109 // incognito-enabled browser actions, and the list of all browser actions. | 115 // incognito-enabled browser actions, and the list of all browser actions. |
110 int IncognitoIndexToOriginal(int incognito_index); | 116 int IncognitoIndexToOriginal(int incognito_index); |
111 int OriginalIndexToIncognito(int original_index); | 117 int OriginalIndexToIncognito(int original_index); |
112 | 118 |
113 void OnExtensionToolbarPrefChange(); | 119 void OnExtensionToolbarPrefChange(); |
114 | 120 |
115 // Tells observers to display a popup without granting tab permissions and | 121 // Finds the Observer associated with |browser| and tells it to display a |
116 // returns whether the popup was slated to be shown. | 122 // popup for the given |extension|. If |grant_active_tab| is true, this |
117 bool ShowBrowserActionPopup(const Extension* extension); | 123 // grants active tab permissions to the |extension|; only do this because of |
| 124 // a direct user action. |
| 125 bool ShowExtensionActionPopup(const Extension* extension, |
| 126 Browser* browser, |
| 127 bool grant_active_tab); |
118 | 128 |
119 // Ensures that the extensions in the |extension_ids| list are visible on the | 129 // Ensures that the extensions in the |extension_ids| list are visible on the |
120 // toolbar. This might mean they need to be moved to the front (if they are in | 130 // toolbar. This might mean they need to be moved to the front (if they are in |
121 // the overflow bucket). | 131 // the overflow bucket). |
122 void EnsureVisibility(const ExtensionIdList& extension_ids); | 132 void EnsureVisibility(const ExtensionIdList& extension_ids); |
123 | 133 |
124 // Highlight the extensions specified by |extension_ids|. This will cause | 134 // Highlight the extensions specified by |extension_ids|. This will cause |
125 // the ToolbarModel to only display those extensions. | 135 // the ToolbarModel to only display those extensions. |
126 // Highlighting mode is only entered if there is at least one extension to | 136 // Highlighting mode is only entered if there is at least one extension to |
127 // be shown. | 137 // be shown. |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 base::Closure pref_change_callback_; | 251 base::Closure pref_change_callback_; |
242 | 252 |
243 base::WeakPtrFactory<ExtensionToolbarModel> weak_ptr_factory_; | 253 base::WeakPtrFactory<ExtensionToolbarModel> weak_ptr_factory_; |
244 | 254 |
245 DISALLOW_COPY_AND_ASSIGN(ExtensionToolbarModel); | 255 DISALLOW_COPY_AND_ASSIGN(ExtensionToolbarModel); |
246 }; | 256 }; |
247 | 257 |
248 } // namespace extensions | 258 } // namespace extensions |
249 | 259 |
250 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ | 260 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ |
OLD | NEW |