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

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

Issue 869873008: [Extensions Toolbar] Move some popup logic to be platform-agnostic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Avi's Created 5 years, 10 months 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_H_ 6 #define CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_H_
7 7
8 #include "chrome/browser/extensions/extension_action_icon_factory.h" 8 #include "chrome/browser/extensions/extension_action_icon_factory.h"
9 #include "chrome/browser/extensions/extension_context_menu_model.h" 9 #include "chrome/browser/extensions/extension_context_menu_model.h"
10 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" 10 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
11 #include "ui/gfx/image/image.h" 13 #include "ui/gfx/image/image.h"
12 14
13 class Browser; 15 class Browser;
14 class ExtensionAction; 16 class ExtensionAction;
15 class ExtensionActionPlatformDelegate; 17 class ExtensionActionPlatformDelegate;
16 class GURL; 18 class GURL;
17 19
18 namespace extensions { 20 namespace extensions {
19 class Command; 21 class Command;
20 class Extension; 22 class Extension;
21 class ExtensionRegistry; 23 class ExtensionRegistry;
24 class ExtensionViewHost;
22 } 25 }
23 26
24 // The platform-independent controller for an ExtensionAction that is shown on 27 // The platform-independent controller for an ExtensionAction that is shown on
25 // the toolbar (such as a page or browser action). 28 // the toolbar (such as a page or browser action).
26 // Since this class doesn't own the extension or extension action in question, 29 // Since this class doesn't own the extension or extension action in question,
27 // be sure to check for validity using ExtensionIsValid() before using those 30 // be sure to check for validity using ExtensionIsValid() before using those
28 // members (see also comments above ExtensionIsValid()). 31 // members (see also comments above ExtensionIsValid()).
29 class ExtensionActionViewController 32 class ExtensionActionViewController
30 : public ToolbarActionViewController, 33 : public ToolbarActionViewController,
31 public ExtensionActionIconFactory::Observer, 34 public ExtensionActionIconFactory::Observer,
32 public ExtensionContextMenuModel::PopupDelegate { 35 public ExtensionContextMenuModel::PopupDelegate,
36 public content::NotificationObserver {
33 public: 37 public:
34 // The different options for showing a popup. 38 // The different options for showing a popup.
35 enum PopupShowAction { SHOW_POPUP, SHOW_POPUP_AND_INSPECT }; 39 enum PopupShowAction { SHOW_POPUP, SHOW_POPUP_AND_INSPECT };
36 40
37 ExtensionActionViewController(const extensions::Extension* extension, 41 ExtensionActionViewController(const extensions::Extension* extension,
38 Browser* browser, 42 Browser* browser,
39 ExtensionAction* extension_action); 43 ExtensionAction* extension_action);
40 ~ExtensionActionViewController() override; 44 ~ExtensionActionViewController() override;
41 45
42 // ToolbarActionViewController: 46 // ToolbarActionViewController:
(...skipping 25 matching lines...) Expand all
68 72
69 // Populates |command| with the command associated with |extension|, if one 73 // Populates |command| with the command associated with |extension|, if one
70 // exists. Returns true if |command| was populated. 74 // exists. Returns true if |command| was populated.
71 bool GetExtensionCommand(extensions::Command* command); 75 bool GetExtensionCommand(extensions::Command* command);
72 76
73 const extensions::Extension* extension() const { return extension_; } 77 const extensions::Extension* extension() const { return extension_; }
74 Browser* browser() { return browser_; } 78 Browser* browser() { return browser_; }
75 ExtensionAction* extension_action() { return extension_action_; } 79 ExtensionAction* extension_action() { return extension_action_; }
76 const ExtensionAction* extension_action() const { return extension_action_; } 80 const ExtensionAction* extension_action() const { return extension_action_; }
77 ToolbarActionViewDelegate* view_delegate() { return view_delegate_; } 81 ToolbarActionViewDelegate* view_delegate() { return view_delegate_; }
82 bool is_showing_popup() const { return popup_host_ != nullptr; }
78 83
79 void set_icon_observer(ExtensionActionIconFactory::Observer* icon_observer) { 84 void set_icon_observer(ExtensionActionIconFactory::Observer* icon_observer) {
80 icon_observer_ = icon_observer; 85 icon_observer_ = icon_observer;
81 } 86 }
82 87
83 private: 88 private:
84 // ExtensionActionIconFactory::Observer: 89 // ExtensionActionIconFactory::Observer:
85 void OnIconUpdated() override; 90 void OnIconUpdated() override;
86 91
92 // content::NotificationObserver:
93 void Observe(int notification_type,
94 const content::NotificationSource& source,
95 const content::NotificationDetails& details) override;
96
87 // Checks if the associated |extension| is still valid by checking its 97 // Checks if the associated |extension| is still valid by checking its
88 // status in the registry. Since the OnExtensionUnloaded() notifications are 98 // status in the registry. Since the OnExtensionUnloaded() notifications are
89 // not in a deterministic order, it's possible that the view tries to refresh 99 // not in a deterministic order, it's possible that the view tries to refresh
90 // itself before we're notified to remove it. 100 // itself before we're notified to remove it.
91 bool ExtensionIsValid() const; 101 bool ExtensionIsValid() const;
92 102
93 // Executes the extension action with |show_action|. If 103 // Executes the extension action with |show_action|. If
94 // |grant_tab_permissions| is true, this will grant the extension active tab 104 // |grant_tab_permissions| is true, this will grant the extension active tab
95 // permissions. Only do this if this was done through a user action (and not 105 // permissions. Only do this if this was done through a user action (and not
96 // e.g. an API). Returns true if a popup is shown. 106 // e.g. an API). Returns true if a popup is shown.
97 bool ExecuteAction(PopupShowAction show_action, bool grant_tab_permissions); 107 bool ExecuteAction(PopupShowAction show_action, bool grant_tab_permissions);
98 108
99 // Shows the popup for the extension action, given the associated |popup_url|. 109 // 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 110 // |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 111 // to the extension; this is only true if the popup is opened through a user
102 // action. 112 // action.
103 // Returns true if a popup is successfully shown. 113 // Returns true if a popup is successfully shown.
104 bool ShowPopupWithUrl(PopupShowAction show_action, 114 bool ShowPopupWithUrl(PopupShowAction show_action,
105 const GURL& popup_url, 115 const GURL& popup_url,
106 bool grant_tab_permissions); 116 bool grant_tab_permissions);
107 117
118 // Handles cleanup after the popup closes.
119 void OnPopupClosed();
120
108 // The extension associated with the action we're displaying. 121 // The extension associated with the action we're displaying.
109 const extensions::Extension* extension_; 122 const extensions::Extension* extension_;
110 123
111 // The corresponding browser. 124 // The corresponding browser.
112 Browser* browser_; 125 Browser* browser_;
113 126
114 // The browser action this view represents. The ExtensionAction is not owned 127 // The browser action this view represents. The ExtensionAction is not owned
115 // by this class. 128 // by this class.
116 ExtensionAction* extension_action_; 129 ExtensionAction* extension_action_;
117 130
131 // The extension popup's host if the popup is visible; null otherwise.
132 extensions::ExtensionViewHost* popup_host_;
133
118 // The context menu model for the extension. 134 // The context menu model for the extension.
119 scoped_refptr<ExtensionContextMenuModel> context_menu_model_; 135 scoped_refptr<ExtensionContextMenuModel> context_menu_model_;
120 136
121 // Our view delegate. 137 // Our view delegate.
122 ToolbarActionViewDelegate* view_delegate_; 138 ToolbarActionViewDelegate* view_delegate_;
123 139
124 // The delegate to handle platform-specific implementations. 140 // The delegate to handle platform-specific implementations.
125 scoped_ptr<ExtensionActionPlatformDelegate> platform_delegate_; 141 scoped_ptr<ExtensionActionPlatformDelegate> platform_delegate_;
126 142
127 // The object that will be used to get the browser action icon for us. 143 // The object that will be used to get the browser action icon for us.
128 // It may load the icon asynchronously (in which case the initial icon 144 // It may load the icon asynchronously (in which case the initial icon
129 // returned by the factory will be transparent), so we have to observe it for 145 // returned by the factory will be transparent), so we have to observe it for
130 // updates to the icon. 146 // updates to the icon.
131 ExtensionActionIconFactory icon_factory_; 147 ExtensionActionIconFactory icon_factory_;
132 148
133 // An additional observer that we need to notify when the icon of the button 149 // An additional observer that we need to notify when the icon of the button
134 // has been updated. 150 // has been updated.
135 ExtensionActionIconFactory::Observer* icon_observer_; 151 ExtensionActionIconFactory::Observer* icon_observer_;
136 152
137 // The associated ExtensionRegistry; cached for quick checking. 153 // The associated ExtensionRegistry; cached for quick checking.
138 extensions::ExtensionRegistry* extension_registry_; 154 extensions::ExtensionRegistry* extension_registry_;
139 155
156 content::NotificationRegistrar registrar_;
157
140 DISALLOW_COPY_AND_ASSIGN(ExtensionActionViewController); 158 DISALLOW_COPY_AND_ASSIGN(ExtensionActionViewController);
141 }; 159 };
142 160
143 #endif // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_H_ 161 #endif // CHROME_BROWSER_UI_EXTENSIONS_EXTENSION_ACTION_VIEW_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698