| Index: chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.cc
|
| diff --git a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.cc b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.cc
|
| index cf02de76c3c4fdb871b8eccd147e466f51255d95..962131ceed23e88c9987d1a1af9be730db12ecf6 100644
|
| --- a/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.cc
|
| +++ b/chrome/browser/extensions/api/declarative_webrequest/webrequest_condition.cc
|
| @@ -33,6 +33,7 @@ const char kConditionExpectedString[] =
|
| "Condition '%s' expected a string value";
|
| const char kVectorOfStringsExpected[] =
|
| "Attribute '%s' expected a vector of strings";
|
| +const char kInvalidPortRanges[] = "Invalid port ranges";
|
|
|
| // String literals from the JavaScript API:
|
| const char kHostContainsKey[] = "host_contains";
|
| @@ -179,6 +180,7 @@ scoped_ptr<WebRequestCondition> WebRequestCondition::Create(
|
| WebRequestConditionAttributes attributes;
|
| URLMatcherConditionSet::Conditions url_matcher_conditions;
|
| scoped_ptr<URLMatcherSchemeFilter> url_matcher_schema_filter;
|
| + scoped_ptr<URLMatcherPortFilter> url_matcher_port_filter;
|
|
|
| for (base::DictionaryValue::Iterator iter(*condition_dict);
|
| iter.HasNext(); iter.Advance()) {
|
| @@ -201,6 +203,11 @@ scoped_ptr<WebRequestCondition> WebRequestCondition::Create(
|
| &condition_attribute_value, error);
|
| if (!error->empty())
|
| return scoped_ptr<WebRequestCondition>(NULL);
|
| + } else if (condition_attribute_name == keys::kPortsKey) {
|
| + url_matcher_port_filter = CreateURLMatcherPorts(
|
| + &condition_attribute_value, error);
|
| + if (!error->empty())
|
| + return scoped_ptr<WebRequestCondition>(NULL);
|
| } else if (WebRequestConditionAttribute::IsKnownType(
|
| condition_attribute_name)) {
|
| scoped_ptr<WebRequestConditionAttribute> attribute =
|
| @@ -229,7 +236,7 @@ scoped_ptr<WebRequestCondition> WebRequestCondition::Create(
|
|
|
| scoped_refptr<URLMatcherConditionSet> url_matcher_condition_set(
|
| new URLMatcherConditionSet(++g_next_id, url_matcher_conditions,
|
| - url_matcher_schema_filter.Pass()));
|
| + url_matcher_schema_filter.Pass(), url_matcher_port_filter.Pass()));
|
| return scoped_ptr<WebRequestCondition>(
|
| new WebRequestCondition(url_matcher_condition_set, attributes));
|
| }
|
| @@ -270,6 +277,42 @@ scoped_ptr<URLMatcherSchemeFilter> WebRequestCondition::CreateURLMatcherScheme(
|
| new URLMatcherSchemeFilter(schemas));
|
| }
|
|
|
| +// static
|
| +scoped_ptr<URLMatcherPortFilter> WebRequestCondition::CreateURLMatcherPorts(
|
| + const base::Value* value,
|
| + std::string* error) {
|
| + std::vector<URLMatcherPortFilter::Range> ranges;
|
| + const base::ListValue* value_list = NULL;
|
| + if (!value->GetAsList(&value_list)) {
|
| + *error = kInvalidPortRanges;
|
| + return scoped_ptr<URLMatcherPortFilter>(NULL);
|
| + }
|
| +
|
| + for (ListValue::const_iterator i = value_list->begin();
|
| + i != value_list->end(); ++i) {
|
| + Value* entry = *i;
|
| + int port = 0;
|
| + base::ListValue* range = NULL;
|
| + if (entry->GetAsInteger(&port)) {
|
| + ranges.push_back(URLMatcherPortFilter::CreateRange(port));
|
| + } else if (entry->GetAsList(&range)) {
|
| + int from = 0, to = 0;
|
| + if (range->GetSize() != 2u ||
|
| + !range->GetInteger(0, &from) ||
|
| + !range->GetInteger(1, &to)) {
|
| + *error = kInvalidPortRanges;
|
| + return scoped_ptr<URLMatcherPortFilter>(NULL);
|
| + }
|
| + ranges.push_back(URLMatcherPortFilter::CreateRange(from, to));
|
| + } else {
|
| + *error = kInvalidPortRanges;
|
| + return scoped_ptr<URLMatcherPortFilter>(NULL);
|
| + }
|
| + }
|
| +
|
| + return scoped_ptr<URLMatcherPortFilter>(new URLMatcherPortFilter(ranges));
|
| +}
|
| +
|
| //
|
| // WebRequestConditionSet
|
| //
|
|
|