blob: 7386d9ab57a435cdee99b6644466225f00ffde8a [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>
12#include <set>
13#include <string>
14#include <vector>
15
[email protected]17902752011-08-31 22:52:5416#include "base/compiler_specific.h"
[email protected]2b07c93f2010-08-02 23:13:0417#include "base/gtest_prod_util.h"
avia2f4804a2015-12-24 23:11:1318#include "base/macros.h"
[email protected]3b63f8f42011-03-28 01:54:1519#include "base/memory/scoped_ptr.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"
[email protected]2e3b5202010-03-23 06:52:4130
[email protected]b671760b2010-07-15 21:13:4731class SkBitmap;
[email protected]ea049a02011-12-25 21:37:0932
33namespace content {
[email protected]f5fede02014-07-29 02:48:2134class BrowserContext;
[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:
[email protected]5aeeae12012-07-05 19:13:1147 // A list of MenuItems.
48 typedef std::vector<MenuItem*> List;
[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
[email protected]aeca23f2013-06-21 22:34:41146 scoped_ptr<base::Value> ToValue() const {
[email protected]aa15e2e2013-08-14 02:13:58147 return scoped_ptr<base::Value>(
148 new base::FundamentalValue(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_; }
[email protected]63a414b52010-06-03 23:20:49177 const List& 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.
213 scoped_ptr<base::DictionaryValue> ToValue() const;
214
[email protected]5aeeae12012-07-05 19:13:11215 // Returns a new MenuItem created from |value|, or NULL if there is
216 // an error. The caller takes ownership of the MenuItem.
217 static MenuItem* Populate(const std::string& extension_id,
[email protected]aeca23f2013-06-21 22:34:41218 const base::DictionaryValue& value,
[email protected]5aeeae12012-07-05 19:13:11219 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
[email protected]2e3b5202010-03-23 06:52:41229 // Takes ownership of |item| and sets its parent_id_.
[email protected]5aeeae12012-07-05 19:13:11230 void AddChild(MenuItem* item);
[email protected]2e3b5202010-03-23 06:52:41231
[email protected]66dbfb2c2010-05-12 20:20:15232 // Takes the child item from this parent. The item is returned and the caller
233 // then owns the pointer.
[email protected]5aeeae12012-07-05 19:13:11234 MenuItem* ReleaseChild(const Id& child_id, bool recursive);
[email protected]66dbfb2c2010-05-12 20:20:15235
[email protected]a0011472012-05-30 17:15:40236 // Recursively appends all descendant items (children, grandchildren, etc.)
237 // to the output |list|.
[email protected]5aeeae12012-07-05 19:13:11238 void GetFlattenedSubtree(MenuItem::List* list);
[email protected]a0011472012-05-30 17:15:40239
[email protected]66dbfb2c2010-05-12 20:20:15240 // Recursively removes all descendant items (children, grandchildren, etc.),
241 // returning the ids of the removed items.
[email protected]f4f04592010-07-14 20:40:13242 std::set<Id> RemoveAllDescendants();
[email protected]66dbfb2c2010-05-12 20:20:15243
[email protected]2e3b5202010-03-23 06:52:41244 private:
[email protected]f4f04592010-07-14 20:40:13245 // The unique id for this item.
246 Id id_;
[email protected]2e3b5202010-03-23 06:52:41247
248 // What gets shown in the menu for this item.
249 std::string title_;
250
[email protected]2e3b5202010-03-23 06:52:41251 Type type_;
252
253 // This should only be true for items of type CHECKBOX or RADIO.
254 bool checked_;
255
[email protected]d4a8b7a2012-04-03 07:27:13256 // If the item is enabled or not.
257 bool enabled_;
258
[email protected]2e3b5202010-03-23 06:52:41259 // In what contexts should the item be shown?
260 ContextList contexts_;
261
[email protected]2e3b5202010-03-23 06:52:41262 // If this item is a child of another item, the unique id of its parent. If
[email protected]f4f04592010-07-14 20:40:13263 // this is a top-level item with no parent, this will be NULL.
264 scoped_ptr<Id> parent_id_;
[email protected]2e3b5202010-03-23 06:52:41265
[email protected]9e9d7912010-07-18 21:05:28266 // Patterns for restricting what documents this item will appear for. This
267 // applies to the frame where the click took place.
[email protected]cced75a2011-05-20 08:31:12268 URLPatternSet document_url_patterns_;
[email protected]9e9d7912010-07-18 21:05:28269
270 // Patterns for restricting where items appear based on the src/href
271 // attribute of IMAGE/AUDIO/VIDEO/LINK tags.
[email protected]cced75a2011-05-20 08:31:12272 URLPatternSet target_url_patterns_;
[email protected]9e9d7912010-07-18 21:05:28273
[email protected]2e3b5202010-03-23 06:52:41274 // Any children this item may have.
275 List children_;
276
[email protected]5aeeae12012-07-05 19:13:11277 DISALLOW_COPY_AND_ASSIGN(MenuItem);
[email protected]2e3b5202010-03-23 06:52:41278};
279
280// This class keeps track of menu items added by extensions.
[email protected]5aeeae12012-07-05 19:13:11281class MenuManager : public content::NotificationObserver,
[email protected]b673a5942013-11-14 11:14:19282 public base::SupportsWeakPtr<MenuManager>,
[email protected]00ee2f52014-04-25 09:25:52283 public KeyedService,
284 public ExtensionRegistryObserver {
[email protected]2e3b5202010-03-23 06:52:41285 public:
[email protected]db6bf7f2014-03-27 15:49:26286 static const char kOnContextMenus[];
287 static const char kOnWebviewContextMenus[];
288
[email protected]f5fede02014-07-29 02:48:21289 MenuManager(content::BrowserContext* context, StateStore* store_);
dchengae36a4a2014-10-21 12:36:36290 ~MenuManager() override;
[email protected]2e3b5202010-03-23 06:52:41291
[email protected]f5fede02014-07-29 02:48:21292 // Convenience function to get the MenuManager for a browser context.
293 static MenuManager* Get(content::BrowserContext* context);
[email protected]b673a5942013-11-14 11:14:19294
[email protected]6f9d2c62014-03-10 12:12:05295 // Returns the keys of extensions which have menu items registered.
296 std::set<MenuItem::ExtensionKey> ExtensionIds();
[email protected]2e3b5202010-03-23 06:52:41297
298 // Returns a list of all the *top-level* menu items (added via AddContextItem)
[email protected]6f9d2c62014-03-10 12:12:05299 // for the given extension specified by |extension_key|, *not* including child
300 // items (added via AddChildItem); although those can be reached via the
301 // top-level items' children. A view can then decide how to display these,
302 // including whether to put them into a submenu if there are more than 1.
303 const MenuItem::List* MenuItems(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|
306 // pointer so it can load the icon for the extension. Takes ownership of
[email protected]f4f04592010-07-14 20:40:13307 // |item|. Returns a boolean indicating success or failure.
[email protected]5aeeae12012-07-05 19:13:11308 bool AddContextItem(const Extension* extension, MenuItem* item);
[email protected]2e3b5202010-03-23 06:52:41309
310 // Add an item as a child of another item which has been previously added, and
[email protected]f4f04592010-07-14 20:40:13311 // takes ownership of |item|. Returns a boolean indicating success or failure.
[email protected]5aeeae12012-07-05 19:13:11312 bool AddChildItem(const MenuItem::Id& parent_id,
313 MenuItem* child);
[email protected]2e3b5202010-03-23 06:52:41314
[email protected]66dbfb2c2010-05-12 20:20:15315 // Makes existing item with |child_id| a child of the item with |parent_id|.
316 // If the child item was already a child of another parent, this will remove
317 // 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:13318 // child of one of its own descendants. It is legal to pass NULL for
319 // |parent_id|, which means the item should be moved to the top-level.
[email protected]5aeeae12012-07-05 19:13:11320 bool ChangeParent(const MenuItem::Id& child_id,
321 const MenuItem::Id* parent_id);
[email protected]66dbfb2c2010-05-12 20:20:15322
[email protected]2e3b5202010-03-23 06:52:41323 // Removes a context menu item with the given id (whether it is a top-level
324 // item or a child of some other item), returning true if the item was found
325 // and removed or false otherwise.
[email protected]5aeeae12012-07-05 19:13:11326 bool RemoveContextMenuItem(const MenuItem::Id& id);
[email protected]2e3b5202010-03-23 06:52:41327
[email protected]6f9d2c62014-03-10 12:12:05328 // Removes all items for the given extension specified by |extension_key|.
329 void RemoveAllContextItems(const MenuItem::ExtensionKey& extension_key);
[email protected]66dbfb2c2010-05-12 20:20:15330
[email protected]2e3b5202010-03-23 06:52:41331 // Returns the item with the given |id| or NULL.
[email protected]5aeeae12012-07-05 19:13:11332 MenuItem* GetItemById(const MenuItem::Id& id) const;
[email protected]2e3b5202010-03-23 06:52:41333
[email protected]5aeeae12012-07-05 19:13:11334 // Notify the MenuManager that an item has been updated not through
335 // an explicit call into MenuManager. For example, if an item is
[email protected]7dddebc32012-01-11 22:01:03336 // acquired by a call to GetItemById and changed, then this should be called.
337 // Returns true if the item was found or false otherwise.
[email protected]5aeeae12012-07-05 19:13:11338 bool ItemUpdated(const MenuItem::Id& id);
[email protected]7dddebc32012-01-11 22:01:03339
[email protected]2e3b5202010-03-23 06:52:41340 // Called when a menu item is clicked on by the user.
[email protected]f5fede02014-07-29 02:48:21341 void ExecuteCommand(content::BrowserContext* context,
[email protected]33a86dbd2012-06-20 03:20:18342 content::WebContents* web_contents,
[email protected]35be7ec2012-02-12 20:42:51343 const content::ContextMenuParams& params,
[email protected]5aeeae12012-07-05 19:13:11344 const MenuItem::Id& menu_item_id);
[email protected]2e3b5202010-03-23 06:52:41345
[email protected]f23a8c12011-03-15 14:43:43346 // This returns a bitmap of width/height kFaviconSize, loaded either from an
[email protected]052c92702010-06-25 07:25:52347 // entry specified in the extension's 'icon' section of the manifest, or a
348 // default extension icon.
349 const SkBitmap& GetIconForExtension(const std::string& extension_id);
350
[email protected]00ee2f52014-04-25 09:25:52351 // content::NotificationObserver implementation.
dchengae36a4a2014-10-21 12:36:36352 void Observe(int type,
353 const content::NotificationSource& source,
354 const content::NotificationDetails& details) override;
[email protected]052c92702010-06-25 07:25:52355
[email protected]00ee2f52014-04-25 09:25:52356 // ExtensionRegistryObserver implementation.
dchengae36a4a2014-10-21 12:36:36357 void OnExtensionLoaded(content::BrowserContext* browser_context,
358 const Extension* extension) override;
359 void OnExtensionUnloaded(content::BrowserContext* browser_context,
360 const Extension* extension,
361 UnloadedExtensionInfo::Reason reason) override;
[email protected]00ee2f52014-04-25 09:25:52362
[email protected]bec64552012-06-13 20:25:49363 // Stores the menu items for the extension in the state storage.
[email protected]6f9d2c62014-03-10 12:12:05364 void WriteToStorage(const Extension* extension,
365 const MenuItem::ExtensionKey& extension_key);
[email protected]a0011472012-05-30 17:15:40366
[email protected]bec64552012-06-13 20:25:49367 // Reads menu items for the extension from the state storage. Any invalid
[email protected]a0011472012-05-30 17:15:40368 // items are ignored.
[email protected]bec64552012-06-13 20:25:49369 void ReadFromStorage(const std::string& extension_id,
370 scoped_ptr<base::Value> value);
[email protected]a0011472012-05-30 17:15:40371
[email protected]63503462012-10-30 22:14:31372 // Removes all "incognito" "split" mode context items.
373 void RemoveAllIncognitoContextItems();
374
[email protected]2e3b5202010-03-23 06:52:41375 private:
[email protected]5aeeae12012-07-05 19:13:11376 FRIEND_TEST_ALL_PREFIXES(MenuManagerTest, DeleteParent);
377 FRIEND_TEST_ALL_PREFIXES(MenuManagerTest, RemoveOneByOne);
[email protected]2b07c93f2010-08-02 23:13:04378
[email protected]2e3b5202010-03-23 06:52:41379 // This is a helper function which takes care of de-selecting any other radio
380 // items in the same group (i.e. that are adjacent in the list).
[email protected]5aeeae12012-07-05 19:13:11381 void RadioItemSelected(MenuItem* item);
[email protected]2e3b5202010-03-23 06:52:41382
[email protected]7dddebc32012-01-11 22:01:03383 // Make sure that there is only one radio item selected at once in any run.
384 // If there are no radio items selected, then the first item in the run
385 // will get selected. If there are multiple radio items selected, then only
386 // the last one will get selcted.
[email protected]5aeeae12012-07-05 19:13:11387 void SanitizeRadioList(const MenuItem::List& item_list);
[email protected]7dddebc32012-01-11 22:01:03388
[email protected]66dbfb2c2010-05-12 20:20:15389 // Returns true if item is a descendant of an item with id |ancestor_id|.
[email protected]5aeeae12012-07-05 19:13:11390 bool DescendantOf(MenuItem* item, const MenuItem::Id& ancestor_id);
[email protected]66dbfb2c2010-05-12 20:20:15391
[email protected]6f9d2c62014-03-10 12:12:05392 // We keep items organized by mapping ExtensionKey to a list of items.
393 typedef std::map<MenuItem::ExtensionKey, MenuItem::List> MenuItemMap;
[email protected]2e3b5202010-03-23 06:52:41394 MenuItemMap context_items_;
395
[email protected]5aeeae12012-07-05 19:13:11396 // This lets us make lookup by id fast. It maps id to MenuItem* for
[email protected]2e3b5202010-03-23 06:52:41397 // all items the menu manager knows about, including all children of top-level
398 // items.
[email protected]5aeeae12012-07-05 19:13:11399 std::map<MenuItem::Id, MenuItem*> items_by_id_;
[email protected]2e3b5202010-03-23 06:52:41400
[email protected]6c2381d2011-10-19 02:52:53401 content::NotificationRegistrar registrar_;
[email protected]2e3b5202010-03-23 06:52:41402
[email protected]00ee2f52014-04-25 09:25:52403 // Listen to extension load, unloaded notifications.
404 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver>
405 extension_registry_observer_;
406
[email protected]b671760b2010-07-15 21:13:47407 ExtensionIconManager icon_manager_;
[email protected]052c92702010-06-25 07:25:52408
[email protected]f5fede02014-07-29 02:48:21409 content::BrowserContext* browser_context_;
[email protected]a0011472012-05-30 17:15:40410
[email protected]b673a5942013-11-14 11:14:19411 // Owned by ExtensionSystem.
412 StateStore* store_;
413
[email protected]5aeeae12012-07-05 19:13:11414 DISALLOW_COPY_AND_ASSIGN(MenuManager);
[email protected]2e3b5202010-03-23 06:52:41415};
416
[email protected]5aeeae12012-07-05 19:13:11417} // namespace extensions
418
419#endif // CHROME_BROWSER_EXTENSIONS_MENU_MANAGER_H_