| 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 "base/scoped_observer.h" | 11 #include "base/scoped_observer.h" |
| 12 #include "chrome/browser/extensions/extension_action.h" |
| 12 #include "components/keyed_service/core/keyed_service.h" | 13 #include "components/keyed_service/core/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 #include "extensions/browser/extension_prefs.h" | 16 #include "extensions/browser/extension_prefs.h" |
| 16 #include "extensions/browser/extension_registry_observer.h" | 17 #include "extensions/browser/extension_registry_observer.h" |
| 17 #include "extensions/common/extension.h" | 18 #include "extensions/common/extension.h" |
| 18 | 19 |
| 19 class Browser; | 20 class Browser; |
| 20 class PrefService; | 21 class PrefService; |
| 21 class Profile; | 22 class Profile; |
| 22 | 23 |
| 23 namespace extensions { | 24 namespace extensions { |
| 24 class ExtensionRegistry; | 25 class ExtensionRegistry; |
| 25 class ExtensionSet; | 26 class ExtensionSet; |
| 26 | 27 |
| 27 // Model for the browser actions toolbar. | 28 // Model for the browser actions toolbar. |
| 28 class ExtensionToolbarModel : public content::NotificationObserver, | 29 class ExtensionToolbarModel : public content::NotificationObserver, |
| 29 public ExtensionRegistryObserver, | 30 public ExtensionRegistryObserver, |
| 30 public KeyedService { | 31 public KeyedService { |
| 31 public: | 32 public: |
| 32 ExtensionToolbarModel(Profile* profile, ExtensionPrefs* extension_prefs); | 33 ExtensionToolbarModel(Profile* profile, ExtensionPrefs* extension_prefs); |
| 33 virtual ~ExtensionToolbarModel(); | 34 virtual ~ExtensionToolbarModel(); |
| 34 | 35 |
| 35 // The action that should be taken as a result of clicking a browser action. | |
| 36 enum Action { | |
| 37 ACTION_NONE, | |
| 38 ACTION_SHOW_POPUP, | |
| 39 // Unlike LocationBarController there is no ACTION_SHOW_CONTEXT_MENU, | |
| 40 // because UI implementations tend to handle this themselves at a higher | |
| 41 // level. | |
| 42 }; | |
| 43 | |
| 44 // A class which is informed of changes to the model; represents the view of | 36 // A class which is informed of changes to the model; represents the view of |
| 45 // MVC. Also used for signaling view changes such as showing extension popups. | 37 // MVC. Also used for signaling view changes such as showing extension popups. |
| 46 class Observer { | 38 class Observer { |
| 47 public: | 39 public: |
| 48 // An extension with a browser action button has been added, and should go | 40 // An extension with a browser action button has been added, and should go |
| 49 // in the toolbar at |index|. | 41 // in the toolbar at |index|. |
| 50 virtual void BrowserActionAdded(const Extension* extension, int index) {} | 42 virtual void BrowserActionAdded(const Extension* extension, int index) {} |
| 51 | 43 |
| 52 // The browser action button for |extension| should no longer show. | 44 // The browser action button for |extension| should no longer show. |
| 53 virtual void BrowserActionRemoved(const Extension* extension) {} | 45 virtual void BrowserActionRemoved(const Extension* extension) {} |
| (...skipping 29 matching lines...) Expand all Loading... |
| 83 void AddObserver(Observer* observer); | 75 void AddObserver(Observer* observer); |
| 84 void RemoveObserver(Observer* observer); | 76 void RemoveObserver(Observer* observer); |
| 85 void MoveBrowserAction(const Extension* extension, int index); | 77 void MoveBrowserAction(const Extension* extension, int index); |
| 86 // Executes the browser action for an extension and returns the action that | 78 // Executes the browser action for an extension and returns the action that |
| 87 // the UI should perform in response. | 79 // the UI should perform in response. |
| 88 // |popup_url_out| will be set if the extension should show a popup, with | 80 // |popup_url_out| will be set if the extension should show a popup, with |
| 89 // the URL that should be shown, if non-NULL. |should_grant| controls whether | 81 // the URL that should be shown, if non-NULL. |should_grant| controls whether |
| 90 // the extension should be granted page tab permissions, which is what happens | 82 // the extension should be granted page tab permissions, which is what happens |
| 91 // when the user clicks the browser action, but not, for example, when the | 83 // when the user clicks the browser action, but not, for example, when the |
| 92 // showPopup API is called. | 84 // showPopup API is called. |
| 93 Action ExecuteBrowserAction(const Extension* extension, | 85 ExtensionAction::ShowAction ExecuteBrowserAction(const Extension* extension, |
| 94 Browser* browser, | 86 Browser* browser, |
| 95 GURL* popup_url_out, | 87 GURL* popup_url_out, |
| 96 bool should_grant); | 88 bool should_grant); |
| 97 // If count == size(), this will set the visible icon count to -1, meaning | 89 // If count == size(), this will set the visible icon count to -1, meaning |
| 98 // "show all actions". | 90 // "show all actions". |
| 99 void SetVisibleIconCount(int count); | 91 void SetVisibleIconCount(int count); |
| 100 // As above, a return value of -1 represents "show all actions". | 92 // As above, a return value of -1 represents "show all actions". |
| 101 int GetVisibleIconCount() const { return visible_icon_count_; } | 93 int GetVisibleIconCount() const { return visible_icon_count_; } |
| 102 | 94 |
| 103 bool extensions_initialized() const { return extensions_initialized_; } | 95 bool extensions_initialized() const { return extensions_initialized_; } |
| 104 | 96 |
| 105 const ExtensionList& toolbar_items() const { | 97 const ExtensionList& toolbar_items() const { |
| 106 return is_highlighting_ ? highlighted_items_ : toolbar_items_; | 98 return is_highlighting_ ? highlighted_items_ : toolbar_items_; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 base::Closure pref_change_callback_; | 209 base::Closure pref_change_callback_; |
| 218 | 210 |
| 219 base::WeakPtrFactory<ExtensionToolbarModel> weak_ptr_factory_; | 211 base::WeakPtrFactory<ExtensionToolbarModel> weak_ptr_factory_; |
| 220 | 212 |
| 221 DISALLOW_COPY_AND_ASSIGN(ExtensionToolbarModel); | 213 DISALLOW_COPY_AND_ASSIGN(ExtensionToolbarModel); |
| 222 }; | 214 }; |
| 223 | 215 |
| 224 } // namespace extensions | 216 } // namespace extensions |
| 225 | 217 |
| 226 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ | 218 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ |
| OLD | NEW |