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/android/webapps/add_to_homescreen_data_fetcher.h" | 5 #include "chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h" |
6 | 6 |
7 #include "base/location.h" | 7 #include "base/location.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/task/cancelable_task_tracker.h" | 9 #include "base/task/cancelable_task_tracker.h" |
10 #include "chrome/browser/android/offline_pages/offline_page_utils.h" | 10 #include "chrome/browser/android/offline_pages/offline_page_utils.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 const content::Manifest& manifest) { | 106 const content::Manifest& manifest) { |
107 if (!web_contents() || !weak_observer_) return; | 107 if (!web_contents() || !weak_observer_) return; |
108 | 108 |
109 if (!manifest.IsEmpty()) { | 109 if (!manifest.IsEmpty()) { |
110 content::RecordAction( | 110 content::RecordAction( |
111 base::UserMetricsAction("webapps.AddShortcut.Manifest")); | 111 base::UserMetricsAction("webapps.AddShortcut.Manifest")); |
112 shortcut_info_.UpdateFromManifest(manifest); | 112 shortcut_info_.UpdateFromManifest(manifest); |
113 } | 113 } |
114 | 114 |
115 GURL icon_src = ManifestIconSelector::FindBestMatchingIcon( | 115 GURL icon_src = ManifestIconSelector::FindBestMatchingIcon( |
116 manifest.icons, | 116 manifest.icons, ideal_icon_size_in_dp_, minimum_icon_size_in_dp_); |
117 ideal_icon_size_in_dp_, | |
118 minimum_icon_size_in_dp_, | |
119 gfx::Screen::GetScreenFor(web_contents()->GetNativeView())); | |
120 | 117 |
121 // If fetching the Manifest icon fails, fallback to the best favicon | 118 // If fetching the Manifest icon fails, fallback to the best favicon |
122 // for the page. | 119 // for the page. |
123 if (!ManifestIconDownloader::Download( | 120 if (!ManifestIconDownloader::Download( |
124 web_contents(), | 121 web_contents(), |
125 icon_src, | 122 icon_src, |
126 ideal_icon_size_in_dp_, | 123 ideal_icon_size_in_dp_, |
127 minimum_icon_size_in_dp_, | 124 minimum_icon_size_in_dp_, |
128 base::Bind(&AddToHomescreenDataFetcher::OnManifestIconFetched, | 125 base::Bind(&AddToHomescreenDataFetcher::OnManifestIconFetched, |
129 this))) { | 126 this))) { |
130 FetchFavicon(); | 127 FetchFavicon(); |
131 } | 128 } |
132 | 129 |
133 // Save the splash screen URL for the later download. | 130 // Save the splash screen URL for the later download. |
134 splash_screen_url_ = ManifestIconSelector::FindBestMatchingIcon( | 131 splash_screen_url_ = ManifestIconSelector::FindBestMatchingIcon( |
135 manifest.icons, | 132 manifest.icons, ideal_splash_image_size_in_dp_, |
136 ideal_splash_image_size_in_dp_, | 133 minimum_splash_image_size_in_dp_); |
137 minimum_splash_image_size_in_dp_, | |
138 gfx::Screen::GetScreenFor(web_contents()->GetNativeView())); | |
139 | 134 |
140 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); | 135 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); |
141 | 136 |
142 // Kick off a timeout for downloading the icon. If an icon isn't set within | 137 // Kick off a timeout for downloading the icon. If an icon isn't set within |
143 // the timeout, fall back to using a dynamically-generated launcher icon. | 138 // the timeout, fall back to using a dynamically-generated launcher icon. |
144 icon_timeout_timer_.Start(FROM_HERE, | 139 icon_timeout_timer_.Start(FROM_HERE, |
145 base::TimeDelta::FromMilliseconds(3000), | 140 base::TimeDelta::FromMilliseconds(3000), |
146 base::Bind( | 141 base::Bind( |
147 &AddToHomescreenDataFetcher::OnFaviconFetched, | 142 &AddToHomescreenDataFetcher::OnFaviconFetched, |
148 this, | 143 this, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 std::vector<int> icon_types; | 185 std::vector<int> icon_types; |
191 icon_types.push_back(favicon_base::FAVICON); | 186 icon_types.push_back(favicon_base::FAVICON); |
192 icon_types.push_back(favicon_base::TOUCH_PRECOMPOSED_ICON | | 187 icon_types.push_back(favicon_base::TOUCH_PRECOMPOSED_ICON | |
193 favicon_base::TOUCH_ICON); | 188 favicon_base::TOUCH_ICON); |
194 favicon::FaviconService* favicon_service = | 189 favicon::FaviconService* favicon_service = |
195 FaviconServiceFactory::GetForProfile(profile, | 190 FaviconServiceFactory::GetForProfile(profile, |
196 ServiceAccessType::EXPLICIT_ACCESS); | 191 ServiceAccessType::EXPLICIT_ACCESS); |
197 | 192 |
198 // Using favicon if its size is not smaller than platform required size, | 193 // Using favicon if its size is not smaller than platform required size, |
199 // otherwise using the largest icon among all avaliable icons. | 194 // otherwise using the largest icon among all avaliable icons. |
200 int ideal_icon_size_in_px = ideal_icon_size_in_dp_ * | 195 int ideal_icon_size_in_px = |
201 gfx::Screen::GetScreenFor(web_contents()->GetNativeView())-> | 196 ideal_icon_size_in_dp_ * |
202 GetPrimaryDisplay().device_scale_factor(); | 197 gfx::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor(); |
203 int threshold_to_get_any_largest_icon = ideal_icon_size_in_px - 1; | 198 int threshold_to_get_any_largest_icon = ideal_icon_size_in_px - 1; |
204 favicon_service->GetLargestRawFaviconForPageURL( | 199 favicon_service->GetLargestRawFaviconForPageURL( |
205 shortcut_info_.url, | 200 shortcut_info_.url, |
206 icon_types, | 201 icon_types, |
207 threshold_to_get_any_largest_icon, | 202 threshold_to_get_any_largest_icon, |
208 base::Bind(&AddToHomescreenDataFetcher::OnFaviconFetched, this), | 203 base::Bind(&AddToHomescreenDataFetcher::OnFaviconFetched, this), |
209 &favicon_task_tracker_); | 204 &favicon_task_tracker_); |
210 } | 205 } |
211 | 206 |
212 void AddToHomescreenDataFetcher::OnFaviconFetched( | 207 void AddToHomescreenDataFetcher::OnFaviconFetched( |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url); | 271 dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url); |
277 | 272 |
278 // If URL points to an offline content, get original URL. | 273 // If URL points to an offline content, get original URL. |
279 GURL online_url = offline_pages::OfflinePageUtils::GetOnlineURLForOfflineURL( | 274 GURL online_url = offline_pages::OfflinePageUtils::GetOnlineURLForOfflineURL( |
280 web_contents()->GetBrowserContext(), original_url); | 275 web_contents()->GetBrowserContext(), original_url); |
281 if (online_url.is_valid()) | 276 if (online_url.is_valid()) |
282 return online_url; | 277 return online_url; |
283 | 278 |
284 return original_url; | 279 return original_url; |
285 } | 280 } |
OLD | NEW |