Add ability to gather metrics to BubbleManager.
[chromium-blink-merge.git] / chrome / browser / ui / toolbar / toolbar_action_view_controller.h
blob4702922bec0ece90459b5591814ac8f7e3dffa0c
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTION_VIEW_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTION_VIEW_CONTROLLER_H_
8 #include "base/strings/string16.h"
9 #include "ui/gfx/image/image.h"
11 namespace content {
12 class WebContents;
15 namespace gfx {
16 class Size;
19 namespace ui {
20 class MenuModel;
23 class ToolbarActionViewDelegate;
25 // The basic controller class for an action that is shown on the toolbar -
26 // an extension action (like browser actions) or a component action (like
27 // chromecast).
28 class ToolbarActionViewController {
29 public:
30 virtual ~ToolbarActionViewController() {}
32 // Returns the unique ID of this particular action. For extensions, this is
33 // the extension id; for component actions, this is the name of the component.
34 virtual std::string GetId() const = 0;
36 // Sets the view delegate, which can handle most of the front-end logic.
37 virtual void SetDelegate(ToolbarActionViewDelegate* delegate) = 0;
39 // Returns the icon to use for the given |web_contents| and |size|.
40 virtual gfx::Image GetIcon(content::WebContents* web_contents,
41 const gfx::Size& size) = 0;
43 // Returns the name of the action, which can be separate from the accessible
44 // name or name for the tooltip.
45 virtual base::string16 GetActionName() const = 0;
47 // Returns the accessible name to use for the given |web_contents|.
48 virtual base::string16 GetAccessibleName(content::WebContents* web_contents)
49 const = 0;
51 // Returns the tooltip to use for the given |web_contents|.
52 virtual base::string16 GetTooltip(content::WebContents* web_contents)
53 const = 0;
55 // Returns true if the action should be enabled on the given |web_contents|.
56 virtual bool IsEnabled(content::WebContents* web_contents) const = 0;
58 // Returns true if the action wants to run, and should be popped out of the
59 // overflow menu on the given |web_contents|.
60 virtual bool WantsToRun(content::WebContents* web_contents) const = 0;
62 // Returns true if the action has a popup for the given |web_contents|.
63 virtual bool HasPopup(content::WebContents* web_contents) const = 0;
65 // Hides the current popup, if one is visible.
66 virtual void HidePopup() = 0;
68 // Returns the native view for the popup, if one is active.
69 virtual gfx::NativeView GetPopupNativeView() = 0;
71 // Returns the context menu model, or null if no context menu should be shown.
72 virtual ui::MenuModel* GetContextMenu() = 0;
74 // Called when a context menu has closed so the controller can perform any
75 // necessary cleanup.
76 virtual void OnContextMenuClosed() {}
78 // Executes the default action (which is typically showing the popup). If
79 // |by_user| is true, then this was through a direct user action (as oppposed
80 // to, e.g., an API call).
81 // Returns true if a popup is shown.
82 virtual bool ExecuteAction(bool by_user) = 0;
84 // Updates the current state of the action.
85 virtual void UpdateState() = 0;
87 // Returns true if clicking on an otherwise-disabled action should open the
88 // context menu.
89 virtual bool DisabledClickOpensMenu() const = 0;
91 // Registers an accelerator. Called when the view is added to the hierarchy.
92 // Unregistering any commands is the responsibility of the controller.
93 virtual void RegisterCommand() {
97 #endif // CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ACTION_VIEW_CONTROLLER_H_