| Index: chrome/browser/extensions/menu_manager.h
|
| diff --git a/chrome/browser/extensions/extension_menu_manager.h b/chrome/browser/extensions/menu_manager.h
|
| similarity index 77%
|
| rename from chrome/browser/extensions/extension_menu_manager.h
|
| rename to chrome/browser/extensions/menu_manager.h
|
| index 0bacba740e976c8e7e8036dd56ec475d74a70eb0..38ef3f7aee64890c1da9e8247247549c2d1a2fe9 100644
|
| --- a/chrome/browser/extensions/extension_menu_manager.h
|
| +++ b/chrome/browser/extensions/menu_manager.h
|
| @@ -2,8 +2,8 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_MENU_MANAGER_H_
|
| -#define CHROME_BROWSER_EXTENSIONS_EXTENSION_MENU_MANAGER_H_
|
| +#ifndef CHROME_BROWSER_EXTENSIONS_MENU_MANAGER_H_
|
| +#define CHROME_BROWSER_EXTENSIONS_MENU_MANAGER_H_
|
| #pragma once
|
|
|
| #include <map>
|
| @@ -34,13 +34,12 @@ struct ContextMenuParams;
|
|
|
| namespace extensions {
|
| class Extension;
|
| -}
|
|
|
| // Represents a menu item added by an extension.
|
| -class ExtensionMenuItem {
|
| +class MenuItem {
|
| public:
|
| - // A list of ExtensionMenuItem's.
|
| - typedef std::vector<ExtensionMenuItem*> List;
|
| + // A list of MenuItems.
|
| + typedef std::vector<MenuItem*> List;
|
|
|
| // An Id uniquely identifies a context menu item registered by an extension.
|
| struct Id {
|
| @@ -126,13 +125,13 @@ class ExtensionMenuItem {
|
| uint32 value_; // A bitmask of Context values.
|
| };
|
|
|
| - ExtensionMenuItem(const Id& id,
|
| - const std::string& title,
|
| - bool checked,
|
| - bool enabled,
|
| - Type type,
|
| - const ContextList& contexts);
|
| - virtual ~ExtensionMenuItem();
|
| + MenuItem(const Id& id,
|
| + const std::string& title,
|
| + bool checked,
|
| + bool enabled,
|
| + Type type,
|
| + const ContextList& contexts);
|
| + virtual ~MenuItem();
|
|
|
| // Simple accessor methods.
|
| bool incognito() const { return id_.incognito; }
|
| @@ -176,11 +175,11 @@ class ExtensionMenuItem {
|
| // Converts to Value for serialization to preferences.
|
| scoped_ptr<base::DictionaryValue> ToValue() const;
|
|
|
| - // Returns a new ExtensionMenuItem created from |value|, or NULL if there is
|
| - // an error. The caller takes ownership of the ExtensionMenuItem.
|
| - static ExtensionMenuItem* Populate(const std::string& extension_id,
|
| - const DictionaryValue& value,
|
| - std::string* error);
|
| + // Returns a new MenuItem created from |value|, or NULL if there is
|
| + // an error. The caller takes ownership of the MenuItem.
|
| + static MenuItem* Populate(const std::string& extension_id,
|
| + const DictionaryValue& value,
|
| + std::string* error);
|
|
|
| // Sets any document and target URL patterns from |properties|.
|
| bool PopulateURLPatterns(const base::DictionaryValue& properties,
|
| @@ -189,18 +188,18 @@ class ExtensionMenuItem {
|
| std::string* error);
|
|
|
| protected:
|
| - friend class ExtensionMenuManager;
|
| + friend class MenuManager;
|
|
|
| // Takes ownership of |item| and sets its parent_id_.
|
| - void AddChild(ExtensionMenuItem* item);
|
| + void AddChild(MenuItem* item);
|
|
|
| // Takes the child item from this parent. The item is returned and the caller
|
| // then owns the pointer.
|
| - ExtensionMenuItem* ReleaseChild(const Id& child_id, bool recursive);
|
| + MenuItem* ReleaseChild(const Id& child_id, bool recursive);
|
|
|
| // Recursively appends all descendant items (children, grandchildren, etc.)
|
| // to the output |list|.
|
| - void GetFlattenedSubtree(ExtensionMenuItem::List* list);
|
| + void GetFlattenedSubtree(MenuItem::List* list);
|
|
|
| // Recursively removes all descendant items (children, grandchildren, etc.),
|
| // returning the ids of the removed items.
|
| @@ -239,16 +238,15 @@ class ExtensionMenuItem {
|
| // Any children this item may have.
|
| List children_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(ExtensionMenuItem);
|
| + DISALLOW_COPY_AND_ASSIGN(MenuItem);
|
| };
|
|
|
| // This class keeps track of menu items added by extensions.
|
| -class ExtensionMenuManager
|
| - : public content::NotificationObserver,
|
| - public base::SupportsWeakPtr<ExtensionMenuManager> {
|
| +class MenuManager : public content::NotificationObserver,
|
| + public base::SupportsWeakPtr<MenuManager> {
|
| public:
|
| - explicit ExtensionMenuManager(Profile* profile);
|
| - virtual ~ExtensionMenuManager();
|
| + explicit MenuManager(Profile* profile);
|
| + virtual ~MenuManager();
|
|
|
| // Returns the ids of extensions which have menu items registered.
|
| std::set<std::string> ExtensionIds();
|
| @@ -258,49 +256,48 @@ class ExtensionMenuManager
|
| // 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 ExtensionMenuItem::List* MenuItems(const std::string& extension_id);
|
| + const MenuItem::List* MenuItems(const std::string& extension_id);
|
|
|
| // 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
|
| // |item|. Returns a boolean indicating success or failure.
|
| - bool AddContextItem(const extensions::Extension* extension,
|
| - ExtensionMenuItem* item);
|
| + bool AddContextItem(const Extension* extension, MenuItem* item);
|
|
|
| // Add an item as a child of another item which has been previously added, and
|
| // takes ownership of |item|. Returns a boolean indicating success or failure.
|
| - bool AddChildItem(const ExtensionMenuItem::Id& parent_id,
|
| - ExtensionMenuItem* child);
|
| + bool AddChildItem(const MenuItem::Id& parent_id,
|
| + MenuItem* child);
|
|
|
| // Makes existing item with |child_id| a child of the item with |parent_id|.
|
| // If the child item was already a child of another parent, this will remove
|
| // it from that parent first. It is an error to try and move an item to be a
|
| // child of one of its own descendants. It is legal to pass NULL for
|
| // |parent_id|, which means the item should be moved to the top-level.
|
| - bool ChangeParent(const ExtensionMenuItem::Id& child_id,
|
| - const ExtensionMenuItem::Id* parent_id);
|
| + bool ChangeParent(const MenuItem::Id& child_id,
|
| + const MenuItem::Id* parent_id);
|
|
|
| // Removes a context menu item with the given id (whether it is a top-level
|
| // item or a child of some other item), returning true if the item was found
|
| // and removed or false otherwise.
|
| - bool RemoveContextMenuItem(const ExtensionMenuItem::Id& id);
|
| + bool RemoveContextMenuItem(const MenuItem::Id& id);
|
|
|
| // Removes all items for the given extension id.
|
| void RemoveAllContextItems(const std::string& extension_id);
|
|
|
| // Returns the item with the given |id| or NULL.
|
| - ExtensionMenuItem* GetItemById(const ExtensionMenuItem::Id& id) const;
|
| + MenuItem* GetItemById(const MenuItem::Id& id) const;
|
|
|
| - // Notify the ExtensionMenuManager that an item has been updated not through
|
| - // an explicit call into ExtensionMenuManager. For example, if an item is
|
| + // Notify the MenuManager that an item has been updated not through
|
| + // an explicit call into MenuManager. For example, if an item is
|
| // acquired by a call to GetItemById and changed, then this should be called.
|
| // Returns true if the item was found or false otherwise.
|
| - bool ItemUpdated(const ExtensionMenuItem::Id& id);
|
| + bool ItemUpdated(const MenuItem::Id& id);
|
|
|
| // Called when a menu item is clicked on by the user.
|
| void ExecuteCommand(Profile* profile,
|
| content::WebContents* web_contents,
|
| const content::ContextMenuParams& params,
|
| - const ExtensionMenuItem::Id& menu_item_id);
|
| + const MenuItem::Id& menu_item_id);
|
|
|
| // This returns a bitmap of width/height kFaviconSize, loaded either from an
|
| // entry specified in the extension's 'icon' section of the manifest, or a
|
| @@ -312,7 +309,7 @@ class ExtensionMenuManager
|
| const content::NotificationDetails& details) OVERRIDE;
|
|
|
| // Stores the menu items for the extension in the state storage.
|
| - void WriteToStorage(const extensions::Extension* extension);
|
| + void WriteToStorage(const Extension* extension);
|
|
|
| // Reads menu items for the extension from the state storage. Any invalid
|
| // items are ignored.
|
| @@ -320,31 +317,30 @@ class ExtensionMenuManager
|
| scoped_ptr<base::Value> value);
|
|
|
| private:
|
| - FRIEND_TEST_ALL_PREFIXES(ExtensionMenuManagerTest, DeleteParent);
|
| - FRIEND_TEST_ALL_PREFIXES(ExtensionMenuManagerTest, RemoveOneByOne);
|
| + FRIEND_TEST_ALL_PREFIXES(MenuManagerTest, DeleteParent);
|
| + FRIEND_TEST_ALL_PREFIXES(MenuManagerTest, RemoveOneByOne);
|
|
|
| // This is a helper function which takes care of de-selecting any other radio
|
| // items in the same group (i.e. that are adjacent in the list).
|
| - void RadioItemSelected(ExtensionMenuItem* item);
|
| + void RadioItemSelected(MenuItem* item);
|
|
|
| // Make sure that there is only one radio item selected at once in any run.
|
| // If there are no radio items selected, then the first item in the run
|
| // will get selected. If there are multiple radio items selected, then only
|
| // the last one will get selcted.
|
| - void SanitizeRadioList(const ExtensionMenuItem::List& item_list);
|
| + void SanitizeRadioList(const MenuItem::List& item_list);
|
|
|
| // Returns true if item is a descendant of an item with id |ancestor_id|.
|
| - bool DescendantOf(ExtensionMenuItem* item,
|
| - const ExtensionMenuItem::Id& ancestor_id);
|
| + 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, ExtensionMenuItem::List> MenuItemMap;
|
| + typedef std::map<std::string, MenuItem::List> MenuItemMap;
|
| MenuItemMap context_items_;
|
|
|
| - // This lets us make lookup by id fast. It maps id to ExtensionMenuItem* for
|
| + // This lets us make lookup by id fast. It maps id to MenuItem* for
|
| // all items the menu manager knows about, including all children of top-level
|
| // items.
|
| - std::map<ExtensionMenuItem::Id, ExtensionMenuItem*> items_by_id_;
|
| + std::map<MenuItem::Id, MenuItem*> items_by_id_;
|
|
|
| content::NotificationRegistrar registrar_;
|
|
|
| @@ -352,7 +348,9 @@ class ExtensionMenuManager
|
|
|
| Profile* profile_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(ExtensionMenuManager);
|
| + DISALLOW_COPY_AND_ASSIGN(MenuManager);
|
| };
|
|
|
| -#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MENU_MANAGER_H_
|
| +} // namespace extensions
|
| +
|
| +#endif // CHROME_BROWSER_EXTENSIONS_MENU_MANAGER_H_
|
|
|