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 "chrome/browser/favicon/favicon_handler.h" | 5 #include "chrome/browser/favicon/favicon_handler.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <vector> | 10 #include <vector> |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 // |bitmap_results| should always be complete for data inserted by | 116 // |bitmap_results| should always be complete for data inserted by |
117 // FaviconHandler as the FaviconHandler stores favicons resized to all | 117 // FaviconHandler as the FaviconHandler stores favicons resized to all |
118 // of favicon_base::GetFaviconScaleFactors() into the history backend. | 118 // of favicon_base::GetFaviconScaleFactors() into the history backend. |
119 // Examples of when |bitmap_results| can be incomplete: | 119 // Examples of when |bitmap_results| can be incomplete: |
120 // - Favicons inserted into the history backend by sync. | 120 // - Favicons inserted into the history backend by sync. |
121 // - Favicons for imported bookmarks. | 121 // - Favicons for imported bookmarks. |
122 std::vector<gfx::Size> favicon_sizes; | 122 std::vector<gfx::Size> favicon_sizes; |
123 for (size_t i = 0; i < bitmap_results.size(); ++i) | 123 for (size_t i = 0; i < bitmap_results.size(); ++i) |
124 favicon_sizes.push_back(bitmap_results[i].pixel_size); | 124 favicon_sizes.push_back(bitmap_results[i].pixel_size); |
125 | 125 |
126 std::vector<ui::ScaleFactor> scale_factors = | 126 std::vector<float> favicon_scales = favicon_base::GetFaviconScales(); |
127 favicon_base::GetFaviconScaleFactors(); | 127 for (size_t i = 0; i < favicon_scales.size(); ++i) { |
128 for (size_t i = 0; i < scale_factors.size(); ++i) { | 128 int edge_size_in_pixel = floor(desired_size_in_dip * favicon_scales[i]); |
pkotwicz
2014/06/18 15:46:33
This should be ceil()
| |
129 int edge_size_in_pixel = floor( | |
130 desired_size_in_dip * ui::GetScaleForScaleFactor(scale_factors[i])); | |
131 std::vector<gfx::Size>::iterator it = std::find(favicon_sizes.begin(), | 129 std::vector<gfx::Size>::iterator it = std::find(favicon_sizes.begin(), |
132 favicon_sizes.end(), gfx::Size(edge_size_in_pixel, edge_size_in_pixel)); | 130 favicon_sizes.end(), gfx::Size(edge_size_in_pixel, edge_size_in_pixel)); |
133 if (it == favicon_sizes.end()) | 131 if (it == favicon_sizes.end()) |
134 return true; | 132 return true; |
135 } | 133 } |
136 return false; | 134 return false; |
137 } | 135 } |
138 | 136 |
139 // Returns true if at least one of |bitmap_results| is valid. | 137 // Returns true if at least one of |bitmap_results| is valid. |
140 bool HasValidResult( | 138 bool HasValidResult( |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 if (UrlMatches(url, url_) && icon_type == favicon_base::FAVICON) { | 308 if (UrlMatches(url, url_) && icon_type == favicon_base::FAVICON) { |
311 if (!PageChangedSinceFaviconWasRequested()) | 309 if (!PageChangedSinceFaviconWasRequested()) |
312 SetFaviconOnActivePage(icon_url, image); | 310 SetFaviconOnActivePage(icon_url, image); |
313 } | 311 } |
314 } | 312 } |
315 | 313 |
316 void FaviconHandler::SetFaviconOnActivePage(const std::vector< | 314 void FaviconHandler::SetFaviconOnActivePage(const std::vector< |
317 favicon_base::FaviconRawBitmapResult>& favicon_bitmap_results) { | 315 favicon_base::FaviconRawBitmapResult>& favicon_bitmap_results) { |
318 gfx::Image resized_image = favicon_base::SelectFaviconFramesFromPNGs( | 316 gfx::Image resized_image = favicon_base::SelectFaviconFramesFromPNGs( |
319 favicon_bitmap_results, | 317 favicon_bitmap_results, |
320 favicon_base::GetFaviconScaleFactors(), | 318 favicon_base::GetFaviconScales(), |
321 preferred_icon_size()); | 319 preferred_icon_size()); |
322 // The history service sends back results for a single icon URL, so it does | 320 // The history service sends back results for a single icon URL, so it does |
323 // not matter which result we get the |icon_url| from. | 321 // not matter which result we get the |icon_url| from. |
324 const GURL icon_url = favicon_bitmap_results.empty() ? | 322 const GURL icon_url = favicon_bitmap_results.empty() ? |
325 GURL() : favicon_bitmap_results[0].icon_url; | 323 GURL() : favicon_bitmap_results[0].icon_url; |
326 SetFaviconOnActivePage(icon_url, resized_image); | 324 SetFaviconOnActivePage(icon_url, resized_image); |
327 } | 325 } |
328 | 326 |
329 void FaviconHandler::SetFaviconOnActivePage(const GURL& icon_url, | 327 void FaviconHandler::SetFaviconOnActivePage(const GURL& icon_url, |
330 const gfx::Image& image) { | 328 const gfx::Image& image) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
421 current_candidate()->icon_sizes[0]); | 419 current_candidate()->icon_sizes[0]); |
422 // Find largest bitmap if there is no one exactly matched. | 420 // Find largest bitmap if there is no one exactly matched. |
423 if (index == -1) { | 421 if (index == -1) { |
424 index = GetLargestSizeIndex(original_bitmap_sizes, | 422 index = GetLargestSizeIndex(original_bitmap_sizes, |
425 max_size * max_size); | 423 max_size * max_size); |
426 } | 424 } |
427 } | 425 } |
428 if (index != -1) | 426 if (index != -1) |
429 image_skia = gfx::ImageSkia(gfx::ImageSkiaRep(bitmaps[index], 1)); | 427 image_skia = gfx::ImageSkia(gfx::ImageSkiaRep(bitmaps[index], 1)); |
430 } else { | 428 } else { |
431 std::vector<ui::ScaleFactor> scale_factors = | |
432 favicon_base::GetFaviconScaleFactors(); | |
433 image_skia = SelectFaviconFrames(bitmaps, | 429 image_skia = SelectFaviconFrames(bitmaps, |
434 original_bitmap_sizes, | 430 original_bitmap_sizes, |
435 scale_factors, | 431 favicon_base::GetFaviconScales(), |
436 preferred_icon_size(), | 432 preferred_icon_size(), |
437 &score); | 433 &score); |
438 } | 434 } |
439 | 435 |
440 if (!image_skia.isNull()) { | 436 if (!image_skia.isNull()) { |
441 gfx::Image image(image_skia); | 437 gfx::Image image(image_skia); |
442 // The downloaded icon is still valid when there is no FaviconURL update | 438 // The downloaded icon is still valid when there is no FaviconURL update |
443 // during the downloading. | 439 // during the downloading. |
444 if (!bitmaps.empty()) { | 440 if (!bitmaps.empty()) { |
445 request_next_icon = !UpdateFaviconCandidate( | 441 request_next_icon = !UpdateFaviconCandidate( |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
684 } else { | 680 } else { |
685 gfx::Size largest = i->icon_sizes[index]; | 681 gfx::Size largest = i->icon_sizes[index]; |
686 i->icon_sizes.clear(); | 682 i->icon_sizes.clear(); |
687 i->icon_sizes.push_back(largest); | 683 i->icon_sizes.push_back(largest); |
688 ++i; | 684 ++i; |
689 } | 685 } |
690 } | 686 } |
691 std::stable_sort(image_urls_.begin(), image_urls_.end(), | 687 std::stable_sort(image_urls_.begin(), image_urls_.end(), |
692 CompareIconSize); | 688 CompareIconSize); |
693 } | 689 } |
OLD | NEW |