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

Unified Diff: chrome/browser/extensions/menu_manager.h

Issue 186213003: <webview>: Context menu API implementation CL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make {extension_id,webview_instance_id} key for MenuManager items. Created 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/menu_manager.h
diff --git a/chrome/browser/extensions/menu_manager.h b/chrome/browser/extensions/menu_manager.h
index ea6cecf90de2aec43d6ac8c8f05304b7d76a279c..5f7e5ea7f9bea01014198d6d596413c1d0a10968 100644
--- a/chrome/browser/extensions/menu_manager.h
+++ b/chrome/browser/extensions/menu_manager.h
@@ -60,6 +60,7 @@ class MenuItem {
// Only one of uid or string_uid will be defined.
int uid;
std::string string_uid;
+ int webview_instance_id;
};
// For context menus, these are the contexts where an item can appear.
@@ -84,6 +85,23 @@ class MenuItem {
SEPARATOR
};
+ // Key used to identify which extension a menu item belongs to.
+ // |webview_instance_id| = 0 for regular extension items.
+ struct ExtensionKey {
+ std::string extension_id;
+ int webview_instance_id;
+
+ ExtensionKey(const std::string& extension_id, int webview_instance_id);
+ explicit ExtensionKey(const std::string& extension_id);
+ explicit ExtensionKey(const MenuItem::Id& item_id);
+
+ bool operator==(const ExtensionKey& other) const;
+ bool operator!=(const ExtensionKey& other) const;
+ bool operator<(const ExtensionKey& other) const;
+
+ bool empty() const;
+ };
+
// A list of Contexts for an item.
class ContextList {
public:
@@ -139,6 +157,7 @@ class MenuItem {
// Simple accessor methods.
bool incognito() const { return id_.incognito; }
const std::string& extension_id() const { return id_.extension_id; }
+ // const ExtensionKey extension_key() const { return ExtensionKey(id_); }
const std::string& title() const { return title_; }
const List& children() { return children_; }
const Id& id() const { return id_; }
@@ -262,7 +281,7 @@ class MenuManager : public content::NotificationObserver,
// AddChildItem); although those can be reached via the top-level items'
// children. A view can then decide how to display these, including whether to
// put them into a submenu if there are more than 1.
- const MenuItem::List* MenuItems(const std::string& extension_id);
+ const MenuItem::List* MenuItems(const MenuItem::ExtensionKey& extension_key);
// Adds a top-level menu item for an extension, requiring the |extension|
// pointer so it can load the icon for the extension. Takes ownership of
@@ -287,8 +306,8 @@ class MenuManager : public content::NotificationObserver,
// and removed or false otherwise.
bool RemoveContextMenuItem(const MenuItem::Id& id);
- // Removes all items for the given extension id.
- void RemoveAllContextItems(const std::string& extension_id);
+ // Removes all items for the given extension specified by |extension_key|.
+ void RemoveAllContextItems(const MenuItem::ExtensionKey& extension_key);
// Returns the item with the given |id| or NULL.
MenuItem* GetItemById(const MenuItem::Id& id) const;
@@ -343,7 +362,7 @@ class MenuManager : public content::NotificationObserver,
bool DescendantOf(MenuItem* item, const MenuItem::Id& ancestor_id);
// We keep items organized by mapping an extension id to a list of items.
- typedef std::map<std::string, MenuItem::List> MenuItemMap;
+ typedef std::map<MenuItem::ExtensionKey, MenuItem::List> MenuItemMap;
MenuItemMap context_items_;
// This lets us make lookup by id fast. It maps id to MenuItem* for

Powered by Google App Engine
This is Rietveld 408576698