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/favicon/favicon_handler.h" | 5 #include "chrome/browser/favicon/favicon_handler.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 entry->GetFavicon().url = icon_url; | 307 entry->GetFavicon().url = icon_url; |
308 UpdateFavicon(entry, &image); | 308 UpdateFavicon(entry, &image); |
309 } | 309 } |
310 } | 310 } |
311 } | 311 } |
312 | 312 |
313 void FaviconHandler::UpdateFavicon(NavigationEntry* entry, | 313 void FaviconHandler::UpdateFavicon(NavigationEntry* entry, |
314 const std::vector<history::FaviconBitmapResult>& favicon_bitmap_results) { | 314 const std::vector<history::FaviconBitmapResult>& favicon_bitmap_results) { |
315 gfx::Image resized_image = FaviconUtil::SelectFaviconFramesFromPNGs( | 315 gfx::Image resized_image = FaviconUtil::SelectFaviconFramesFromPNGs( |
316 favicon_bitmap_results, | 316 favicon_bitmap_results, |
317 ui::GetSupportedScaleFactors(), | 317 FaviconUtil::GetFaviconScaleFactors(), |
318 preferred_icon_size()); | 318 preferred_icon_size()); |
319 if (!resized_image.IsEmpty()) | 319 if (!resized_image.IsEmpty()) |
320 UpdateFavicon(entry, &resized_image); | 320 UpdateFavicon(entry, &resized_image); |
321 } | 321 } |
322 | 322 |
323 void FaviconHandler::UpdateFavicon(NavigationEntry* entry, | 323 void FaviconHandler::UpdateFavicon(NavigationEntry* entry, |
324 const gfx::Image* image) { | 324 const gfx::Image* image) { |
325 // No matter what happens, we need to mark the favicon as being set. | 325 // No matter what happens, we need to mark the favicon as being set. |
326 entry->GetFavicon().valid = true; | 326 entry->GetFavicon().valid = true; |
327 | 327 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 std::vector<size_t> selected_bitmap_indices; | 405 std::vector<size_t> selected_bitmap_indices; |
406 SelectFaviconFrameIndices(sizes, scale_factors, requested_size, | 406 SelectFaviconFrameIndices(sizes, scale_factors, requested_size, |
407 &selected_bitmap_indices, NULL); | 407 &selected_bitmap_indices, NULL); |
408 DCHECK_EQ(1u, selected_bitmap_indices.size()); | 408 DCHECK_EQ(1u, selected_bitmap_indices.size()); |
409 size_t closest_index = selected_bitmap_indices[0]; | 409 size_t closest_index = selected_bitmap_indices[0]; |
410 i->second.callback.Run(id, errored, bitmaps[closest_index]); | 410 i->second.callback.Run(id, errored, bitmaps[closest_index]); |
411 } else if (current_candidate() && | 411 } else if (current_candidate() && |
412 DoUrlAndIconMatch(*current_candidate(), image_url, | 412 DoUrlAndIconMatch(*current_candidate(), image_url, |
413 i->second.icon_type)) { | 413 i->second.icon_type)) { |
414 float score = 0.0f; | 414 float score = 0.0f; |
415 std::vector<ui::ScaleFactor> scale_factors = ui::GetSupportedScaleFactors(); | 415 std::vector<ui::ScaleFactor> scale_factors = |
| 416 FaviconUtil::GetFaviconScaleFactors(); |
416 gfx::Image image(SelectFaviconFrames(bitmaps, scale_factors, requested_size, | 417 gfx::Image image(SelectFaviconFrames(bitmaps, scale_factors, requested_size, |
417 &score)); | 418 &score)); |
418 | 419 |
419 // The downloaded icon is still valid when there is no FaviconURL update | 420 // The downloaded icon is still valid when there is no FaviconURL update |
420 // during the downloading. | 421 // during the downloading. |
421 bool request_next_icon = true; | 422 bool request_next_icon = true; |
422 if (!errored) { | 423 if (!errored) { |
423 request_next_icon = !UpdateFaviconCandidate( | 424 request_next_icon = !UpdateFaviconCandidate( |
424 i->second.url, image_url, image, score, i->second.icon_type); | 425 i->second.url, image_url, image, score, i->second.icon_type); |
425 } | 426 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 const GURL& page_url, | 465 const GURL& page_url, |
465 const GURL& icon_url, | 466 const GURL& icon_url, |
466 history::IconType icon_type, | 467 history::IconType icon_type, |
467 CancelableRequestConsumerBase* consumer, | 468 CancelableRequestConsumerBase* consumer, |
468 const FaviconService::FaviconResultsCallback& callback) { | 469 const FaviconService::FaviconResultsCallback& callback) { |
469 // TODO(pkotwicz): pass in all of |image_urls_| to | 470 // TODO(pkotwicz): pass in all of |image_urls_| to |
470 // UpdateFaviconMappingsAndFetch(). | 471 // UpdateFaviconMappingsAndFetch(). |
471 std::vector<GURL> icon_urls; | 472 std::vector<GURL> icon_urls; |
472 icon_urls.push_back(icon_url); | 473 icon_urls.push_back(icon_url); |
473 GetFaviconService()->UpdateFaviconMappingsAndFetch(page_url, icon_urls, | 474 GetFaviconService()->UpdateFaviconMappingsAndFetch(page_url, icon_urls, |
474 icon_type, preferred_icon_size(), ui::GetSupportedScaleFactors(), | 475 icon_type, preferred_icon_size(), consumer, callback); |
475 consumer, callback); | |
476 } | 476 } |
477 | 477 |
478 void FaviconHandler::GetFavicon( | 478 void FaviconHandler::GetFavicon( |
479 const GURL& icon_url, | 479 const GURL& icon_url, |
480 history::IconType icon_type, | 480 history::IconType icon_type, |
481 CancelableRequestConsumerBase* consumer, | 481 CancelableRequestConsumerBase* consumer, |
482 const FaviconService::FaviconResultsCallback& callback) { | 482 const FaviconService::FaviconResultsCallback& callback) { |
483 GetFaviconService()->GetFavicon(icon_url, icon_type, preferred_icon_size(), | 483 GetFaviconService()->GetFavicon(icon_url, icon_type, preferred_icon_size(), |
484 ui::GetSupportedScaleFactors(), consumer, callback); | 484 consumer, callback); |
485 } | 485 } |
486 | 486 |
487 void FaviconHandler::GetFaviconForURL( | 487 void FaviconHandler::GetFaviconForURL( |
488 const GURL& page_url, | 488 const GURL& page_url, |
489 int icon_types, | 489 int icon_types, |
490 CancelableRequestConsumerBase* consumer, | 490 CancelableRequestConsumerBase* consumer, |
491 const FaviconService::FaviconResultsCallback& callback) { | 491 const FaviconService::FaviconResultsCallback& callback) { |
492 GetFaviconService()->GetFaviconForURL( | 492 GetFaviconService()->GetFaviconForURL( |
493 FaviconService::FaviconForURLParams(profile_, page_url, icon_types, | 493 FaviconService::FaviconForURLParams(profile_, page_url, icon_types, |
494 preferred_icon_size(), consumer), | 494 preferred_icon_size(), consumer), |
495 ui::GetSupportedScaleFactors(), callback); | 495 callback); |
496 } | 496 } |
497 | 497 |
498 void FaviconHandler::SetHistoryFavicons(const GURL& page_url, | 498 void FaviconHandler::SetHistoryFavicons(const GURL& page_url, |
499 const GURL& icon_url, | 499 const GURL& icon_url, |
500 history::IconType icon_type, | 500 history::IconType icon_type, |
501 const gfx::Image& image) { | 501 const gfx::Image& image) { |
502 GetFaviconService()->SetFavicons(page_url, icon_url, icon_type, image); | 502 GetFaviconService()->SetFavicons(page_url, icon_url, icon_type, image); |
503 } | 503 } |
504 | 504 |
505 bool FaviconHandler::ShouldSaveFavicon(const GURL& url) { | 505 bool FaviconHandler::ShouldSaveFavicon(const GURL& url) { |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 const int download_id = DownloadFavicon(image_url, image_size); | 644 const int download_id = DownloadFavicon(image_url, image_size); |
645 if (download_id) { | 645 if (download_id) { |
646 // Download ids should be unique. | 646 // Download ids should be unique. |
647 DCHECK(download_requests_.find(download_id) == download_requests_.end()); | 647 DCHECK(download_requests_.find(download_id) == download_requests_.end()); |
648 download_requests_[download_id] = | 648 download_requests_[download_id] = |
649 DownloadRequest(url, image_url, callback, icon_type); | 649 DownloadRequest(url, image_url, callback, icon_type); |
650 } | 650 } |
651 | 651 |
652 return download_id; | 652 return download_id; |
653 } | 653 } |
OLD | NEW |