| 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" |
| 11 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
| 12 #include "chrome/browser/extensions/extension_prefs.h" | 12 #include "chrome/browser/extensions/extension_prefs.h" |
| 13 #include "components/browser_context_keyed_service/browser_context_keyed_service
.h" |
| 13 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
| 14 #include "content/public/browser/notification_registrar.h" | 15 #include "content/public/browser/notification_registrar.h" |
| 15 | 16 |
| 16 class Browser; | 17 class Browser; |
| 17 class ExtensionService; | 18 class ExtensionService; |
| 18 class PrefService; | 19 class PrefService; |
| 19 | 20 |
| 20 // Model for the browser actions toolbar. | 21 // Model for the browser actions toolbar. |
| 21 class ExtensionToolbarModel : public content::NotificationObserver { | 22 class ExtensionToolbarModel : public content::NotificationObserver, |
| 23 public BrowserContextKeyedService { |
| 22 public: | 24 public: |
| 23 explicit ExtensionToolbarModel(ExtensionService* service); | 25 ExtensionToolbarModel(Profile* profile, |
| 26 extensions::ExtensionPrefs* extension_prefs); |
| 24 virtual ~ExtensionToolbarModel(); | 27 virtual ~ExtensionToolbarModel(); |
| 25 | 28 |
| 26 // The action that should be taken as a result of clicking a browser action. | 29 // The action that should be taken as a result of clicking a browser action. |
| 27 enum Action { | 30 enum Action { |
| 28 ACTION_NONE, | 31 ACTION_NONE, |
| 29 ACTION_SHOW_POPUP, | 32 ACTION_SHOW_POPUP, |
| 30 // Unlike LocationBarController there is no ACTION_SHOW_CONTEXT_MENU, | 33 // Unlike LocationBarController there is no ACTION_SHOW_CONTEXT_MENU, |
| 31 // because UI implementations tend to handle this themselves at a higher | 34 // because UI implementations tend to handle this themselves at a higher |
| 32 // level. | 35 // level. |
| 33 }; | 36 }; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 52 // Returns true if a popup was slated to be shown. | 55 // Returns true if a popup was slated to be shown. |
| 53 virtual bool BrowserActionShowPopup(const extensions::Extension* extension); | 56 virtual bool BrowserActionShowPopup(const extensions::Extension* extension); |
| 54 | 57 |
| 55 // Called when the model has finished loading. | 58 // Called when the model has finished loading. |
| 56 virtual void ModelLoaded() {} | 59 virtual void ModelLoaded() {} |
| 57 | 60 |
| 58 protected: | 61 protected: |
| 59 virtual ~Observer() {} | 62 virtual ~Observer() {} |
| 60 }; | 63 }; |
| 61 | 64 |
| 65 // Convenience function to get the ExtensionToolbarModel for a Profile. |
| 66 static ExtensionToolbarModel* Get(Profile* profile); |
| 67 |
| 62 // Functions called by the view. | 68 // Functions called by the view. |
| 63 void AddObserver(Observer* observer); | 69 void AddObserver(Observer* observer); |
| 64 void RemoveObserver(Observer* observer); | 70 void RemoveObserver(Observer* observer); |
| 65 void MoveBrowserAction(const extensions::Extension* extension, int index); | 71 void MoveBrowserAction(const extensions::Extension* extension, int index); |
| 66 // Executes the browser action for an extension and returns the action that | 72 // Executes the browser action for an extension and returns the action that |
| 67 // the UI should perform in response. | 73 // the UI should perform in response. |
| 68 // |popup_url_out| will be set if the extension should show a popup, with | 74 // |popup_url_out| will be set if the extension should show a popup, with |
| 69 // the URL that should be shown, if non-NULL. |should_grant| controls whether | 75 // the URL that should be shown, if non-NULL. |should_grant| controls whether |
| 70 // the extension should be granted page tab permissions, which is what happens | 76 // the extension should be granted page tab permissions, which is what happens |
| 71 // when the user clicks the browser action, but not, for example, when the | 77 // when the user clicks the browser action, but not, for example, when the |
| (...skipping 27 matching lines...) Expand all Loading... |
| 99 | 105 |
| 100 private: | 106 private: |
| 101 // content::NotificationObserver implementation. | 107 // content::NotificationObserver implementation. |
| 102 virtual void Observe(int type, | 108 virtual void Observe(int type, |
| 103 const content::NotificationSource& source, | 109 const content::NotificationSource& source, |
| 104 const content::NotificationDetails& details) OVERRIDE; | 110 const content::NotificationDetails& details) OVERRIDE; |
| 105 | 111 |
| 106 // 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 |
| 107 // 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 |
| 108 // and constructs |toolbar_items_| from these data. | 114 // and constructs |toolbar_items_| from these data. |
| 109 void InitializeExtensionList(); | 115 void InitializeExtensionList(ExtensionService* service); |
| 110 void Populate(const extensions::ExtensionIdList& positions); | 116 void Populate(const extensions::ExtensionIdList& positions, |
| 117 ExtensionService* service); |
| 111 | 118 |
| 112 // Fills |list| with extensions based on provided |order|. | 119 // Fills |list| with extensions based on provided |order|. |
| 113 void FillExtensionList(const extensions::ExtensionIdList& order); | 120 void FillExtensionList(const extensions::ExtensionIdList& order, |
| 121 ExtensionService* service); |
| 114 | 122 |
| 115 // Save the model to prefs. | 123 // Save the model to prefs. |
| 116 void UpdatePrefs(); | 124 void UpdatePrefs(); |
| 117 | 125 |
| 118 // Finds the last known visible position of the icon for an |extension|. The | 126 // Finds the last known visible position of the icon for an |extension|. The |
| 119 // value returned is a zero-based index into the vector of visible items. | 127 // value returned is a zero-based index into the vector of visible items. |
| 120 size_t FindNewPositionFromLastKnownGood( | 128 size_t FindNewPositionFromLastKnownGood( |
| 121 const extensions::Extension* extension); | 129 const extensions::Extension* extension); |
| 122 | 130 |
| 123 // Our observers. | 131 // Our observers. |
| 124 ObserverList<Observer> observers_; | 132 ObserverList<Observer> observers_; |
| 125 | 133 |
| 126 void AddExtension(const extensions::Extension* extension); | 134 void AddExtension(const extensions::Extension* extension); |
| 127 void RemoveExtension(const extensions::Extension* extension); | 135 void RemoveExtension(const extensions::Extension* extension); |
| 128 void UninstalledExtension(const extensions::Extension* extension); | 136 void UninstalledExtension(const extensions::Extension* extension); |
| 129 | 137 |
| 130 // Our ExtensionService, guaranteed to outlive us. | 138 // The Profile this toolbar model is for. |
| 131 ExtensionService* service_; | 139 Profile* profile_; |
| 132 | 140 |
| 141 extensions::ExtensionPrefs* extension_prefs_; |
| 133 PrefService* prefs_; | 142 PrefService* prefs_; |
| 134 | 143 |
| 135 // True if we've handled the initial EXTENSIONS_READY notification. | 144 // True if we've handled the initial EXTENSIONS_READY notification. |
| 136 bool extensions_initialized_; | 145 bool extensions_initialized_; |
| 137 | 146 |
| 138 // Ordered list of browser action buttons. | 147 // Ordered list of browser action buttons. |
| 139 extensions::ExtensionList toolbar_items_; | 148 extensions::ExtensionList toolbar_items_; |
| 140 | 149 |
| 141 extensions::ExtensionIdList last_known_positions_; | 150 extensions::ExtensionIdList last_known_positions_; |
| 142 | 151 |
| 143 // The number of icons visible (the rest should be hidden in the overflow | 152 // The number of icons visible (the rest should be hidden in the overflow |
| 144 // chevron). | 153 // chevron). |
| 145 int visible_icon_count_; | 154 int visible_icon_count_; |
| 146 | 155 |
| 147 content::NotificationRegistrar registrar_; | 156 content::NotificationRegistrar registrar_; |
| 148 | 157 |
| 149 // For observing change of toolbar order preference by external entity (sync). | 158 // For observing change of toolbar order preference by external entity (sync). |
| 150 PrefChangeRegistrar pref_change_registrar_; | 159 PrefChangeRegistrar pref_change_registrar_; |
| 151 base::Closure pref_change_callback_; | 160 base::Closure pref_change_callback_; |
| 152 | 161 |
| 153 base::WeakPtrFactory<ExtensionToolbarModel> weak_ptr_factory_; | 162 base::WeakPtrFactory<ExtensionToolbarModel> weak_ptr_factory_; |
| 154 | 163 |
| 155 DISALLOW_COPY_AND_ASSIGN(ExtensionToolbarModel); | 164 DISALLOW_COPY_AND_ASSIGN(ExtensionToolbarModel); |
| 156 }; | 165 }; |
| 157 | 166 |
| 158 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ | 167 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ |
| OLD | NEW |