Chromium Code Reviews| 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 "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&, |
|
Peter Beverloo
2014/11/27 13:24:31
This argument should have a name.
mlamouri (slow - plz ping)
2014/11/27 13:49:09
Done.
| |
| 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 Manifest manifest() const; | |
|
Peter Beverloo
2014/11/27 13:24:31
This can return a "const Manifest&", leaving the c
mlamouri (slow - plz ping)
2014/11/27 13:49:09
Done.
| |
| 36 const std::vector<std::string>& errors() const; | |
| 37 bool failed() const; | |
| 38 | |
| 39 private: | |
| 40 enum TrimType { | |
|
Peter Beverloo
2014/11/27 13:24:31
nit: I realize you're just moving this, but add a
mlamouri (slow - plz ping)
2014/11/27 13:49:09
Done.
| |
| 41 Trim, | |
| 42 NoTrim | |
| 43 }; | |
| 44 | |
| 45 // Helper function to parse strings present on a given |dictionary| in a given | |
| 46 // field identified by its |key|. | |
| 47 // Returns the parsed string if any, a null string if the parsing failed. | |
| 48 base::NullableString16 ParseString(const base::DictionaryValue& dictionary, | |
| 49 const std::string& key, | |
| 50 TrimType trim); | |
| 51 | |
| 52 // Helper function to parse URLs present on a given |dictionary| in a given | |
| 53 // field identified by its |key|. The URL is first parsed as a string then | |
| 54 // resolved using |base_url|. | |
| 55 // Returns a GURL. If the parsing failed, the GURL will not be valid. | |
| 56 GURL ParseURL(const base::DictionaryValue& dictionary, | |
| 57 const std::string& key, | |
| 58 const GURL& base_url); | |
| 59 | |
| 60 // Parses the 'name' field of the manifest, as defined in: | |
| 61 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-name-member | |
| 62 // Returns the parsed string if any, a null string if the parsing failed. | |
| 63 base::NullableString16 ParseName(const base::DictionaryValue& dictionary); | |
| 64 | |
| 65 // Parses the 'short_name' field of the manifest, as defined in: | |
| 66 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-short-name-memb er | |
| 67 // Returns the parsed string if any, a null string if the parsing failed. | |
| 68 base::NullableString16 ParseShortName( | |
| 69 const base::DictionaryValue& dictionary); | |
| 70 | |
| 71 // Parses the 'start_url' field of the manifest, as defined in: | |
| 72 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-start_url-membe r | |
| 73 // Returns the parsed GURL if any, an empty GURL if the parsing failed. | |
| 74 GURL ParseStartURL(const base::DictionaryValue& dictionary); | |
| 75 | |
| 76 // Parses the 'display' field of the manifest, as defined in: | |
| 77 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-display-member | |
| 78 // Returns the parsed DisplayMode if any, DISPLAY_MODE_UNSPECIFIED if the | |
| 79 // parsing failed. | |
| 80 Manifest::DisplayMode ParseDisplay(const base::DictionaryValue& dictionary); | |
| 81 | |
| 82 // Parses the 'orientation' field of the manifest, as defined in: | |
| 83 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-orientation-mem ber | |
| 84 // Returns the parsed WebScreenOrientationLockType if any, | |
| 85 // WebScreenOrientationLockDefault if the parsing failed. | |
| 86 blink::WebScreenOrientationLockType ParseOrientation( | |
| 87 const base::DictionaryValue& dictionary); | |
| 88 | |
| 89 // Parses the 'src' field of an icon, as defined in: | |
| 90 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-src-member-of-a n-icon | |
| 91 // Returns the parsed GURL if any, an empty GURL if the parsing failed. | |
| 92 GURL ParseIconSrc(const base::DictionaryValue& icon); | |
| 93 | |
| 94 // Parses the 'type' field of an icon, as defined in: | |
| 95 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-type-member-of- an-icon | |
| 96 // Returns the parsed string if any, a null string if the parsing failed. | |
| 97 base::NullableString16 ParseIconType(const base::DictionaryValue& icon); | |
| 98 | |
| 99 // Parses the 'density' field of an icon, as defined in: | |
| 100 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-density-member-of -an-icon | |
| 101 // Returns the parsed double if any, Manifest::Icon::kDefaultDensity if the | |
| 102 // parsing failed. | |
| 103 double ParseIconDensity(const base::DictionaryValue& icon); | |
| 104 | |
| 105 // Parses the 'sizes' field of an icon, as defined in: | |
| 106 // http://w3c.github.io/manifest/#dfn-steps-for-processing-a-sizes-member-of-a n-icon | |
| 107 // Returns a vector of gfx::Size with the successfully parsed sizes, if any. | |
| 108 // An empty vector if the field was not present or empty. "Any" is represented | |
| 109 // by gfx::Size(0, 0). | |
| 110 std::vector<gfx::Size> ParseIconSizes(const base::DictionaryValue& icon); | |
| 111 | |
| 112 // Parses the 'icons' field of a Manifest, as defined in: | |
| 113 // http://w3c.github.io/manifest/#dfn-steps-for-processing-the-icons-member | |
| 114 // Returns a vector of Manifest::Icon with the successfully parsed icons, if | |
| 115 // any. An empty vector if the field was not present or empty. | |
| 116 std::vector<Manifest::Icon> ParseIcons( | |
| 117 const base::DictionaryValue& dictionary); | |
| 118 | |
| 119 // Parses the 'gcm_sender_id' field of the manifest. | |
| 120 // This is a proprietary extension of the Web Manifest specification. | |
| 121 // Returns the parsed string if any, a null string if the parsing failed. | |
| 122 base::NullableString16 ParseGCMSenderID( | |
| 123 const base::DictionaryValue& dictionary); | |
| 124 | |
| 125 const base::StringPiece& data_; | |
| 126 const GURL& manifest_url_; | |
| 127 const GURL& document_url_; | |
| 128 | |
| 129 bool failed_; | |
| 130 Manifest manifest_; | |
| 131 std::vector<std::string> errors_; | |
| 132 | |
| 133 DISALLOW_COPY_AND_ASSIGN(ManifestParser); | |
| 29 }; | 134 }; |
| 30 | 135 |
| 31 } // namespace content | 136 } // namespace content |
| 32 | 137 |
| 33 #endif // CONTENT_RENDERER_MANIFEST_MANIFEST_PARSER_H_ | 138 #endif // CONTENT_RENDERER_MANIFEST_MANIFEST_PARSER_H_ |
| OLD | NEW |