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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // Simply set the user-editable title to be the page's title | 115 // Simply set the user-editable title to be the page's title |
116 shortcut_info_.user_title = web_app_info.title.empty() | 116 shortcut_info_.user_title = web_app_info.title.empty() |
117 ? web_contents()->GetTitle() | 117 ? web_contents()->GetTitle() |
118 : web_app_info.title; | 118 : web_app_info.title; |
119 shortcut_info_.short_name = shortcut_info_.user_title; | 119 shortcut_info_.short_name = shortcut_info_.user_title; |
120 shortcut_info_.name = shortcut_info_.user_title; | 120 shortcut_info_.name = shortcut_info_.user_title; |
121 | 121 |
122 if (web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE || | 122 if (web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE || |
123 web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE_APPLE) { | 123 web_app_info.mobile_capable == WebApplicationInfo::MOBILE_CAPABLE_APPLE) { |
124 shortcut_info_.display = blink::WebDisplayModeStandalone; | 124 shortcut_info_.display = blink::WebDisplayModeStandalone; |
| 125 shortcut_info_.UpdateSource( |
| 126 ShortcutInfo::SOURCE_ADD_TO_HOMESCREEN_STANDALONE); |
125 } | 127 } |
126 | 128 |
127 // Record what type of shortcut was added by the user. | 129 // Record what type of shortcut was added by the user. |
128 switch (web_app_info.mobile_capable) { | 130 switch (web_app_info.mobile_capable) { |
129 case WebApplicationInfo::MOBILE_CAPABLE: | 131 case WebApplicationInfo::MOBILE_CAPABLE: |
130 content::RecordAction( | 132 content::RecordAction( |
131 base::UserMetricsAction("webapps.AddShortcut.AppShortcut")); | 133 base::UserMetricsAction("webapps.AddShortcut.AppShortcut")); |
132 break; | 134 break; |
133 case WebApplicationInfo::MOBILE_CAPABLE_APPLE: | 135 case WebApplicationInfo::MOBILE_CAPABLE_APPLE: |
134 content::RecordAction( | 136 content::RecordAction( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 | 201 |
200 void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck( | 202 void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck( |
201 const InstallableData& data) { | 203 const InstallableData& data) { |
202 badge_icon_.reset(); | 204 badge_icon_.reset(); |
203 | 205 |
204 if (!web_contents() || !weak_observer_) | 206 if (!web_contents() || !weak_observer_) |
205 return; | 207 return; |
206 | 208 |
207 is_installable_check_complete_ = true; | 209 is_installable_check_complete_ = true; |
208 | 210 |
| 211 bool webapk_compatible = false; |
209 if (check_webapk_compatibility_) { | 212 if (check_webapk_compatibility_) { |
210 bool webapk_compatible = | 213 webapk_compatible = (data.error_code == NO_ERROR_DETECTED && |
211 (data.error_code == NO_ERROR_DETECTED && | 214 AreWebManifestUrlsWebApkCompatible(data.manifest)); |
212 AreWebManifestUrlsWebApkCompatible(data.manifest)); | |
213 weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible); | 215 weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible); |
214 | 216 |
215 if (webapk_compatible) { | 217 if (webapk_compatible) { |
216 // WebAPKs are wholly defined by the Web Manifest. Ignore the <meta> tag | 218 // WebAPKs are wholly defined by the Web Manifest. Ignore the <meta> tag |
217 // data received in OnDidGetWebApplicationInfo(). | 219 // data received in OnDidGetWebApplicationInfo(). |
218 shortcut_info_ = ShortcutInfo(GURL()); | 220 shortcut_info_ = ShortcutInfo(GURL()); |
219 | |
220 if (data.badge_icon && !data.badge_icon->drawsNothing()) { | |
221 shortcut_info_.best_badge_icon_url = data.badge_icon_url; | |
222 badge_icon_ = *data.badge_icon; | |
223 } | |
224 } | 221 } |
225 } | 222 } |
226 | 223 |
227 if (!data.manifest.IsEmpty()) { | 224 if (!data.manifest.IsEmpty()) { |
228 content::RecordAction( | 225 content::RecordAction( |
229 base::UserMetricsAction("webapps.AddShortcut.Manifest")); | 226 base::UserMetricsAction("webapps.AddShortcut.Manifest")); |
230 shortcut_info_.UpdateFromManifest(data.manifest); | 227 shortcut_info_.UpdateFromManifest(data.manifest); |
231 shortcut_info_.manifest_url = data.manifest_url; | 228 shortcut_info_.manifest_url = data.manifest_url; |
| 229 |
| 230 if (webapk_compatible) { |
| 231 shortcut_info_.UpdateSource(ShortcutInfo::SOURCE_ADD_TO_HOMESCREEN_PWA); |
| 232 |
| 233 if (data.badge_icon && !data.badge_icon->drawsNothing()) { |
| 234 shortcut_info_.best_badge_icon_url = data.badge_icon_url; |
| 235 badge_icon_ = *data.badge_icon; |
| 236 } |
| 237 } |
232 } | 238 } |
233 | 239 |
234 // Save the splash screen URL for the later download. | 240 // Save the splash screen URL for the later download. |
235 splash_screen_url_ = ManifestIconSelector::FindBestMatchingIcon( | 241 splash_screen_url_ = ManifestIconSelector::FindBestMatchingIcon( |
236 data.manifest.icons, ideal_splash_image_size_in_px_, | 242 data.manifest.icons, ideal_splash_image_size_in_px_, |
237 minimum_splash_image_size_in_px_, | 243 minimum_splash_image_size_in_px_, |
238 content::Manifest::Icon::IconPurpose::ANY); | 244 content::Manifest::Icon::IconPurpose::ANY); |
239 | 245 |
240 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); | 246 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); |
241 | 247 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) { | 338 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) { |
333 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 339 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
334 if (!web_contents() || !weak_observer_ || is_icon_saved_) | 340 if (!web_contents() || !weak_observer_ || is_icon_saved_) |
335 return; | 341 return; |
336 | 342 |
337 is_icon_saved_ = true; | 343 is_icon_saved_ = true; |
338 primary_icon_ = primary_icon; | 344 primary_icon_ = primary_icon; |
339 is_ready_ = true; | 345 is_ready_ = true; |
340 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_); | 346 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_); |
341 } | 347 } |
OLD | NEW |