Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: chrome/browser/favicon/favicon_handler.cc

Issue 934693002: Reload favicon from HTTP cache on Ctrl+Refresh (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/favicon/favicon_handler.h ('k') | chrome/browser/favicon/favicon_tab_helper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 const GURL& image_url, 374 const GURL& image_url,
375 const std::vector<SkBitmap>& bitmaps, 375 const std::vector<SkBitmap>& bitmaps,
376 const std::vector<gfx::Size>& original_bitmap_sizes) { 376 const std::vector<gfx::Size>& original_bitmap_sizes) {
377 DownloadRequests::iterator i = download_requests_.find(id); 377 DownloadRequests::iterator i = download_requests_.find(id);
378 if (i == download_requests_.end()) { 378 if (i == download_requests_.end()) {
379 // Currently WebContents notifies us of ANY downloads so that it is 379 // Currently WebContents notifies us of ANY downloads so that it is
380 // possible to get here. 380 // possible to get here.
381 return; 381 return;
382 } 382 }
383 383
384 DownloadRequest download_request = i->second;
385 download_requests_.erase(i);
386
384 if (current_candidate() && 387 if (current_candidate() &&
385 DoUrlAndIconMatch(*current_candidate(), image_url, i->second.icon_type)) { 388 DoUrlAndIconMatch(*current_candidate(),
389 image_url,
390 download_request.icon_type)) {
386 bool request_next_icon = true; 391 bool request_next_icon = true;
387 float score = 0.0f; 392 float score = 0.0f;
388 gfx::ImageSkia image_skia; 393 gfx::ImageSkia image_skia;
389 if (download_largest_icon_ && !bitmaps.empty()) { 394 if (download_largest_icon_ && !bitmaps.empty()) {
390 int index = -1; 395 int index = -1;
391 // Use the largest bitmap if FaviconURL doesn't have sizes attribute. 396 // Use the largest bitmap if FaviconURL doesn't have sizes attribute.
392 if (current_candidate()->icon_sizes.empty()) { 397 if (current_candidate()->icon_sizes.empty()) {
393 index = GetLargestSizeIndex(original_bitmap_sizes); 398 index = GetLargestSizeIndex(original_bitmap_sizes);
394 } else { 399 } else {
395 index = GetIndexBySize(original_bitmap_sizes, 400 index = GetIndexBySize(original_bitmap_sizes,
396 current_candidate()->icon_sizes[0]); 401 current_candidate()->icon_sizes[0]);
397 // Find largest bitmap if there is no one exactly matched. 402 // Find largest bitmap if there is no one exactly matched.
398 if (index == -1) 403 if (index == -1)
399 index = GetLargestSizeIndex(original_bitmap_sizes); 404 index = GetLargestSizeIndex(original_bitmap_sizes);
400 } 405 }
401 image_skia = gfx::ImageSkia(gfx::ImageSkiaRep(bitmaps[index], 1)); 406 image_skia = gfx::ImageSkia(gfx::ImageSkiaRep(bitmaps[index], 1));
402 } else { 407 } else {
403 image_skia = CreateFaviconImageSkia(bitmaps, 408 image_skia = CreateFaviconImageSkia(bitmaps,
404 original_bitmap_sizes, 409 original_bitmap_sizes,
405 preferred_icon_size(), 410 preferred_icon_size(),
406 &score); 411 &score);
407 } 412 }
408 413
409 if (!image_skia.isNull()) { 414 if (!image_skia.isNull()) {
410 gfx::Image image(image_skia); 415 gfx::Image image(image_skia);
411 // The downloaded icon is still valid when there is no FaviconURL update 416 // The downloaded icon is still valid when there is no FaviconURL update
412 // during the downloading. 417 // during the downloading.
413 if (!bitmaps.empty()) { 418 if (!bitmaps.empty()) {
414 request_next_icon = !UpdateFaviconCandidate( 419 request_next_icon = !UpdateFaviconCandidate(
415 i->second.url, image_url, image, score, i->second.icon_type); 420 download_request.url, image_url, image, score,
421 download_request.icon_type);
416 } 422 }
417 } 423 }
418 if (request_next_icon && !PageChangedSinceFaviconWasRequested() && 424 if (request_next_icon && !PageChangedSinceFaviconWasRequested() &&
419 image_urls_.size() > 1) { 425 image_urls_.size() > 1) {
420 // Remove the first member of image_urls_ and process the remaining. 426 // Remove the first member of image_urls_ and process the remaining.
421 image_urls_.erase(image_urls_.begin()); 427 image_urls_.erase(image_urls_.begin());
422 ProcessCurrentUrl(); 428 ProcessCurrentUrl();
423 } else if (best_favicon_candidate_.icon_type != 429 } else if (best_favicon_candidate_.icon_type !=
424 favicon_base::INVALID_ICON) { 430 favicon_base::INVALID_ICON) {
425 // No more icons to request, set the favicon from the candidate. 431 // No more icons to request, set the favicon from the candidate.
426 SetFavicon(best_favicon_candidate_.url, 432 SetFavicon(best_favicon_candidate_.url,
427 best_favicon_candidate_.image_url, 433 best_favicon_candidate_.image_url,
428 best_favicon_candidate_.image, 434 best_favicon_candidate_.image,
429 best_favicon_candidate_.icon_type); 435 best_favicon_candidate_.icon_type);
430 // Reset candidate. 436 // Reset candidate.
431 image_urls_.clear(); 437 image_urls_.clear();
438 download_requests_.clear();
432 best_favicon_candidate_ = FaviconCandidate(); 439 best_favicon_candidate_ = FaviconCandidate();
433 } 440 }
434 } 441 }
435 download_requests_.erase(i);
436 } 442 }
437 443
438 bool FaviconHandler::PageChangedSinceFaviconWasRequested() { 444 bool FaviconHandler::PageChangedSinceFaviconWasRequested() {
439 if (UrlMatches(driver_->GetActiveURL(), url_) && url_.is_valid()) { 445 if (UrlMatches(driver_->GetActiveURL(), url_) && url_.is_valid()) {
440 return false; 446 return false;
441 } 447 }
442 // If the URL has changed out from under us (as will happen with redirects) 448 // If the URL has changed out from under us (as will happen with redirects)
443 // return true. 449 // return true.
444 return true; 450 return true;
445 } 451 }
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 continue; 684 continue;
679 685
680 gfx::Size largest = 686 gfx::Size largest =
681 image_url.icon_sizes[GetLargestSizeIndex(image_url.icon_sizes)]; 687 image_url.icon_sizes[GetLargestSizeIndex(image_url.icon_sizes)];
682 image_url.icon_sizes.clear(); 688 image_url.icon_sizes.clear();
683 image_url.icon_sizes.push_back(largest); 689 image_url.icon_sizes.push_back(largest);
684 } 690 }
685 std::stable_sort(image_urls_.begin(), image_urls_.end(), 691 std::stable_sort(image_urls_.begin(), image_urls_.end(),
686 CompareIconSize); 692 CompareIconSize);
687 } 693 }
OLDNEW
« no previous file with comments | « chrome/browser/favicon/favicon_handler.h ('k') | chrome/browser/favicon/favicon_tab_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698