Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1073)

Side by Side Diff: components/favicon/core/favicon_handler.cc

Issue 2948963002: Prefer 192x192 icons from Web Manifests instead of 144x144 (Closed)
Patch Set: Addressed comments. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 13 matching lines...) Expand all
24 #include "ui/gfx/image/image_skia.h" 24 #include "ui/gfx/image/image_skia.h"
25 #include "ui/gfx/image/image_util.h" 25 #include "ui/gfx/image/image_util.h"
26 26
27 namespace favicon { 27 namespace favicon {
28 namespace { 28 namespace {
29 29
30 const int kNonTouchLargestIconSize = 192; 30 const int kNonTouchLargestIconSize = 192;
31 31
32 // Size (along each axis) of a touch icon. This currently corresponds to 32 // Size (along each axis) of a touch icon. This currently corresponds to
33 // the apple touch icon for iPad. 33 // the apple touch icon for iPad.
34 // TODO(crbug.com/736290): Consider changing this to 192x192 for Android.
34 const int kTouchIconSize = 144; 35 const int kTouchIconSize = 144;
35 36
36 // Return true if |bitmap_result| is expired. 37 // Return true if |bitmap_result| is expired.
37 bool IsExpired(const favicon_base::FaviconRawBitmapResult& bitmap_result) { 38 bool IsExpired(const favicon_base::FaviconRawBitmapResult& bitmap_result) {
38 return bitmap_result.expired; 39 return bitmap_result.expired;
39 } 40 }
40 41
41 // Return true if |bitmap_result| is valid. 42 // Return true if |bitmap_result| is valid.
42 bool IsValid(const favicon_base::FaviconRawBitmapResult& bitmap_result) { 43 bool IsValid(const favicon_base::FaviconRawBitmapResult& bitmap_result) {
43 return bitmap_result.is_valid(); 44 return bitmap_result.is_valid();
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 // Check if the manifest was previously blacklisted (e.g. returned a 404) and 341 // Check if the manifest was previously blacklisted (e.g. returned a 404) and
341 // ignore the manifest URL if that's the case. 342 // ignore the manifest URL if that's the case.
342 if (!manifest_url_.is_empty() && 343 if (!manifest_url_.is_empty() &&
343 service_->WasUnableToDownloadFavicon(manifest_url_)) { 344 service_->WasUnableToDownloadFavicon(manifest_url_)) {
344 DVLOG(1) << "Skip failed Manifest: " << manifest_url; 345 DVLOG(1) << "Skip failed Manifest: " << manifest_url;
345 manifest_url_ = GURL(); 346 manifest_url_ = GURL();
346 } 347 }
347 348
348 // If no manifest available, proceed with the regular candidates only. 349 // If no manifest available, proceed with the regular candidates only.
349 if (manifest_url_.is_empty()) { 350 if (manifest_url_.is_empty()) {
350 OnGotFinalIconURLCandidates(candidates); 351 OnGotFinalIconURLCandidates(candidates,
352 GetDesiredPixelSizes(handler_type_));
351 return; 353 return;
352 } 354 }
353 355
354 // See if there is a cached favicon for the manifest. This will update the DB 356 // See if there is a cached favicon for the manifest. This will update the DB
355 // mappings only if the manifest URL is cached. 357 // mappings only if the manifest URL is cached.
356 GetFaviconAndUpdateMappingsUnlessIncognito( 358 GetFaviconAndUpdateMappingsUnlessIncognito(
357 /*icon_url=*/manifest_url_, favicon_base::WEB_MANIFEST_ICON, 359 /*icon_url=*/manifest_url_, favicon_base::WEB_MANIFEST_ICON,
358 base::Bind(&FaviconHandler::OnFaviconDataForManifestFromFaviconService, 360 base::Bind(&FaviconHandler::OnFaviconDataForManifestFromFaviconService,
359 base::Unretained(this))); 361 base::Unretained(this)));
360 } 362 }
(...skipping 28 matching lines...) Expand all
389 manifest_download_request_.callback()); 391 manifest_download_request_.callback());
390 } 392 }
391 } 393 }
392 394
393 void FaviconHandler::OnDidDownloadManifest( 395 void FaviconHandler::OnDidDownloadManifest(
394 const std::vector<FaviconURL>& candidates) { 396 const std::vector<FaviconURL>& candidates) {
395 // Mark manifest download as finished. 397 // Mark manifest download as finished.
396 manifest_download_request_.Cancel(); 398 manifest_download_request_.Cancel();
397 399
398 if (!candidates.empty()) { 400 if (!candidates.empty()) {
399 OnGotFinalIconURLCandidates(candidates); 401 // When reading icons from web manifests, prefer kNonTouchLargestIconSize.
402 OnGotFinalIconURLCandidates(candidates,
403 std::vector<int>(1U, kNonTouchLargestIconSize));
400 return; 404 return;
401 } 405 }
402 406
403 // If either the downloading of the manifest failed, OR the manifest contains 407 // 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. 408 // no icons, proceed with the list of icons listed in the HTML.
405 DVLOG(1) << "Could not fetch Manifest icons from " << manifest_url_ 409 DVLOG(1) << "Could not fetch Manifest icons from " << manifest_url_
406 << ", falling back to inlined ones, which are " 410 << ", falling back to inlined ones, which are "
407 << non_manifest_original_candidates_.size(); 411 << non_manifest_original_candidates_.size();
408 412
409 service_->UnableToDownloadFavicon(manifest_url_); 413 service_->UnableToDownloadFavicon(manifest_url_);
410 manifest_url_ = GURL(); 414 manifest_url_ = GURL();
411 415
412 OnGotFinalIconURLCandidates(non_manifest_original_candidates_); 416 OnGotFinalIconURLCandidates(non_manifest_original_candidates_,
417 GetDesiredPixelSizes(handler_type_));
413 } 418 }
414 419
415 void FaviconHandler::OnGotFinalIconURLCandidates( 420 void FaviconHandler::OnGotFinalIconURLCandidates(
416 const std::vector<FaviconURL>& candidates) { 421 const std::vector<FaviconURL>& candidates,
422 const std::vector<int>& desired_pixel_sizes) {
417 std::vector<FaviconCandidate> sorted_candidates; 423 std::vector<FaviconCandidate> sorted_candidates;
418 const std::vector<int> desired_pixel_sizes =
419 GetDesiredPixelSizes(handler_type_);
420 for (const FaviconURL& candidate : candidates) { 424 for (const FaviconURL& candidate : candidates) {
421 if (!candidate.icon_url.is_empty() && (candidate.icon_type & icon_types_)) { 425 if (!candidate.icon_url.is_empty() && (candidate.icon_type & icon_types_)) {
422 sorted_candidates.push_back( 426 sorted_candidates.push_back(
423 FaviconCandidate::FromFaviconURL(candidate, desired_pixel_sizes)); 427 FaviconCandidate::FromFaviconURL(candidate, desired_pixel_sizes));
424 } 428 }
425 } 429 }
426 430
427 std::stable_sort(sorted_candidates.begin(), sorted_candidates.end(), 431 std::stable_sort(sorted_candidates.begin(), sorted_candidates.end(),
428 &FaviconCandidate::CompareScore); 432 &FaviconCandidate::CompareScore);
429 433
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 // A max bitmap size is specified to avoid receiving huge bitmaps in 668 // A max bitmap size is specified to avoid receiving huge bitmaps in
665 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() 669 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload()
666 // for more details about the max bitmap size. 670 // for more details about the max bitmap size.
667 const int download_id = 671 const int download_id =
668 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_), 672 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_),
669 image_download_request_.callback()); 673 image_download_request_.callback());
670 DCHECK_NE(download_id, 0); 674 DCHECK_NE(download_id, 0);
671 } 675 }
672 676
673 } // namespace favicon 677 } // namespace favicon
OLDNEW
« no previous file with comments | « components/favicon/core/favicon_handler.h ('k') | components/favicon/core/favicon_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698