OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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> |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 // item or a child of some other item), returning true if the item was found | 232 // item or a child of some other item), returning true if the item was found |
233 // and removed or false otherwise. | 233 // and removed or false otherwise. |
234 bool RemoveContextMenuItem(const ExtensionMenuItem::Id& id); | 234 bool RemoveContextMenuItem(const ExtensionMenuItem::Id& id); |
235 | 235 |
236 // Removes all items for the given extension id. | 236 // Removes all items for the given extension id. |
237 void RemoveAllContextItems(const std::string& extension_id); | 237 void RemoveAllContextItems(const std::string& extension_id); |
238 | 238 |
239 // Returns the item with the given |id| or NULL. | 239 // Returns the item with the given |id| or NULL. |
240 ExtensionMenuItem* GetItemById(const ExtensionMenuItem::Id& id) const; | 240 ExtensionMenuItem* GetItemById(const ExtensionMenuItem::Id& id) const; |
241 | 241 |
242 // Notify the ExtensionMenuManager that an item has been updated not through | |
243 // an explicit call into ExtensionMenuManager. For example, if an item is | |
244 // acquired by a call to GetItemById and changed, then this should be called. | |
245 // Returns true if the item was found or false otherwise. | |
246 bool ItemUpdated(const ExtensionMenuItem::Id& id); | |
247 | |
242 // Called when a menu item is clicked on by the user. | 248 // Called when a menu item is clicked on by the user. |
243 void ExecuteCommand(Profile* profile, content::WebContents* web_contents, | 249 void ExecuteCommand(Profile* profile, content::WebContents* web_contents, |
244 const ContextMenuParams& params, | 250 const ContextMenuParams& params, |
245 const ExtensionMenuItem::Id& menuItemId); | 251 const ExtensionMenuItem::Id& menuItemId); |
246 | 252 |
247 // This returns a bitmap of width/height kFaviconSize, loaded either from an | 253 // This returns a bitmap of width/height kFaviconSize, loaded either from an |
248 // entry specified in the extension's 'icon' section of the manifest, or a | 254 // entry specified in the extension's 'icon' section of the manifest, or a |
249 // default extension icon. | 255 // default extension icon. |
250 const SkBitmap& GetIconForExtension(const std::string& extension_id); | 256 const SkBitmap& GetIconForExtension(const std::string& extension_id); |
251 | 257 |
252 // Implements the content::NotificationObserver interface. | 258 // Implements the content::NotificationObserver interface. |
253 virtual void Observe(int type, const content::NotificationSource& source, | 259 virtual void Observe(int type, const content::NotificationSource& source, |
254 const content::NotificationDetails& details) OVERRIDE; | 260 const content::NotificationDetails& details) OVERRIDE; |
255 | 261 |
256 private: | 262 private: |
257 FRIEND_TEST_ALL_PREFIXES(ExtensionMenuManagerTest, DeleteParent); | 263 FRIEND_TEST_ALL_PREFIXES(ExtensionMenuManagerTest, DeleteParent); |
258 FRIEND_TEST_ALL_PREFIXES(ExtensionMenuManagerTest, RemoveOneByOne); | 264 FRIEND_TEST_ALL_PREFIXES(ExtensionMenuManagerTest, RemoveOneByOne); |
259 | 265 |
260 // This is a helper function which takes care of de-selecting any other radio | 266 // This is a helper function which takes care of de-selecting any other radio |
261 // items in the same group (i.e. that are adjacent in the list). | 267 // items in the same group (i.e. that are adjacent in the list). |
262 void RadioItemSelected(ExtensionMenuItem* item); | 268 void RadioItemSelected(ExtensionMenuItem* item); |
263 | 269 |
270 // Make sure that there is only one radio item selected at once in any run. | |
271 // If there are no radio items selected, then the first item in the run | |
272 // will get selected. If there are multiple radio items selected, then only | |
273 // the last one will get selcted. | |
274 void SanitizeRadioList(const ExtensionMenuItem::List& item_list); | |
asargent_no_longer_on_chrome
2012/01/06 21:17:42
Since you potentially modify some of |item_list|'s
| |
275 | |
264 // Returns true if item is a descendant of an item with id |ancestor_id|. | 276 // Returns true if item is a descendant of an item with id |ancestor_id|. |
265 bool DescendantOf(ExtensionMenuItem* item, | 277 bool DescendantOf(ExtensionMenuItem* item, |
266 const ExtensionMenuItem::Id& ancestor_id); | 278 const ExtensionMenuItem::Id& ancestor_id); |
267 | 279 |
268 // We keep items organized by mapping an extension id to a list of items. | 280 // We keep items organized by mapping an extension id to a list of items. |
269 typedef std::map<std::string, ExtensionMenuItem::List> MenuItemMap; | 281 typedef std::map<std::string, ExtensionMenuItem::List> MenuItemMap; |
270 MenuItemMap context_items_; | 282 MenuItemMap context_items_; |
271 | 283 |
272 // This lets us make lookup by id fast. It maps id to ExtensionMenuItem* for | 284 // This lets us make lookup by id fast. It maps id to ExtensionMenuItem* for |
273 // all items the menu manager knows about, including all children of top-level | 285 // all items the menu manager knows about, including all children of top-level |
274 // items. | 286 // items. |
275 std::map<ExtensionMenuItem::Id, ExtensionMenuItem*> items_by_id_; | 287 std::map<ExtensionMenuItem::Id, ExtensionMenuItem*> items_by_id_; |
276 | 288 |
277 content::NotificationRegistrar registrar_; | 289 content::NotificationRegistrar registrar_; |
278 | 290 |
279 ExtensionIconManager icon_manager_; | 291 ExtensionIconManager icon_manager_; |
280 | 292 |
281 DISALLOW_COPY_AND_ASSIGN(ExtensionMenuManager); | 293 DISALLOW_COPY_AND_ASSIGN(ExtensionMenuManager); |
282 }; | 294 }; |
283 | 295 |
284 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MENU_MANAGER_H_ | 296 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MENU_MANAGER_H_ |
OLD | NEW |