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 10ExtensionExtent::ExtensionExtent() { 11} 12 13ExtensionExtent::ExtensionExtent(const ExtensionExtent& rhs) 14 : patterns_(rhs.patterns_) { 15} 16 17ExtensionExtent::~ExtensionExtent() { 18} 19 20ExtensionExtent& ExtensionExtent::operator=(const ExtensionExtent& rhs) { 21 patterns_ = rhs.patterns_; 22 return *this; 23} 24 25bool ExtensionExtent::is_empty() const { 26 return patterns_.empty(); 27} 28 29void ExtensionExtent::AddPattern(const URLPattern& pattern) { 30 patterns_.push_back(pattern); 31} 32 33void ExtensionExtent::ClearPaths() { 34 patterns_.clear(); 35} 36 37bool 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 47bool 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