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

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

Issue 2972643002: Always prefer 192x192 on mobile, also for touch icons (Closed)
Patch Set: Created 3 years, 5 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>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/bind_helpers.h" 13 #include "base/bind_helpers.h"
14 #include "base/feature_list.h" 14 #include "base/feature_list.h"
15 #include "base/memory/ref_counted_memory.h" 15 #include "base/memory/ref_counted_memory.h"
16 #include "base/metrics/histogram_macros.h" 16 #include "base/metrics/histogram_macros.h"
17 #include "build/build_config.h" 17 #include "build/build_config.h"
18 #include "components/favicon/core/favicon_service.h" 18 #include "components/favicon/core/favicon_service.h"
19 #include "components/favicon/core/features.h" 19 #include "components/favicon/core/features.h"
20 #include "components/favicon_base/favicon_util.h" 20 #include "components/favicon_base/favicon_util.h"
21 #include "components/favicon_base/select_favicon_frames.h" 21 #include "components/favicon_base/select_favicon_frames.h"
22 #include "skia/ext/image_operations.h" 22 #include "skia/ext/image_operations.h"
23 #include "ui/gfx/codec/png_codec.h" 23 #include "ui/gfx/codec/png_codec.h"
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 kLargestIconSize = 192;
31
32 // Size (along each axis) of a touch icon. This currently corresponds to
33 // the apple touch icon for iPad.
34 // TODO(crbug.com/736290): Consider changing this to 192x192 for Android.
35 const int kTouchIconSize = 144;
36 31
37 // Return true if |bitmap_result| is expired. 32 // Return true if |bitmap_result| is expired.
38 bool IsExpired(const favicon_base::FaviconRawBitmapResult& bitmap_result) { 33 bool IsExpired(const favicon_base::FaviconRawBitmapResult& bitmap_result) {
39 return bitmap_result.expired; 34 return bitmap_result.expired;
40 } 35 }
41 36
42 // Return true if |bitmap_result| is valid. 37 // Return true if |bitmap_result| is valid.
43 bool IsValid(const favicon_base::FaviconRawBitmapResult& bitmap_result) { 38 bool IsValid(const favicon_base::FaviconRawBitmapResult& bitmap_result) {
44 return bitmap_result.is_valid(); 39 return bitmap_result.is_valid();
45 } 40 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 switch (handler_type) { 124 switch (handler_type) {
130 case FaviconDriverObserver::NON_TOUCH_16_DIP: { 125 case FaviconDriverObserver::NON_TOUCH_16_DIP: {
131 std::vector<int> pixel_sizes; 126 std::vector<int> pixel_sizes;
132 for (float scale_factor : favicon_base::GetFaviconScales()) { 127 for (float scale_factor : favicon_base::GetFaviconScales()) {
133 pixel_sizes.push_back( 128 pixel_sizes.push_back(
134 static_cast<int>(ceil(scale_factor * gfx::kFaviconSize))); 129 static_cast<int>(ceil(scale_factor * gfx::kFaviconSize)));
135 } 130 }
136 return pixel_sizes; 131 return pixel_sizes;
137 } 132 }
138 case FaviconDriverObserver::NON_TOUCH_LARGEST: 133 case FaviconDriverObserver::NON_TOUCH_LARGEST:
139 return std::vector<int>(1U, kNonTouchLargestIconSize);
140 case FaviconDriverObserver::TOUCH_LARGEST: 134 case FaviconDriverObserver::TOUCH_LARGEST:
141 return std::vector<int>(1U, kTouchIconSize); 135 return std::vector<int>(1U, kLargestIconSize);
142 } 136 }
143 NOTREACHED(); 137 NOTREACHED();
144 return std::vector<int>(); 138 return std::vector<int>();
145 } 139 }
146 140
147 bool FaviconURLEquals(const FaviconURL& lhs, const FaviconURL& rhs) { 141 bool FaviconURLEquals(const FaviconURL& lhs, const FaviconURL& rhs) {
148 return lhs.icon_url == rhs.icon_url && lhs.icon_type == rhs.icon_type && 142 return lhs.icon_url == rhs.icon_url && lhs.icon_type == rhs.icon_type &&
149 lhs.icon_sizes == rhs.icon_sizes; 143 lhs.icon_sizes == rhs.icon_sizes;
150 } 144 }
151 145
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 // Check if the manifest was previously blacklisted (e.g. returned a 404) and 335 // Check if the manifest was previously blacklisted (e.g. returned a 404) and
342 // ignore the manifest URL if that's the case. 336 // ignore the manifest URL if that's the case.
343 if (!manifest_url_.is_empty() && 337 if (!manifest_url_.is_empty() &&
344 service_->WasUnableToDownloadFavicon(manifest_url_)) { 338 service_->WasUnableToDownloadFavicon(manifest_url_)) {
345 DVLOG(1) << "Skip failed Manifest: " << manifest_url; 339 DVLOG(1) << "Skip failed Manifest: " << manifest_url;
346 manifest_url_ = GURL(); 340 manifest_url_ = GURL();
347 } 341 }
348 342
349 // If no manifest available, proceed with the regular candidates only. 343 // If no manifest available, proceed with the regular candidates only.
350 if (manifest_url_.is_empty()) { 344 if (manifest_url_.is_empty()) {
351 OnGotFinalIconURLCandidates(candidates, 345 OnGotFinalIconURLCandidates(candidates);
352 GetDesiredPixelSizes(handler_type_));
353 return; 346 return;
354 } 347 }
355 348
356 // See if there is a cached favicon for the manifest. This will update the DB 349 // See if there is a cached favicon for the manifest. This will update the DB
357 // mappings only if the manifest URL is cached. 350 // mappings only if the manifest URL is cached.
358 GetFaviconAndUpdateMappingsUnlessIncognito( 351 GetFaviconAndUpdateMappingsUnlessIncognito(
359 /*icon_url=*/manifest_url_, favicon_base::WEB_MANIFEST_ICON, 352 /*icon_url=*/manifest_url_, favicon_base::WEB_MANIFEST_ICON,
360 base::Bind(&FaviconHandler::OnFaviconDataForManifestFromFaviconService, 353 base::Bind(&FaviconHandler::OnFaviconDataForManifestFromFaviconService,
361 base::Unretained(this))); 354 base::Unretained(this)));
362 } 355 }
(...skipping 28 matching lines...) Expand all
391 manifest_download_request_.callback()); 384 manifest_download_request_.callback());
392 } 385 }
393 } 386 }
394 387
395 void FaviconHandler::OnDidDownloadManifest( 388 void FaviconHandler::OnDidDownloadManifest(
396 const std::vector<FaviconURL>& candidates) { 389 const std::vector<FaviconURL>& candidates) {
397 // Mark manifest download as finished. 390 // Mark manifest download as finished.
398 manifest_download_request_.Cancel(); 391 manifest_download_request_.Cancel();
399 392
400 if (!candidates.empty()) { 393 if (!candidates.empty()) {
401 // When reading icons from web manifests, prefer kNonTouchLargestIconSize. 394 // When reading icons from web manifests, prefer kNonTouchLargestIconSize.
pkotwicz 2017/07/12 15:27:30 Should the comment be deleted?
mastiz 2017/07/24 07:52:15 Done.
402 OnGotFinalIconURLCandidates(candidates, 395 OnGotFinalIconURLCandidates(candidates);
403 std::vector<int>(1U, kNonTouchLargestIconSize));
404 return; 396 return;
405 } 397 }
406 398
407 // If either the downloading of the manifest failed, OR the manifest contains 399 // If either the downloading of the manifest failed, OR the manifest contains
408 // no icons, proceed with the list of icons listed in the HTML. 400 // no icons, proceed with the list of icons listed in the HTML.
409 DVLOG(1) << "Could not fetch Manifest icons from " << manifest_url_ 401 DVLOG(1) << "Could not fetch Manifest icons from " << manifest_url_
410 << ", falling back to inlined ones, which are " 402 << ", falling back to inlined ones, which are "
411 << non_manifest_original_candidates_.size(); 403 << non_manifest_original_candidates_.size();
412 404
413 service_->UnableToDownloadFavicon(manifest_url_); 405 service_->UnableToDownloadFavicon(manifest_url_);
414 manifest_url_ = GURL(); 406 manifest_url_ = GURL();
415 407
416 OnGotFinalIconURLCandidates(non_manifest_original_candidates_, 408 OnGotFinalIconURLCandidates(non_manifest_original_candidates_);
417 GetDesiredPixelSizes(handler_type_));
418 } 409 }
419 410
420 void FaviconHandler::OnGotFinalIconURLCandidates( 411 void FaviconHandler::OnGotFinalIconURLCandidates(
421 const std::vector<FaviconURL>& candidates, 412 const std::vector<FaviconURL>& candidates) {
422 const std::vector<int>& desired_pixel_sizes) { 413 const std::vector<int> desired_pixel_sizes =
414 GetDesiredPixelSizes(handler_type_);
415
423 std::vector<FaviconCandidate> sorted_candidates; 416 std::vector<FaviconCandidate> sorted_candidates;
424 for (const FaviconURL& candidate : candidates) { 417 for (const FaviconURL& candidate : candidates) {
425 if (!candidate.icon_url.is_empty() && (candidate.icon_type & icon_types_)) { 418 if (!candidate.icon_url.is_empty() && (candidate.icon_type & icon_types_)) {
426 sorted_candidates.push_back( 419 sorted_candidates.push_back(
427 FaviconCandidate::FromFaviconURL(candidate, desired_pixel_sizes)); 420 FaviconCandidate::FromFaviconURL(candidate, desired_pixel_sizes));
428 } 421 }
429 } 422 }
430 423
431 std::stable_sort(sorted_candidates.begin(), sorted_candidates.end(), 424 std::stable_sort(sorted_candidates.begin(), sorted_candidates.end(),
432 &FaviconCandidate::CompareScore); 425 &FaviconCandidate::CompareScore);
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 // A max bitmap size is specified to avoid receiving huge bitmaps in 661 // A max bitmap size is specified to avoid receiving huge bitmaps in
669 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload() 662 // OnDidDownloadFavicon(). See FaviconDriver::StartDownload()
670 // for more details about the max bitmap size. 663 // for more details about the max bitmap size.
671 const int download_id = 664 const int download_id =
672 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_), 665 delegate_->DownloadImage(image_url, GetMaximalIconSize(handler_type_),
673 image_download_request_.callback()); 666 image_download_request_.callback());
674 DCHECK_NE(download_id, 0); 667 DCHECK_NE(download_id, 0);
675 } 668 }
676 669
677 } // namespace favicon 670 } // namespace favicon
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698