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, compute its | |
55 // dominant color and use it as background in |fallback_icon_style|. | |
56 if (bitmap_result.pixel_size.width() < desired_size_in_pixel || | |
57 bitmap_result.pixel_size.height() < desired_size_in_pixel) { | |
58 result.fallback_icon_style.reset(new favicon_base::FallbackIconStyle()); | |
59 favicon_base::SetDominantColorAsBackground( | |
60 bitmap_result.bitmap_data, result.fallback_icon_style.get()); | |
61 } else { | |
62 // The bitmap is the right size, use it. | |
63 result.bitmap = bitmap_result; | |
huangs
2015/04/21 05:00:28
// FIXME: Resize the bitmap to be |desired_size_in
beaudoin
2015/04/21 15:11:11
Done.
| |
64 } | |
65 | |
66 callback.Run(result); | |
67 } | |
68 | |
69 } // namespace favicon | |
OLD | NEW |