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

Side by Side Diff: chrome/browser/extensions/extension_icon_manager.cc

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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/extension_icon_manager.h"
6
7 #include "app/resource_bundle.h"
8 #include "base/logging.h"
9 #include "base/stl_util-inl.h"
10 #include "chrome/common/extensions/extension.h"
11 #include "chrome/common/extensions/extension_resource.h"
12 #include "gfx/color_utils.h"
13 #include "gfx/favicon_size.h"
14 #include "gfx/skbitmap_operations.h"
15 #include "gfx/size.h"
16 #include "grit/theme_resources.h"
17 #include "skia/ext/image_operations.h"
18
19 ExtensionIconManager::ExtensionIconManager()
20 : ALLOW_THIS_IN_INITIALIZER_LIST(image_tracker_(this)),
21 monochrome_(false) {
22 }
23
24 void ExtensionIconManager::LoadIcon(Extension* extension) {
25 ExtensionResource icon_resource;
26 extension->GetIconPathAllowLargerSize(&icon_resource,
27 Extension::EXTENSION_ICON_BITTY);
28 if (!icon_resource.extension_root().empty()) {
29 image_tracker_.LoadImage(extension,
30 icon_resource,
31 gfx::Size(kFavIconSize, kFavIconSize),
32 ImageLoadingTracker::CACHE);
33 pending_icons_.insert(extension->id());
34 }
35 }
36
37 const SkBitmap& ExtensionIconManager::GetIcon(const std::string& extension_id) {
38 const SkBitmap* result = NULL;
39 if (ContainsKey(icons_, extension_id)) {
40 result = &icons_[extension_id];
41 } else {
42 EnsureDefaultIcon();
43 result = &default_icon_;
44 }
45 DCHECK(result);
46 DCHECK(result->width() == kFavIconSize);
47 DCHECK(result->height() == kFavIconSize);
48 return *result;
49 }
50
51 void ExtensionIconManager::RemoveIcon(const std::string& extension_id) {
52 icons_.erase(extension_id);
53 pending_icons_.erase(extension_id);
54 }
55
56 void ExtensionIconManager::OnImageLoaded(SkBitmap* image,
57 ExtensionResource resource,
58 int index) {
59 if (!image)
60 return;
61
62 const std::string extension_id = resource.extension_id();
63
64 // We may have removed the icon while waiting for it to load. In that case,
65 // do nothing.
66 if (!ContainsKey(pending_icons_, extension_id))
67 return;
68
69 pending_icons_.erase(extension_id);
70 icons_[extension_id] = ApplyTransforms(*image);
71 }
72
73 void ExtensionIconManager::EnsureDefaultIcon() {
74 if (default_icon_.empty()) {
75 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
76 SkBitmap* src = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION);
77 default_icon_ = ApplyTransforms(*src);
78 }
79 }
80
81 SkBitmap ExtensionIconManager::ApplyTransforms(const SkBitmap& source) {
82 SkBitmap result = source;
83
84 if (result.width() != kFavIconSize || result.height() != kFavIconSize) {
85 result = skia::ImageOperations::Resize(
86 result, skia::ImageOperations::RESIZE_LANCZOS3,
87 kFavIconSize, kFavIconSize);
88 }
89
90 if (monochrome_) {
91 color_utils::HSL shift = {-1, 0, 0.6};
92 result = SkBitmapOperations::CreateHSLShiftedBitmap(result, shift);
93 }
94
95 return result;
96 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_icon_manager.h ('k') | chrome/browser/extensions/extension_menu_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698