| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
| 15 #include "chrome/browser/favicon/favicon_service_factory.h" | 15 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 16 #include "chrome/browser/favicon/favicon_util.h" | 16 #include "chrome/browser/favicon/favicon_util.h" |
| 17 #include "components/favicon_base/select_favicon_frames.h" | 17 #include "components/favicon_base/select_favicon_frames.h" |
| 18 #include "content/public/browser/favicon_status.h" | |
| 19 #include "content/public/browser/navigation_entry.h" | |
| 20 #include "skia/ext/image_operations.h" | 18 #include "skia/ext/image_operations.h" |
| 21 #include "ui/gfx/codec/png_codec.h" | 19 #include "ui/gfx/codec/png_codec.h" |
| 22 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
| 23 #include "ui/gfx/image/image_skia.h" | 21 #include "ui/gfx/image/image_skia.h" |
| 24 #include "ui/gfx/image/image_util.h" | 22 #include "ui/gfx/image/image_util.h" |
| 25 | 23 |
| 26 using content::FaviconURL; | 24 using content::FaviconURL; |
| 27 using content::NavigationEntry; | |
| 28 | 25 |
| 29 namespace { | 26 namespace { |
| 30 | 27 |
| 31 // Size (along each axis) of a touch icon. This currently corresponds to | 28 // Size (along each axis) of a touch icon. This currently corresponds to |
| 32 // the apple touch icon for iPad. | 29 // the apple touch icon for iPad. |
| 33 const int kTouchIconSize = 144; | 30 const int kTouchIconSize = 144; |
| 34 | 31 |
| 35 // Returns favicon_base::IconType the given icon_type corresponds to. | 32 // Returns favicon_base::IconType the given icon_type corresponds to. |
| 36 favicon_base::IconType ToChromeIconType(FaviconURL::IconType icon_type) { | 33 favicon_base::IconType ToChromeIconType(FaviconURL::IconType icon_type) { |
| 37 switch (icon_type) { | 34 switch (icon_type) { |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 } | 318 } |
| 322 | 319 |
| 323 void FaviconHandler::SetFavicon(const GURL& url, | 320 void FaviconHandler::SetFavicon(const GURL& url, |
| 324 const GURL& icon_url, | 321 const GURL& icon_url, |
| 325 const gfx::Image& image, | 322 const gfx::Image& image, |
| 326 favicon_base::IconType icon_type) { | 323 favicon_base::IconType icon_type) { |
| 327 if (client_->GetFaviconService() && ShouldSaveFavicon(url)) | 324 if (client_->GetFaviconService() && ShouldSaveFavicon(url)) |
| 328 SetHistoryFavicons(url, icon_url, icon_type, image); | 325 SetHistoryFavicons(url, icon_url, icon_type, image); |
| 329 | 326 |
| 330 if (UrlMatches(url, url_) && icon_type == favicon_base::FAVICON) { | 327 if (UrlMatches(url, url_) && icon_type == favicon_base::FAVICON) { |
| 331 NavigationEntry* entry = GetEntry(); | 328 if (!PageChangedSinceFaviconWasRequested()) |
| 332 if (entry) | 329 SetFaviconOnActivePage(icon_url, image); |
| 333 SetFaviconOnNavigationEntry(entry, icon_url, image); | |
| 334 } | 330 } |
| 335 } | 331 } |
| 336 | 332 |
| 337 void FaviconHandler::SetFaviconOnNavigationEntry( | 333 void FaviconHandler::SetFaviconOnActivePage(const std::vector< |
| 338 NavigationEntry* entry, | 334 favicon_base::FaviconBitmapResult>& favicon_bitmap_results) { |
| 339 const std::vector<favicon_base::FaviconBitmapResult>& | |
| 340 favicon_bitmap_results) { | |
| 341 gfx::Image resized_image = FaviconUtil::SelectFaviconFramesFromPNGs( | 335 gfx::Image resized_image = FaviconUtil::SelectFaviconFramesFromPNGs( |
| 342 favicon_bitmap_results, | 336 favicon_bitmap_results, |
| 343 FaviconUtil::GetFaviconScaleFactors(), | 337 FaviconUtil::GetFaviconScaleFactors(), |
| 344 preferred_icon_size()); | 338 preferred_icon_size()); |
| 345 // The history service sends back results for a single icon URL, so it does | 339 // The history service sends back results for a single icon URL, so it does |
| 346 // not matter which result we get the |icon_url| from. | 340 // not matter which result we get the |icon_url| from. |
| 347 const GURL icon_url = favicon_bitmap_results.empty() ? | 341 const GURL icon_url = favicon_bitmap_results.empty() ? |
| 348 GURL() : favicon_bitmap_results[0].icon_url; | 342 GURL() : favicon_bitmap_results[0].icon_url; |
| 349 SetFaviconOnNavigationEntry(entry, icon_url, resized_image); | 343 SetFaviconOnActivePage(icon_url, resized_image); |
| 350 } | 344 } |
| 351 | 345 |
| 352 void FaviconHandler::SetFaviconOnNavigationEntry( | 346 void FaviconHandler::SetFaviconOnActivePage(const GURL& icon_url, |
| 353 NavigationEntry* entry, | 347 const gfx::Image& image) { |
| 354 const GURL& icon_url, | |
| 355 const gfx::Image& image) { | |
| 356 // No matter what happens, we need to mark the favicon as being set. | 348 // No matter what happens, we need to mark the favicon as being set. |
| 357 entry->GetFavicon().valid = true; | 349 driver_->SetActiveFaviconValidity(true); |
| 358 | 350 |
| 359 bool icon_url_changed = (entry->GetFavicon().url != icon_url); | 351 bool icon_url_changed = driver_->GetActiveFaviconURL() != icon_url; |
| 360 entry->GetFavicon().url = icon_url; | 352 driver_->SetActiveFaviconURL(icon_url); |
| 361 | 353 |
| 362 if (image.IsEmpty()) | 354 if (image.IsEmpty()) |
| 363 return; | 355 return; |
| 364 | 356 |
| 365 gfx::Image image_with_adjusted_colorspace = image; | 357 gfx::Image image_with_adjusted_colorspace = image; |
| 366 FaviconUtil::SetFaviconColorSpace(&image_with_adjusted_colorspace); | 358 FaviconUtil::SetFaviconColorSpace(&image_with_adjusted_colorspace); |
| 367 | 359 |
| 368 entry->GetFavicon().image = image_with_adjusted_colorspace; | 360 driver_->SetActiveFaviconImage(image_with_adjusted_colorspace); |
| 369 NotifyFaviconUpdated(icon_url_changed); | 361 NotifyFaviconUpdated(icon_url_changed); |
| 370 } | 362 } |
| 371 | 363 |
| 372 void FaviconHandler::OnUpdateFaviconURL( | 364 void FaviconHandler::OnUpdateFaviconURL( |
| 373 const std::vector<FaviconURL>& candidates) { | 365 const std::vector<FaviconURL>& candidates) { |
| 374 image_urls_.clear(); | 366 image_urls_.clear(); |
| 375 best_favicon_candidate_ = FaviconCandidate(); | 367 best_favicon_candidate_ = FaviconCandidate(); |
| 376 for (std::vector<FaviconURL>::const_iterator i = candidates.begin(); | 368 for (std::vector<FaviconURL>::const_iterator i = candidates.begin(); |
| 377 i != candidates.end(); ++i) { | 369 i != candidates.end(); ++i) { |
| 378 if (!i->icon_url.is_empty() && (i->icon_type & icon_types_)) | 370 if (!i->icon_url.is_empty() && (i->icon_type & icon_types_)) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 389 | 381 |
| 390 if (download_largest_icon_) | 382 if (download_largest_icon_) |
| 391 SortAndPruneImageUrls(); | 383 SortAndPruneImageUrls(); |
| 392 | 384 |
| 393 ProcessCurrentUrl(); | 385 ProcessCurrentUrl(); |
| 394 } | 386 } |
| 395 | 387 |
| 396 void FaviconHandler::ProcessCurrentUrl() { | 388 void FaviconHandler::ProcessCurrentUrl() { |
| 397 DCHECK(!image_urls_.empty()); | 389 DCHECK(!image_urls_.empty()); |
| 398 | 390 |
| 399 NavigationEntry* entry = GetEntry(); | |
| 400 | |
| 401 // current_candidate() may return NULL if download_largest_icon_ is true and | 391 // current_candidate() may return NULL if download_largest_icon_ is true and |
| 402 // all the sizes are larger than the max. | 392 // all the sizes are larger than the max. |
| 403 if (!entry || !current_candidate()) | 393 if (PageChangedSinceFaviconWasRequested() || !current_candidate()) |
| 404 return; | 394 return; |
| 405 | 395 |
| 406 if (current_candidate()->icon_type == FaviconURL::FAVICON) { | 396 if (current_candidate()->icon_type == FaviconURL::FAVICON) { |
| 407 if (!favicon_expired_or_incomplete_ && entry->GetFavicon().valid && | 397 if (!favicon_expired_or_incomplete_ && |
| 398 driver_->GetActiveFaviconValidity() && |
| 408 DoUrlAndIconMatch(*current_candidate(), | 399 DoUrlAndIconMatch(*current_candidate(), |
| 409 entry->GetFavicon().url, | 400 driver_->GetActiveFaviconURL(), |
| 410 favicon_base::FAVICON)) | 401 favicon_base::FAVICON)) |
| 411 return; | 402 return; |
| 412 } else if (!favicon_expired_or_incomplete_ && got_favicon_from_history_ && | 403 } else if (!favicon_expired_or_incomplete_ && got_favicon_from_history_ && |
| 413 HasValidResult(history_results_) && | 404 HasValidResult(history_results_) && |
| 414 DoUrlsAndIconsMatch(*current_candidate(), history_results_)) { | 405 DoUrlsAndIconsMatch(*current_candidate(), history_results_)) { |
| 415 return; | 406 return; |
| 416 } | 407 } |
| 417 | 408 |
| 418 if (got_favicon_from_history_) | 409 if (got_favicon_from_history_) |
| 419 DownloadFaviconOrAskFaviconService( | 410 DownloadFaviconOrAskFaviconService( |
| 420 entry->GetURL(), current_candidate()->icon_url, | 411 driver_->GetActiveURL(), |
| 412 current_candidate()->icon_url, |
| 421 ToChromeIconType(current_candidate()->icon_type)); | 413 ToChromeIconType(current_candidate()->icon_type)); |
| 422 } | 414 } |
| 423 | 415 |
| 424 void FaviconHandler::OnDidDownloadFavicon( | 416 void FaviconHandler::OnDidDownloadFavicon( |
| 425 int id, | 417 int id, |
| 426 const GURL& image_url, | 418 const GURL& image_url, |
| 427 const std::vector<SkBitmap>& bitmaps, | 419 const std::vector<SkBitmap>& bitmaps, |
| 428 const std::vector<gfx::Size>& original_bitmap_sizes) { | 420 const std::vector<gfx::Size>& original_bitmap_sizes) { |
| 429 DownloadRequests::iterator i = download_requests_.find(id); | 421 DownloadRequests::iterator i = download_requests_.find(id); |
| 430 if (i == download_requests_.end()) { | 422 if (i == download_requests_.end()) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 | 459 |
| 468 if (!image_skia.isNull()) { | 460 if (!image_skia.isNull()) { |
| 469 gfx::Image image(image_skia); | 461 gfx::Image image(image_skia); |
| 470 // The downloaded icon is still valid when there is no FaviconURL update | 462 // The downloaded icon is still valid when there is no FaviconURL update |
| 471 // during the downloading. | 463 // during the downloading. |
| 472 if (!bitmaps.empty()) { | 464 if (!bitmaps.empty()) { |
| 473 request_next_icon = !UpdateFaviconCandidate( | 465 request_next_icon = !UpdateFaviconCandidate( |
| 474 i->second.url, image_url, image, score, i->second.icon_type); | 466 i->second.url, image_url, image, score, i->second.icon_type); |
| 475 } | 467 } |
| 476 } | 468 } |
| 477 if (request_next_icon && GetEntry() && image_urls_.size() > 1) { | 469 if (request_next_icon && !PageChangedSinceFaviconWasRequested() && |
| 470 image_urls_.size() > 1) { |
| 478 // Remove the first member of image_urls_ and process the remaining. | 471 // Remove the first member of image_urls_ and process the remaining. |
| 479 image_urls_.erase(image_urls_.begin()); | 472 image_urls_.erase(image_urls_.begin()); |
| 480 ProcessCurrentUrl(); | 473 ProcessCurrentUrl(); |
| 481 } else if (best_favicon_candidate_.icon_type != | 474 } else if (best_favicon_candidate_.icon_type != |
| 482 favicon_base::INVALID_ICON) { | 475 favicon_base::INVALID_ICON) { |
| 483 // No more icons to request, set the favicon from the candidate. | 476 // No more icons to request, set the favicon from the candidate. |
| 484 SetFavicon(best_favicon_candidate_.url, | 477 SetFavicon(best_favicon_candidate_.url, |
| 485 best_favicon_candidate_.image_url, | 478 best_favicon_candidate_.image_url, |
| 486 best_favicon_candidate_.image, | 479 best_favicon_candidate_.image, |
| 487 best_favicon_candidate_.icon_type); | 480 best_favicon_candidate_.icon_type); |
| 488 // Reset candidate. | 481 // Reset candidate. |
| 489 image_urls_.clear(); | 482 image_urls_.clear(); |
| 490 best_favicon_candidate_ = FaviconCandidate(); | 483 best_favicon_candidate_ = FaviconCandidate(); |
| 491 } | 484 } |
| 492 } | 485 } |
| 493 download_requests_.erase(i); | 486 download_requests_.erase(i); |
| 494 } | 487 } |
| 495 | 488 |
| 496 NavigationEntry* FaviconHandler::GetEntry() { | 489 bool FaviconHandler::PageChangedSinceFaviconWasRequested() { |
| 497 NavigationEntry* entry = driver_->GetActiveEntry(); | 490 if (UrlMatches(driver_->GetActiveURL(), url_) && url_.is_valid()) { |
| 498 if (entry && UrlMatches(entry->GetURL(), url_)) | 491 return false; |
| 499 return entry; | 492 } |
| 500 | |
| 501 // If the URL has changed out from under us (as will happen with redirects) | 493 // If the URL has changed out from under us (as will happen with redirects) |
| 502 // return NULL. | 494 // return true. |
| 503 return NULL; | 495 return true; |
| 504 } | 496 } |
| 505 | 497 |
| 506 int FaviconHandler::DownloadFavicon(const GURL& image_url, | 498 int FaviconHandler::DownloadFavicon(const GURL& image_url, |
| 507 int max_bitmap_size) { | 499 int max_bitmap_size) { |
| 508 if (!image_url.is_valid()) { | 500 if (!image_url.is_valid()) { |
| 509 NOTREACHED(); | 501 NOTREACHED(); |
| 510 return 0; | 502 return 0; |
| 511 } | 503 } |
| 512 return driver_->StartDownload(image_url, max_bitmap_size); | 504 return driver_->StartDownload(image_url, max_bitmap_size); |
| 513 } | 505 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 return client_->IsBookmarked(url); | 555 return client_->IsBookmarked(url); |
| 564 } | 556 } |
| 565 | 557 |
| 566 void FaviconHandler::NotifyFaviconUpdated(bool icon_url_changed) { | 558 void FaviconHandler::NotifyFaviconUpdated(bool icon_url_changed) { |
| 567 driver_->NotifyFaviconUpdated(icon_url_changed); | 559 driver_->NotifyFaviconUpdated(icon_url_changed); |
| 568 } | 560 } |
| 569 | 561 |
| 570 void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService( | 562 void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService( |
| 571 const std::vector<favicon_base::FaviconBitmapResult>& | 563 const std::vector<favicon_base::FaviconBitmapResult>& |
| 572 favicon_bitmap_results) { | 564 favicon_bitmap_results) { |
| 573 NavigationEntry* entry = GetEntry(); | 565 if (PageChangedSinceFaviconWasRequested()) |
| 574 if (!entry) | |
| 575 return; | 566 return; |
| 576 | |
| 577 got_favicon_from_history_ = true; | 567 got_favicon_from_history_ = true; |
| 578 history_results_ = favicon_bitmap_results; | 568 history_results_ = favicon_bitmap_results; |
| 579 | |
| 580 bool has_results = !favicon_bitmap_results.empty(); | 569 bool has_results = !favicon_bitmap_results.empty(); |
| 581 favicon_expired_or_incomplete_ = has_results && HasExpiredOrIncompleteResult( | 570 favicon_expired_or_incomplete_ = has_results && HasExpiredOrIncompleteResult( |
| 582 preferred_icon_size(), favicon_bitmap_results); | 571 preferred_icon_size(), favicon_bitmap_results); |
| 583 | |
| 584 if (has_results && icon_types_ == favicon_base::FAVICON && | 572 if (has_results && icon_types_ == favicon_base::FAVICON && |
| 585 !entry->GetFavicon().valid && | 573 !driver_->GetActiveFaviconValidity() && |
| 586 (!current_candidate() || | 574 (!current_candidate() || |
| 587 DoUrlsAndIconsMatch(*current_candidate(), favicon_bitmap_results))) { | 575 DoUrlsAndIconsMatch(*current_candidate(), favicon_bitmap_results))) { |
| 588 if (HasValidResult(favicon_bitmap_results)) { | 576 if (HasValidResult(favicon_bitmap_results)) { |
| 589 // The db knows the favicon (although it may be out of date) and the entry | 577 // The db knows the favicon (although it may be out of date) and the entry |
| 590 // doesn't have an icon. Set the favicon now, and if the favicon turns out | 578 // doesn't have an icon. Set the favicon now, and if the favicon turns out |
| 591 // to be expired (or the wrong url) we'll fetch later on. This way the | 579 // to be expired (or the wrong url) we'll fetch later on. This way the |
| 592 // user doesn't see a flash of the default favicon. | 580 // user doesn't see a flash of the default favicon. |
| 593 SetFaviconOnNavigationEntry(entry, favicon_bitmap_results); | 581 SetFaviconOnActivePage(favicon_bitmap_results); |
| 594 } else { | 582 } else { |
| 595 // If |favicon_bitmap_results| does not have any valid results, treat the | 583 // If |favicon_bitmap_results| does not have any valid results, treat the |
| 596 // favicon as if it's expired. | 584 // favicon as if it's expired. |
| 597 // TODO(pkotwicz): Do something better. | 585 // TODO(pkotwicz): Do something better. |
| 598 favicon_expired_or_incomplete_ = true; | 586 favicon_expired_or_incomplete_ = true; |
| 599 } | 587 } |
| 600 } | 588 } |
| 601 | |
| 602 if (has_results && !favicon_expired_or_incomplete_) { | 589 if (has_results && !favicon_expired_or_incomplete_) { |
| 603 if (current_candidate() && | 590 if (current_candidate() && |
| 604 !DoUrlsAndIconsMatch(*current_candidate(), favicon_bitmap_results)) { | 591 !DoUrlsAndIconsMatch(*current_candidate(), favicon_bitmap_results)) { |
| 605 // Mapping in the database is wrong. DownloadFavIconOrAskHistory will | 592 // Mapping in the database is wrong. DownloadFavIconOrAskHistory will |
| 606 // update the mapping for this url and download the favicon if we don't | 593 // update the mapping for this url and download the favicon if we don't |
| 607 // already have it. | 594 // already have it. |
| 608 DownloadFaviconOrAskFaviconService( | 595 DownloadFaviconOrAskFaviconService( |
| 609 entry->GetURL(), current_candidate()->icon_url, | 596 driver_->GetActiveURL(), |
| 597 current_candidate()->icon_url, |
| 610 ToChromeIconType(current_candidate()->icon_type)); | 598 ToChromeIconType(current_candidate()->icon_type)); |
| 611 } | 599 } |
| 612 } else if (current_candidate()) { | 600 } else if (current_candidate()) { |
| 613 // We know the official url for the favicon, but either don't have the | 601 // We know the official url for the favicon, but either don't have the |
| 614 // favicon or it's expired. Continue on to DownloadFaviconOrAskHistory to | 602 // favicon or it's expired. Continue on to DownloadFaviconOrAskHistory to |
| 615 // either download or check history again. | 603 // either download or check history again. |
| 616 DownloadFaviconOrAskFaviconService( | 604 DownloadFaviconOrAskFaviconService( |
| 617 entry->GetURL(), current_candidate()->icon_url, | 605 driver_->GetActiveURL(), |
| 606 current_candidate()->icon_url, |
| 618 ToChromeIconType(current_candidate()->icon_type)); | 607 ToChromeIconType(current_candidate()->icon_type)); |
| 619 } | 608 } |
| 620 // else we haven't got the icon url. When we get it we'll ask the | 609 // else we haven't got the icon url. When we get it we'll ask the |
| 621 // renderer to download the icon. | 610 // renderer to download the icon. |
| 622 } | 611 } |
| 623 | 612 |
| 624 void FaviconHandler::DownloadFaviconOrAskFaviconService( | 613 void FaviconHandler::DownloadFaviconOrAskFaviconService( |
| 625 const GURL& page_url, | 614 const GURL& page_url, |
| 626 const GURL& icon_url, | 615 const GURL& icon_url, |
| 627 favicon_base::IconType icon_type) { | 616 favicon_base::IconType icon_type) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 646 UpdateFaviconMappingAndFetch( | 635 UpdateFaviconMappingAndFetch( |
| 647 page_url, icon_url, icon_type, | 636 page_url, icon_url, icon_type, |
| 648 base::Bind(&FaviconHandler::OnFaviconData, base::Unretained(this)), | 637 base::Bind(&FaviconHandler::OnFaviconData, base::Unretained(this)), |
| 649 &cancelable_task_tracker_); | 638 &cancelable_task_tracker_); |
| 650 } | 639 } |
| 651 } | 640 } |
| 652 } | 641 } |
| 653 | 642 |
| 654 void FaviconHandler::OnFaviconData(const std::vector< | 643 void FaviconHandler::OnFaviconData(const std::vector< |
| 655 favicon_base::FaviconBitmapResult>& favicon_bitmap_results) { | 644 favicon_base::FaviconBitmapResult>& favicon_bitmap_results) { |
| 656 NavigationEntry* entry = GetEntry(); | 645 if (PageChangedSinceFaviconWasRequested()) |
| 657 if (!entry) | |
| 658 return; | 646 return; |
| 659 | 647 |
| 660 bool has_results = !favicon_bitmap_results.empty(); | 648 bool has_results = !favicon_bitmap_results.empty(); |
| 661 bool has_expired_or_incomplete_result = HasExpiredOrIncompleteResult( | 649 bool has_expired_or_incomplete_result = HasExpiredOrIncompleteResult( |
| 662 preferred_icon_size(), favicon_bitmap_results); | 650 preferred_icon_size(), favicon_bitmap_results); |
| 663 | 651 |
| 664 if (has_results && icon_types_ == favicon_base::FAVICON) { | 652 if (has_results && icon_types_ == favicon_base::FAVICON) { |
| 665 if (HasValidResult(favicon_bitmap_results)) { | 653 if (HasValidResult(favicon_bitmap_results)) { |
| 666 // There is a favicon, set it now. If expired we'll download the current | 654 // There is a favicon, set it now. If expired we'll download the current |
| 667 // one again, but at least the user will get some icon instead of the | 655 // one again, but at least the user will get some icon instead of the |
| 668 // default and most likely the current one is fine anyway. | 656 // default and most likely the current one is fine anyway. |
| 669 SetFaviconOnNavigationEntry(entry, favicon_bitmap_results); | 657 SetFaviconOnActivePage(favicon_bitmap_results); |
| 670 } | 658 } |
| 671 if (has_expired_or_incomplete_result) { | 659 if (has_expired_or_incomplete_result) { |
| 672 // The favicon is out of date. Request the current one. | 660 // The favicon is out of date. Request the current one. |
| 673 ScheduleDownload( | 661 ScheduleDownload(driver_->GetActiveURL(), |
| 674 entry->GetURL(), entry->GetFavicon().url, favicon_base::FAVICON); | 662 driver_->GetActiveFaviconURL(), |
| 663 favicon_base::FAVICON); |
| 675 } | 664 } |
| 676 } else if (current_candidate() && | 665 } else if (current_candidate() && |
| 677 (!has_results || has_expired_or_incomplete_result || | 666 (!has_results || has_expired_or_incomplete_result || |
| 678 !(DoUrlsAndIconsMatch(*current_candidate(), favicon_bitmap_results)))) { | 667 !(DoUrlsAndIconsMatch(*current_candidate(), favicon_bitmap_results)))) { |
| 679 // We don't know the favicon, it is out of date or its type is not same as | 668 // We don't know the favicon, it is out of date or its type is not same as |
| 680 // one got from page. Request the current one. | 669 // one got from page. Request the current one. |
| 681 ScheduleDownload(entry->GetURL(), current_candidate()->icon_url, | 670 ScheduleDownload(driver_->GetActiveURL(), |
| 671 current_candidate()->icon_url, |
| 682 ToChromeIconType(current_candidate()->icon_type)); | 672 ToChromeIconType(current_candidate()->icon_type)); |
| 683 } | 673 } |
| 684 history_results_ = favicon_bitmap_results; | 674 history_results_ = favicon_bitmap_results; |
| 685 } | 675 } |
| 686 | 676 |
| 687 int FaviconHandler::ScheduleDownload(const GURL& url, | 677 int FaviconHandler::ScheduleDownload(const GURL& url, |
| 688 const GURL& image_url, | 678 const GURL& image_url, |
| 689 favicon_base::IconType icon_type) { | 679 favicon_base::IconType icon_type) { |
| 690 // A max bitmap size is specified to avoid receiving huge bitmaps in | 680 // A max bitmap size is specified to avoid receiving huge bitmaps in |
| 691 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() | 681 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() |
| (...skipping 24 matching lines...) Expand all Loading... |
| 716 } else { | 706 } else { |
| 717 gfx::Size largest = i->icon_sizes[index]; | 707 gfx::Size largest = i->icon_sizes[index]; |
| 718 i->icon_sizes.clear(); | 708 i->icon_sizes.clear(); |
| 719 i->icon_sizes.push_back(largest); | 709 i->icon_sizes.push_back(largest); |
| 720 ++i; | 710 ++i; |
| 721 } | 711 } |
| 722 } | 712 } |
| 723 std::stable_sort(image_urls_.begin(), image_urls_.end(), | 713 std::stable_sort(image_urls_.begin(), image_urls_.end(), |
| 724 CompareIconSize); | 714 CompareIconSize); |
| 725 } | 715 } |
| OLD | NEW |