| 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/favicon/favicon_service_factory.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
| 20 #include "chrome/common/extensions/extension_resource.h" | 21 #include "chrome/common/extensions/extension_resource.h" |
| 21 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
| 22 #include "googleurl/src/gurl.h" | 23 #include "googleurl/src/gurl.h" |
| 23 #include "grit/component_extension_resources_map.h" | 24 #include "grit/component_extension_resources_map.h" |
| 24 #include "grit/theme_resources.h" | 25 #include "grit/theme_resources.h" |
| 25 #include "skia/ext/image_operations.h" | 26 #include "skia/ext/image_operations.h" |
| 26 #include "ui/base/layout.h" | 27 #include "ui/base/layout.h" |
| 27 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 ExtensionIconRequest* request = GetData(request_id); | 197 ExtensionIconRequest* request = GetData(request_id); |
| 197 tracker_map_[next_tracker_id_++] = request_id; | 198 tracker_map_[next_tracker_id_++] = request_id; |
| 198 tracker_->LoadImage(request->extension, | 199 tracker_->LoadImage(request->extension, |
| 199 icon, | 200 icon, |
| 200 gfx::Size(request->size, request->size), | 201 gfx::Size(request->size, request->size), |
| 201 ImageLoadingTracker::DONT_CACHE); | 202 ImageLoadingTracker::DONT_CACHE); |
| 202 } | 203 } |
| 203 | 204 |
| 204 void ExtensionIconSource::LoadFaviconImage(int request_id) { | 205 void ExtensionIconSource::LoadFaviconImage(int request_id) { |
| 205 FaviconService* favicon_service = | 206 FaviconService* favicon_service = |
| 206 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS); | 207 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
| 207 // Fall back to the default icons if the service isn't available. | 208 // Fall back to the default icons if the service isn't available. |
| 208 if (favicon_service == NULL) { | 209 if (favicon_service == NULL) { |
| 209 LoadDefaultImage(request_id); | 210 LoadDefaultImage(request_id); |
| 210 return; | 211 return; |
| 211 } | 212 } |
| 212 | 213 |
| 213 GURL favicon_url = GetData(request_id)->extension->GetFullLaunchURL(); | 214 GURL favicon_url = GetData(request_id)->extension->GetFullLaunchURL(); |
| 214 FaviconService::Handle handle = favicon_service->GetFaviconForURL( | 215 FaviconService::Handle handle = favicon_service->GetFaviconForURL( |
| 215 favicon_url, | 216 favicon_url, |
| 216 history::FAVICON, | 217 history::FAVICON, |
| 217 &cancelable_consumer_, | 218 &cancelable_consumer_, |
| 218 base::Bind(&ExtensionIconSource::OnFaviconDataAvailable, | 219 base::Bind(&ExtensionIconSource::OnFaviconDataAvailable, |
| 219 base::Unretained(this))); | 220 base::Unretained(this))); |
| 220 cancelable_consumer_.SetClientData(favicon_service, handle, request_id); | 221 cancelable_consumer_.SetClientData(favicon_service, handle, request_id); |
| 221 } | 222 } |
| 222 | 223 |
| 223 void ExtensionIconSource::OnFaviconDataAvailable( | 224 void ExtensionIconSource::OnFaviconDataAvailable( |
| 224 FaviconService::Handle request_handle, | 225 FaviconService::Handle request_handle, |
| 225 history::FaviconData favicon) { | 226 history::FaviconData favicon) { |
| 226 int request_id = cancelable_consumer_.GetClientData( | 227 int request_id = cancelable_consumer_.GetClientData( |
| 227 profile_->GetFaviconService(Profile::EXPLICIT_ACCESS), request_handle); | 228 FaviconServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS), |
| 229 request_handle); |
| 228 ExtensionIconRequest* request = GetData(request_id); | 230 ExtensionIconRequest* request = GetData(request_id); |
| 229 | 231 |
| 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 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 340 |
| 339 void ExtensionIconSource::ClearData(int request_id) { | 341 void ExtensionIconSource::ClearData(int request_id) { |
| 340 std::map<int, ExtensionIconRequest*>::iterator i = | 342 std::map<int, ExtensionIconRequest*>::iterator i = |
| 341 request_map_.find(request_id); | 343 request_map_.find(request_id); |
| 342 if (i == request_map_.end()) | 344 if (i == request_map_.end()) |
| 343 return; | 345 return; |
| 344 | 346 |
| 345 delete i->second; | 347 delete i->second; |
| 346 request_map_.erase(i); | 348 request_map_.erase(i); |
| 347 } | 349 } |
| OLD | NEW |