Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: chrome/browser/android/webapps/add_to_homescreen_data_fetcher.cc

Issue 2675803004: Fall back to shortcut A2HS when Phonesky is out of date or unavailable. (Closed)
Patch Set: Update add_to_homescreen_data_fetcher_unittest.cc. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } // namespace 64 } // namespace
65 65
66 AddToHomescreenDataFetcher::AddToHomescreenDataFetcher( 66 AddToHomescreenDataFetcher::AddToHomescreenDataFetcher(
67 content::WebContents* web_contents, 67 content::WebContents* web_contents,
68 int ideal_icon_size_in_px, 68 int ideal_icon_size_in_px,
69 int minimum_icon_size_in_px, 69 int minimum_icon_size_in_px,
70 int ideal_splash_image_size_in_px, 70 int ideal_splash_image_size_in_px,
71 int minimum_splash_image_size_in_px, 71 int minimum_splash_image_size_in_px,
72 int badge_size_in_px, 72 int badge_size_in_px,
73 bool check_webapk_compatibility, 73 bool check_webapk_compatibility,
74 bool can_use_webapk_install_flow,
74 Observer* observer) 75 Observer* observer)
75 : WebContentsObserver(web_contents), 76 : WebContentsObserver(web_contents),
76 weak_observer_(observer), 77 weak_observer_(observer),
77 shortcut_info_(GetShortcutUrl(web_contents->GetBrowserContext(), 78 shortcut_info_(GetShortcutUrl(web_contents->GetBrowserContext(),
78 web_contents->GetLastCommittedURL())), 79 web_contents->GetLastCommittedURL())),
79 data_timeout_timer_(false, false), 80 data_timeout_timer_(false, false),
80 ideal_icon_size_in_px_(ideal_icon_size_in_px), 81 ideal_icon_size_in_px_(ideal_icon_size_in_px),
81 minimum_icon_size_in_px_(minimum_icon_size_in_px), 82 minimum_icon_size_in_px_(minimum_icon_size_in_px),
82 ideal_splash_image_size_in_px_(ideal_splash_image_size_in_px), 83 ideal_splash_image_size_in_px_(ideal_splash_image_size_in_px),
83 minimum_splash_image_size_in_px_(minimum_splash_image_size_in_px), 84 minimum_splash_image_size_in_px_(minimum_splash_image_size_in_px),
84 badge_size_in_px_(badge_size_in_px), 85 badge_size_in_px_(badge_size_in_px),
85 check_webapk_compatibility_(check_webapk_compatibility), 86 check_webapk_compatibility_(check_webapk_compatibility),
86 is_waiting_for_web_application_info_(true), 87 is_waiting_for_web_application_info_(true),
87 is_installable_check_complete_(false), 88 is_installable_check_complete_(false),
88 is_icon_saved_(false), 89 is_icon_saved_(false),
89 is_ready_(false) { 90 is_ready_(false),
91 can_use_webapk_install_flow_(can_use_webapk_install_flow) {
90 DCHECK(minimum_icon_size_in_px <= ideal_icon_size_in_px); 92 DCHECK(minimum_icon_size_in_px <= ideal_icon_size_in_px);
91 DCHECK(minimum_splash_image_size_in_px <= ideal_splash_image_size_in_px); 93 DCHECK(minimum_splash_image_size_in_px <= ideal_splash_image_size_in_px);
92 94
93 // Send a message to the renderer to retrieve information about the page. 95 // Send a message to the renderer to retrieve information about the page.
94 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); 96 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id()));
95 } 97 }
96 98
97 base::Closure AddToHomescreenDataFetcher::FetchSplashScreenImageCallback( 99 base::Closure AddToHomescreenDataFetcher::FetchSplashScreenImageCallback(
98 const std::string& webapp_id) { 100 const std::string& webapp_id) {
99 return base::Bind(&ShortcutHelper::FetchSplashScreenImage, web_contents(), 101 return base::Bind(&ShortcutHelper::FetchSplashScreenImage, web_contents(),
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 =
211 (data.error_code == NO_ERROR_DETECTED && 214 (data.error_code == NO_ERROR_DETECTED &&
212 AreWebManifestUrlsWebApkCompatible(data.manifest)); 215 AreWebManifestUrlsWebApkCompatible(data.manifest));
216
217 if (webapk_compatible) {
218 std::string webapk_package_name = ShortcutHelper::QueryWebApkPackage(
219 data.manifest.start_url);
220 // We will continue the WebAPK install flow if:
221 // The WebAPK has been installed, or
222 // The WebAPK install flow can be used.
223 // Otherwises, we will continue the classic add-to-homescreen shortcut
224 // flow.
225 if (webapk_package_name.empty() && !can_use_webapk_install_flow_)
226 webapk_compatible = false;
227 }
213 weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible); 228 weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible);
214 229
215 if (webapk_compatible) { 230 if (webapk_compatible) {
216 // WebAPKs are wholly defined by the Web Manifest. Ignore the <meta> tag 231 // WebAPKs are wholly defined by the Web Manifest. Ignore the <meta> tag
217 // data received in OnDidGetWebApplicationInfo(). 232 // data received in OnDidGetWebApplicationInfo().
218 shortcut_info_ = ShortcutInfo(GURL()); 233 shortcut_info_ = ShortcutInfo(GURL());
219 234
220 if (data.badge_icon && !data.badge_icon->drawsNothing()) { 235 if (data.badge_icon && !data.badge_icon->drawsNothing()) {
221 shortcut_info_.best_badge_icon_url = data.badge_icon_url; 236 shortcut_info_.best_badge_icon_url = data.badge_icon_url;
222 badge_icon_ = *data.badge_icon; 237 badge_icon_ = *data.badge_icon;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) { 349 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) {
335 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 350 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
336 if (!web_contents() || !weak_observer_ || is_icon_saved_) 351 if (!web_contents() || !weak_observer_ || is_icon_saved_)
337 return; 352 return;
338 353
339 is_icon_saved_ = true; 354 is_icon_saved_ = true;
340 primary_icon_ = primary_icon; 355 primary_icon_ = primary_icon;
341 is_ready_ = true; 356 is_ready_ = true;
342 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_); 357 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_);
343 } 358 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698