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_PUBLIC_RENDERER_MANIFEST_PARSER_H_ |
6 #define CONTENT_RENDERER_MANIFEST_MANIFEST_PARSER_H_ | 6 #define CONTENT_PUBLIC_RENDERER_MANIFEST_PARSER_H_ |
7 | 7 |
8 #include "base/strings/nullable_string16.h" | 8 #include "base/strings/nullable_string16.h" |
9 #include "base/strings/string_piece.h" | 9 #include "base/strings/string_piece.h" |
10 #include "content/common/content_export.h" | 10 #include "content/common/content_export.h" |
11 #include "content/public/common/manifest.h" | 11 #include "content/public/common/manifest.h" |
12 | 12 |
13 class GURL; | 13 class GURL; |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 class DictionaryValue; | 16 class DictionaryValue; |
17 } | 17 } |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
21 // ManifestParser handles the logic of parsing the Web Manifest from a string. | 21 // ManifestParser handles the logic of parsing the Web Manifest from a string. |
22 // It implements: | 22 // It implements: |
23 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-manifest | 23 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-manifest |
24 class CONTENT_EXPORT ManifestParser { | 24 class CONTENT_EXPORT ManifestParser { |
25 public: | 25 public: |
26 ManifestParser(const base::StringPiece& data, | 26 // Returns an implementation of the ManifestParser. |
27 const GURL& manifest_url, | 27 static scoped_ptr<ManifestParser> Get(); |
28 const GURL& document_url); | 28 virtual ~ManifestParser(); |
29 ~ManifestParser(); | |
30 | 29 |
31 // Parse the Manifest from a string using following: | 30 // Parse the Manifest from a string using following: |
32 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-manifest | 31 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-manifest |
33 void Parse(); | 32 void Parse(const base::StringPiece& data, |
33 const GURL& manifest_url, | |
34 const GURL& document_url); | |
34 | 35 |
35 const Manifest& manifest() const; | 36 const Manifest& manifest() const; |
36 const std::vector<std::string>& errors() const; | 37 const std::vector<std::string>& errors() const; |
37 bool failed() const; | 38 bool failed() const; |
38 | 39 |
39 private: | 40 protected: |
40 // Used to indicate whether to strip whitespace when parsing a string. | 41 // Used to indicate whether to strip whitespace when parsing a string. |
41 enum TrimType { | 42 enum TrimType { |
42 Trim, | 43 Trim, |
43 NoTrim | 44 NoTrim |
44 }; | 45 }; |
45 | 46 |
47 // It is not possible to create a direct instance of the ManifestParser to | |
48 // allow it to be overridden with ContentRendererClient. | |
Avi (use Gerrit)
2015/02/20 20:07:57
I can't parse this sentence. Rather than "it is no
| |
49 ManifestParser(); | |
50 | |
51 // Parses extensions of the ManifestParser. This is expected to be implemented | |
52 // by objects returned from ContentRendererClient::OverrideManifestParser(). | |
53 // That call happens before the regular parsing of the Manifest to prevent | |
54 // manifest parsing extensions to override regular parsing. | |
55 // https://w3c.github.io/manifest/#dfn-extension-point | |
56 virtual void ParseExtensionPoint(const base::DictionaryValue& dictionary); | |
57 | |
46 // Helper function to parse booleans present on a given |dictionary| in a | 58 // Helper function to parse booleans present on a given |dictionary| in a |
47 // given field identified by its |key|. | 59 // given field identified by its |key|. |
48 // Returns the parsed boolean if any, or |default_value| if parsing failed. | 60 // Returns the parsed boolean if any, or |default_value| if parsing failed. |
49 bool ParseBoolean(const base::DictionaryValue& dictionary, | 61 bool ParseBoolean(const base::DictionaryValue& dictionary, |
50 const std::string& key, | 62 const std::string& key, |
51 bool default_value); | 63 bool default_value); |
52 | 64 |
53 // Helper function to parse strings present on a given |dictionary| in a given | 65 // Helper function to parse strings present on a given |dictionary| in a given |
54 // field identified by its |key|. | 66 // field identified by its |key|. |
55 // Returns the parsed string if any, a null string if the parsing failed. | 67 // Returns the parsed string if any, a null string if the parsing failed. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 // by gfx::Size(0, 0). | 129 // by gfx::Size(0, 0). |
118 std::vector<gfx::Size> ParseIconSizes(const base::DictionaryValue& icon); | 130 std::vector<gfx::Size> ParseIconSizes(const base::DictionaryValue& icon); |
119 | 131 |
120 // Parses the 'icons' field of a Manifest, as defined in: | 132 // Parses the 'icons' field of a Manifest, as defined in: |
121 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-icons-member | 133 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-icons-member |
122 // Returns a vector of Manifest::Icon with the successfully parsed icons, if | 134 // Returns a vector of Manifest::Icon with the successfully parsed icons, if |
123 // any. An empty vector if the field was not present or empty. | 135 // any. An empty vector if the field was not present or empty. |
124 std::vector<Manifest::Icon> ParseIcons( | 136 std::vector<Manifest::Icon> ParseIcons( |
125 const base::DictionaryValue& dictionary); | 137 const base::DictionaryValue& dictionary); |
126 | 138 |
127 // Parses the 'gcm_sender_id' field of the manifest. | |
128 // This is a proprietary extension of the Web Manifest specification. | |
129 // Returns the parsed string if any, a null string if the parsing failed. | |
130 base::NullableString16 ParseGCMSenderID( | |
131 const base::DictionaryValue& dictionary); | |
132 | |
133 // Parses the 'gcm_user_visible_only' field of the manifest. | |
134 // This is a proprietary extension of the Web Manifest specification. | |
135 // Returns true iff the string could be parsed as the boolean true. | |
136 bool ParseGCMUserVisibleOnly(const base::DictionaryValue& dictionary); | |
137 | |
138 const base::StringPiece& data_; | |
139 GURL manifest_url_; | 139 GURL manifest_url_; |
140 GURL document_url_; | 140 GURL document_url_; |
141 | 141 |
142 bool failed_; | 142 bool failed_; |
143 Manifest manifest_; | 143 Manifest manifest_; |
144 std::vector<std::string> errors_; | 144 std::vector<std::string> errors_; |
145 | 145 |
146 private: | |
146 DISALLOW_COPY_AND_ASSIGN(ManifestParser); | 147 DISALLOW_COPY_AND_ASSIGN(ManifestParser); |
147 }; | 148 }; |
148 | 149 |
149 } // namespace content | 150 } // namespace content |
150 | 151 |
151 #endif // CONTENT_RENDERER_MANIFEST_MANIFEST_PARSER_H_ | 152 #endif // CONTENT_PUBLIC_RENDERER_MANIFEST_PARSER_H_ |
OLD | NEW |