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