Remove support for the "gcm_user_visible_only" manifest key.
[chromium-blink-merge.git] / content / renderer / manifest / manifest_parser.h
blobf8817314fd09c76ea44b8dd9b16bb89b0f73d6c8
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 "base/strings/nullable_string16.h"
9 #include "base/strings/string_piece.h"
10 #include "content/common/content_export.h"
11 #include "content/public/common/manifest.h"
13 class GURL;
15 namespace base {
16 class DictionaryValue;
19 namespace content {
21 // ManifestParser handles the logic of parsing the Web Manifest from a string.
22 // It implements:
23 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-manifest
24 class CONTENT_EXPORT ManifestParser {
25 public:
26 ManifestParser(const base::StringPiece& data,
27 const GURL& manifest_url,
28 const GURL& document_url);
29 ~ManifestParser();
31 // Parse the Manifest from a string using following:
32 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-manifest
33 void Parse();
35 const Manifest& manifest() const;
36 const std::vector<std::string>& errors() const;
37 bool failed() const;
39 private:
40 // Used to indicate whether to strip whitespace when parsing a string.
41 enum TrimType {
42 Trim,
43 NoTrim
46 // Helper function to parse booleans present on a given |dictionary| in a
47 // given field identified by its |key|.
48 // Returns the parsed boolean if any, or |default_value| if parsing failed.
49 bool ParseBoolean(const base::DictionaryValue& dictionary,
50 const std::string& key,
51 bool default_value);
53 // Helper function to parse strings present on a given |dictionary| in a given
54 // field identified by its |key|.
55 // Returns the parsed string if any, a null string if the parsing failed.
56 base::NullableString16 ParseString(const base::DictionaryValue& dictionary,
57 const std::string& key,
58 TrimType trim);
60 // Helper function to parse URLs present on a given |dictionary| in a given
61 // field identified by its |key|. The URL is first parsed as a string then
62 // resolved using |base_url|.
63 // Returns a GURL. If the parsing failed, the GURL will not be valid.
64 GURL ParseURL(const base::DictionaryValue& dictionary,
65 const std::string& key,
66 const GURL& base_url);
68 // Parses the 'name' field of the manifest, as defined in:
69 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-name-member
70 // Returns the parsed string if any, a null string if the parsing failed.
71 base::NullableString16 ParseName(const base::DictionaryValue& dictionary);
73 // Parses the 'short_name' field of the manifest, as defined in:
74 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-short-name-member
75 // Returns the parsed string if any, a null string if the parsing failed.
76 base::NullableString16 ParseShortName(
77 const base::DictionaryValue& dictionary);
79 // Parses the 'start_url' field of the manifest, as defined in:
80 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-start_url-member
81 // Returns the parsed GURL if any, an empty GURL if the parsing failed.
82 GURL ParseStartURL(const base::DictionaryValue& dictionary);
84 // Parses the 'display' field of the manifest, as defined in:
85 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-display-member
86 // Returns the parsed DisplayMode if any, DISPLAY_MODE_UNSPECIFIED if the
87 // parsing failed.
88 Manifest::DisplayMode ParseDisplay(const base::DictionaryValue& dictionary);
90 // Parses the 'orientation' field of the manifest, as defined in:
91 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-orientation-member
92 // Returns the parsed WebScreenOrientationLockType if any,
93 // WebScreenOrientationLockDefault if the parsing failed.
94 blink::WebScreenOrientationLockType ParseOrientation(
95 const base::DictionaryValue& dictionary);
97 // Parses the 'src' field of an icon, as defined in:
98 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-src-member-of-an-icon
99 // Returns the parsed GURL if any, an empty GURL if the parsing failed.
100 GURL ParseIconSrc(const base::DictionaryValue& icon);
102 // Parses the 'type' field of an icon, as defined in:
103 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-type-member-of-an-icon
104 // Returns the parsed string if any, a null string if the parsing failed.
105 base::NullableString16 ParseIconType(const base::DictionaryValue& icon);
107 // Parses the 'density' field of an icon, as defined in:
108 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-density-member-of-an-icon
109 // Returns the parsed double if any, Manifest::Icon::kDefaultDensity if the
110 // parsing failed.
111 double ParseIconDensity(const base::DictionaryValue& icon);
113 // Parses the 'sizes' field of an icon, as defined in:
114 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-sizes-member-of-an-icon
115 // Returns a vector of gfx::Size with the successfully parsed sizes, if any.
116 // An empty vector if the field was not present or empty. "Any" is represented
117 // by gfx::Size(0, 0).
118 std::vector<gfx::Size> ParseIconSizes(const base::DictionaryValue& icon);
120 // Parses the 'icons' field of a Manifest, as defined in:
121 // 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
123 // any. An empty vector if the field was not present or empty.
124 std::vector<Manifest::Icon> ParseIcons(
125 const base::DictionaryValue& dictionary);
127 // Parses the 'platform' field of a related application, as defined in:
128 // https://w3c.github.io/manifest/#dfn-steps-for-processing-the-platform-member-of-an-application
129 // Returns the parsed string if any, a null string if the parsing failed.
130 base::NullableString16 ParseRelatedApplicationPlatform(
131 const base::DictionaryValue& application);
133 // Parses the 'url' field of a related application, as defined in:
134 // https://w3c.github.io/manifest/#dfn-steps-for-processing-the-url-member-of-an-application
135 // Returns the paresed GURL if any, an empty GURL if the parsing failed.
136 GURL ParseRelatedApplicationURL(const base::DictionaryValue& application);
138 // Parses the 'id' field of a related application, as defined in:
139 // https://w3c.github.io/manifest/#dfn-steps-for-processing-the-id-member-of-an-application
140 // Returns the parsed string if any, a null string if the parsing failed.
141 base::NullableString16 ParseRelatedApplicationId(
142 const base::DictionaryValue& application);
144 // Parses the 'related_applications' field of the manifest, as defined in:
145 // https://w3c.github.io/manifest/#dfn-steps-for-processing-the-related_applications-member
146 // Returns a vector of Manifest::RelatedApplication with the successfully
147 // parsed applications, if any. An empty vector if the field was not present
148 // or empty.
149 std::vector<Manifest::RelatedApplication> ParseRelatedApplications(
150 const base::DictionaryValue& dictionary);
152 // Parses the 'prefer_related_applications' field on the manifest, as defined
153 // in:
154 // https://w3c.github.io/manifest/#dfn-steps-for-processing-the-prefer_related_applications-member
155 // returns true iff the field could be parsed as the boolean true.
156 bool ParsePreferRelatedApplications(const base::DictionaryValue& dictionary);
158 // Parses the 'gcm_sender_id' field of the manifest.
159 // This is a proprietary extension of the Web Manifest specification.
160 // Returns the parsed string if any, a null string if the parsing failed.
161 base::NullableString16 ParseGCMSenderID(
162 const base::DictionaryValue& dictionary);
164 const base::StringPiece& data_;
165 GURL manifest_url_;
166 GURL document_url_;
168 bool failed_;
169 Manifest manifest_;
170 std::vector<std::string> errors_;
172 DISALLOW_COPY_AND_ASSIGN(ManifestParser);
175 } // namespace content
177 #endif // CONTENT_RENDERER_MANIFEST_MANIFEST_PARSER_H_