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

Side by Side Diff: chrome/browser/ui/extensions/extension_action_view_controller.h

Issue 1168383002: Implement sidebar support for extension action popups Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_UI_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_H_ 6 #define CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_H_
7 7
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/scoped_observer.h" 9 #include "base/scoped_observer.h"
10 #include "chrome/browser/extensions/extension_action_icon_factory.h" 10 #include "chrome/browser/extensions/extension_action_icon_factory.h"
11 #include "chrome/browser/extensions/extension_context_menu_model.h" 11 #include "chrome/browser/extensions/extension_context_menu_model.h"
12 #include "chrome/browser/extensions/sidebar_container.h"
12 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" 13 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
13 #include "extensions/browser/extension_host_observer.h" 14 #include "extensions/browser/extension_host_observer.h"
14 #include "ui/gfx/image/image.h" 15 #include "ui/gfx/image/image.h"
15 16
16 class Browser; 17 class Browser;
17 class ExtensionAction; 18 class ExtensionAction;
18 class ExtensionActionPlatformDelegate; 19 class ExtensionActionPlatformDelegate;
19 class GURL; 20 class GURL;
20 class ToolbarActionsBar; 21 class ToolbarActionsBar;
21 22
(...skipping 30 matching lines...) Expand all
52 gfx::Image GetIcon(content::WebContents* web_contents) override; 53 gfx::Image GetIcon(content::WebContents* web_contents) override;
53 gfx::ImageSkia GetIconWithBadge() override; 54 gfx::ImageSkia GetIconWithBadge() override;
54 base::string16 GetActionName() const override; 55 base::string16 GetActionName() const override;
55 base::string16 GetAccessibleName(content::WebContents* web_contents) const 56 base::string16 GetAccessibleName(content::WebContents* web_contents) const
56 override; 57 override;
57 base::string16 GetTooltip(content::WebContents* web_contents) const override; 58 base::string16 GetTooltip(content::WebContents* web_contents) const override;
58 bool IsEnabled(content::WebContents* web_contents) const override; 59 bool IsEnabled(content::WebContents* web_contents) const override;
59 bool WantsToRun(content::WebContents* web_contents) const override; 60 bool WantsToRun(content::WebContents* web_contents) const override;
60 bool HasPopup(content::WebContents* web_contents) const override; 61 bool HasPopup(content::WebContents* web_contents) const override;
61 void HidePopup() override; 62 void HidePopup() override;
63 void HideSidebar() override;
62 gfx::NativeView GetPopupNativeView() override; 64 gfx::NativeView GetPopupNativeView() override;
63 ui::MenuModel* GetContextMenu() override; 65 ui::MenuModel* GetContextMenu() override;
64 void OnContextMenuClosed() override; 66 void OnContextMenuClosed() override;
65 bool CanDrag() const override; 67 bool CanDrag() const override;
66 bool ExecuteAction(bool by_user) override; 68 bool ExecuteAction(bool by_user) override;
67 void UpdateState() override; 69 void UpdateState() override;
68 void PaintExtra(gfx::Canvas* canvas, 70 void PaintExtra(gfx::Canvas* canvas,
69 const gfx::Rect& bounds, 71 const gfx::Rect& bounds,
70 content::WebContents* web_contents) const override; 72 content::WebContents* web_contents) const override;
71 void RegisterCommand() override; 73 void RegisterCommand() override;
72 74
73 // ExtensionContextMenuModel::PopupDelegate: 75 // ExtensionContextMenuModel::PopupDelegate:
74 void InspectPopup() override; 76 void InspectPopup() override;
75 77
76 // Closes the active popup (whether it was this action's popup or not). 78 // Closes the active popup (whether it was this action's popup or not).
77 void HideActivePopup(); 79 void HideActivePopup();
78 80
81 // Closes the active sidebar.
82 void HideActiveSidebar();
79 83
80 // Populates |command| with the command associated with |extension|, if one 84 // Populates |command| with the command associated with |extension|, if one
81 // exists. Returns true if |command| was populated. 85 // exists. Returns true if |command| was populated.
82 bool GetExtensionCommand(extensions::Command* command); 86 bool GetExtensionCommand(extensions::Command* command);
83 87
84 const extensions::Extension* extension() const { return extension_.get(); } 88 const extensions::Extension* extension() const { return extension_.get(); }
85 Browser* browser() { return browser_; } 89 Browser* browser() { return browser_; }
86 ExtensionAction* extension_action() { return extension_action_; } 90 ExtensionAction* extension_action() { return extension_action_; }
87 const ExtensionAction* extension_action() const { return extension_action_; } 91 const ExtensionAction* extension_action() const { return extension_action_; }
88 ToolbarActionViewDelegate* view_delegate() { return view_delegate_; } 92 ToolbarActionViewDelegate* view_delegate() { return view_delegate_; }
89 bool is_showing_popup() const { return popup_host_ != nullptr; } 93 bool is_showing_popup() const { return popup_host_ != nullptr; }
94 bool is_showing_sidebar() const { return sidebar_container_ != nullptr; }
90 95
91 void set_icon_observer(ExtensionActionIconFactory::Observer* icon_observer) { 96 void set_icon_observer(ExtensionActionIconFactory::Observer* icon_observer) {
92 icon_observer_ = icon_observer; 97 icon_observer_ = icon_observer;
93 } 98 }
94 99
95 private: 100 private:
101 // Update button state to be pressed
102 void PressButton(bool grant_tab_permissions);
103 void PressButtonWithSlideOutIfEnabled(const base::Closure& closure);
104
105 // Update button state to be unpressed
106 void RaiseButton();
107
96 // ExtensionActionIconFactory::Observer: 108 // ExtensionActionIconFactory::Observer:
97 void OnIconUpdated() override; 109 void OnIconUpdated() override;
98 110
99 // ExtensionHostObserver: 111 // ExtensionHostObserver:
100 void OnExtensionHostDestroyed(const extensions::ExtensionHost* host) override; 112 void OnExtensionHostDestroyed(const extensions::ExtensionHost* host) override;
101 113
102 // Checks if the associated |extension| is still valid by checking its 114 // Checks if the associated |extension| is still valid by checking its
103 // status in the registry. Since the OnExtensionUnloaded() notifications are 115 // status in the registry. Since the OnExtensionUnloaded() notifications are
104 // not in a deterministic order, it's possible that the view tries to refresh 116 // not in a deterministic order, it's possible that the view tries to refresh
105 // itself before we're notified to remove it. 117 // itself before we're notified to remove it.
(...skipping 14 matching lines...) Expand all
120 // associated |popup_url|. |grant_tab_permissions| is true if active tab 132 // associated |popup_url|. |grant_tab_permissions| is true if active tab
121 // permissions should be given to the extension; this is only true if the 133 // permissions should be given to the extension; this is only true if the
122 // popup is opened through a user action. 134 // popup is opened through a user action.
123 // The popup may not be shown synchronously if the extension is hidden and 135 // The popup may not be shown synchronously if the extension is hidden and
124 // first needs to slide itself out. 136 // first needs to slide itself out.
125 // Returns true if a popup will be shown. 137 // Returns true if a popup will be shown.
126 bool TriggerPopupWithUrl(PopupShowAction show_action, 138 bool TriggerPopupWithUrl(PopupShowAction show_action,
127 const GURL& popup_url, 139 const GURL& popup_url,
128 bool grant_tab_permissions); 140 bool grant_tab_permissions);
129 141
142 // Begins the process of showing the sidebar for the extension action,
143 // given the associated |popup_url|.
144 // The sidebar may not be shown synchronously if the extension is hidden and
145 // first needs to slide itself out.
146 // Returns true if a sidebar will be shown.
147 bool TriggerSidebarWithUrl(const GURL& popup_url);
148
130 // Shows the popup with the given |host|. 149 // Shows the popup with the given |host|.
131 void ShowPopup(scoped_ptr<extensions::ExtensionViewHost> host, 150 void ShowPopup(scoped_ptr<extensions::ExtensionViewHost> host,
132 bool grant_tab_permissions, 151 bool grant_tab_permissions,
133 PopupShowAction show_action); 152 PopupShowAction show_action);
134 153
135 // Handles cleanup after the popup closes. 154 // Handles cleanup after the popup closes.
136 void OnPopupClosed(); 155 void OnPopupClosed();
137 156
138 // The extension associated with the action we're displaying. 157 // The extension associated with the action we're displaying.
139 scoped_refptr<const extensions::Extension> extension_; 158 scoped_refptr<const extensions::Extension> extension_;
140 159
141 // The corresponding browser. 160 // The corresponding browser.
142 Browser* browser_; 161 Browser* browser_;
143 162
144 // The browser action this view represents. The ExtensionAction is not owned 163 // The browser action this view represents. The ExtensionAction is not owned
145 // by this class. 164 // by this class.
146 ExtensionAction* extension_action_; 165 ExtensionAction* extension_action_;
147 166
148 // The owning ToolbarActionsBar, if any. This will be null if this is a 167 // The owning ToolbarActionsBar, if any. This will be null if this is a
149 // page action without the toolbar redesign turned on. 168 // page action without the toolbar redesign turned on.
150 // TODO(devlin): Would this be better behind a delegate interface? On the one 169 // TODO(devlin): Would this be better behind a delegate interface? On the one
151 // hand, it's odd for this class to know about ToolbarActionsBar, but on the 170 // hand, it's odd for this class to know about ToolbarActionsBar, but on the
152 // other, yet-another-delegate-class might just confuse things. 171 // other, yet-another-delegate-class might just confuse things.
153 ToolbarActionsBar* toolbar_actions_bar_; 172 ToolbarActionsBar* toolbar_actions_bar_;
154 173
155 // The extension popup's host if the popup is visible; null otherwise. 174 // The extension popup's host if the popup is visible; null otherwise.
156 extensions::ExtensionViewHost* popup_host_; 175 extensions::ExtensionViewHost* popup_host_;
157 176
177 // The sidebar container if the sidebar is visible.
178 scoped_ptr<extensions::SidebarContainer> sidebar_container_;
179
158 // The context menu model for the extension. 180 // The context menu model for the extension.
159 scoped_refptr<ExtensionContextMenuModel> context_menu_model_; 181 scoped_refptr<ExtensionContextMenuModel> context_menu_model_;
160 182
161 // Our view delegate. 183 // Our view delegate.
162 ToolbarActionViewDelegate* view_delegate_; 184 ToolbarActionViewDelegate* view_delegate_;
163 185
164 // The delegate to handle platform-specific implementations. 186 // The delegate to handle platform-specific implementations.
165 scoped_ptr<ExtensionActionPlatformDelegate> platform_delegate_; 187 scoped_ptr<ExtensionActionPlatformDelegate> platform_delegate_;
166 188
167 // The object that will be used to get the browser action icon for us. 189 // The object that will be used to get the browser action icon for us.
(...skipping 11 matching lines...) Expand all
179 201
180 ScopedObserver<extensions::ExtensionHost, extensions::ExtensionHostObserver> 202 ScopedObserver<extensions::ExtensionHost, extensions::ExtensionHostObserver>
181 popup_host_observer_; 203 popup_host_observer_;
182 204
183 base::WeakPtrFactory<ExtensionActionViewController> weak_factory_; 205 base::WeakPtrFactory<ExtensionActionViewController> weak_factory_;
184 206
185 DISALLOW_COPY_AND_ASSIGN(ExtensionActionViewController); 207 DISALLOW_COPY_AND_ASSIGN(ExtensionActionViewController);
186 }; 208 };
187 209
188 #endif // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_H_ 210 #endif // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698