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/ui/webui/favicon_source.h" | 5 #include "chrome/browser/ui/webui/favicon_source.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "chrome/browser/favicon/favicon_service_factory.h" | 10 #include "chrome/browser/favicon/favicon_service_factory.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 72 |
73 chrome::ParsedFaviconPath parsed; | 73 chrome::ParsedFaviconPath parsed; |
74 bool success = chrome::ParseFaviconPath(path, icon_types_, &parsed); | 74 bool success = chrome::ParseFaviconPath(path, icon_types_, &parsed); |
75 if (!success) { | 75 if (!success) { |
76 SendDefaultResponse(callback); | 76 SendDefaultResponse(callback); |
77 return; | 77 return; |
78 } | 78 } |
79 | 79 |
80 GURL url(parsed.url); | 80 GURL url(parsed.url); |
81 | 81 |
| 82 ui::ScaleFactor scale_factor = |
| 83 ui::GetSupportedScaleFactor(parsed.scale_factor); |
82 if (parsed.is_icon_url) { | 84 if (parsed.is_icon_url) { |
83 // TODO(michaelbai): Change GetRawFavicon to support combination of | 85 // TODO(michaelbai): Change GetRawFavicon to support combination of |
84 // IconType. | 86 // IconType. |
85 favicon_service->GetRawFavicon( | 87 favicon_service->GetRawFavicon( |
86 url, | 88 url, |
87 favicon_base::FAVICON, | 89 favicon_base::FAVICON, |
88 parsed.size_in_dip, | 90 parsed.size_in_dip, |
89 parsed.scale_factor, | 91 scale_factor, |
90 base::Bind(&FaviconSource::OnFaviconDataAvailable, | 92 base::Bind(&FaviconSource::OnFaviconDataAvailable, |
91 base::Unretained(this), | 93 base::Unretained(this), |
92 IconRequest( | 94 IconRequest( |
93 callback, url, parsed.size_in_dip, parsed.scale_factor)), | 95 callback, url, parsed.size_in_dip, scale_factor)), |
94 &cancelable_task_tracker_); | 96 &cancelable_task_tracker_); |
95 } else { | 97 } else { |
96 // Intercept requests for prepopulated pages. | 98 // Intercept requests for prepopulated pages. |
97 for (size_t i = 0; i < arraysize(history::kPrepopulatedPages); i++) { | 99 for (size_t i = 0; i < arraysize(history::kPrepopulatedPages); i++) { |
98 if (url.spec() == | 100 if (url.spec() == |
99 l10n_util::GetStringUTF8(history::kPrepopulatedPages[i].url_id)) { | 101 l10n_util::GetStringUTF8(history::kPrepopulatedPages[i].url_id)) { |
100 callback.Run( | 102 callback.Run( |
101 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( | 103 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( |
102 history::kPrepopulatedPages[i].favicon_id, | 104 history::kPrepopulatedPages[i].favicon_id, |
103 parsed.scale_factor)); | 105 scale_factor)); |
104 return; | 106 return; |
105 } | 107 } |
106 } | 108 } |
107 | 109 |
108 favicon_service->GetRawFaviconForURL( | 110 favicon_service->GetRawFaviconForURL( |
109 FaviconService::FaviconForURLParams(url, icon_types_, | 111 FaviconService::FaviconForURLParams(url, icon_types_, |
110 parsed.size_in_dip), | 112 parsed.size_in_dip), |
111 parsed.scale_factor, | 113 scale_factor, |
112 base::Bind(&FaviconSource::OnFaviconDataAvailable, | 114 base::Bind(&FaviconSource::OnFaviconDataAvailable, |
113 base::Unretained(this), | 115 base::Unretained(this), |
114 IconRequest(callback, | 116 IconRequest(callback, |
115 url, | 117 url, |
116 parsed.size_in_dip, | 118 parsed.size_in_dip, |
117 parsed.scale_factor)), | 119 scale_factor)), |
118 &cancelable_task_tracker_); | 120 &cancelable_task_tracker_); |
119 } | 121 } |
120 } | 122 } |
121 | 123 |
122 std::string FaviconSource::GetMimeType(const std::string&) const { | 124 std::string FaviconSource::GetMimeType(const std::string&) const { |
123 // We need to explicitly return a mime type, otherwise if the user tries to | 125 // We need to explicitly return a mime type, otherwise if the user tries to |
124 // drag the image they get no extension. | 126 // drag the image they get no extension. |
125 return "image/png"; | 127 return "image/png"; |
126 } | 128 } |
127 | 129 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 break; | 187 break; |
186 default: | 188 default: |
187 favicon_index = SIZE_16; | 189 favicon_index = SIZE_16; |
188 resource_id = IDR_DEFAULT_FAVICON; | 190 resource_id = IDR_DEFAULT_FAVICON; |
189 break; | 191 break; |
190 } | 192 } |
191 base::RefCountedMemory* default_favicon = | 193 base::RefCountedMemory* default_favicon = |
192 default_favicons_[favicon_index].get(); | 194 default_favicons_[favicon_index].get(); |
193 | 195 |
194 if (!default_favicon) { | 196 if (!default_favicon) { |
195 ui::ScaleFactor scale_factor = icon_request.scale_factor; | |
196 default_favicon = ResourceBundle::GetSharedInstance() | 197 default_favicon = ResourceBundle::GetSharedInstance() |
197 .LoadDataResourceBytesForScale(resource_id, scale_factor); | 198 .LoadDataResourceBytesForScale(resource_id, |
| 199 icon_request.scale_factor); |
198 default_favicons_[favicon_index] = default_favicon; | 200 default_favicons_[favicon_index] = default_favicon; |
199 } | 201 } |
200 | 202 |
201 icon_request.callback.Run(default_favicon); | 203 icon_request.callback.Run(default_favicon); |
202 } | 204 } |
OLD | NEW |