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 <iterator> | 7 #include <iterator> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/linked_ptr.h" | 10 #include "base/memory/linked_ptr.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "content/public/common/url_constants.h" | |
14 #include "extensions/common/error_utils.h" | 13 #include "extensions/common/error_utils.h" |
15 #include "extensions/common/url_pattern.h" | 14 #include "extensions/common/url_pattern.h" |
16 #include "url/gurl.h" | 15 #include "url/gurl.h" |
| 16 #include "url/url_constants.h" |
17 | 17 |
18 namespace extensions { | 18 namespace extensions { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 const char kInvalidURLPatternError[] = "Invalid url pattern '*'"; | 22 const char kInvalidURLPatternError[] = "Invalid url pattern '*'"; |
23 | 23 |
24 } // namespace | 24 } // namespace |
25 | 25 |
26 // static | 26 // static |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 URLPattern pattern(valid_schemes); | 191 URLPattern pattern(valid_schemes); |
192 if (pattern.Parse(patterns[i]) != URLPattern::PARSE_SUCCESS) { | 192 if (pattern.Parse(patterns[i]) != URLPattern::PARSE_SUCCESS) { |
193 if (error) { | 193 if (error) { |
194 *error = ErrorUtils::FormatErrorMessage(kInvalidURLPatternError, | 194 *error = ErrorUtils::FormatErrorMessage(kInvalidURLPatternError, |
195 patterns[i]); | 195 patterns[i]); |
196 } else { | 196 } else { |
197 LOG(ERROR) << "Invalid url pattern: " << patterns[i]; | 197 LOG(ERROR) << "Invalid url pattern: " << patterns[i]; |
198 } | 198 } |
199 return false; | 199 return false; |
200 } | 200 } |
201 if (!allow_file_access && pattern.MatchesScheme(content::kFileScheme)) { | 201 if (!allow_file_access && pattern.MatchesScheme(url::kFileScheme)) { |
202 pattern.SetValidSchemes( | 202 pattern.SetValidSchemes( |
203 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); | 203 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); |
204 } | 204 } |
205 AddPattern(pattern); | 205 AddPattern(pattern); |
206 } | 206 } |
207 return true; | 207 return true; |
208 } | 208 } |
209 | 209 |
210 bool URLPatternSet::Populate(const base::ListValue& value, | 210 bool URLPatternSet::Populate(const base::ListValue& value, |
211 int valid_schemes, | 211 int valid_schemes, |
212 bool allow_file_access, | 212 bool allow_file_access, |
213 std::string* error) { | 213 std::string* error) { |
214 std::vector<std::string> patterns; | 214 std::vector<std::string> patterns; |
215 for (size_t i = 0; i < value.GetSize(); ++i) { | 215 for (size_t i = 0; i < value.GetSize(); ++i) { |
216 std::string item; | 216 std::string item; |
217 if (!value.GetString(i, &item)) | 217 if (!value.GetString(i, &item)) |
218 return false; | 218 return false; |
219 patterns.push_back(item); | 219 patterns.push_back(item); |
220 } | 220 } |
221 return Populate(patterns, valid_schemes, allow_file_access, error); | 221 return Populate(patterns, valid_schemes, allow_file_access, error); |
222 } | 222 } |
223 | 223 |
224 } // namespace extensions | 224 } // namespace extensions |
OLD | NEW |