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

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

Issue 919293002: Add related_applications field to manifest parser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update for additions to spec Created 5 years, 8 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 "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/strings/nullable_string16.h" 8 #include "base/strings/nullable_string16.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 return; 120 return;
121 } 121 }
122 DCHECK(dictionary); 122 DCHECK(dictionary);
123 123
124 manifest_.name = ParseName(*dictionary); 124 manifest_.name = ParseName(*dictionary);
125 manifest_.short_name = ParseShortName(*dictionary); 125 manifest_.short_name = ParseShortName(*dictionary);
126 manifest_.start_url = ParseStartURL(*dictionary); 126 manifest_.start_url = ParseStartURL(*dictionary);
127 manifest_.display = ParseDisplay(*dictionary); 127 manifest_.display = ParseDisplay(*dictionary);
128 manifest_.orientation = ParseOrientation(*dictionary); 128 manifest_.orientation = ParseOrientation(*dictionary);
129 manifest_.icons = ParseIcons(*dictionary); 129 manifest_.icons = ParseIcons(*dictionary);
130 manifest_.related_applications = ParseRelatedApplications(*dictionary);
131 manifest_.prefer_related_applications =
132 ParsePreferRelatedApplications(*dictionary);
130 manifest_.gcm_sender_id = ParseGCMSenderID(*dictionary); 133 manifest_.gcm_sender_id = ParseGCMSenderID(*dictionary);
131 manifest_.gcm_user_visible_only = ParseGCMUserVisibleOnly(*dictionary); 134 manifest_.gcm_user_visible_only = ParseGCMUserVisibleOnly(*dictionary);
132 135
133 ManifestUmaUtil::ParseSucceeded(manifest_); 136 ManifestUmaUtil::ParseSucceeded(manifest_);
134 } 137 }
135 138
136 const Manifest& ManifestParser::manifest() const { 139 const Manifest& ManifestParser::manifest() const {
137 return manifest_; 140 return manifest_;
138 } 141 }
139 142
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 icon.type = ParseIconType(*icon_dictionary); 330 icon.type = ParseIconType(*icon_dictionary);
328 icon.density = ParseIconDensity(*icon_dictionary); 331 icon.density = ParseIconDensity(*icon_dictionary);
329 icon.sizes = ParseIconSizes(*icon_dictionary); 332 icon.sizes = ParseIconSizes(*icon_dictionary);
330 333
331 icons.push_back(icon); 334 icons.push_back(icon);
332 } 335 }
333 336
334 return icons; 337 return icons;
335 } 338 }
336 339
340 Manifest::RelatedApplicationPlatform
341 ManifestParser::ParseRelatedApplicationPlatform(
342 const base::DictionaryValue& application) {
343 base::NullableString16 platform = ParseString(application, "platform", Trim);
344 if (platform.is_null()) {
345 errors_.push_back(GetErrorPrefix() + "'platform' is a required field, "
346 "related application ignored.");
347 return Manifest::RELATED_APPLICATION_PLATFORM_UNSPECIFIED;
348 }
349
350 if (LowerCaseEqualsASCII(platform.string(), "play"))
351 return Manifest::RELATED_APPLICATION_PLATFORM_PLAY;
352 else {
353 errors_.push_back(GetErrorPrefix() + "unknown 'platform' value ignored.");
354 return Manifest::RELATED_APPLICATION_PLATFORM_UNSPECIFIED;
355 }
356 }
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.
357
358 GURL ManifestParser::ParseRelatedApplicationURL(
359 const base::DictionaryValue& application) {
360 return ParseURL(application, "url", manifest_url_);
361 }
362
363 base::NullableString16 ManifestParser::ParseRelatedApplicationId(
364 const base::DictionaryValue& application) {
365 return ParseString(application, "id", Trim);
366 }
367
368 std::vector<Manifest::RelatedApplication>
369 ManifestParser::ParseRelatedApplications(
370 const base::DictionaryValue& dictionary) {
371 std::vector<Manifest::RelatedApplication> applications;
372 if (!dictionary.HasKey("related_applications"))
373 return applications;
374
375 const base::ListValue* applications_list = nullptr;
376 if (!dictionary.GetList("related_applications", &applications_list)) {
377 errors_.push_back(
378 GetErrorPrefix() +
379 "property 'related_applications' ignored, type array expected.");
380 return applications;
381 }
382
383 for (size_t i = 0; i < applications_list->GetSize(); ++i) {
384 const base::DictionaryValue* application_dictionary = nullptr;
385 if (!applications_list->GetDictionary(i, &application_dictionary))
386 continue;
387
388 Manifest::RelatedApplication application;
389 application.platform =
390 ParseRelatedApplicationPlatform(*application_dictionary);
391 // "If platform is undefined, move onto the next item if any are left."
392 // No error needs to be reported here, as it will have been reported in
393 // ParseRelatedApplicationPlatform.
394 if (application.platform ==
395 Manifest::RELATED_APPLICATION_PLATFORM_UNSPECIFIED) {
396 continue;
397 }
398
399 application.id = ParseRelatedApplicationId(*application_dictionary);
400 application.url = ParseRelatedApplicationURL(*application_dictionary);
401 // "If both id and url are undefined, move onto the next item if any are
402 // left."
403 if (application.url.is_empty() && application.id.is_null()) {
404 errors_.push_back(
405 GetErrorPrefix() +
406 "one of 'url' or 'id' is required, related application ignored.");
407 continue;
408 }
409
410 applications.push_back(application);
411 }
412
413 return applications;
414 }
415
416 bool ManifestParser::ParsePreferRelatedApplications(
417 const base::DictionaryValue& dictionary) {
418 return ParseBoolean(dictionary, "prefer_related_applications", false);
419 }
420
337 base::NullableString16 ManifestParser::ParseGCMSenderID( 421 base::NullableString16 ManifestParser::ParseGCMSenderID(
338 const base::DictionaryValue& dictionary) { 422 const base::DictionaryValue& dictionary) {
339 return ParseString(dictionary, "gcm_sender_id", Trim); 423 return ParseString(dictionary, "gcm_sender_id", Trim);
340 } 424 }
341 425
342 bool ManifestParser::ParseGCMUserVisibleOnly( 426 bool ManifestParser::ParseGCMUserVisibleOnly(
343 const base::DictionaryValue& dictionary) { 427 const base::DictionaryValue& dictionary) {
344 return ParseBoolean(dictionary, "gcm_user_visible_only", false); 428 return ParseBoolean(dictionary, "gcm_user_visible_only", false);
345 } 429 }
346 430
347 } // namespace content 431 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698