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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 186 |
187 // Any children this item may have. | 187 // Any children this item may have. |
188 List children_; | 188 List children_; |
189 | 189 |
190 DISALLOW_COPY_AND_ASSIGN(ExtensionMenuItem); | 190 DISALLOW_COPY_AND_ASSIGN(ExtensionMenuItem); |
191 }; | 191 }; |
192 | 192 |
193 // This class keeps track of menu items added by extensions. | 193 // This class keeps track of menu items added by extensions. |
194 class ExtensionMenuManager : public NotificationObserver { | 194 class ExtensionMenuManager : public NotificationObserver { |
195 public: | 195 public: |
196 // A bitmask of values from URLPattern::SchemeMasks indicating the schemes | |
197 // of pages where we'll show extension menu items. | |
198 static const int kAllowedSchemes; | |
199 | |
200 ExtensionMenuManager(); | 196 ExtensionMenuManager(); |
201 virtual ~ExtensionMenuManager(); | 197 virtual ~ExtensionMenuManager(); |
202 | 198 |
203 // Returns the ids of extensions which have menu items registered. | 199 // Returns the ids of extensions which have menu items registered. |
204 std::set<std::string> ExtensionIds(); | 200 std::set<std::string> ExtensionIds(); |
205 | 201 |
206 // Returns a list of all the *top-level* menu items (added via AddContextItem) | 202 // Returns a list of all the *top-level* menu items (added via AddContextItem) |
207 // for the given extension id, *not* including child items (added via | 203 // for the given extension id, *not* including child items (added via |
208 // AddChildItem); although those can be reached via the top-level items' | 204 // AddChildItem); although those can be reached via the top-level items' |
209 // children. A view can then decide how to display these, including whether to | 205 // children. A view can then decide how to display these, including whether to |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 242 |
247 // This returns a bitmap of width/height kFaviconSize, loaded either from an | 243 // 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 | 244 // entry specified in the extension's 'icon' section of the manifest, or a |
249 // default extension icon. | 245 // default extension icon. |
250 const SkBitmap& GetIconForExtension(const std::string& extension_id); | 246 const SkBitmap& GetIconForExtension(const std::string& extension_id); |
251 | 247 |
252 // Implements the NotificationObserver interface. | 248 // Implements the NotificationObserver interface. |
253 virtual void Observe(int type, const NotificationSource& source, | 249 virtual void Observe(int type, const NotificationSource& source, |
254 const NotificationDetails& details); | 250 const NotificationDetails& details); |
255 | 251 |
256 // Returns true if |url| has an allowed scheme for extension context menu | |
257 // items. This checks against kAllowedSchemes. | |
258 static bool HasAllowedScheme(const GURL& url); | |
259 | |
260 private: | 252 private: |
261 FRIEND_TEST_ALL_PREFIXES(ExtensionMenuManagerTest, DeleteParent); | 253 FRIEND_TEST_ALL_PREFIXES(ExtensionMenuManagerTest, DeleteParent); |
262 FRIEND_TEST_ALL_PREFIXES(ExtensionMenuManagerTest, RemoveOneByOne); | 254 FRIEND_TEST_ALL_PREFIXES(ExtensionMenuManagerTest, RemoveOneByOne); |
263 | 255 |
264 // This is a helper function which takes care of de-selecting any other radio | 256 // This is a helper function which takes care of de-selecting any other radio |
265 // items in the same group (i.e. that are adjacent in the list). | 257 // items in the same group (i.e. that are adjacent in the list). |
266 void RadioItemSelected(ExtensionMenuItem* item); | 258 void RadioItemSelected(ExtensionMenuItem* item); |
267 | 259 |
268 // Returns true if item is a descendant of an item with id |ancestor_id|. | 260 // Returns true if item is a descendant of an item with id |ancestor_id|. |
269 bool DescendantOf(ExtensionMenuItem* item, | 261 bool DescendantOf(ExtensionMenuItem* item, |
270 const ExtensionMenuItem::Id& ancestor_id); | 262 const ExtensionMenuItem::Id& ancestor_id); |
271 | 263 |
272 // We keep items organized by mapping an extension id to a list of items. | 264 // We keep items organized by mapping an extension id to a list of items. |
273 typedef std::map<std::string, ExtensionMenuItem::List> MenuItemMap; | 265 typedef std::map<std::string, ExtensionMenuItem::List> MenuItemMap; |
274 MenuItemMap context_items_; | 266 MenuItemMap context_items_; |
275 | 267 |
276 // This lets us make lookup by id fast. It maps id to ExtensionMenuItem* for | 268 // This lets us make lookup by id fast. It maps id to ExtensionMenuItem* for |
277 // all items the menu manager knows about, including all children of top-level | 269 // all items the menu manager knows about, including all children of top-level |
278 // items. | 270 // items. |
279 std::map<ExtensionMenuItem::Id, ExtensionMenuItem*> items_by_id_; | 271 std::map<ExtensionMenuItem::Id, ExtensionMenuItem*> items_by_id_; |
280 | 272 |
281 NotificationRegistrar registrar_; | 273 NotificationRegistrar registrar_; |
282 | 274 |
283 ExtensionIconManager icon_manager_; | 275 ExtensionIconManager icon_manager_; |
284 | 276 |
285 DISALLOW_COPY_AND_ASSIGN(ExtensionMenuManager); | 277 DISALLOW_COPY_AND_ASSIGN(ExtensionMenuManager); |
286 }; | 278 }; |
287 | 279 |
288 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MENU_MANAGER_H_ | 280 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MENU_MANAGER_H_ |
OLD | NEW |