OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/favicon/core/large_icon_service.h" | |
6 | |
7 #include "components/favicon/core/favicon_service.h" | |
8 #include "components/favicon_base/fallback_icon_style.h" | |
9 #include "components/favicon_base/favicon_types.h" | |
10 | |
11 namespace favicon { | |
12 | |
13 LargeIconService::LargeIconService(FaviconService* favicon_service) | |
14 : favicon_service_(favicon_service) { | |
15 large_icon_types_.push_back(favicon_base::IconType::FAVICON); | |
16 large_icon_types_.push_back(favicon_base::IconType::TOUCH_ICON); | |
17 large_icon_types_.push_back(favicon_base::IconType::TOUCH_PRECOMPOSED_ICON); | |
18 } | |
19 | |
20 LargeIconService::~LargeIconService() { | |
21 } | |
22 | |
23 base::CancelableTaskTracker::TaskId | |
24 LargeIconService::GetLargeIconOrFallbackStyle( | |
25 const GURL& page_url, | |
26 int desired_size_in_pixel, | |
27 const favicon_base::LargeIconCallback& callback, | |
28 base::CancelableTaskTracker* tracker) { | |
29 // TODO(beaudoin): For now this is just a wrapper around | |
30 // GetLargestRawFaviconForPageURL. Add the logic required to select the best | |
31 // possible large icon. Also add logic to fetch-on-demand when the URL of | |
32 // a large icon is known but its bitmap is not available. | |
33 return favicon_service_->GetLargestRawFaviconForPageURL( | |
34 page_url, | |
35 large_icon_types_, | |
36 desired_size_in_pixel, | |
37 base::Bind(&LargeIconService::RunLargeIconCallback, | |
38 base::Unretained(this), callback, desired_size_in_pixel), | |
39 tracker); | |
40 } | |
41 | |
42 void LargeIconService::RunLargeIconCallback( | |
43 const favicon_base::LargeIconCallback& callback, | |
44 int desired_size_in_pixel, | |
45 const favicon_base::FaviconRawBitmapResult& bitmap_result) { | |
46 // If there are no bitmaps, return a result with an empty |bitmap| and a | |
47 // default |fallback_icon_style|. | |
48 favicon_base::LargeIconResult result; | |
49 if (!bitmap_result.is_valid()) { | |
50 callback.Run(result); | |
51 return; | |
52 } | |
53 | |
54 // If there is a bitmap but it's smaller than the requested size or | |
55 // non-square, compute its dominant color and use it as background in | |
56 // |fallback_icon_style|. | |
57 if (bitmap_result.pixel_size.width() < desired_size_in_pixel || | |
58 bitmap_result.pixel_size.height() < desired_size_in_pixel || | |
59 bitmap_result.pixel_size.width() != bitmap_result.pixel_size.height()) { | |
pkotwicz
2015/04/21 18:19:48
It is probably worth mentioning in the CL descript
beaudoin
2015/04/21 19:03:23
Good point. I think it was a blatant bug in the or
| |
60 // TODO(beaudoin): Resize the icon if it's large enough. Alternatively, | |
61 // return it and let the HTML resize it. | |
62 result.fallback_icon_style.reset(new favicon_base::FallbackIconStyle()); | |
63 favicon_base::SetDominantColorAsBackground( | |
64 bitmap_result.bitmap_data, result.fallback_icon_style.get()); | |
65 } else { | |
66 // The bitmap is square and at least as large as the requested one, return | |
67 // it. | |
68 // TODO(beaudoin): Resize the icon if it's too large. Alternatively, return | |
69 // it and let the HTML resize it. | |
70 result.bitmap = bitmap_result; | |
71 } | |
72 | |
73 callback.Run(result); | |
74 } | |
75 | |
76 } // namespace favicon | |
OLD | NEW |