Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(821)

Side by Side Diff: chrome/browser/extensions/extension_toolbar_model.h

Issue 25305002: Implement initial chrome.browserAction.openPopup API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move to interactive_ui_test Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 15 matching lines...) Expand all
26 // The action that should be taken as a result of clicking a browser action. 26 // The action that should be taken as a result of clicking a browser action.
27 enum Action { 27 enum Action {
28 ACTION_NONE, 28 ACTION_NONE,
29 ACTION_SHOW_POPUP, 29 ACTION_SHOW_POPUP,
30 // Unlike LocationBarController there is no ACTION_SHOW_CONTEXT_MENU, 30 // Unlike LocationBarController there is no ACTION_SHOW_CONTEXT_MENU,
31 // because UI implementations tend to handle this themselves at a higher 31 // because UI implementations tend to handle this themselves at a higher
32 // level. 32 // level.
33 }; 33 };
34 34
35 // A class which is informed of changes to the model; represents the view of 35 // A class which is informed of changes to the model; represents the view of
36 // MVC. 36 // MVC. Also used for signaling view changes such as showing extension popups.
37 class Observer { 37 class Observer {
38 public: 38 public:
39 // An extension with a browser action button has been added, and should go 39 // An extension with a browser action button has been added, and should go
40 // in the toolbar at |index|. 40 // in the toolbar at |index|.
41 virtual void BrowserActionAdded(const extensions::Extension* extension, 41 virtual void BrowserActionAdded(const extensions::Extension* extension,
42 int index) {} 42 int index) {}
43 43
44 // The browser action button for |extension| should no longer show. 44 // The browser action button for |extension| should no longer show.
45 virtual void BrowserActionRemoved(const extensions::Extension* extension) {} 45 virtual void BrowserActionRemoved(const extensions::Extension* extension) {}
46 46
47 // The browser action button for |extension| has been moved to |index|. 47 // The browser action button for |extension| has been moved to |index|.
48 virtual void BrowserActionMoved(const extensions::Extension* extension, 48 virtual void BrowserActionMoved(const extensions::Extension* extension,
49 int index) {} 49 int index) {}
50 50
51 // Signal the |extension| to show the popup now in the active window.
52 // Returns true if a popup was slated to be shown.
53 virtual bool BrowserActionShowPopup(const extensions::Extension* extension);
54
51 // Called when the model has finished loading. 55 // Called when the model has finished loading.
52 virtual void ModelLoaded() {} 56 virtual void ModelLoaded() {}
53 57
54 protected: 58 protected:
55 virtual ~Observer() {} 59 virtual ~Observer() {}
56 }; 60 };
57 61
58 // Functions called by the view. 62 // Functions called by the view.
59 void AddObserver(Observer* observer); 63 void AddObserver(Observer* observer);
60 void RemoveObserver(Observer* observer); 64 void RemoveObserver(Observer* observer);
61 void MoveBrowserAction(const extensions::Extension* extension, int index); 65 void MoveBrowserAction(const extensions::Extension* extension, int index);
62 // Executes the browser action for an extension and returns the action that 66 // Executes the browser action for an extension and returns the action that
63 // the UI should perform in response. 67 // the UI should perform in response.
64 // |popup_url_out| will be set if the extension should show a popup, with 68 // |popup_url_out| will be set if the extension should show a popup, with
65 // the URL that should be shown, if non-NULL. 69 // 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
71 // when the user clicks the browser action, but not, for example, when the
72 // showPopup API is called.
66 Action ExecuteBrowserAction(const extensions::Extension* extension, 73 Action ExecuteBrowserAction(const extensions::Extension* extension,
67 Browser* browser, 74 Browser* browser,
68 GURL* popup_url_out); 75 GURL* popup_url_out,
76 bool should_grant);
69 // If count == size(), this will set the visible icon count to -1, meaning 77 // If count == size(), this will set the visible icon count to -1, meaning
70 // "show all actions". 78 // "show all actions".
71 void SetVisibleIconCount(int count); 79 void SetVisibleIconCount(int count);
72 // As above, a return value of -1 represents "show all actions". 80 // As above, a return value of -1 represents "show all actions".
73 int GetVisibleIconCount() const { return visible_icon_count_; } 81 int GetVisibleIconCount() const { return visible_icon_count_; }
74 82
75 bool extensions_initialized() const { return extensions_initialized_; } 83 bool extensions_initialized() const { return extensions_initialized_; }
76 84
77 const extensions::ExtensionList& toolbar_items() const { 85 const extensions::ExtensionList& toolbar_items() const {
78 return toolbar_items_; 86 return toolbar_items_;
79 } 87 }
80 88
81 // Utility functions for converting between an index into the list of 89 // Utility functions for converting between an index into the list of
82 // incognito-enabled browser actions, and the list of all browser actions. 90 // incognito-enabled browser actions, and the list of all browser actions.
83 int IncognitoIndexToOriginal(int incognito_index); 91 int IncognitoIndexToOriginal(int incognito_index);
84 int OriginalIndexToIncognito(int original_index); 92 int OriginalIndexToIncognito(int original_index);
85 93
86 void OnExtensionToolbarPrefChange(); 94 void OnExtensionToolbarPrefChange();
87 95
96 // Tells observers to display a popup without granting tab permissions and
97 // returns whether the popup was slated to be shown.
98 bool ShowBrowserActionPopup(const extensions::Extension* extension);
99
88 private: 100 private:
89 // content::NotificationObserver implementation. 101 // content::NotificationObserver implementation.
90 virtual void Observe(int type, 102 virtual void Observe(int type,
91 const content::NotificationSource& source, 103 const content::NotificationSource& source,
92 const content::NotificationDetails& details) OVERRIDE; 104 const content::NotificationDetails& details) OVERRIDE;
93 105
94 // To be called after the extension service is ready; gets loaded extensions 106 // To be called after the extension service is ready; gets loaded extensions
95 // from the extension service and their saved order from the pref service 107 // from the extension service and their saved order from the pref service
96 // and constructs |toolbar_items_| from these data. 108 // and constructs |toolbar_items_| from these data.
97 void InitializeExtensionList(); 109 void InitializeExtensionList();
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 // For observing change of toolbar order preference by external entity (sync). 149 // For observing change of toolbar order preference by external entity (sync).
138 PrefChangeRegistrar pref_change_registrar_; 150 PrefChangeRegistrar pref_change_registrar_;
139 base::Closure pref_change_callback_; 151 base::Closure pref_change_callback_;
140 152
141 base::WeakPtrFactory<ExtensionToolbarModel> weak_ptr_factory_; 153 base::WeakPtrFactory<ExtensionToolbarModel> weak_ptr_factory_;
142 154
143 DISALLOW_COPY_AND_ASSIGN(ExtensionToolbarModel); 155 DISALLOW_COPY_AND_ASSIGN(ExtensionToolbarModel);
144 }; 156 };
145 157
146 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_ 158 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_TOOLBAR_MODEL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698