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

Unified Diff: content/renderer/manifest/manifest_parser.cc

Issue 2063003003: Implement "scope" Web Manifest parsing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge branch 'webapk_manifest_scope00' into webapk_manifest_scope0 Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/manifest/manifest_parser.h ('k') | content/renderer/manifest/manifest_parser_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/manifest/manifest_parser.cc
diff --git a/content/renderer/manifest/manifest_parser.cc b/content/renderer/manifest/manifest_parser.cc
index 8be16c8b0055d59b49e2c9175008bb864e9ca4de..23dca88bb9baf247d8b8e2f6762718a9e41bd136 100644
--- a/content/renderer/manifest/manifest_parser.cc
+++ b/content/renderer/manifest/manifest_parser.cc
@@ -64,6 +64,7 @@ void ManifestParser::Parse() {
manifest_.name = ParseName(*dictionary);
manifest_.short_name = ParseShortName(*dictionary);
manifest_.start_url = ParseStartURL(*dictionary);
+ manifest_.scope = ParseScope(*dictionary, manifest_.start_url);
manifest_.display = ParseDisplay(*dictionary);
manifest_.orientation = ParseOrientation(*dictionary);
manifest_.icons = ParseIcons(*dictionary);
@@ -156,7 +157,10 @@ GURL ManifestParser::ParseURL(const base::DictionaryValue& dictionary,
if (url_str.is_null())
return GURL();
- return base_url.Resolve(url_str.string());
+ GURL resolved = base_url.Resolve(url_str.string());
+ if (!resolved.is_valid())
+ AddErrorInfo("property '" + key + "' ignored, URL is invalid.");
+ return resolved;
}
base::NullableString16 ManifestParser::ParseName(
@@ -183,6 +187,34 @@ GURL ManifestParser::ParseStartURL(const base::DictionaryValue& dictionary) {
return start_url;
}
+GURL ManifestParser::ParseScope(const base::DictionaryValue& dictionary,
+ const GURL& start_url) {
+ GURL scope = ParseURL(dictionary, "scope", manifest_url_);
+ if (!scope.is_valid()) {
+ return GURL();
+ }
+
+ if (scope.GetOrigin() != document_url_.GetOrigin()) {
+ AddErrorInfo("property 'scope' ignored, should be "
+ "same origin as document.");
+ return GURL();
+ }
+
+ // According to the spec, if the start_url cannot be parsed, the document URL
+ // should be used as the start URL. If the start_url could not be parsed,
+ // check that the document URL is within scope.
+ GURL check_in_scope = start_url.is_empty() ? document_url_ : start_url;
+ if (check_in_scope.GetOrigin() != scope.GetOrigin() ||
+ !base::StartsWith(check_in_scope.path(), scope.path(),
+ base::CompareCase::SENSITIVE)) {
+ AddErrorInfo(
+ "property 'scope' ignored. Start url should be within scope "
+ "of scope URL.");
+ return GURL();
+ }
+ return scope;
+}
+
blink::WebDisplayMode ManifestParser::ParseDisplay(
const base::DictionaryValue& dictionary) {
base::NullableString16 display = ParseString(dictionary, "display", Trim);
« no previous file with comments | « content/renderer/manifest/manifest_parser.h ('k') | content/renderer/manifest/manifest_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698