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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 best_favicon_candidate_ = FaviconCandidate(); | 344 best_favicon_candidate_ = FaviconCandidate(); |
343 | 345 |
344 for (const FaviconURL& candidate : candidates) { | 346 for (const FaviconURL& candidate : candidates) { |
345 if (!candidate.icon_url.is_empty() && (candidate.icon_type & icon_types_)) | 347 if (!candidate.icon_url.is_empty() && (candidate.icon_type & icon_types_)) |
346 image_urls_.push_back(candidate); | 348 image_urls_.push_back(candidate); |
347 } | 349 } |
348 | 350 |
349 if (download_largest_icon_) | 351 if (download_largest_icon_) |
350 SortAndPruneImageUrls(); | 352 SortAndPruneImageUrls(); |
351 | 353 |
354 // TODO(rogerm): To use fetch on demand for large icons: just add the Favicon | |
huangs
2015/05/04 05:17:30
NIT: Perhaps the comment should be in ProcessCurre
Roger McFarlane (Chromium)
2015/05/04 18:48:15
Done.
| |
355 // record and update the url mappings here, instead of processing the url. | |
356 // i.e., if (handler_type_ == LARGE) { Save(image_urls[0]); return; } | |
357 | |
352 // TODO(davemoore) Should clear on empty url. Currently we ignore it. | 358 // TODO(davemoore) Should clear on empty url. Currently we ignore it. |
353 // This appears to be what FF does as well. | 359 // This appears to be what FF does as well. |
354 if (!image_urls_.empty()) | 360 if (!image_urls_.empty()) |
355 ProcessCurrentUrl(); | 361 ProcessCurrentUrl(); |
356 } | 362 } |
357 | 363 |
358 void FaviconHandler::ProcessCurrentUrl() { | 364 void FaviconHandler::ProcessCurrentUrl() { |
359 DCHECK(!image_urls_.empty()); | 365 DCHECK(!image_urls_.empty()); |
360 | 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 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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. |
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 icon_type != favicon_base::INVALID_ICON) { | |
552 return 192; | |
huangs
2015/05/04 05:17:30
I'd prefer
return icon_type == favicon_base::I
Roger McFarlane (Chromium)
2015/05/04 18:48:15
Done.
| |
553 } | |
554 | |
543 switch (icon_type) { | 555 switch (icon_type) { |
544 case favicon_base::FAVICON: | 556 case favicon_base::FAVICON: |
545 #if defined(OS_ANDROID) | 557 #if defined(OS_ANDROID) |
546 return 192; | 558 return 192; |
547 #else | 559 #else |
548 return gfx::ImageSkia::GetMaxSupportedScale() * gfx::kFaviconSize; | 560 return gfx::ImageSkia::GetMaxSupportedScale() * gfx::kFaviconSize; |
549 #endif | 561 #endif |
550 case favicon_base::TOUCH_ICON: | 562 case favicon_base::TOUCH_ICON: |
551 case favicon_base::TOUCH_PRECOMPOSED_ICON: | 563 case favicon_base::TOUCH_PRECOMPOSED_ICON: |
552 return kTouchIconSize; | 564 return kTouchIconSize; |
565 case favicon_base::LARGE_ICON: | |
566 NOTREACHED(); // This is a virtual icon type. | |
567 return 192; | |
553 case favicon_base::INVALID_ICON: | 568 case favicon_base::INVALID_ICON: |
554 return 0; | 569 return 0; |
555 } | 570 } |
556 NOTREACHED(); | 571 NOTREACHED(); |
557 return 0; | 572 return 0; |
558 } | 573 } |
559 | 574 |
560 void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService( | 575 void FaviconHandler::OnFaviconDataForInitialURLFromFaviconService( |
561 const std::vector<favicon_base::FaviconRawBitmapResult>& | 576 const std::vector<favicon_base::FaviconRawBitmapResult>& |
562 favicon_bitmap_results) { | 577 favicon_bitmap_results) { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
706 gfx::Size largest = | 721 gfx::Size largest = |
707 image_url.icon_sizes[GetLargestSizeIndex(image_url.icon_sizes)]; | 722 image_url.icon_sizes[GetLargestSizeIndex(image_url.icon_sizes)]; |
708 image_url.icon_sizes.clear(); | 723 image_url.icon_sizes.clear(); |
709 image_url.icon_sizes.push_back(largest); | 724 image_url.icon_sizes.push_back(largest); |
710 } | 725 } |
711 std::stable_sort(image_urls_.begin(), image_urls_.end(), | 726 std::stable_sort(image_urls_.begin(), image_urls_.end(), |
712 CompareIconSize); | 727 CompareIconSize); |
713 } | 728 } |
714 | 729 |
715 } // namespace favicon | 730 } // namespace favicon |
OLD | NEW |