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

Side by Side Diff: chrome/browser/ui/webui/extensions/extension_icon_source.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/ui/webui/extensions/extension_icon_source.h" 5 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/memory/ref_counted_memory.h" 9 #include "base/memory/ref_counted_memory.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 19 matching lines...) Expand all
30 #include "webkit/glue/image_decoder.h" 30 #include "webkit/glue/image_decoder.h"
31 31
32 namespace { 32 namespace {
33 33
34 scoped_refptr<RefCountedMemory> BitmapToMemory(const SkBitmap* image) { 34 scoped_refptr<RefCountedMemory> BitmapToMemory(const SkBitmap* image) {
35 RefCountedBytes* image_bytes = new RefCountedBytes; 35 RefCountedBytes* image_bytes = new RefCountedBytes;
36 gfx::PNGCodec::EncodeBGRASkBitmap(*image, false, &image_bytes->data()); 36 gfx::PNGCodec::EncodeBGRASkBitmap(*image, false, &image_bytes->data());
37 return image_bytes; 37 return image_bytes;
38 } 38 }
39 39
40 void DesaturateImage(SkBitmap* image) { 40 SkBitmap DesaturateImage(const SkBitmap* image) {
41 color_utils::HSL shift = {-1, 0, 0.6}; 41 color_utils::HSL shift = {-1, 0, 0.6};
42 *image = SkBitmapOperations::CreateHSLShiftedBitmap(*image, shift); 42 return SkBitmapOperations::CreateHSLShiftedBitmap(*image, shift);
43 } 43 }
44 44
45 SkBitmap* ToBitmap(const unsigned char* data, size_t size) { 45 SkBitmap* ToBitmap(const unsigned char* data, size_t size) {
46 webkit_glue::ImageDecoder decoder; 46 webkit_glue::ImageDecoder decoder;
47 SkBitmap* decoded = new SkBitmap(); 47 SkBitmap* decoded = new SkBitmap();
48 *decoded = decoder.Decode(data, size); 48 *decoded = decoder.Decode(data, size);
49 return decoded; 49 return decoded;
50 } 50 }
51 51
52 } // namespace 52 } // namespace
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 161
162 const SkBitmap* ExtensionIconSource::GetDefaultExtensionImage() { 162 const SkBitmap* ExtensionIconSource::GetDefaultExtensionImage() {
163 if (!default_extension_data_.get()) { 163 if (!default_extension_data_.get()) {
164 default_extension_data_.reset( 164 default_extension_data_.reset(
165 LoadImageByResourceId(IDR_EXTENSION_DEFAULT_ICON)); 165 LoadImageByResourceId(IDR_EXTENSION_DEFAULT_ICON));
166 } 166 }
167 167
168 return default_extension_data_.get(); 168 return default_extension_data_.get();
169 } 169 }
170 170
171 void ExtensionIconSource::FinalizeImage(SkBitmap* image, 171 void ExtensionIconSource::FinalizeImage(const SkBitmap* image,
172 int request_id) { 172 int request_id) {
173 SkBitmap bitmap;
173 if (GetData(request_id)->grayscale) 174 if (GetData(request_id)->grayscale)
174 DesaturateImage(image); 175 bitmap = DesaturateImage(image);
176 else
177 bitmap = *image;
175 178
176 ClearData(request_id); 179 ClearData(request_id);
177 SendResponse(request_id, BitmapToMemory(image)); 180 SendResponse(request_id, BitmapToMemory(&bitmap));
178 } 181 }
179 182
180 void ExtensionIconSource::LoadDefaultImage(int request_id) { 183 void ExtensionIconSource::LoadDefaultImage(int request_id) {
181 ExtensionIconRequest* request = GetData(request_id); 184 ExtensionIconRequest* request = GetData(request_id);
182 const SkBitmap* default_image = NULL; 185 const SkBitmap* default_image = NULL;
183 186
184 if (request->extension->id() == extension_misc::kWebStoreAppId) 187 if (request->extension->id() == extension_misc::kWebStoreAppId)
185 default_image = GetWebStoreImage(); 188 default_image = GetWebStoreImage();
186 else if (request->extension->is_app()) 189 else if (request->extension->is_app())
187 default_image = GetDefaultAppImage(); 190 default_image = GetDefaultAppImage();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 // If we don't need a grayscale image, then we can bypass FinalizeImage 270 // If we don't need a grayscale image, then we can bypass FinalizeImage
268 // to avoid unnecessary conversions. 271 // to avoid unnecessary conversions.
269 ClearData(request_id); 272 ClearData(request_id);
270 SendResponse(request_id, favicon.image_data); 273 SendResponse(request_id, favicon.image_data);
271 } else { 274 } else {
272 FinalizeImage(ToBitmap(favicon.image_data->front(), 275 FinalizeImage(ToBitmap(favicon.image_data->front(),
273 favicon.image_data->size()), request_id); 276 favicon.image_data->size()), request_id);
274 } 277 }
275 } 278 }
276 279
277 void ExtensionIconSource::OnImageLoaded(SkBitmap* image, 280 void ExtensionIconSource::OnImageLoaded(const gfx::Image& image,
278 const ExtensionResource& resource, 281 const std::string& extension_id,
279 int index) { 282 int index) {
280 int request_id = tracker_map_[index]; 283 int request_id = tracker_map_[index];
281 tracker_map_.erase(tracker_map_.find(index)); 284 tracker_map_.erase(tracker_map_.find(index));
282 285
283 if (!image || image->empty()) 286 if (image.IsEmpty())
284 LoadIconFailed(request_id); 287 LoadIconFailed(request_id);
285 else 288 else
286 FinalizeImage(image, request_id); 289 FinalizeImage(image.ToSkBitmap(), request_id);
287 } 290 }
288 291
289 bool ExtensionIconSource::ParseData(const std::string& path, 292 bool ExtensionIconSource::ParseData(const std::string& path,
290 int request_id) { 293 int request_id) {
291 // Extract the parameters from the path by lower casing and splitting. 294 // Extract the parameters from the path by lower casing and splitting.
292 std::string path_lower = StringToLowerASCII(path); 295 std::string path_lower = StringToLowerASCII(path);
293 std::vector<std::string> path_parts; 296 std::vector<std::string> path_parts;
294 297
295 base::SplitString(path_lower, '/', &path_parts); 298 base::SplitString(path_lower, '/', &path_parts);
296 if (path_lower.empty() || path_parts.size() < 3) 299 if (path_lower.empty() || path_parts.size() < 3)
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 360
358 void ExtensionIconSource::ClearData(int request_id) { 361 void ExtensionIconSource::ClearData(int request_id) {
359 std::map<int, ExtensionIconRequest*>::iterator i = 362 std::map<int, ExtensionIconRequest*>::iterator i =
360 request_map_.find(request_id); 363 request_map_.find(request_id);
361 if (i == request_map_.end()) 364 if (i == request_map_.end())
362 return; 365 return;
363 366
364 delete i->second; 367 delete i->second;
365 request_map_.erase(i); 368 request_map_.erase(i);
366 } 369 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/extensions/extension_icon_source.h ('k') | chrome/browser/ui/webui/ntp/favicon_webui_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698