OLD | NEW |
---|---|
(Empty) | |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_H_ | |
6 #define CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_H_ | |
7 | |
8 #include "chrome/browser/extensions/extension_action_icon_factory.h" | |
9 #include "chrome/browser/extensions/extension_context_menu_model.h" | |
10 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | |
11 #include "ui/gfx/image/image.h" | |
12 | |
13 class Browser; | |
14 class ExtensionAction; | |
15 class GURL; | |
16 | |
17 namespace extensions { | |
18 class Command; | |
19 class Extension; | |
20 } | |
21 | |
22 class ExtensionActionViewController | |
sky
2014/10/23 20:24:30
Add a description.
Devlin
2014/10/23 20:50:32
Done.
| |
23 : public ToolbarActionViewController, | |
24 public ExtensionActionIconFactory::Observer, | |
25 public ExtensionContextMenuModel::PopupDelegate { | |
26 public: | |
27 ExtensionActionViewController(const extensions::Extension* extension, | |
28 Browser* browser, | |
29 ExtensionAction* extension_action); | |
30 ~ExtensionActionViewController() override; | |
31 | |
32 // ToolbarActionViewController: | |
33 const std::string& GetId() const override; | |
34 void SetDelegate(ToolbarActionViewDelegate* delegate) override; | |
35 gfx::Image GetIcon(content::WebContents* web_contents) override; | |
36 gfx::ImageSkia GetIconWithBadge() override; | |
37 base::string16 GetActionName() const override; | |
38 base::string16 GetAccessibleName(content::WebContents* web_contents) const | |
39 override; | |
40 base::string16 GetTooltip(content::WebContents* web_contents) const override; | |
41 bool IsEnabled(content::WebContents* web_contents) const override; | |
42 bool HasPopup(content::WebContents* web_contents) const override; | |
43 void HidePopup() override; | |
44 bool CanDrag() const override; | |
45 bool ExecuteAction(bool by_user) override; | |
46 void PaintExtra(gfx::Canvas* canvas, | |
47 const gfx::Rect& bounds, | |
48 content::WebContents* web_contents) const override; | |
49 | |
50 // ExtensionContextMenuModel::PopupDelegate: | |
51 void InspectPopup() override; | |
52 | |
53 const extensions::Extension* extension() const { return extension_; } | |
54 Browser* browser() { return browser_; } | |
55 ExtensionAction* extension_action() { return extension_action_; } | |
56 const ExtensionAction* extension_action() const { return extension_action_; } | |
57 | |
58 protected: | |
59 enum PopupShowAction { | |
60 SHOW_POPUP, | |
61 SHOW_POPUP_AND_INSPECT | |
62 }; | |
63 | |
64 ToolbarActionViewDelegate* delegate() const { return delegate_; } | |
65 | |
66 // Populates |command| with the command associated with |extension|, if one | |
67 // exists. Returns true if |command| was populated. | |
68 bool GetExtensionCommand(extensions::Command* command); | |
69 | |
70 // Returns true if there is currently a popup for this extension action. | |
71 virtual bool IsShowingPopup() const = 0; | |
sky
2014/10/23 20:24:30
Is there a reason you're going with subclassing in
Devlin
2014/10/23 20:50:32
Two reasons:
- I thought a delegate might get conf
| |
72 | |
73 // Closes the active popup (whether it was this action's popup or not). | |
74 virtual void CloseActivePopup() = 0; | |
75 | |
76 // Closes this action's popup. This will only be called if the popup is | |
77 // showing. | |
78 virtual void ClosePopupImpl() = 0; | |
79 | |
80 // See ShowPopupWithUrl() for documentation. | |
81 virtual bool ShowPopupWithUrlImpl(PopupShowAction show_action, | |
82 const GURL& popup_url, | |
83 bool grant_tab_permissions) = 0; | |
84 | |
85 // Called once the delegate is set, in order to do any extra initialization. | |
86 virtual void OnDelegateSet() {} | |
sky
2014/10/23 20:24:30
nit: don't inline virtual methods.
Devlin
2014/10/23 20:50:32
Thought the rule was "don't inline non-empty virtu
| |
87 | |
88 private: | |
89 // ExtensionActionIconFactory::Observer: | |
90 void OnIconUpdated() override; | |
91 | |
92 // Executes the extension action with |show_action|. If | |
93 // |grant_tab_permissions| is true, this will grant the extension active tab | |
94 // permissions. Only do this if this was done through a user action (and not | |
95 // e.g. an API). Returns true if a popup is shown. | |
96 bool ExecuteAction(PopupShowAction show_action, | |
97 bool grant_tab_permissions); | |
98 | |
99 // Shows the popup for the extension action, given the associated |popup_url|. | |
100 // |grant_tab_permissions| is true if active tab permissions should be given | |
101 // to the extension; this is only true if the popup is opened through a user | |
102 // action. | |
103 // Returns true if a popup is successfully shown. | |
104 bool ShowPopupWithUrl(PopupShowAction show_action, | |
105 const GURL& popup_url, | |
106 bool grant_tab_permissions); | |
107 | |
108 // The extension associated with the action we're displaying. | |
109 const extensions::Extension* extension_; | |
110 | |
111 // The corresponding browser. | |
112 Browser* browser_; | |
113 | |
114 // The browser action this view represents. The ExtensionAction is not owned | |
115 // by this class. | |
116 ExtensionAction* extension_action_; | |
117 | |
118 // Our delegate. | |
119 ToolbarActionViewDelegate* delegate_; | |
120 | |
121 // The object that will be used to get the browser action icon for us. | |
122 // It may load the icon asynchronously (in which case the initial icon | |
123 // returned by the factory will be transparent), so we have to observe it for | |
124 // updates to the icon. | |
125 ExtensionActionIconFactory icon_factory_; | |
126 | |
127 DISALLOW_COPY_AND_ASSIGN(ExtensionActionViewController); | |
128 }; | |
129 | |
130 #endif // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_H_ | |
OLD | NEW |