| Index: chrome/browser/ui/views/extensions/extension_action_view_controller.h
|
| diff --git a/chrome/browser/ui/views/extensions/extension_action_view_controller.h b/chrome/browser/ui/views/extensions/extension_action_view_controller.h
|
| index 9efc499b02e0d84bbf09977da031fb1e48a47543..50c5745bbfd6206c0b6789f2f8b4a60d949b3c2c 100644
|
| --- a/chrome/browser/ui/views/extensions/extension_action_view_controller.h
|
| +++ b/chrome/browser/ui/views/extensions/extension_action_view_controller.h
|
| @@ -8,6 +8,9 @@
|
| #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/toolbar/toolbar_action_view_controller.h"
|
| +#include "content/public/browser/notification_observer.h"
|
| +#include "content/public/browser/notification_registrar.h"
|
| #include "ui/base/accelerators/accelerator.h"
|
| #include "ui/gfx/image/image.h"
|
| #include "ui/views/context_menu_controller.h"
|
| @@ -15,7 +18,7 @@
|
|
|
| class Browser;
|
| class ExtensionAction;
|
| -class ExtensionActionViewDelegate;
|
| +class ToolbarActionViewDelegate;
|
|
|
| namespace content {
|
| class WebContents;
|
| @@ -45,7 +48,9 @@ class Widget;
|
| // ExtensionActionViewDelegate classes should only have knowledge relating to
|
| // the views::View wrapper.
|
| class ExtensionActionViewController
|
| - : public ExtensionActionIconFactory::Observer,
|
| + : public ToolbarActionViewController,
|
| + public content::NotificationObserver,
|
| + public ExtensionActionIconFactory::Observer,
|
| public ExtensionContextMenuModel::PopupDelegate,
|
| public ui::AcceleratorTarget,
|
| public views::ContextMenuController,
|
| @@ -54,17 +59,27 @@ class ExtensionActionViewController
|
| ExtensionActionViewController(const extensions::Extension* extension,
|
| Browser* browser,
|
| ExtensionAction* extension_action,
|
| - ExtensionActionViewDelegate* delegate);
|
| + ToolbarActionViewDelegate* delegate);
|
| virtual ~ExtensionActionViewController();
|
|
|
| + // ToolbarActionViewController:
|
| + virtual void SetDelegate(ToolbarActionViewDelegate* delegate) override;
|
| + virtual gfx::Image GetIcon(int tab_id) override;
|
| + virtual base::string16 GetAccessibleName(int tab_id) const override;
|
| + virtual base::string16 GetTooltip(int tab_id) const override;
|
| + virtual bool IsEnabled(int tab_id) const override;
|
| + virtual bool HasPopup(int tab_id) const override;
|
| + virtual void HidePopup() override;
|
| + virtual bool IsMenuRunning() const override;
|
| + virtual void ExecuteActionByUser() override;
|
| + virtual void PaintExtra(gfx::Canvas* canvas,
|
| + const gfx::Rect& bounds,
|
| + int tab_id) const override;
|
| + virtual void RegisterCommand() override;
|
| +
|
| // ExtensionContextMenuModel::PopupDelegate:
|
| virtual void InspectPopup() override;
|
|
|
| - // Executes the default extension action (typically showing the popup), and
|
| - // attributes the action to a user (thus, only use this for actions that
|
| - // *were* done by the user).
|
| - void ExecuteActionByUser();
|
| -
|
| // Executes the extension action with |show_action|. 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
|
| @@ -72,30 +87,18 @@ class ExtensionActionViewController
|
| bool ExecuteAction(ExtensionPopup::ShowAction show_action,
|
| bool grant_tab_permissions);
|
|
|
| - // Hides the popup, if one is open.
|
| - void HidePopup();
|
| -
|
| - // Returns the icon from the |icon_factory_|.
|
| - gfx::Image GetIcon(int tab_id);
|
| -
|
| - // Returns the current tab id.
|
| - int GetCurrentTabId() const;
|
| -
|
| - // Registers an accelerator for the extension action's command, if one
|
| - // exists.
|
| - void RegisterCommand();
|
| + // Returns the icon, plus any badge, for the current tab.
|
| + gfx::ImageSkia GetIconWithBadge();
|
|
|
| - // Unregisters the accelerator for the extension action's command, if one
|
| - // exists. If |only_if_removed| is true, then this will only unregister if the
|
| - // command has been removed.
|
| - void UnregisterCommand(bool only_if_removed);
|
| + void set_icon_observer(ExtensionActionIconFactory::Observer* icon_observer) {
|
| + icon_observer_ = icon_observer;
|
| + }
|
|
|
| const extensions::Extension* extension() const { return extension_; }
|
| Browser* browser() { return browser_; }
|
| ExtensionAction* extension_action() { return extension_action_; }
|
| const ExtensionAction* extension_action() const { return extension_action_; }
|
| ExtensionPopup* popup() { return popup_; }
|
| - bool is_menu_running() const { return menu_runner_.get() != NULL; }
|
|
|
| private:
|
| // ExtensionActionIconFactory::Observer:
|
| @@ -113,6 +116,11 @@ class ExtensionActionViewController
|
| const gfx::Point& point,
|
| ui::MenuSourceType source_type) override;
|
|
|
| + // content::NotificationObserver:
|
| + virtual void Observe(int type,
|
| + const content::NotificationSource& source,
|
| + const content::NotificationDetails& details) override;
|
| +
|
| // Shows the context menu for extension action.
|
| void DoShowContextMenu(ui::MenuSourceType source_type);
|
|
|
| @@ -129,6 +137,11 @@ class ExtensionActionViewController
|
| // exists. Returns true if |command| was populated.
|
| bool GetExtensionCommand(extensions::Command* command);
|
|
|
| + // Unregisters the accelerator for the extension action's command, if one
|
| + // exists. If |only_if_removed| is true, then this will only unregister if the
|
| + // command has been removed.
|
| + void UnregisterCommand(bool only_if_removed);
|
| +
|
| // Closes the currently-active menu, if needed. This is the case when there
|
| // is an active menu that wouldn't close automatically when a new one is
|
| // opened.
|
| @@ -151,7 +164,7 @@ class ExtensionActionViewController
|
| ExtensionAction* extension_action_;
|
|
|
| // Our delegate.
|
| - ExtensionActionViewDelegate* delegate_;
|
| + ToolbarActionViewDelegate* delegate_;
|
|
|
| // 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
|
| @@ -159,6 +172,10 @@ class ExtensionActionViewController
|
| // updates to the icon.
|
| ExtensionActionIconFactory icon_factory_;
|
|
|
| + // The observer that we need to notify when the icon of the button has been
|
| + // updated.
|
| + ExtensionActionIconFactory::Observer* icon_observer_;
|
| +
|
| // Responsible for running the menu.
|
| scoped_ptr<views::MenuRunner> menu_runner_;
|
|
|
| @@ -169,6 +186,8 @@ class ExtensionActionViewController
|
| // for (to show the popup).
|
| scoped_ptr<ui::Accelerator> action_keybinding_;
|
|
|
| + content::NotificationRegistrar registrar_;
|
| +
|
| // If non-NULL, this is the next ExtensionActionViewController context menu
|
| // which wants to run once the current owner (this one) is done.
|
| base::Closure followup_context_menu_task_;
|
|
|