| 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 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 // Check if the manifest was previously blacklisted (e.g. returned a 404) and | 340 // Check if the manifest was previously blacklisted (e.g. returned a 404) and |
| 341 // ignore the manifest URL if that's the case. | 341 // ignore the manifest URL if that's the case. |
| 342 if (!manifest_url_.is_empty() && | 342 if (!manifest_url_.is_empty() && |
| 343 service_->WasUnableToDownloadFavicon(manifest_url_)) { | 343 service_->WasUnableToDownloadFavicon(manifest_url_)) { |
| 344 DVLOG(1) << "Skip failed Manifest: " << manifest_url; | 344 DVLOG(1) << "Skip failed Manifest: " << manifest_url; |
| 345 manifest_url_ = GURL(); | 345 manifest_url_ = GURL(); |
| 346 } | 346 } |
| 347 | 347 |
| 348 // If no manifest available, proceed with the regular candidates only. | 348 // If no manifest available, proceed with the regular candidates only. |
| 349 if (manifest_url_.is_empty()) { | 349 if (manifest_url_.is_empty()) { |
| 350 OnGotFinalIconURLCandidates(candidates); | 350 OnGotFinalIconURLCandidates(candidates, |
| 351 GetDesiredPixelSizes(handler_type_)); |
| 351 return; | 352 return; |
| 352 } | 353 } |
| 353 | 354 |
| 354 // See if there is a cached favicon for the manifest. This will update the DB | 355 // See if there is a cached favicon for the manifest. This will update the DB |
| 355 // mappings only if the manifest URL is cached. | 356 // mappings only if the manifest URL is cached. |
| 356 GetFaviconAndUpdateMappingsUnlessIncognito( | 357 GetFaviconAndUpdateMappingsUnlessIncognito( |
| 357 /*icon_url=*/manifest_url_, favicon_base::WEB_MANIFEST_ICON, | 358 /*icon_url=*/manifest_url_, favicon_base::WEB_MANIFEST_ICON, |
| 358 base::Bind(&FaviconHandler::OnFaviconDataForManifestFromFaviconService, | 359 base::Bind(&FaviconHandler::OnFaviconDataForManifestFromFaviconService, |
| 359 base::Unretained(this))); | 360 base::Unretained(this))); |
| 360 } | 361 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 389 manifest_download_request_.callback()); | 390 manifest_download_request_.callback()); |
| 390 } | 391 } |
| 391 } | 392 } |
| 392 | 393 |
| 393 void FaviconHandler::OnDidDownloadManifest( | 394 void FaviconHandler::OnDidDownloadManifest( |
| 394 const std::vector<FaviconURL>& candidates) { | 395 const std::vector<FaviconURL>& candidates) { |
| 395 // Mark manifest download as finished. | 396 // Mark manifest download as finished. |
| 396 manifest_download_request_.Cancel(); | 397 manifest_download_request_.Cancel(); |
| 397 | 398 |
| 398 if (!candidates.empty()) { | 399 if (!candidates.empty()) { |
| 399 OnGotFinalIconURLCandidates(candidates); | 400 // When reading icons from web manifests, prefer kNonTouchLargestIconSize. |
| 401 OnGotFinalIconURLCandidates(candidates, |
| 402 std::vector<int>(1U, kNonTouchLargestIconSize)); |
| 400 return; | 403 return; |
| 401 } | 404 } |
| 402 | 405 |
| 403 // 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 |
| 404 // 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. |
| 405 DVLOG(1) << "Could not fetch Manifest icons from " << manifest_url_ | 408 DVLOG(1) << "Could not fetch Manifest icons from " << manifest_url_ |
| 406 << ", falling back to inlined ones, which are " | 409 << ", falling back to inlined ones, which are " |
| 407 << non_manifest_original_candidates_.size(); | 410 << non_manifest_original_candidates_.size(); |
| 408 | 411 |
| 409 service_->UnableToDownloadFavicon(manifest_url_); | 412 service_->UnableToDownloadFavicon(manifest_url_); |
| 410 manifest_url_ = GURL(); | 413 manifest_url_ = GURL(); |
| 411 | 414 |
| 412 OnGotFinalIconURLCandidates(non_manifest_original_candidates_); | 415 OnGotFinalIconURLCandidates(non_manifest_original_candidates_, |
| 416 GetDesiredPixelSizes(handler_type_)); |
| 413 } | 417 } |
| 414 | 418 |
| 415 void FaviconHandler::OnGotFinalIconURLCandidates( | 419 void FaviconHandler::OnGotFinalIconURLCandidates( |
| 416 const std::vector<FaviconURL>& candidates) { | 420 const std::vector<FaviconURL>& candidates, |
| 421 const std::vector<int>& desired_pixel_sizes) { |
| 417 std::vector<FaviconCandidate> sorted_candidates; | 422 std::vector<FaviconCandidate> sorted_candidates; |
| 418 const std::vector<int> desired_pixel_sizes = | |
| 419 GetDesiredPixelSizes(handler_type_); | |
| 420 for (const FaviconURL& candidate : candidates) { | 423 for (const FaviconURL& candidate : candidates) { |
| 421 if (!candidate.icon_url.is_empty() && (candidate.icon_type & icon_types_)) { | 424 if (!candidate.icon_url.is_empty() && (candidate.icon_type & icon_types_)) { |
| 422 sorted_candidates.push_back( | 425 sorted_candidates.push_back( |
| 423 FaviconCandidate::FromFaviconURL(candidate, desired_pixel_sizes)); | 426 FaviconCandidate::FromFaviconURL(candidate, desired_pixel_sizes)); |
| 424 } | 427 } |
| 425 } | 428 } |
| 426 | 429 |
| 427 std::stable_sort(sorted_candidates.begin(), sorted_candidates.end(), | 430 std::stable_sort(sorted_candidates.begin(), sorted_candidates.end(), |
| 428 &FaviconCandidate::CompareScore); | 431 &FaviconCandidate::CompareScore); |
| 429 | 432 |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 // 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 |
| 665 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() | 668 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() |
| 666 // for more details about the max bitmap size. | 669 // for more details about the max bitmap size. |
| 667 const int download_id = | 670 const int download_id = |
| 668 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_), | 671 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_), |
| 669 image_download_request_.callback()); | 672 image_download_request_.callback()); |
| 670 DCHECK_NE(download_id, 0); | 673 DCHECK_NE(download_id, 0); |
| 671 } | 674 } |
| 672 | 675 |
| 673 } // namespace favicon | 676 } // namespace favicon |
| OLD | NEW |