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

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: Do IPC stuff Created 5 years, 10 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
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..be537b5088148d2b6e5e06e15511e821fbfc36ac 100644
--- a/content/renderer/manifest/manifest_parser.cc
+++ b/content/renderer/manifest/manifest_parser.cc
@@ -129,6 +129,8 @@ void ManifestParser::Parse() {
manifest_.icons = ParseIcons(*dictionary);
manifest_.gcm_sender_id = ParseGCMSenderID(*dictionary);
manifest_.gcm_user_visible_only = ParseGCMUserVisibleOnly(*dictionary);
+ manifest_.chrome_related_applications =
+ ParseChromeRelatedApplications(*dictionary);
ManifestUmaUtil::ParseSucceeded(manifest_);
}
@@ -344,4 +346,66 @@ bool ManifestParser::ParseGCMUserVisibleOnly(
return ParseBoolean(dictionary, "gcm_user_visible_only", false);
}
+Manifest::ChromeRelatedApplicationPlatform
+ManifestParser::ParseChromeRelatedApplicationPlatform(
+ const base::DictionaryValue& application) {
+ base::NullableString16 platform = ParseString(application, "platform", Trim);
+ if (platform.is_null()) {
+ errors_.push_back(GetErrorPrefix() + "'platform' is a required field, "
+ "chrome related application ignored.");
+ return Manifest::CHROME_RELATED_APPLICATION_PLATFORM_UNSPECIFIED;
+ }
+
+ if (LowerCaseEqualsASCII(platform.string(), "web"))
+ return Manifest::CHROME_RELATED_APPLICATION_PLATFORM_WEB;
+ else if (LowerCaseEqualsASCII(platform.string(), "android"))
+ return Manifest::CHROME_RELATED_APPLICATION_PLATFORM_ANDROID;
+ else {
+ errors_.push_back(GetErrorPrefix() + "unknown 'platform' value ignored.");
+ return Manifest::CHROME_RELATED_APPLICATION_PLATFORM_UNSPECIFIED;
+ }
+}
+
+base::NullableString16 ManifestParser::ParseChromeRelatedApplicationId(
+ const base::DictionaryValue& application) {
+ return ParseString(application, "id", Trim);
+}
+
+std::vector<Manifest::ChromeRelatedApplication>
+ManifestParser::ParseChromeRelatedApplications(
+ const base::DictionaryValue& dictionary) {
+ std::vector<Manifest::ChromeRelatedApplication> applications;
+ if (!dictionary.HasKey("chrome_related_applications"))
+ return applications;
+
+ const base::ListValue* applications_list = nullptr;
+ if (!dictionary.GetList("chrome_related_applications", &applications_list)) {
+ errors_.push_back(
+ GetErrorPrefix() +
+ "property 'chrome_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::ChromeRelatedApplication application;
+ application.platform =
+ ParseChromeRelatedApplicationPlatform(*application_dictionary);
+ // An application MUST have a valid platform. If it does not, it MUST be
+ // ignored. No error needs to be reported here, as it will have been
+ // reported in ParseChromeRelatedApplicationPlatform.
+ if (application.platform ==
+ Manifest::CHROME_RELATED_APPLICATION_PLATFORM_UNSPECIFIED)
+ continue;
+ application.id = ParseChromeRelatedApplicationId(*application_dictionary);
+
+ applications.push_back(application);
+ }
+
+ return applications;
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698