Chromium Code Reviews| Index: content/renderer/manifest/manifest_parser.cc |
| diff --git a/content/renderer/manifest/manifest_parser.cc b/content/renderer/manifest/manifest_parser.cc |
| index 19b69a540278b1782cda702ed986fbe0e91f453b..59d2eddd27d3fcb611ea96501953265df5bb9a32 100644 |
| --- a/content/renderer/manifest/manifest_parser.cc |
| +++ b/content/renderer/manifest/manifest_parser.cc |
| @@ -11,23 +11,39 @@ |
| #include "base/values.h" |
| #include "content/public/common/manifest.h" |
| +namespace content { |
| + |
| namespace { |
| -// Parses the 'name' field of the manifest, as defined in: |
| -// http://w3c.github.io/manifest/#dfn-steps-for-processing-the-name-member |
| -// Returns the parsed string if any, a null string if the parsing failed. |
| -base::NullableString16 ParseName(const base::DictionaryValue& dictionary) { |
| - if (!dictionary.HasKey("name")) |
| +enum TrimType { |
| + Trim, |
| + NoTrim |
| +}; |
| + |
| +base::NullableString16 ParseString(const base::DictionaryValue& dictionary, |
| + const std::string& key, |
| + TrimType trim) { |
| + if (!dictionary.HasKey(key)) |
| return base::NullableString16(); |
| - base::string16 name; |
| - if (!dictionary.GetString("name", &name)) { |
| - // TODO(mlamouri): provide a custom message to the developer console. |
| + base::string16 value; |
| + if (!dictionary.GetString(key, &value)) { |
| + // TODO(mlamouri): provide a custom message to the developer console about |
| + // the property being incorrectly set. |
| return base::NullableString16(); |
| } |
| - base::TrimWhitespace(name, base::TRIM_ALL, &name); |
| - return base::NullableString16(name, false); |
| + if (trim == Trim) { |
| + base::TrimWhitespace(value, base::TRIM_ALL, &value); |
| + } |
|
Avi (use Gerrit)
2014/09/18 02:00:02
No {} here; you don't use it above for a one-line
|
| + return base::NullableString16(value, false); |
| +} |
| + |
| +// Parses the 'name' field of the manifest, as defined in: |
| +// http://w3c.github.io/manifest/#dfn-steps-for-processing-the-name-member |
| +// Returns the parsed string if any, a null string if the parsing failed. |
| +base::NullableString16 ParseName(const base::DictionaryValue& dictionary) { |
| + return ParseString(dictionary, "name", Trim); |
| } |
| // Parses the 'short_name' field of the manifest, as defined in: |
| @@ -35,17 +51,7 @@ base::NullableString16 ParseName(const base::DictionaryValue& dictionary) { |
| // Returns the parsed string if any, a null string if the parsing failed. |
| base::NullableString16 ParseShortName( |
| const base::DictionaryValue& dictionary) { |
| - if (!dictionary.HasKey("short_name")) |
| - return base::NullableString16(); |
| - |
| - base::string16 short_name; |
| - if (!dictionary.GetString("short_name", &short_name)) { |
| - // TODO(mlamouri): provide a custom message to the developer console. |
| - return base::NullableString16(); |
| - } |
| - |
| - base::TrimWhitespace(short_name, base::TRIM_ALL, &short_name); |
| - return base::NullableString16(short_name, false); |
| + return ParseString(dictionary, "short_name", Trim); |
| } |
| // Parses the 'start_url' field of the manifest, as defined in: |
| @@ -54,16 +60,13 @@ base::NullableString16 ParseShortName( |
| GURL ParseStartURL(const base::DictionaryValue& dictionary, |
| const GURL& manifest_url, |
| const GURL& document_url) { |
| - if (!dictionary.HasKey("start_url")) |
| - return GURL(); |
| + base::NullableString16 start_url_str = |
| + ParseString(dictionary, "start_url", NoTrim); |
| - base::string16 start_url_str; |
| - if (!dictionary.GetString("start_url", &start_url_str)) { |
| - // TODO(mlamouri): provide a custom message to the developer console. |
| + if (start_url_str.is_null()) |
| return GURL(); |
| - } |
| - GURL start_url = manifest_url.Resolve(start_url_str); |
| + GURL start_url = manifest_url.Resolve(start_url_str.string()); |
| if (!start_url.is_valid()) |
| return GURL(); |
| @@ -75,9 +78,29 @@ GURL ParseStartURL(const base::DictionaryValue& dictionary, |
| return start_url; |
| } |
| -} // anonymous namespace |
| +// Parses the 'display' field of the manifest, as defined in: |
| +// http://w3c.github.io/manifest/#dfn-steps-for-processing-the-display-member |
| +// Returns the parsed DisplayMode if any, DISPLAY_MODE_UNSPECIFIED if the |
| +// parsing failed. |
| +Manifest::DisplayMode ParseDisplay(const base::DictionaryValue& dictionary) { |
| + base::NullableString16 display = ParseString(dictionary, "display", Trim); |
| + |
| + if (display.is_null()) |
| + return Manifest::DISPLAY_MODE_UNSPECIFIED; |
| + |
| + if (LowerCaseEqualsASCII(display.string(), "fullscreen")) |
| + return Manifest::DISPLAY_MODE_FULLSCREEN; |
| + else if (LowerCaseEqualsASCII(display.string(), "standalone")) |
| + return Manifest::DISPLAY_MODE_STANDALONE; |
| + else if (LowerCaseEqualsASCII(display.string(), "minimal-ui")) |
| + return Manifest::DISPLAY_MODE_MINIMAL_UI; |
| + else if (LowerCaseEqualsASCII(display.string(), "browser")) |
| + return Manifest::DISPLAY_MODE_BROWSER; |
| + else |
| + return Manifest::DISPLAY_MODE_UNSPECIFIED; |
| +} |
| -namespace content { |
| +} // anonymous namespace |
| Manifest ManifestParser::Parse(const base::StringPiece& json, |
| const GURL& manifest_url, |
| @@ -106,6 +129,7 @@ Manifest ManifestParser::Parse(const base::StringPiece& json, |
| manifest.name = ParseName(*dictionary); |
| manifest.short_name = ParseShortName(*dictionary); |
| manifest.start_url = ParseStartURL(*dictionary, manifest_url, document_url); |
| + manifest.display = ParseDisplay(*dictionary); |
| return manifest; |
| } |