Index: content/renderer/manifest/manifest_parser.cc |
diff --git a/content/renderer/manifest/manifest_parser.cc b/content/renderer/manifest/manifest_parser.cc |
index 9a3e8520932cc7d18b6054066deda1d8f0a65c29..169fcb98cbe88375564e6288caa6c5874141b81f 100644 |
--- a/content/renderer/manifest/manifest_parser.cc |
+++ b/content/renderer/manifest/manifest_parser.cc |
@@ -11,7 +11,9 @@ |
#include "base/strings/string_util.h" |
#include "base/strings/utf_string_conversions.h" |
#include "base/values.h" |
+#include "content/public/common/content_client.h" |
#include "content/public/common/manifest.h" |
+#include "content/public/renderer/content_renderer_client.h" |
#include "content/renderer/manifest/manifest_uma_util.h" |
#include "ui/gfx/geometry/size.h" |
@@ -85,7 +87,6 @@ const std::string& GetErrorPrefix() { |
} // anonymous namespace |
- |
ManifestParser::ManifestParser(const base::StringPiece& data, |
const GURL& manifest_url, |
const GURL& document_url) |
@@ -93,6 +94,8 @@ ManifestParser::ManifestParser(const base::StringPiece& data, |
manifest_url_(manifest_url), |
document_url_(document_url), |
failed_(false) { |
+ DCHECK(manifest_url_.is_valid()); |
+ DCHECK(document_url_.is_valid()); |
} |
ManifestParser::~ManifestParser() { |
@@ -121,18 +124,43 @@ void ManifestParser::Parse() { |
} |
DCHECK(dictionary); |
- manifest_.name = ParseName(*dictionary); |
- manifest_.short_name = ParseShortName(*dictionary); |
- manifest_.start_url = ParseStartURL(*dictionary); |
- manifest_.display = ParseDisplay(*dictionary); |
- manifest_.orientation = ParseOrientation(*dictionary); |
- manifest_.icons = ParseIcons(*dictionary); |
- manifest_.gcm_sender_id = ParseGCMSenderID(*dictionary); |
- manifest_.gcm_user_visible_only = ParseGCMUserVisibleOnly(*dictionary); |
+ for (base::DictionaryValue::Iterator iterator(*dictionary); |
+ !iterator.IsAtEnd(); iterator.Advance()) { |
+ const std::string& key = iterator.key(); |
+ const base::Value& value = iterator.value(); |
+ |
+ bool handled = Parse(key, value); |
+ if (!handled) { |
+ handled = GetContentClient()->renderer()->ParseManifestProperty(key, |
+ value); |
+ } |
+ |
+ if (!handled) |
+ errors_.push_back(GetErrorPrefix() + "unknown property '" + key + "'."); |
+ } |
ManifestUmaUtil::ParseSucceeded(manifest_); |
} |
+bool ManifestParser::Parse(const std::string& key, const base::Value& value) { |
+ if (key == "name") |
+ manifest_.name = ParseName(key, value); |
+ else if (key == "short_name") |
+ manifest_.short_name = ParseShortName(key, value); |
+ else if (key == "start_url") |
+ manifest_.start_url = ParseStartURL(key, value); |
+ else if (key == "display") |
+ manifest_.display = ParseDisplay(key, value); |
+ else if (key == "orientation") |
+ manifest_.orientation = ParseOrientation(key, value); |
+ else if (key == "icons") |
+ manifest_.icons = ParseIcons(key, value); |
+ else |
+ return false; |
+ |
+ return true; |
+} |
+ |
const Manifest& ManifestParser::manifest() const { |
return manifest_; |
} |
@@ -145,45 +173,35 @@ bool ManifestParser::failed() const { |
return failed_; |
} |
-bool ManifestParser::ParseBoolean(const base::DictionaryValue& dictionary, |
- const std::string& key, |
- bool default_value) { |
- if (!dictionary.HasKey(key)) |
- return default_value; |
- |
- bool value; |
- if (!dictionary.GetBoolean(key, &value)) { |
+bool ManifestParser::ParseBoolean( |
+ const std::string& key, const base::Value& value, bool default_value) { |
+ bool bool_value; |
+ if (!value.GetAsBoolean(&bool_value)) { |
errors_.push_back(GetErrorPrefix() + |
"property '" + key + "' ignored, type boolean expected."); |
return default_value; |
} |
- return value; |
+ return bool_value; |
} |
base::NullableString16 ManifestParser::ParseString( |
- const base::DictionaryValue& dictionary, |
- const std::string& key, |
- TrimType trim) { |
- if (!dictionary.HasKey(key)) |
- return base::NullableString16(); |
- |
- base::string16 value; |
- if (!dictionary.GetString(key, &value)) { |
+ const std::string& key, const base::Value& value, TrimType trim) { |
+ base::string16 string_value; |
+ if (!value.GetAsString(&string_value)) { |
errors_.push_back(GetErrorPrefix() + |
"property '" + key + "' ignored, type string expected."); |
return base::NullableString16(); |
} |
if (trim == Trim) |
- base::TrimWhitespace(value, base::TRIM_ALL, &value); |
- return base::NullableString16(value, false); |
+ base::TrimWhitespace(string_value, base::TRIM_ALL, &string_value); |
+ return base::NullableString16(string_value, false); |
} |
-GURL ManifestParser::ParseURL(const base::DictionaryValue& dictionary, |
- const std::string& key, |
- const GURL& base_url) { |
- base::NullableString16 url_str = ParseString(dictionary, key, NoTrim); |
+GURL ManifestParser::ParseURL( |
+ const std::string& key, const base::Value& value, const GURL& base_url) { |
+ base::NullableString16 url_str = ParseString(key, value, NoTrim); |
if (url_str.is_null()) |
return GURL(); |
@@ -191,17 +209,18 @@ GURL ManifestParser::ParseURL(const base::DictionaryValue& dictionary, |
} |
base::NullableString16 ManifestParser::ParseName( |
- const base::DictionaryValue& dictionary) { |
- return ParseString(dictionary, "name", Trim); |
+ const std::string& key, const base::Value& value) { |
+ return ParseString(key, value, Trim); |
} |
base::NullableString16 ManifestParser::ParseShortName( |
- const base::DictionaryValue& dictionary) { |
- return ParseString(dictionary, "short_name", Trim); |
+ const std::string& key, const base::Value& value) { |
+ return ParseString(key, value, Trim); |
} |
-GURL ManifestParser::ParseStartURL(const base::DictionaryValue& dictionary) { |
- GURL start_url = ParseURL(dictionary, "start_url", manifest_url_); |
+GURL ManifestParser::ParseStartURL( |
+ const std::string& key, const base::Value& value) { |
+ GURL start_url = ParseURL(key, value, manifest_url_); |
if (!start_url.is_valid()) |
return GURL(); |
@@ -215,8 +234,8 @@ GURL ManifestParser::ParseStartURL(const base::DictionaryValue& dictionary) { |
} |
Manifest::DisplayMode ManifestParser::ParseDisplay( |
- const base::DictionaryValue& dictionary) { |
- base::NullableString16 display = ParseString(dictionary, "display", Trim); |
+ const std::string& key, const base::Value& value) { |
+ base::NullableString16 display = ParseString(key, value, Trim); |
if (display.is_null()) |
return Manifest::DISPLAY_MODE_UNSPECIFIED; |
@@ -235,10 +254,8 @@ Manifest::DisplayMode ManifestParser::ParseDisplay( |
} |
blink::WebScreenOrientationLockType ManifestParser::ParseOrientation( |
- const base::DictionaryValue& dictionary) { |
- base::NullableString16 orientation = |
- ParseString(dictionary, "orientation", Trim); |
- |
+ const std::string& key, const base::Value& value) { |
+ base::NullableString16 orientation = ParseString(key, value, Trim); |
if (orientation.is_null()) |
return blink::WebScreenOrientationLockDefault; |
@@ -266,12 +283,22 @@ blink::WebScreenOrientationLockType ManifestParser::ParseOrientation( |
} |
GURL ManifestParser::ParseIconSrc(const base::DictionaryValue& icon) { |
- return ParseURL(icon, "src", manifest_url_); |
+ const std::string key = "src"; |
+ const base::Value* value; |
+ |
+ if (!icon.Get(key, &value)) |
+ return GURL(); |
+ return ParseURL(key, *value, manifest_url_); |
} |
base::NullableString16 ManifestParser::ParseIconType( |
const base::DictionaryValue& icon) { |
- return ParseString(icon, "type", Trim); |
+ const std::string key = "type"; |
+ const base::Value* value; |
+ |
+ if (!icon.Get(key, &value)) |
+ return base::NullableString16(); |
+ return ParseString(key, *value, Trim); |
} |
double ManifestParser::ParseIconDensity(const base::DictionaryValue& icon) { |
@@ -289,8 +316,13 @@ double ManifestParser::ParseIconDensity(const base::DictionaryValue& icon) { |
std::vector<gfx::Size> ManifestParser::ParseIconSizes( |
const base::DictionaryValue& icon) { |
- base::NullableString16 sizes_str = ParseString(icon, "sizes", NoTrim); |
+ const std::string key = "sizes"; |
+ const base::Value* value; |
+ if (!icon.Get(key, &value)) |
+ return std::vector<gfx::Size>(); |
+ |
+ base::NullableString16 sizes_str = ParseString(key, *value, NoTrim); |
if (sizes_str.is_null()) |
return std::vector<gfx::Size>(); |
@@ -302,13 +334,11 @@ std::vector<gfx::Size> ManifestParser::ParseIconSizes( |
} |
std::vector<Manifest::Icon> ManifestParser::ParseIcons( |
- const base::DictionaryValue& dictionary) { |
+ const std::string& key, const base::Value& value) { |
std::vector<Manifest::Icon> icons; |
- if (!dictionary.HasKey("icons")) |
- return icons; |
const base::ListValue* icons_list = nullptr; |
- if (!dictionary.GetList("icons", &icons_list)) { |
+ if (!value.GetAsList(&icons_list)) { |
errors_.push_back(GetErrorPrefix() + |
"property 'icons' ignored, type array expected."); |
return icons; |
@@ -334,14 +364,4 @@ std::vector<Manifest::Icon> ManifestParser::ParseIcons( |
return icons; |
} |
-base::NullableString16 ManifestParser::ParseGCMSenderID( |
- const base::DictionaryValue& dictionary) { |
- return ParseString(dictionary, "gcm_sender_id", Trim); |
-} |
- |
-bool ManifestParser::ParseGCMUserVisibleOnly( |
- const base::DictionaryValue& dictionary) { |
- return ParseBoolean(dictionary, "gcm_user_visible_only", false); |
-} |
- |
} // namespace content |