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

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

Issue 2425833002: Parse "purpose" member from Web Manifest (Closed)
Patch Set: patch Created 4 years, 2 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 442e0d8e1be88bcc619c213290ded27fa4faf3c9..ac0b70fd6541c2bfbc7b0ebbec615325f23407ca 100644
--- a/content/renderer/manifest/manifest_parser.cc
+++ b/content/renderer/manifest/manifest_parser.cc
@@ -276,6 +276,34 @@ 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> purpose;
pkotwicz 2016/10/18 14:13:56 Nit: |purpose| -> |purposes| because this is a std
F 2016/10/18 15:34:46 Done.
+
+ if (purpose_str.is_null())
+ return purpose;
+
+ std::vector<base::string16> keywords = base::SplitString(
+ purpose_str.string(), base::ASCIIToUTF16(" "),
+ base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
+ for (base::string16 keyword : keywords) {
pkotwicz 2016/10/18 14:13:56 I think that your for() loop copies elements into
F 2016/10/18 15:34:46 Done. Thanks!
+ if (LowerCaseEqualsASCII(keyword, "any")) {
+ purpose.push_back(Manifest::Icon::IconPurpose::ANY);
+ } else if (LowerCaseEqualsASCII(keyword, "badge")) {
+ purpose.push_back(Manifest::Icon::IconPurpose::BADGE);
+ } else {
+ AddErrorInfo("found icon with invalid purpose.");
+ }
+ }
+
+ if (purpose.empty()) {
+ purpose.push_back(Manifest::Icon::IconPurpose::ANY);
+ }
+
+ return purpose;
+}
+
std::vector<Manifest::Icon> ManifestParser::ParseIcons(
const base::DictionaryValue& dictionary) {
std::vector<Manifest::Icon> icons;
@@ -300,6 +328,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);
}

Powered by Google App Engine
This is Rietveld 408576698