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

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

Issue 919293002: Add related_applications field to manifest parser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Feedback Created 5 years, 8 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 9a3e8520932cc7d18b6054066deda1d8f0a65c29..bb4fc4e37f48711a70fcaf6f81a38d4e7a67d92c 100644
--- a/content/renderer/manifest/manifest_parser.cc
+++ b/content/renderer/manifest/manifest_parser.cc
@@ -127,6 +127,9 @@ void ManifestParser::Parse() {
manifest_.display = ParseDisplay(*dictionary);
manifest_.orientation = ParseOrientation(*dictionary);
manifest_.icons = ParseIcons(*dictionary);
+ manifest_.related_applications = ParseRelatedApplications(*dictionary);
+ manifest_.prefer_related_applications =
+ ParsePreferRelatedApplications(*dictionary);
manifest_.gcm_sender_id = ParseGCMSenderID(*dictionary);
manifest_.gcm_user_visible_only = ParseGCMUserVisibleOnly(*dictionary);
@@ -334,6 +337,74 @@ std::vector<Manifest::Icon> ManifestParser::ParseIcons(
return icons;
}
+base::NullableString16 ManifestParser::ParseRelatedApplicationPlatform(
+ const base::DictionaryValue& application) {
+ return ParseString(application, "platform", Trim);
+}
+
+GURL ManifestParser::ParseRelatedApplicationURL(
+ const base::DictionaryValue& application) {
+ return ParseURL(application, "url", manifest_url_);
+}
+
+base::NullableString16 ManifestParser::ParseRelatedApplicationId(
+ const base::DictionaryValue& application) {
+ return ParseString(application, "id", Trim);
+}
+
+std::vector<Manifest::RelatedApplication>
+ManifestParser::ParseRelatedApplications(
+ const base::DictionaryValue& dictionary) {
+ std::vector<Manifest::RelatedApplication> applications;
+ if (!dictionary.HasKey("related_applications"))
+ return applications;
+
+ const base::ListValue* applications_list = nullptr;
+ if (!dictionary.GetList("related_applications", &applications_list)) {
+ errors_.push_back(
+ GetErrorPrefix() +
+ "property 'related_applications' ignored, type array expected.");
+ return applications;
+ }
+
+ for (size_t i = 0; i < applications_list->GetSize(); ++i) {
+ const base::DictionaryValue* application_dictionary = nullptr;
+ if (!applications_list->GetDictionary(i, &application_dictionary))
+ continue;
+
+ Manifest::RelatedApplication application;
+ application.platform =
+ ParseRelatedApplicationPlatform(*application_dictionary);
+ // "If platform is undefined, move onto the next item if any are left."
+ if (application.platform.is_null()) {
+ errors_.push_back(
+ GetErrorPrefix() +
+ "'platform' is a required field, related application ignored.");
+ continue;
+ }
+
+ application.id = ParseRelatedApplicationId(*application_dictionary);
+ application.url = ParseRelatedApplicationURL(*application_dictionary);
+ // "If both id and url are undefined, move onto the next item if any are
+ // left."
+ if (application.url.is_empty() && application.id.is_null()) {
+ errors_.push_back(
+ GetErrorPrefix() +
+ "one of 'url' or 'id' is required, related application ignored.");
+ continue;
+ }
+
+ applications.push_back(application);
+ }
+
+ return applications;
+}
+
+bool ManifestParser::ParsePreferRelatedApplications(
+ const base::DictionaryValue& dictionary) {
+ return ParseBoolean(dictionary, "prefer_related_applications", false);
+}
+
base::NullableString16 ManifestParser::ParseGCMSenderID(
const base::DictionaryValue& dictionary) {
return ParseString(dictionary, "gcm_sender_id", 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