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 #include <ostream> | 8 #include <ostream> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 bool URLPatternSet::MatchesURL(const GURL& url) const { | 164 bool URLPatternSet::MatchesURL(const GURL& url) const { |
165 for (URLPatternSet::const_iterator pattern = patterns_.begin(); | 165 for (URLPatternSet::const_iterator pattern = patterns_.begin(); |
166 pattern != patterns_.end(); ++pattern) { | 166 pattern != patterns_.end(); ++pattern) { |
167 if (pattern->MatchesURL(url)) | 167 if (pattern->MatchesURL(url)) |
168 return true; | 168 return true; |
169 } | 169 } |
170 | 170 |
171 return false; | 171 return false; |
172 } | 172 } |
173 | 173 |
| 174 bool URLPatternSet::MatchesAllURLs() const { |
| 175 for (URLPatternSet::const_iterator host = begin(); host != end(); ++host) { |
| 176 if (host->match_all_urls() || |
| 177 (host->match_subdomains() && host->host().empty())) |
| 178 return true; |
| 179 } |
| 180 return false; |
| 181 } |
| 182 |
174 bool URLPatternSet::MatchesSecurityOrigin(const GURL& origin) const { | 183 bool URLPatternSet::MatchesSecurityOrigin(const GURL& origin) const { |
175 for (URLPatternSet::const_iterator pattern = patterns_.begin(); | 184 for (URLPatternSet::const_iterator pattern = patterns_.begin(); |
176 pattern != patterns_.end(); ++pattern) { | 185 pattern != patterns_.end(); ++pattern) { |
177 if (pattern->MatchesSecurityOrigin(origin)) | 186 if (pattern->MatchesSecurityOrigin(origin)) |
178 return true; | 187 return true; |
179 } | 188 } |
180 | 189 |
181 return false; | 190 return false; |
182 } | 191 } |
183 | 192 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 } | 231 } |
223 if (!allow_file_access && pattern.MatchesScheme(url::kFileScheme)) { | 232 if (!allow_file_access && pattern.MatchesScheme(url::kFileScheme)) { |
224 pattern.SetValidSchemes( | 233 pattern.SetValidSchemes( |
225 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); | 234 pattern.valid_schemes() & ~URLPattern::SCHEME_FILE); |
226 } | 235 } |
227 AddPattern(pattern); | 236 AddPattern(pattern); |
228 } | 237 } |
229 return true; | 238 return true; |
230 } | 239 } |
231 | 240 |
| 241 scoped_ptr<std::vector<std::string> > URLPatternSet::ToStringVector() const { |
| 242 scoped_ptr<std::vector<std::string> > value(new std::vector<std::string>); |
| 243 for (URLPatternSet::const_iterator i = patterns_.begin(); |
| 244 i != patterns_.end(); |
| 245 ++i) { |
| 246 value->push_back(i->GetAsString()); |
| 247 } |
| 248 std::unique(value->begin(), value->end()); |
| 249 return value.Pass(); |
| 250 } |
| 251 |
232 bool URLPatternSet::Populate(const base::ListValue& value, | 252 bool URLPatternSet::Populate(const base::ListValue& value, |
233 int valid_schemes, | 253 int valid_schemes, |
234 bool allow_file_access, | 254 bool allow_file_access, |
235 std::string* error) { | 255 std::string* error) { |
236 std::vector<std::string> patterns; | 256 std::vector<std::string> patterns; |
237 for (size_t i = 0; i < value.GetSize(); ++i) { | 257 for (size_t i = 0; i < value.GetSize(); ++i) { |
238 std::string item; | 258 std::string item; |
239 if (!value.GetString(i, &item)) | 259 if (!value.GetString(i, &item)) |
240 return false; | 260 return false; |
241 patterns.push_back(item); | 261 patterns.push_back(item); |
242 } | 262 } |
243 return Populate(patterns, valid_schemes, allow_file_access, error); | 263 return Populate(patterns, valid_schemes, allow_file_access, error); |
244 } | 264 } |
245 | 265 |
246 } // namespace extensions | 266 } // namespace extensions |
OLD | NEW |