OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/ui/webui/large_icon_source.h" | 5 #include "chrome/browser/ui/webui/large_icon_source.h" |
6 | 6 |
7 #include <string> | |
8 #include <vector> | 7 #include <vector> |
9 | 8 |
10 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
11 #include "chrome/browser/favicon/favicon_service_factory.h" | |
12 #include "chrome/browser/profiles/profile.h" | |
13 #include "chrome/browser/search/instant_io_context.h" | 10 #include "chrome/browser/search/instant_io_context.h" |
14 #include "chrome/common/favicon/large_icon_url_parser.h" | 11 #include "chrome/common/favicon/large_icon_url_parser.h" |
15 #include "chrome/common/url_constants.h" | 12 #include "chrome/common/url_constants.h" |
| 13 #include "components/favicon/core/fallback_icon_service.h" |
16 #include "components/favicon/core/favicon_service.h" | 14 #include "components/favicon/core/favicon_service.h" |
17 #include "components/favicon_base/fallback_icon_style.h" | 15 #include "components/favicon_base/fallback_icon_style.h" |
18 #include "grit/platform_locale_settings.h" | |
19 #include "net/url_request/url_request.h" | 16 #include "net/url_request/url_request.h" |
20 #include "third_party/skia/include/core/SkColor.h" | 17 #include "third_party/skia/include/core/SkColor.h" |
21 #include "ui/base/l10n/l10n_util.h" | |
22 | 18 |
23 namespace { | 19 namespace { |
24 | 20 |
25 int kDefaultLargeIconSize = 96; | 21 int kDefaultLargeIconSize = 96; |
26 int kMaxLargeIconSize = 192; // Arbitrary bound to safeguard endpoint. | 22 int kMaxLargeIconSize = 192; // Arbitrary bound to safeguard endpoint. |
27 | 23 |
28 } // namespace | 24 } // namespace |
29 | 25 |
30 LargeIconSource::IconRequest::IconRequest() : size(kDefaultLargeIconSize) { | 26 LargeIconSource::IconRequest::IconRequest() : size(kDefaultLargeIconSize) { |
31 } | 27 } |
32 | 28 |
33 LargeIconSource::IconRequest::IconRequest( | 29 LargeIconSource::IconRequest::IconRequest( |
34 const content::URLDataSource::GotDataCallback& callback_in, | 30 const content::URLDataSource::GotDataCallback& callback_in, |
35 const GURL& url_in, | 31 const GURL& url_in, |
36 int size_in) | 32 int size_in) |
37 : callback(callback_in), | 33 : callback(callback_in), |
38 url(url_in), | 34 url(url_in), |
39 size(size_in) { | 35 size(size_in) { |
40 } | 36 } |
41 | 37 |
42 LargeIconSource::IconRequest::~IconRequest() { | 38 LargeIconSource::IconRequest::~IconRequest() { |
43 } | 39 } |
44 | 40 |
45 LargeIconSource::LargeIconSource(Profile* profile) : profile_(profile) { | 41 LargeIconSource::LargeIconSource(FaviconService* favicon_service, |
46 std::vector<std::string> font_list; | 42 FallbackIconService* fallback_icon_service) |
47 #if defined(OS_CHROMEOS) | 43 : favicon_service_(favicon_service), |
48 font_list.push_back("Noto Sans"); | 44 fallback_icon_service_(fallback_icon_service) { |
49 #elif defined(OS_IOS) | 45 DCHECK(favicon_service_); |
50 font_list.push_back("Helvetica Neue"); | 46 DCHECK(fallback_icon_service_); |
51 #else | |
52 font_list.push_back(l10n_util::GetStringUTF8(IDS_SANS_SERIF_FONT_FAMILY)); | |
53 #endif | |
54 fallback_icon_service_.reset(new FallbackIconService(font_list)); | |
55 } | 47 } |
56 | 48 |
57 LargeIconSource::~LargeIconSource() { | 49 LargeIconSource::~LargeIconSource() { |
58 } | 50 } |
59 | 51 |
60 std::string LargeIconSource::GetSource() const { | 52 std::string LargeIconSource::GetSource() const { |
61 return chrome::kChromeUILargeIconHost; | 53 return chrome::kChromeUILargeIconHost; |
62 } | 54 } |
63 | 55 |
64 void LargeIconSource::StartDataRequest( | 56 void LargeIconSource::StartDataRequest( |
65 const std::string& path, | 57 const std::string& path, |
66 int render_process_id, | 58 int render_process_id, |
67 int render_frame_id, | 59 int render_frame_id, |
68 const content::URLDataSource::GotDataCallback& callback) { | 60 const content::URLDataSource::GotDataCallback& callback) { |
69 LargeIconUrlParser parser; | 61 LargeIconUrlParser parser; |
70 bool success = parser.Parse(path); | 62 bool success = parser.Parse(path); |
71 if (!success || parser.size_in_pixels() <= 0 || | 63 if (!success || parser.size_in_pixels() <= 0 || |
72 parser.size_in_pixels() > kMaxLargeIconSize) { | 64 parser.size_in_pixels() > kMaxLargeIconSize) { |
73 SendNotFoundResponse(callback); | 65 SendNotFoundResponse(callback); |
74 return; | 66 return; |
75 } | 67 } |
76 | 68 |
77 FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( | |
78 profile_, ServiceAccessType::EXPLICIT_ACCESS); | |
79 if (!favicon_service) { | |
80 SendNotFoundResponse(callback); | |
81 return; | |
82 } | |
83 | |
84 GURL url(parser.url_string()); | 69 GURL url(parser.url_string()); |
85 if (!url.is_valid()) { | 70 if (!url.is_valid()) { |
86 SendNotFoundResponse(callback); | 71 SendNotFoundResponse(callback); |
87 return; | 72 return; |
88 } | 73 } |
89 | 74 |
90 favicon_service->GetRawFaviconForPageURL( | 75 favicon_service_->GetRawFaviconForPageURL( |
91 url, | 76 url, |
92 favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON, | 77 favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON, |
93 parser.size_in_pixels(), | 78 parser.size_in_pixels(), |
94 base::Bind( | 79 base::Bind( |
95 &LargeIconSource::OnIconDataAvailable, | 80 &LargeIconSource::OnIconDataAvailable, |
96 base::Unretained(this), | 81 base::Unretained(this), |
97 IconRequest(callback, url, parser.size_in_pixels())), | 82 IconRequest(callback, url, parser.size_in_pixels())), |
98 &cancelable_task_tracker_); | 83 &cancelable_task_tracker_); |
99 } | 84 } |
100 | 85 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 std::vector<unsigned char> bitmap_data = | 119 std::vector<unsigned char> bitmap_data = |
135 fallback_icon_service_->RenderFallbackIconBitmap( | 120 fallback_icon_service_->RenderFallbackIconBitmap( |
136 request.url, request.size, style); | 121 request.url, request.size, style); |
137 request.callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data)); | 122 request.callback.Run(base::RefCountedBytes::TakeVector(&bitmap_data)); |
138 } | 123 } |
139 | 124 |
140 void LargeIconSource::SendNotFoundResponse( | 125 void LargeIconSource::SendNotFoundResponse( |
141 const content::URLDataSource::GotDataCallback& callback) { | 126 const content::URLDataSource::GotDataCallback& callback) { |
142 callback.Run(nullptr); | 127 callback.Run(nullptr); |
143 } | 128 } |
OLD | NEW |