| 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 #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 <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/strings/nullable_string16.h" | 13 #include "base/strings/nullable_string16.h" |
| 14 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
| 15 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 16 #include "content/public/common/manifest.h" | 16 #include "content/public/common/manifest.h" |
| 17 #include "content/renderer/manifest/manifest_debug_info.h" |
| 17 | 18 |
| 18 class GURL; | 19 class GURL; |
| 19 | 20 |
| 20 namespace base { | 21 namespace base { |
| 21 class DictionaryValue; | 22 class DictionaryValue; |
| 22 } | 23 } |
| 23 | 24 |
| 24 namespace content { | 25 namespace content { |
| 25 | 26 |
| 26 // ManifestParser handles the logic of parsing the Web Manifest from a string. | 27 // ManifestParser handles the logic of parsing the Web Manifest from a string. |
| 27 // It implements: | 28 // It implements: |
| 28 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-manifest | 29 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-manifest |
| 29 class CONTENT_EXPORT ManifestParser { | 30 class CONTENT_EXPORT ManifestParser { |
| 30 public: | 31 public: |
| 31 class ErrorInfo { | |
| 32 public: | |
| 33 ErrorInfo(const std::string& error_msg, int error_line, int error_column) | |
| 34 : error_msg(error_msg), | |
| 35 error_line(error_line), | |
| 36 error_column(error_column) {} | |
| 37 const std::string error_msg; | |
| 38 const int error_line; | |
| 39 const int error_column; | |
| 40 }; | |
| 41 ManifestParser(const base::StringPiece& data, | 32 ManifestParser(const base::StringPiece& data, |
| 42 const GURL& manifest_url, | 33 const GURL& manifest_url, |
| 43 const GURL& document_url); | 34 const GURL& document_url); |
| 44 ~ManifestParser(); | 35 ~ManifestParser(); |
| 45 | 36 |
| 46 // Parse the Manifest from a string using following: | 37 // Parse the Manifest from a string using following: |
| 47 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-manifest | 38 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-manifest |
| 48 void Parse(); | 39 void Parse(); |
| 49 | 40 |
| 50 const Manifest& manifest() const; | 41 const Manifest& manifest() const; |
| 51 const std::vector<std::unique_ptr<ErrorInfo>>& errors() const; | |
| 52 bool failed() const; | 42 bool failed() const; |
| 53 | 43 |
| 44 void TakeErrors(std::vector<ManifestDebugInfo::Error>* errors); |
| 45 |
| 54 private: | 46 private: |
| 55 // Used to indicate whether to strip whitespace when parsing a string. | 47 // Used to indicate whether to strip whitespace when parsing a string. |
| 56 enum TrimType { | 48 enum TrimType { |
| 57 Trim, | 49 Trim, |
| 58 NoTrim | 50 NoTrim |
| 59 }; | 51 }; |
| 60 | 52 |
| 61 // Helper function to parse booleans present on a given |dictionary| in a | 53 // Helper function to parse booleans present on a given |dictionary| in a |
| 62 // given field identified by its |key|. | 54 // given field identified by its |key|. |
| 63 // Returns the parsed boolean if any, or |default_value| if parsing failed. | 55 // Returns the parsed boolean if any, or |default_value| if parsing failed. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 // Manifest::kInvalidOrMissingColor if the parsing failed. | 175 // Manifest::kInvalidOrMissingColor if the parsing failed. |
| 184 int64_t ParseBackgroundColor(const base::DictionaryValue& dictionary); | 176 int64_t ParseBackgroundColor(const base::DictionaryValue& dictionary); |
| 185 | 177 |
| 186 // Parses the 'gcm_sender_id' field of the manifest. | 178 // Parses the 'gcm_sender_id' field of the manifest. |
| 187 // This is a proprietary extension of the Web Manifest specification. | 179 // This is a proprietary extension of the Web Manifest specification. |
| 188 // Returns the parsed string if any, a null string if the parsing failed. | 180 // Returns the parsed string if any, a null string if the parsing failed. |
| 189 base::NullableString16 ParseGCMSenderID( | 181 base::NullableString16 ParseGCMSenderID( |
| 190 const base::DictionaryValue& dictionary); | 182 const base::DictionaryValue& dictionary); |
| 191 | 183 |
| 192 void AddErrorInfo(const std::string& error_msg, | 184 void AddErrorInfo(const std::string& error_msg, |
| 185 bool critical = false, |
| 193 int error_line = 0, | 186 int error_line = 0, |
| 194 int error_column = 0); | 187 int error_column = 0); |
| 195 | 188 |
| 196 const base::StringPiece& data_; | 189 const base::StringPiece& data_; |
| 197 GURL manifest_url_; | 190 GURL manifest_url_; |
| 198 GURL document_url_; | 191 GURL document_url_; |
| 199 | 192 |
| 200 bool failed_; | 193 bool failed_; |
| 201 Manifest manifest_; | 194 Manifest manifest_; |
| 202 std::vector<std::unique_ptr<ErrorInfo>> errors_; | 195 std::vector<ManifestDebugInfo::Error> errors_; |
| 203 | 196 |
| 204 DISALLOW_COPY_AND_ASSIGN(ManifestParser); | 197 DISALLOW_COPY_AND_ASSIGN(ManifestParser); |
| 205 }; | 198 }; |
| 206 | 199 |
| 207 } // namespace content | 200 } // namespace content |
| 208 | 201 |
| 209 #endif // CONTENT_RENDERER_MANIFEST_MANIFEST_PARSER_H_ | 202 #endif // CONTENT_RENDERER_MANIFEST_MANIFEST_PARSER_H_ |
| OLD | NEW |