Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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_.gcm_sender_id = ParseGCMSenderID(*dictionary); | 130 manifest_.gcm_sender_id = ParseGCMSenderID(*dictionary); |
| 131 manifest_.gcm_user_visible_only = ParseGCMUserVisibleOnly(*dictionary); | 131 manifest_.gcm_user_visible_only = ParseGCMUserVisibleOnly(*dictionary); |
| 132 manifest_.chrome_related_applications = | |
| 133 ParseChromeRelatedApplications(*dictionary); | |
| 132 | 134 |
| 133 ManifestUmaUtil::ParseSucceeded(manifest_); | 135 ManifestUmaUtil::ParseSucceeded(manifest_); |
| 134 } | 136 } |
| 135 | 137 |
| 136 const Manifest& ManifestParser::manifest() const { | 138 const Manifest& ManifestParser::manifest() const { |
| 137 return manifest_; | 139 return manifest_; |
| 138 } | 140 } |
| 139 | 141 |
| 140 const std::vector<std::string>& ManifestParser::errors() const { | 142 const std::vector<std::string>& ManifestParser::errors() const { |
| 141 return errors_; | 143 return errors_; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 base::NullableString16 ManifestParser::ParseGCMSenderID( | 339 base::NullableString16 ManifestParser::ParseGCMSenderID( |
| 338 const base::DictionaryValue& dictionary) { | 340 const base::DictionaryValue& dictionary) { |
| 339 return ParseString(dictionary, "gcm_sender_id", Trim); | 341 return ParseString(dictionary, "gcm_sender_id", Trim); |
| 340 } | 342 } |
| 341 | 343 |
| 342 bool ManifestParser::ParseGCMUserVisibleOnly( | 344 bool ManifestParser::ParseGCMUserVisibleOnly( |
| 343 const base::DictionaryValue& dictionary) { | 345 const base::DictionaryValue& dictionary) { |
| 344 return ParseBoolean(dictionary, "gcm_user_visible_only", false); | 346 return ParseBoolean(dictionary, "gcm_user_visible_only", false); |
| 345 } | 347 } |
| 346 | 348 |
| 349 Manifest::RelatedApplicationPlatform | |
| 350 ManifestParser::ParseRelatedApplicationPlatform( | |
| 351 const base::DictionaryValue& application) { | |
| 352 base::NullableString16 display = ParseString(application, "platform", Trim); | |
|
mlamouri (slow - plz ping)
2015/02/16 20:20:40
s/display/platform/
benwells
2015/02/16 23:58:43
Done.
| |
| 353 if (display.is_null()) | |
| 354 return Manifest::RELATED_APPLICATION_PLATFORM_UNSPECIFIED; | |
|
mlamouri (slow - plz ping)
2015/02/16 20:20:39
Could you add an error in that case? It seems that
benwells
2015/02/16 23:58:43
Done.
| |
| 355 | |
| 356 if (LowerCaseEqualsASCII(display.string(), "web")) | |
| 357 return Manifest::RELATED_APPLICATION_PLATFORM_WEB; | |
| 358 else if (LowerCaseEqualsASCII(display.string(), "android")) | |
| 359 return Manifest::RELATED_APPLICATION_PLATFORM_ANDROID; | |
| 360 else { | |
| 361 errors_.push_back(GetErrorPrefix() + "unknown 'platform' value ignored."); | |
| 362 return Manifest::RELATED_APPLICATION_PLATFORM_UNSPECIFIED; | |
| 363 } | |
| 364 } | |
| 365 | |
| 366 base::NullableString16 ManifestParser::ParseRelatedApplicationId( | |
| 367 const base::DictionaryValue& application) { | |
| 368 return ParseString(application, "id", Trim); | |
| 369 } | |
| 370 | |
| 371 std::vector<Manifest::RelatedApplication> | |
| 372 ManifestParser::ParseChromeRelatedApplications( | |
| 373 const base::DictionaryValue& dictionary) { | |
| 374 std::vector<Manifest::RelatedApplication> applications; | |
| 375 if (!dictionary.HasKey("chrome_related_applications")) | |
| 376 return applications; | |
| 377 | |
| 378 const base::ListValue* applications_list = nullptr; | |
| 379 if (!dictionary.GetList("chrome_related_applications", &applications_list)) { | |
| 380 errors_.push_back( | |
| 381 GetErrorPrefix() + | |
| 382 "property 'chrome_related_applications' ignored, type array expected."); | |
| 383 return applications; | |
| 384 } | |
| 385 | |
| 386 for (size_t i = 0; i < applications_list->GetSize(); ++i) { | |
| 387 const base::DictionaryValue* application_dictionary = nullptr; | |
| 388 if (!applications_list->GetDictionary(i, &application_dictionary)) | |
| 389 continue; | |
| 390 | |
| 391 Manifest::RelatedApplication application; | |
| 392 application.platform = | |
| 393 ParseRelatedApplicationPlatform(*application_dictionary); | |
| 394 // An application MUST have a valid platform. If it does not, it MUST be | |
| 395 // ignored. | |
| 396 if (application.platform == | |
| 397 Manifest::RELATED_APPLICATION_PLATFORM_UNSPECIFIED) | |
| 398 continue; | |
|
mlamouri (slow - plz ping)
2015/02/16 20:20:40
Could you add a comment pointing that no error is
| |
| 399 application.id = ParseRelatedApplicationId(*application_dictionary); | |
| 400 | |
| 401 applications.push_back(application); | |
| 402 } | |
| 403 | |
| 404 return applications; | |
| 405 } | |
| 406 | |
| 347 } // namespace content | 407 } // namespace content |
| OLD | NEW |