| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "components/url_matcher/url_matcher_factory.h" | 5 #include "components/url_matcher/url_matcher_factory.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cctype> | 8 #include <cctype> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 const base::DictionaryValue* url_filter_dict, | 107 const base::DictionaryValue* url_filter_dict, |
| 108 URLMatcherConditionSet::ID id, | 108 URLMatcherConditionSet::ID id, |
| 109 std::string* error) { | 109 std::string* error) { |
| 110 scoped_ptr<URLMatcherSchemeFilter> url_matcher_schema_filter; | 110 scoped_ptr<URLMatcherSchemeFilter> url_matcher_schema_filter; |
| 111 scoped_ptr<URLMatcherPortFilter> url_matcher_port_filter; | 111 scoped_ptr<URLMatcherPortFilter> url_matcher_port_filter; |
| 112 URLMatcherConditionSet::Conditions url_matcher_conditions; | 112 URLMatcherConditionSet::Conditions url_matcher_conditions; |
| 113 | 113 |
| 114 for (base::DictionaryValue::Iterator iter(*url_filter_dict); | 114 for (base::DictionaryValue::Iterator iter(*url_filter_dict); |
| 115 !iter.IsAtEnd(); iter.Advance()) { | 115 !iter.IsAtEnd(); iter.Advance()) { |
| 116 const std::string& condition_attribute_name = iter.key(); | 116 const std::string& condition_attribute_name = iter.key(); |
| 117 const Value& condition_attribute_value = iter.value(); | 117 const base::Value& condition_attribute_value = iter.value(); |
| 118 if (IsURLMatcherConditionAttribute(condition_attribute_name)) { | 118 if (IsURLMatcherConditionAttribute(condition_attribute_name)) { |
| 119 // Handle {host, path, ...}{Prefix, Suffix, Contains, Equals}. | 119 // Handle {host, path, ...}{Prefix, Suffix, Contains, Equals}. |
| 120 URLMatcherCondition url_matcher_condition = | 120 URLMatcherCondition url_matcher_condition = |
| 121 CreateURLMatcherCondition( | 121 CreateURLMatcherCondition( |
| 122 url_matcher_condition_factory, | 122 url_matcher_condition_factory, |
| 123 condition_attribute_name, | 123 condition_attribute_name, |
| 124 &condition_attribute_value, | 124 &condition_attribute_value, |
| 125 error); | 125 error); |
| 126 if (!error->empty()) | 126 if (!error->empty()) |
| 127 return scoped_refptr<URLMatcherConditionSet>(NULL); | 127 return scoped_refptr<URLMatcherConditionSet>(NULL); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 scoped_ptr<URLMatcherPortFilter> URLMatcherFactory::CreateURLMatcherPorts( | 238 scoped_ptr<URLMatcherPortFilter> URLMatcherFactory::CreateURLMatcherPorts( |
| 239 const base::Value* value, | 239 const base::Value* value, |
| 240 std::string* error) { | 240 std::string* error) { |
| 241 std::vector<URLMatcherPortFilter::Range> ranges; | 241 std::vector<URLMatcherPortFilter::Range> ranges; |
| 242 const base::ListValue* value_list = NULL; | 242 const base::ListValue* value_list = NULL; |
| 243 if (!value->GetAsList(&value_list)) { | 243 if (!value->GetAsList(&value_list)) { |
| 244 *error = kInvalidPortRanges; | 244 *error = kInvalidPortRanges; |
| 245 return scoped_ptr<URLMatcherPortFilter>(); | 245 return scoped_ptr<URLMatcherPortFilter>(); |
| 246 } | 246 } |
| 247 | 247 |
| 248 for (ListValue::const_iterator i = value_list->begin(); | 248 for (base::ListValue::const_iterator i = value_list->begin(); |
| 249 i != value_list->end(); ++i) { | 249 i != value_list->end(); ++i) { |
| 250 Value* entry = *i; | 250 base::Value* entry = *i; |
| 251 int port = 0; | 251 int port = 0; |
| 252 base::ListValue* range = NULL; | 252 base::ListValue* range = NULL; |
| 253 if (entry->GetAsInteger(&port)) { | 253 if (entry->GetAsInteger(&port)) { |
| 254 ranges.push_back(URLMatcherPortFilter::CreateRange(port)); | 254 ranges.push_back(URLMatcherPortFilter::CreateRange(port)); |
| 255 } else if (entry->GetAsList(&range)) { | 255 } else if (entry->GetAsList(&range)) { |
| 256 int from = 0, to = 0; | 256 int from = 0, to = 0; |
| 257 if (range->GetSize() != 2u || | 257 if (range->GetSize() != 2u || |
| 258 !range->GetInteger(0, &from) || | 258 !range->GetInteger(0, &from) || |
| 259 !range->GetInteger(1, &to)) { | 259 !range->GetInteger(1, &to)) { |
| 260 *error = kInvalidPortRanges; | 260 *error = kInvalidPortRanges; |
| 261 return scoped_ptr<URLMatcherPortFilter>(); | 261 return scoped_ptr<URLMatcherPortFilter>(); |
| 262 } | 262 } |
| 263 ranges.push_back(URLMatcherPortFilter::CreateRange(from, to)); | 263 ranges.push_back(URLMatcherPortFilter::CreateRange(from, to)); |
| 264 } else { | 264 } else { |
| 265 *error = kInvalidPortRanges; | 265 *error = kInvalidPortRanges; |
| 266 return scoped_ptr<URLMatcherPortFilter>(); | 266 return scoped_ptr<URLMatcherPortFilter>(); |
| 267 } | 267 } |
| 268 } | 268 } |
| 269 | 269 |
| 270 return scoped_ptr<URLMatcherPortFilter>(new URLMatcherPortFilter(ranges)); | 270 return scoped_ptr<URLMatcherPortFilter>(new URLMatcherPortFilter(ranges)); |
| 271 } | 271 } |
| 272 | 272 |
| 273 } // namespace url_matcher | 273 } // namespace url_matcher |
| OLD | NEW |