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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 | 114 |
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; |
pkotwicz
2017/02/14 19:47:11
Nit: Can you please set the source explicitly here
dominickn
2017/02/14 23:02:14
Good catch, done.
| |
125 } | 125 } |
126 | 126 |
127 // Record what type of shortcut was added by the user. | 127 // Record what type of shortcut was added by the user. |
128 switch (web_app_info.mobile_capable) { | 128 switch (web_app_info.mobile_capable) { |
129 case WebApplicationInfo::MOBILE_CAPABLE: | 129 case WebApplicationInfo::MOBILE_CAPABLE: |
130 content::RecordAction( | 130 content::RecordAction( |
131 base::UserMetricsAction("webapps.AddShortcut.AppShortcut")); | 131 base::UserMetricsAction("webapps.AddShortcut.AppShortcut")); |
132 break; | 132 break; |
133 case WebApplicationInfo::MOBILE_CAPABLE_APPLE: | 133 case WebApplicationInfo::MOBILE_CAPABLE_APPLE: |
134 content::RecordAction( | 134 content::RecordAction( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 | 199 |
200 void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck( | 200 void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck( |
201 const InstallableData& data) { | 201 const InstallableData& data) { |
202 badge_icon_.reset(); | 202 badge_icon_.reset(); |
203 | 203 |
204 if (!web_contents() || !weak_observer_) | 204 if (!web_contents() || !weak_observer_) |
205 return; | 205 return; |
206 | 206 |
207 is_installable_check_complete_ = true; | 207 is_installable_check_complete_ = true; |
208 | 208 |
209 bool webapk_compatible = false; | |
209 if (check_webapk_compatibility_) { | 210 if (check_webapk_compatibility_) { |
210 bool webapk_compatible = | 211 webapk_compatible = (data.error_code == NO_ERROR_DETECTED && |
211 (data.error_code == NO_ERROR_DETECTED && | 212 AreWebManifestUrlsWebApkCompatible(data.manifest)); |
212 AreWebManifestUrlsWebApkCompatible(data.manifest)); | |
213 weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible); | 213 weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible); |
214 | 214 |
215 if (webapk_compatible) { | 215 if (webapk_compatible) { |
216 // WebAPKs are wholly defined by the Web Manifest. Ignore the <meta> tag | 216 // WebAPKs are wholly defined by the Web Manifest. Ignore the <meta> tag |
217 // data received in OnDidGetWebApplicationInfo(). | 217 // data received in OnDidGetWebApplicationInfo(). |
218 shortcut_info_ = ShortcutInfo(GURL()); | 218 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 } | 219 } |
225 } | 220 } |
226 | 221 |
227 if (!data.manifest.IsEmpty()) { | 222 if (!data.manifest.IsEmpty()) { |
228 content::RecordAction( | 223 content::RecordAction( |
229 base::UserMetricsAction("webapps.AddShortcut.Manifest")); | 224 base::UserMetricsAction("webapps.AddShortcut.Manifest")); |
230 shortcut_info_.UpdateFromManifest(data.manifest); | 225 shortcut_info_.UpdateFromManifest(data.manifest); |
231 shortcut_info_.manifest_url = data.manifest_url; | 226 shortcut_info_.manifest_url = data.manifest_url; |
227 | |
228 if (webapk_compatible) { | |
229 shortcut_info_.UpdateSource(ShortcutInfo::SOURCE_ADD_TO_HOMESCREEN_PWA); | |
230 | |
231 if (data.badge_icon && !data.badge_icon->drawsNothing()) { | |
232 shortcut_info_.best_badge_icon_url = data.badge_icon_url; | |
233 badge_icon_ = *data.badge_icon; | |
234 } | |
235 } | |
232 } | 236 } |
233 | 237 |
234 // Save the splash screen URL for the later download. | 238 // Save the splash screen URL for the later download. |
235 splash_screen_url_ = ManifestIconSelector::FindBestMatchingIcon( | 239 splash_screen_url_ = ManifestIconSelector::FindBestMatchingIcon( |
236 data.manifest.icons, ideal_splash_image_size_in_px_, | 240 data.manifest.icons, ideal_splash_image_size_in_px_, |
237 minimum_splash_image_size_in_px_, | 241 minimum_splash_image_size_in_px_, |
238 content::Manifest::Icon::IconPurpose::ANY); | 242 content::Manifest::Icon::IconPurpose::ANY); |
239 | 243 |
240 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); | 244 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); |
241 | 245 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
332 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) { | 336 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) { |
333 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 337 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
334 if (!web_contents() || !weak_observer_ || is_icon_saved_) | 338 if (!web_contents() || !weak_observer_ || is_icon_saved_) |
335 return; | 339 return; |
336 | 340 |
337 is_icon_saved_ = true; | 341 is_icon_saved_ = true; |
338 primary_icon_ = primary_icon; | 342 primary_icon_ = primary_icon; |
339 is_ready_ = true; | 343 is_ready_ = true; |
340 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_); | 344 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_); |
341 } | 345 } |
OLD | NEW |