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 |