Chromium Code Reviews| Index: chrome/browser/ui/views/toolbar/browser_action_view.h |
| diff --git a/chrome/browser/ui/views/toolbar/browser_action_view.h b/chrome/browser/ui/views/toolbar/browser_action_view.h |
| index 25dfe71bd08bca82b6cd8d3e56114f8509e04a8b..c79bdc236e296ac0d391122cdd8bae1db981d526 100644 |
| --- a/chrome/browser/ui/views/toolbar/browser_action_view.h |
| +++ b/chrome/browser/ui/views/toolbar/browser_action_view.h |
| @@ -5,17 +5,13 @@ |
| #ifndef CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ |
| #define CHROME_BROWSER_UI_VIEWS_TOOLBAR_BROWSER_ACTION_VIEW_H_ |
| -#include "chrome/browser/extensions/extension_action_icon_factory.h" |
| -#include "chrome/browser/extensions/extension_context_menu_model.h" |
| -#include "chrome/browser/ui/views/extensions/extension_popup.h" |
| +#include "chrome/browser/ui/views/extensions/extension_action_view.h" |
| #include "content/public/browser/notification_observer.h" |
| #include "content/public/browser/notification_registrar.h" |
| -#include "ui/views/context_menu_controller.h" |
| #include "ui/views/controls/button/menu_button.h" |
| #include "ui/views/controls/button/menu_button_listener.h" |
| #include "ui/views/drag_controller.h" |
| #include "ui/views/view.h" |
| -#include "ui/views/widget/widget_observer.h" |
| class Browser; |
| class BrowserActionButton; |
| @@ -23,18 +19,12 @@ class ExtensionAction; |
| namespace extensions { |
| class Extension; |
| -class ExtensionToolbarModel; |
| } |
| namespace gfx { |
| class Image; |
| } |
| -namespace views { |
| -class MenuItemView; |
| -class MenuRunner; |
| -} |
| - |
| //////////////////////////////////////////////////////////////////////////////// |
| // BrowserActionView |
| // A single entry in the browser action container. This contains the actual |
| @@ -45,8 +35,8 @@ class BrowserActionView : public views::View { |
| // dragged/dropped. |
| class Delegate : public views::DragController { |
| public: |
| - // Returns the current tab's ID, or -1 if there is no current tab. |
| - virtual int GetCurrentTabId() const = 0; |
| + // Returns the current web contents. |
| + virtual content::WebContents* GetCurrentWebContents() = 0; |
| // Called when a browser action becomes visible/hidden. |
| virtual void OnBrowserActionVisibilityChanged() = 0; |
| @@ -70,9 +60,6 @@ class BrowserActionView : public views::View { |
| // Hides the active popup of the delegate, if one exists. |
| virtual void HideActivePopup() = 0; |
| - // Returns the Model backing the browser actions. |
| - virtual extensions::ExtensionToolbarModel* GetModel() = 0; |
| - |
| protected: |
| virtual ~Delegate() {} |
| }; |
| @@ -98,18 +85,12 @@ class BrowserActionView : public views::View { |
| const views::CullSet& cull_set) OVERRIDE; |
| private: |
| - // The Browser object this view is associated with. |
| - Browser* browser_; |
| - |
| // Usually a container for this view. |
| Delegate* delegate_; |
| // The button this view contains. |
| BrowserActionButton* button_; |
|
sky
2014/08/05 22:29:47
Wrap in scoped_ptr now? If delete needs to be run
Devlin
2014/08/05 23:51:10
Done.
|
| - // Extension this view associated with. |
| - const extensions::Extension* extension_; |
| - |
| DISALLOW_COPY_AND_ASSIGN(BrowserActionView); |
| }; |
| @@ -117,15 +98,12 @@ class BrowserActionView : public views::View { |
| // BrowserActionButton |
| // The BrowserActionButton is a specialization of the MenuButton class. |
| -// It acts on a ExtensionAction, in this case a BrowserAction and handles |
| -// loading the image for the button asynchronously on the file thread. |
| +// This wraps an ExtensionActionView, and has knowledge of how to render itself |
| +// and when to trigger the extension action. |
| class BrowserActionButton : public views::MenuButton, |
| + public ExtensionActionView::ViewDelegate, |
| public views::ButtonListener, |
| - public views::ContextMenuController, |
| - public content::NotificationObserver, |
| - public ExtensionActionIconFactory::Observer, |
| - public views::WidgetObserver, |
| - public ExtensionContextMenuModel::PopupDelegate { |
| + public content::NotificationObserver { |
| public: |
| // The IconObserver will receive a notification when the button's icon has |
| // been updated. |
| @@ -138,15 +116,19 @@ class BrowserActionButton : public views::MenuButton, |
| }; |
| BrowserActionButton(const extensions::Extension* extension, |
| - Browser* browser_, |
| + Browser* browser, |
| BrowserActionView::Delegate* delegate); |
| + virtual ~BrowserActionButton(); |
| - // Call this instead of delete. |
| - void Destroy(); |
| - |
| - ExtensionAction* browser_action() const { return browser_action_; } |
| - const extensions::Extension* extension() { return extension_; } |
| - |
| + const extensions::Extension* extension() const { |
| + return extension_action_view_->extension(); |
| + } |
| + ExtensionAction* extension_action() { |
| + return extension_action_view_->extension_action(); |
| + } |
| + ExtensionActionView* extension_action_view() { |
| + return extension_action_view_.get(); |
| + } |
| void set_icon_observer(IconObserver* icon_observer) { |
| icon_observer_ = icon_observer; |
| } |
| @@ -155,20 +137,7 @@ class BrowserActionButton : public views::MenuButton, |
| void UpdateState(); |
| // Does this button's action have a popup? |
| - virtual bool IsPopup(); |
| - virtual GURL GetPopupUrl(); |
| - |
| - // Show this extension's popup. If |grant_tab_permissions| is true, this will |
| - // grant the extension active tab permissions. Only do this if this was done |
| - // through a user action (and not e.g. an API). |
| - bool ShowPopup(ExtensionPopup::ShowAction show_action, |
| - bool grant_tab_permissions); |
| - |
| - // Hides the popup, if one is open. |
| - void HidePopup(); |
| - |
| - // Executes the browser action (and also shows the popup, if one exists). |
| - void ExecuteBrowserAction(); |
| + bool IsPopup(); |
| // Overridden from views::View: |
| virtual bool CanHandleAccelerators() const OVERRIDE; |
| @@ -178,19 +147,11 @@ class BrowserActionButton : public views::MenuButton, |
| virtual void ButtonPressed(views::Button* sender, |
| const ui::Event& event) OVERRIDE; |
| - // Overridden from views::ContextMenuController. |
| - virtual void ShowContextMenuForView(View* source, |
| - const gfx::Point& point, |
| - ui::MenuSourceType source_type) OVERRIDE; |
| - |
| // Overridden from content::NotificationObserver: |
| virtual void Observe(int type, |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) OVERRIDE; |
| - // Overriden from ExtensionActionIconFactory::Observer. |
| - virtual void OnIconUpdated() OVERRIDE; |
| - |
| // MenuButton behavior overrides. These methods all default to LabelButton |
| // behavior unless this button is a popup. In that case, it uses MenuButton |
| // behavior. MenuButton has the notion of a child popup being shown where the |
| @@ -208,9 +169,6 @@ class BrowserActionButton : public views::MenuButton, |
| // Overridden from ui::AcceleratorTarget. |
| virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE; |
| - // ExtensionContextMenuModel::PopupDelegate: |
| - virtual void InspectPopup() OVERRIDE; |
| - |
| // Notifications when to set button state to pushed/not pushed (for when the |
| // popup/context menu is hidden or shown by the container). |
| void SetButtonPushed(); |
| @@ -221,10 +179,6 @@ class BrowserActionButton : public views::MenuButton, |
| // receive drag events. |
| bool IsEnabled(int tab_id) const; |
| - // Accessors. |
| - ExtensionActionIconFactory& icon_factory() { return icon_factory_; } |
| - ExtensionPopup* popup() { return popup_; } |
| - |
| // Gets the icon of this button and its badge. |
| gfx::ImageSkia GetIconWithBadge(); |
| @@ -238,64 +192,35 @@ class BrowserActionButton : public views::MenuButton, |
| virtual void OnDragDone() OVERRIDE; |
| private: |
| - virtual ~BrowserActionButton(); |
| - |
| - // views::WidgetObserver: |
| - virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE; |
| - |
| - // Register an extension command if the extension has an active one. |
| - void MaybeRegisterExtensionCommand(); |
| - |
| - // Unregisters an extension command, if the extension has registered one and |
| - // it is active. |
| - void MaybeUnregisterExtensionCommand(bool only_if_active); |
| - |
| - // Cleans up after the popup. If |close_widget| is true, this will call |
| - // Widget::Close() on the popup's widget; otherwise it assumes the popup is |
| - // already closing. |
| - void CleanupPopup(bool close_widget); |
| - |
| - // The Browser object this button is associated with. |
| - Browser* browser_; |
| - |
| - // The browser action this view represents. The ExtensionAction is not owned |
| - // by this class. |
| - ExtensionAction* browser_action_; |
| - |
| - // The extension associated with the browser action we're displaying. |
| - const extensions::Extension* extension_; |
| + // ExtensionActionView::ViewDelegate: |
| + virtual views::View* GetAsView() OVERRIDE; |
| + virtual bool IsNestedView() OVERRIDE; |
| + virtual views::FocusManager* GetFocusManagerForAccelerator() OVERRIDE; |
| + virtual views::Widget* GetParentForContextMenu() OVERRIDE; |
| + virtual views::View* GetReferenceViewForPopup() OVERRIDE; |
| + virtual content::WebContents* GetCurrentWebContents() OVERRIDE; |
| + virtual void HideActivePopup() OVERRIDE; |
| + virtual void OnIconUpdated() OVERRIDE; |
| + virtual void OnPopupShown(bool grant_tab_permissions) OVERRIDE; |
| + virtual void CleanupPopup() OVERRIDE; |
| + virtual void OnWillShowContextMenus() OVERRIDE; |
| + virtual void OnContextMenuDone() OVERRIDE; |
| - // The object that will be used to get the browser action icon for us. |
| - // It may load the icon asynchronously (in which case the initial icon |
| - // returned by the factory will be transparent), so we have to observe it for |
| - // updates to the icon. |
| - ExtensionActionIconFactory icon_factory_; |
| + // The ExtensionActionView implementation. |
| + scoped_ptr<ExtensionActionView> extension_action_view_; |
| // Delegate that usually represents a container for BrowserActionView. |
| BrowserActionView::Delegate* delegate_; |
| - // Used to make sure MaybeRegisterExtensionCommand() is called only once |
| - // from ViewHierarchyChanged(). |
| + // Used to make sure we only register the command once. |
| bool called_registered_extension_command_; |
| content::NotificationRegistrar registrar_; |
| - // The extension key binding accelerator this browser action is listening for |
| - // (to show the popup). |
| - scoped_ptr<ui::Accelerator> keybinding_; |
| - |
| - // Responsible for running the menu. |
| - scoped_ptr<views::MenuRunner> menu_runner_; |
| - |
| - // The browser action's popup, if it is visible; NULL otherwise. |
| - ExtensionPopup* popup_; |
| - |
| // The observer that we need to notify when the icon of the button has been |
| // updated. |
| IconObserver* icon_observer_; |
| - friend class base::DeleteHelper<BrowserActionButton>; |
| - |
| DISALLOW_COPY_AND_ASSIGN(BrowserActionButton); |
| }; |