OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/extension_extent.h" | 5 #include "chrome/common/extensions/extension_extent.h" |
6 | 6 |
| 7 #include "chrome/common/extensions/url_pattern.h" |
| 8 #include "googleurl/src/gurl.h" |
| 9 |
| 10 ExtensionExtent::ExtensionExtent() { |
| 11 } |
| 12 |
| 13 ExtensionExtent::ExtensionExtent(const ExtensionExtent& rhs) |
| 14 : patterns_(rhs.patterns_) { |
| 15 } |
| 16 |
| 17 ExtensionExtent::~ExtensionExtent() { |
| 18 } |
| 19 |
| 20 ExtensionExtent& ExtensionExtent::operator=(const ExtensionExtent& rhs) { |
| 21 patterns_ = rhs.patterns_; |
| 22 return *this; |
| 23 } |
| 24 |
| 25 bool ExtensionExtent::is_empty() const { |
| 26 return patterns_.empty(); |
| 27 } |
| 28 |
| 29 void ExtensionExtent::AddPattern(const URLPattern& pattern) { |
| 30 patterns_.push_back(pattern); |
| 31 } |
| 32 |
| 33 void ExtensionExtent::ClearPaths() { |
| 34 patterns_.clear(); |
| 35 } |
| 36 |
7 bool ExtensionExtent::ContainsURL(const GURL& url) const { | 37 bool ExtensionExtent::ContainsURL(const GURL& url) const { |
8 for (PatternList::const_iterator pattern = patterns_.begin(); | 38 for (PatternList::const_iterator pattern = patterns_.begin(); |
9 pattern != patterns_.end(); ++pattern) { | 39 pattern != patterns_.end(); ++pattern) { |
10 if (pattern->MatchesUrl(url)) | 40 if (pattern->MatchesUrl(url)) |
11 return true; | 41 return true; |
12 } | 42 } |
13 | 43 |
14 return false; | 44 return false; |
15 } | 45 } |
16 | 46 |
17 bool ExtensionExtent::OverlapsWith(const ExtensionExtent& other) const { | 47 bool ExtensionExtent::OverlapsWith(const ExtensionExtent& other) const { |
18 // Two extension extents overlap if there is any one URL that would match at | 48 // Two extension extents overlap if there is any one URL that would match at |
19 // least one pattern in each of the extents. | 49 // least one pattern in each of the extents. |
20 for (PatternList::const_iterator i = patterns_.begin(); | 50 for (PatternList::const_iterator i = patterns_.begin(); |
21 i != patterns_.end(); ++i) { | 51 i != patterns_.end(); ++i) { |
22 for (PatternList::const_iterator j = other.patterns().begin(); | 52 for (PatternList::const_iterator j = other.patterns().begin(); |
23 j != other.patterns().end(); ++j) { | 53 j != other.patterns().end(); ++j) { |
24 if (i->OverlapsWith(*j)) | 54 if (i->OverlapsWith(*j)) |
25 return true; | 55 return true; |
26 } | 56 } |
27 } | 57 } |
28 | 58 |
29 return false; | 59 return false; |
30 } | 60 } |
OLD | NEW |