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 <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 } | 198 } |
| 199 | 199 |
| 200 // static | 200 // static |
| 201 int FaviconHandler::GetIconTypesFromHandlerType( | 201 int FaviconHandler::GetIconTypesFromHandlerType( |
| 202 FaviconDriverObserver::NotificationIconType handler_type) { | 202 FaviconDriverObserver::NotificationIconType handler_type) { |
| 203 switch (handler_type) { | 203 switch (handler_type) { |
| 204 case FaviconDriverObserver::NON_TOUCH_16_DIP: | 204 case FaviconDriverObserver::NON_TOUCH_16_DIP: |
| 205 case FaviconDriverObserver::NON_TOUCH_LARGEST: | 205 case FaviconDriverObserver::NON_TOUCH_LARGEST: |
| 206 return favicon_base::FAVICON; | 206 return favicon_base::FAVICON; |
| 207 case FaviconDriverObserver::TOUCH_LARGEST: | 207 case FaviconDriverObserver::TOUCH_LARGEST: |
| 208 return favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON; | 208 return favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON | |
| 209 favicon_base::WEB_MANIFEST_ICON; | |
| 209 } | 210 } |
| 210 return 0; | 211 return 0; |
| 211 } | 212 } |
| 212 | 213 |
| 213 void FaviconHandler::FetchFavicon(const GURL& url) { | 214 void FaviconHandler::FetchFavicon(const GURL& url) { |
| 214 cancelable_task_tracker_for_page_url_.TryCancelAll(); | 215 cancelable_task_tracker_for_page_url_.TryCancelAll(); |
| 215 cancelable_task_tracker_for_candidates_.TryCancelAll(); | 216 cancelable_task_tracker_for_candidates_.TryCancelAll(); |
| 216 | 217 |
| 217 url_ = url; | 218 url_ = url; |
| 218 | 219 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 | 350 |
| 350 // If no manifest available, proceed with the regular candidates only. | 351 // If no manifest available, proceed with the regular candidates only. |
| 351 if (manifest_url_.is_empty()) { | 352 if (manifest_url_.is_empty()) { |
| 352 OnGotFinalIconURLCandidates(candidates); | 353 OnGotFinalIconURLCandidates(candidates); |
| 353 return; | 354 return; |
| 354 } | 355 } |
| 355 | 356 |
| 356 // See if there is a cached favicon for the manifest. This will update the DB | 357 // See if there is a cached favicon for the manifest. This will update the DB |
| 357 // mappings only if the manifest URL is cached. | 358 // mappings only if the manifest URL is cached. |
| 358 GetFaviconAndUpdateMappingsUnlessIncognito( | 359 GetFaviconAndUpdateMappingsUnlessIncognito( |
| 359 /*icon_url=*/manifest_url_, favicon_base::FAVICON, | 360 /*icon_url=*/manifest_url_, favicon_base::WEB_MANIFEST_ICON, |
| 360 base::Bind(&FaviconHandler::OnFaviconDataForManifestFromFaviconService, | 361 base::Bind(&FaviconHandler::OnFaviconDataForManifestFromFaviconService, |
| 361 base::Unretained(this))); | 362 base::Unretained(this))); |
| 362 } | 363 } |
| 363 | 364 |
| 364 void FaviconHandler::OnFaviconDataForManifestFromFaviconService( | 365 void FaviconHandler::OnFaviconDataForManifestFromFaviconService( |
| 365 const std::vector<favicon_base::FaviconRawBitmapResult>& | 366 const std::vector<favicon_base::FaviconRawBitmapResult>& |
| 366 favicon_bitmap_results) { | 367 favicon_bitmap_results) { |
| 367 // The database lookup for the page URL is guaranteed to be completed because | 368 // The database lookup for the page URL is guaranteed to be completed because |
| 368 // the HistoryBackend uses a SequencedTaskRunner, and we also know that | 369 // the HistoryBackend uses a SequencedTaskRunner, and we also know that |
| 369 // FetchFavicon() was called before OnUpdateCandidates(). | 370 // FetchFavicon() was called before OnUpdateCandidates(). |
| 370 DCHECK(got_favicon_from_history_); | 371 DCHECK(got_favicon_from_history_); |
| 371 | 372 |
| 372 bool has_valid_result = HasValidResult(favicon_bitmap_results); | 373 bool has_valid_result = HasValidResult(favicon_bitmap_results); |
| 373 bool has_expired_or_incomplete_result = | 374 bool has_expired_or_incomplete_result = |
| 374 !has_valid_result || HasExpiredOrIncompleteResult(preferred_icon_size(), | 375 !has_valid_result || HasExpiredOrIncompleteResult(preferred_icon_size(), |
| 375 favicon_bitmap_results); | 376 favicon_bitmap_results); |
| 376 | 377 |
| 377 if (has_valid_result && (notification_icon_url_ != manifest_url_ || | 378 if (has_valid_result && |
| 378 notification_icon_type_ != favicon_base::FAVICON)) { | 379 (notification_icon_url_ != manifest_url_ || |
| 380 notification_icon_type_ != favicon_base::WEB_MANIFEST_ICON)) { | |
| 379 // There is a valid favicon. Notify any observers. It is useful to notify | 381 // There is a valid favicon. Notify any observers. It is useful to notify |
| 380 // the observers even if the favicon is expired or incomplete (incorrect | 382 // the observers even if the favicon is expired or incomplete (incorrect |
| 381 // size) because temporarily showing the user an expired favicon or | 383 // size) because temporarily showing the user an expired favicon or |
| 382 // streched favicon is preferable to showing the user the default favicon. | 384 // streched favicon is preferable to showing the user the default favicon. |
| 383 NotifyFaviconUpdated(favicon_bitmap_results); | 385 NotifyFaviconUpdated(favicon_bitmap_results); |
| 384 } | 386 } |
| 385 | 387 |
| 386 if (has_expired_or_incomplete_result) { | 388 if (has_expired_or_incomplete_result) { |
| 387 manifest_download_request_.Reset(base::Bind( | 389 manifest_download_request_.Reset(base::Bind( |
| 388 &FaviconHandler::OnDidDownloadManifest, base::Unretained(this))); | 390 &FaviconHandler::OnDidDownloadManifest, base::Unretained(this))); |
| 389 delegate_->DownloadManifest(manifest_url_, | 391 delegate_->DownloadManifest(manifest_url_, |
| 390 manifest_download_request_.callback()); | 392 manifest_download_request_.callback()); |
| 391 } | 393 } |
| 392 } | 394 } |
| 393 | 395 |
| 394 void FaviconHandler::OnDidDownloadManifest( | 396 void FaviconHandler::OnDidDownloadManifest( |
| 395 const std::vector<FaviconURL>& candidates) { | 397 const std::vector<FaviconURL>& candidates) { |
|
pkotwicz
2017/05/24 14:27:44
Shouldn't |candidates| be of type favicon_base::WE
mastiz
2017/05/25 11:14:16
Done, changed. It's certainly cleaner this way, al
| |
| 396 // Mark manifest download as finished. | 398 // Mark manifest download as finished. |
| 397 manifest_download_request_.Cancel(); | 399 manifest_download_request_.Cancel(); |
| 398 | 400 |
| 399 if (!candidates.empty()) { | 401 if (!candidates.empty()) { |
| 400 OnGotFinalIconURLCandidates(candidates); | 402 OnGotFinalIconURLCandidates(candidates); |
| 401 return; | 403 return; |
| 402 } | 404 } |
| 403 | 405 |
| 404 // If either the downloading of the manifest failed, OR the manifest contains | 406 // If either the downloading of the manifest failed, OR the manifest contains |
| 405 // no icons, proceed with the list of icons listed in the HTML. | 407 // no icons, proceed with the list of icons listed in the HTML. |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 519 // OnDidDownloadFavicon() can only be called after requesting a download, so | 521 // OnDidDownloadFavicon() can only be called after requesting a download, so |
| 520 // |num_image_download_requests_| can never be 0. | 522 // |num_image_download_requests_| can never be 0. |
| 521 RecordDownloadAttemptsForHandlerType(handler_type_, | 523 RecordDownloadAttemptsForHandlerType(handler_type_, |
| 522 num_image_download_requests_); | 524 num_image_download_requests_); |
| 523 // We have either found the ideal candidate or run out of candidates. | 525 // We have either found the ideal candidate or run out of candidates. |
| 524 if (best_favicon_.candidate.icon_type != favicon_base::INVALID_ICON) { | 526 if (best_favicon_.candidate.icon_type != favicon_base::INVALID_ICON) { |
| 525 // No more icons to request, set the favicon from the candidate. The | 527 // No more icons to request, set the favicon from the candidate. The |
| 526 // manifest URL, if available, is used instead of the icon URL. | 528 // manifest URL, if available, is used instead of the icon URL. |
| 527 SetFavicon(manifest_url_.is_empty() ? best_favicon_.candidate.icon_url | 529 SetFavicon(manifest_url_.is_empty() ? best_favicon_.candidate.icon_url |
| 528 : manifest_url_, | 530 : manifest_url_, |
| 529 best_favicon_.image, best_favicon_.candidate.icon_type); | 531 best_favicon_.image, |
| 532 manifest_url_.is_empty() ? best_favicon_.candidate.icon_type | |
| 533 : favicon_base::WEB_MANIFEST_ICON); | |
|
pkotwicz
2017/05/24 14:27:44
You need to update HistoryBackend::SetFaviconMappi
mastiz
2017/05/25 11:14:16
Done.
| |
| 530 } | 534 } |
| 531 // Clear download related state. | 535 // Clear download related state. |
| 532 current_candidate_index_ = candidates_.size(); | 536 current_candidate_index_ = candidates_.size(); |
| 533 num_image_download_requests_ = 0; | 537 num_image_download_requests_ = 0; |
| 534 best_favicon_ = DownloadedFavicon(); | 538 best_favicon_ = DownloadedFavicon(); |
| 535 } | 539 } |
| 536 } | 540 } |
| 537 | 541 |
| 538 const std::vector<GURL> FaviconHandler::GetIconURLs() const { | 542 const std::vector<GURL> FaviconHandler::GetIconURLs() const { |
| 539 std::vector<GURL> icon_urls; | 543 std::vector<GURL> icon_urls; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 663 // A max bitmap size is specified to avoid receiving huge bitmaps in | 667 // A max bitmap size is specified to avoid receiving huge bitmaps in |
| 664 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() | 668 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() |
| 665 // for more details about the max bitmap size. | 669 // for more details about the max bitmap size. |
| 666 const int download_id = | 670 const int download_id = |
| 667 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_), | 671 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_), |
| 668 image_download_request_.callback()); | 672 image_download_request_.callback()); |
| 669 DCHECK_NE(download_id, 0); | 673 DCHECK_NE(download_id, 0); |
| 670 } | 674 } |
| 671 | 675 |
| 672 } // namespace favicon | 676 } // namespace favicon |
| OLD | NEW |