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