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

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

Issue 2050933002: Upstream: Add additional checks before creating a WebAPK after clicking "Add to Homescreen" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'create_webapk_requirements_enum_class' into create_webapk_requirements2 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"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/banners/app_banner_debug_log.h"
14 #include "chrome/browser/banners/app_banner_metrics.h" 13 #include "chrome/browser/banners/app_banner_metrics.h"
15 #include "chrome/browser/banners/app_banner_settings_helper.h" 14 #include "chrome/browser/banners/app_banner_settings_helper.h"
15 #include "chrome/browser/banners/webapp_manifest_validator.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/manifest/manifest_icon_downloader.h" 17 #include "chrome/browser/manifest/manifest_icon_downloader.h"
18 #include "chrome/browser/manifest/manifest_icon_selector.h" 18 #include "chrome/browser/manifest/manifest_icon_selector.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/common/chrome_switches.h" 20 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/render_messages.h" 21 #include "chrome/common/render_messages.h"
22 #include "components/rappor/rappor_utils.h" 22 #include "components/rappor/rappor_utils.h"
23 #include "content/public/browser/browser_context.h" 23 #include "content/public/browser/browser_context.h"
24 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
25 #include "content/public/browser/navigation_details.h" 25 #include "content/public/browser/navigation_details.h"
26 #include "content/public/browser/render_frame_host.h" 26 #include "content/public/browser/render_frame_host.h"
27 #include "content/public/browser/service_worker_context.h" 27 #include "content/public/browser/service_worker_context.h"
28 #include "content/public/browser/storage_partition.h" 28 #include "content/public/browser/storage_partition.h"
29 #include "net/base/load_flags.h" 29 #include "net/base/load_flags.h"
30 #include "third_party/WebKit/public/platform/WebDisplayMode.h" 30 #include "third_party/WebKit/public/platform/WebDisplayMode.h"
31 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm ptReply.h" 31 #include "third_party/WebKit/public/platform/modules/app_banner/WebAppBannerProm ptReply.h"
32 32
33 namespace { 33 namespace {
34 34
35 base::LazyInstance<base::TimeDelta> gTimeDeltaForTesting = 35 base::LazyInstance<base::TimeDelta> gTimeDeltaForTesting =
36 LAZY_INSTANCE_INITIALIZER; 36 LAZY_INSTANCE_INITIALIZER;
37 int gCurrentRequestID = -1; 37 int gCurrentRequestID = -1;
38 const char kPngExtension[] = ".png";
39
40 // The requirement for now is an image/png that is at least 144x144.
41 const int kIconMinimumSize = 144;
42 bool DoesManifestContainRequiredIcon(const content::Manifest& manifest) {
43 for (const auto& icon : manifest.icons) {
44 // The type field is optional. If it isn't present, fall back on checking
45 // the src extension, and allow the icon if the extension ends with png.
46 if (!base::EqualsASCII(icon.type.string(), "image/png") &&
47 !(icon.type.is_null() &&
48 base::EndsWith(icon.src.ExtractFileName(), kPngExtension,
49 base::CompareCase::INSENSITIVE_ASCII)))
50 continue;
51
52 for (const auto& size : icon.sizes) {
53 if (size.IsEmpty()) // "any"
54 return true;
55 if (size.width() >= kIconMinimumSize && size.height() >= kIconMinimumSize)
56 return true;
57 }
58 }
59
60 return false;
61 }
62 38
63 } // anonymous namespace 39 } // anonymous namespace
64 40
65 namespace banners { 41 namespace banners {
66 42
67 // static 43 // static
68 base::Time AppBannerDataFetcher::GetCurrentTime() { 44 base::Time AppBannerDataFetcher::GetCurrentTime() {
69 return base::Time::Now() + gTimeDeltaForTesting.Get(); 45 return base::Time::Now() + gTimeDeltaForTesting.Get();
70 } 46 }
71 47
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 manifest.related_applications.size()) { 266 manifest.related_applications.size()) {
291 for (const auto& application : manifest.related_applications) { 267 for (const auto& application : manifest.related_applications) {
292 std::string platform = base::UTF16ToUTF8(application.platform.string()); 268 std::string platform = base::UTF16ToUTF8(application.platform.string());
293 std::string id = base::UTF16ToUTF8(application.id.string()); 269 std::string id = base::UTF16ToUTF8(application.id.string());
294 if (weak_delegate_->HandleNonWebApp(platform, application.url, id, 270 if (weak_delegate_->HandleNonWebApp(platform, application.url, id,
295 is_debug_mode_)) 271 is_debug_mode_))
296 return; 272 return;
297 } 273 }
298 } 274 }
299 275
300 if (!IsManifestValidForWebApp(manifest, web_contents, is_debug_mode_)) { 276 OutputDeveloperMessageCode error_code = OutputDeveloperMessageCode::kNone;
277 if (!CheckManifest(manifest, &error_code)) {
278 OutputDeveloperNotShownMessage(web_contents, error_code, is_debug_mode_);
301 Cancel(); 279 Cancel();
302 return; 280 return;
303 } 281 }
304 282
305 // Since the manifest is valid, one of short name or name must be non-null. 283 // Since the manifest is valid, one of short name or name must be non-null.
306 // Prefer name if it isn't null. 284 // Prefer name if it isn't null.
307 manifest_url_ = manifest_url; 285 manifest_url_ = manifest_url;
308 manifest_ = manifest; 286 manifest_ = manifest;
309 app_title_ = (manifest_.name.is_null()) ? manifest_.short_name.string() 287 app_title_ = (manifest_.name.is_null()) ? manifest_.short_name.string()
310 : manifest_.name.string(); 288 : manifest_.name.string();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 386
409 app_icon_.reset(new SkBitmap(bitmap)); 387 app_icon_.reset(new SkBitmap(bitmap));
410 event_request_id_ = ++gCurrentRequestID; 388 event_request_id_ = ++gCurrentRequestID;
411 web_contents->GetMainFrame()->Send( 389 web_contents->GetMainFrame()->Send(
412 new ChromeViewMsg_AppBannerPromptRequest( 390 new ChromeViewMsg_AppBannerPromptRequest(
413 web_contents->GetMainFrame()->GetRoutingID(), 391 web_contents->GetMainFrame()->GetRoutingID(),
414 event_request_id_, 392 event_request_id_,
415 GetBannerType())); 393 GetBannerType()));
416 } 394 }
417 395
396 bool AppBannerDataFetcher::CheckManifest(const content::Manifest& manifest,
397 OutputDeveloperMessageCode* code) {
398 return webapp_manifest_validator::IsManifestGoodForWebapp(manifest, code);
399 }
400
418 bool AppBannerDataFetcher::IsWebAppInstalled( 401 bool AppBannerDataFetcher::IsWebAppInstalled(
419 content::BrowserContext* browser_context, 402 content::BrowserContext* browser_context,
420 const GURL& start_url) { 403 const GURL& start_url) {
421 return false; 404 return false;
422 } 405 }
423 406
424 void AppBannerDataFetcher::RecordCouldShowBanner() { 407 void AppBannerDataFetcher::RecordCouldShowBanner() {
425 content::WebContents* web_contents = GetWebContents(); 408 content::WebContents* web_contents = GetWebContents();
426 DCHECK(web_contents); 409 DCHECK(web_contents);
427 410
(...skipping 18 matching lines...) Expand all
446 OutputDeveloperMessageCode::kUserNavigatedBeforeBannerShown, 429 OutputDeveloperMessageCode::kUserNavigatedBeforeBannerShown,
447 is_debug_mode_); 430 is_debug_mode_);
448 return false; 431 return false;
449 } 432 }
450 if (!web_contents) { 433 if (!web_contents) {
451 return false; // We cannot show a message if |web_contents| is null 434 return false; // We cannot show a message if |web_contents| is null
452 } 435 }
453 return true; 436 return true;
454 } 437 }
455 438
456 // static
457 bool AppBannerDataFetcher::IsManifestValidForWebApp(
458 const content::Manifest& manifest,
459 content::WebContents* web_contents,
460 bool is_debug_mode) {
461 if (manifest.IsEmpty()) {
462 OutputDeveloperNotShownMessage(web_contents,
463 OutputDeveloperMessageCode::kManifestEmpty,
464 is_debug_mode);
465 return false;
466 }
467 if (!manifest.start_url.is_valid()) {
468 OutputDeveloperNotShownMessage(
469 web_contents, OutputDeveloperMessageCode::kStartURLNotValid,
470 is_debug_mode);
471 return false;
472 }
473 if ((manifest.name.is_null() || manifest.name.string().empty()) &&
474 (manifest.short_name.is_null() || manifest.short_name.string().empty())) {
475 OutputDeveloperNotShownMessage(
476 web_contents,
477 OutputDeveloperMessageCode::kManifestMissingNameOrShortName,
478 is_debug_mode);
479 return false;
480 }
481
482 // TODO(dominickn,mlamouri): when Chrome supports "minimal-ui", it should be
483 // accepted. If we accept it today, it would fallback to "browser" and make
484 // this check moot. See https://crbug.com/604390
485 if (manifest.display != blink::WebDisplayModeStandalone &&
486 manifest.display != blink::WebDisplayModeFullscreen) {
487 OutputDeveloperNotShownMessage(
488 web_contents,
489 OutputDeveloperMessageCode::kManifestDisplayStandaloneFullscreen,
490 is_debug_mode);
491 return false;
492 }
493
494 if (!DoesManifestContainRequiredIcon(manifest)) {
495 OutputDeveloperNotShownMessage(
496 web_contents, OutputDeveloperMessageCode::kManifestMissingSuitableIcon,
497 is_debug_mode);
498 return false;
499 }
500 return true;
501 }
502
503 } // namespace banners 439 } // namespace banners
OLDNEW
« no previous file with comments | « chrome/browser/banners/app_banner_data_fetcher.h ('k') | chrome/browser/banners/app_banner_data_fetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698