OLD | NEW |
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" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 gfx::Image GetIcon(content::WebContents* web_contents, | 53 gfx::Image GetIcon(content::WebContents* web_contents, |
54 const gfx::Size& size) override; | 54 const gfx::Size& size) override; |
55 base::string16 GetActionName() const override; | 55 base::string16 GetActionName() const override; |
56 base::string16 GetAccessibleName(content::WebContents* web_contents) const | 56 base::string16 GetAccessibleName(content::WebContents* web_contents) const |
57 override; | 57 override; |
58 base::string16 GetTooltip(content::WebContents* web_contents) const override; | 58 base::string16 GetTooltip(content::WebContents* web_contents) const override; |
59 bool IsEnabled(content::WebContents* web_contents) const override; | 59 bool IsEnabled(content::WebContents* web_contents) const override; |
60 bool WantsToRun(content::WebContents* web_contents) const override; | 60 bool WantsToRun(content::WebContents* web_contents) const override; |
61 bool HasPopup(content::WebContents* web_contents) const override; | 61 bool HasPopup(content::WebContents* web_contents) const override; |
62 void HidePopup() override; | 62 void HidePopup() override; |
| 63 void HideSidebar() override; |
63 gfx::NativeView GetPopupNativeView() override; | 64 gfx::NativeView GetPopupNativeView() override; |
64 ui::MenuModel* GetContextMenu() override; | 65 ui::MenuModel* GetContextMenu() override; |
65 void OnContextMenuClosed() override; | 66 void OnContextMenuClosed() override; |
66 bool ExecuteAction(bool by_user) override; | 67 bool ExecuteAction(bool by_user) override; |
67 void UpdateState() override; | 68 void UpdateState() override; |
68 void RegisterCommand() override; | 69 void RegisterCommand() override; |
69 bool DisabledClickOpensMenu() const override; | 70 bool DisabledClickOpensMenu() const override; |
70 | 71 |
71 // ExtensionContextMenuModel::PopupDelegate: | 72 // ExtensionContextMenuModel::PopupDelegate: |
72 void InspectPopup() override; | 73 void InspectPopup() override; |
73 | 74 |
74 // Closes the active popup (whether it was this action's popup or not). | 75 // Closes the active popup (whether it was this action's popup or not). |
75 void HideActivePopup(); | 76 void HideActivePopup(); |
76 | 77 |
| 78 // Closes the active sidebar. |
| 79 void HideActiveSidebar(); |
| 80 |
77 // Populates |command| with the command associated with |extension|, if one | 81 // Populates |command| with the command associated with |extension|, if one |
78 // exists. Returns true if |command| was populated. | 82 // exists. Returns true if |command| was populated. |
79 bool GetExtensionCommand(extensions::Command* command); | 83 bool GetExtensionCommand(extensions::Command* command); |
80 | 84 |
81 const extensions::Extension* extension() const { return extension_.get(); } | 85 const extensions::Extension* extension() const { return extension_.get(); } |
82 Browser* browser() { return browser_; } | 86 Browser* browser() { return browser_; } |
83 ExtensionAction* extension_action() { return extension_action_; } | 87 ExtensionAction* extension_action() { return extension_action_; } |
84 const ExtensionAction* extension_action() const { return extension_action_; } | 88 const ExtensionAction* extension_action() const { return extension_action_; } |
85 ToolbarActionViewDelegate* view_delegate() { return view_delegate_; } | 89 ToolbarActionViewDelegate* view_delegate() { return view_delegate_; } |
86 bool is_showing_popup() const { return popup_host_ != nullptr; } | 90 bool is_showing_popup() const { return popup_host_ != nullptr; } |
| 91 bool is_showing_sidebar() const { return sidebar_host_; } |
87 | 92 |
88 void set_icon_observer(ExtensionActionIconFactory::Observer* icon_observer) { | 93 void set_icon_observer(ExtensionActionIconFactory::Observer* icon_observer) { |
89 icon_observer_ = icon_observer; | 94 icon_observer_ = icon_observer; |
90 } | 95 } |
91 | 96 |
92 scoped_ptr<IconWithBadgeImageSource> GetIconImageSourceForTesting( | 97 scoped_ptr<IconWithBadgeImageSource> GetIconImageSourceForTesting( |
93 content::WebContents* web_contents, | 98 content::WebContents* web_contents, |
94 const gfx::Size& size); | 99 const gfx::Size& size); |
95 | 100 |
96 private: | 101 private: |
| 102 // Update button state to be pressed |
| 103 void PressButton(bool grant_tab_permissions); |
| 104 void PressButtonWithSlideOutIfEnabled(const base::Closure& closure); |
| 105 |
| 106 // Update button state to be unpressed |
| 107 void RaiseButton(); |
| 108 |
97 // ExtensionActionIconFactory::Observer: | 109 // ExtensionActionIconFactory::Observer: |
98 void OnIconUpdated() override; | 110 void OnIconUpdated() override; |
99 | 111 |
100 // ExtensionHostObserver: | 112 // ExtensionHostObserver: |
101 void OnExtensionHostDestroyed(const extensions::ExtensionHost* host) override; | 113 void OnExtensionHostDestroyed(const extensions::ExtensionHost* host) override; |
102 | 114 |
103 // Checks if the associated |extension| is still valid by checking its | 115 // Checks if the associated |extension| is still valid by checking its |
104 // status in the registry. Since the OnExtensionUnloaded() notifications are | 116 // status in the registry. Since the OnExtensionUnloaded() notifications are |
105 // not in a deterministic order, it's possible that the view tries to refresh | 117 // not in a deterministic order, it's possible that the view tries to refresh |
106 // itself before we're notified to remove it. | 118 // itself before we're notified to remove it. |
(...skipping 14 matching lines...) Expand all Loading... |
121 // associated |popup_url|. |grant_tab_permissions| is true if active tab | 133 // associated |popup_url|. |grant_tab_permissions| is true if active tab |
122 // permissions should be given to the extension; this is only true if the | 134 // permissions should be given to the extension; this is only true if the |
123 // popup is opened through a user action. | 135 // popup is opened through a user action. |
124 // The popup may not be shown synchronously if the extension is hidden and | 136 // The popup may not be shown synchronously if the extension is hidden and |
125 // first needs to slide itself out. | 137 // first needs to slide itself out. |
126 // Returns true if a popup will be shown. | 138 // Returns true if a popup will be shown. |
127 bool TriggerPopupWithUrl(PopupShowAction show_action, | 139 bool TriggerPopupWithUrl(PopupShowAction show_action, |
128 const GURL& popup_url, | 140 const GURL& popup_url, |
129 bool grant_tab_permissions); | 141 bool grant_tab_permissions); |
130 | 142 |
| 143 // Begins the process of showing the sidebar for the extension action, |
| 144 // given the associated |popup_url|. |
| 145 // The sidebar may not be shown synchronously if the extension is hidden and |
| 146 // first needs to slide itself out. |
| 147 // Returns true if a sidebar will be shown. |
| 148 bool TriggerSidebarWithUrl(const GURL& popup_url); |
| 149 |
131 // Shows the popup with the given |host|. | 150 // Shows the popup with the given |host|. |
132 void ShowPopup(scoped_ptr<extensions::ExtensionViewHost> host, | 151 void ShowPopup(scoped_ptr<extensions::ExtensionViewHost> host, |
133 bool grant_tab_permissions, | 152 bool grant_tab_permissions, |
134 PopupShowAction show_action); | 153 PopupShowAction show_action); |
135 | 154 |
136 // Handles cleanup after the popup closes. | 155 // Handles cleanup after the popup closes. |
137 void OnPopupClosed(); | 156 void OnPopupClosed(); |
138 | 157 |
139 // Returns the image source for the icon. | 158 // Returns the image source for the icon. |
140 scoped_ptr<IconWithBadgeImageSource> GetIconImageSource( | 159 scoped_ptr<IconWithBadgeImageSource> GetIconImageSource( |
(...skipping 13 matching lines...) Expand all Loading... |
154 // The owning ToolbarActionsBar, if any. This will be null if this is a | 173 // The owning ToolbarActionsBar, if any. This will be null if this is a |
155 // page action without the toolbar redesign turned on. | 174 // page action without the toolbar redesign turned on. |
156 // TODO(devlin): Would this be better behind a delegate interface? On the one | 175 // TODO(devlin): Would this be better behind a delegate interface? On the one |
157 // hand, it's odd for this class to know about ToolbarActionsBar, but on the | 176 // hand, it's odd for this class to know about ToolbarActionsBar, but on the |
158 // other, yet-another-delegate-class might just confuse things. | 177 // other, yet-another-delegate-class might just confuse things. |
159 ToolbarActionsBar* toolbar_actions_bar_; | 178 ToolbarActionsBar* toolbar_actions_bar_; |
160 | 179 |
161 // The extension popup's host if the popup is visible; null otherwise. | 180 // The extension popup's host if the popup is visible; null otherwise. |
162 extensions::ExtensionViewHost* popup_host_; | 181 extensions::ExtensionViewHost* popup_host_; |
163 | 182 |
| 183 // The extension sidebar's host if the sidebar is visible; null otherwise. |
| 184 scoped_ptr<extensions::ExtensionViewHost> sidebar_host_; |
| 185 |
164 // The context menu model for the extension. | 186 // The context menu model for the extension. |
165 scoped_refptr<ExtensionContextMenuModel> context_menu_model_; | 187 scoped_refptr<ExtensionContextMenuModel> context_menu_model_; |
166 | 188 |
167 // Our view delegate. | 189 // Our view delegate. |
168 ToolbarActionViewDelegate* view_delegate_; | 190 ToolbarActionViewDelegate* view_delegate_; |
169 | 191 |
170 // The delegate to handle platform-specific implementations. | 192 // The delegate to handle platform-specific implementations. |
171 scoped_ptr<ExtensionActionPlatformDelegate> platform_delegate_; | 193 scoped_ptr<ExtensionActionPlatformDelegate> platform_delegate_; |
172 | 194 |
173 // The object that will be used to get the browser action icon for us. | 195 // The object that will be used to get the browser action icon for us. |
(...skipping 11 matching lines...) Expand all Loading... |
185 | 207 |
186 ScopedObserver<extensions::ExtensionHost, extensions::ExtensionHostObserver> | 208 ScopedObserver<extensions::ExtensionHost, extensions::ExtensionHostObserver> |
187 popup_host_observer_; | 209 popup_host_observer_; |
188 | 210 |
189 base::WeakPtrFactory<ExtensionActionViewController> weak_factory_; | 211 base::WeakPtrFactory<ExtensionActionViewController> weak_factory_; |
190 | 212 |
191 DISALLOW_COPY_AND_ASSIGN(ExtensionActionViewController); | 213 DISALLOW_COPY_AND_ASSIGN(ExtensionActionViewController); |
192 }; | 214 }; |
193 | 215 |
194 #endif // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_H_ | 216 #endif // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_H_ |
OLD | NEW |