blob: 65f8635d2bb873880ecba1097646eff7b320c206 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/common/extensions/url_pattern_set.h"
#include "chrome/common/extensions/url_pattern.h"
#include "googleurl/src/gurl.h"
// static
void URLPatternSet::CreateUnion(const URLPatternSet& set1,
const URLPatternSet& set2,
URLPatternSet* out) {
const URLPatternList list1 = set1.patterns();
const URLPatternList list2 = set2.patterns();
out->ClearPatterns();
for (size_t i = 0; i < list1.size(); ++i)
out->AddPattern(list1.at(i));
for (size_t i = 0; i < list2.size(); ++i)
out->AddPattern(list2.at(i));
}
URLPatternSet::URLPatternSet() {
}
URLPatternSet::URLPatternSet(const URLPatternSet& rhs)
: patterns_(rhs.patterns_) {
}
URLPatternSet::~URLPatternSet() {
}
URLPatternSet& URLPatternSet::operator=(const URLPatternSet& rhs) {
patterns_ = rhs.patterns_;
return *this;
}
bool URLPatternSet::is_empty() const {
return patterns_.empty();
}
void URLPatternSet::AddPattern(const URLPattern& pattern) {
patterns_.push_back(pattern);
}
void URLPatternSet::ClearPatterns() {
patterns_.clear();
}
bool URLPatternSet::MatchesURL(const GURL& url) const {
for (URLPatternList::const_iterator pattern = patterns_.begin();
pattern != patterns_.end(); ++pattern) {
if (pattern->MatchesURL(url))
return true;
}
return false;
}
bool URLPatternSet::OverlapsWith(const URLPatternSet& other) const {
// Two extension extents overlap if there is any one URL that would match at
// least one pattern in each of the extents.
for (URLPatternList::const_iterator i = patterns_.begin();
i != patterns_.end(); ++i) {
for (URLPatternList::const_iterator j = other.patterns().begin();
j != other.patterns().end(); ++j) {
if (i->OverlapsWith(*j))
return true;
}
}
return false;
}
|