| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 AddErrorInfo("property '" + key + "' ignored, type " + | 120 AddErrorInfo("property '" + key + "' ignored, type " + |
| 121 "string expected."); | 121 "string expected."); |
| 122 return base::NullableString16(); | 122 return base::NullableString16(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 if (trim == Trim) | 125 if (trim == Trim) |
| 126 base::TrimWhitespace(value, base::TRIM_ALL, &value); | 126 base::TrimWhitespace(value, base::TRIM_ALL, &value); |
| 127 return base::NullableString16(value, false); | 127 return base::NullableString16(value, false); |
| 128 } | 128 } |
| 129 | 129 |
| 130 int64_t ManifestParser::ParseColor( | 130 base::Optional<SkColor> ManifestParser::ParseColor( |
| 131 const base::DictionaryValue& dictionary, | 131 const base::DictionaryValue& dictionary, |
| 132 const std::string& key) { | 132 const std::string& key) { |
| 133 base::NullableString16 parsed_color = ParseString(dictionary, key, Trim); | 133 base::NullableString16 parsed_color = ParseString(dictionary, key, Trim); |
| 134 if (parsed_color.is_null()) | 134 if (parsed_color.is_null()) |
| 135 return Manifest::kInvalidOrMissingColor; | 135 return base::nullopt; |
| 136 | 136 |
| 137 blink::WebColor color; | 137 blink::WebColor color; |
| 138 if (!blink::WebCSSParser::parseColor(&color, parsed_color.string())) { | 138 if (!blink::WebCSSParser::parseColor(&color, parsed_color.string())) { |
| 139 AddErrorInfo("property '" + key + "' ignored, '" + | 139 AddErrorInfo("property '" + key + "' ignored, '" + |
| 140 base::UTF16ToUTF8(parsed_color.string()) + "' is not a " + | 140 base::UTF16ToUTF8(parsed_color.string()) + "' is not a " + |
| 141 "valid color."); | 141 "valid color."); |
| 142 return Manifest::kInvalidOrMissingColor; | 142 return base::nullopt; |
| 143 } | 143 } |
| 144 | 144 |
| 145 // We do this here because Java does not have an unsigned int32_t type so | 145 return color; |
| 146 // colors with high alpha values will be negative. Instead of doing the | |
| 147 // conversion after we pass over to Java, we do it here as it is easier and | |
| 148 // clearer. | |
| 149 int32_t signed_color = reinterpret_cast<int32_t&>(color); | |
| 150 return static_cast<int64_t>(signed_color); | |
| 151 } | 146 } |
| 152 | 147 |
| 153 GURL ManifestParser::ParseURL(const base::DictionaryValue& dictionary, | 148 GURL ManifestParser::ParseURL(const base::DictionaryValue& dictionary, |
| 154 const std::string& key, | 149 const std::string& key, |
| 155 const GURL& base_url) { | 150 const GURL& base_url) { |
| 156 base::NullableString16 url_str = ParseString(dictionary, key, NoTrim); | 151 base::NullableString16 url_str = ParseString(dictionary, key, NoTrim); |
| 157 if (url_str.is_null()) | 152 if (url_str.is_null()) |
| 158 return GURL(); | 153 return GURL(); |
| 159 | 154 |
| 160 GURL resolved = base_url.Resolve(url_str.string()); | 155 GURL resolved = base_url.Resolve(url_str.string()); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 } | 381 } |
| 387 | 382 |
| 388 return applications; | 383 return applications; |
| 389 } | 384 } |
| 390 | 385 |
| 391 bool ManifestParser::ParsePreferRelatedApplications( | 386 bool ManifestParser::ParsePreferRelatedApplications( |
| 392 const base::DictionaryValue& dictionary) { | 387 const base::DictionaryValue& dictionary) { |
| 393 return ParseBoolean(dictionary, "prefer_related_applications", false); | 388 return ParseBoolean(dictionary, "prefer_related_applications", false); |
| 394 } | 389 } |
| 395 | 390 |
| 396 int64_t ManifestParser::ParseThemeColor( | 391 base::Optional<SkColor> ManifestParser::ParseThemeColor( |
| 397 const base::DictionaryValue& dictionary) { | 392 const base::DictionaryValue& dictionary) { |
| 398 return ParseColor(dictionary, "theme_color"); | 393 return ParseColor(dictionary, "theme_color"); |
| 399 } | 394 } |
| 400 | 395 |
| 401 int64_t ManifestParser::ParseBackgroundColor( | 396 base::Optional<SkColor> ManifestParser::ParseBackgroundColor( |
| 402 const base::DictionaryValue& dictionary) { | 397 const base::DictionaryValue& dictionary) { |
| 403 return ParseColor(dictionary, "background_color"); | 398 return ParseColor(dictionary, "background_color"); |
| 404 } | 399 } |
| 405 | 400 |
| 406 base::NullableString16 ManifestParser::ParseGCMSenderID( | 401 base::NullableString16 ManifestParser::ParseGCMSenderID( |
| 407 const base::DictionaryValue& dictionary) { | 402 const base::DictionaryValue& dictionary) { |
| 408 return ParseString(dictionary, "gcm_sender_id", Trim); | 403 return ParseString(dictionary, "gcm_sender_id", Trim); |
| 409 } | 404 } |
| 410 | 405 |
| 411 void ManifestParser::AddErrorInfo(const std::string& error_msg, | 406 void ManifestParser::AddErrorInfo(const std::string& error_msg, |
| 412 bool critical, | 407 bool critical, |
| 413 int error_line, | 408 int error_line, |
| 414 int error_column) { | 409 int error_column) { |
| 415 errors_.push_back({error_msg, critical, error_line, error_column}); | 410 errors_.push_back({error_msg, critical, error_line, error_column}); |
| 416 } | 411 } |
| 417 | 412 |
| 418 } // namespace content | 413 } // namespace content |
| OLD | NEW |