Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / content / renderer / manifest / manifest_parser.h
blob581f76e96d76b55f4c2da30af6eb0e152e0020ce
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_MANIFEST_MANIFEST_PARSER_H_
6 #define CONTENT_RENDERER_MANIFEST_MANIFEST_PARSER_H_
8 #include <stdint.h>
10 #include "base/strings/nullable_string16.h"
11 #include "base/strings/string_piece.h"
12 #include "content/common/content_export.h"
13 #include "content/public/common/manifest.h"
15 class GURL;
17 namespace base {
18 class DictionaryValue;
21 namespace content {
23 // ManifestParser handles the logic of parsing the Web Manifest from a string.
24 // It implements:
25 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-manifest
26 class CONTENT_EXPORT ManifestParser {
27 public:
28 ManifestParser(const base::StringPiece& data,
29 const GURL& manifest_url,
30 const GURL& document_url);
31 ~ManifestParser();
33 // Parse the Manifest from a string using following:
34 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-manifest
35 void Parse();
37 const Manifest& manifest() const;
38 const std::vector<std::string>& errors() const;
39 bool failed() const;
41 private:
42 // Used to indicate whether to strip whitespace when parsing a string.
43 enum TrimType {
44 Trim,
45 NoTrim
48 // Helper function to parse booleans present on a given |dictionary| in a
49 // given field identified by its |key|.
50 // Returns the parsed boolean if any, or |default_value| if parsing failed.
51 bool ParseBoolean(const base::DictionaryValue& dictionary,
52 const std::string& key,
53 bool default_value);
55 // Helper function to parse strings present on a given |dictionary| in a given
56 // field identified by its |key|.
57 // Returns the parsed string if any, a null string if the parsing failed.
58 base::NullableString16 ParseString(const base::DictionaryValue& dictionary,
59 const std::string& key,
60 TrimType trim);
62 // Helper function to parse colors present on a given |dictionary| in a given
63 // field identified by its |key|.
64 // Returns the parsed color as an int64_t if any,
65 // Manifest::kInvalidOrMissingColor if the parsing failed.
66 int64_t ParseColor(const base::DictionaryValue& dictionary,
67 const std::string& key);
69 // Helper function to parse URLs present on a given |dictionary| in a given
70 // field identified by its |key|. The URL is first parsed as a string then
71 // resolved using |base_url|.
72 // Returns a GURL. If the parsing failed, the GURL will not be valid.
73 GURL ParseURL(const base::DictionaryValue& dictionary,
74 const std::string& key,
75 const GURL& base_url);
77 // Parses the 'name' field of the manifest, as defined in:
78 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-name-member
79 // Returns the parsed string if any, a null string if the parsing failed.
80 base::NullableString16 ParseName(const base::DictionaryValue& dictionary);
82 // Parses the 'short_name' field of the manifest, as defined in:
83 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-short-name-member
84 // Returns the parsed string if any, a null string if the parsing failed.
85 base::NullableString16 ParseShortName(
86 const base::DictionaryValue& dictionary);
88 // Parses the 'start_url' field of the manifest, as defined in:
89 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-start_url-member
90 // Returns the parsed GURL if any, an empty GURL if the parsing failed.
91 GURL ParseStartURL(const base::DictionaryValue& dictionary);
93 // Parses the 'display' field of the manifest, as defined in:
94 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-display-member
95 // Returns the parsed DisplayMode if any, WebDisplayModeUndefined if the
96 // parsing failed.
97 blink::WebDisplayMode ParseDisplay(const base::DictionaryValue& dictionary);
99 // Parses the 'orientation' field of the manifest, as defined in:
100 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-orientation-member
101 // Returns the parsed WebScreenOrientationLockType if any,
102 // WebScreenOrientationLockDefault if the parsing failed.
103 blink::WebScreenOrientationLockType ParseOrientation(
104 const base::DictionaryValue& dictionary);
106 // Parses the 'src' field of an icon, as defined in:
107 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-src-member-of-an-icon
108 // Returns the parsed GURL if any, an empty GURL if the parsing failed.
109 GURL ParseIconSrc(const base::DictionaryValue& icon);
111 // Parses the 'type' field of an icon, as defined in:
112 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-type-member-of-an-icon
113 // Returns the parsed string if any, a null string if the parsing failed.
114 base::NullableString16 ParseIconType(const base::DictionaryValue& icon);
116 // Parses the 'density' field of an icon, as defined in:
117 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-density-member-of-an-icon
118 // Returns the parsed double if any, Manifest::Icon::kDefaultDensity if the
119 // parsing failed.
120 double ParseIconDensity(const base::DictionaryValue& icon);
122 // Parses the 'sizes' field of an icon, as defined in:
123 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-sizes-member-of-an-icon
124 // Returns a vector of gfx::Size with the successfully parsed sizes, if any.
125 // An empty vector if the field was not present or empty. "Any" is represented
126 // by gfx::Size(0, 0).
127 std::vector<gfx::Size> ParseIconSizes(const base::DictionaryValue& icon);
129 // Parses the 'icons' field of a Manifest, as defined in:
130 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-icons-member
131 // Returns a vector of Manifest::Icon with the successfully parsed icons, if
132 // any. An empty vector if the field was not present or empty.
133 std::vector<Manifest::Icon> ParseIcons(
134 const base::DictionaryValue& dictionary);
136 // Parses the 'platform' field of a related application, as defined in:
137 // https://w3c.github.io/manifest/#dfn-steps-for-processing-the-platform-member-of-an-application
138 // Returns the parsed string if any, a null string if the parsing failed.
139 base::NullableString16 ParseRelatedApplicationPlatform(
140 const base::DictionaryValue& application);
142 // Parses the 'url' field of a related application, as defined in:
143 // https://w3c.github.io/manifest/#dfn-steps-for-processing-the-url-member-of-an-application
144 // Returns the paresed GURL if any, an empty GURL if the parsing failed.
145 GURL ParseRelatedApplicationURL(const base::DictionaryValue& application);
147 // Parses the 'id' field of a related application, as defined in:
148 // https://w3c.github.io/manifest/#dfn-steps-for-processing-the-id-member-of-an-application
149 // Returns the parsed string if any, a null string if the parsing failed.
150 base::NullableString16 ParseRelatedApplicationId(
151 const base::DictionaryValue& application);
153 // Parses the 'related_applications' field of the manifest, as defined in:
154 // https://w3c.github.io/manifest/#dfn-steps-for-processing-the-related_applications-member
155 // Returns a vector of Manifest::RelatedApplication with the successfully
156 // parsed applications, if any. An empty vector if the field was not present
157 // or empty.
158 std::vector<Manifest::RelatedApplication> ParseRelatedApplications(
159 const base::DictionaryValue& dictionary);
161 // Parses the 'prefer_related_applications' field on the manifest, as defined
162 // in:
163 // https://w3c.github.io/manifest/#dfn-steps-for-processing-the-prefer_related_applications-member
164 // returns true iff the field could be parsed as the boolean true.
165 bool ParsePreferRelatedApplications(const base::DictionaryValue& dictionary);
167 // Parses the 'theme_color' field of the manifest, as defined in:
168 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-theme_color-member
169 // Returns the parsed theme color if any,
170 // Manifest::kInvalidOrMissingColor if the parsing failed.
171 int64_t ParseThemeColor(const base::DictionaryValue& dictionary);
173 // Parses the 'background_color' field of the manifest, as defined in:
174 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-background_color-member
175 // Returns the parsed background color if any,
176 // Manifest::kInvalidOrMissingColor if the parsing failed.
177 int64_t ParseBackgroundColor(const base::DictionaryValue& dictionary);
179 // Parses the 'gcm_sender_id' field of the manifest.
180 // This is a proprietary extension of the Web Manifest specification.
181 // Returns the parsed string if any, a null string if the parsing failed.
182 base::NullableString16 ParseGCMSenderID(
183 const base::DictionaryValue& dictionary);
185 const base::StringPiece& data_;
186 GURL manifest_url_;
187 GURL document_url_;
189 bool failed_;
190 Manifest manifest_;
191 std::vector<std::string> errors_;
193 DISALLOW_COPY_AND_ASSIGN(ManifestParser);
196 } // namespace content
198 #endif // CONTENT_RENDERER_MANIFEST_MANIFEST_PARSER_H_