| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_MENU_MANAGER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_MENU_MANAGER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_MENU_MANAGER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_MENU_MANAGER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/string16.h" | 18 #include "base/string16.h" |
| 19 #include "chrome/browser/extensions/extension_icon_manager.h" | 19 #include "chrome/browser/extensions/extension_icon_manager.h" |
| 20 #include "chrome/common/extensions/url_pattern_set.h" | 20 #include "chrome/common/extensions/url_pattern_set.h" |
| 21 #include "content/public/browser/notification_observer.h" | 21 #include "content/public/browser/notification_observer.h" |
| 22 #include "content/public/browser/notification_registrar.h" | 22 #include "content/public/browser/notification_registrar.h" |
| 23 | 23 |
| 24 | 24 |
| 25 class Extension; | |
| 26 class Profile; | 25 class Profile; |
| 27 class SkBitmap; | 26 class SkBitmap; |
| 28 | 27 |
| 29 namespace content { | 28 namespace content { |
| 30 class WebContents; | 29 class WebContents; |
| 31 struct ContextMenuParams; | 30 struct ContextMenuParams; |
| 32 } | 31 } |
| 33 | 32 |
| 33 namespace extensions { |
| 34 class Extension; |
| 35 } |
| 36 |
| 34 // Represents a menu item added by an extension. | 37 // Represents a menu item added by an extension. |
| 35 class ExtensionMenuItem { | 38 class ExtensionMenuItem { |
| 36 public: | 39 public: |
| 37 // A list of ExtensionMenuItem's. | 40 // A list of ExtensionMenuItem's. |
| 38 typedef std::vector<ExtensionMenuItem*> List; | 41 typedef std::vector<ExtensionMenuItem*> List; |
| 39 | 42 |
| 40 // An Id uniquely identifies a context menu item registered by an extension. | 43 // An Id uniquely identifies a context menu item registered by an extension. |
| 41 struct Id { | 44 struct Id { |
| 42 Id(); | 45 Id(); |
| 43 Id(Profile* profile, const std::string& extension_id, int uid); | 46 Id(Profile* profile, const std::string& extension_id, int uid); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 // Returns a list of all the *top-level* menu items (added via AddContextItem) | 215 // Returns a list of all the *top-level* menu items (added via AddContextItem) |
| 213 // for the given extension id, *not* including child items (added via | 216 // for the given extension id, *not* including child items (added via |
| 214 // AddChildItem); although those can be reached via the top-level items' | 217 // AddChildItem); although those can be reached via the top-level items' |
| 215 // children. A view can then decide how to display these, including whether to | 218 // children. A view can then decide how to display these, including whether to |
| 216 // put them into a submenu if there are more than 1. | 219 // put them into a submenu if there are more than 1. |
| 217 const ExtensionMenuItem::List* MenuItems(const std::string& extension_id); | 220 const ExtensionMenuItem::List* MenuItems(const std::string& extension_id); |
| 218 | 221 |
| 219 // Adds a top-level menu item for an extension, requiring the |extension| | 222 // Adds a top-level menu item for an extension, requiring the |extension| |
| 220 // pointer so it can load the icon for the extension. Takes ownership of | 223 // pointer so it can load the icon for the extension. Takes ownership of |
| 221 // |item|. Returns a boolean indicating success or failure. | 224 // |item|. Returns a boolean indicating success or failure. |
| 222 bool AddContextItem(const Extension* extension, ExtensionMenuItem* item); | 225 bool AddContextItem(const extensions::Extension* extension, |
| 226 ExtensionMenuItem* item); |
| 223 | 227 |
| 224 // Add an item as a child of another item which has been previously added, and | 228 // Add an item as a child of another item which has been previously added, and |
| 225 // takes ownership of |item|. Returns a boolean indicating success or failure. | 229 // takes ownership of |item|. Returns a boolean indicating success or failure. |
| 226 bool AddChildItem(const ExtensionMenuItem::Id& parent_id, | 230 bool AddChildItem(const ExtensionMenuItem::Id& parent_id, |
| 227 ExtensionMenuItem* child); | 231 ExtensionMenuItem* child); |
| 228 | 232 |
| 229 // Makes existing item with |child_id| a child of the item with |parent_id|. | 233 // Makes existing item with |child_id| a child of the item with |parent_id|. |
| 230 // If the child item was already a child of another parent, this will remove | 234 // If the child item was already a child of another parent, this will remove |
| 231 // it from that parent first. It is an error to try and move an item to be a | 235 // it from that parent first. It is an error to try and move an item to be a |
| 232 // child of one of its own descendants. It is legal to pass NULL for | 236 // child of one of its own descendants. It is legal to pass NULL for |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 std::map<ExtensionMenuItem::Id, ExtensionMenuItem*> items_by_id_; | 297 std::map<ExtensionMenuItem::Id, ExtensionMenuItem*> items_by_id_; |
| 294 | 298 |
| 295 content::NotificationRegistrar registrar_; | 299 content::NotificationRegistrar registrar_; |
| 296 | 300 |
| 297 ExtensionIconManager icon_manager_; | 301 ExtensionIconManager icon_manager_; |
| 298 | 302 |
| 299 DISALLOW_COPY_AND_ASSIGN(ExtensionMenuManager); | 303 DISALLOW_COPY_AND_ASSIGN(ExtensionMenuManager); |
| 300 }; | 304 }; |
| 301 | 305 |
| 302 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MENU_MANAGER_H_ | 306 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MENU_MANAGER_H_ |
| OLD | NEW |