Skip to content

Commit

Permalink
DPWA: use ParseURL for manifest id parsing logic
Browse files Browse the repository at this point in the history
Use ParseURL for manifest id parsing logic. This allows id to be both
specified as a full url or a string as path to app's origin. This allows
a more consistent spec processing definition, see in spec pull request
w3c/manifest#988 (comment). The
processed manifest id is still passed as a  normalized relative url path
to WebAppProvider system to keep the manifest_id saved in sync system
the same and backward-compatible since changing the manifest_id format
in sync system will make new apps not syncable to previous versions of
Chromium.

Bug: 1182363
Change-Id: I65a7ca615bae3ee504b605abba954f60dc5d2c31
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3042714
Commit-Queue: Phillis Tang <phillis@chromium.org>
Reviewed-by: Daniel Murphy <dmurph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#904128}
  • Loading branch information
philloooo authored and Chromium LUCI CQ committed Jul 22, 2021
1 parent cd3e88c commit 3ef03e9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
30 changes: 17 additions & 13 deletions third_party/blink/renderer/modules/manifest/manifest_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,23 +340,27 @@ String ManifestParser::ParseId(const JSONObject* object,
return String();
}

absl::optional<String> id = ParseString(object, "id", NoTrim);
if (id.has_value()) {
if (!start_url.IsValid()) {
ManifestUmaUtil::ParseIdResult(
ManifestUmaUtil::ParseIdResultType::kInvalidStartUrl);
return String();
}
KURL start_url_origin = KURL(SecurityOrigin::Create(start_url)->ToString());

KURL id = ParseURL(object, "id", start_url_origin,
ParseURLRestrictions::kSameOriginOnly);
if (id.IsValid()) {
ManifestUmaUtil::ParseIdResult(
ManifestUmaUtil::ParseIdResultType::kSucceed);
return *id;
} else {
// If id is not specified, sets to start_url with origin stripped.
if (start_url.IsValid()) {
ManifestUmaUtil::ParseIdResult(
ManifestUmaUtil::ParseIdResultType::kDefaultToStartUrl);
return start_url.GetString().Substring(start_url.PathStart() + 1);
} else {
ManifestUmaUtil::ParseIdResult(
ManifestUmaUtil::ParseIdResultType::kInvalidStartUrl);
return String();
}
// If id is not specified, sets to start_url
ManifestUmaUtil::ParseIdResult(
ManifestUmaUtil::ParseIdResultType::kDefaultToStartUrl);
id = start_url;
}
// TODO(https://crbug.com/1231765): rename the field to relative_id to reflect
// the actual value.
return id.GetString().Substring(id.PathStart() + 1);
}

KURL ManifestParser::ParseStartURL(const JSONObject* object) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,50 @@ TEST_F(ManifestParserTest, IdParseRules) {
ASSERT_EQ(0u, GetErrorCount());
EXPECT_EQ("start?query=a", manifest->id);
}
// Invalid type.
{
auto& manifest =
ParseManifest("{\"start_url\": \"/start?query=a\", \"id\": 1}");
ASSERT_EQ(1u, GetErrorCount());
EXPECT_EQ("start?query=a", manifest->id);
}
// Empty string.
{
auto& manifest =
ParseManifest("{ \"start_url\": \"/start?query=a\", \"id\": \"\" }");
ASSERT_EQ(0u, GetErrorCount());
EXPECT_EQ("", manifest->id);
}
// Full url.
{
auto& manifest = ParseManifest(
"{ \"start_url\": \"/start?query=a\", \"id\": \"http://foo.com/foo\" "
"}");
ASSERT_EQ(0u, GetErrorCount());
EXPECT_EQ("foo", manifest->id);
}
// Full url with different origin.
{
auto& manifest = ParseManifest(
"{ \"start_url\": \"/start?query=a\", \"id\": "
"\"http://another.com/foo\" }");
ASSERT_EQ(1u, GetErrorCount());
EXPECT_EQ("start?query=a", manifest->id);
}
// Relative path
{
auto& manifest =
ParseManifest("{ \"start_url\": \"/start?query=a\", \"id\": \".\" }");
ASSERT_EQ(0u, GetErrorCount());
EXPECT_EQ("", manifest->id);
}
// Absolute path
{
auto& manifest =
ParseManifest("{ \"start_url\": \"/start?query=a\", \"id\": \"/\" }");
ASSERT_EQ(0u, GetErrorCount());
EXPECT_EQ("", manifest->id);
}
// Smoke test.
{
auto& manifest =
Expand Down

0 comments on commit 3ef03e9

Please sign in to comment.