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 "extensions/common/url_pattern_set.h" | 5 #include "extensions/common/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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 URLPattern pattern(valid_schemes); | 199 URLPattern pattern(valid_schemes); |
200 if (pattern.Parse(patterns[i]) != URLPattern::PARSE_SUCCESS) { | 200 if (pattern.Parse(patterns[i]) != URLPattern::PARSE_SUCCESS) { |
201 if (error) { | 201 if (error) { |
202 *error = ErrorUtils::FormatErrorMessage(kInvalidURLPatternError, | 202 *error = ErrorUtils::FormatErrorMessage(kInvalidURLPatternError, |
203 patterns[i]); | 203 patterns[i]); |
204 } else { | 204 } else { |
205 LOG(ERROR) << "Invalid url pattern: " << patterns[i]; | 205 LOG(ERROR) << "Invalid url pattern: " << patterns[i]; |
206 } | 206 } |
207 return false; | 207 return false; |
208 } | 208 } |
209 if (!allow_file_access && pattern.MatchesScheme(chrome::kFileScheme)) { | 209 if (!allow_file_access && pattern.MatchesScheme(content::kFileScheme)) { |
210 pattern.SetValidSchemes( | 210 pattern.SetValidSchemes( |
211 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); | 211 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); |
212 } | 212 } |
213 AddPattern(pattern); | 213 AddPattern(pattern); |
214 } | 214 } |
215 return true; | 215 return true; |
216 } | 216 } |
217 | 217 |
218 bool URLPatternSet::Populate(const base::ListValue& value, | 218 bool URLPatternSet::Populate(const base::ListValue& value, |
219 int valid_schemes, | 219 int valid_schemes, |
220 bool allow_file_access, | 220 bool allow_file_access, |
221 std::string* error) { | 221 std::string* error) { |
222 std::vector<std::string> patterns; | 222 std::vector<std::string> patterns; |
223 for (size_t i = 0; i < value.GetSize(); ++i) { | 223 for (size_t i = 0; i < value.GetSize(); ++i) { |
224 std::string item; | 224 std::string item; |
225 if (!value.GetString(i, &item)) | 225 if (!value.GetString(i, &item)) |
226 return false; | 226 return false; |
227 patterns.push_back(item); | 227 patterns.push_back(item); |
228 } | 228 } |
229 return Populate(patterns, valid_schemes, allow_file_access, error); | 229 return Populate(patterns, valid_schemes, allow_file_access, error); |
230 } | 230 } |
231 | 231 |
232 } // namespace extensions | 232 } // namespace extensions |
OLD | NEW |