| 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" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/string_split.h" | 12 #include "base/string_split.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 16 #include "chrome/browser/extensions/extension_prefs.h" | 16 #include "chrome/browser/extensions/extension_prefs.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/extensions/image_loader.h" |
| 18 #include "chrome/browser/favicon/favicon_service_factory.h" | 19 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
| 21 #include "chrome/common/extensions/extension_constants.h" | 22 #include "chrome/common/extensions/extension_constants.h" |
| 22 #include "chrome/common/extensions/extension_resource.h" | 23 #include "chrome/common/extensions/extension_resource.h" |
| 23 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 24 #include "googleurl/src/gurl.h" | 25 #include "googleurl/src/gurl.h" |
| 25 #include "grit/component_extension_resources_map.h" | 26 #include "grit/component_extension_resources_map.h" |
| 26 #include "grit/theme_resources.h" | 27 #include "grit/theme_resources.h" |
| 27 #include "skia/ext/image_operations.h" | 28 #include "skia/ext/image_operations.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 50 webkit_glue::ImageDecoder decoder; | 51 webkit_glue::ImageDecoder decoder; |
| 51 SkBitmap* decoded = new SkBitmap(); | 52 SkBitmap* decoded = new SkBitmap(); |
| 52 *decoded = decoder.Decode(data, size); | 53 *decoded = decoder.Decode(data, size); |
| 53 return decoded; | 54 return decoded; |
| 54 } | 55 } |
| 55 | 56 |
| 56 } // namespace | 57 } // namespace |
| 57 | 58 |
| 58 ExtensionIconSource::ExtensionIconSource(Profile* profile) | 59 ExtensionIconSource::ExtensionIconSource(Profile* profile) |
| 59 : DataSource(chrome::kChromeUIExtensionIconHost, MessageLoop::current()), | 60 : DataSource(chrome::kChromeUIExtensionIconHost, MessageLoop::current()), |
| 60 profile_(profile), | 61 profile_(profile) { |
| 61 next_tracker_id_(0) { | |
| 62 tracker_.reset(new ImageLoadingTracker(this)); | |
| 63 } | 62 } |
| 64 | 63 |
| 65 struct ExtensionIconSource::ExtensionIconRequest { | 64 struct ExtensionIconSource::ExtensionIconRequest { |
| 66 int request_id; | 65 int request_id; |
| 67 const extensions::Extension* extension; | 66 const extensions::Extension* extension; |
| 68 bool grayscale; | 67 bool grayscale; |
| 69 int size; | 68 int size; |
| 70 ExtensionIconSet::MatchType match; | 69 ExtensionIconSet::MatchType match; |
| 71 }; | 70 }; |
| 72 | 71 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 // image than returning nothing at all. | 180 // image than returning nothing at all. |
| 182 if (resized_image.empty()) | 181 if (resized_image.empty()) |
| 183 resized_image = *default_image; | 182 resized_image = *default_image; |
| 184 | 183 |
| 185 FinalizeImage(&resized_image, request_id); | 184 FinalizeImage(&resized_image, request_id); |
| 186 } | 185 } |
| 187 | 186 |
| 188 void ExtensionIconSource::LoadExtensionImage(const ExtensionResource& icon, | 187 void ExtensionIconSource::LoadExtensionImage(const ExtensionResource& icon, |
| 189 int request_id) { | 188 int request_id) { |
| 190 ExtensionIconRequest* request = GetData(request_id); | 189 ExtensionIconRequest* request = GetData(request_id); |
| 191 tracker_map_[next_tracker_id_++] = request_id; | 190 extensions::ImageLoader::Get(profile_)->LoadImageAsync( |
| 192 tracker_->LoadImage(request->extension, | 191 request->extension, icon, |
| 193 icon, | 192 gfx::Size(request->size, request->size), |
| 194 gfx::Size(request->size, request->size), | 193 base::Bind(&ExtensionIconSource::OnImageLoaded, this, request_id)); |
| 195 ImageLoadingTracker::DONT_CACHE); | |
| 196 } | 194 } |
| 197 | 195 |
| 198 void ExtensionIconSource::LoadFaviconImage(int request_id) { | 196 void ExtensionIconSource::LoadFaviconImage(int request_id) { |
| 199 FaviconService* favicon_service = | 197 FaviconService* favicon_service = |
| 200 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); | 198 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 201 // Fall back to the default icons if the service isn't available. | 199 // Fall back to the default icons if the service isn't available. |
| 202 if (favicon_service == NULL) { | 200 if (favicon_service == NULL) { |
| 203 LoadDefaultImage(request_id); | 201 LoadDefaultImage(request_id); |
| 204 return; | 202 return; |
| 205 } | 203 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 236 // If we don't need a grayscale image, then we can bypass FinalizeImage | 234 // If we don't need a grayscale image, then we can bypass FinalizeImage |
| 237 // to avoid unnecessary conversions. | 235 // to avoid unnecessary conversions. |
| 238 ClearData(request_id); | 236 ClearData(request_id); |
| 239 SendResponse(request_id, bitmap_result.bitmap_data); | 237 SendResponse(request_id, bitmap_result.bitmap_data); |
| 240 } else { | 238 } else { |
| 241 FinalizeImage(ToBitmap(bitmap_result.bitmap_data->front(), | 239 FinalizeImage(ToBitmap(bitmap_result.bitmap_data->front(), |
| 242 bitmap_result.bitmap_data->size()), request_id); | 240 bitmap_result.bitmap_data->size()), request_id); |
| 243 } | 241 } |
| 244 } | 242 } |
| 245 | 243 |
| 246 void ExtensionIconSource::OnImageLoaded(const gfx::Image& image, | 244 void ExtensionIconSource::OnImageLoaded(int request_id, |
| 247 const std::string& extension_id, | 245 const gfx::Image& image) { |
| 248 int index) { | |
| 249 int request_id = tracker_map_[index]; | |
| 250 tracker_map_.erase(tracker_map_.find(index)); | |
| 251 | |
| 252 if (image.IsEmpty()) | 246 if (image.IsEmpty()) |
| 253 LoadIconFailed(request_id); | 247 LoadIconFailed(request_id); |
| 254 else | 248 else |
| 255 FinalizeImage(image.ToSkBitmap(), request_id); | 249 FinalizeImage(image.ToSkBitmap(), request_id); |
| 256 } | 250 } |
| 257 | 251 |
| 258 void ExtensionIconSource::LoadIconFailed(int request_id) { | 252 void ExtensionIconSource::LoadIconFailed(int request_id) { |
| 259 ExtensionIconRequest* request = GetData(request_id); | 253 ExtensionIconRequest* request = GetData(request_id); |
| 260 ExtensionResource icon = | 254 ExtensionResource icon = |
| 261 request->extension->GetIconResource(request->size, request->match); | 255 request->extension->GetIconResource(request->size, request->match); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 | 331 |
| 338 void ExtensionIconSource::ClearData(int request_id) { | 332 void ExtensionIconSource::ClearData(int request_id) { |
| 339 std::map<int, ExtensionIconRequest*>::iterator i = | 333 std::map<int, ExtensionIconRequest*>::iterator i = |
| 340 request_map_.find(request_id); | 334 request_map_.find(request_id); |
| 341 if (i == request_map_.end()) | 335 if (i == request_map_.end()) |
| 342 return; | 336 return; |
| 343 | 337 |
| 344 delete i->second; | 338 delete i->second; |
| 345 request_map_.erase(i); | 339 request_map_.erase(i); |
| 346 } | 340 } |
| OLD | NEW |