| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 void ExtensionIconSource::LoadFaviconImage(int request_id) { | 176 void ExtensionIconSource::LoadFaviconImage(int request_id) { |
| 176 FaviconService* favicon_service = | 177 FaviconService* favicon_service = |
| 177 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 178 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 178 // Fall back to the default icons if the service isn't available. | 179 // Fall back to the default icons if the service isn't available. |
| 179 if (favicon_service == NULL) { | 180 if (favicon_service == NULL) { |
| 180 LoadDefaultImage(request_id); | 181 LoadDefaultImage(request_id); |
| 181 return; | 182 return; |
| 182 } | 183 } |
| 183 | 184 |
| 184 GURL favicon_url = GetData(request_id)->extension->GetFullLaunchURL(); | 185 GURL favicon_url = GetData(request_id)->extension->GetFullLaunchURL(); |
| 185 FaviconService::Handle handle = favicon_service->GetFaviconForURL( | 186 FaviconService::Handle handle = favicon_service->GetRawFaviconForURL( |
| 186 profile_, | 187 profile_, |
| 187 favicon_url, | 188 favicon_url, |
| 188 history::FAVICON, | 189 history::FAVICON, |
| 190 gfx::kFaviconSize, |
| 191 ui::SCALE_FACTOR_100P, |
| 189 &cancelable_consumer_, | 192 &cancelable_consumer_, |
| 190 base::Bind(&ExtensionIconSource::OnFaviconDataAvailable, | 193 base::Bind(&ExtensionIconSource::OnFaviconDataAvailable, |
| 191 base::Unretained(this))); | 194 base::Unretained(this))); |
| 192 cancelable_consumer_.SetClientData(favicon_service, handle, request_id); | 195 cancelable_consumer_.SetClientData(favicon_service, handle, request_id); |
| 193 } | 196 } |
| 194 | 197 |
| 195 void ExtensionIconSource::OnFaviconDataAvailable( | 198 void ExtensionIconSource::OnFaviconDataAvailable( |
| 196 FaviconService::Handle request_handle, | 199 FaviconService::Handle request_handle, |
| 197 history::FaviconData favicon) { | 200 const history::FaviconBitmapResult& bitmap_result) { |
| 198 int request_id = cancelable_consumer_.GetClientData( | 201 int request_id = cancelable_consumer_.GetClientData( |
| 199 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS), | 202 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS), |
| 200 request_handle); | 203 request_handle); |
| 201 ExtensionIconRequest* request = GetData(request_id); | 204 ExtensionIconRequest* request = GetData(request_id); |
| 202 | 205 |
| 203 // Fallback to the default icon if there wasn't a favicon. | 206 // Fallback to the default icon if there wasn't a favicon. |
| 204 if (!favicon.is_valid()) { | 207 if (!bitmap_result.is_valid()) { |
| 205 LoadDefaultImage(request_id); | 208 LoadDefaultImage(request_id); |
| 206 return; | 209 return; |
| 207 } | 210 } |
| 208 | 211 |
| 209 if (!request->grayscale) { | 212 if (!request->grayscale) { |
| 210 // If we don't need a grayscale image, then we can bypass FinalizeImage | 213 // If we don't need a grayscale image, then we can bypass FinalizeImage |
| 211 // to avoid unnecessary conversions. | 214 // to avoid unnecessary conversions. |
| 212 ClearData(request_id); | 215 ClearData(request_id); |
| 213 SendResponse(request_id, favicon.image_data); | 216 SendResponse(request_id, bitmap_result.bitmap_data); |
| 214 } else { | 217 } else { |
| 215 FinalizeImage(ToBitmap(favicon.image_data->front(), | 218 FinalizeImage(ToBitmap(bitmap_result.bitmap_data->front(), |
| 216 favicon.image_data->size()), request_id); | 219 bitmap_result.bitmap_data->size()), request_id); |
| 217 } | 220 } |
| 218 } | 221 } |
| 219 | 222 |
| 220 void ExtensionIconSource::OnImageLoaded(const gfx::Image& image, | 223 void ExtensionIconSource::OnImageLoaded(const gfx::Image& image, |
| 221 const std::string& extension_id, | 224 const std::string& extension_id, |
| 222 int index) { | 225 int index) { |
| 223 int request_id = tracker_map_[index]; | 226 int request_id = tracker_map_[index]; |
| 224 tracker_map_.erase(tracker_map_.find(index)); | 227 tracker_map_.erase(tracker_map_.find(index)); |
| 225 | 228 |
| 226 if (image.IsEmpty()) | 229 if (image.IsEmpty()) |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 | 316 |
| 314 void ExtensionIconSource::ClearData(int request_id) { | 317 void ExtensionIconSource::ClearData(int request_id) { |
| 315 std::map<int, ExtensionIconRequest*>::iterator i = | 318 std::map<int, ExtensionIconRequest*>::iterator i = |
| 316 request_map_.find(request_id); | 319 request_map_.find(request_id); |
| 317 if (i == request_map_.end()) | 320 if (i == request_map_.end()) |
| 318 return; | 321 return; |
| 319 | 322 |
| 320 delete i->second; | 323 delete i->second; |
| 321 request_map_.erase(i); | 324 request_map_.erase(i); |
| 322 } | 325 } |
| OLD | NEW |