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

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

Issue 2425833002: Parse "purpose" member from Web Manifest (Closed)
Patch Set: Fix Created 4 years 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 442e0d8e1be88bcc619c213290ded27fa4faf3c9..93e596992567517a587041776e7dd692d59af6c4 100644
--- a/content/renderer/manifest/manifest_parser.cc
+++ b/content/renderer/manifest/manifest_parser.cc
@@ -276,6 +276,38 @@ std::vector<gfx::Size> ManifestParser::ParseIconSizes(
return sizes;
}
+std::vector<Manifest::Icon::IconPurpose> ManifestParser::ParseIconPurpose(
+ const base::DictionaryValue& icon) {
+ base::NullableString16 purpose_str = ParseString(icon, "purpose", NoTrim);
+ std::vector<Manifest::Icon::IconPurpose> purposes;
+
+ if (purpose_str.is_null()) {
+ purposes.push_back(Manifest::Icon::IconPurpose::ANY);
+ return purposes;
+ }
+
+ std::vector<base::string16> keywords = base::SplitString(
+ purpose_str.string(), base::ASCIIToUTF16(" "),
+ base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
+ for (const base::string16& keyword : keywords) {
+ if (base::LowerCaseEqualsASCII(keyword, "any")) {
+ purposes.push_back(Manifest::Icon::IconPurpose::ANY);
+ } else if (base::LowerCaseEqualsASCII(keyword, "badge")) {
+ purposes.push_back(Manifest::Icon::IconPurpose::BADGE);
+ } else {
+ AddErrorInfo(
+ "found icon with invalid purpose. "
+ "Using default value 'any'.");
+ }
+ }
+
+ if (purposes.empty()) {
+ purposes.push_back(Manifest::Icon::IconPurpose::ANY);
+ }
+
+ return purposes;
+}
+
std::vector<Manifest::Icon> ManifestParser::ParseIcons(
const base::DictionaryValue& dictionary) {
std::vector<Manifest::Icon> icons;
@@ -300,6 +332,7 @@ std::vector<Manifest::Icon> ManifestParser::ParseIcons(
continue;
icon.type = ParseIconType(*icon_dictionary);
icon.sizes = ParseIconSizes(*icon_dictionary);
+ icon.purpose = ParseIconPurpose(*icon_dictionary);
icons.push_back(icon);
}
« 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