Chromium Code Reviews| Index: chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc |
| diff --git a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc |
| index e989d277320cc6fa501d9e74346637b49c19d8e9..6a33cd0e0df7bbcddeb4e1fe3a7f581d5494877a 100644 |
| --- a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc |
| +++ b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc |
| @@ -8,6 +8,7 @@ |
| #include "base/location.h" |
| #include "base/strings/string16.h" |
| #include "base/task/cancelable_task_tracker.h" |
| +#include "chrome/browser/android/shortcut_helper.h" |
| #include "chrome/browser/favicon/favicon_service_factory.h" |
| #include "chrome/browser/manifest/manifest_icon_downloader.h" |
| #include "chrome/browser/manifest/manifest_icon_selector.h" |
| @@ -31,12 +32,10 @@ |
| using content::Manifest; |
| -// Android's preferred icon size in DP is 48, as defined in |
| -// http://developer.android.com/design/style/iconography.html |
| -const int AddToHomescreenDataFetcher::kPreferredIconSizeInDp = 48; |
| - |
| AddToHomescreenDataFetcher::AddToHomescreenDataFetcher( |
| content::WebContents* web_contents, |
| + int ideal_icon_size_in_dp, |
| + int ideal_splash_icon_size_in_dp, |
| Observer* observer) |
| : WebContentsObserver(web_contents), |
| weak_observer_(observer), |
| @@ -46,9 +45,8 @@ AddToHomescreenDataFetcher::AddToHomescreenDataFetcher( |
| icon_timeout_timer_(false, false), |
| shortcut_info_(dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl( |
| web_contents->GetURL())), |
| - preferred_icon_size_in_px_(kPreferredIconSizeInDp * |
| - gfx::Screen::GetScreenFor(web_contents->GetNativeView())-> |
| - GetPrimaryDisplay().device_scale_factor()) { |
| + ideal_icon_size_in_dp_(ideal_icon_size_in_dp), |
| + ideal_splash_icon_size_in_dp_(ideal_splash_icon_size_in_dp) { |
| // Send a message to the renderer to retrieve information about the page. |
| is_waiting_for_web_application_info_ = true; |
| Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); |
| @@ -110,7 +108,7 @@ void AddToHomescreenDataFetcher::OnDidGetManifest( |
| GURL icon_src = ManifestIconSelector::FindBestMatchingIcon( |
| manifest.icons, |
| - kPreferredIconSizeInDp, |
| + ideal_icon_size_in_dp_, |
| gfx::Screen::GetScreenFor(web_contents()->GetNativeView())); |
| // If fetching the Manifest icon fails, fallback to the best favicon |
| @@ -118,12 +116,18 @@ void AddToHomescreenDataFetcher::OnDidGetManifest( |
| if (!ManifestIconDownloader::Download( |
| web_contents(), |
| icon_src, |
| - kPreferredIconSizeInDp, |
| + ideal_icon_size_in_dp_, |
| base::Bind(&AddToHomescreenDataFetcher::OnManifestIconFetched, |
| this))) { |
| FetchFavicon(); |
| } |
| + // Save the splashscreen URL for the later download. |
| + splashscreen_url_ = ManifestIconSelector::FindBestMatchingIcon( |
| + manifest.icons, |
| + ideal_splash_icon_size_in_dp_, |
| + gfx::Screen::GetScreenFor(web_contents()->GetNativeView())); |
| + |
| weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); |
| // Kick off a timeout for downloading the icon. If an icon isn't set within |
| @@ -155,6 +159,19 @@ AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() { |
| DCHECK(!weak_observer_); |
| } |
| +void AddToHomescreenDataFetcher::FetchSplashscreenIcon( |
| + const std::string& webapp_id) { |
| + // This is a fire and forget task. It is not vital for the splashscreen icon |
| + // to be downloaded so the result of the download is not checked and neither |
| + // is there any fallback option. |
|
gone
2015/08/26 02:01:19
Same comment as above, since you just seem to have
Lalit Maganti
2015/08/26 13:11:56
Put into shortcut helper and fixed the comment.
|
| + ManifestIconDownloader::Download( |
| + web_contents(), |
| + splashscreen_url_, |
| + ideal_splash_icon_size_in_dp_, |
| + base::Bind(&ShortcutHelper::AddSplashscreenIconToWebappData, |
| + webapp_id)); |
| +} |
| + |
| void AddToHomescreenDataFetcher::FetchFavicon() { |
| if (!web_contents() || !weak_observer_) return; |
| @@ -174,7 +191,10 @@ void AddToHomescreenDataFetcher::FetchFavicon() { |
| // Using favicon if its size is not smaller than platform required size, |
| // otherwise using the largest icon among all avaliable icons. |
| - int threshold_to_get_any_largest_icon = preferred_icon_size_in_px_ - 1; |
| + int ideal_icon_size_in_px = ideal_icon_size_in_dp_ * |
| + gfx::Screen::GetScreenFor(web_contents()->GetNativeView())-> |
| + GetPrimaryDisplay().device_scale_factor(); |
| + int threshold_to_get_any_largest_icon = ideal_icon_size_in_px - 1; |
| favicon_service->GetLargestRawFaviconForPageURL( |
| shortcut_info_.url, |
| icon_types, |