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

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

Issue 580513002: Add support for gcm_sender_id in Manifest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@manifest_start_url
Patch Set: Created 6 years, 2 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"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 87
88 return start_url; 88 return start_url;
89 } 89 }
90 90
91 // Parses the 'display' field of the manifest, as defined in: 91 // Parses the 'display' field of the manifest, as defined in:
92 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-display-member 92 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-display-member
93 // Returns the parsed DisplayMode if any, DISPLAY_MODE_UNSPECIFIED if the 93 // Returns the parsed DisplayMode if any, DISPLAY_MODE_UNSPECIFIED if the
94 // parsing failed. 94 // parsing failed.
95 Manifest::DisplayMode ParseDisplay(const base::DictionaryValue& dictionary) { 95 Manifest::DisplayMode ParseDisplay(const base::DictionaryValue& dictionary) {
96 base::NullableString16 display = ParseString(dictionary, "display", Trim); 96 base::NullableString16 display = ParseString(dictionary, "display", Trim);
97
98 if (display.is_null()) 97 if (display.is_null())
99 return Manifest::DISPLAY_MODE_UNSPECIFIED; 98 return Manifest::DISPLAY_MODE_UNSPECIFIED;
100 99
101 if (LowerCaseEqualsASCII(display.string(), "fullscreen")) 100 if (LowerCaseEqualsASCII(display.string(), "fullscreen"))
102 return Manifest::DISPLAY_MODE_FULLSCREEN; 101 return Manifest::DISPLAY_MODE_FULLSCREEN;
103 else if (LowerCaseEqualsASCII(display.string(), "standalone")) 102 else if (LowerCaseEqualsASCII(display.string(), "standalone"))
104 return Manifest::DISPLAY_MODE_STANDALONE; 103 return Manifest::DISPLAY_MODE_STANDALONE;
105 else if (LowerCaseEqualsASCII(display.string(), "minimal-ui")) 104 else if (LowerCaseEqualsASCII(display.string(), "minimal-ui"))
106 return Manifest::DISPLAY_MODE_MINIMAL_UI; 105 return Manifest::DISPLAY_MODE_MINIMAL_UI;
107 else if (LowerCaseEqualsASCII(display.string(), "browser")) 106 else if (LowerCaseEqualsASCII(display.string(), "browser"))
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 icon.type = ParseIconType(*icon_dictionary); 267 icon.type = ParseIconType(*icon_dictionary);
269 icon.density = ParseIconDensity(*icon_dictionary); 268 icon.density = ParseIconDensity(*icon_dictionary);
270 icon.sizes = ParseIconSizes(*icon_dictionary); 269 icon.sizes = ParseIconSizes(*icon_dictionary);
271 270
272 icons.push_back(icon); 271 icons.push_back(icon);
273 } 272 }
274 273
275 return icons; 274 return icons;
276 } 275 }
277 276
277 // Parses the 'gcm_sender_id' field of the manifest.
278 // This is a proprietary extension of the Web Manifest specification.
279 // Returns the parsed string if any, a null string if the parsing failed.
280 base::NullableString16 ParseGCMSenderID(
281 const base::DictionaryValue& dictionary) {
282 return ParseString(dictionary, "gcm_sender_id", Trim);
283 }
284
278 } // anonymous namespace 285 } // anonymous namespace
279 286
280 Manifest ManifestParser::Parse(const base::StringPiece& json, 287 Manifest ManifestParser::Parse(const base::StringPiece& json,
281 const GURL& manifest_url, 288 const GURL& manifest_url,
282 const GURL& document_url) { 289 const GURL& document_url) {
283 scoped_ptr<base::Value> value(base::JSONReader::Read(json)); 290 scoped_ptr<base::Value> value(base::JSONReader::Read(json));
284 if (!value) { 291 if (!value) {
285 // TODO(mlamouri): get the JSON parsing error and report it to the developer 292 // TODO(mlamouri): get the JSON parsing error and report it to the developer
286 // console. 293 // console.
287 return Manifest(); 294 return Manifest();
(...skipping 12 matching lines...) Expand all
300 } 307 }
301 308
302 Manifest manifest; 309 Manifest manifest;
303 310
304 manifest.name = ParseName(*dictionary); 311 manifest.name = ParseName(*dictionary);
305 manifest.short_name = ParseShortName(*dictionary); 312 manifest.short_name = ParseShortName(*dictionary);
306 manifest.start_url = ParseStartURL(*dictionary, manifest_url, document_url); 313 manifest.start_url = ParseStartURL(*dictionary, manifest_url, document_url);
307 manifest.display = ParseDisplay(*dictionary); 314 manifest.display = ParseDisplay(*dictionary);
308 manifest.orientation = ParseOrientation(*dictionary); 315 manifest.orientation = ParseOrientation(*dictionary);
309 manifest.icons = ParseIcons(*dictionary, manifest_url); 316 manifest.icons = ParseIcons(*dictionary, manifest_url);
317 manifest.gcm_sender_id = ParseGCMSenderID(*dictionary);
310 318
311 return manifest; 319 return manifest;
312 } 320 }
313 321
314 } // namespace content 322 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/manifest/manifest_manager.cc ('k') | content/renderer/manifest/manifest_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698