| 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/favicon_source.h" | 5 #include "chrome/browser/ui/webui/favicon_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/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "chrome/browser/favicon/favicon_service_factory.h" | 10 #include "chrome/browser/favicon/favicon_service_factory.h" |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 } | 264 } |
| 265 } | 265 } |
| 266 return true; | 266 return true; |
| 267 } | 267 } |
| 268 | 268 |
| 269 void FaviconSource::OnFaviconDataAvailable( | 269 void FaviconSource::OnFaviconDataAvailable( |
| 270 const IconRequest& request, | 270 const IconRequest& request, |
| 271 const chrome::FaviconBitmapResult& bitmap_result) { | 271 const chrome::FaviconBitmapResult& bitmap_result) { |
| 272 if (bitmap_result.is_valid()) { | 272 if (bitmap_result.is_valid()) { |
| 273 // Forward the data along to the networking system. | 273 // Forward the data along to the networking system. |
| 274 request.callback.Run(bitmap_result.bitmap_data); | 274 request.callback.Run(bitmap_result.bitmap_data.get()); |
| 275 } else if (!HandleMissingResource(request)) { | 275 } else if (!HandleMissingResource(request)) { |
| 276 SendDefaultResponse(request); | 276 SendDefaultResponse(request); |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 | 279 |
| 280 void FaviconSource::SendDefaultResponse( | 280 void FaviconSource::SendDefaultResponse( |
| 281 const content::URLDataSource::GotDataCallback& callback) { | 281 const content::URLDataSource::GotDataCallback& callback) { |
| 282 SendDefaultResponse( | 282 SendDefaultResponse( |
| 283 IconRequest(callback, GURL(), 16, ui::SCALE_FACTOR_100P)); | 283 IconRequest(callback, GURL(), 16, ui::SCALE_FACTOR_100P)); |
| 284 } | 284 } |
| 285 | 285 |
| 286 void FaviconSource::SendDefaultResponse(const IconRequest& icon_request) { | 286 void FaviconSource::SendDefaultResponse(const IconRequest& icon_request) { |
| 287 int favicon_index; | 287 int favicon_index; |
| 288 int resource_id; | 288 int resource_id; |
| 289 switch (icon_request.size_in_dip) { | 289 switch (icon_request.size_in_dip) { |
| 290 case 64: | 290 case 64: |
| 291 favicon_index = SIZE_64; | 291 favicon_index = SIZE_64; |
| 292 resource_id = IDR_DEFAULT_FAVICON_64; | 292 resource_id = IDR_DEFAULT_FAVICON_64; |
| 293 break; | 293 break; |
| 294 case 32: | 294 case 32: |
| 295 favicon_index = SIZE_32; | 295 favicon_index = SIZE_32; |
| 296 resource_id = IDR_DEFAULT_FAVICON_32; | 296 resource_id = IDR_DEFAULT_FAVICON_32; |
| 297 break; | 297 break; |
| 298 default: | 298 default: |
| 299 favicon_index = SIZE_16; | 299 favicon_index = SIZE_16; |
| 300 resource_id = IDR_DEFAULT_FAVICON; | 300 resource_id = IDR_DEFAULT_FAVICON; |
| 301 break; | 301 break; |
| 302 } | 302 } |
| 303 base::RefCountedMemory* default_favicon = default_favicons_[favicon_index]; | 303 base::RefCountedMemory* default_favicon = |
| 304 default_favicons_[favicon_index].get(); |
| 304 | 305 |
| 305 if (!default_favicon) { | 306 if (!default_favicon) { |
| 306 ui::ScaleFactor scale_factor = icon_request.scale_factor; | 307 ui::ScaleFactor scale_factor = icon_request.scale_factor; |
| 307 default_favicon = ResourceBundle::GetSharedInstance() | 308 default_favicon = ResourceBundle::GetSharedInstance() |
| 308 .LoadDataResourceBytesForScale(resource_id, scale_factor); | 309 .LoadDataResourceBytesForScale(resource_id, scale_factor); |
| 309 default_favicons_[favicon_index] = default_favicon; | 310 default_favicons_[favicon_index] = default_favicon; |
| 310 } | 311 } |
| 311 | 312 |
| 312 icon_request.callback.Run(default_favicon); | 313 icon_request.callback.Run(default_favicon); |
| 313 } | 314 } |
| OLD | NEW |