summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/browser/manifest/manifest_manager_host.cc4
-rw-r--r--content/common/manifest_manager_messages.h1
-rw-r--r--content/public/common/manifest.cc3
-rw-r--r--content/public/common/manifest.h5
-rw-r--r--content/renderer/manifest/manifest_manager.cc4
-rw-r--r--content/renderer/manifest/manifest_parser.cc10
-rw-r--r--content/renderer/manifest/manifest_parser_unittest.cc24
7 files changed, 49 insertions, 2 deletions
diff --git a/content/browser/manifest/manifest_manager_host.cc b/content/browser/manifest/manifest_manager_host.cc
index ebab903..962189f 100644
--- a/content/browser/manifest/manifest_manager_host.cc
+++ b/content/browser/manifest/manifest_manager_host.cc
@@ -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);
diff --git a/content/common/manifest_manager_messages.h b/content/common/manifest_manager_messages.h
index be80405..881ff6b 100644
--- a/content/common/manifest_manager_messages.h
+++ b/content/common/manifest_manager_messages.h
@@ -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
diff --git a/content/public/common/manifest.cc b/content/public/common/manifest.cc
index 71b2cd2..292b85b 100644
--- a/content/public/common/manifest.cc
+++ b/content/public/common/manifest.cc
@@ -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
diff --git a/content/public/common/manifest.h b/content/public/common/manifest.h
index 957f007..038bd0d 100644
--- a/content/public/common/manifest.h
+++ b/content/public/common/manifest.h
@@ -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.
diff --git a/content/renderer/manifest/manifest_manager.cc b/content/renderer/manifest/manifest_manager.cc
index 08612b8..d3989e7 100644
--- a/content/renderer/manifest/manifest_manager.cc
+++ b/content/renderer/manifest/manifest_manager.cc
@@ -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));
diff --git a/content/renderer/manifest/manifest_parser.cc b/content/renderer/manifest/manifest_parser.cc
index dc1624a..a68ca2a 100644
--- a/content/renderer/manifest/manifest_parser.cc
+++ b/content/renderer/manifest/manifest_parser.cc
@@ -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;
}
diff --git a/content/renderer/manifest/manifest_parser_unittest.cc b/content/renderer/manifest/manifest_parser_unittest.cc
index 32730f7..7212756 100644
--- a/content/renderer/manifest/manifest_parser_unittest.cc
+++ b/content/renderer/manifest/manifest_parser_unittest.cc
@@ -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