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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 Loading... |
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 base::NullableString16 ManifestParser::ParseRelatedApplicationPlatform( |
| 341 const base::DictionaryValue& application) { |
| 342 return ParseString(application, "platform", Trim); |
| 343 } |
| 344 |
| 345 GURL ManifestParser::ParseRelatedApplicationURL( |
| 346 const base::DictionaryValue& application) { |
| 347 return ParseURL(application, "url", manifest_url_); |
| 348 } |
| 349 |
| 350 base::NullableString16 ManifestParser::ParseRelatedApplicationId( |
| 351 const base::DictionaryValue& application) { |
| 352 return ParseString(application, "id", Trim); |
| 353 } |
| 354 |
| 355 std::vector<Manifest::RelatedApplication> |
| 356 ManifestParser::ParseRelatedApplications( |
| 357 const base::DictionaryValue& dictionary) { |
| 358 std::vector<Manifest::RelatedApplication> applications; |
| 359 if (!dictionary.HasKey("related_applications")) |
| 360 return applications; |
| 361 |
| 362 const base::ListValue* applications_list = nullptr; |
| 363 if (!dictionary.GetList("related_applications", &applications_list)) { |
| 364 errors_.push_back( |
| 365 GetErrorPrefix() + |
| 366 "property 'related_applications' ignored, type array expected."); |
| 367 return applications; |
| 368 } |
| 369 |
| 370 for (size_t i = 0; i < applications_list->GetSize(); ++i) { |
| 371 const base::DictionaryValue* application_dictionary = nullptr; |
| 372 if (!applications_list->GetDictionary(i, &application_dictionary)) |
| 373 continue; |
| 374 |
| 375 Manifest::RelatedApplication application; |
| 376 application.platform = |
| 377 ParseRelatedApplicationPlatform(*application_dictionary); |
| 378 // "If platform is undefined, move onto the next item if any are left." |
| 379 if (application.platform.is_null()) { |
| 380 errors_.push_back( |
| 381 GetErrorPrefix() + |
| 382 "'platform' is a required field, related application ignored."); |
| 383 continue; |
| 384 } |
| 385 |
| 386 application.id = ParseRelatedApplicationId(*application_dictionary); |
| 387 application.url = ParseRelatedApplicationURL(*application_dictionary); |
| 388 // "If both id and url are undefined, move onto the next item if any are |
| 389 // left." |
| 390 if (application.url.is_empty() && application.id.is_null()) { |
| 391 errors_.push_back( |
| 392 GetErrorPrefix() + |
| 393 "one of 'url' or 'id' is required, related application ignored."); |
| 394 continue; |
| 395 } |
| 396 |
| 397 applications.push_back(application); |
| 398 } |
| 399 |
| 400 return applications; |
| 401 } |
| 402 |
| 403 bool ManifestParser::ParsePreferRelatedApplications( |
| 404 const base::DictionaryValue& dictionary) { |
| 405 return ParseBoolean(dictionary, "prefer_related_applications", false); |
| 406 } |
| 407 |
337 base::NullableString16 ManifestParser::ParseGCMSenderID( | 408 base::NullableString16 ManifestParser::ParseGCMSenderID( |
338 const base::DictionaryValue& dictionary) { | 409 const base::DictionaryValue& dictionary) { |
339 return ParseString(dictionary, "gcm_sender_id", Trim); | 410 return ParseString(dictionary, "gcm_sender_id", Trim); |
340 } | 411 } |
341 | 412 |
342 bool ManifestParser::ParseGCMUserVisibleOnly( | 413 bool ManifestParser::ParseGCMUserVisibleOnly( |
343 const base::DictionaryValue& dictionary) { | 414 const base::DictionaryValue& dictionary) { |
344 return ParseBoolean(dictionary, "gcm_user_visible_only", false); | 415 return ParseBoolean(dictionary, "gcm_user_visible_only", false); |
345 } | 416 } |
346 | 417 |
347 } // namespace content | 418 } // namespace content |
OLD | NEW |