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 cc11a59bf46ac648cdff950cea631d3c6649dc15..d604b766c6787503e692ba25a4e47ad5ce09f3a7 100644 |
| --- a/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc |
| +++ b/chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc |
| @@ -43,14 +43,22 @@ GURL GetShortcutUrl(content::BrowserContext* browser_context, |
| return dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url); |
| } |
| -InstallableParams ParamsToPerformInstallableCheck(int ideal_icon_size_in_px, |
| - int minimum_icon_size_in_px, |
| - bool check_installable) { |
| +InstallableParams ParamsToPerformInstallableCheck( |
| + int ideal_icon_size_in_px, |
| + int minimum_icon_size_in_px, |
| + bool check_webapk_compatibility, |
|
dominickn
2017/02/02 19:16:50
It's weird to me to see the bool in the middle of
F
2017/02/02 21:05:51
Done.
|
| + int ideal_badge_size_in_px, |
| + int minimum_badge_size_in_px) { |
| InstallableParams params; |
| params.ideal_primary_icon_size_in_px = ideal_icon_size_in_px; |
| params.minimum_primary_icon_size_in_px = minimum_icon_size_in_px; |
| - params.check_installable = check_installable; |
| + params.check_installable = check_webapk_compatibility; |
| params.fetch_valid_primary_icon = true; |
| + if (check_webapk_compatibility) { |
| + params.ideal_badge_icon_size_in_px = ideal_badge_size_in_px; |
| + params.minimum_badge_icon_size_in_px = minimum_badge_size_in_px; |
| + params.fetch_valid_badge_icon = true; |
| + } |
| return params; |
| } |
| @@ -62,6 +70,8 @@ AddToHomescreenDataFetcher::AddToHomescreenDataFetcher( |
| int minimum_icon_size_in_px, |
| int ideal_splash_image_size_in_px, |
| int minimum_splash_image_size_in_px, |
| + int ideal_badge_size_in_px, |
| + int minimum_badge_size_in_px, |
| bool check_webapk_compatibility, |
| Observer* observer) |
| : WebContentsObserver(web_contents), |
| @@ -73,6 +83,8 @@ AddToHomescreenDataFetcher::AddToHomescreenDataFetcher( |
| minimum_icon_size_in_px_(minimum_icon_size_in_px), |
| ideal_splash_image_size_in_px_(ideal_splash_image_size_in_px), |
| minimum_splash_image_size_in_px_(minimum_splash_image_size_in_px), |
| + ideal_badge_size_in_px_(ideal_badge_size_in_px), |
| + minimum_badge_size_in_px_(minimum_badge_size_in_px), |
| check_webapk_compatibility_(check_webapk_compatibility), |
| is_waiting_for_web_application_info_(true), |
| is_installable_check_complete_(false), |
| @@ -80,6 +92,7 @@ AddToHomescreenDataFetcher::AddToHomescreenDataFetcher( |
| is_ready_(false) { |
| DCHECK(minimum_icon_size_in_px <= ideal_icon_size_in_px); |
| DCHECK(minimum_splash_image_size_in_px <= ideal_splash_image_size_in_px); |
| + DCHECK(minimum_badge_size_in_px <= ideal_badge_size_in_px); |
| // Send a message to the renderer to retrieve information about the page. |
| Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); |
| @@ -145,7 +158,9 @@ void AddToHomescreenDataFetcher::OnDidGetWebApplicationInfo( |
| manager->GetData( |
| ParamsToPerformInstallableCheck(ideal_icon_size_in_px_, |
| minimum_icon_size_in_px_, |
| - check_webapk_compatibility_), |
| + check_webapk_compatibility_, |
| + ideal_badge_size_in_px_, |
| + minimum_badge_size_in_px_), |
| base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck, |
| this)); |
| } |
| @@ -181,12 +196,16 @@ void AddToHomescreenDataFetcher::OnDataTimedout() { |
| weak_observer_->OnUserTitleAvailable(base::string16()); |
| } |
| - if (!is_icon_saved_) |
| + if (!is_icon_saved_) { |
| + shortcut_badge_.reset(); |
| CreateLauncherIcon(SkBitmap()); |
| + } |
| } |
| void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck( |
| const InstallableData& data) { |
| + shortcut_badge_.reset(); |
| + |
| if (!web_contents() || !weak_observer_) |
| return; |
| @@ -198,10 +217,17 @@ void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck( |
| AreWebManifestUrlsWebApkCompatible(data.manifest)); |
| weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible); |
| - // WebAPKs are wholly defined by the Web Manifest. Ignore the <meta> tag |
| - // data received in OnDidGetWebApplicationInfo(). |
| - if (webapk_compatible) |
| + if (webapk_compatible) { |
| + // WebAPKs are wholly defined by the Web Manifest. Ignore the <meta> tag |
| + // data received in OnDidGetWebApplicationInfo(). |
| shortcut_info_ = ShortcutInfo(GURL()); |
| + |
| + if (data.badge_icon && !data.badge_icon->drawsNothing()) { |
| + shortcut_info_.best_badge_url = data.badge_icon_url; |
| + |
| + data.badge_icon->deepCopyTo(&shortcut_badge_); |
|
dominickn
2017/02/02 19:16:50
Why does this need to be a deep copy as opposed to
F
2017/02/02 21:05:51
My bad. I wasn't sure of the life span of SkBitmap
dominickn
2017/02/02 21:17:11
We use the copy constructor for the primary icon h
F
2017/02/02 22:30:42
Thanks for the info :)
|
| + } |
| + } |
| } |
| if (!data.manifest.IsEmpty()) { |
| @@ -318,5 +344,6 @@ void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& icon) { |
| is_icon_saved_ = true; |
| shortcut_icon_ = icon; |
| is_ready_ = true; |
| - weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_); |
| + weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_, |
| + shortcut_badge_); |
| } |