Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: chrome/browser/ui/extensions/extension_action_view_controller.h

Issue 670463004: Make a platform-independent ToolbarActionViewController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 ExtensionActionPlatformDelegate;
16 class GURL;
17
18 namespace extensions {
19 class Command;
20 class Extension;
21 }
22
23 // The platform-independent controller for an ExtensionAction that is shown on
24 // the toolbar (such as a page or browser action).
25 class ExtensionActionViewController
26 : public ToolbarActionViewController,
27 public ExtensionActionIconFactory::Observer,
28 public ExtensionContextMenuModel::PopupDelegate {
29 public:
30 // The different options for showing a popup.
31 enum PopupShowAction { SHOW_POPUP, SHOW_POPUP_AND_INSPECT };
32
33 ExtensionActionViewController(const extensions::Extension* extension,
34 Browser* browser,
35 ExtensionAction* extension_action);
36 ~ExtensionActionViewController() override;
37
38 // ToolbarActionViewController:
39 const std::string& GetId() const override;
40 void SetDelegate(ToolbarActionViewDelegate* delegate) override;
41 gfx::Image GetIcon(content::WebContents* web_contents) override;
42 gfx::ImageSkia GetIconWithBadge() override;
43 base::string16 GetActionName() const override;
44 base::string16 GetAccessibleName(content::WebContents* web_contents) const
45 override;
46 base::string16 GetTooltip(content::WebContents* web_contents) const override;
47 bool IsEnabled(content::WebContents* web_contents) const override;
48 bool HasPopup(content::WebContents* web_contents) const override;
49 void HidePopup() override;
50 gfx::NativeView GetPopupNativeView() override;
51 bool IsMenuRunning() const override;
52 bool CanDrag() const override;
53 bool ExecuteAction(bool by_user) override;
54 void PaintExtra(gfx::Canvas* canvas,
55 const gfx::Rect& bounds,
56 content::WebContents* web_contents) const override;
57 void RegisterCommand() override;
58
59 // ExtensionContextMenuModel::PopupDelegate:
60 void InspectPopup() override;
61
62 // Populates |command| with the command associated with |extension|, if one
63 // exists. Returns true if |command| was populated.
64 bool GetExtensionCommand(extensions::Command* command);
65
66 const extensions::Extension* extension() const { return extension_; }
67 Browser* browser() { return browser_; }
68 ExtensionAction* extension_action() { return extension_action_; }
69 const ExtensionAction* extension_action() const { return extension_action_; }
70 ToolbarActionViewDelegate* view_delegate() { return view_delegate_; }
71
72 void set_icon_observer(ExtensionActionIconFactory::Observer* icon_observer) {
73 icon_observer_ = icon_observer;
74 }
75
76 private:
77 // ExtensionActionIconFactory::Observer:
78 void OnIconUpdated() override;
79
80 // Executes the extension action with |show_action|. If
81 // |grant_tab_permissions| is true, this will grant the extension active tab
82 // permissions. Only do this if this was done through a user action (and not
83 // e.g. an API). Returns true if a popup is shown.
84 bool ExecuteAction(PopupShowAction show_action, bool grant_tab_permissions);
85
86 // Shows the popup for the extension action, given the associated |popup_url|.
87 // |grant_tab_permissions| is true if active tab permissions should be given
88 // to the extension; this is only true if the popup is opened through a user
89 // action.
90 // Returns true if a popup is successfully shown.
91 bool ShowPopupWithUrl(PopupShowAction show_action,
92 const GURL& popup_url,
93 bool grant_tab_permissions);
94
95 // The extension associated with the action we're displaying.
96 const extensions::Extension* extension_;
97
98 // The corresponding browser.
99 Browser* browser_;
100
101 // The browser action this view represents. The ExtensionAction is not owned
102 // by this class.
103 ExtensionAction* extension_action_;
104
105 // Our view delegate.
106 ToolbarActionViewDelegate* view_delegate_;
107
108 // The delegate to handle platform-specific implementations.
109 scoped_ptr<ExtensionActionPlatformDelegate> platform_delegate_;
110
111 // The object that will be used to get the browser action icon for us.
112 // It may load the icon asynchronously (in which case the initial icon
113 // returned by the factory will be transparent), so we have to observe it for
114 // updates to the icon.
115 ExtensionActionIconFactory icon_factory_;
116
117 // An additional observer that we need to notify when the icon of the button
118 // has been updated.
119 ExtensionActionIconFactory::Observer* icon_observer_;
120
121 DISALLOW_COPY_AND_ASSIGN(ExtensionActionViewController);
122 };
123
124 #endif // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698