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

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: Reflect change in Blink patch 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 <inttypes.h>
8
7 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
8 #include "base/strings/nullable_string16.h" 10 #include "base/strings/nullable_string16.h"
9 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h" 12 #include "base/strings/string_split.h"
11 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h" 15 #include "base/values.h"
14 #include "content/public/common/manifest.h" 16 #include "content/public/common/manifest.h"
15 #include "content/renderer/manifest/manifest_uma_util.h" 17 #include "content/renderer/manifest/manifest_uma_util.h"
18 #include "third_party/WebKit/public/platform/WebColor.h"
19 #include "third_party/WebKit/public/platform/WebString.h"
20 #include "third_party/WebKit/public/web/WebCSSParser.h"
21 #include "third_party/skia/include/core/SkColor.h"
16 #include "ui/gfx/geometry/size.h" 22 #include "ui/gfx/geometry/size.h"
17 23
18 namespace content { 24 namespace content {
19 25
20 namespace { 26 namespace {
21 27
22 // Helper function that returns whether the given |str| is a valid width or 28 // Helper function that returns whether the given |str| is a valid width or
23 // height value for an icon sizes per: 29 // height value for an icon sizes per:
24 // https://html.spec.whatwg.org/multipage/semantics.html#attr-link-sizes 30 // https://html.spec.whatwg.org/multipage/semantics.html#attr-link-sizes
25 bool IsValidIconWidthOrHeight(const std::string& str) { 31 bool IsValidIconWidthOrHeight(const std::string& str) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 ManifestUmaUtil::ParseFailed(); 123 ManifestUmaUtil::ParseFailed();
118 failed_ = true; 124 failed_ = true;
119 return; 125 return;
120 } 126 }
121 DCHECK(dictionary); 127 DCHECK(dictionary);
122 128
123 manifest_.name = ParseName(*dictionary); 129 manifest_.name = ParseName(*dictionary);
124 manifest_.short_name = ParseShortName(*dictionary); 130 manifest_.short_name = ParseShortName(*dictionary);
125 manifest_.start_url = ParseStartURL(*dictionary); 131 manifest_.start_url = ParseStartURL(*dictionary);
126 manifest_.display = ParseDisplay(*dictionary); 132 manifest_.display = ParseDisplay(*dictionary);
133 manifest_.theme_color = ParseThemeColor(*dictionary);
127 manifest_.orientation = ParseOrientation(*dictionary); 134 manifest_.orientation = ParseOrientation(*dictionary);
128 manifest_.icons = ParseIcons(*dictionary); 135 manifest_.icons = ParseIcons(*dictionary);
129 manifest_.related_applications = ParseRelatedApplications(*dictionary); 136 manifest_.related_applications = ParseRelatedApplications(*dictionary);
130 manifest_.prefer_related_applications = 137 manifest_.prefer_related_applications =
131 ParsePreferRelatedApplications(*dictionary); 138 ParsePreferRelatedApplications(*dictionary);
132 manifest_.gcm_sender_id = ParseGCMSenderID(*dictionary); 139 manifest_.gcm_sender_id = ParseGCMSenderID(*dictionary);
133 140
134 ManifestUmaUtil::ParseSucceeded(manifest_); 141 ManifestUmaUtil::ParseSucceeded(manifest_);
135 } 142 }
136 143
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 215
209 if (start_url.GetOrigin() != document_url_.GetOrigin()) { 216 if (start_url.GetOrigin() != document_url_.GetOrigin()) {
210 errors_.push_back(GetErrorPrefix() + "property 'start_url' ignored, should " 217 errors_.push_back(GetErrorPrefix() + "property 'start_url' ignored, should "
211 "be same origin as document."); 218 "be same origin as document.");
212 return GURL(); 219 return GURL();
213 } 220 }
214 221
215 return start_url; 222 return start_url;
216 } 223 }
217 224
225 int64_t ManifestParser::ParseThemeColor(
226 const base::DictionaryValue& dictionary) {
227 base::NullableString16 display = ParseString(dictionary, "theme_color", Trim);
228 if (display.is_null())
mlamouri (slow - plz ping) 2015/07/16 12:35:41 s/display/theme_color/g
Lalit Maganti 2015/07/16 14:49:02 Done.
229 return Manifest::kInvalidThemeColor;
230
231 blink::WebColor color = SK_ColorTRANSPARENT;
mlamouri (slow - plz ping) 2015/07/16 12:35:41 I don't think you need to initialize that.
Lalit Maganti 2015/07/16 14:49:02 Done.
232
233 bool success = blink::WebCSSParser::parseColor(&color, display.string());
234 if (!success) {
mlamouri (slow - plz ping) 2015/07/16 12:35:40 You don't need the |success| variable.
Lalit Maganti 2015/07/16 14:49:01 Done.
235 errors_.push_back(GetErrorPrefix() +
236 "unable to parse 'theme_color' as color.");
mlamouri (slow - plz ping) 2015/07/16 12:35:40 nit: follow the same language as the other errors:
Lalit Maganti 2015/07/16 14:49:02 Almost done - the concatenation of the strings did
237 return Manifest::kInvalidThemeColor;
238 }
239
240 int64_t int_color = color;
241 return int_color;
mlamouri (slow - plz ping) 2015/07/16 12:35:41 return static_cast<int64>(color);
Lalit Maganti 2015/07/16 14:49:01 Done.
242 }
243
218 Manifest::DisplayMode ManifestParser::ParseDisplay( 244 Manifest::DisplayMode ManifestParser::ParseDisplay(
219 const base::DictionaryValue& dictionary) { 245 const base::DictionaryValue& dictionary) {
220 base::NullableString16 display = ParseString(dictionary, "display", Trim); 246 base::NullableString16 display = ParseString(dictionary, "display", Trim);
221 if (display.is_null()) 247 if (display.is_null())
222 return Manifest::DISPLAY_MODE_UNSPECIFIED; 248 return Manifest::DISPLAY_MODE_UNSPECIFIED;
223 249
224 if (base::LowerCaseEqualsASCII(display.string(), "fullscreen")) 250 if (base::LowerCaseEqualsASCII(display.string(), "fullscreen"))
225 return Manifest::DISPLAY_MODE_FULLSCREEN; 251 return Manifest::DISPLAY_MODE_FULLSCREEN;
226 else if (base::LowerCaseEqualsASCII(display.string(), "standalone")) 252 else if (base::LowerCaseEqualsASCII(display.string(), "standalone"))
227 return Manifest::DISPLAY_MODE_STANDALONE; 253 return Manifest::DISPLAY_MODE_STANDALONE;
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 const base::DictionaryValue& dictionary) { 432 const base::DictionaryValue& dictionary) {
407 return ParseBoolean(dictionary, "prefer_related_applications", false); 433 return ParseBoolean(dictionary, "prefer_related_applications", false);
408 } 434 }
409 435
410 base::NullableString16 ManifestParser::ParseGCMSenderID( 436 base::NullableString16 ManifestParser::ParseGCMSenderID(
411 const base::DictionaryValue& dictionary) { 437 const base::DictionaryValue& dictionary) {
412 return ParseString(dictionary, "gcm_sender_id", Trim); 438 return ParseString(dictionary, "gcm_sender_id", Trim);
413 } 439 }
414 440
415 } // namespace content 441 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698