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

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

Issue 9586018: Add support for multiple icon sizes for Mac platform apps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix build Created 8 years, 9 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 | Annotate | Revision Log
OLDNEW
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 #include "chrome/browser/extensions/extension_icon_manager.h" 5 #include "chrome/browser/extensions/extension_icon_manager.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "chrome/common/extensions/extension.h" 9 #include "chrome/common/extensions/extension.h"
10 #include "chrome/common/extensions/extension_icon_set.h" 10 #include "chrome/common/extensions/extension_icon_set.h"
11 #include "chrome/common/extensions/extension_resource.h" 11 #include "chrome/common/extensions/extension_resource.h"
12 #include "grit/theme_resources.h" 12 #include "grit/theme_resources.h"
13 #include "skia/ext/image_operations.h" 13 #include "skia/ext/image_operations.h"
14 #include "ui/base/resource/resource_bundle.h" 14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/gfx/canvas_skia.h" 15 #include "ui/gfx/canvas_skia.h"
16 #include "ui/gfx/color_utils.h" 16 #include "ui/gfx/color_utils.h"
17 #include "ui/gfx/favicon_size.h" 17 #include "ui/gfx/favicon_size.h"
18 #include "ui/gfx/image/image.h"
18 #include "ui/gfx/size.h" 19 #include "ui/gfx/size.h"
19 #include "ui/gfx/skbitmap_operations.h" 20 #include "ui/gfx/skbitmap_operations.h"
20 21
21 namespace { 22 namespace {
22 23
23 // Helper function to create a new bitmap with |padding| amount of empty space 24 // Helper function to create a new bitmap with |padding| amount of empty space
24 // around the original bitmap. 25 // around the original bitmap.
25 static SkBitmap ApplyPadding(const SkBitmap& source, 26 static SkBitmap ApplyPadding(const SkBitmap& source,
26 const gfx::Insets& padding) { 27 const gfx::Insets& padding) {
27 scoped_ptr<gfx::CanvasSkia> result( 28 scoped_ptr<gfx::CanvasSkia> result(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 DCHECK_EQ(gfx::kFaviconSize + padding_.width(), result->width()); 73 DCHECK_EQ(gfx::kFaviconSize + padding_.width(), result->width());
73 DCHECK_EQ(gfx::kFaviconSize + padding_.height(), result->height()); 74 DCHECK_EQ(gfx::kFaviconSize + padding_.height(), result->height());
74 return *result; 75 return *result;
75 } 76 }
76 77
77 void ExtensionIconManager::RemoveIcon(const std::string& extension_id) { 78 void ExtensionIconManager::RemoveIcon(const std::string& extension_id) {
78 icons_.erase(extension_id); 79 icons_.erase(extension_id);
79 pending_icons_.erase(extension_id); 80 pending_icons_.erase(extension_id);
80 } 81 }
81 82
82 void ExtensionIconManager::OnImageLoaded(SkBitmap* image, 83 void ExtensionIconManager::OnImageLoaded(const gfx::Image& image,
83 const ExtensionResource& resource, 84 const std::string& extension_id,
84 int index) { 85 int index) {
85 if (!image) 86 if (image.IsEmpty())
86 return; 87 return;
87 88
88 const std::string extension_id = resource.extension_id();
89
90 // We may have removed the icon while waiting for it to load. In that case, 89 // We may have removed the icon while waiting for it to load. In that case,
91 // do nothing. 90 // do nothing.
92 if (!ContainsKey(pending_icons_, extension_id)) 91 if (!ContainsKey(pending_icons_, extension_id))
93 return; 92 return;
94 93
95 pending_icons_.erase(extension_id); 94 pending_icons_.erase(extension_id);
96 icons_[extension_id] = ApplyTransforms(*image); 95 icons_[extension_id] = ApplyTransforms(*image.ToSkBitmap());
97 } 96 }
98 97
99 void ExtensionIconManager::EnsureDefaultIcon() { 98 void ExtensionIconManager::EnsureDefaultIcon() {
100 if (default_icon_.empty()) { 99 if (default_icon_.empty()) {
101 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 100 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
102 SkBitmap* src = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION); 101 SkBitmap* src = rb.GetBitmapNamed(IDR_EXTENSIONS_SECTION);
103 default_icon_ = ApplyTransforms(*src); 102 default_icon_ = ApplyTransforms(*src);
104 } 103 }
105 } 104 }
106 105
(...skipping 10 matching lines...) Expand all
117 if (monochrome_) { 116 if (monochrome_) {
118 color_utils::HSL shift = {-1, 0, 0.6}; 117 color_utils::HSL shift = {-1, 0, 0.6};
119 result = SkBitmapOperations::CreateHSLShiftedBitmap(result, shift); 118 result = SkBitmapOperations::CreateHSLShiftedBitmap(result, shift);
120 } 119 }
121 120
122 if (!padding_.empty()) 121 if (!padding_.empty())
123 result = ApplyPadding(result, padding_); 122 result = ApplyPadding(result, padding_);
124 123
125 return result; 124 return result;
126 } 125 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_icon_manager.h ('k') | chrome/browser/extensions/extension_icon_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698