Commit 9291444d authored by mlamouri's avatar mlamouri Committed by Commit bot

Add support for gcm_sender_id in Manifest.

It is a proprietary extension of the Web Manifest.

BUG=414873

Review URL: https://codereview.chromium.org/580513002

Cr-Commit-Position: refs/heads/master@{#297197}
parent 11f1faa1
......@@ -119,6 +119,10 @@ void ManifestManagerHost::OnRequestManifestResponse(
Manifest::kMaxIPCStringLength),
manifest.icons[i].type.is_null());
}
manifest.gcm_sender_id = base::NullableString16(
manifest.gcm_sender_id.string().substr(
0, Manifest::kMaxIPCStringLength),
manifest.gcm_sender_id.is_null());
callback->Run(manifest);
callbacks->Remove(request_id);
......
......@@ -31,6 +31,7 @@ IPC_STRUCT_TRAITS_BEGIN(content::Manifest)
IPC_STRUCT_TRAITS_MEMBER(display)
IPC_STRUCT_TRAITS_MEMBER(orientation)
IPC_STRUCT_TRAITS_MEMBER(icons)
IPC_STRUCT_TRAITS_MEMBER(gcm_sender_id)
IPC_STRUCT_TRAITS_END()
// The browser process requests for the manifest linked with the associated
......
......@@ -30,7 +30,8 @@ bool Manifest::IsEmpty() const {
start_url.is_empty() &&
display == DISPLAY_MODE_UNSPECIFIED &&
orientation == blink::WebScreenOrientationLockDefault &&
icons.empty();
icons.empty() &&
gcm_sender_id.is_null();
}
} // namespace content
......@@ -82,6 +82,11 @@ struct CONTENT_EXPORT Manifest {
// icons inside the JSON array were invalid.
std::vector<Icon> icons;
// This is a proprietary extension of the web Manifest, double-check that it
// is okay to use this entry.
// Null if parsing failed or the field was not present.
base::NullableString16 gcm_sender_id;
// Maximum length for all the strings inside the Manifest when it is sent over
// IPC. The renderer process should truncate the strings before sending the
// Manifest and the browser process must do the same when receiving it.
......
......@@ -65,6 +65,10 @@ void ManifestManager::OnRequestManifestComplete(
0, Manifest::kMaxIPCStringLength),
ipc_manifest.icons[i].type.is_null());
}
ipc_manifest.gcm_sender_id = base::NullableString16(
ipc_manifest.gcm_sender_id.string().substr(
0, Manifest::kMaxIPCStringLength),
ipc_manifest.gcm_sender_id.is_null());
Send(new ManifestManagerHostMsg_RequestManifestResponse(
routing_id(), request_id, ipc_manifest));
......
......@@ -94,7 +94,6 @@ GURL ParseStartURL(const base::DictionaryValue& dictionary,
// parsing failed.
Manifest::DisplayMode ParseDisplay(const base::DictionaryValue& dictionary) {
base::NullableString16 display = ParseString(dictionary, "display", Trim);
if (display.is_null())
return Manifest::DISPLAY_MODE_UNSPECIFIED;
......@@ -275,6 +274,14 @@ std::vector<Manifest::Icon> ParseIcons(const base::DictionaryValue& dictionary,
return icons;
}
// Parses the 'gcm_sender_id' field of the manifest.
// This is a proprietary extension of the Web Manifest specification.
// Returns the parsed string if any, a null string if the parsing failed.
base::NullableString16 ParseGCMSenderID(
const base::DictionaryValue& dictionary) {
return ParseString(dictionary, "gcm_sender_id", Trim);
}
} // anonymous namespace
Manifest ManifestParser::Parse(const base::StringPiece& json,
......@@ -307,6 +314,7 @@ Manifest ManifestParser::Parse(const base::StringPiece& json,
manifest.display = ParseDisplay(*dictionary);
manifest.orientation = ParseOrientation(*dictionary);
manifest.icons = ParseIcons(*dictionary, manifest_url);
manifest.gcm_sender_id = ParseGCMSenderID(*dictionary);
return manifest;
}
......
......@@ -580,4 +580,28 @@ TEST_F(ManifestParserTest, IconSizesParseRules) {
}
}
TEST_F(ManifestParserTest, GCMSenderIDParseRules) {
// Smoke test.
{
Manifest manifest = ParseManifest("{ \"gcm_sender_id\": \"foo\" }");
EXPECT_TRUE(EqualsASCII(manifest.gcm_sender_id.string(), "foo"));
}
// Trim whitespaces.
{
Manifest manifest = ParseManifest("{ \"gcm_sender_id\": \" foo \" }");
EXPECT_TRUE(EqualsASCII(manifest.gcm_sender_id.string(), "foo"));
}
// Don't parse if property isn't a string.
{
Manifest manifest = ParseManifest("{ \"gcm_sender_id\": {} }");
EXPECT_TRUE(manifest.gcm_sender_id.is_null());
}
{
Manifest manifest = ParseManifest("{ \"gcm_sender_id\": 42 }");
EXPECT_TRUE(manifest.gcm_sender_id.is_null());
}
}
} // namespace content
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment