| 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 <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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 | 307 |
| 308 GURL ManifestParser::ParseIconSrc(const base::DictionaryValue& icon) { | 308 GURL ManifestParser::ParseIconSrc(const base::DictionaryValue& icon) { |
| 309 return ParseURL(icon, "src", manifest_url_); | 309 return ParseURL(icon, "src", manifest_url_); |
| 310 } | 310 } |
| 311 | 311 |
| 312 base::NullableString16 ManifestParser::ParseIconType( | 312 base::NullableString16 ManifestParser::ParseIconType( |
| 313 const base::DictionaryValue& icon) { | 313 const base::DictionaryValue& icon) { |
| 314 return ParseString(icon, "type", Trim); | 314 return ParseString(icon, "type", Trim); |
| 315 } | 315 } |
| 316 | 316 |
| 317 double ManifestParser::ParseIconDensity(const base::DictionaryValue& icon) { | |
| 318 double density; | |
| 319 if (!icon.HasKey("density")) | |
| 320 return Manifest::Icon::kDefaultDensity; | |
| 321 | |
| 322 if (!icon.GetDouble("density", &density) || density <= 0) { | |
| 323 AddErrorInfo(GetErrorPrefix() + | |
| 324 "icon 'density' ignored, must be float greater than 0."); | |
| 325 return Manifest::Icon::kDefaultDensity; | |
| 326 } | |
| 327 return density; | |
| 328 } | |
| 329 | |
| 330 std::vector<gfx::Size> ManifestParser::ParseIconSizes( | 317 std::vector<gfx::Size> ManifestParser::ParseIconSizes( |
| 331 const base::DictionaryValue& icon) { | 318 const base::DictionaryValue& icon) { |
| 332 base::NullableString16 sizes_str = ParseString(icon, "sizes", NoTrim); | 319 base::NullableString16 sizes_str = ParseString(icon, "sizes", NoTrim); |
| 333 | 320 |
| 334 if (sizes_str.is_null()) | 321 if (sizes_str.is_null()) |
| 335 return std::vector<gfx::Size>(); | 322 return std::vector<gfx::Size>(); |
| 336 | 323 |
| 337 std::vector<gfx::Size> sizes = ParseIconSizesHTML(sizes_str.string()); | 324 std::vector<gfx::Size> sizes = ParseIconSizesHTML(sizes_str.string()); |
| 338 if (sizes.empty()) { | 325 if (sizes.empty()) { |
| 339 AddErrorInfo(GetErrorPrefix() + "found icon with no valid size."); | 326 AddErrorInfo(GetErrorPrefix() + "found icon with no valid size."); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 358 const base::DictionaryValue* icon_dictionary = nullptr; | 345 const base::DictionaryValue* icon_dictionary = nullptr; |
| 359 if (!icons_list->GetDictionary(i, &icon_dictionary)) | 346 if (!icons_list->GetDictionary(i, &icon_dictionary)) |
| 360 continue; | 347 continue; |
| 361 | 348 |
| 362 Manifest::Icon icon; | 349 Manifest::Icon icon; |
| 363 icon.src = ParseIconSrc(*icon_dictionary); | 350 icon.src = ParseIconSrc(*icon_dictionary); |
| 364 // An icon MUST have a valid src. If it does not, it MUST be ignored. | 351 // An icon MUST have a valid src. If it does not, it MUST be ignored. |
| 365 if (!icon.src.is_valid()) | 352 if (!icon.src.is_valid()) |
| 366 continue; | 353 continue; |
| 367 icon.type = ParseIconType(*icon_dictionary); | 354 icon.type = ParseIconType(*icon_dictionary); |
| 368 icon.density = ParseIconDensity(*icon_dictionary); | |
| 369 icon.sizes = ParseIconSizes(*icon_dictionary); | 355 icon.sizes = ParseIconSizes(*icon_dictionary); |
| 370 | 356 |
| 371 icons.push_back(icon); | 357 icons.push_back(icon); |
| 372 } | 358 } |
| 373 | 359 |
| 374 return icons; | 360 return icons; |
| 375 } | 361 } |
| 376 | 362 |
| 377 base::NullableString16 ManifestParser::ParseRelatedApplicationPlatform( | 363 base::NullableString16 ManifestParser::ParseRelatedApplicationPlatform( |
| 378 const base::DictionaryValue& application) { | 364 const base::DictionaryValue& application) { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 return ParseString(dictionary, "gcm_sender_id", Trim); | 443 return ParseString(dictionary, "gcm_sender_id", Trim); |
| 458 } | 444 } |
| 459 | 445 |
| 460 void ManifestParser::AddErrorInfo(const std::string& error_msg, | 446 void ManifestParser::AddErrorInfo(const std::string& error_msg, |
| 461 int error_line, | 447 int error_line, |
| 462 int error_column) { | 448 int error_column) { |
| 463 errors_.push_back( | 449 errors_.push_back( |
| 464 base::WrapUnique(new ErrorInfo(error_msg, error_line, error_column))); | 450 base::WrapUnique(new ErrorInfo(error_msg, error_line, error_column))); |
| 465 } | 451 } |
| 466 } // namespace content | 452 } // namespace content |
| OLD | NEW |