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

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

Issue 2669133003: Update AddToHomescreenDataFetcher to accept badge icon for WebAPK. (Closed)
Patch Set: Addressing comments 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 25 matching lines...) Expand all
36 namespace { 36 namespace {
37 37
38 // Looks up the original, online URL of the site requested. The URL from the 38 // Looks up the original, online URL of the site requested. The URL from the
39 // WebContents may be a distilled article which is not appropriate for a home 39 // WebContents may be a distilled article which is not appropriate for a home
40 // screen shortcut. 40 // screen shortcut.
41 GURL GetShortcutUrl(content::BrowserContext* browser_context, 41 GURL GetShortcutUrl(content::BrowserContext* browser_context,
42 const GURL& actual_url) { 42 const GURL& actual_url) {
43 return dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url); 43 return dom_distiller::url_utils::GetOriginalUrlFromDistillerUrl(actual_url);
44 } 44 }
45 45
46 InstallableParams ParamsToPerformInstallableCheck(int ideal_icon_size_in_px, 46 InstallableParams ParamsToPerformInstallableCheck(
47 int minimum_icon_size_in_px, 47 int ideal_icon_size_in_px,
48 bool check_installable) { 48 int minimum_icon_size_in_px,
49 int badge_size_in_px,
50 bool check_webapk_compatibility) {
49 InstallableParams params; 51 InstallableParams params;
50 params.ideal_primary_icon_size_in_px = ideal_icon_size_in_px; 52 params.ideal_primary_icon_size_in_px = ideal_icon_size_in_px;
51 params.minimum_primary_icon_size_in_px = minimum_icon_size_in_px; 53 params.minimum_primary_icon_size_in_px = minimum_icon_size_in_px;
52 params.check_installable = check_installable; 54 params.check_installable = check_webapk_compatibility;
53 params.fetch_valid_primary_icon = true; 55 params.fetch_valid_primary_icon = true;
56 if (check_webapk_compatibility) {
57 params.ideal_badge_icon_size_in_px = badge_size_in_px;
58 params.minimum_badge_icon_size_in_px = badge_size_in_px;
59 params.fetch_valid_badge_icon = true;
60 }
54 return params; 61 return params;
55 } 62 }
56 63
57 } // namespace 64 } // namespace
58 65
59 AddToHomescreenDataFetcher::AddToHomescreenDataFetcher( 66 AddToHomescreenDataFetcher::AddToHomescreenDataFetcher(
60 content::WebContents* web_contents, 67 content::WebContents* web_contents,
61 int ideal_icon_size_in_px, 68 int ideal_icon_size_in_px,
62 int minimum_icon_size_in_px, 69 int minimum_icon_size_in_px,
63 int ideal_splash_image_size_in_px, 70 int ideal_splash_image_size_in_px,
64 int minimum_splash_image_size_in_px, 71 int minimum_splash_image_size_in_px,
72 int badge_size_in_px,
65 bool check_webapk_compatibility, 73 bool check_webapk_compatibility,
66 Observer* observer) 74 Observer* observer)
67 : WebContentsObserver(web_contents), 75 : WebContentsObserver(web_contents),
68 weak_observer_(observer), 76 weak_observer_(observer),
69 shortcut_info_(GetShortcutUrl(web_contents->GetBrowserContext(), 77 shortcut_info_(GetShortcutUrl(web_contents->GetBrowserContext(),
70 web_contents->GetLastCommittedURL())), 78 web_contents->GetLastCommittedURL())),
71 data_timeout_timer_(false, false), 79 data_timeout_timer_(false, false),
72 ideal_icon_size_in_px_(ideal_icon_size_in_px), 80 ideal_icon_size_in_px_(ideal_icon_size_in_px),
73 minimum_icon_size_in_px_(minimum_icon_size_in_px), 81 minimum_icon_size_in_px_(minimum_icon_size_in_px),
74 ideal_splash_image_size_in_px_(ideal_splash_image_size_in_px), 82 ideal_splash_image_size_in_px_(ideal_splash_image_size_in_px),
75 minimum_splash_image_size_in_px_(minimum_splash_image_size_in_px), 83 minimum_splash_image_size_in_px_(minimum_splash_image_size_in_px),
84 badge_size_in_px_(badge_size_in_px),
76 check_webapk_compatibility_(check_webapk_compatibility), 85 check_webapk_compatibility_(check_webapk_compatibility),
77 is_waiting_for_web_application_info_(true), 86 is_waiting_for_web_application_info_(true),
78 is_installable_check_complete_(false), 87 is_installable_check_complete_(false),
79 is_icon_saved_(false), 88 is_icon_saved_(false),
80 is_ready_(false) { 89 is_ready_(false) {
81 DCHECK(minimum_icon_size_in_px <= ideal_icon_size_in_px); 90 DCHECK(minimum_icon_size_in_px <= ideal_icon_size_in_px);
82 DCHECK(minimum_splash_image_size_in_px <= ideal_splash_image_size_in_px); 91 DCHECK(minimum_splash_image_size_in_px <= ideal_splash_image_size_in_px);
83 92
84 // Send a message to the renderer to retrieve information about the page. 93 // Send a message to the renderer to retrieve information about the page.
85 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); 94 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id()));
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 147
139 // Kick off a timeout for downloading data. If we haven't finished within the 148 // Kick off a timeout for downloading data. If we haven't finished within the
140 // timeout, fall back to using a dynamically-generated launcher icon. 149 // timeout, fall back to using a dynamically-generated launcher icon.
141 data_timeout_timer_.Start( 150 data_timeout_timer_.Start(
142 FROM_HERE, base::TimeDelta::FromMilliseconds(4000), 151 FROM_HERE, base::TimeDelta::FromMilliseconds(4000),
143 base::Bind(&AddToHomescreenDataFetcher::OnDataTimedout, this)); 152 base::Bind(&AddToHomescreenDataFetcher::OnDataTimedout, this));
144 153
145 manager->GetData( 154 manager->GetData(
146 ParamsToPerformInstallableCheck(ideal_icon_size_in_px_, 155 ParamsToPerformInstallableCheck(ideal_icon_size_in_px_,
147 minimum_icon_size_in_px_, 156 minimum_icon_size_in_px_,
157 badge_size_in_px_,
148 check_webapk_compatibility_), 158 check_webapk_compatibility_),
149 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck, 159 base::Bind(&AddToHomescreenDataFetcher::OnDidPerformInstallableCheck,
150 this)); 160 this));
151 } 161 }
152 162
153 AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() { 163 AddToHomescreenDataFetcher::~AddToHomescreenDataFetcher() {
154 DCHECK(!weak_observer_); 164 DCHECK(!weak_observer_);
155 } 165 }
156 166
157 bool AddToHomescreenDataFetcher::OnMessageReceived( 167 bool AddToHomescreenDataFetcher::OnMessageReceived(
(...skipping 16 matching lines...) Expand all
174 if (!web_contents() || !weak_observer_) 184 if (!web_contents() || !weak_observer_)
175 return; 185 return;
176 186
177 if (!is_installable_check_complete_) { 187 if (!is_installable_check_complete_) {
178 is_installable_check_complete_ = true; 188 is_installable_check_complete_ = true;
179 if (check_webapk_compatibility_) 189 if (check_webapk_compatibility_)
180 weak_observer_->OnDidDetermineWebApkCompatibility(false); 190 weak_observer_->OnDidDetermineWebApkCompatibility(false);
181 weak_observer_->OnUserTitleAvailable(base::string16()); 191 weak_observer_->OnUserTitleAvailable(base::string16());
182 } 192 }
183 193
184 if (!is_icon_saved_) 194 if (!is_icon_saved_) {
195 badge_icon_.reset();
185 CreateLauncherIcon(SkBitmap()); 196 CreateLauncherIcon(SkBitmap());
197 }
186 } 198 }
187 199
188 void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck( 200 void AddToHomescreenDataFetcher::OnDidPerformInstallableCheck(
189 const InstallableData& data) { 201 const InstallableData& data) {
202 badge_icon_.reset();
203
190 if (!web_contents() || !weak_observer_) 204 if (!web_contents() || !weak_observer_)
191 return; 205 return;
192 206
193 is_installable_check_complete_ = true; 207 is_installable_check_complete_ = true;
194 208
195 if (check_webapk_compatibility_) { 209 if (check_webapk_compatibility_) {
196 bool webapk_compatible = 210 bool webapk_compatible =
197 (data.error_code == NO_ERROR_DETECTED && 211 (data.error_code == NO_ERROR_DETECTED &&
198 AreWebManifestUrlsWebApkCompatible(data.manifest)); 212 AreWebManifestUrlsWebApkCompatible(data.manifest));
199 weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible); 213 weak_observer_->OnDidDetermineWebApkCompatibility(webapk_compatible);
200 214
201 // WebAPKs are wholly defined by the Web Manifest. Ignore the <meta> tag 215 if (webapk_compatible) {
202 // data received in OnDidGetWebApplicationInfo(). 216 // WebAPKs are wholly defined by the Web Manifest. Ignore the <meta> tag
203 if (webapk_compatible) 217 // data received in OnDidGetWebApplicationInfo().
204 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 }
205 } 225 }
206 226
207 if (!data.manifest.IsEmpty()) { 227 if (!data.manifest.IsEmpty()) {
208 content::RecordAction( 228 content::RecordAction(
209 base::UserMetricsAction("webapps.AddShortcut.Manifest")); 229 base::UserMetricsAction("webapps.AddShortcut.Manifest"));
210 shortcut_info_.UpdateFromManifest(data.manifest); 230 shortcut_info_.UpdateFromManifest(data.manifest);
211 shortcut_info_.manifest_url = data.manifest_url; 231 shortcut_info_.manifest_url = data.manifest_url;
212 } 232 }
213 233
214 // Save the splash screen URL for the later download. 234 // Save the splash screen URL for the later download.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 base::Bind( 308 base::Bind(
289 &AddToHomescreenDataFetcher::CreateLauncherIconInBackground, 309 &AddToHomescreenDataFetcher::CreateLauncherIconInBackground,
290 this, raw_icon), 310 this, raw_icon),
291 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 311 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
292 } 312 }
293 313
294 void AddToHomescreenDataFetcher::CreateLauncherIconInBackground( 314 void AddToHomescreenDataFetcher::CreateLauncherIconInBackground(
295 const SkBitmap& raw_icon) { 315 const SkBitmap& raw_icon) {
296 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 316 DCHECK(content::BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
297 317
298 SkBitmap icon; 318 SkBitmap primary_icon;
299 bool is_generated = false; 319 bool is_generated = false;
300 if (weak_observer_) { 320 if (weak_observer_) {
301 icon = weak_observer_->FinalizeLauncherIconInBackground( 321 primary_icon = weak_observer_->FinalizeLauncherIconInBackground(
302 raw_icon, shortcut_info_.url, &is_generated); 322 raw_icon, shortcut_info_.url, &is_generated);
303 } 323 }
304 324
305 if (is_generated) 325 if (is_generated)
306 shortcut_info_.best_icon_url = GURL(); 326 shortcut_info_.best_icon_url = GURL();
307 327
308 content::BrowserThread::PostTask( 328 content::BrowserThread::PostTask(
309 content::BrowserThread::UI, FROM_HERE, 329 content::BrowserThread::UI, FROM_HERE,
310 base::Bind(&AddToHomescreenDataFetcher::NotifyObserver, this, icon)); 330 base::Bind(&AddToHomescreenDataFetcher::NotifyObserver, this,
331 primary_icon));
311 } 332 }
312 333
313 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& icon) { 334 void AddToHomescreenDataFetcher::NotifyObserver(const SkBitmap& primary_icon) {
314 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 335 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
315 if (!web_contents() || !weak_observer_ || is_icon_saved_) 336 if (!web_contents() || !weak_observer_ || is_icon_saved_)
316 return; 337 return;
317 338
318 is_icon_saved_ = true; 339 is_icon_saved_ = true;
319 shortcut_icon_ = icon; 340 primary_icon_ = primary_icon;
320 is_ready_ = true; 341 is_ready_ = true;
321 weak_observer_->OnDataAvailable(shortcut_info_, shortcut_icon_); 342 weak_observer_->OnDataAvailable(shortcut_info_, primary_icon_, badge_icon_);
322 } 343 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698