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" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/values.h" | 13 #include "base/values.h" |
14 #include "content/public/common/manifest.h" | 14 #include "content/public/common/manifest.h" |
15 #include "content/renderer/manifest/manifest_uma_util.h" | 15 #include "content/renderer/manifest/manifest_uma_util.h" |
16 #include "third_party/WebKit/public/platform/WebColor.h" | |
17 #include "third_party/WebKit/public/platform/WebString.h" | |
18 #include "third_party/WebKit/public/web/WebCSSParser.h" | |
19 #include "third_party/skia/include/core/SkColor.h" | |
mlamouri (slow - plz ping)
2015/07/16 14:53:31
I don't think you need SkColor.
Lalit Maganti
2015/07/16 15:12:28
Done.
| |
16 #include "ui/gfx/geometry/size.h" | 20 #include "ui/gfx/geometry/size.h" |
17 | 21 |
18 namespace content { | 22 namespace content { |
19 | 23 |
20 namespace { | 24 namespace { |
21 | 25 |
22 // Helper function that returns whether the given |str| is a valid width or | 26 // Helper function that returns whether the given |str| is a valid width or |
23 // height value for an icon sizes per: | 27 // height value for an icon sizes per: |
24 // https://html.spec.whatwg.org/multipage/semantics.html#attr-link-sizes | 28 // https://html.spec.whatwg.org/multipage/semantics.html#attr-link-sizes |
25 bool IsValidIconWidthOrHeight(const std::string& str) { | 29 bool IsValidIconWidthOrHeight(const std::string& str) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 | 126 |
123 manifest_.name = ParseName(*dictionary); | 127 manifest_.name = ParseName(*dictionary); |
124 manifest_.short_name = ParseShortName(*dictionary); | 128 manifest_.short_name = ParseShortName(*dictionary); |
125 manifest_.start_url = ParseStartURL(*dictionary); | 129 manifest_.start_url = ParseStartURL(*dictionary); |
126 manifest_.display = ParseDisplay(*dictionary); | 130 manifest_.display = ParseDisplay(*dictionary); |
127 manifest_.orientation = ParseOrientation(*dictionary); | 131 manifest_.orientation = ParseOrientation(*dictionary); |
128 manifest_.icons = ParseIcons(*dictionary); | 132 manifest_.icons = ParseIcons(*dictionary); |
129 manifest_.related_applications = ParseRelatedApplications(*dictionary); | 133 manifest_.related_applications = ParseRelatedApplications(*dictionary); |
130 manifest_.prefer_related_applications = | 134 manifest_.prefer_related_applications = |
131 ParsePreferRelatedApplications(*dictionary); | 135 ParsePreferRelatedApplications(*dictionary); |
136 manifest_.theme_color = ParseThemeColor(*dictionary); | |
132 manifest_.gcm_sender_id = ParseGCMSenderID(*dictionary); | 137 manifest_.gcm_sender_id = ParseGCMSenderID(*dictionary); |
133 | 138 |
134 ManifestUmaUtil::ParseSucceeded(manifest_); | 139 ManifestUmaUtil::ParseSucceeded(manifest_); |
135 } | 140 } |
136 | 141 |
137 const Manifest& ManifestParser::manifest() const { | 142 const Manifest& ManifestParser::manifest() const { |
138 return manifest_; | 143 return manifest_; |
139 } | 144 } |
140 | 145 |
141 const std::vector<std::string>& ManifestParser::errors() const { | 146 const std::vector<std::string>& ManifestParser::errors() const { |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 } | 405 } |
401 | 406 |
402 return applications; | 407 return applications; |
403 } | 408 } |
404 | 409 |
405 bool ManifestParser::ParsePreferRelatedApplications( | 410 bool ManifestParser::ParsePreferRelatedApplications( |
406 const base::DictionaryValue& dictionary) { | 411 const base::DictionaryValue& dictionary) { |
407 return ParseBoolean(dictionary, "prefer_related_applications", false); | 412 return ParseBoolean(dictionary, "prefer_related_applications", false); |
408 } | 413 } |
409 | 414 |
415 int64_t ManifestParser::ParseThemeColor( | |
416 const base::DictionaryValue& dictionary) { | |
417 base::NullableString16 theme_color = ParseString( | |
418 dictionary, "theme_color", Trim); | |
419 if (theme_color.is_null()) | |
420 return Manifest::kInvalidOrMissingThemeColor; | |
421 | |
422 blink::WebColor color; | |
423 if (!blink::WebCSSParser::parseColor(&color, theme_color.string())) { | |
424 errors_.push_back(GetErrorPrefix() + | |
425 "property 'theme_color' ignored, " + | |
426 "invalid color specified."); | |
mlamouri (slow - plz ping)
2015/07/16 14:53:31
Could you include theme_color.string() it would be
mlamouri (slow - plz ping)
2015/07/16 15:00:49
You can use UTF16ToASCII(theme_color.string()).
Lalit Maganti
2015/07/16 15:12:28
Done
| |
427 return Manifest::kInvalidOrMissingThemeColor; | |
428 } | |
429 | |
430 return static_cast<int64_t>(color); | |
431 } | |
432 | |
410 base::NullableString16 ManifestParser::ParseGCMSenderID( | 433 base::NullableString16 ManifestParser::ParseGCMSenderID( |
411 const base::DictionaryValue& dictionary) { | 434 const base::DictionaryValue& dictionary) { |
412 return ParseString(dictionary, "gcm_sender_id", Trim); | 435 return ParseString(dictionary, "gcm_sender_id", Trim); |
413 } | 436 } |
414 | 437 |
415 } // namespace content | 438 } // namespace content |
OLD | NEW |