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 std::vector<std::string>& patterns, | |
179 int valid_schemes, | |
180 bool allow_file_access, | |
181 std::string* error) { | |
182 ClearPatterns(); | |
183 for (size_t i = 0; i < patterns.size(); ++i) { | |
184 URLPattern pattern(valid_schemes); | |
185 if (!ParseURLPattern(pattern, patterns.at(i), allow_file_access, error)) | |
186 return false; | |
187 AddPattern(pattern); | |
188 } | |
189 return true; | |
190 } | |
191 | |
178 bool URLPatternSet::Populate(const base::ListValue& value, | 192 bool URLPatternSet::Populate(const base::ListValue& value, |
179 int valid_schemes, | 193 int valid_schemes, |
180 bool allow_file_access, | 194 bool allow_file_access, |
181 std::string* error) { | 195 std::string* error) { |
182 ClearPatterns(); | 196 ClearPatterns(); |
183 for (size_t i = 0; i < value.GetSize(); ++i) { | 197 for (size_t i = 0; i < value.GetSize(); ++i) { |
184 std::string item; | 198 std::string item; |
185 if (!value.GetString(i, &item)) | 199 if (!value.GetString(i, &item)) |
186 return false; | 200 return false; |
187 URLPattern pattern(valid_schemes); | 201 URLPattern pattern(valid_schemes); |
not at google - send to devlin
2012/08/06 01:55:45
nice, though also just convert this to a vector an
chebert
2012/08/06 22:43:06
Done.
| |
188 if (pattern.Parse(item) != URLPattern::PARSE_SUCCESS) { | 202 if (!ParseURLPattern(pattern, item, allow_file_access, error)) |
189 if (error) { | |
190 *error = ExtensionErrorUtils::FormatErrorMessage( | |
191 kInvalidURLPatternError, item); | |
192 } else { | |
193 LOG(ERROR) << "Invalid url pattern: " << item; | |
194 } | |
195 return false; | 203 return false; |
196 } | |
197 if (!allow_file_access && pattern.MatchesScheme(chrome::kFileScheme)) { | |
198 pattern.SetValidSchemes( | |
199 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); | |
200 } | |
201 AddPattern(pattern); | 204 AddPattern(pattern); |
202 } | 205 } |
203 return true; | 206 return true; |
204 } | 207 } |
208 | |
209 bool URLPatternSet::ParseURLPattern(URLPattern& pattern, | |
210 const std::string& item, | |
211 bool allow_file_access, | |
212 std::string* error) { | |
213 if (pattern.Parse(item) != URLPattern::PARSE_SUCCESS) { | |
214 if (error) { | |
215 *error = ExtensionErrorUtils::FormatErrorMessage( | |
216 kInvalidURLPatternError, item); | |
217 } else { | |
218 LOG(ERROR) << "Invalid url pattern: " << item; | |
219 } | |
220 return false; | |
221 } | |
222 if (!allow_file_access && pattern.MatchesScheme(chrome::kFileScheme)) { | |
223 pattern.SetValidSchemes( | |
224 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); | |
225 } | |
226 return true; | |
227 } | |
OLD | NEW |