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

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

Issue 748373003: Report errors when parsing Manifest and expose them in developer console. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 6 years 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 "base/strings/nullable_string16.h"
8 #include "base/strings/string_piece.h" 9 #include "base/strings/string_piece.h"
9 #include "content/common/content_export.h" 10 #include "content/common/content_export.h"
11 #include "content/public/common/manifest.h"
10 12
11 class GURL; 13 class GURL;
12 14
13 namespace base { 15 namespace base {
14 class DictionaryValue; 16 class DictionaryValue;
15 } 17 }
16 18
17 namespace content { 19 namespace content {
18 20
19 struct Manifest;
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 static Manifest Parse(const base::StringPiece&, 26 ManifestParser(const base::StringPiece& data,
27 const GURL& manifest_url, 27 const GURL& manifest_url,
28 const GURL& document_url); 28 const GURL& document_url);
29 ~ManifestParser();
30
31 // Parse the Manifest from a string using following:
32 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-manifest
33 void Parse();
34
35 const Manifest& manifest() const;
36 const std::vector<std::string>& errors() const;
37 bool failed() const;
38
39 private:
40 // Used to indicate whether to strip whitespace when parsing a string.
41 enum TrimType {
42 Trim,
43 NoTrim
44 };
45
46 // Helper function to parse strings present on a given |dictionary| in a given
47 // field identified by its |key|.
48 // Returns the parsed string if any, a null string if the parsing failed.
49 base::NullableString16 ParseString(const base::DictionaryValue& dictionary,
50 const std::string& key,
51 TrimType trim);
52
53 // Helper function to parse URLs present on a given |dictionary| in a given
54 // field identified by its |key|. The URL is first parsed as a string then
55 // resolved using |base_url|.
56 // Returns a GURL. If the parsing failed, the GURL will not be valid.
57 GURL ParseURL(const base::DictionaryValue& dictionary,
58 const std::string& key,
59 const GURL& base_url);
60
61 // Parses the 'name' field of the manifest, as defined in:
62 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-name-member
63 // Returns the parsed string if any, a null string if the parsing failed.
64 base::NullableString16 ParseName(const base::DictionaryValue& dictionary);
65
66 // Parses the 'short_name' field of the manifest, as defined in:
67 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-short-name-memb er
68 // Returns the parsed string if any, a null string if the parsing failed.
69 base::NullableString16 ParseShortName(
70 const base::DictionaryValue& dictionary);
71
72 // Parses the 'start_url' field of the manifest, as defined in:
73 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-start_url-membe r
74 // Returns the parsed GURL if any, an empty GURL if the parsing failed.
75 GURL ParseStartURL(const base::DictionaryValue& dictionary);
76
77 // Parses the 'display' field of the manifest, as defined in:
78 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-display-member
79 // Returns the parsed DisplayMode if any, DISPLAY_MODE_UNSPECIFIED if the
80 // parsing failed.
81 Manifest::DisplayMode ParseDisplay(const base::DictionaryValue& dictionary);
82
83 // Parses the 'orientation' field of the manifest, as defined in:
84 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-orientation-mem ber
85 // Returns the parsed WebScreenOrientationLockType if any,
86 // WebScreenOrientationLockDefault if the parsing failed.
87 blink::WebScreenOrientationLockType ParseOrientation(
88 const base::DictionaryValue& dictionary);
89
90 // Parses the 'src' field of an icon, as defined in:
91 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-src-member-of-a n-icon
92 // Returns the parsed GURL if any, an empty GURL if the parsing failed.
93 GURL ParseIconSrc(const base::DictionaryValue& icon);
94
95 // Parses the 'type' field of an icon, as defined in:
96 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-type-member-of- an-icon
97 // Returns the parsed string if any, a null string if the parsing failed.
98 base::NullableString16 ParseIconType(const base::DictionaryValue& icon);
99
100 // Parses the 'density' field of an icon, as defined in:
101 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-density-member-of -an-icon
102 // Returns the parsed double if any, Manifest::Icon::kDefaultDensity if the
103 // parsing failed.
104 double ParseIconDensity(const base::DictionaryValue& icon);
105
106 // Parses the 'sizes' field of an icon, as defined in:
107 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-sizes-member-of-a n-icon
108 // Returns a vector of gfx::Size with the successfully parsed sizes, if any.
109 // An empty vector if the field was not present or empty. "Any" is represented
110 // by gfx::Size(0, 0).
111 std::vector<gfx::Size> ParseIconSizes(const base::DictionaryValue& icon);
112
113 // Parses the 'icons' field of a Manifest, as defined in:
114 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-icons-member
115 // Returns a vector of Manifest::Icon with the successfully parsed icons, if
116 // any. An empty vector if the field was not present or empty.
117 std::vector<Manifest::Icon> ParseIcons(
118 const base::DictionaryValue& dictionary);
119
120 // Parses the 'gcm_sender_id' field of the manifest.
121 // This is a proprietary extension of the Web Manifest specification.
122 // Returns the parsed string if any, a null string if the parsing failed.
123 base::NullableString16 ParseGCMSenderID(
124 const base::DictionaryValue& dictionary);
125
126 const base::StringPiece& data_;
127 const GURL& manifest_url_;
128 const GURL& document_url_;
129
130 bool failed_;
131 Manifest manifest_;
132 std::vector<std::string> errors_;
133
134 DISALLOW_COPY_AND_ASSIGN(ManifestParser);
29 }; 135 };
30 136
31 } // namespace content 137 } // namespace content
32 138
33 #endif // CONTENT_RENDERER_MANIFEST_MANIFEST_PARSER_H_ 139 #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