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