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

Unified Diff: chrome/browser/banners/webapp_manifest_validator.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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/banners/webapp_manifest_validator.cc
diff --git a/chrome/browser/banners/webapp_manifest_validator.cc b/chrome/browser/banners/webapp_manifest_validator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..811b12084d492bc4889979ab49ebe4150d7cd964
--- /dev/null
+++ b/chrome/browser/banners/webapp_manifest_validator.cc
@@ -0,0 +1,88 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/banners/webapp_manifest_validator.h"
+
+#include "base/strings/string_util.h"
+#include "content/public/common/manifest.h"
+#include "ui/gfx/geometry/size.h"
+#include "url/gurl.h"
+
+namespace banners {
+namespace webapp_manifest_validator {
+
+namespace {
+
+const char kPngExtension[] = ".png";
+
+// The requirement for now is an image/png that is at least 144x144.
+const int kIconMinimumSize = 144;
+
+bool DoesManifestContainRequiredIcon(const content::Manifest& manifest) {
+ for (const auto& icon : manifest.icons) {
+ // The type field is optional. If it isn't present, fall back on checking
+ // the src extension, and allow the icon if the extension ends with png.
+ if (!base::EqualsASCII(icon.type.string(), "image/png") &&
+ !(icon.type.is_null() &&
+ base::EndsWith(icon.src.ExtractFileName(), kPngExtension,
+ base::CompareCase::INSENSITIVE_ASCII)))
+ continue;
+
+ for (const auto& size : icon.sizes) {
+ if (size.IsEmpty()) // "any"
+ return true;
+ if (size.width() >= kIconMinimumSize && size.height() >= kIconMinimumSize)
+ return true;
+ }
+ }
+
+ return false;
+}
+
+} // anonymous namespace
+
+bool IsWebappCapable(const content::Manifest& manifest,
+ OutputDeveloperMessageCode* code) {
+ // TODO(dominickn,mlamouri): when Chrome supports "minimal-ui", it should be
+ // accepted. If we accept it today, it would fallback to "browser" and make
+ // this check moot. See https://crbug.com/604390
+ if (manifest.display == blink::WebDisplayModeStandalone ||
+ manifest.display == blink::WebDisplayModeFullscreen) {
+ return true;
+ }
+ *code = OutputDeveloperMessageCode::kManifestDisplayStandaloneFullscreen;
+ return false;
+}
+
+bool IsManifestGoodForWebapp(
+ const content::Manifest& manifest,
+ OutputDeveloperMessageCode* code) {
+ if (manifest.IsEmpty()) {
+ *code = OutputDeveloperMessageCode::kManifestEmpty;
+ return false;
+ }
+
+ if (!IsWebappCapable(manifest, code)) {
+ return false;
+ }
+
+ if (!manifest.start_url.is_valid()) {
+ *code = OutputDeveloperMessageCode::kStartURLNotValid;
+ return false;
+ }
+ if ((manifest.name.is_null() || manifest.name.string().empty()) &&
+ (manifest.short_name.is_null() || manifest.short_name.string().empty())) {
+ *code = OutputDeveloperMessageCode::kManifestMissingNameOrShortName;
+ return false;
+ }
+
+ if (!DoesManifestContainRequiredIcon(manifest)) {
+ *code = OutputDeveloperMessageCode::kManifestMissingSuitableIcon;
+ return false;
+ }
+ return true;
+}
+
+} // namespace webapp_manifest_validator
+} // namespace banners
« no previous file with comments | « chrome/browser/banners/webapp_manifest_validator.h ('k') | chrome/browser/banners/webapp_manifest_validator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698