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

Side by Side Diff: content/renderer/manifest/manifest_parser.cc

Issue 2425833002: Parse "purpose" member from Web Manifest (Closed)
Patch Set: Addressing comments 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/manifest/manifest_parser.h" 5 #include "content/renderer/manifest/manifest_parser.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 blink::WebIconSizesParser::parseIconSizes(sizes_str.string()); 269 blink::WebIconSizesParser::parseIconSizes(sizes_str.string());
270 sizes.resize(web_sizes.size()); 270 sizes.resize(web_sizes.size());
271 for (size_t i = 0; i < web_sizes.size(); ++i) 271 for (size_t i = 0; i < web_sizes.size(); ++i)
272 sizes[i] = web_sizes[i]; 272 sizes[i] = web_sizes[i];
273 if (sizes.empty()) { 273 if (sizes.empty()) {
274 AddErrorInfo("found icon with no valid size."); 274 AddErrorInfo("found icon with no valid size.");
275 } 275 }
276 return sizes; 276 return sizes;
277 } 277 }
278 278
279 std::vector<Manifest::Icon::IconPurpose> ManifestParser::ParseIconPurpose(
280 const base::DictionaryValue& icon) {
281 base::NullableString16 purpose_str = ParseString(icon, "purpose", NoTrim);
282 std::vector<Manifest::Icon::IconPurpose> purposes;
283
284 if (purpose_str.is_null())
285 return purposes;
mlamouri (slow - plz ping) 2016/11/02 14:44:59 can you return the array with Manifest::Icon::Icon
F 2016/12/09 19:07:23 Done.
286
287 std::vector<base::string16> keywords = base::SplitString(
288 purpose_str.string(), base::ASCIIToUTF16(" "),
289 base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
290 for (const base::string16& keyword : keywords) {
291 if (base::LowerCaseEqualsASCII(keyword, "any")) {
292 purposes.push_back(Manifest::Icon::IconPurpose::ANY);
293 } else if (base::LowerCaseEqualsASCII(keyword, "badge")) {
294 purposes.push_back(Manifest::Icon::IconPurpose::BADGE);
295 } else {
296 AddErrorInfo("found icon with invalid purpose.");
mlamouri (slow - plz ping) 2016/10/25 11:12:22 Can you put the keyword that isn't valid in the er
F 2016/12/09 19:07:23 Unfortunately the keyword is of type string16, whi
297 }
298 }
299
300 if (purposes.empty()) {
301 purposes.push_back(Manifest::Icon::IconPurpose::ANY);
302 }
mlamouri (slow - plz ping) 2016/10/25 11:12:22 That looks odd. Not sure why we need to differenti
F 2016/12/09 19:07:23 Done.
303
304 return purposes;
305 }
306
279 std::vector<Manifest::Icon> ManifestParser::ParseIcons( 307 std::vector<Manifest::Icon> ManifestParser::ParseIcons(
280 const base::DictionaryValue& dictionary) { 308 const base::DictionaryValue& dictionary) {
281 std::vector<Manifest::Icon> icons; 309 std::vector<Manifest::Icon> icons;
282 if (!dictionary.HasKey("icons")) 310 if (!dictionary.HasKey("icons"))
283 return icons; 311 return icons;
284 312
285 const base::ListValue* icons_list = nullptr; 313 const base::ListValue* icons_list = nullptr;
286 if (!dictionary.GetList("icons", &icons_list)) { 314 if (!dictionary.GetList("icons", &icons_list)) {
287 AddErrorInfo("property 'icons' ignored, type array expected."); 315 AddErrorInfo("property 'icons' ignored, type array expected.");
288 return icons; 316 return icons;
289 } 317 }
290 318
291 for (size_t i = 0; i < icons_list->GetSize(); ++i) { 319 for (size_t i = 0; i < icons_list->GetSize(); ++i) {
292 const base::DictionaryValue* icon_dictionary = nullptr; 320 const base::DictionaryValue* icon_dictionary = nullptr;
293 if (!icons_list->GetDictionary(i, &icon_dictionary)) 321 if (!icons_list->GetDictionary(i, &icon_dictionary))
294 continue; 322 continue;
295 323
296 Manifest::Icon icon; 324 Manifest::Icon icon;
297 icon.src = ParseIconSrc(*icon_dictionary); 325 icon.src = ParseIconSrc(*icon_dictionary);
298 // An icon MUST have a valid src. If it does not, it MUST be ignored. 326 // An icon MUST have a valid src. If it does not, it MUST be ignored.
299 if (!icon.src.is_valid()) 327 if (!icon.src.is_valid())
300 continue; 328 continue;
301 icon.type = ParseIconType(*icon_dictionary); 329 icon.type = ParseIconType(*icon_dictionary);
302 icon.sizes = ParseIconSizes(*icon_dictionary); 330 icon.sizes = ParseIconSizes(*icon_dictionary);
331 icon.purpose = ParseIconPurpose(*icon_dictionary);
303 332
304 icons.push_back(icon); 333 icons.push_back(icon);
305 } 334 }
306 335
307 return icons; 336 return icons;
308 } 337 }
309 338
310 base::NullableString16 ManifestParser::ParseRelatedApplicationPlatform( 339 base::NullableString16 ManifestParser::ParseRelatedApplicationPlatform(
311 const base::DictionaryValue& application) { 340 const base::DictionaryValue& application) {
312 return ParseString(application, "platform", Trim); 341 return ParseString(application, "platform", Trim);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 } 417 }
389 418
390 void ManifestParser::AddErrorInfo(const std::string& error_msg, 419 void ManifestParser::AddErrorInfo(const std::string& error_msg,
391 bool critical, 420 bool critical,
392 int error_line, 421 int error_line,
393 int error_column) { 422 int error_column) {
394 errors_.push_back({error_msg, critical, error_line, error_column}); 423 errors_.push_back({error_msg, critical, error_line, error_column});
395 } 424 }
396 425
397 } // namespace content 426 } // namespace content
OLDNEW
« 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