| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // Simply set the user-editable title to be the page's title | 106 // Simply set the user-editable title to be the page's title |
| 107 shortcut_info_.user_title = web_app_info.title.empty() | 107 shortcut_info_.user_title = web_app_info.title.empty() |
| 108 ? web_contents()->GetTitle() | 108 ? web_contents()->GetTitle() |
| 109 : web_app_info.title; | 109 : web_app_info.title; |
| 110 shortcut_info_.short_name = shortcut_info_.user_title; | 110 shortcut_info_.short_name = shortcut_info_.user_title; |
| 111 shortcut_info_.name = shortcut_info_.user_title; | 111 shortcut_info_.name = shortcut_info_.user_title; |
| 112 | 112 |
| 113 if (web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE || | 113 if (web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE || |
| 114 web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE_APPLE) { | 114 web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE_APPLE) { |
| 115 shortcut_info_.display = blink::WebDisplayModeStandalone; | 115 shortcut_info_.display = blink::WebDisplayModeStandalone; |
| 116 shortcut_info_.UpdateSource( | |
| 117 ShortcutInfo::SOURCE_ADD_TO_HOMESCREEN_STANDALONE); | |
| 118 } | 116 } |
| 119 | 117 |
| 120 // Record what type of shortcut was added by the user. | 118 // Record what type of shortcut was added by the user. |
| 121 switch (web_app_info.mobile_capable) { | 119 switch (web_app_info.mobile_capable) { |
| 122 case WebApplicationInfo::MOBILE_CAPABLE: | 120 case WebApplicationInfo::MOBILE_CAPABLE: |
| 123 content::RecordAction( | 121 content::RecordAction( |
| 124 base::UserMetricsAction("webapps.AddShortcut.AppShortcut")); | 122 base::UserMetricsAction("webapps.AddShortcut.AppShortcut")); |
| 125 break; | 123 break; |
| 126 case WebApplicationInfo::MOBILE_CAPABLE_APPLE: | 124 case WebApplicationInfo::MOBILE_CAPABLE_APPLE: |
| 127 content::RecordAction( | 125 content::RecordAction( |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 CreateLauncherIcon(SkBitmap()); | 185 CreateLauncherIcon(SkBitmap()); |
| 188 } | 186 } |
| 189 | 187 |
| 190 void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck( | 188 void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck( |
| 191 const InstallableData& data) { | 189 const InstallableData& data) { |
| 192 if (!web_contents() || !weak_observer_) | 190 if (!web_contents() || !weak_observer_) |
| 193 return; | 191 return; |
| 194 | 192 |
| 195 is_installable_check_complete_ = true; | 193 is_installable_check_complete_ = true; |
| 196 | 194 |
| 197 bool webapk_compatible = false; | |
| 198 if (check_webapk_compatibility_) { | 195 if (check_webapk_compatibility_) { |
| 199 webapk_compatible = (data.error_code == NO_ERROR_DETECTED && | 196 bool webapk_compatible = |
| 200 AreWebManifestUrlsWebApkCompatible(data.manifest)); | 197 (data.error_code == NO_ERROR_DETECTED && |
| 198 AreWebManifestUrlsWebApkCompatible(data.manifest)); |
| 201 weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible); | 199 weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible); |
| 202 | 200 |
| 203 // WebAPKs are wholly defined by the Web Manifest. Ignore the <meta> tag | 201 // WebAPKs are wholly defined by the Web Manifest. Ignore the <meta> tag |
| 204 // data received in OnDidGetWebApplicationInfo(). | 202 // data received in OnDidGetWebApplicationInfo(). |
| 205 if (webapk_compatible) | 203 if (webapk_compatible) |
| 206 shortcut_info_ = ShortcutInfo(GURL()); | 204 shortcut_info_ = ShortcutInfo(GURL()); |
| 207 } | 205 } |
| 208 | 206 |
| 209 if (!data.manifest.IsEmpty()) { | 207 if (!data.manifest.IsEmpty()) { |
| 210 content::RecordAction( | 208 content::RecordAction( |
| 211 base::UserMetricsAction("webapps.AddShortcut.Manifest")); | 209 base::UserMetricsAction("webapps.AddShortcut.Manifest")); |
| 212 shortcut_info_.UpdateFromManifest(data.manifest); | 210 shortcut_info_.UpdateFromManifest(data.manifest); |
| 213 shortcut_info_.manifest_url = data.manifest_url; | 211 shortcut_info_.manifest_url = data.manifest_url; |
| 214 | |
| 215 if (webapk_compatible) { | |
| 216 shortcut_info_.UpdateSource(ShortcutInfo::SOURCE_ADD_TO_HOMESCREEN_PWA); | |
| 217 | |
| 218 if (data.badge_icon && !data.badge_icon->drawsNothing()) { | |
| 219 shortcut_info_.best_badge_icon_url = data.badge_icon_url; | |
| 220 badge_icon_ = *data.badge_icon; | |
| 221 } | |
| 222 } | |
| 223 } | 212 } |
| 224 | 213 |
| 225 // Save the splash screen URL for the later download. | 214 // Save the splash screen URL for the later download. |
| 226 splash_screen_url_ = ManifestIconSelector::FindBestMatchingIcon( | 215 splash_screen_url_ = ManifestIconSelector::FindBestMatchingIcon( |
| 227 data.manifest.icons, ideal_splash_image_size_in_px_, | 216 data.manifest.icons, ideal_splash_image_size_in_px_, |
| 228 minimum_splash_image_size_in_px_); | 217 minimum_splash_image_size_in_px_); |
| 229 | 218 |
| 230 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); | 219 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); |
| 231 | 220 |
| 232 if (data.primary_icon) { | 221 if (data.primary_icon) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& icon) { | 312 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& icon) { |
| 324 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 313 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 325 if (!web_contents() || !weak_observer_ || is_icon_saved_) | 314 if (!web_contents() || !weak_observer_ || is_icon_saved_) |
| 326 return; | 315 return; |
| 327 | 316 |
| 328 is_icon_saved_ = true; | 317 is_icon_saved_ = true; |
| 329 shortcut_icon_ = icon; | 318 shortcut_icon_ = icon; |
| 330 is_ready_ = true; | 319 is_ready_ = true; |
| 331 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_); | 320 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_); |
| 332 } | 321 } |
| OLD | NEW |