[email protected] | 2f7826a3 | 2012-04-18 00:29:54 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | f8464522 | 2009-03-30 23:06:27 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | fd42ac30f | 2011-02-27 19:33:36 | [diff] [blame] | 5 | #include "chrome/browser/ui/webui/favicon_source.h" |
[email protected] | f8464522 | 2009-03-30 23:06:27 | [diff] [blame] | 6 | |
[email protected] | 25244a93 | 2014-07-12 23:00:24 | [diff] [blame] | 7 | #include <cmath> |
| 8 | |
[email protected] | bbdd298 | 2011-10-08 18:14:24 | [diff] [blame] | 9 | #include "base/bind.h" |
| 10 | #include "base/bind_helpers.h" |
Victor Hugo Vianna Silva | 969aca6 | 2019-04-23 11:28:34 | [diff] [blame] | 11 | #include "base/metrics/histogram_macros.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 12 | #include "base/strings/string_number_conversions.h" |
[email protected] | f3d2b31 | 2012-08-23 22:27:59 | [diff] [blame] | 13 | #include "chrome/browser/favicon/favicon_service_factory.h" |
Victor Hugo Vianna Silva | df127bfc | 2019-07-03 00:02:12 | [diff] [blame] | 14 | #include "chrome/browser/favicon/history_ui_favicon_request_handler_factory.h" |
sdefresne | 0da3bc0 | 2015-01-29 18:26:35 | [diff] [blame] | 15 | #include "chrome/browser/history/top_sites_factory.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 16 | #include "chrome/browser/profiles/profile.h" |
[email protected] | a7b8e43d | 2013-03-18 18:52:43 | [diff] [blame] | 17 | #include "chrome/browser/search/instant_io_context.h" |
[email protected] | f8464522 | 2009-03-30 23:06:27 | [diff] [blame] | 18 | #include "chrome/common/url_constants.h" |
Dan Beam | 3c16470 | 2019-05-30 01:44:10 | [diff] [blame] | 19 | #include "chrome/common/webui_url_constants.h" |
Victor Hugo Vianna Silva | df127bfc | 2019-07-03 00:02:12 | [diff] [blame] | 20 | #include "components/favicon/core/history_ui_favicon_request_handler.h" |
blundell | ee0ade2 | 2015-07-08 10:07:45 | [diff] [blame] | 21 | #include "components/favicon_base/favicon_url_parser.h" |
sdefresne | 0da3bc0 | 2015-01-29 18:26:35 | [diff] [blame] | 22 | #include "components/history/core/browser/top_sites.h" |
Victor Hugo Vianna Silva | 969aca6 | 2019-04-23 11:28:34 | [diff] [blame] | 23 | #include "content/public/browser/web_contents.h" |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 24 | #include "net/url_request/url_request.h" |
[email protected] | c49201a | 2012-05-24 11:04:57 | [diff] [blame] | 25 | #include "ui/base/layout.h" |
[email protected] | 42ce29d | 2011-01-20 23:19:46 | [diff] [blame] | 26 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | cd67ed5 | 2013-10-15 01:22:13 | [diff] [blame] | 27 | #include "ui/base/webui/web_ui_util.h" |
Dan Beam | 75cd5b07 | 2019-02-23 01:04:46 | [diff] [blame] | 28 | #include "ui/native_theme/native_theme.h" |
[email protected] | b47dc49 | 2014-08-17 07:05:57 | [diff] [blame] | 29 | #include "ui/resources/grit/ui_resources.h" |
Victor Hugo Vianna Silva | 969aca6 | 2019-04-23 11:28:34 | [diff] [blame] | 30 | #include "url/gurl.h" |
| 31 | |
| 32 | namespace { |
Victor Hugo Vianna Silva | 55a7cd5 | 2019-07-14 17:34:23 | [diff] [blame] | 33 | |
Victor Hugo Vianna Silva | d611d270 | 2019-07-16 10:11:23 | [diff] [blame] | 34 | // web_contents->GetLastCommittedURL in general will not necessarily yield the |
| 35 | // original URL that started the request, but we're only interested in verifying |
| 36 | // if it was issued by a history page, for whom this is the case. If it is not |
| 37 | // possible to obtain the URL, we return the empty GURL. |
John Abd-El-Malek | 92bf360 | 2019-07-31 02:25:48 | [diff] [blame] | 38 | GURL GetUnsafeRequestOrigin(const content::WebContents::Getter& wc_getter) { |
Victor Hugo Vianna Silva | 55a7cd5 | 2019-07-14 17:34:23 | [diff] [blame] | 39 | content::WebContents* web_contents = wc_getter.Run(); |
Victor Hugo Vianna Silva | d611d270 | 2019-07-16 10:11:23 | [diff] [blame] | 40 | return web_contents ? web_contents->GetLastCommittedURL() : GURL(); |
Victor Hugo Vianna Silva | 55a7cd5 | 2019-07-14 17:34:23 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | bool ParseHistoryUiOrigin(const GURL& url, |
Victor Hugo Vianna Silva | 9214a229 | 2019-07-14 18:30:04 | [diff] [blame] | 44 | favicon::HistoryUiFaviconRequestOrigin* origin) { |
Victor Hugo Vianna Silva | 969aca6 | 2019-04-23 11:28:34 | [diff] [blame] | 45 | GURL history_url(chrome::kChromeUIHistoryURL); |
Victor Hugo Vianna Silva | 55a7cd5 | 2019-07-14 17:34:23 | [diff] [blame] | 46 | if (url == history_url) { |
Victor Hugo Vianna Silva | 64b3818 | 2019-07-20 21:19:59 | [diff] [blame] | 47 | *origin = favicon::HistoryUiFaviconRequestOrigin::kHistory; |
Victor Hugo Vianna Silva | 55a7cd5 | 2019-07-14 17:34:23 | [diff] [blame] | 48 | return true; |
| 49 | } |
| 50 | if (url == history_url.Resolve(chrome::kChromeUIHistorySyncedTabs)) { |
Victor Hugo Vianna Silva | 64b3818 | 2019-07-20 21:19:59 | [diff] [blame] | 51 | *origin = favicon::HistoryUiFaviconRequestOrigin::kHistorySyncedTabs; |
Victor Hugo Vianna Silva | 55a7cd5 | 2019-07-14 17:34:23 | [diff] [blame] | 52 | return true; |
| 53 | } |
| 54 | return false; |
Victor Hugo Vianna Silva | 969aca6 | 2019-04-23 11:28:34 | [diff] [blame] | 55 | } |
Victor Hugo Vianna Silva | adf1af3d | 2019-05-20 09:01:16 | [diff] [blame] | 56 | |
Victor Hugo Vianna Silva | 969aca6 | 2019-04-23 11:28:34 | [diff] [blame] | 57 | } // namespace |
[email protected] | f8464522 | 2009-03-30 23:06:27 | [diff] [blame] | 58 | |
Victor Hugo Vianna Silva | ed44148 | 2019-06-27 12:40:40 | [diff] [blame] | 59 | FaviconSource::FaviconSource(Profile* profile, |
| 60 | chrome::FaviconUrlFormat url_format) |
| 61 | : profile_(profile->GetOriginalProfile()), url_format_(url_format) {} |
[email protected] | f8464522 | 2009-03-30 23:06:27 | [diff] [blame] | 62 | |
[email protected] | 16835e6 | 2011-03-16 14:13:08 | [diff] [blame] | 63 | FaviconSource::~FaviconSource() { |
[email protected] | 307175443 | 2010-07-28 00:09:54 | [diff] [blame] | 64 | } |
| 65 | |
Lucas Furukawa Gadani | 4b4eed0 | 2019-06-04 23:12:04 | [diff] [blame] | 66 | std::string FaviconSource::GetSource() { |
Victor Hugo Vianna Silva | ed44148 | 2019-06-27 12:40:40 | [diff] [blame] | 67 | switch (url_format_) { |
| 68 | case chrome::FaviconUrlFormat::kFaviconLegacy: |
| 69 | return chrome::kChromeUIFaviconHost; |
| 70 | case chrome::FaviconUrlFormat::kFavicon2: |
| 71 | return chrome::kChromeUIFavicon2Host; |
| 72 | } |
| 73 | NOTREACHED(); |
| 74 | return ""; |
[email protected] | 97642ce | 2012-04-30 17:05:22 | [diff] [blame] | 75 | } |
| 76 | |
[email protected] | 90d9f1e | 2013-01-16 02:46:41 | [diff] [blame] | 77 | void FaviconSource::StartDataRequest( |
Wei-Yin Chen (陳威尹) | 39f4ff3 | 2019-10-22 17:59:09 | [diff] [blame] | 78 | const GURL& url, |
John Abd-El-Malek | 92bf360 | 2019-07-31 02:25:48 | [diff] [blame] | 79 | const content::WebContents::Getter& wc_getter, |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame^] | 80 | content::URLDataSource::GotDataCallback callback) { |
Wei-Yin Chen (陳威尹) | 39f4ff3 | 2019-10-22 17:59:09 | [diff] [blame] | 81 | const std::string path = content::URLDataSource::URLToRequestPath(url); |
hayato | be13e67 | 2015-03-31 04:51:38 | [diff] [blame] | 82 | favicon::FaviconService* favicon_service = |
| 83 | FaviconServiceFactory::GetForProfile(profile_, |
| 84 | ServiceAccessType::EXPLICIT_ACCESS); |
[email protected] | 89ba386 | 2013-05-01 16:10:09 | [diff] [blame] | 85 | if (!favicon_service) { |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame^] | 86 | SendDefaultResponse(std::move(callback)); |
[email protected] | b4ae88cc | 2011-10-26 04:26:59 | [diff] [blame] | 87 | return; |
[email protected] | f8464522 | 2009-03-30 23:06:27 | [diff] [blame] | 88 | } |
[email protected] | b4ae88cc | 2011-10-26 04:26:59 | [diff] [blame] | 89 | |
[email protected] | 78dfe38 | 2013-07-17 18:05:42 | [diff] [blame] | 90 | chrome::ParsedFaviconPath parsed; |
Victor Hugo Vianna Silva | ed44148 | 2019-06-27 12:40:40 | [diff] [blame] | 91 | bool success = chrome::ParseFaviconPath(path, url_format_, &parsed); |
[email protected] | 89ba386 | 2013-05-01 16:10:09 | [diff] [blame] | 92 | if (!success) { |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame^] | 93 | SendDefaultResponse(std::move(callback)); |
[email protected] | 89ba386 | 2013-05-01 16:10:09 | [diff] [blame] | 94 | return; |
[email protected] | 79eaee6 | 2013-01-22 22:33:40 | [diff] [blame] | 95 | } |
| 96 | |
Victor Hugo Vianna Silva | 86363bfc | 2019-07-26 02:37:05 | [diff] [blame] | 97 | GURL page_url(parsed.page_url); |
| 98 | GURL icon_url(parsed.icon_url); |
| 99 | if (!page_url.is_valid() && !icon_url.is_valid()) { |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame^] | 100 | SendDefaultResponse(std::move(callback)); |
Dominick Ng | 4c85aa1 | 2018-01-09 02:39:13 | [diff] [blame] | 101 | return; |
| 102 | } |
| 103 | |
[email protected] | 25244a93 | 2014-07-12 23:00:24 | [diff] [blame] | 104 | int desired_size_in_pixel = |
| 105 | std::ceil(parsed.size_in_dip * parsed.device_scale_factor); |
[email protected] | 78dfe38 | 2013-07-17 18:05:42 | [diff] [blame] | 106 | |
Victor Hugo Vianna Silva | 86363bfc | 2019-07-26 02:37:05 | [diff] [blame] | 107 | if (parsed.page_url.empty()) { |
| 108 | // Request by icon url. |
| 109 | |
[email protected] | 81883b0 | 2012-09-27 00:14:05 | [diff] [blame] | 110 | // TODO(michaelbai): Change GetRawFavicon to support combination of |
| 111 | // IconType. |
huangs | 5f6eca4c | 2015-01-27 17:47:22 | [diff] [blame] | 112 | favicon_service->GetRawFavicon( |
Victor Hugo Vianna Silva | 86363bfc | 2019-07-26 02:37:05 | [diff] [blame] | 113 | icon_url, favicon_base::IconType::kFavicon, desired_size_in_pixel, |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame^] | 114 | base::BindOnce(&FaviconSource::OnFaviconDataAvailable, |
| 115 | base::Unretained(this), std::move(callback), |
| 116 | parsed.size_in_dip, parsed.device_scale_factor), |
[email protected] | a55e85b | 2012-12-12 02:31:58 | [diff] [blame] | 117 | &cancelable_task_tracker_); |
[email protected] | b4ae88cc | 2011-10-26 04:26:59 | [diff] [blame] | 118 | } else { |
sdefresne | 0da3bc0 | 2015-01-29 18:26:35 | [diff] [blame] | 119 | // Intercept requests for prepopulated pages if TopSites exists. |
| 120 | scoped_refptr<history::TopSites> top_sites = |
| 121 | TopSitesFactory::GetForProfile(profile_); |
| 122 | if (top_sites) { |
| 123 | for (const auto& prepopulated_page : top_sites->GetPrepopulatedPages()) { |
Victor Hugo Vianna Silva | 86363bfc | 2019-07-26 02:37:05 | [diff] [blame] | 124 | if (page_url == prepopulated_page.most_visited.url) { |
sdefresne | 0da3bc0 | 2015-01-29 18:26:35 | [diff] [blame] | 125 | ui::ScaleFactor resource_scale_factor = |
| 126 | ui::GetSupportedScaleFactor(parsed.device_scale_factor); |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame^] | 127 | std::move(callback).Run( |
Lei Zhang | 7640d54 | 2017-10-03 16:26:49 | [diff] [blame] | 128 | ui::ResourceBundle::GetSharedInstance() |
| 129 | .LoadDataResourceBytesForScale(prepopulated_page.favicon_id, |
| 130 | resource_scale_factor)); |
sdefresne | 0da3bc0 | 2015-01-29 18:26:35 | [diff] [blame] | 131 | return; |
| 132 | } |
[email protected] | b4ae88cc | 2011-10-26 04:26:59 | [diff] [blame] | 133 | } |
| 134 | } |
Victor Hugo Vianna Silva | 1674fcbd | 2019-07-09 09:24:41 | [diff] [blame] | 135 | |
Victor Hugo Vianna Silva | 9214a229 | 2019-07-14 18:30:04 | [diff] [blame] | 136 | favicon::HistoryUiFaviconRequestOrigin parsed_history_ui_origin; |
Victor Hugo Vianna Silva | 55a7cd5 | 2019-07-14 17:34:23 | [diff] [blame] | 137 | if (!parsed.allow_favicon_server_fallback || |
| 138 | !ParseHistoryUiOrigin(GetUnsafeRequestOrigin(wc_getter), |
| 139 | &parsed_history_ui_origin)) { |
Victor Hugo Vianna Silva | 1674fcbd | 2019-07-09 09:24:41 | [diff] [blame] | 140 | // Request from local storage only. |
| 141 | // TODO(victorvianna): Expose fallback_to_host in FaviconRequestHandler |
| 142 | // API and move the explanatory comment for |fallback_to_host| here. |
| 143 | const bool fallback_to_host = true; |
| 144 | favicon_service->GetRawFaviconForPageURL( |
Victor Hugo Vianna Silva | 86363bfc | 2019-07-26 02:37:05 | [diff] [blame] | 145 | page_url, {favicon_base::IconType::kFavicon}, desired_size_in_pixel, |
Victor Hugo Vianna Silva | 1674fcbd | 2019-07-09 09:24:41 | [diff] [blame] | 146 | fallback_to_host, |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame^] | 147 | base::BindOnce(&FaviconSource::OnFaviconDataAvailable, |
| 148 | base::Unretained(this), std::move(callback), |
| 149 | parsed.size_in_dip, parsed.device_scale_factor), |
Victor Hugo Vianna Silva | 1674fcbd | 2019-07-09 09:24:41 | [diff] [blame] | 150 | &cancelable_task_tracker_); |
| 151 | return; |
| 152 | } |
| 153 | |
| 154 | // Request from both local storage and favicon server using |
| 155 | // HistoryUiFaviconRequestHandler. |
Victor Hugo Vianna Silva | df127bfc | 2019-07-03 00:02:12 | [diff] [blame] | 156 | favicon::HistoryUiFaviconRequestHandler* |
| 157 | history_ui_favicon_request_handler = |
| 158 | HistoryUiFaviconRequestHandlerFactory::GetForBrowserContext( |
| 159 | profile_); |
| 160 | if (!history_ui_favicon_request_handler) { |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame^] | 161 | SendDefaultResponse(std::move(callback)); |
Victor Hugo Vianna Silva | 81d5124 | 2019-06-13 17:52:17 | [diff] [blame] | 162 | return; |
| 163 | } |
Victor Hugo Vianna Silva | df127bfc | 2019-07-03 00:02:12 | [diff] [blame] | 164 | history_ui_favicon_request_handler->GetRawFaviconForPageURL( |
Victor Hugo Vianna Silva | 86363bfc | 2019-07-26 02:37:05 | [diff] [blame] | 165 | page_url, desired_size_in_pixel, |
Victor Hugo Vianna Silva | e7ba15a | 2019-06-04 21:04:15 | [diff] [blame] | 166 | base::BindOnce(&FaviconSource::OnFaviconDataAvailable, |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame^] | 167 | base::Unretained(this), std::move(callback), |
| 168 | parsed.size_in_dip, parsed.device_scale_factor), |
Victor Hugo Vianna Silva | 64b3818 | 2019-07-20 21:19:59 | [diff] [blame] | 169 | favicon::FaviconRequestPlatform::kDesktop, parsed_history_ui_origin, |
Victor Hugo Vianna Silva | 6f1af5b | 2019-05-27 19:02:31 | [diff] [blame] | 170 | /*icon_url_for_uma=*/ |
Victor Hugo Vianna Silva | 8d13966 | 2019-07-26 11:14:51 | [diff] [blame] | 171 | GURL(parsed.icon_url), &cancelable_task_tracker_); |
[email protected] | b4ae88cc | 2011-10-26 04:26:59 | [diff] [blame] | 172 | } |
[email protected] | f8464522 | 2009-03-30 23:06:27 | [diff] [blame] | 173 | } |
| 174 | |
Lucas Furukawa Gadani | 4b4eed0 | 2019-06-04 23:12:04 | [diff] [blame] | 175 | std::string FaviconSource::GetMimeType(const std::string&) { |
[email protected] | 307175443 | 2010-07-28 00:09:54 | [diff] [blame] | 176 | // We need to explicitly return a mime type, otherwise if the user tries to |
| 177 | // drag the image they get no extension. |
| 178 | return "image/png"; |
| 179 | } |
| 180 | |
Lucas Furukawa Gadani | 4b4eed0 | 2019-06-04 23:12:04 | [diff] [blame] | 181 | bool FaviconSource::AllowCaching() { |
treib | c782ea5 | 2017-01-25 13:24:40 | [diff] [blame] | 182 | return false; |
| 183 | } |
| 184 | |
Lucas Furukawa Gadani | 4b4eed0 | 2019-06-04 23:12:04 | [diff] [blame] | 185 | bool FaviconSource::ShouldReplaceExistingSource() { |
[email protected] | ffe3d6f | 2011-02-23 16:42:52 | [diff] [blame] | 186 | // Leave the existing DataSource in place, otherwise we'll drop any pending |
| 187 | // requests on the floor. |
| 188 | return false; |
| 189 | } |
| 190 | |
jam | cf6f762 | 2017-05-03 22:16:28 | [diff] [blame] | 191 | bool FaviconSource::ShouldServiceRequest( |
| 192 | const GURL& url, |
| 193 | content::ResourceContext* resource_context, |
Lucas Furukawa Gadani | 4b4eed0 | 2019-06-04 23:12:04 | [diff] [blame] | 194 | int render_process_id) { |
jam | cf6f762 | 2017-05-03 22:16:28 | [diff] [blame] | 195 | if (url.SchemeIs(chrome::kChromeSearchScheme)) { |
| 196 | return InstantIOContext::ShouldServiceRequest(url, resource_context, |
| 197 | render_process_id); |
| 198 | } |
| 199 | return URLDataSource::ShouldServiceRequest(url, resource_context, |
| 200 | render_process_id); |
[email protected] | 672c8c1 | 2013-03-07 12:30:06 | [diff] [blame] | 201 | } |
| 202 | |
Dan Beam | 75cd5b07 | 2019-02-23 01:04:46 | [diff] [blame] | 203 | ui::NativeTheme* FaviconSource::GetNativeTheme() { |
| 204 | return ui::NativeTheme::GetInstanceForNativeUi(); |
| 205 | } |
| 206 | |
[email protected] | 16835e6 | 2011-03-16 14:13:08 | [diff] [blame] | 207 | void FaviconSource::OnFaviconDataAvailable( |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame^] | 208 | content::URLDataSource::GotDataCallback callback, |
Victor Hugo Vianna Silva | 7be8d85 | 2019-07-22 09:15:41 | [diff] [blame] | 209 | int size_in_dip, |
| 210 | float scale_factor, |
[email protected] | 12b54c7 | 2014-06-14 00:38:48 | [diff] [blame] | 211 | const favicon_base::FaviconRawBitmapResult& bitmap_result) { |
[email protected] | 0ea3db5 | 2012-12-07 01:32:01 | [diff] [blame] | 212 | if (bitmap_result.is_valid()) { |
| 213 | // Forward the data along to the networking system. |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame^] | 214 | std::move(callback).Run(bitmap_result.bitmap_data.get()); |
Victor Hugo Vianna Silva | 969aca6 | 2019-04-23 11:28:34 | [diff] [blame] | 215 | } else { |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame^] | 216 | SendDefaultResponse(std::move(callback), size_in_dip, scale_factor); |
[email protected] | 0ea3db5 | 2012-12-07 01:32:01 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | |
[email protected] | 79eaee6 | 2013-01-22 22:33:40 | [diff] [blame] | 220 | void FaviconSource::SendDefaultResponse( |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame^] | 221 | content::URLDataSource::GotDataCallback callback) { |
| 222 | SendDefaultResponse(std::move(callback), 16, 1.0f); |
[email protected] | 79eaee6 | 2013-01-22 22:33:40 | [diff] [blame] | 223 | } |
| 224 | |
Victor Hugo Vianna Silva | 7be8d85 | 2019-07-22 09:15:41 | [diff] [blame] | 225 | void FaviconSource::SendDefaultResponse( |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame^] | 226 | content::URLDataSource::GotDataCallback callback, |
Victor Hugo Vianna Silva | 7be8d85 | 2019-07-22 09:15:41 | [diff] [blame] | 227 | int size_in_dip, |
| 228 | float scale_factor) { |
minch | 1edd4d0 | 2019-08-05 19:10:56 | [diff] [blame] | 229 | const bool dark = GetNativeTheme()->ShouldUseDarkColors(); |
[email protected] | 81883b0 | 2012-09-27 00:14:05 | [diff] [blame] | 230 | int resource_id; |
Victor Hugo Vianna Silva | 7be8d85 | 2019-07-22 09:15:41 | [diff] [blame] | 231 | switch (size_in_dip) { |
[email protected] | 81883b0 | 2012-09-27 00:14:05 | [diff] [blame] | 232 | case 64: |
Dan Beam | 75cd5b07 | 2019-02-23 01:04:46 | [diff] [blame] | 233 | resource_id = dark ? IDR_DEFAULT_FAVICON_DARK_64 : IDR_DEFAULT_FAVICON_64; |
[email protected] | 81883b0 | 2012-09-27 00:14:05 | [diff] [blame] | 234 | break; |
| 235 | case 32: |
Dan Beam | 75cd5b07 | 2019-02-23 01:04:46 | [diff] [blame] | 236 | resource_id = dark ? IDR_DEFAULT_FAVICON_DARK_32 : IDR_DEFAULT_FAVICON_32; |
[email protected] | 81883b0 | 2012-09-27 00:14:05 | [diff] [blame] | 237 | break; |
| 238 | default: |
Dan Beam | 75cd5b07 | 2019-02-23 01:04:46 | [diff] [blame] | 239 | resource_id = dark ? IDR_DEFAULT_FAVICON_DARK : IDR_DEFAULT_FAVICON; |
[email protected] | 81883b0 | 2012-09-27 00:14:05 | [diff] [blame] | 240 | break; |
[email protected] | 969894ab | 2010-08-29 00:35:01 | [diff] [blame] | 241 | } |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame^] | 242 | std::move(callback).Run(LoadIconBytes(scale_factor, resource_id)); |
Dan Beam | 75cd5b07 | 2019-02-23 01:04:46 | [diff] [blame] | 243 | } |
[email protected] | 81883b0 | 2012-09-27 00:14:05 | [diff] [blame] | 244 | |
Victor Hugo Vianna Silva | 7be8d85 | 2019-07-22 09:15:41 | [diff] [blame] | 245 | base::RefCountedMemory* FaviconSource::LoadIconBytes(float scale_factor, |
Dan Beam | 75cd5b07 | 2019-02-23 01:04:46 | [diff] [blame] | 246 | int resource_id) { |
| 247 | return ui::ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( |
Victor Hugo Vianna Silva | 7be8d85 | 2019-07-22 09:15:41 | [diff] [blame] | 248 | resource_id, ui::GetSupportedScaleFactor(scale_factor)); |
[email protected] | 969894ab | 2010-08-29 00:35:01 | [diff] [blame] | 249 | } |