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

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

Issue 1571633002: Pass Manifest JSON paser error line and column number to console. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add comments Created 4 years, 11 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 #ifndef CONTENT_RENDERER_MANIFEST_MANIFEST_PARSER_H_ 5 #ifndef CONTENT_RENDERER_MANIFEST_MANIFEST_PARSER_H_
6 #define CONTENT_RENDERER_MANIFEST_MANIFEST_PARSER_H_ 6 #define CONTENT_RENDERER_MANIFEST_MANIFEST_PARSER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/strings/nullable_string16.h" 11 #include "base/strings/nullable_string16.h"
12 #include "base/strings/string_piece.h" 12 #include "base/strings/string_piece.h"
13 #include "content/common/content_export.h" 13 #include "content/common/content_export.h"
14 #include "content/public/common/manifest.h" 14 #include "content/public/common/manifest.h"
15 15
16 class GURL; 16 class GURL;
17 17
18 namespace base { 18 namespace base {
19 class DictionaryValue; 19 class DictionaryValue;
20 } 20 }
21 21
22 namespace content { 22 namespace content {
23 23
24 // ManifestParser handles the logic of parsing the Web Manifest from a string. 24 // ManifestParser handles the logic of parsing the Web Manifest from a string.
25 // It implements: 25 // It implements:
26 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-manifest 26 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-manifest
27 class CONTENT_EXPORT ManifestParser { 27 class CONTENT_EXPORT ManifestParser {
28 public: 28 public:
29 class ErrorInfo {
30 public:
31 ErrorInfo(const std::string& error_msg, int error_line, int error_column)
32 : error_msg(error_msg),
33 error_line(error_line),
34 error_column(error_column) {}
35 const std::string error_msg;
36 const int error_line;
37 const int error_column;
38 };
29 ManifestParser(const base::StringPiece& data, 39 ManifestParser(const base::StringPiece& data,
30 const GURL& manifest_url, 40 const GURL& manifest_url,
31 const GURL& document_url); 41 const GURL& document_url);
32 ~ManifestParser(); 42 ~ManifestParser();
33 43
34 // Parse the Manifest from a string using following: 44 // Parse the Manifest from a string using following:
35 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-manifest 45 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-manifest
36 void Parse(); 46 void Parse();
37 47
38 const Manifest& manifest() const; 48 const Manifest& manifest() const;
39 const std::vector<std::string>& errors() const; 49 const std::vector<scoped_ptr<ErrorInfo>>& errors() const;
40 bool failed() const; 50 bool failed() const;
41 51
42 private: 52 private:
43 // Used to indicate whether to strip whitespace when parsing a string. 53 // Used to indicate whether to strip whitespace when parsing a string.
44 enum TrimType { 54 enum TrimType {
45 Trim, 55 Trim,
46 NoTrim 56 NoTrim
47 }; 57 };
48 58
49 // Helper function to parse booleans present on a given |dictionary| in a 59 // Helper function to parse booleans present on a given |dictionary| in a
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // Returns the parsed background color if any, 186 // Returns the parsed background color if any,
177 // Manifest::kInvalidOrMissingColor if the parsing failed. 187 // Manifest::kInvalidOrMissingColor if the parsing failed.
178 int64_t ParseBackgroundColor(const base::DictionaryValue& dictionary); 188 int64_t ParseBackgroundColor(const base::DictionaryValue& dictionary);
179 189
180 // Parses the 'gcm_sender_id' field of the manifest. 190 // Parses the 'gcm_sender_id' field of the manifest.
181 // This is a proprietary extension of the Web Manifest specification. 191 // This is a proprietary extension of the Web Manifest specification.
182 // Returns the parsed string if any, a null string if the parsing failed. 192 // Returns the parsed string if any, a null string if the parsing failed.
183 base::NullableString16 ParseGCMSenderID( 193 base::NullableString16 ParseGCMSenderID(
184 const base::DictionaryValue& dictionary); 194 const base::DictionaryValue& dictionary);
185 195
196 void AddErrorInfo(const std::string& error_msg,
197 int error_line = 0,
198 int error_column = 0);
199
186 const base::StringPiece& data_; 200 const base::StringPiece& data_;
187 GURL manifest_url_; 201 GURL manifest_url_;
188 GURL document_url_; 202 GURL document_url_;
189 203
190 bool failed_; 204 bool failed_;
191 Manifest manifest_; 205 Manifest manifest_;
192 std::vector<std::string> errors_; 206 std::vector<scoped_ptr<ErrorInfo>> errors_;
193 207
194 DISALLOW_COPY_AND_ASSIGN(ManifestParser); 208 DISALLOW_COPY_AND_ASSIGN(ManifestParser);
195 }; 209 };
196 210
197 } // namespace content 211 } // namespace content
198 212
199 #endif // CONTENT_RENDERER_MANIFEST_MANIFEST_PARSER_H_ 213 #endif // CONTENT_RENDERER_MANIFEST_MANIFEST_PARSER_H_
OLDNEW
« no previous file with comments | « content/renderer/manifest/manifest_manager.cc ('k') | content/renderer/manifest/manifest_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698