| 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 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/common/extensions/extension_resource.h" | 22 #include "chrome/common/extensions/extension_resource.h" |
| 23 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 24 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
| 25 #include "grit/component_extension_resources_map.h" | 25 #include "grit/component_extension_resources_map.h" |
| 26 #include "grit/theme_resources.h" | 26 #include "grit/theme_resources.h" |
| 27 #include "skia/ext/image_operations.h" | 27 #include "skia/ext/image_operations.h" |
| 28 #include "ui/base/layout.h" | 28 #include "ui/base/layout.h" |
| 29 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
| 30 #include "ui/gfx/codec/png_codec.h" | 30 #include "ui/gfx/codec/png_codec.h" |
| 31 #include "ui/gfx/color_utils.h" | 31 #include "ui/gfx/color_utils.h" |
| 32 #include "ui/gfx/favicon_size.h" |
| 32 #include "ui/gfx/skbitmap_operations.h" | 33 #include "ui/gfx/skbitmap_operations.h" |
| 33 #include "webkit/glue/image_decoder.h" | 34 #include "webkit/glue/image_decoder.h" |
| 34 | 35 |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| 37 scoped_refptr<base::RefCountedMemory> BitmapToMemory(const SkBitmap* image) { | 38 scoped_refptr<base::RefCountedMemory> BitmapToMemory(const SkBitmap* image) { |
| 38 base::RefCountedBytes* image_bytes = new base::RefCountedBytes; | 39 base::RefCountedBytes* image_bytes = new base::RefCountedBytes; |
| 39 gfx::PNGCodec::EncodeBGRASkBitmap(*image, false, &image_bytes->data()); | 40 gfx::PNGCodec::EncodeBGRASkBitmap(*image, false, &image_bytes->data()); |
| 40 return image_bytes; | 41 return image_bytes; |
| 41 } | 42 } |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 void ExtensionIconSource::LoadFaviconImage(int request_id) { | 207 void ExtensionIconSource::LoadFaviconImage(int request_id) { |
| 207 FaviconService* favicon_service = | 208 FaviconService* favicon_service = |
| 208 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 209 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 209 // Fall back to the default icons if the service isn't available. | 210 // Fall back to the default icons if the service isn't available. |
| 210 if (favicon_service == NULL) { | 211 if (favicon_service == NULL) { |
| 211 LoadDefaultImage(request_id); | 212 LoadDefaultImage(request_id); |
| 212 return; | 213 return; |
| 213 } | 214 } |
| 214 | 215 |
| 215 GURL favicon_url = GetData(request_id)->extension->GetFullLaunchURL(); | 216 GURL favicon_url = GetData(request_id)->extension->GetFullLaunchURL(); |
| 216 FaviconService::Handle handle = favicon_service->GetFaviconForURL( | 217 FaviconService::Handle handle = favicon_service->GetRawFaviconForURL( |
| 217 profile_, | 218 profile_, |
| 218 favicon_url, | 219 favicon_url, |
| 219 history::FAVICON, | 220 history::FAVICON, |
| 221 gfx::kFaviconSize, |
| 222 ui::SCALE_FACTOR_100P, |
| 220 &cancelable_consumer_, | 223 &cancelable_consumer_, |
| 221 base::Bind(&ExtensionIconSource::OnFaviconDataAvailable, | 224 base::Bind(&ExtensionIconSource::OnFaviconDataAvailable, |
| 222 base::Unretained(this))); | 225 base::Unretained(this))); |
| 223 cancelable_consumer_.SetClientData(favicon_service, handle, request_id); | 226 cancelable_consumer_.SetClientData(favicon_service, handle, request_id); |
| 224 } | 227 } |
| 225 | 228 |
| 226 void ExtensionIconSource::OnFaviconDataAvailable( | 229 void ExtensionIconSource::OnFaviconDataAvailable( |
| 227 FaviconService::Handle request_handle, | 230 FaviconService::Handle request_handle, |
| 228 history::FaviconData favicon) { | 231 const history::FaviconBitmapResult& bitmap_result) { |
| 229 int request_id = cancelable_consumer_.GetClientData( | 232 int request_id = cancelable_consumer_.GetClientData( |
| 230 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS), | 233 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS), |
| 231 request_handle); | 234 request_handle); |
| 232 ExtensionIconRequest* request = GetData(request_id); | 235 ExtensionIconRequest* request = GetData(request_id); |
| 233 | 236 |
| 234 // Fallback to the default icon if there wasn't a favicon. | 237 // Fallback to the default icon if there wasn't a favicon. |
| 235 if (!favicon.is_valid()) { | 238 if (!bitmap_result.is_valid()) { |
| 236 LoadDefaultImage(request_id); | 239 LoadDefaultImage(request_id); |
| 237 return; | 240 return; |
| 238 } | 241 } |
| 239 | 242 |
| 240 if (!request->grayscale) { | 243 if (!request->grayscale) { |
| 241 // If we don't need a grayscale image, then we can bypass FinalizeImage | 244 // If we don't need a grayscale image, then we can bypass FinalizeImage |
| 242 // to avoid unnecessary conversions. | 245 // to avoid unnecessary conversions. |
| 243 ClearData(request_id); | 246 ClearData(request_id); |
| 244 SendResponse(request_id, favicon.image_data); | 247 SendResponse(request_id, bitmap_result.bitmap_data); |
| 245 } else { | 248 } else { |
| 246 FinalizeImage(ToBitmap(favicon.image_data->front(), | 249 FinalizeImage(ToBitmap(bitmap_result.bitmap_data->front(), |
| 247 favicon.image_data->size()), request_id); | 250 bitmap_result.bitmap_data->size()), request_id); |
| 248 } | 251 } |
| 249 } | 252 } |
| 250 | 253 |
| 251 void ExtensionIconSource::OnImageLoaded(const gfx::Image& image, | 254 void ExtensionIconSource::OnImageLoaded(const gfx::Image& image, |
| 252 const std::string& extension_id, | 255 const std::string& extension_id, |
| 253 int index) { | 256 int index) { |
| 254 int request_id = tracker_map_[index]; | 257 int request_id = tracker_map_[index]; |
| 255 tracker_map_.erase(tracker_map_.find(index)); | 258 tracker_map_.erase(tracker_map_.find(index)); |
| 256 | 259 |
| 257 if (image.IsEmpty()) | 260 if (image.IsEmpty()) |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 | 345 |
| 343 void ExtensionIconSource::ClearData(int request_id) { | 346 void ExtensionIconSource::ClearData(int request_id) { |
| 344 std::map<int, ExtensionIconRequest*>::iterator i = | 347 std::map<int, ExtensionIconRequest*>::iterator i = |
| 345 request_map_.find(request_id); | 348 request_map_.find(request_id); |
| 346 if (i == request_map_.end()) | 349 if (i == request_map_.end()) |
| 347 return; | 350 return; |
| 348 | 351 |
| 349 delete i->second; | 352 delete i->second; |
| 350 request_map_.erase(i); | 353 request_map_.erase(i); |
| 351 } | 354 } |
| OLD | NEW |