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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 122 |
123 void URLPatternSet::AddPatterns(const URLPatternSet& set) { | 123 void URLPatternSet::AddPatterns(const URLPatternSet& set) { |
124 patterns_.insert(set.patterns().begin(), | 124 patterns_.insert(set.patterns().begin(), |
125 set.patterns().end()); | 125 set.patterns().end()); |
126 } | 126 } |
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& other) const { |
133 return std::includes(patterns_.begin(), patterns_.end(), | 133 for (URLPatternSet::const_iterator it = other.begin(); |
134 set.patterns_.begin(), set.patterns_.end()); | 134 it != other.end(); ++it) { |
| 135 if (!Encompasses(*it)) |
| 136 return false; |
| 137 } |
| 138 |
| 139 return true; |
135 } | 140 } |
136 | 141 |
137 bool URLPatternSet::MatchesURL(const GURL& url) const { | 142 bool URLPatternSet::MatchesURL(const GURL& url) const { |
138 for (URLPatternSet::const_iterator pattern = patterns_.begin(); | 143 for (URLPatternSet::const_iterator pattern = patterns_.begin(); |
139 pattern != patterns_.end(); ++pattern) { | 144 pattern != patterns_.end(); ++pattern) { |
140 if (pattern->MatchesURL(url)) | 145 if (pattern->MatchesURL(url)) |
141 return true; | 146 return true; |
142 } | 147 } |
143 | 148 |
144 return false; | 149 return false; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 std::vector<std::string> patterns; | 214 std::vector<std::string> patterns; |
210 for (size_t i = 0; i < value.GetSize(); ++i) { | 215 for (size_t i = 0; i < value.GetSize(); ++i) { |
211 std::string item; | 216 std::string item; |
212 if (!value.GetString(i, &item)) | 217 if (!value.GetString(i, &item)) |
213 return false; | 218 return false; |
214 patterns.push_back(item); | 219 patterns.push_back(item); |
215 } | 220 } |
216 return Populate(patterns, valid_schemes, allow_file_access, error); | 221 return Populate(patterns, valid_schemes, allow_file_access, error); |
217 } | 222 } |
218 | 223 |
| 224 bool URLPatternSet::Encompasses(const URLPattern& pattern) const { |
| 225 for (URLPatternSet::const_iterator it = begin(); |
| 226 it != end(); ++it) { |
| 227 if (it->Encompasses(pattern)) |
| 228 return true; |
| 229 } |
| 230 return false; |
| 231 } |
| 232 |
| 233 std::ostream& operator<<(std::ostream& out, const URLPatternSet& set) { |
| 234 out << "{"; |
| 235 for (URLPatternSet::const_iterator it = set.begin(); it != set.end(); ++it) { |
| 236 if (it != set.begin()) |
| 237 out << ","; |
| 238 out << it->GetAsString(); |
| 239 } |
| 240 return out << "}"; |
| 241 } |
| 242 |
219 } // namespace extensions | 243 } // namespace extensions |
OLD | NEW |