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

Side by Side Diff: chrome/browser/extensions/extension_menu_manager.h

Issue 2973006: Use the extension icon for extension omnibox results instead of the generic (Closed)
Patch Set: fixed mac Created 10 years, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 7
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/basictypes.h" 13 #include "base/basictypes.h"
14 #include "base/scoped_ptr.h" 14 #include "base/scoped_ptr.h"
15 #include "base/string16.h" 15 #include "base/string16.h"
16 #include "chrome/browser/extensions/image_loading_tracker.h" 16 #include "chrome/browser/extensions/extension_icon_manager.h"
17 #include "chrome/common/notification_observer.h" 17 #include "chrome/common/notification_observer.h"
18 #include "chrome/common/notification_registrar.h" 18 #include "chrome/common/notification_registrar.h"
19 #include "third_party/skia/include/core/SkBitmap.h"
20 19
21 struct ContextMenuParams; 20 struct ContextMenuParams;
22 21
23 class Extension; 22 class Extension;
24 class ExtensionMessageService; 23 class ExtensionMessageService;
25 class Profile; 24 class Profile;
25 class SkBitmap;
26 class TabContents; 26 class TabContents;
27 27
28 // Represents a menu item added by an extension. 28 // Represents a menu item added by an extension.
29 class ExtensionMenuItem { 29 class ExtensionMenuItem {
30 public: 30 public:
31 // A list of ExtensionMenuItem's. 31 // A list of ExtensionMenuItem's.
32 typedef std::vector<ExtensionMenuItem*> List; 32 typedef std::vector<ExtensionMenuItem*> List;
33 33
34 // For context menus, these are the contexts where an item can appear. 34 // For context menus, these are the contexts where an item can appear.
35 enum Context { 35 enum Context {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // this is a top-level item with no parent, this will be NULL. 149 // this is a top-level item with no parent, this will be NULL.
150 scoped_ptr<Id> parent_id_; 150 scoped_ptr<Id> parent_id_;
151 151
152 // Any children this item may have. 152 // Any children this item may have.
153 List children_; 153 List children_;
154 154
155 DISALLOW_COPY_AND_ASSIGN(ExtensionMenuItem); 155 DISALLOW_COPY_AND_ASSIGN(ExtensionMenuItem);
156 }; 156 };
157 157
158 // This class keeps track of menu items added by extensions. 158 // This class keeps track of menu items added by extensions.
159 class ExtensionMenuManager 159 class ExtensionMenuManager : public NotificationObserver {
160 : public ImageLoadingTracker::Observer,
161 public NotificationObserver {
162 public: 160 public:
163 ExtensionMenuManager(); 161 ExtensionMenuManager();
164 virtual ~ExtensionMenuManager(); 162 virtual ~ExtensionMenuManager();
165 163
166 // Returns the ids of extensions which have menu items registered. 164 // Returns the ids of extensions which have menu items registered.
167 std::set<std::string> ExtensionIds(); 165 std::set<std::string> ExtensionIds();
168 166
169 // Returns a list of all the *top-level* menu items (added via AddContextItem) 167 // Returns a list of all the *top-level* menu items (added via AddContextItem)
170 // for the given extension id, *not* including child items (added via 168 // for the given extension id, *not* including child items (added via
171 // AddChildItem); although those can be reached via the top-level items' 169 // AddChildItem); although those can be reached via the top-level items'
(...skipping 28 matching lines...) Expand all
200 void RemoveAllContextItems(std::string extension_id); 198 void RemoveAllContextItems(std::string extension_id);
201 199
202 // Returns the item with the given |id| or NULL. 200 // Returns the item with the given |id| or NULL.
203 ExtensionMenuItem* GetItemById(const ExtensionMenuItem::Id& id) const; 201 ExtensionMenuItem* GetItemById(const ExtensionMenuItem::Id& id) const;
204 202
205 // Called when a menu item is clicked on by the user. 203 // Called when a menu item is clicked on by the user.
206 void ExecuteCommand(Profile* profile, TabContents* tab_contents, 204 void ExecuteCommand(Profile* profile, TabContents* tab_contents,
207 const ContextMenuParams& params, 205 const ContextMenuParams& params,
208 const ExtensionMenuItem::Id& menuItemId); 206 const ExtensionMenuItem::Id& menuItemId);
209 207
210 // Implements the NotificationObserver interface.
211 virtual void Observe(NotificationType type, const NotificationSource& source,
212 const NotificationDetails& details);
213
214 // This returns a bitmap of width/height kFavIconSize, loaded either from an 208 // This returns a bitmap of width/height kFavIconSize, loaded either from an
215 // entry specified in the extension's 'icon' section of the manifest, or a 209 // entry specified in the extension's 'icon' section of the manifest, or a
216 // default extension icon. 210 // default extension icon.
217 const SkBitmap& GetIconForExtension(const std::string& extension_id); 211 const SkBitmap& GetIconForExtension(const std::string& extension_id);
218 212
219 // Implements the ImageLoadingTracker::Observer interface. 213 // Implements the NotificationObserver interface.
220 virtual void OnImageLoaded(SkBitmap* image, ExtensionResource resource, 214 virtual void Observe(NotificationType type, const NotificationSource& source,
221 int index); 215 const NotificationDetails& details);
222 216
223 private: 217 private:
224 // This is a helper function which takes care of de-selecting any other radio 218 // This is a helper function which takes care of de-selecting any other radio
225 // items in the same group (i.e. that are adjacent in the list). 219 // items in the same group (i.e. that are adjacent in the list).
226 void RadioItemSelected(ExtensionMenuItem* item); 220 void RadioItemSelected(ExtensionMenuItem* item);
227 221
228 // Returns true if item is a descendant of an item with id |ancestor_id|. 222 // Returns true if item is a descendant of an item with id |ancestor_id|.
229 bool DescendantOf(ExtensionMenuItem* item, 223 bool DescendantOf(ExtensionMenuItem* item,
230 const ExtensionMenuItem::Id& ancestor_id); 224 const ExtensionMenuItem::Id& ancestor_id);
231 225
232 // Makes sure we've done one-time initialization of the default extension icon
233 // default_icon_.
234 void EnsureDefaultIcon();
235
236 // Helper function to return a copy of |src| scaled to kFavIconSize.
237 SkBitmap ScaleToFavIconSize(const SkBitmap& src);
238
239 // We keep items organized by mapping an extension id to a list of items. 226 // We keep items organized by mapping an extension id to a list of items.
240 typedef std::map<std::string, ExtensionMenuItem::List> MenuItemMap; 227 typedef std::map<std::string, ExtensionMenuItem::List> MenuItemMap;
241 MenuItemMap context_items_; 228 MenuItemMap context_items_;
242 229
243 // This lets us make lookup by id fast. It maps id to ExtensionMenuItem* for 230 // This lets us make lookup by id fast. It maps id to ExtensionMenuItem* for
244 // all items the menu manager knows about, including all children of top-level 231 // all items the menu manager knows about, including all children of top-level
245 // items. 232 // items.
246 std::map<ExtensionMenuItem::Id, ExtensionMenuItem*> items_by_id_; 233 std::map<ExtensionMenuItem::Id, ExtensionMenuItem*> items_by_id_;
247 234
248 NotificationRegistrar registrar_; 235 NotificationRegistrar registrar_;
249 236
250 // Used for loading extension icons. 237 ExtensionIconManager icon_manager_;
251 ImageLoadingTracker image_tracker_;
252
253 // Maps extension id to an SkBitmap with the icon for that extension.
254 std::map<std::string, SkBitmap> extension_icons_;
255
256 // The default icon we'll use if an extension doesn't have one.
257 SkBitmap default_icon_;
258 238
259 DISALLOW_COPY_AND_ASSIGN(ExtensionMenuManager); 239 DISALLOW_COPY_AND_ASSIGN(ExtensionMenuManager);
260 }; 240 };
261 241
262 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MENU_MANAGER_H_ 242 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MENU_MANAGER_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_icon_manager.cc ('k') | chrome/browser/extensions/extension_menu_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698