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 "components/favicon/core/favicon_handler.h" | 5 #include "components/favicon/core/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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 | 218 |
| 219 FaviconHandler::~FaviconHandler() { | 219 FaviconHandler::~FaviconHandler() { |
| 220 } | 220 } |
| 221 | 221 |
| 222 // static | 222 // static |
| 223 int FaviconHandler::GetIconTypesFromHandlerType( | 223 int FaviconHandler::GetIconTypesFromHandlerType( |
| 224 FaviconHandler::Type handler_type) { | 224 FaviconHandler::Type handler_type) { |
| 225 switch (handler_type) { | 225 switch (handler_type) { |
| 226 case FAVICON: | 226 case FAVICON: |
| 227 return favicon_base::FAVICON; | 227 return favicon_base::FAVICON; |
| 228 case TOUCH: // Falls through. | 228 case TOUCH: |
| 229 return favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON; | |
| 229 case LARGE: | 230 case LARGE: |
| 230 return favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON; | 231 return favicon_base::FAVICON | favicon_base::TOUCH_ICON | |
| 232 favicon_base::TOUCH_PRECOMPOSED_ICON; | |
| 231 default: | 233 default: |
| 232 NOTREACHED(); | 234 NOTREACHED(); |
| 233 } | 235 } |
| 234 return 0; | 236 return 0; |
| 235 } | 237 } |
| 236 | 238 |
| 237 void FaviconHandler::FetchFavicon(const GURL& url) { | 239 void FaviconHandler::FetchFavicon(const GURL& url) { |
| 238 cancelable_task_tracker_.TryCancelAll(); | 240 cancelable_task_tracker_.TryCancelAll(); |
| 239 | 241 |
| 240 url_ = url; | 242 url_ = url; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 351 | 353 |
| 352 // TODO(davemoore) Should clear on empty url. Currently we ignore it. | 354 // TODO(davemoore) Should clear on empty url. Currently we ignore it. |
| 353 // This appears to be what FF does as well. | 355 // This appears to be what FF does as well. |
| 354 if (!image_urls_.empty()) | 356 if (!image_urls_.empty()) |
| 355 ProcessCurrentUrl(); | 357 ProcessCurrentUrl(); |
| 356 } | 358 } |
| 357 | 359 |
| 358 void FaviconHandler::ProcessCurrentUrl() { | 360 void FaviconHandler::ProcessCurrentUrl() { |
| 359 DCHECK(!image_urls_.empty()); | 361 DCHECK(!image_urls_.empty()); |
| 360 | 362 |
| 363 // TODO(rogerm): To use fetch on demand for large icons: just add the Favicon | |
| 364 // record and update the url mappings here, instead of downloading. | |
| 365 // i.e., if (handler_type_ == LARGE) { Save(image_urls[0]); return; } | |
| 366 | |
| 361 // current_candidate() may return NULL if download_largest_icon_ is true and | 367 // current_candidate() may return NULL if download_largest_icon_ is true and |
| 362 // all the sizes are larger than the max. | 368 // all the sizes are larger than the max. |
| 363 if (PageChangedSinceFaviconWasRequested() || !current_candidate()) | 369 if (PageChangedSinceFaviconWasRequested() || !current_candidate()) |
| 364 return; | 370 return; |
| 365 | 371 |
| 366 if (current_candidate()->icon_type == favicon_base::FAVICON && | 372 if (current_candidate()->icon_type == favicon_base::FAVICON && |
| 367 !download_largest_icon_) { | 373 !download_largest_icon_) { |
| 368 if (!favicon_expired_or_incomplete_ && | 374 if (!favicon_expired_or_incomplete_ && |
| 369 driver_->GetActiveFaviconValidity() && | 375 driver_->GetActiveFaviconValidity() && |
| 370 DoUrlAndIconMatch(*current_candidate(), | 376 DoUrlAndIconMatch(*current_candidate(), |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 } | 446 } |
| 441 } | 447 } |
| 442 | 448 |
| 443 if (request_next_icon && image_urls_.size() > 1) { | 449 if (request_next_icon && image_urls_.size() > 1) { |
| 444 // Remove the first member of image_urls_ and process the remaining. | 450 // Remove the first member of image_urls_ and process the remaining. |
| 445 image_urls_.erase(image_urls_.begin()); | 451 image_urls_.erase(image_urls_.begin()); |
| 446 ProcessCurrentUrl(); | 452 ProcessCurrentUrl(); |
| 447 } else { | 453 } else { |
| 448 // We have either found the ideal candidate or run out of candidates. | 454 // We have either found the ideal candidate or run out of candidates. |
| 449 if (best_favicon_candidate_.icon_type != favicon_base::INVALID_ICON) { | 455 if (best_favicon_candidate_.icon_type != favicon_base::INVALID_ICON) { |
| 450 // No more icons to request, set the favicon from the candidate. | 456 // No more icons to request, set the favicon from the candidate. |
|
beaudoin
2015/05/05 00:54:00
Augment the comment to indicate what save_type mea
Roger McFarlane (Chromium)
2015/05/05 15:09:47
Done.
| |
| 457 favicon_base::IconType saved_type = handler_type_ == LARGE ? | |
| 458 favicon_base::LARGE_ICON : best_favicon_candidate_.icon_type; | |
| 451 SetFavicon(best_favicon_candidate_.url, best_favicon_candidate_.image_url, | 459 SetFavicon(best_favicon_candidate_.url, best_favicon_candidate_.image_url, |
| 452 best_favicon_candidate_.image, | 460 best_favicon_candidate_.image, saved_type); |
| 453 best_favicon_candidate_.icon_type); | |
| 454 } | 461 } |
| 455 // Clear download related state. | 462 // Clear download related state. |
| 456 image_urls_.clear(); | 463 image_urls_.clear(); |
| 457 download_requests_.clear(); | 464 download_requests_.clear(); |
| 458 best_favicon_candidate_ = FaviconCandidate(); | 465 best_favicon_candidate_ = FaviconCandidate(); |
| 459 } | 466 } |
| 460 } | 467 } |
| 461 | 468 |
| 462 bool FaviconHandler::HasPendingTasksForTest() { | 469 bool FaviconHandler::HasPendingTasksForTest() { |
| 463 return !download_requests_.empty() || | 470 return !download_requests_.empty() || |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 | 540 |
| 534 bool FaviconHandler::ShouldSaveFavicon(const GURL& url) { | 541 bool FaviconHandler::ShouldSaveFavicon(const GURL& url) { |
| 535 if (!driver_->IsOffTheRecord()) | 542 if (!driver_->IsOffTheRecord()) |
| 536 return true; | 543 return true; |
| 537 | 544 |
| 538 // Always save favicon if the page is bookmarked. | 545 // Always save favicon if the page is bookmarked. |
| 539 return driver_->IsBookmarked(url); | 546 return driver_->IsBookmarked(url); |
| 540 } | 547 } |
| 541 | 548 |
| 542 int FaviconHandler::GetMaximalIconSize(favicon_base::IconType icon_type) { | 549 int FaviconHandler::GetMaximalIconSize(favicon_base::IconType icon_type) { |
| 550 if (handler_type_ == FaviconHandler::LARGE) { | |
| 551 return icon_type == favicon_base::INVALID_ICON ? 0 : 192; | |
|
beaudoin
2015/05/05 00:54:00
Comment to explain this logic?
Roger McFarlane (Chromium)
2015/05/05 15:09:47
Done.
| |
| 552 } | |
| 553 | |
| 543 switch (icon_type) { | 554 switch (icon_type) { |
| 544 case favicon_base::FAVICON: | 555 case favicon_base::FAVICON: |
| 545 #if defined(OS_ANDROID) | 556 #if defined(OS_ANDROID) |
| 546 return 192; | 557 return 192; |
| 547 #else | 558 #else |
| 548 return gfx::ImageSkia::GetMaxSupportedScale() * gfx::kFaviconSize; | 559 return gfx::ImageSkia::GetMaxSupportedScale() * gfx::kFaviconSize; |
| 549 #endif | 560 #endif |
| 550 case favicon_base::TOUCH_ICON: | 561 case favicon_base::TOUCH_ICON: |
| 551 case favicon_base::TOUCH_PRECOMPOSED_ICON: | 562 case favicon_base::TOUCH_PRECOMPOSED_ICON: |
| 552 return kTouchIconSize; | 563 return kTouchIconSize; |
| 564 case favicon_base::LARGE_ICON: | |
| 565 NOTREACHED(); // This is a virtual icon type. | |
| 566 return 192; | |
|
beaudoin
2015/05/05 00:54:00
Strange to return such a specific value behind a N
Roger McFarlane (Chromium)
2015/05/05 15:09:47
We don't expect that GetMaximalIconSize will be ca
beaudoin
2015/05/05 19:47:52
Acknowledged, although a quick comment to explain
Roger McFarlane (Chromium)
2015/05/06 16:06:16
Done.
| |
| 553 case favicon_base::INVALID_ICON: | 567 case favicon_base::INVALID_ICON: |
| 554 return 0; | 568 return 0; |
| 555 } | 569 } |
| 556 NOTREACHED(); | 570 NOTREACHED(); |
| 557 return 0; | 571 return 0; |
| 558 } | 572 } |
| 559 | 573 |
| 560 void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService( | 574 void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService( |
| 561 const std::vector<favicon_base::FaviconRawBitmapResult>& | 575 const std::vector<favicon_base::FaviconRawBitmapResult>& |
| 562 favicon_bitmap_results) { | 576 favicon_bitmap_results) { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 706 gfx::Size largest = | 720 gfx::Size largest = |
| 707 image_url.icon_sizes[GetLargestSizeIndex(image_url.icon_sizes)]; | 721 image_url.icon_sizes[GetLargestSizeIndex(image_url.icon_sizes)]; |
| 708 image_url.icon_sizes.clear(); | 722 image_url.icon_sizes.clear(); |
| 709 image_url.icon_sizes.push_back(largest); | 723 image_url.icon_sizes.push_back(largest); |
| 710 } | 724 } |
| 711 std::stable_sort(image_urls_.begin(), image_urls_.end(), | 725 std::stable_sort(image_urls_.begin(), image_urls_.end(), |
| 712 CompareIconSize); | 726 CompareIconSize); |
| 713 } | 727 } |
| 714 | 728 |
| 715 } // namespace favicon | 729 } // namespace favicon |
| OLD | NEW |