Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(217)

Side by Side Diff: content/renderer/manifest/manifest_parser.cc

Issue 1235883007: manifest: add theme_color value to the manifest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use UTF16ToUTF8 instead of assuming ASCII Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
16 #include "ui/gfx/geometry/size.h" 19 #include "ui/gfx/geometry/size.h"
17 20
18 namespace content { 21 namespace content {
19 22
20 namespace { 23 namespace {
21 24
22 // Helper function that returns whether the given |str| is a valid width or 25 // Helper function that returns whether the given |str| is a valid width or
23 // height value for an icon sizes per: 26 // height value for an icon sizes per:
24 // https://html.spec.whatwg.org/multipage/semantics.html#attr-link-sizes 27 // https://html.spec.whatwg.org/multipage/semantics.html#attr-link-sizes
25 bool IsValidIconWidthOrHeight(const std::string& str) { 28 bool IsValidIconWidthOrHeight(const std::string& str) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 125
123 manifest_.name = ParseName(*dictionary); 126 manifest_.name = ParseName(*dictionary);
124 manifest_.short_name = ParseShortName(*dictionary); 127 manifest_.short_name = ParseShortName(*dictionary);
125 manifest_.start_url = ParseStartURL(*dictionary); 128 manifest_.start_url = ParseStartURL(*dictionary);
126 manifest_.display = ParseDisplay(*dictionary); 129 manifest_.display = ParseDisplay(*dictionary);
127 manifest_.orientation = ParseOrientation(*dictionary); 130 manifest_.orientation = ParseOrientation(*dictionary);
128 manifest_.icons = ParseIcons(*dictionary); 131 manifest_.icons = ParseIcons(*dictionary);
129 manifest_.related_applications = ParseRelatedApplications(*dictionary); 132 manifest_.related_applications = ParseRelatedApplications(*dictionary);
130 manifest_.prefer_related_applications = 133 manifest_.prefer_related_applications =
131 ParsePreferRelatedApplications(*dictionary); 134 ParsePreferRelatedApplications(*dictionary);
135 manifest_.theme_color = ParseThemeColor(*dictionary);
132 manifest_.gcm_sender_id = ParseGCMSenderID(*dictionary); 136 manifest_.gcm_sender_id = ParseGCMSenderID(*dictionary);
133 137
134 ManifestUmaUtil::ParseSucceeded(manifest_); 138 ManifestUmaUtil::ParseSucceeded(manifest_);
135 } 139 }
136 140
137 const Manifest& ManifestParser::manifest() const { 141 const Manifest& ManifestParser::manifest() const {
138 return manifest_; 142 return manifest_;
139 } 143 }
140 144
141 const std::vector<std::string>& ManifestParser::errors() const { 145 const std::vector<std::string>& ManifestParser::errors() const {
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 } 404 }
401 405
402 return applications; 406 return applications;
403 } 407 }
404 408
405 bool ManifestParser::ParsePreferRelatedApplications( 409 bool ManifestParser::ParsePreferRelatedApplications(
406 const base::DictionaryValue& dictionary) { 410 const base::DictionaryValue& dictionary) {
407 return ParseBoolean(dictionary, "prefer_related_applications", false); 411 return ParseBoolean(dictionary, "prefer_related_applications", false);
408 } 412 }
409 413
414 int64_t ManifestParser::ParseThemeColor(
415 const base::DictionaryValue& dictionary) {
416 base::NullableString16 theme_color = ParseString(
417 dictionary, "theme_color", Trim);
418 if (theme_color.is_null())
419 return Manifest::kInvalidOrMissingThemeColor;
420
421 blink::WebColor color;
422 if (!blink::WebCSSParser::parseColor(&color, theme_color.string())) {
423 errors_.push_back(GetErrorPrefix() +
424 "property 'theme_color' ignored, " +
425 base::UTF16ToUTF8(theme_color.string()) +
mlamouri (slow - plz ping) 2015/07/16 17:19:00 nit: could you add ' ' around the string? ie: "
Lalit Maganti 2015/07/16 18:37:23 Done.
426 " is not a valid color.");
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
OLDNEW
« no previous file with comments | « content/renderer/manifest/manifest_parser.h ('k') | content/renderer/manifest/manifest_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698