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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 | 127 |
128 void URLPatternSet::ClearPatterns() { | 128 void URLPatternSet::ClearPatterns() { |
129 patterns_.clear(); | 129 patterns_.clear(); |
130 } | 130 } |
131 | 131 |
132 bool URLPatternSet::Contains(const URLPatternSet& set) const { | 132 bool URLPatternSet::Contains(const URLPatternSet& set) const { |
133 return std::includes(patterns_.begin(), patterns_.end(), | 133 return std::includes(patterns_.begin(), patterns_.end(), |
134 set.patterns_.begin(), set.patterns_.end()); | 134 set.patterns_.begin(), set.patterns_.end()); |
135 } | 135 } |
136 | 136 |
137 bool URLPatternSet::EncompassesPattern(const URLPattern& pattern) const { | |
138 for (URLPatternSet::const_iterator it = begin(); | |
139 it != end(); ++it) { | |
140 if (it->Encompasses(pattern)) | |
141 return true; | |
142 } | |
143 | |
144 return false; | |
145 } | |
146 | |
147 bool URLPatternSet::Encompasses(const URLPatternSet& other) const { | |
148 for (URLPatternSet::const_iterator it = other.begin(); | |
149 it != other.end(); ++it) { | |
150 if (!EncompassesPattern(*it)) | |
151 return false; | |
152 } | |
153 | |
154 return true; | |
155 } | |
156 | |
137 bool URLPatternSet::MatchesURL(const GURL& url) const { | 157 bool URLPatternSet::MatchesURL(const GURL& url) const { |
138 for (URLPatternSet::const_iterator pattern = patterns_.begin(); | 158 for (URLPatternSet::const_iterator pattern = patterns_.begin(); |
139 pattern != patterns_.end(); ++pattern) { | 159 pattern != patterns_.end(); ++pattern) { |
140 if (pattern->MatchesURL(url)) | 160 if (pattern->MatchesURL(url)) |
141 return true; | 161 return true; |
142 } | 162 } |
143 | 163 |
144 return false; | 164 return false; |
145 } | 165 } |
146 | 166 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
209 std::vector<std::string> patterns; | 229 std::vector<std::string> patterns; |
210 for (size_t i = 0; i < value.GetSize(); ++i) { | 230 for (size_t i = 0; i < value.GetSize(); ++i) { |
211 std::string item; | 231 std::string item; |
212 if (!value.GetString(i, &item)) | 232 if (!value.GetString(i, &item)) |
213 return false; | 233 return false; |
214 patterns.push_back(item); | 234 patterns.push_back(item); |
215 } | 235 } |
216 return Populate(patterns, valid_schemes, allow_file_access, error); | 236 return Populate(patterns, valid_schemes, allow_file_access, error); |
217 } | 237 } |
218 | 238 |
239 std::ostream& operator<<(std::ostream& out, const URLPatternSet& set) { | |
240 bool needs_comma = false; | |
241 out << "{"; | |
242 for (URLPatternSet::const_iterator it = set.begin(); it != set.end(); ++it) { | |
243 if (needs_comma) | |
Matt Perry
2013/02/12 01:14:47
could this just be "it != set.begin()" ?
not at google - send to devlin
2013/02/12 01:49:36
Done.
| |
244 out << ","; | |
245 needs_comma = true; | |
246 out << it->GetAsString(); | |
247 } | |
248 return out << "}"; | |
249 } | |
250 | |
219 } // namespace extensions | 251 } // namespace extensions |
OLD | NEW |