| 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" |
| 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_manager_observer.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 |
| 22 namespace extensions { | 23 namespace extensions { |
| 23 class Command; | 24 class Command; |
| 24 class Extension; | 25 class Extension; |
| 25 class ExtensionRegistry; | 26 class ExtensionRegistry; |
| 26 class ExtensionViewHost; | 27 class ExtensionViewHost; |
| 27 } | 28 } |
| 28 | 29 |
| 29 // The platform-independent controller for an ExtensionAction that is shown on | 30 // The platform-independent controller for an ExtensionAction that is shown on |
| 30 // the toolbar (such as a page or browser action). | 31 // the toolbar (such as a page or browser action). |
| 31 // Since this class doesn't own the extension or extension action in question, | 32 // Since this class doesn't own the extension or extension action in question, |
| 32 // be sure to check for validity using ExtensionIsValid() before using those | 33 // be sure to check for validity using ExtensionIsValid() before using those |
| 33 // members (see also comments above ExtensionIsValid()). | 34 // members (see also comments above ExtensionIsValid()). |
| 34 class ExtensionActionViewController | 35 class ExtensionActionViewController |
| 35 : public ToolbarActionViewController, | 36 : public ToolbarActionViewController, |
| 36 public ExtensionActionIconFactory::Observer, | 37 public ExtensionActionIconFactory::Observer, |
| 37 public ExtensionContextMenuModel::PopupDelegate, | 38 public ExtensionContextMenuModel::PopupDelegate, |
| 39 public SidebarManagerObserver, |
| 38 public extensions::ExtensionHostObserver { | 40 public extensions::ExtensionHostObserver { |
| 39 public: | 41 public: |
| 40 // The different options for showing a popup. | 42 // The different options for showing a popup. |
| 41 enum PopupShowAction { SHOW_POPUP, SHOW_POPUP_AND_INSPECT }; | 43 enum PopupShowAction { SHOW_POPUP, SHOW_POPUP_AND_INSPECT }; |
| 42 | 44 |
| 43 ExtensionActionViewController(const extensions::Extension* extension, | 45 ExtensionActionViewController(const extensions::Extension* extension, |
| 44 Browser* browser, | 46 Browser* browser, |
| 45 ExtensionAction* extension_action, | 47 ExtensionAction* extension_action, |
| 46 ToolbarActionsBar* toolbar_actions_bar); | 48 ToolbarActionsBar* toolbar_actions_bar); |
| 47 ~ExtensionActionViewController() override; | 49 ~ExtensionActionViewController() override; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 ExtensionAction* extension_action() { return extension_action_; } | 88 ExtensionAction* extension_action() { return extension_action_; } |
| 87 const ExtensionAction* extension_action() const { return extension_action_; } | 89 const ExtensionAction* extension_action() const { return extension_action_; } |
| 88 ToolbarActionViewDelegate* view_delegate() { return view_delegate_; } | 90 ToolbarActionViewDelegate* view_delegate() { return view_delegate_; } |
| 89 bool is_showing_popup() const { return popup_host_ != nullptr; } | 91 bool is_showing_popup() const { return popup_host_ != nullptr; } |
| 90 | 92 |
| 91 void set_icon_observer(ExtensionActionIconFactory::Observer* icon_observer) { | 93 void set_icon_observer(ExtensionActionIconFactory::Observer* icon_observer) { |
| 92 icon_observer_ = icon_observer; | 94 icon_observer_ = icon_observer; |
| 93 } | 95 } |
| 94 | 96 |
| 95 private: | 97 private: |
| 98 // Update button state to be pressed/unpressed |
| 99 void UpdateButtonState(); |
| 100 |
| 96 // ExtensionActionIconFactory::Observer: | 101 // ExtensionActionIconFactory::Observer: |
| 97 void OnIconUpdated() override; | 102 void OnIconUpdated() override; |
| 98 | 103 |
| 99 // ExtensionHostObserver: | 104 // ExtensionHostObserver: |
| 100 void OnExtensionHostDestroyed(const extensions::ExtensionHost* host) override; | 105 void OnExtensionHostDestroyed(const extensions::ExtensionHost* host) override; |
| 101 | 106 |
| 102 // Checks if the associated |extension| is still valid by checking its | 107 // Checks if the associated |extension| is still valid by checking its |
| 103 // status in the registry. Since the OnExtensionUnloaded() notifications are | 108 // status in the registry. Since the OnExtensionUnloaded() notifications are |
| 104 // not in a deterministic order, it's possible that the view tries to refresh | 109 // not in a deterministic order, it's possible that the view tries to refresh |
| 105 // itself before we're notified to remove it. | 110 // itself before we're notified to remove it. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 128 bool grant_tab_permissions); | 133 bool grant_tab_permissions); |
| 129 | 134 |
| 130 // Shows the popup with the given |host|. | 135 // Shows the popup with the given |host|. |
| 131 void ShowPopup(scoped_ptr<extensions::ExtensionViewHost> host, | 136 void ShowPopup(scoped_ptr<extensions::ExtensionViewHost> host, |
| 132 bool grant_tab_permissions, | 137 bool grant_tab_permissions, |
| 133 PopupShowAction show_action); | 138 PopupShowAction show_action); |
| 134 | 139 |
| 135 // Handles cleanup after the popup closes. | 140 // Handles cleanup after the popup closes. |
| 136 void OnPopupClosed(); | 141 void OnPopupClosed(); |
| 137 | 142 |
| 143 void OnPopupShown(bool grant_tab_permissions); |
| 144 |
| 145 // Handles sidebar events |
| 146 void OnSidebarHidden(content::WebContents* tab, |
| 147 const std::string& content_id) override; |
| 148 |
| 138 // The extension associated with the action we're displaying. | 149 // The extension associated with the action we're displaying. |
| 139 scoped_refptr<const extensions::Extension> extension_; | 150 scoped_refptr<const extensions::Extension> extension_; |
| 140 | 151 |
| 141 // The corresponding browser. | 152 // The corresponding browser. |
| 142 Browser* browser_; | 153 Browser* browser_; |
| 143 | 154 |
| 144 // The browser action this view represents. The ExtensionAction is not owned | 155 // The browser action this view represents. The ExtensionAction is not owned |
| 145 // by this class. | 156 // by this class. |
| 146 ExtensionAction* extension_action_; | 157 ExtensionAction* extension_action_; |
| 147 | 158 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 | 190 |
| 180 ScopedObserver<extensions::ExtensionHost, extensions::ExtensionHostObserver> | 191 ScopedObserver<extensions::ExtensionHost, extensions::ExtensionHostObserver> |
| 181 popup_host_observer_; | 192 popup_host_observer_; |
| 182 | 193 |
| 183 base::WeakPtrFactory<ExtensionActionViewController> weak_factory_; | 194 base::WeakPtrFactory<ExtensionActionViewController> weak_factory_; |
| 184 | 195 |
| 185 DISALLOW_COPY_AND_ASSIGN(ExtensionActionViewController); | 196 DISALLOW_COPY_AND_ASSIGN(ExtensionActionViewController); |
| 186 }; | 197 }; |
| 187 | 198 |
| 188 #endif // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_H_ | 199 #endif // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_H_ |
| OLD | NEW |