| 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 #ifndef CHROME_COMMON_EXTENSIONS_URL_PATTERN_SET_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_URL_PATTERN_SET_H_ |
| 6 #define CHROME_COMMON_EXTENSIONS_URL_PATTERN_SET_H_ | 6 #define CHROME_COMMON_EXTENSIONS_URL_PATTERN_SET_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "chrome/common/extensions/url_pattern.h" | 11 #include "chrome/common/extensions/url_pattern.h" |
| 12 | 12 |
| 13 class GURL; | 13 class GURL; |
| 14 | 14 |
| 15 // Represents the set of URLs an extension uses for web content. | 15 // Represents the set of URLs an extension uses for web content. |
| 16 class URLPatternSet { | 16 class URLPatternSet { |
| 17 public: | 17 public: |
| 18 typedef std::set<URLPattern>::const_iterator const_iterator; | 18 typedef std::set<URLPattern>::const_iterator const_iterator; |
| 19 typedef std::set<URLPattern>::iterator iterator; | 19 typedef std::set<URLPattern>::iterator iterator; |
| 20 | 20 |
| 21 // Clears |out| and populates the set with |set1| - |set2|. |
| 22 static void CreateDifference(const URLPatternSet& set1, |
| 23 const URLPatternSet& set2, |
| 24 URLPatternSet* out); |
| 25 |
| 26 // Clears |out| and populates the set with the intersection of |set1| |
| 27 // and |set2|. |
| 28 static void CreateIntersection(const URLPatternSet& set1, |
| 29 const URLPatternSet& set2, |
| 30 URLPatternSet* out); |
| 31 |
| 21 // Clears |out| and populates the set with the union of |set1| and |set2|. | 32 // Clears |out| and populates the set with the union of |set1| and |set2|. |
| 22 static void CreateUnion(const URLPatternSet& set1, | 33 static void CreateUnion(const URLPatternSet& set1, |
| 23 const URLPatternSet& set2, | 34 const URLPatternSet& set2, |
| 24 URLPatternSet* out); | 35 URLPatternSet* out); |
| 25 | 36 |
| 26 URLPatternSet(); | 37 URLPatternSet(); |
| 27 URLPatternSet(const URLPatternSet& rhs); | 38 URLPatternSet(const URLPatternSet& rhs); |
| 28 explicit URLPatternSet(const std::set<URLPattern>& patterns); | 39 explicit URLPatternSet(const std::set<URLPattern>& patterns); |
| 29 ~URLPatternSet(); | 40 ~URLPatternSet(); |
| 30 | 41 |
| 31 URLPatternSet& operator=(const URLPatternSet& rhs); | 42 URLPatternSet& operator=(const URLPatternSet& rhs); |
| 32 bool operator==(const URLPatternSet& rhs) const; | 43 bool operator==(const URLPatternSet& rhs) const; |
| 33 | 44 |
| 34 bool is_empty() const; | 45 bool is_empty() const; |
| 35 const std::set<URLPattern>& patterns() const { return patterns_; } | 46 const std::set<URLPattern>& patterns() const { return patterns_; } |
| 36 const_iterator begin() const { return patterns_.begin(); } | 47 const_iterator begin() const { return patterns_.begin(); } |
| 37 const_iterator end() const { return patterns_.end(); } | 48 const_iterator end() const { return patterns_.end(); } |
| 38 | 49 |
| 39 void AddPattern(const URLPattern& pattern); | 50 void AddPattern(const URLPattern& pattern); |
| 40 void ClearPatterns(); | 51 void ClearPatterns(); |
| 41 | 52 |
| 53 // Returns true if the permission |set| is a subset of this. |
| 54 bool Contains(const URLPatternSet& set) const; |
| 55 |
| 42 // Test if the extent contains a URL. | 56 // Test if the extent contains a URL. |
| 43 bool MatchesURL(const GURL& url) const; | 57 bool MatchesURL(const GURL& url) const; |
| 44 | 58 |
| 45 // Returns true if there is a single URL that would be in two extents. | 59 // Returns true if there is a single URL that would be in two extents. |
| 46 bool OverlapsWith(const URLPatternSet& other) const; | 60 bool OverlapsWith(const URLPatternSet& other) const; |
| 47 | 61 |
| 48 private: | 62 private: |
| 49 // The list of URL patterns that comprise the extent. | 63 // The list of URL patterns that comprise the extent. |
| 50 std::set<URLPattern> patterns_; | 64 std::set<URLPattern> patterns_; |
| 51 }; | 65 }; |
| 52 | 66 |
| 53 #endif // CHROME_COMMON_EXTENSIONS_URL_PATTERN_SET_H_ | 67 #endif // CHROME_COMMON_EXTENSIONS_URL_PATTERN_SET_H_ |
| OLD | NEW |