Chromium Code Reviews| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 const GURL& image_url, | 377 const GURL& image_url, |
| 378 const std::vector<SkBitmap>& bitmaps, | 378 const std::vector<SkBitmap>& bitmaps, |
| 379 const std::vector<gfx::Size>& original_bitmap_sizes) { | 379 const std::vector<gfx::Size>& original_bitmap_sizes) { |
| 380 DownloadRequests::iterator i = download_requests_.find(id); | 380 DownloadRequests::iterator i = download_requests_.find(id); |
| 381 if (i == download_requests_.end()) { | 381 if (i == download_requests_.end()) { |
| 382 // Currently WebContents notifies us of ANY downloads so that it is | 382 // Currently WebContents notifies us of ANY downloads so that it is |
| 383 // possible to get here. | 383 // possible to get here. |
| 384 return; | 384 return; |
| 385 } | 385 } |
| 386 | 386 |
| 387 DownloadRequest download_request = i->second; | |
|
pkotwicz
2015/02/19 21:29:57
I switched to erasing |download_requests_| immedia
| |
| 388 download_requests_.erase(i); | |
| 389 | |
| 387 if (current_candidate() && | 390 if (current_candidate() && |
| 388 DoUrlAndIconMatch(*current_candidate(), image_url, i->second.icon_type)) { | 391 DoUrlAndIconMatch(*current_candidate(), |
| 392 image_url, | |
| 393 download_request.icon_type)) { | |
| 389 bool request_next_icon = true; | 394 bool request_next_icon = true; |
| 390 float score = 0.0f; | 395 float score = 0.0f; |
| 391 gfx::ImageSkia image_skia; | 396 gfx::ImageSkia image_skia; |
| 392 if (download_largest_icon_ && !bitmaps.empty()) { | 397 if (download_largest_icon_ && !bitmaps.empty()) { |
| 393 int index = -1; | 398 int index = -1; |
| 394 // Use the largest bitmap if FaviconURL doesn't have sizes attribute. | 399 // Use the largest bitmap if FaviconURL doesn't have sizes attribute. |
| 395 if (current_candidate()->icon_sizes.empty()) { | 400 if (current_candidate()->icon_sizes.empty()) { |
| 396 index = GetLargestSizeIndex(original_bitmap_sizes); | 401 index = GetLargestSizeIndex(original_bitmap_sizes); |
| 397 } else { | 402 } else { |
| 398 index = GetIndexBySize(original_bitmap_sizes, | 403 index = GetIndexBySize(original_bitmap_sizes, |
| 399 current_candidate()->icon_sizes[0]); | 404 current_candidate()->icon_sizes[0]); |
| 400 // Find largest bitmap if there is no one exactly matched. | 405 // Find largest bitmap if there is no one exactly matched. |
| 401 if (index == -1) | 406 if (index == -1) |
| 402 index = GetLargestSizeIndex(original_bitmap_sizes); | 407 index = GetLargestSizeIndex(original_bitmap_sizes); |
| 403 } | 408 } |
| 404 image_skia = gfx::ImageSkia(gfx::ImageSkiaRep(bitmaps[index], 1)); | 409 image_skia = gfx::ImageSkia(gfx::ImageSkiaRep(bitmaps[index], 1)); |
| 405 } else { | 410 } else { |
| 406 image_skia = CreateFaviconImageSkia(bitmaps, | 411 image_skia = CreateFaviconImageSkia(bitmaps, |
| 407 original_bitmap_sizes, | 412 original_bitmap_sizes, |
| 408 preferred_icon_size(), | 413 preferred_icon_size(), |
| 409 &score); | 414 &score); |
| 410 } | 415 } |
| 411 | 416 |
| 412 if (!image_skia.isNull()) { | 417 if (!image_skia.isNull()) { |
| 413 gfx::Image image(image_skia); | 418 gfx::Image image(image_skia); |
| 414 // The downloaded icon is still valid when there is no FaviconURL update | 419 // The downloaded icon is still valid when there is no FaviconURL update |
| 415 // during the downloading. | 420 // during the downloading. |
| 416 if (!bitmaps.empty()) { | 421 if (!bitmaps.empty()) { |
| 417 request_next_icon = !UpdateFaviconCandidate( | 422 request_next_icon = !UpdateFaviconCandidate( |
| 418 i->second.url, image_url, image, score, i->second.icon_type); | 423 download_request.url, image_url, image, score, |
| 424 download_request.icon_type); | |
| 419 } | 425 } |
| 420 } | 426 } |
| 421 if (request_next_icon && !PageChangedSinceFaviconWasRequested() && | 427 if (request_next_icon && !PageChangedSinceFaviconWasRequested() && |
| 422 image_urls_.size() > 1) { | 428 image_urls_.size() > 1) { |
| 423 // Remove the first member of image_urls_ and process the remaining. | 429 // Remove the first member of image_urls_ and process the remaining. |
| 424 image_urls_.erase(image_urls_.begin()); | 430 image_urls_.erase(image_urls_.begin()); |
| 425 ProcessCurrentUrl(); | 431 ProcessCurrentUrl(); |
| 426 } else if (best_favicon_candidate_.icon_type != | 432 } else if (best_favicon_candidate_.icon_type != |
| 427 favicon_base::INVALID_ICON) { | 433 favicon_base::INVALID_ICON) { |
| 428 // No more icons to request, set the favicon from the candidate. | 434 // No more icons to request, set the favicon from the candidate. |
| 429 SetFavicon(best_favicon_candidate_.url, | 435 SetFavicon(best_favicon_candidate_.url, |
| 430 best_favicon_candidate_.image_url, | 436 best_favicon_candidate_.image_url, |
| 431 best_favicon_candidate_.image, | 437 best_favicon_candidate_.image, |
| 432 best_favicon_candidate_.icon_type); | 438 best_favicon_candidate_.icon_type); |
| 433 // Reset candidate. | 439 // Reset candidate. |
| 434 image_urls_.clear(); | 440 image_urls_.clear(); |
| 441 download_requests_.clear(); | |
| 435 best_favicon_candidate_ = FaviconCandidate(); | 442 best_favicon_candidate_ = FaviconCandidate(); |
| 436 } | 443 } |
| 437 } | 444 } |
| 438 download_requests_.erase(i); | |
| 439 } | 445 } |
| 440 | 446 |
| 441 bool FaviconHandler::PageChangedSinceFaviconWasRequested() { | 447 bool FaviconHandler::PageChangedSinceFaviconWasRequested() { |
| 442 if (UrlMatches(driver_->GetActiveURL(), url_) && url_.is_valid()) { | 448 if (UrlMatches(driver_->GetActiveURL(), url_) && url_.is_valid()) { |
| 443 return false; | 449 return false; |
| 444 } | 450 } |
| 445 // If the URL has changed out from under us (as will happen with redirects) | 451 // If the URL has changed out from under us (as will happen with redirects) |
| 446 // return true. | 452 // return true. |
| 447 return true; | 453 return true; |
| 448 } | 454 } |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 676 if (i->icon_sizes.empty()) | 682 if (i->icon_sizes.empty()) |
| 677 continue; | 683 continue; |
| 678 | 684 |
| 679 gfx::Size largest = i->icon_sizes[GetLargestSizeIndex(i->icon_sizes)]; | 685 gfx::Size largest = i->icon_sizes[GetLargestSizeIndex(i->icon_sizes)]; |
| 680 i->icon_sizes.clear(); | 686 i->icon_sizes.clear(); |
| 681 i->icon_sizes.push_back(largest); | 687 i->icon_sizes.push_back(largest); |
| 682 } | 688 } |
| 683 std::stable_sort(image_urls_.begin(), image_urls_.end(), | 689 std::stable_sort(image_urls_.begin(), image_urls_.end(), |
| 684 CompareIconSize); | 690 CompareIconSize); |
| 685 } | 691 } |
| OLD | NEW |