blob: ec9f8a428bb45db83c7de0965240a51ef047e3e8 [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"
[email protected]00ee2f52014-04-25 09:25:5228#include "extensions/browser/extension_registry_observer.h"
[email protected]e9f541a2012-11-19 21:52:3129#include "extensions/common/url_pattern_set.h"
estade32426e02016-12-18 01:26:1730#include "ui/gfx/image/image.h"
[email protected]ea049a02011-12-25 21:37:0931
32namespace content {
[email protected]f5fede02014-07-29 02:48:2133class BrowserContext;
robcbe35ba2016-03-10 01:20:4934class RenderFrameHost;
[email protected]ea049a02011-12-25 21:37:0935class WebContents;
[email protected]35be7ec2012-02-12 20:42:5136struct ContextMenuParams;
[email protected]ea049a02011-12-25 21:37:0937}
[email protected]2e3b5202010-03-23 06:52:4138
[email protected]1c321ee52012-05-21 03:02:3439namespace extensions {
40class Extension;
[email protected]00ee2f52014-04-25 09:25:5241class ExtensionRegistry;
[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,
166 bool enabled,
167 Type type,
168 const ContextList& contexts);
169 virtual ~MenuItem();
[email protected]2e3b5202010-03-23 06:52:41170
171 // Simple accessor methods.
[email protected]9a4cb812012-05-23 20:32:32172 bool incognito() const { return id_.incognito; }
[email protected]6f9d2c62014-03-10 12:12:05173 const std::string& extension_id() const {
174 return id_.extension_key.extension_id;
175 }
[email protected]2e3b5202010-03-23 06:52:41176 const std::string& title() const { return title_; }
avi5d5b7e92016-10-21 01:11:40177 const OwnedList& children() { return children_; }
[email protected]f4f04592010-07-14 20:40:13178 const Id& id() const { return id_; }
179 Id* parent_id() const { return parent_id_.get(); }
[email protected]2e3b5202010-03-23 06:52:41180 int child_count() const { return children_.size(); }
[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_; }
[email protected]d4a8b7a2012-04-03 07:27:13184 bool enabled() const { return enabled_; }
[email protected]cced75a2011-05-20 08:31:12185 const URLPatternSet& document_url_patterns() const {
[email protected]9e9d7912010-07-18 21:05:28186 return document_url_patterns_;
187 }
[email protected]cced75a2011-05-20 08:31:12188 const URLPatternSet& target_url_patterns() const {
[email protected]9e9d7912010-07-18 21:05:28189 return target_url_patterns_;
190 }
[email protected]2e3b5202010-03-23 06:52:41191
[email protected]66dbfb2c2010-05-12 20:20:15192 // Simple mutator methods.
[email protected]48329f92011-03-28 19:38:22193 void set_title(const std::string& new_title) { title_ = new_title; }
[email protected]66dbfb2c2010-05-12 20:20:15194 void set_contexts(ContextList contexts) { contexts_ = contexts; }
[email protected]66dbfb2c2010-05-12 20:20:15195 void set_type(Type type) { type_ = type; }
[email protected]d4a8b7a2012-04-03 07:27:13196 void set_enabled(bool enabled) { enabled_ = enabled; }
[email protected]cced75a2011-05-20 08:31:12197 void set_document_url_patterns(const URLPatternSet& patterns) {
[email protected]9e9d7912010-07-18 21:05:28198 document_url_patterns_ = patterns;
199 }
[email protected]cced75a2011-05-20 08:31:12200 void set_target_url_patterns(const URLPatternSet& patterns) {
[email protected]9e9d7912010-07-18 21:05:28201 target_url_patterns_ = patterns;
202 }
[email protected]66dbfb2c2010-05-12 20:20:15203
[email protected]745feedb2010-08-02 04:08:07204 // Returns the title with any instances of %s replaced by |selection|. The
205 // result will be no longer than |max_length|.
[email protected]439f1e32013-12-09 20:09:09206 base::string16 TitleWithReplacement(const base::string16& selection,
[email protected]745feedb2010-08-02 04:08:07207 size_t max_length) const;
[email protected]2e3b5202010-03-23 06:52:41208
[email protected]a0011472012-05-30 17:15:40209 // Sets the checked state to |checked|. Returns true if successful.
[email protected]66dbfb2c2010-05-12 20:20:15210 bool SetChecked(bool checked);
211
[email protected]a0011472012-05-30 17:15:40212 // Converts to Value for serialization to preferences.
dchengc963c7142016-04-08 03:55:22213 std::unique_ptr<base::DictionaryValue> ToValue() const;
[email protected]a0011472012-05-30 17:15:40214
[email protected]5aeeae12012-07-05 19:13:11215 // Returns a new MenuItem created from |value|, or NULL if there is
avi5d5b7e92016-10-21 01:11:40216 // an error.
217 static std::unique_ptr<MenuItem> Populate(const std::string& extension_id,
218 const base::DictionaryValue& value,
219 std::string* error);
[email protected]a0011472012-05-30 17:15:40220
221 // Sets any document and target URL patterns from |properties|.
[email protected]8af81c02012-08-14 23:06:15222 bool PopulateURLPatterns(std::vector<std::string>* document_url_patterns,
223 std::vector<std::string>* target_url_patterns,
[email protected]a0011472012-05-30 17:15:40224 std::string* error);
225
[email protected]2e3b5202010-03-23 06:52:41226 protected:
[email protected]5aeeae12012-07-05 19:13:11227 friend class MenuManager;
[email protected]2e3b5202010-03-23 06:52:41228
avi5d5b7e92016-10-21 01:11:40229 // Adds |item| and sets its parent_id_.
230 void AddChild(std::unique_ptr<MenuItem> item);
[email protected]2e3b5202010-03-23 06:52:41231
avi5d5b7e92016-10-21 01:11:40232 // Removes the child item from this parent and returns it.
233 std::unique_ptr<MenuItem> ReleaseChild(const Id& child_id, bool recursive);
[email protected]66dbfb2c2010-05-12 20:20:15234
[email protected]a0011472012-05-30 17:15:40235 // Recursively appends all descendant items (children, grandchildren, etc.)
236 // to the output |list|.
[email protected]5aeeae12012-07-05 19:13:11237 void GetFlattenedSubtree(MenuItem::List* list);
[email protected]a0011472012-05-30 17:15:40238
[email protected]66dbfb2c2010-05-12 20:20:15239 // Recursively removes all descendant items (children, grandchildren, etc.),
240 // returning the ids of the removed items.
[email protected]f4f04592010-07-14 20:40:13241 std::set<Id> RemoveAllDescendants();
[email protected]66dbfb2c2010-05-12 20:20:15242
[email protected]2e3b5202010-03-23 06:52:41243 private:
[email protected]f4f04592010-07-14 20:40:13244 // The unique id for this item.
245 Id id_;
[email protected]2e3b5202010-03-23 06:52:41246
247 // What gets shown in the menu for this item.
248 std::string title_;
249
[email protected]2e3b5202010-03-23 06:52:41250 Type type_;
251
252 // This should only be true for items of type CHECKBOX or RADIO.
253 bool checked_;
254
[email protected]d4a8b7a2012-04-03 07:27:13255 // If the item is enabled or not.
256 bool enabled_;
257
[email protected]2e3b5202010-03-23 06:52:41258 // In what contexts should the item be shown?
259 ContextList contexts_;
260
[email protected]2e3b5202010-03-23 06:52:41261 // If this item is a child of another item, the unique id of its parent. If
[email protected]f4f04592010-07-14 20:40:13262 // this is a top-level item with no parent, this will be NULL.
dchengc963c7142016-04-08 03:55:22263 std::unique_ptr<Id> parent_id_;
[email protected]2e3b5202010-03-23 06:52:41264
[email protected]9e9d7912010-07-18 21:05:28265 // Patterns for restricting what documents this item will appear for. This
266 // applies to the frame where the click took place.
[email protected]cced75a2011-05-20 08:31:12267 URLPatternSet document_url_patterns_;
[email protected]9e9d7912010-07-18 21:05:28268
269 // Patterns for restricting where items appear based on the src/href
270 // attribute of IMAGE/AUDIO/VIDEO/LINK tags.
[email protected]cced75a2011-05-20 08:31:12271 URLPatternSet target_url_patterns_;
[email protected]9e9d7912010-07-18 21:05:28272
[email protected]2e3b5202010-03-23 06:52:41273 // Any children this item may have.
avi5d5b7e92016-10-21 01:11:40274 OwnedList children_;
[email protected]2e3b5202010-03-23 06:52:41275
[email protected]5aeeae12012-07-05 19:13:11276 DISALLOW_COPY_AND_ASSIGN(MenuItem);
[email protected]2e3b5202010-03-23 06:52:41277};
278
279// This class keeps track of menu items added by extensions.
[email protected]5aeeae12012-07-05 19:13:11280class MenuManager : public content::NotificationObserver,
[email protected]b673a5942013-11-14 11:14:19281 public base::SupportsWeakPtr<MenuManager>,
[email protected]00ee2f52014-04-25 09:25:52282 public KeyedService,
283 public ExtensionRegistryObserver {
[email protected]2e3b5202010-03-23 06:52:41284 public:
[email protected]db6bf7f2014-03-27 15:49:26285 static const char kOnContextMenus[];
286 static const char kOnWebviewContextMenus[];
287
[email protected]f5fede02014-07-29 02:48:21288 MenuManager(content::BrowserContext* context, StateStore* store_);
dchengae36a4a2014-10-21 12:36:36289 ~MenuManager() override;
[email protected]2e3b5202010-03-23 06:52:41290
[email protected]f5fede02014-07-29 02:48:21291 // Convenience function to get the MenuManager for a browser context.
292 static MenuManager* Get(content::BrowserContext* context);
[email protected]b673a5942013-11-14 11:14:19293
[email protected]6f9d2c62014-03-10 12:12:05294 // Returns the keys of extensions which have menu items registered.
295 std::set<MenuItem::ExtensionKey> ExtensionIds();
[email protected]2e3b5202010-03-23 06:52:41296
297 // Returns a list of all the *top-level* menu items (added via AddContextItem)
[email protected]6f9d2c62014-03-10 12:12:05298 // for the given extension specified by |extension_key|, *not* including child
299 // items (added via AddChildItem); although those can be reached via the
300 // top-level items' children. A view can then decide how to display these,
301 // including whether to put them into a submenu if there are more than 1.
avi5d5b7e92016-10-21 01:11:40302 const MenuItem::OwnedList* MenuItems(
303 const MenuItem::ExtensionKey& extension_key);
[email protected]2e3b5202010-03-23 06:52:41304
[email protected]052c92702010-06-25 07:25:52305 // Adds a top-level menu item for an extension, requiring the |extension|
avi5d5b7e92016-10-21 01:11:40306 // pointer so it can load the icon for the extension. Returns a boolean
307 // indicating success or failure.
308 bool AddContextItem(const Extension* extension,
309 std::unique_ptr<MenuItem> item);
[email protected]2e3b5202010-03-23 06:52:41310
avi5d5b7e92016-10-21 01:11:40311 // Add an item as a child of another item which has been previously added.
312 // Returns a boolean indicating success or failure.
[email protected]5aeeae12012-07-05 19:13:11313 bool AddChildItem(const MenuItem::Id& parent_id,
avi5d5b7e92016-10-21 01:11:40314 std::unique_ptr<MenuItem> child);
[email protected]2e3b5202010-03-23 06:52:41315
[email protected]66dbfb2c2010-05-12 20:20:15316 // Makes existing item with |child_id| a child of the item with |parent_id|.
317 // If the child item was already a child of another parent, this will remove
318 // 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:13319 // child of one of its own descendants. It is legal to pass NULL for
320 // |parent_id|, which means the item should be moved to the top-level.
[email protected]5aeeae12012-07-05 19:13:11321 bool ChangeParent(const MenuItem::Id& child_id,
322 const MenuItem::Id* parent_id);
[email protected]66dbfb2c2010-05-12 20:20:15323
[email protected]2e3b5202010-03-23 06:52:41324 // Removes a context menu item with the given id (whether it is a top-level
325 // item or a child of some other item), returning true if the item was found
326 // and removed or false otherwise.
[email protected]5aeeae12012-07-05 19:13:11327 bool RemoveContextMenuItem(const MenuItem::Id& id);
[email protected]2e3b5202010-03-23 06:52:41328
[email protected]6f9d2c62014-03-10 12:12:05329 // Removes all items for the given extension specified by |extension_key|.
330 void RemoveAllContextItems(const MenuItem::ExtensionKey& extension_key);
[email protected]66dbfb2c2010-05-12 20:20:15331
[email protected]2e3b5202010-03-23 06:52:41332 // Returns the item with the given |id| or NULL.
[email protected]5aeeae12012-07-05 19:13:11333 MenuItem* GetItemById(const MenuItem::Id& id) const;
[email protected]2e3b5202010-03-23 06:52:41334
[email protected]5aeeae12012-07-05 19:13:11335 // Notify the MenuManager that an item has been updated not through
336 // an explicit call into MenuManager. For example, if an item is
[email protected]7dddebc32012-01-11 22:01:03337 // acquired by a call to GetItemById and changed, then this should be called.
338 // Returns true if the item was found or false otherwise.
[email protected]5aeeae12012-07-05 19:13:11339 bool ItemUpdated(const MenuItem::Id& id);
[email protected]7dddebc32012-01-11 22:01:03340
[email protected]2e3b5202010-03-23 06:52:41341 // Called when a menu item is clicked on by the user.
[email protected]f5fede02014-07-29 02:48:21342 void ExecuteCommand(content::BrowserContext* context,
[email protected]33a86dbd2012-06-20 03:20:18343 content::WebContents* web_contents,
robcbe35ba2016-03-10 01:20:49344 content::RenderFrameHost* render_frame_host,
[email protected]35be7ec2012-02-12 20:42:51345 const content::ContextMenuParams& params,
[email protected]5aeeae12012-07-05 19:13:11346 const MenuItem::Id& menu_item_id);
[email protected]2e3b5202010-03-23 06:52:41347
estade32426e02016-12-18 01:26:17348 // This returns a image of width/height kFaviconSize, loaded either from an
[email protected]052c92702010-06-25 07:25:52349 // entry specified in the extension's 'icon' section of the manifest, or a
350 // default extension icon.
estade32426e02016-12-18 01:26:17351 gfx::Image GetIconForExtension(const std::string& extension_id);
[email protected]052c92702010-06-25 07:25:52352
[email protected]00ee2f52014-04-25 09:25:52353 // content::NotificationObserver implementation.
dchengae36a4a2014-10-21 12:36:36354 void Observe(int type,
355 const content::NotificationSource& source,
356 const content::NotificationDetails& details) override;
[email protected]052c92702010-06-25 07:25:52357
[email protected]00ee2f52014-04-25 09:25:52358 // ExtensionRegistryObserver implementation.
dchengae36a4a2014-10-21 12:36:36359 void OnExtensionLoaded(content::BrowserContext* browser_context,
360 const Extension* extension) override;
361 void OnExtensionUnloaded(content::BrowserContext* browser_context,
362 const Extension* extension,
363 UnloadedExtensionInfo::Reason reason) override;
[email protected]00ee2f52014-04-25 09:25:52364
[email protected]bec64552012-06-13 20:25:49365 // Stores the menu items for the extension in the state storage.
[email protected]6f9d2c62014-03-10 12:12:05366 void WriteToStorage(const Extension* extension,
367 const MenuItem::ExtensionKey& extension_key);
[email protected]a0011472012-05-30 17:15:40368
[email protected]bec64552012-06-13 20:25:49369 // Reads menu items for the extension from the state storage. Any invalid
[email protected]a0011472012-05-30 17:15:40370 // items are ignored.
[email protected]bec64552012-06-13 20:25:49371 void ReadFromStorage(const std::string& extension_id,
dchengc963c7142016-04-08 03:55:22372 std::unique_ptr<base::Value> value);
[email protected]a0011472012-05-30 17:15:40373
[email protected]63503462012-10-30 22:14:31374 // Removes all "incognito" "split" mode context items.
375 void RemoveAllIncognitoContextItems();
376
[email protected]2e3b5202010-03-23 06:52:41377 private:
[email protected]5aeeae12012-07-05 19:13:11378 FRIEND_TEST_ALL_PREFIXES(MenuManagerTest, DeleteParent);
379 FRIEND_TEST_ALL_PREFIXES(MenuManagerTest, RemoveOneByOne);
[email protected]2b07c93f2010-08-02 23:13:04380
[email protected]2e3b5202010-03-23 06:52:41381 // This is a helper function which takes care of de-selecting any other radio
382 // items in the same group (i.e. that are adjacent in the list).
[email protected]5aeeae12012-07-05 19:13:11383 void RadioItemSelected(MenuItem* item);
[email protected]2e3b5202010-03-23 06:52:41384
[email protected]7dddebc32012-01-11 22:01:03385 // Make sure that there is only one radio item selected at once in any run.
386 // If there are no radio items selected, then the first item in the run
387 // will get selected. If there are multiple radio items selected, then only
avi5d5b7e92016-10-21 01:11:40388 // the last one will get selected.
389 void SanitizeRadioList(const MenuItem::OwnedList& item_list);
[email protected]7dddebc32012-01-11 22:01:03390
[email protected]66dbfb2c2010-05-12 20:20:15391 // Returns true if item is a descendant of an item with id |ancestor_id|.
[email protected]5aeeae12012-07-05 19:13:11392 bool DescendantOf(MenuItem* item, const MenuItem::Id& ancestor_id);
[email protected]66dbfb2c2010-05-12 20:20:15393
[email protected]6f9d2c62014-03-10 12:12:05394 // We keep items organized by mapping ExtensionKey to a list of items.
avi5d5b7e92016-10-21 01:11:40395 std::map<MenuItem::ExtensionKey, MenuItem::OwnedList> context_items_;
[email protected]2e3b5202010-03-23 06:52:41396
[email protected]5aeeae12012-07-05 19:13:11397 // This lets us make lookup by id fast. It maps id to MenuItem* for
[email protected]2e3b5202010-03-23 06:52:41398 // all items the menu manager knows about, including all children of top-level
399 // items.
[email protected]5aeeae12012-07-05 19:13:11400 std::map<MenuItem::Id, MenuItem*> items_by_id_;
[email protected]2e3b5202010-03-23 06:52:41401
[email protected]6c2381d2011-10-19 02:52:53402 content::NotificationRegistrar registrar_;
[email protected]2e3b5202010-03-23 06:52:41403
[email protected]00ee2f52014-04-25 09:25:52404 // Listen to extension load, unloaded notifications.
405 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
406 extension_registry_observer_;
407
[email protected]b671760b2010-07-15 21:13:47408 ExtensionIconManager icon_manager_;
[email protected]052c92702010-06-25 07:25:52409
[email protected]f5fede02014-07-29 02:48:21410 content::BrowserContext* browser_context_;
[email protected]a0011472012-05-30 17:15:40411
[email protected]b673a5942013-11-14 11:14:19412 // Owned by ExtensionSystem.
413 StateStore* store_;
414
[email protected]5aeeae12012-07-05 19:13:11415 DISALLOW_COPY_AND_ASSIGN(MenuManager);
[email protected]2e3b5202010-03-23 06:52:41416};
417
[email protected]5aeeae12012-07-05 19:13:11418} // namespace extensions
419
420#endif // CHROME_BROWSER_EXTENSIONS_MENU_MANAGER_H_