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

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

Issue 2949993002: Don't ignore manifest icons for sites that don't have a service worker. (Closed)
Patch Set: Created 3 years, 6 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/location.h" 10 #include "base/location.h"
(...skipping 29 matching lines...) Expand all
40 const int kDataTimeoutInMilliseconds = 4000; 40 const int kDataTimeoutInMilliseconds = 4000;
41 41
42 // Looks up the original, online URL of the site requested. The URL from the 42 // Looks up the original, online URL of the site requested. The URL from the
43 // WebContents may be a distilled article which is not appropriate for a home 43 // WebContents may be a distilled article which is not appropriate for a home
44 // screen shortcut. 44 // screen shortcut.
45 GURL GetShortcutUrl(content::BrowserContext* browser_context, 45 GURL GetShortcutUrl(content::BrowserContext* browser_context,
46 const GURL& actual_url) { 46 const GURL& actual_url) {
47 return dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url); 47 return dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url);
48 } 48 }
49 49
50 InstallableParams ParamsToPerformManifestAndIconFetch(
51 int ideal_icon_size_in_px,
52 int minimum_icon_size_in_px) {
53 InstallableParams params;
54 params.ideal_primary_icon_size_in_px = ideal_icon_size_in_px;
55 params.minimum_primary_icon_size_in_px = minimum_icon_size_in_px;
56 params.fetch_valid_primary_icon = true;
57 return params;
58 }
59
50 InstallableParams ParamsToPerformInstallableCheck( 60 InstallableParams ParamsToPerformInstallableCheck(
51 int ideal_icon_size_in_px, 61 int ideal_icon_size_in_px,
52 int minimum_icon_size_in_px, 62 int minimum_icon_size_in_px,
53 int badge_size_in_px, 63 int badge_size_in_px,
54 bool check_webapk_compatibility) { 64 bool check_webapk_compatibility) {
55 InstallableParams params; 65 InstallableParams params = ParamsToPerformManifestAndIconFetch(
56 params.ideal_primary_icon_size_in_px = ideal_icon_size_in_px; 66 ideal_icon_size_in_px, minimum_icon_size_in_px);
57 params.minimum_primary_icon_size_in_px = minimum_icon_size_in_px;
58 params.check_installable = check_webapk_compatibility;
59 params.fetch_valid_primary_icon = true;
60 if (check_webapk_compatibility) { 67 if (check_webapk_compatibility) {
68 params.check_installable = check_webapk_compatibility;
61 params.ideal_badge_icon_size_in_px = badge_size_in_px; 69 params.ideal_badge_icon_size_in_px = badge_size_in_px;
62 params.minimum_badge_icon_size_in_px = badge_size_in_px; 70 params.minimum_badge_icon_size_in_px = badge_size_in_px;
63 params.fetch_valid_badge_icon = true; 71 params.fetch_valid_badge_icon = true;
64 } 72 }
65 return params; 73 return params;
66 } 74 }
67 75
68 } // namespace 76 } // namespace
69 77
70 AddToHomescreenDataFetcher::AddToHomescreenDataFetcher( 78 AddToHomescreenDataFetcher::AddToHomescreenDataFetcher(
71 content::WebContents* web_contents, 79 content::WebContents* web_contents,
72 int ideal_icon_size_in_px, 80 int ideal_icon_size_in_px,
73 int minimum_icon_size_in_px, 81 int minimum_icon_size_in_px,
74 int ideal_splash_image_size_in_px, 82 int ideal_splash_image_size_in_px,
75 int minimum_splash_image_size_in_px, 83 int minimum_splash_image_size_in_px,
76 int badge_size_in_px, 84 int badge_size_in_px,
77 bool check_webapk_compatibility, 85 bool check_webapk_compatibility,
78 Observer* observer) 86 Observer* observer)
79 : WebContentsObserver(web_contents), 87 : WebContentsObserver(web_contents),
80 background_task_runner_( 88 background_task_runner_(
81 content::BrowserThread::GetBlockingPool() 89 content::BrowserThread::GetBlockingPool()
82 ->GetTaskRunnerWithShutdownBehavior( 90 ->GetTaskRunnerWithShutdownBehavior(
83 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)), 91 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN)),
92 installable_manager_(InstallableManager::FromWebContents(web_contents)),
84 weak_observer_(observer), 93 weak_observer_(observer),
85 shortcut_info_(GetShortcutUrl(web_contents->GetBrowserContext(), 94 shortcut_info_(GetShortcutUrl(web_contents->GetBrowserContext(),
86 web_contents->GetLastCommittedURL())), 95 web_contents->GetLastCommittedURL())),
87 ideal_icon_size_in_px_(ideal_icon_size_in_px), 96 ideal_icon_size_in_px_(ideal_icon_size_in_px),
88 minimum_icon_size_in_px_(minimum_icon_size_in_px), 97 minimum_icon_size_in_px_(minimum_icon_size_in_px),
89 ideal_splash_image_size_in_px_(ideal_splash_image_size_in_px), 98 ideal_splash_image_size_in_px_(ideal_splash_image_size_in_px),
90 minimum_splash_image_size_in_px_(minimum_splash_image_size_in_px), 99 minimum_splash_image_size_in_px_(minimum_splash_image_size_in_px),
91 badge_size_in_px_(badge_size_in_px), 100 badge_size_in_px_(badge_size_in_px),
92 check_webapk_compatibility_(check_webapk_compatibility), 101 check_webapk_compatibility_(check_webapk_compatibility),
93 is_waiting_for_web_application_info_(true), 102 is_waiting_for_web_application_info_(true),
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 case WebApplicationInfo::MOBILE_CAPABLE_APPLE: 143 case WebApplicationInfo::MOBILE_CAPABLE_APPLE:
135 base::RecordAction( 144 base::RecordAction(
136 base::UserMetricsAction("webapps.AddShortcut.AppShortcutApple")); 145 base::UserMetricsAction("webapps.AddShortcut.AppShortcutApple"));
137 break; 146 break;
138 case WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED: 147 case WebApplicationInfo::MOBILE_CAPABLE_UNSPECIFIED:
139 base::RecordAction( 148 base::RecordAction(
140 base::UserMetricsAction("webapps.AddShortcut.Bookmark")); 149 base::UserMetricsAction("webapps.AddShortcut.Bookmark"));
141 break; 150 break;
142 } 151 }
143 152
144 InstallableManager::CreateForWebContents(web_contents());
145 InstallableManager* manager =
146 InstallableManager::FromWebContents(web_contents());
147 DCHECK(manager);
148
149 // Kick off a timeout for downloading data. If we haven't finished within the 153 // Kick off a timeout for downloading data. If we haven't finished within the
150 // timeout, fall back to using a dynamically-generated launcher icon. 154 // timeout, fall back to using a dynamically-generated launcher icon.
151 data_timeout_timer_.Start( 155 data_timeout_timer_.Start(
152 FROM_HERE, base::TimeDelta::FromMilliseconds(kDataTimeoutInMilliseconds), 156 FROM_HERE, base::TimeDelta::FromMilliseconds(kDataTimeoutInMilliseconds),
153 base::Bind(&AddToHomescreenDataFetcher::OnDataTimedout, this)); 157 base::Bind(&AddToHomescreenDataFetcher::OnDataTimedout, this));
154 158
155 manager->GetData( 159 installable_manager_->GetData(
156 ParamsToPerformInstallableCheck(ideal_icon_size_in_px_, 160 ParamsToPerformManifestAndIconFetch(ideal_icon_size_in_px_,
157 minimum_icon_size_in_px_, 161 minimum_icon_size_in_px_),
158 badge_size_in_px_, 162 base::Bind(&AddToHomescreenDataFetcher::OnDidGetManifestAndIcon, this));
159 check_webapk_compatibility_),
160 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck,
161 this));
162 } 163 }
163 164
164 AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() { 165 AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() {
165 DCHECK(!weak_observer_); 166 DCHECK(!weak_observer_);
166 } 167 }
167 168
168 bool AddToHomescreenDataFetcher::OnMessageReceived( 169 bool AddToHomescreenDataFetcher::OnMessageReceived(
169 const IPC::Message& message) { 170 const IPC::Message& message) {
170 if (!is_waiting_for_web_application_info_) 171 if (!is_waiting_for_web_application_info_)
171 return false; 172 return false;
(...skipping 17 matching lines...) Expand all
189 is_installable_check_complete_ = true; 190 is_installable_check_complete_ = true;
190 if (check_webapk_compatibility_) 191 if (check_webapk_compatibility_)
191 weak_observer_->OnDidDetermineWebApkCompatibility(false); 192 weak_observer_->OnDidDetermineWebApkCompatibility(false);
192 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title); 193 weak_observer_->OnUserTitleAvailable(shortcut_info_.user_title);
193 } 194 }
194 195
195 badge_icon_.reset(); 196 badge_icon_.reset();
196 CreateLauncherIcon(SkBitmap()); 197 CreateLauncherIcon(SkBitmap());
197 } 198 }
198 199
200 void AddToHomescreenDataFetcher::OnDidGetManifestAndIcon(
201 const InstallableData& data) {
202 if (!web_contents() || !weak_observer_ || is_installable_check_complete_)
203 return;
204
205 if (!data.manifest.IsEmpty()) {
206 base::RecordAction(base::UserMetricsAction("webapps.AddShortcut.Manifest"));
207 shortcut_info_.UpdateFromManifest(data.manifest);
208 shortcut_info_.manifest_url = data.manifest_url;
209 }
210
211 installable_manager_->GetData(
212 ParamsToPerformInstallableCheck(
213 ideal_icon_size_in_px_, minimum_icon_size_in_px_, badge_size_in_px_,
214 check_webapk_compatibility_),
215 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck,
216 this));
217 }
218
199 void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck( 219 void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck(
200 const InstallableData& data) { 220 const InstallableData& data) {
201 data_timeout_timer_.Stop(); 221 data_timeout_timer_.Stop();
202 badge_icon_.reset(); 222 badge_icon_.reset();
203 223
204 if (!web_contents() || !weak_observer_ || is_installable_check_complete_) 224 if (!web_contents() || !weak_observer_ || is_installable_check_complete_)
205 return; 225 return;
206 226
207 is_installable_check_complete_ = true; 227 is_installable_check_complete_ = true;
208 228
209 bool webapk_compatible = false; 229 bool webapk_compatible = false;
210 if (check_webapk_compatibility_) { 230 if (check_webapk_compatibility_) {
211 webapk_compatible = (data.error_code == NO_ERROR_DETECTED && 231 webapk_compatible = (data.error_code == NO_ERROR_DETECTED &&
212 AreWebManifestUrlsWebApkCompatible(data.manifest)); 232 AreWebManifestUrlsWebApkCompatible(data.manifest));
213 weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible); 233 weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible);
234 }
214 235
215 if (webapk_compatible) { 236 if (webapk_compatible) {
216 // WebAPKs are wholly defined by the Web Manifest. Ignore the <meta> tag 237 shortcut_info_.UpdateSource(ShortcutInfo::SOURCE_ADD_TO_HOMESCREEN_PWA);
dominickn 2017/06/21 01:18:04 I thought about this for a while and I don't think
217 // data received in OnDidGetWebApplicationInfo(). 238
218 shortcut_info_ = ShortcutInfo(GURL()); 239 if (data.badge_icon && !data.badge_icon->drawsNothing()) {
240 shortcut_info_.best_badge_icon_url = data.badge_icon_url;
241 badge_icon_ = *data.badge_icon;
219 } 242 }
220 } 243 }
221 244
222 if (!data.manifest.IsEmpty()) {
223 base::RecordAction(base::UserMetricsAction("webapps.AddShortcut.Manifest"));
224 shortcut_info_.UpdateFromManifest(data.manifest);
225 shortcut_info_.manifest_url = data.manifest_url;
226
227 if (webapk_compatible) {
228 shortcut_info_.UpdateSource(ShortcutInfo::SOURCE_ADD_TO_HOMESCREEN_PWA);
229
230 if (data.badge_icon && !data.badge_icon->drawsNothing()) {
231 shortcut_info_.best_badge_icon_url = data.badge_icon_url;
232 badge_icon_ = *data.badge_icon;
233 }
234 }
235 }
236
237 // Save the splash screen URL for the later download. 245 // Save the splash screen URL for the later download.
238 shortcut_info_.splash_image_url = 246 shortcut_info_.splash_image_url =
239 content::ManifestIconSelector::FindBestMatchingIcon( 247 content::ManifestIconSelector::FindBestMatchingIcon(
240 data.manifest.icons, ideal_splash_image_size_in_px_, 248 data.manifest.icons, ideal_splash_image_size_in_px_,
241 minimum_splash_image_size_in_px_, 249 minimum_splash_image_size_in_px_,
242 content::Manifest::Icon::IconPurpose::ANY); 250 content::Manifest::Icon::IconPurpose::ANY);
243 shortcut_info_.ideal_splash_image_size_in_px = ideal_splash_image_size_in_px_; 251 shortcut_info_.ideal_splash_image_size_in_px = ideal_splash_image_size_in_px_;
244 shortcut_info_.minimum_splash_image_size_in_px = 252 shortcut_info_.minimum_splash_image_size_in_px =
245 minimum_splash_image_size_in_px_; 253 minimum_splash_image_size_in_px_;
246 254
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 349
342 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) { 350 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) {
343 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 351 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
344 if (!web_contents() || !weak_observer_ || is_icon_saved_) 352 if (!web_contents() || !weak_observer_ || is_icon_saved_)
345 return; 353 return;
346 354
347 is_icon_saved_ = true; 355 is_icon_saved_ = true;
348 primary_icon_ = primary_icon; 356 primary_icon_ = primary_icon;
349 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_); 357 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_);
350 } 358 }
OLDNEW
« no previous file with comments | « chrome/browser/android/webapps/add_to_homescreen_data_fetcher.h ('k') | chrome/browser/ui/tab_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698