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..dcdb2b48da3d4a70bcbc03a50f844914f6030d5e 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,87 @@ std::vector<Manifest::Icon> ManifestParser::ParseIcons( |
return icons; |
} |
+Manifest::RelatedApplicationPlatform |
+ManifestParser::ParseRelatedApplicationPlatform( |
+ const base::DictionaryValue& application) { |
+ base::NullableString16 platform = ParseString(application, "platform", Trim); |
+ if (platform.is_null()) { |
+ errors_.push_back(GetErrorPrefix() + "'platform' is a required field, " |
+ "related application ignored."); |
+ return Manifest::RELATED_APPLICATION_PLATFORM_UNSPECIFIED; |
+ } |
+ |
+ if (LowerCaseEqualsASCII(platform.string(), "play")) |
+ return Manifest::RELATED_APPLICATION_PLATFORM_PLAY; |
+ else { |
+ errors_.push_back(GetErrorPrefix() + "unknown 'platform' value ignored."); |
+ return Manifest::RELATED_APPLICATION_PLATFORM_UNSPECIFIED; |
+ } |
+} |
mlamouri (slow - plz ping)
2015/04/10 09:49:45
I would do:
return ParseString(application, "pla
benwells
2015/04/15 06:45:22
Done.
|
+ |
+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." |
+ // No error needs to be reported here, as it will have been reported in |
+ // ParseRelatedApplicationPlatform. |
+ if (application.platform == |
+ Manifest::RELATED_APPLICATION_PLATFORM_UNSPECIFIED) { |
+ 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); |