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" |
11 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
12 #include "content/public/browser/notification_observer.h" | 12 #include "content/public/browser/notification_observer.h" |
13 #include "content/public/browser/notification_registrar.h" | 13 #include "content/public/browser/notification_registrar.h" |
14 | 14 |
15 class Browser; | 15 class Browser; |
16 class ExtensionService; | 16 class ExtensionService; |
17 class PrefService; | 17 class PrefService; |
18 | 18 |
19 // Model for the browser actions toolbar. | 19 // Model for the browser actions toolbar. |
20 class ExtensionToolbarModel : public content::NotificationObserver { | 20 class ExtensionToolbarModel : public content::NotificationObserver { |
21 public: | 21 public: |
22 explicit ExtensionToolbarModel(ExtensionService* service); | 22 explicit ExtensionToolbarModel(ExtensionService* service); |
23 virtual ~ExtensionToolbarModel(); | 23 virtual ~ExtensionToolbarModel(); |
24 | 24 |
25 // The action that should be taken as a result of clicking a browser action. | |
26 enum Action { | |
27 ACTION_NONE, | |
28 ACTION_SHOW_POPUP, | |
29 // Unlike ActionBoxController there is no ACTION_SHOW_CONTEXT_MENU, because | |
30 // UI implementations tend to handle this themselves at a higher level. | |
31 }; | |
32 | |
25 // A class which is informed of changes to the model; represents the view of | 33 // A class which is informed of changes to the model; represents the view of |
26 // MVC. | 34 // MVC. |
27 class Observer { | 35 class Observer { |
28 public: | 36 public: |
29 // An extension with a browser action button has been added, and should go | 37 // An extension with a browser action button has been added, and should go |
30 // in the toolbar at |index|. | 38 // in the toolbar at |index|. |
31 virtual void BrowserActionAdded(const extensions::Extension* extension, | 39 virtual void BrowserActionAdded(const extensions::Extension* extension, |
32 int index) {} | 40 int index) {} |
33 | 41 |
34 // The browser action button for |extension| should no longer show. | 42 // The browser action button for |extension| should no longer show. |
35 virtual void BrowserActionRemoved(const extensions::Extension* extension) {} | 43 virtual void BrowserActionRemoved(const extensions::Extension* extension) {} |
36 | 44 |
37 // The browser action button for |extension| has been moved to |index|. | 45 // The browser action button for |extension| has been moved to |index|. |
38 virtual void BrowserActionMoved(const extensions::Extension* extension, | 46 virtual void BrowserActionMoved(const extensions::Extension* extension, |
39 int index) {} | 47 int index) {} |
40 | 48 |
41 // The browser action button for |extension_id| (which was not a popup) was | |
42 // clicked, executing it. | |
43 virtual void BrowserActionExecuted(const std::string& extension_id, | |
44 Browser* browser) {} | |
45 | |
46 // Called when the model has finished loading. | 49 // Called when the model has finished loading. |
47 virtual void ModelLoaded() {} | 50 virtual void ModelLoaded() {} |
48 | 51 |
49 protected: | 52 protected: |
50 virtual ~Observer() {} | 53 virtual ~Observer() {} |
51 }; | 54 }; |
52 | 55 |
53 // Functions called by the view. | 56 // Functions called by the view. |
54 void AddObserver(Observer* observer); | 57 void AddObserver(Observer* observer); |
55 void RemoveObserver(Observer* observer); | 58 void RemoveObserver(Observer* observer); |
56 void MoveBrowserAction(const extensions::Extension* extension, int index); | 59 void MoveBrowserAction(const extensions::Extension* extension, int index); |
57 void ExecuteBrowserAction(const std::string& extension_id, Browser* browser); | 60 // Executes the browser action for an extension and returns the action that |
61 // the UI should perform in response. | |
62 // |popup_url_out| will be set if the extension should show a popup, with | |
63 // the URL that should be shown, if non-NULL. | |
64 Action ExecuteBrowserAction(const extensions::Extension* extension, | |
65 Browser* browser, | |
66 GURL* popup_url_out); | |
58 // 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 |
59 // "show all actions". | 68 // "show all actions". |
60 void SetVisibleIconCount(int count); | 69 void SetVisibleIconCount(int count); |
61 // As above, a return value of -1 represents "show all actions". | 70 // As above, a return value of -1 represents "show all actions". |
62 int GetVisibleIconCount() { return visible_icon_count_; } | 71 int GetVisibleIconCount() { return visible_icon_count_; } |
tfarina
2012/05/24 18:44:55
nit: make this function const.
not at google - send to devlin
2012/05/25 00:55:40
Done.
| |
63 | 72 |
64 bool extensions_initialized() const { return extensions_initialized_; } | 73 bool extensions_initialized() const { return extensions_initialized_; } |
65 | 74 |
66 size_t size() const { | 75 size_t size() const { |
67 return toolitems_.size(); | 76 return toolitems_.size(); |
68 } | 77 } |
69 | 78 |
70 extensions::ExtensionList::iterator begin() { | 79 extensions::ExtensionList::iterator begin() { |
71 return toolitems_.begin(); | 80 return toolitems_.begin(); |
72 } | 81 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 std::string last_extension_removed_; | 126 std::string last_extension_removed_; |
118 | 127 |
119 // Keeps track of where the last extension to get disabled was in the list. | 128 // Keeps track of where the last extension to get disabled was in the list. |
120 size_t last_extension_removed_index_; | 129 size_t last_extension_removed_index_; |
121 | 130 |
122 // The number of icons visible (the rest should be hidden in the overflow | 131 // The number of icons visible (the rest should be hidden in the overflow |
123 // chevron). | 132 // chevron). |
124 int visible_icon_count_; | 133 int visible_icon_count_; |
125 | 134 |
126 content::NotificationRegistrar registrar_; | 135 content::NotificationRegistrar registrar_; |
127 }; | 136 }; |
tfarina
2012/05/24 18:44:55
nit: if we don't want copy and assign semantics, p
not at google - send to devlin
2012/05/25 00:55:40
Done.
| |
128 | 137 |
129 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ | 138 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ |
OLD | NEW |