| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/common/extensions/url_pattern_set.h" | 5 #include "chrome/common/extensions/url_pattern_set.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 } | 168 } |
| 169 | 169 |
| 170 scoped_ptr<base::ListValue> URLPatternSet::ToValue() const { | 170 scoped_ptr<base::ListValue> URLPatternSet::ToValue() const { |
| 171 scoped_ptr<ListValue> value(new ListValue); | 171 scoped_ptr<ListValue> value(new ListValue); |
| 172 for (URLPatternSet::const_iterator i = patterns_.begin(); | 172 for (URLPatternSet::const_iterator i = patterns_.begin(); |
| 173 i != patterns_.end(); ++i) | 173 i != patterns_.end(); ++i) |
| 174 value->AppendIfNotPresent(Value::CreateStringValue(i->GetAsString())); | 174 value->AppendIfNotPresent(Value::CreateStringValue(i->GetAsString())); |
| 175 return value.Pass(); | 175 return value.Pass(); |
| 176 } | 176 } |
| 177 | 177 |
| 178 bool URLPatternSet::Populate(const base::ListValue& value, | 178 bool URLPatternSet::Populate(const std::vector<std::string>& patterns, |
| 179 int valid_schemes, | 179 int valid_schemes, |
| 180 bool allow_file_access, | 180 bool allow_file_access, |
| 181 std::string* error) { | 181 std::string* error) { |
| 182 ClearPatterns(); | 182 ClearPatterns(); |
| 183 for (size_t i = 0; i < value.GetSize(); ++i) { | 183 for (size_t i = 0; i < patterns.size(); ++i) { |
| 184 std::string item; | |
| 185 if (!value.GetString(i, &item)) | |
| 186 return false; | |
| 187 URLPattern pattern(valid_schemes); | 184 URLPattern pattern(valid_schemes); |
| 188 if (pattern.Parse(item) != URLPattern::PARSE_SUCCESS) { | 185 if (pattern.Parse(patterns[i]) != URLPattern::PARSE_SUCCESS) { |
| 189 if (error) { | 186 if (error) { |
| 190 *error = ExtensionErrorUtils::FormatErrorMessage( | 187 *error = ExtensionErrorUtils::FormatErrorMessage( |
| 191 kInvalidURLPatternError, item); | 188 kInvalidURLPatternError, patterns[i]); |
| 192 } else { | 189 } else { |
| 193 LOG(ERROR) << "Invalid url pattern: " << item; | 190 LOG(ERROR) << "Invalid url pattern: " << patterns[i]; |
| 194 } | 191 } |
| 195 return false; | 192 return false; |
| 196 } | 193 } |
| 197 if (!allow_file_access && pattern.MatchesScheme(chrome::kFileScheme)) { | 194 if (!allow_file_access && pattern.MatchesScheme(chrome::kFileScheme)) { |
| 198 pattern.SetValidSchemes( | 195 pattern.SetValidSchemes( |
| 199 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); | 196 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); |
| 200 } | 197 } |
| 201 AddPattern(pattern); | 198 AddPattern(pattern); |
| 202 } | 199 } |
| 203 return true; | 200 return true; |
| 204 } | 201 } |
| 202 |
| 203 bool URLPatternSet::Populate(const base::ListValue& value, |
| 204 int valid_schemes, |
| 205 bool allow_file_access, |
| 206 std::string* error) { |
| 207 std::vector<std::string> patterns; |
| 208 for (size_t i = 0; i < value.GetSize(); ++i) { |
| 209 std::string item; |
| 210 if (!value.GetString(i, &item)) |
| 211 return false; |
| 212 patterns.push_back(item); |
| 213 } |
| 214 return Populate(patterns, valid_schemes, allow_file_access, error); |
| 215 } |
| OLD | NEW |