OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/common/extensions/url_pattern.h" | 10 #include "chrome/common/extensions/url_pattern.h" |
11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
12 | 12 |
| 13 |
| 14 // static |
| 15 void URLPatternSet::CreateDifference(const URLPatternSet& set1, |
| 16 const URLPatternSet& set2, |
| 17 URLPatternSet* out) { |
| 18 out->ClearPatterns(); |
| 19 std::set_difference(set1.patterns_.begin(), set1.patterns_.end(), |
| 20 set2.patterns_.begin(), set2.patterns_.end(), |
| 21 std::inserter<std::set<URLPattern> >( |
| 22 out->patterns_, out->patterns_.begin())); |
| 23 } |
| 24 |
| 25 // static |
| 26 void URLPatternSet::CreateIntersection(const URLPatternSet& set1, |
| 27 const URLPatternSet& set2, |
| 28 URLPatternSet* out) { |
| 29 out->ClearPatterns(); |
| 30 std::set_intersection(set1.patterns_.begin(), set1.patterns_.end(), |
| 31 set2.patterns_.begin(), set2.patterns_.end(), |
| 32 std::inserter<std::set<URLPattern> >( |
| 33 out->patterns_, out->patterns_.begin())); |
| 34 } |
| 35 |
13 // static | 36 // static |
14 void URLPatternSet::CreateUnion(const URLPatternSet& set1, | 37 void URLPatternSet::CreateUnion(const URLPatternSet& set1, |
15 const URLPatternSet& set2, | 38 const URLPatternSet& set2, |
16 URLPatternSet* out) { | 39 URLPatternSet* out) { |
17 out->ClearPatterns(); | 40 out->ClearPatterns(); |
18 std::set_union(set1.patterns_.begin(), set1.patterns_.end(), | 41 std::set_union(set1.patterns_.begin(), set1.patterns_.end(), |
19 set2.patterns_.begin(), set2.patterns_.end(), | 42 set2.patterns_.begin(), set2.patterns_.end(), |
20 std::inserter<std::set<URLPattern> >( | 43 std::inserter<std::set<URLPattern> >( |
21 out->patterns_, out->patterns_.begin())); | 44 out->patterns_, out->patterns_.begin())); |
22 } | 45 } |
(...skipping 22 matching lines...) Expand all Loading... |
45 } | 68 } |
46 | 69 |
47 void URLPatternSet::AddPattern(const URLPattern& pattern) { | 70 void URLPatternSet::AddPattern(const URLPattern& pattern) { |
48 patterns_.insert(pattern); | 71 patterns_.insert(pattern); |
49 } | 72 } |
50 | 73 |
51 void URLPatternSet::ClearPatterns() { | 74 void URLPatternSet::ClearPatterns() { |
52 patterns_.clear(); | 75 patterns_.clear(); |
53 } | 76 } |
54 | 77 |
| 78 bool URLPatternSet::Contains(const URLPatternSet& set) const { |
| 79 return std::includes(patterns_.begin(), patterns_.end(), |
| 80 set.patterns_.begin(), set.patterns_.end()); |
| 81 } |
| 82 |
55 bool URLPatternSet::MatchesURL(const GURL& url) const { | 83 bool URLPatternSet::MatchesURL(const GURL& url) const { |
56 for (URLPatternSet::const_iterator pattern = patterns_.begin(); | 84 for (URLPatternSet::const_iterator pattern = patterns_.begin(); |
57 pattern != patterns_.end(); ++pattern) { | 85 pattern != patterns_.end(); ++pattern) { |
58 if (pattern->MatchesURL(url)) | 86 if (pattern->MatchesURL(url)) |
59 return true; | 87 return true; |
60 } | 88 } |
61 | 89 |
62 return false; | 90 return false; |
63 } | 91 } |
64 | 92 |
65 bool URLPatternSet::OverlapsWith(const URLPatternSet& other) const { | 93 bool URLPatternSet::OverlapsWith(const URLPatternSet& other) const { |
66 // Two extension extents overlap if there is any one URL that would match at | 94 // Two extension extents overlap if there is any one URL that would match at |
67 // least one pattern in each of the extents. | 95 // least one pattern in each of the extents. |
68 for (URLPatternSet::const_iterator i = patterns_.begin(); | 96 for (URLPatternSet::const_iterator i = patterns_.begin(); |
69 i != patterns_.end(); ++i) { | 97 i != patterns_.end(); ++i) { |
70 for (URLPatternSet::const_iterator j = other.patterns().begin(); | 98 for (URLPatternSet::const_iterator j = other.patterns().begin(); |
71 j != other.patterns().end(); ++j) { | 99 j != other.patterns().end(); ++j) { |
72 if (i->OverlapsWith(*j)) | 100 if (i->OverlapsWith(*j)) |
73 return true; | 101 return true; |
74 } | 102 } |
75 } | 103 } |
76 | 104 |
77 return false; | 105 return false; |
78 } | 106 } |
OLD | NEW |