blob: e44d27e9358f536cb4d8bd2351abe1166f9ef68f [file] [log] [blame]
[email protected]7dddebc32012-01-11 22:01:031// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]2e3b5202010-03-23 06:52:412// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]5aeeae12012-07-05 19:13:115#ifndef CHROME_BROWSER_EXTENSIONS_MENU_MANAGER_H_
6#define CHROME_BROWSER_EXTENSIONS_MENU_MANAGER_H_
[email protected]2e3b5202010-03-23 06:52:417
avia2f4804a2015-12-24 23:11:138#include <stddef.h>
9#include <stdint.h>
10
[email protected]2e3b5202010-03-23 06:52:4111#include <map>
dchengc963c7142016-04-08 03:55:2212#include <memory>
[email protected]2e3b5202010-03-23 06:52:4113#include <set>
14#include <string>
15#include <vector>
16
[email protected]17902752011-08-31 22:52:5417#include "base/compiler_specific.h"
[email protected]2b07c93f2010-08-02 23:13:0418#include "base/gtest_prod_util.h"
avia2f4804a2015-12-24 23:11:1319#include "base/macros.h"
[email protected]bec64552012-06-13 20:25:4920#include "base/memory/weak_ptr.h"
[email protected]00ee2f52014-04-25 09:25:5221#include "base/scoped_observer.h"
[email protected]46acbf12013-06-10 18:43:4222#include "base/strings/string16.h"
[email protected]a0011472012-05-30 17:15:4023#include "base/values.h"
[email protected]b671760b2010-07-15 21:13:4724#include "chrome/browser/extensions/extension_icon_manager.h"
[email protected]b33f0b112014-03-13 17:05:3025#include "components/keyed_service/core/keyed_service.h"
[email protected]6c2381d2011-10-19 02:52:5326#include "content/public/browser/notification_observer.h"
27#include "content/public/browser/notification_registrar.h"
Evan Stade75872a62019-09-06 21:17:3828#include "extensions/browser/extension_registry.h"
[email protected]00ee2f52014-04-25 09:25:5229#include "extensions/browser/extension_registry_observer.h"
[email protected]e9f541a2012-11-19 21:52:3130#include "extensions/common/url_pattern_set.h"
estade32426e02016-12-18 01:26:1731#include "ui/gfx/image/image.h"
[email protected]ea049a02011-12-25 21:37:0932
33namespace content {
[email protected]f5fede02014-07-29 02:48:2134class BrowserContext;
robcbe35ba2016-03-10 01:20:4935class RenderFrameHost;
[email protected]ea049a02011-12-25 21:37:0936class WebContents;
[email protected]35be7ec2012-02-12 20:42:5137struct ContextMenuParams;
[email protected]ea049a02011-12-25 21:37:0938}
[email protected]2e3b5202010-03-23 06:52:4139
[email protected]1c321ee52012-05-21 03:02:3440namespace extensions {
41class Extension;
[email protected]b673a5942013-11-14 11:14:1942class StateStore;
[email protected]1c321ee52012-05-21 03:02:3443
[email protected]2e3b5202010-03-23 06:52:4144// Represents a menu item added by an extension.
[email protected]5aeeae12012-07-05 19:13:1145class MenuItem {
[email protected]2e3b5202010-03-23 06:52:4146 public:
avi5d5b7e92016-10-21 01:11:4047 using List = std::vector<MenuItem*>;
48 using OwnedList = std::vector<std::unique_ptr<MenuItem>>;
[email protected]2e3b5202010-03-23 06:52:4149
paulmeyered437262015-07-09 16:05:2950 // Key used to identify which extension a menu item belongs to. A menu item
51 // can also belong to a <webview>, in which case |webview_embedder_process_id|
52 // and |webview_instance_id| will be non-zero. When two ExtensionKeys are
53 // compared, an empty |extension_id| will match any other extension ID. This
54 // allows menu items belonging to webviews to be found with only the two
55 // webview IDs when the extension ID is not known. This is currently done from
56 // ChromeExtensionsBrowserClient::CleanUpWebView().
[email protected]6f9d2c62014-03-10 12:12:0557 struct ExtensionKey {
58 std::string extension_id;
paulmeyered437262015-07-09 16:05:2959 int webview_embedder_process_id;
[email protected]6f9d2c62014-03-10 12:12:0560 int webview_instance_id;
61
62 ExtensionKey();
[email protected]6f9d2c62014-03-10 12:12:0563 explicit ExtensionKey(const std::string& extension_id);
paulmeyered437262015-07-09 16:05:2964 ExtensionKey(const std::string& extension_id,
65 int webview_embedder_process_id,
66 int webview_instance_id);
[email protected]6f9d2c62014-03-10 12:12:0567
68 bool operator==(const ExtensionKey& other) const;
69 bool operator!=(const ExtensionKey& other) const;
70 bool operator<(const ExtensionKey& other) const;
71
72 bool empty() const;
73 };
74
[email protected]5a7b5eaf2010-11-02 20:52:1975 // An Id uniquely identifies a context menu item registered by an extension.
76 struct Id {
77 Id();
[email protected]619c5dba2012-05-16 00:44:4878 // Since the unique ID (uid or string_uid) is parsed from API arguments,
79 // the normal usage is to set the uid or string_uid immediately after
80 // construction.
[email protected]6f9d2c62014-03-10 12:12:0581 Id(bool incognito, const ExtensionKey& extension_key);
[email protected]5a7b5eaf2010-11-02 20:52:1982 ~Id();
83
84 bool operator==(const Id& other) const;
85 bool operator!=(const Id& other) const;
86 bool operator<(const Id& other) const;
87
[email protected]9a4cb812012-05-23 20:32:3288 bool incognito;
[email protected]6f9d2c62014-03-10 12:12:0589 ExtensionKey extension_key;
[email protected]619c5dba2012-05-16 00:44:4890 // Only one of uid or string_uid will be defined.
[email protected]5a7b5eaf2010-11-02 20:52:1991 int uid;
[email protected]619c5dba2012-05-16 00:44:4892 std::string string_uid;
[email protected]5a7b5eaf2010-11-02 20:52:1993 };
[email protected]9e9d7912010-07-18 21:05:2894
[email protected]a11fa342010-07-09 16:56:0095 // For context menus, these are the contexts where an item can appear.
[email protected]2e3b5202010-03-23 06:52:4196 enum Context {
97 ALL = 1,
98 PAGE = 2,
99 SELECTION = 4,
100 LINK = 8,
101 EDITABLE = 16,
102 IMAGE = 32,
103 VIDEO = 64,
104 AUDIO = 128,
[email protected]0e5e8d52011-04-06 21:02:51105 FRAME = 256,
[email protected]69e1c12d2014-08-13 08:25:34106 LAUNCHER = 512,
107 BROWSER_ACTION = 1024,
108 PAGE_ACTION = 2048
[email protected]2e3b5202010-03-23 06:52:41109 };
110
111 // An item can be only one of these types.
112 enum Type {
113 NORMAL,
114 CHECKBOX,
115 RADIO,
116 SEPARATOR
117 };
118
[email protected]a11fa342010-07-09 16:56:00119 // A list of Contexts for an item.
[email protected]2e3b5202010-03-23 06:52:41120 class ContextList {
121 public:
122 ContextList() : value_(0) {}
123 explicit ContextList(Context context) : value_(context) {}
124 ContextList(const ContextList& other) : value_(other.value_) {}
125
126 void operator=(const ContextList& other) {
127 value_ = other.value_;
128 }
129
[email protected]66dbfb2c2010-05-12 20:20:15130 bool operator==(const ContextList& other) const {
131 return value_ == other.value_;
132 }
133
134 bool operator!=(const ContextList& other) const {
135 return !(*this == other);
136 }
137
[email protected]2e3b5202010-03-23 06:52:41138 bool Contains(Context context) const {
139 return (value_ & context) > 0;
140 }
141
142 void Add(Context context) {
143 value_ |= context;
144 }
145
dchengc963c7142016-04-08 03:55:22146 std::unique_ptr<base::Value> ToValue() const {
147 return std::unique_ptr<base::Value>(
jdoerrie239723572017-03-02 12:09:19148 new base::Value(static_cast<int>(value_)));
[email protected]a0011472012-05-30 17:15:40149 }
150
[email protected]aeca23f2013-06-21 22:34:41151 bool Populate(const base::Value& value) {
[email protected]a0011472012-05-30 17:15:40152 int int_value;
153 if (!value.GetAsInteger(&int_value) || int_value < 0)
154 return false;
155 value_ = int_value;
156 return true;
157 }
158
[email protected]2e3b5202010-03-23 06:52:41159 private:
avia2f4804a2015-12-24 23:11:13160 uint32_t value_; // A bitmask of Context values.
[email protected]2e3b5202010-03-23 06:52:41161 };
162
[email protected]5aeeae12012-07-05 19:13:11163 MenuItem(const Id& id,
164 const std::string& title,
165 bool checked,
catmullingsff2cdbc2017-08-22 22:07:02166 bool visible,
[email protected]5aeeae12012-07-05 19:13:11167 bool enabled,
168 Type type,
169 const ContextList& contexts);
170 virtual ~MenuItem();
[email protected]2e3b5202010-03-23 06:52:41171
172 // Simple accessor methods.
[email protected]9a4cb812012-05-23 20:32:32173 bool incognito() const { return id_.incognito; }
[email protected]6f9d2c62014-03-10 12:12:05174 const std::string& extension_id() const {
175 return id_.extension_key.extension_id;
176 }
[email protected]2e3b5202010-03-23 06:52:41177 const std::string& title() const { return title_; }
avi5d5b7e92016-10-21 01:11:40178 const OwnedList& children() { return children_; }
[email protected]f4f04592010-07-14 20:40:13179 const Id& id() const { return id_; }
180 Id* parent_id() const { return parent_id_.get(); }
[email protected]69e1c12d2014-08-13 08:25:34181 const ContextList& contexts() const { return contexts_; }
[email protected]2e3b5202010-03-23 06:52:41182 Type type() const { return type_; }
183 bool checked() const { return checked_; }
catmullingsff2cdbc2017-08-22 22:07:02184 bool visible() const { return visible_; }
[email protected]d4a8b7a2012-04-03 07:27:13185 bool enabled() const { return enabled_; }
[email protected]cced75a2011-05-20 08:31:12186 const URLPatternSet& document_url_patterns() const {
[email protected]9e9d7912010-07-18 21:05:28187 return document_url_patterns_;
188 }
[email protected]cced75a2011-05-20 08:31:12189 const URLPatternSet& target_url_patterns() const {
[email protected]9e9d7912010-07-18 21:05:28190 return target_url_patterns_;
191 }
[email protected]2e3b5202010-03-23 06:52:41192
[email protected]66dbfb2c2010-05-12 20:20:15193 // Simple mutator methods.
[email protected]48329f92011-03-28 19:38:22194 void set_title(const std::string& new_title) { title_ = new_title; }
[email protected]66dbfb2c2010-05-12 20:20:15195 void set_contexts(ContextList contexts) { contexts_ = contexts; }
[email protected]66dbfb2c2010-05-12 20:20:15196 void set_type(Type type) { type_ = type; }
catmullingsff2cdbc2017-08-22 22:07:02197 void set_visible(bool visible) { visible_ = visible; }
[email protected]d4a8b7a2012-04-03 07:27:13198 void set_enabled(bool enabled) { enabled_ = enabled; }
[email protected]cced75a2011-05-20 08:31:12199 void set_document_url_patterns(const URLPatternSet& patterns) {
Devlin Cronin11860c982018-12-14 20:18:27200 document_url_patterns_ = patterns.Clone();
[email protected]9e9d7912010-07-18 21:05:28201 }
[email protected]cced75a2011-05-20 08:31:12202 void set_target_url_patterns(const URLPatternSet& patterns) {
Devlin Cronin11860c982018-12-14 20:18:27203 target_url_patterns_ = patterns.Clone();
[email protected]9e9d7912010-07-18 21:05:28204 }
[email protected]66dbfb2c2010-05-12 20:20:15205
[email protected]745feedb2010-08-02 04:08:07206 // Returns the title with any instances of %s replaced by |selection|. The
207 // result will be no longer than |max_length|.
[email protected]439f1e32013-12-09 20:09:09208 base::string16 TitleWithReplacement(const base::string16& selection,
[email protected]745feedb2010-08-02 04:08:07209 size_t max_length) const;
[email protected]2e3b5202010-03-23 06:52:41210
[email protected]a0011472012-05-30 17:15:40211 // Sets the checked state to |checked|. Returns true if successful.
[email protected]66dbfb2c2010-05-12 20:20:15212 bool SetChecked(bool checked);
213
[email protected]a0011472012-05-30 17:15:40214 // Converts to Value for serialization to preferences.
dchengc963c7142016-04-08 03:55:22215 std::unique_ptr<base::DictionaryValue> ToValue() const;
[email protected]a0011472012-05-30 17:15:40216
[email protected]5aeeae12012-07-05 19:13:11217 // Returns a new MenuItem created from |value|, or NULL if there is
avi5d5b7e92016-10-21 01:11:40218 // an error.
219 static std::unique_ptr<MenuItem> Populate(const std::string& extension_id,
220 const base::DictionaryValue& value,
221 std::string* error);
[email protected]a0011472012-05-30 17:15:40222
223 // Sets any document and target URL patterns from |properties|.
[email protected]8af81c02012-08-14 23:06:15224 bool PopulateURLPatterns(std::vector<std::string>* document_url_patterns,
225 std::vector<std::string>* target_url_patterns,
[email protected]a0011472012-05-30 17:15:40226 std::string* error);
227
[email protected]2e3b5202010-03-23 06:52:41228 protected:
[email protected]5aeeae12012-07-05 19:13:11229 friend class MenuManager;
[email protected]2e3b5202010-03-23 06:52:41230
avi5d5b7e92016-10-21 01:11:40231 // Adds |item| and sets its parent_id_.
232 void AddChild(std::unique_ptr<MenuItem> item);
[email protected]2e3b5202010-03-23 06:52:41233
avi5d5b7e92016-10-21 01:11:40234 // Removes the child item from this parent and returns it.
235 std::unique_ptr<MenuItem> ReleaseChild(const Id& child_id, bool recursive);
[email protected]66dbfb2c2010-05-12 20:20:15236
[email protected]a0011472012-05-30 17:15:40237 // Recursively appends all descendant items (children, grandchildren, etc.)
238 // to the output |list|.
[email protected]5aeeae12012-07-05 19:13:11239 void GetFlattenedSubtree(MenuItem::List* list);
[email protected]a0011472012-05-30 17:15:40240
[email protected]66dbfb2c2010-05-12 20:20:15241 // Recursively removes all descendant items (children, grandchildren, etc.),
242 // returning the ids of the removed items.
[email protected]f4f04592010-07-14 20:40:13243 std::set<Id> RemoveAllDescendants();
[email protected]66dbfb2c2010-05-12 20:20:15244
[email protected]2e3b5202010-03-23 06:52:41245 private:
[email protected]f4f04592010-07-14 20:40:13246 // The unique id for this item.
247 Id id_;
[email protected]2e3b5202010-03-23 06:52:41248
249 // What gets shown in the menu for this item.
250 std::string title_;
251
[email protected]2e3b5202010-03-23 06:52:41252 Type type_;
253
254 // This should only be true for items of type CHECKBOX or RADIO.
255 bool checked_;
256
catmullingsff2cdbc2017-08-22 22:07:02257 // If the item is visible (shown or hidden) in the menu.
258 bool visible_;
259
[email protected]d4a8b7a2012-04-03 07:27:13260 // If the item is enabled or not.
261 bool enabled_;
262
[email protected]2e3b5202010-03-23 06:52:41263 // In what contexts should the item be shown?
264 ContextList contexts_;
265
[email protected]2e3b5202010-03-23 06:52:41266 // If this item is a child of another item, the unique id of its parent. If
[email protected]f4f04592010-07-14 20:40:13267 // this is a top-level item with no parent, this will be NULL.
dchengc963c7142016-04-08 03:55:22268 std::unique_ptr<Id> parent_id_;
[email protected]2e3b5202010-03-23 06:52:41269
[email protected]9e9d7912010-07-18 21:05:28270 // Patterns for restricting what documents this item will appear for. This
271 // applies to the frame where the click took place.
[email protected]cced75a2011-05-20 08:31:12272 URLPatternSet document_url_patterns_;
[email protected]9e9d7912010-07-18 21:05:28273
274 // Patterns for restricting where items appear based on the src/href
275 // attribute of IMAGE/AUDIO/VIDEO/LINK tags.
[email protected]cced75a2011-05-20 08:31:12276 URLPatternSet target_url_patterns_;
[email protected]9e9d7912010-07-18 21:05:28277
[email protected]2e3b5202010-03-23 06:52:41278 // Any children this item may have.
avi5d5b7e92016-10-21 01:11:40279 OwnedList children_;
[email protected]2e3b5202010-03-23 06:52:41280
[email protected]5aeeae12012-07-05 19:13:11281 DISALLOW_COPY_AND_ASSIGN(MenuItem);
[email protected]2e3b5202010-03-23 06:52:41282};
283
284// This class keeps track of menu items added by extensions.
[email protected]5aeeae12012-07-05 19:13:11285class MenuManager : public content::NotificationObserver,
[email protected]b673a5942013-11-14 11:14:19286 public base::SupportsWeakPtr<MenuManager>,
[email protected]00ee2f52014-04-25 09:25:52287 public KeyedService,
288 public ExtensionRegistryObserver {
[email protected]2e3b5202010-03-23 06:52:41289 public:
[email protected]db6bf7f2014-03-27 15:49:26290 static const char kOnContextMenus[];
291 static const char kOnWebviewContextMenus[];
292
[email protected]f5fede02014-07-29 02:48:21293 MenuManager(content::BrowserContext* context, StateStore* store_);
dchengae36a4a2014-10-21 12:36:36294 ~MenuManager() override;
[email protected]2e3b5202010-03-23 06:52:41295
[email protected]f5fede02014-07-29 02:48:21296 // Convenience function to get the MenuManager for a browser context.
297 static MenuManager* Get(content::BrowserContext* context);
[email protected]b673a5942013-11-14 11:14:19298
[email protected]6f9d2c62014-03-10 12:12:05299 // Returns the keys of extensions which have menu items registered.
300 std::set<MenuItem::ExtensionKey> ExtensionIds();
[email protected]2e3b5202010-03-23 06:52:41301
302 // Returns a list of all the *top-level* menu items (added via AddContextItem)
[email protected]6f9d2c62014-03-10 12:12:05303 // for the given extension specified by |extension_key|, *not* including child
304 // items (added via AddChildItem); although those can be reached via the
305 // top-level items' children. A view can then decide how to display these,
306 // including whether to put them into a submenu if there are more than 1.
avi5d5b7e92016-10-21 01:11:40307 const MenuItem::OwnedList* MenuItems(
308 const MenuItem::ExtensionKey& extension_key);
[email protected]2e3b5202010-03-23 06:52:41309
[email protected]052c92702010-06-25 07:25:52310 // Adds a top-level menu item for an extension, requiring the |extension|
avi5d5b7e92016-10-21 01:11:40311 // pointer so it can load the icon for the extension. Returns a boolean
312 // indicating success or failure.
313 bool AddContextItem(const Extension* extension,
314 std::unique_ptr<MenuItem> item);
[email protected]2e3b5202010-03-23 06:52:41315
avi5d5b7e92016-10-21 01:11:40316 // Add an item as a child of another item which has been previously added.
317 // Returns a boolean indicating success or failure.
[email protected]5aeeae12012-07-05 19:13:11318 bool AddChildItem(const MenuItem::Id& parent_id,
avi5d5b7e92016-10-21 01:11:40319 std::unique_ptr<MenuItem> child);
[email protected]2e3b5202010-03-23 06:52:41320
[email protected]66dbfb2c2010-05-12 20:20:15321 // Makes existing item with |child_id| a child of the item with |parent_id|.
322 // If the child item was already a child of another parent, this will remove
323 // it from that parent first. It is an error to try and move an item to be a
[email protected]f4f04592010-07-14 20:40:13324 // child of one of its own descendants. It is legal to pass NULL for
325 // |parent_id|, which means the item should be moved to the top-level.
[email protected]5aeeae12012-07-05 19:13:11326 bool ChangeParent(const MenuItem::Id& child_id,
327 const MenuItem::Id* parent_id);
[email protected]66dbfb2c2010-05-12 20:20:15328
[email protected]2e3b5202010-03-23 06:52:41329 // Removes a context menu item with the given id (whether it is a top-level
330 // item or a child of some other item), returning true if the item was found
331 // and removed or false otherwise.
[email protected]5aeeae12012-07-05 19:13:11332 bool RemoveContextMenuItem(const MenuItem::Id& id);
[email protected]2e3b5202010-03-23 06:52:41333
[email protected]6f9d2c62014-03-10 12:12:05334 // Removes all items for the given extension specified by |extension_key|.
335 void RemoveAllContextItems(const MenuItem::ExtensionKey& extension_key);
[email protected]66dbfb2c2010-05-12 20:20:15336
[email protected]2e3b5202010-03-23 06:52:41337 // Returns the item with the given |id| or NULL.
[email protected]5aeeae12012-07-05 19:13:11338 MenuItem* GetItemById(const MenuItem::Id& id) const;
[email protected]2e3b5202010-03-23 06:52:41339
[email protected]5aeeae12012-07-05 19:13:11340 // Notify the MenuManager that an item has been updated not through
341 // an explicit call into MenuManager. For example, if an item is
[email protected]7dddebc32012-01-11 22:01:03342 // acquired by a call to GetItemById and changed, then this should be called.
343 // Returns true if the item was found or false otherwise.
[email protected]5aeeae12012-07-05 19:13:11344 bool ItemUpdated(const MenuItem::Id& id);
[email protected]7dddebc32012-01-11 22:01:03345
[email protected]2e3b5202010-03-23 06:52:41346 // Called when a menu item is clicked on by the user.
[email protected]f5fede02014-07-29 02:48:21347 void ExecuteCommand(content::BrowserContext* context,
[email protected]33a86dbd2012-06-20 03:20:18348 content::WebContents* web_contents,
robcbe35ba2016-03-10 01:20:49349 content::RenderFrameHost* render_frame_host,
[email protected]35be7ec2012-02-12 20:42:51350 const content::ContextMenuParams& params,
[email protected]5aeeae12012-07-05 19:13:11351 const MenuItem::Id& menu_item_id);
[email protected]2e3b5202010-03-23 06:52:41352
estade32426e02016-12-18 01:26:17353 // This returns a image of width/height kFaviconSize, loaded either from an
[email protected]052c92702010-06-25 07:25:52354 // entry specified in the extension's 'icon' section of the manifest, or a
355 // default extension icon.
estade32426e02016-12-18 01:26:17356 gfx::Image GetIconForExtension(const std::string& extension_id);
[email protected]052c92702010-06-25 07:25:52357
[email protected]00ee2f52014-04-25 09:25:52358 // content::NotificationObserver implementation.
dchengae36a4a2014-10-21 12:36:36359 void Observe(int type,
360 const content::NotificationSource& source,
361 const content::NotificationDetails& details) override;
[email protected]052c92702010-06-25 07:25:52362
[email protected]00ee2f52014-04-25 09:25:52363 // ExtensionRegistryObserver implementation.
dchengae36a4a2014-10-21 12:36:36364 void OnExtensionLoaded(content::BrowserContext* browser_context,
365 const Extension* extension) override;
366 void OnExtensionUnloaded(content::BrowserContext* browser_context,
367 const Extension* extension,
limasdf0deef2042017-05-03 19:17:17368 UnloadedExtensionReason reason) override;
[email protected]00ee2f52014-04-25 09:25:52369
[email protected]bec64552012-06-13 20:25:49370 // Stores the menu items for the extension in the state storage.
[email protected]6f9d2c62014-03-10 12:12:05371 void WriteToStorage(const Extension* extension,
372 const MenuItem::ExtensionKey& extension_key);
[email protected]a0011472012-05-30 17:15:40373
[email protected]bec64552012-06-13 20:25:49374 // Reads menu items for the extension from the state storage. Any invalid
[email protected]a0011472012-05-30 17:15:40375 // items are ignored.
[email protected]bec64552012-06-13 20:25:49376 void ReadFromStorage(const std::string& extension_id,
dchengc963c7142016-04-08 03:55:22377 std::unique_ptr<base::Value> value);
[email protected]a0011472012-05-30 17:15:40378
[email protected]63503462012-10-30 22:14:31379 // Removes all "incognito" "split" mode context items.
380 void RemoveAllIncognitoContextItems();
381
[email protected]2e3b5202010-03-23 06:52:41382 private:
[email protected]5aeeae12012-07-05 19:13:11383 FRIEND_TEST_ALL_PREFIXES(MenuManagerTest, DeleteParent);
384 FRIEND_TEST_ALL_PREFIXES(MenuManagerTest, RemoveOneByOne);
[email protected]2b07c93f2010-08-02 23:13:04385
[email protected]2e3b5202010-03-23 06:52:41386 // This is a helper function which takes care of de-selecting any other radio
387 // items in the same group (i.e. that are adjacent in the list).
[email protected]5aeeae12012-07-05 19:13:11388 void RadioItemSelected(MenuItem* item);
[email protected]2e3b5202010-03-23 06:52:41389
[email protected]7dddebc32012-01-11 22:01:03390 // Make sure that there is only one radio item selected at once in any run.
391 // If there are no radio items selected, then the first item in the run
392 // will get selected. If there are multiple radio items selected, then only
avi5d5b7e92016-10-21 01:11:40393 // the last one will get selected.
Catherine Mullings97a2769d2017-08-04 17:55:20394 void SanitizeRadioListsInMenu(const MenuItem::OwnedList& item_list);
[email protected]7dddebc32012-01-11 22:01:03395
[email protected]66dbfb2c2010-05-12 20:20:15396 // Returns true if item is a descendant of an item with id |ancestor_id|.
[email protected]5aeeae12012-07-05 19:13:11397 bool DescendantOf(MenuItem* item, const MenuItem::Id& ancestor_id);
[email protected]66dbfb2c2010-05-12 20:20:15398
[email protected]6f9d2c62014-03-10 12:12:05399 // We keep items organized by mapping ExtensionKey to a list of items.
avi5d5b7e92016-10-21 01:11:40400 std::map<MenuItem::ExtensionKey, MenuItem::OwnedList> context_items_;
[email protected]2e3b5202010-03-23 06:52:41401
[email protected]5aeeae12012-07-05 19:13:11402 // This lets us make lookup by id fast. It maps id to MenuItem* for
[email protected]2e3b5202010-03-23 06:52:41403 // all items the menu manager knows about, including all children of top-level
404 // items.
[email protected]5aeeae12012-07-05 19:13:11405 std::map<MenuItem::Id, MenuItem*> items_by_id_;
[email protected]2e3b5202010-03-23 06:52:41406
[email protected]6c2381d2011-10-19 02:52:53407 content::NotificationRegistrar registrar_;
[email protected]2e3b5202010-03-23 06:52:41408
[email protected]00ee2f52014-04-25 09:25:52409 // Listen to extension load, unloaded notifications.
410 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
Evan Stade75872a62019-09-06 21:17:38411 extension_registry_observer_{this};
[email protected]00ee2f52014-04-25 09:25:52412
[email protected]b671760b2010-07-15 21:13:47413 ExtensionIconManager icon_manager_;
[email protected]052c92702010-06-25 07:25:52414
[email protected]f5fede02014-07-29 02:48:21415 content::BrowserContext* browser_context_;
[email protected]a0011472012-05-30 17:15:40416
[email protected]b673a5942013-11-14 11:14:19417 // Owned by ExtensionSystem.
418 StateStore* store_;
419
[email protected]5aeeae12012-07-05 19:13:11420 DISALLOW_COPY_AND_ASSIGN(MenuManager);
[email protected]2e3b5202010-03-23 06:52:41421};
422
[email protected]5aeeae12012-07-05 19:13:11423} // namespace extensions
424
425#endif // CHROME_BROWSER_EXTENSIONS_MENU_MANAGER_H_