| OLD | NEW |
| 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 14 matching lines...) Expand all Loading... |
| 25 #include "skia/ext/image_operations.h" | 25 #include "skia/ext/image_operations.h" |
| 26 #include "ui/base/layout.h" | 26 #include "ui/base/layout.h" |
| 27 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| 28 #include "ui/gfx/codec/png_codec.h" | 28 #include "ui/gfx/codec/png_codec.h" |
| 29 #include "ui/gfx/color_utils.h" | 29 #include "ui/gfx/color_utils.h" |
| 30 #include "ui/gfx/skbitmap_operations.h" | 30 #include "ui/gfx/skbitmap_operations.h" |
| 31 #include "webkit/glue/image_decoder.h" | 31 #include "webkit/glue/image_decoder.h" |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 // Hmm, this sends desaturated favicons to the renderer. We either need our own |
| 36 // binary serialization of multiple pngs, or we just use ico. |
| 35 scoped_refptr<base::RefCountedMemory> BitmapToMemory(const SkBitmap* image) { | 37 scoped_refptr<base::RefCountedMemory> BitmapToMemory(const SkBitmap* image) { |
| 36 base::RefCountedBytes* image_bytes = new base::RefCountedBytes; | 38 base::RefCountedBytes* image_bytes = new base::RefCountedBytes; |
| 37 gfx::PNGCodec::EncodeBGRASkBitmap(*image, false, &image_bytes->data()); | 39 gfx::PNGCodec::EncodeBGRASkBitmap(*image, false, &image_bytes->data()); |
| 38 return image_bytes; | 40 return image_bytes; |
| 39 } | 41 } |
| 40 | 42 |
| 41 SkBitmap DesaturateImage(const SkBitmap* image) { | 43 SkBitmap DesaturateImage(const SkBitmap* image) { |
| 42 color_utils::HSL shift = {-1, 0, 0.6}; | 44 color_utils::HSL shift = {-1, 0, 0.6}; |
| 43 return SkBitmapOperations::CreateHSLShiftedBitmap(*image, shift); | 45 return SkBitmapOperations::CreateHSLShiftedBitmap(*image, shift); |
| 44 } | 46 } |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 // Fallback to the default icon if there wasn't a favicon. | 232 // Fallback to the default icon if there wasn't a favicon. |
| 231 if (!favicon.is_valid()) { | 233 if (!favicon.is_valid()) { |
| 232 LoadDefaultImage(request_id); | 234 LoadDefaultImage(request_id); |
| 233 return; | 235 return; |
| 234 } | 236 } |
| 235 | 237 |
| 236 if (!request->grayscale) { | 238 if (!request->grayscale) { |
| 237 // If we don't need a grayscale image, then we can bypass FinalizeImage | 239 // If we don't need a grayscale image, then we can bypass FinalizeImage |
| 238 // to avoid unnecessary conversions. | 240 // to avoid unnecessary conversions. |
| 239 ClearData(request_id); | 241 ClearData(request_id); |
| 240 SendResponse(request_id, favicon.bitmap_data); | 242 SendResponse(request_id, favicon.variants[0].bitmap_data); |
| 241 } else { | 243 } else { |
| 242 FinalizeImage(ToBitmap(favicon.bitmap_data->front(), | 244 FinalizeImage(ToBitmap( |
| 243 favicon.bitmap_data->size()), request_id); | 245 favicon.variants[0].bitmap_data->front(), |
| 246 favicon.variants[0].bitmap_data->size()), request_id); |
| 244 } | 247 } |
| 245 } | 248 } |
| 246 | 249 |
| 247 void ExtensionIconSource::OnImageLoaded(const gfx::Image& image, | 250 void ExtensionIconSource::OnImageLoaded(const gfx::Image& image, |
| 248 const std::string& extension_id, | 251 const std::string& extension_id, |
| 249 int index) { | 252 int index) { |
| 250 int request_id = tracker_map_[index]; | 253 int request_id = tracker_map_[index]; |
| 251 tracker_map_.erase(tracker_map_.find(index)); | 254 tracker_map_.erase(tracker_map_.find(index)); |
| 252 | 255 |
| 253 if (image.IsEmpty()) | 256 if (image.IsEmpty()) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 341 |
| 339 void ExtensionIconSource::ClearData(int request_id) { | 342 void ExtensionIconSource::ClearData(int request_id) { |
| 340 std::map<int, ExtensionIconRequest*>::iterator i = | 343 std::map<int, ExtensionIconRequest*>::iterator i = |
| 341 request_map_.find(request_id); | 344 request_map_.find(request_id); |
| 342 if (i == request_map_.end()) | 345 if (i == request_map_.end()) |
| 343 return; | 346 return; |
| 344 | 347 |
| 345 delete i->second; | 348 delete i->second; |
| 346 request_map_.erase(i); | 349 request_map_.erase(i); |
| 347 } | 350 } |
| OLD | NEW |