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

Side by Side Diff: chrome/browser/banners/app_banner_data_fetcher.cc

Issue 2064943002: Pass in extra parameters to WebApkBuilder#buildWebApkAsync() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'master' into webapk_manifest000 Created 4 years, 5 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/banners/app_banner_data_fetcher.h" 5 #include "chrome/browser/banners/app_banner_data_fetcher.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 return; 195 return;
196 } 196 }
197 197
198 AppBannerSettingsHelper::RecordMinutesFromFirstVisitToShow( 198 AppBannerSettingsHelper::RecordMinutesFromFirstVisitToShow(
199 web_contents, validated_url_, GetAppIdentifier(), GetCurrentTime()); 199 web_contents, validated_url_, GetAppIdentifier(), GetCurrentTime());
200 200
201 // Definitely going to show the banner now. 201 // Definitely going to show the banner now.
202 FOR_EACH_OBSERVER(Observer, observer_list_, 202 FOR_EACH_OBSERVER(Observer, observer_list_,
203 OnDecidedWhetherToShow(this, true)); 203 OnDecidedWhetherToShow(this, true));
204 204
205 ShowBanner(app_icon_.get(), app_title_, referrer); 205 ShowBanner(app_icon_url_, app_icon_.get(), app_title_, referrer);
206 is_active_ = false; 206 is_active_ = false;
207 } 207 }
208 208
209 void AppBannerDataFetcher::OnRequestShowAppBanner( 209 void AppBannerDataFetcher::OnRequestShowAppBanner(
210 content::RenderFrameHost* render_frame_host, 210 content::RenderFrameHost* render_frame_host,
211 int request_id) { 211 int request_id) {
212 if (was_canceled_by_page_) { 212 if (was_canceled_by_page_) {
213 // Simulate an "OK" from the website to restart the banner display pipeline. 213 // Simulate an "OK" from the website to restart the banner display pipeline.
214 was_canceled_by_page_ = false; 214 was_canceled_by_page_ = false;
215 OnBannerPromptReply(render_frame_host, request_id, 215 OnBannerPromptReply(render_frame_host, request_id,
(...skipping 12 matching lines...) Expand all
228 return "web"; 228 return "web";
229 } 229 }
230 230
231 content::WebContents* AppBannerDataFetcher::GetWebContents() { 231 content::WebContents* AppBannerDataFetcher::GetWebContents() {
232 if (!web_contents() || web_contents()->IsBeingDestroyed()) 232 if (!web_contents() || web_contents()->IsBeingDestroyed())
233 return nullptr; 233 return nullptr;
234 return web_contents(); 234 return web_contents();
235 } 235 }
236 236
237 std::string AppBannerDataFetcher::GetAppIdentifier() { 237 std::string AppBannerDataFetcher::GetAppIdentifier() {
238 DCHECK(!web_app_data_.IsEmpty()); 238 DCHECK(!manifest_.IsEmpty());
239 return web_app_data_.start_url.spec(); 239 return manifest_.start_url.spec();
240 } 240 }
241 241
242 void AppBannerDataFetcher::RecordDidShowBanner(const std::string& event_name) { 242 void AppBannerDataFetcher::RecordDidShowBanner(const std::string& event_name) {
243 content::WebContents* web_contents = GetWebContents(); 243 content::WebContents* web_contents = GetWebContents();
244 DCHECK(web_contents); 244 DCHECK(web_contents);
245 245
246 AppBannerSettingsHelper::RecordBannerEvent( 246 AppBannerSettingsHelper::RecordBannerEvent(
247 web_contents, validated_url_, GetAppIdentifier(), 247 web_contents, validated_url_, GetAppIdentifier(),
248 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW, 248 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_SHOW,
249 GetCurrentTime()); 249 GetCurrentTime());
(...skipping 11 matching lines...) Expand all
261 261
262 Cancel(); 262 Cancel();
263 return; 263 return;
264 } 264 }
265 265
266 web_contents->GetManifest( 266 web_contents->GetManifest(
267 base::Bind(&AppBannerDataFetcher::OnDidGetManifest, this)); 267 base::Bind(&AppBannerDataFetcher::OnDidGetManifest, this));
268 } 268 }
269 269
270 void AppBannerDataFetcher::OnDidGetManifest( 270 void AppBannerDataFetcher::OnDidGetManifest(
271 const GURL& manifest_url,
271 const content::Manifest& manifest) { 272 const content::Manifest& manifest) {
272 content::WebContents* web_contents = GetWebContents(); 273 content::WebContents* web_contents = GetWebContents();
273 if (!CheckFetcherIsStillAlive(web_contents)) { 274 if (!CheckFetcherIsStillAlive(web_contents)) {
274 Cancel(); 275 Cancel();
275 return; 276 return;
276 } 277 }
277 if (manifest.IsEmpty()) { 278 if (manifest.IsEmpty()) {
278 OutputDeveloperNotShownMessage(web_contents, kManifestEmpty, 279 OutputDeveloperNotShownMessage(web_contents, kManifestEmpty,
279 is_debug_mode_); 280 is_debug_mode_);
280 Cancel(); 281 Cancel();
(...skipping 11 matching lines...) Expand all
292 } 293 }
293 } 294 }
294 295
295 if (!IsManifestValidForWebApp(manifest, web_contents, is_debug_mode_)) { 296 if (!IsManifestValidForWebApp(manifest, web_contents, is_debug_mode_)) {
296 Cancel(); 297 Cancel();
297 return; 298 return;
298 } 299 }
299 300
300 // Since the manifest is valid, one of short name or name must be non-null. 301 // Since the manifest is valid, one of short name or name must be non-null.
301 // Prefer name if it isn't null. 302 // Prefer name if it isn't null.
302 web_app_data_ = manifest; 303 manifest_url_ = manifest_url;
303 app_title_ = (web_app_data_.name.is_null()) 304 manifest_ = manifest;
304 ? web_app_data_.short_name.string() 305 app_title_ = (manifest_.name.is_null()) ? manifest_.short_name.string()
305 : web_app_data_.name.string(); 306 : manifest_.name.string();
306 307
307 if (IsWebAppInstalled(web_contents->GetBrowserContext(), 308 if (IsWebAppInstalled(web_contents->GetBrowserContext(),
308 manifest.start_url) && 309 manifest.start_url) &&
309 !is_debug_mode_) { 310 !is_debug_mode_) {
310 Cancel(); 311 Cancel();
311 return; 312 return;
312 } 313 }
313 314
314 banners::TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_REQUESTED); 315 banners::TrackDisplayEvent(DISPLAY_EVENT_WEB_APP_BANNER_REQUESTED);
315 316
(...skipping 27 matching lines...) Expand all
343 Cancel(); 344 Cancel();
344 return; 345 return;
345 } 346 }
346 347
347 OnHasServiceWorker(web_contents); 348 OnHasServiceWorker(web_contents);
348 } 349 }
349 350
350 void AppBannerDataFetcher::OnHasServiceWorker( 351 void AppBannerDataFetcher::OnHasServiceWorker(
351 content::WebContents* web_contents) { 352 content::WebContents* web_contents) {
352 GURL icon_url = ManifestIconSelector::FindBestMatchingIcon( 353 GURL icon_url = ManifestIconSelector::FindBestMatchingIcon(
353 web_app_data_.icons, ideal_icon_size_in_dp_, minimum_icon_size_in_dp_); 354 manifest_.icons, ideal_icon_size_in_dp_, minimum_icon_size_in_dp_);
354 355
355 if (icon_url.is_empty()) { 356 if (icon_url.is_empty()) {
356 OutputDeveloperNotShownMessage( 357 OutputDeveloperNotShownMessage(
357 web_contents, 358 web_contents,
358 kNoIconMatchingRequirements, 359 kNoIconMatchingRequirements,
359 base::IntToString(ManifestIconSelector::ConvertIconSizeFromDpToPx( 360 base::IntToString(ManifestIconSelector::ConvertIconSizeFromDpToPx(
360 minimum_icon_size_in_dp_)), 361 minimum_icon_size_in_dp_)),
361 is_debug_mode_); 362 is_debug_mode_);
362 Cancel(); 363 Cancel();
363 } else if (!FetchAppIcon(web_contents, icon_url)) { 364 } else if (!FetchAppIcon(web_contents, icon_url)) {
364 OutputDeveloperNotShownMessage(web_contents, kCannotDownloadIcon, 365 OutputDeveloperNotShownMessage(web_contents, kCannotDownloadIcon,
365 is_debug_mode_); 366 is_debug_mode_);
366 Cancel(); 367 Cancel();
367 } 368 }
368 } 369 }
369 370
370 bool AppBannerDataFetcher::FetchAppIcon(content::WebContents* web_contents, 371 bool AppBannerDataFetcher::FetchAppIcon(content::WebContents* web_contents,
371 const GURL& icon_url) { 372 const GURL& icon_url) {
373 app_icon_url_ = icon_url;
372 return ManifestIconDownloader::Download( 374 return ManifestIconDownloader::Download(
373 web_contents, 375 web_contents, icon_url, ideal_icon_size_in_dp_, minimum_icon_size_in_dp_,
374 icon_url, 376 base::Bind(&AppBannerDataFetcher::OnAppIconFetched, this));
375 ideal_icon_size_in_dp_,
376 minimum_icon_size_in_dp_,
377 base::Bind(&AppBannerDataFetcher::OnAppIconFetched,
378 this));
379 } 377 }
380 378
381 void AppBannerDataFetcher::OnAppIconFetched(const SkBitmap& bitmap) { 379 void AppBannerDataFetcher::OnAppIconFetched(const SkBitmap& bitmap) {
382 if (!is_active_) return; 380 if (!is_active_) return;
383 381
384 content::WebContents* web_contents = GetWebContents(); 382 content::WebContents* web_contents = GetWebContents();
385 if (!CheckFetcherIsStillAlive(web_contents)) { 383 if (!CheckFetcherIsStillAlive(web_contents)) {
386 Cancel(); 384 Cancel();
387 return; 385 return;
388 } 386 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 477
480 if (!DoesManifestContainRequiredIcon(manifest)) { 478 if (!DoesManifestContainRequiredIcon(manifest)) {
481 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon, 479 OutputDeveloperNotShownMessage(web_contents, kManifestMissingSuitableIcon,
482 is_debug_mode); 480 is_debug_mode);
483 return false; 481 return false;
484 } 482 }
485 return true; 483 return true;
486 } 484 }
487 485
488 } // namespace banners 486 } // namespace banners
OLDNEW
« no previous file with comments | « chrome/browser/banners/app_banner_data_fetcher.h ('k') | chrome/browser/banners/app_banner_data_fetcher_desktop.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698