| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 #ifndef CHROME_COMMON_EXTENSIONS_URL_PATTERN_SET_H_ | |
| 6 #define CHROME_COMMON_EXTENSIONS_URL_PATTERN_SET_H_ | |
| 7 | |
| 8 #include <set> | |
| 9 | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "extensions/common/url_pattern.h" | |
| 12 | |
| 13 class GURL; | |
| 14 | |
| 15 namespace base { | |
| 16 class ListValue; | |
| 17 class Value; | |
| 18 } | |
| 19 | |
| 20 // Represents the set of URLs an extension uses for web content. | |
| 21 class URLPatternSet { | |
| 22 public: | |
| 23 typedef std::set<URLPattern>::const_iterator const_iterator; | |
| 24 typedef std::set<URLPattern>::iterator iterator; | |
| 25 | |
| 26 // Clears |out| and populates the set with |set1| - |set2|. | |
| 27 static void CreateDifference(const URLPatternSet& set1, | |
| 28 const URLPatternSet& set2, | |
| 29 URLPatternSet* out); | |
| 30 | |
| 31 // Clears |out| and populates the set with the intersection of |set1| | |
| 32 // and |set2|. | |
| 33 static void CreateIntersection(const URLPatternSet& set1, | |
| 34 const URLPatternSet& set2, | |
| 35 URLPatternSet* out); | |
| 36 | |
| 37 // Clears |out| and populates the set with the union of |set1| and |set2|. | |
| 38 static void CreateUnion(const URLPatternSet& set1, | |
| 39 const URLPatternSet& set2, | |
| 40 URLPatternSet* out); | |
| 41 | |
| 42 // Clears |out| and populates it with the union of all sets in |sets|. | |
| 43 static void CreateUnion(const std::vector<URLPatternSet>& sets, | |
| 44 URLPatternSet* out); | |
| 45 | |
| 46 URLPatternSet(); | |
| 47 URLPatternSet(const URLPatternSet& rhs); | |
| 48 explicit URLPatternSet(const std::set<URLPattern>& patterns); | |
| 49 ~URLPatternSet(); | |
| 50 | |
| 51 URLPatternSet& operator=(const URLPatternSet& rhs); | |
| 52 bool operator==(const URLPatternSet& rhs) const; | |
| 53 | |
| 54 bool is_empty() const; | |
| 55 size_t size() const; | |
| 56 const std::set<URLPattern>& patterns() const { return patterns_; } | |
| 57 const_iterator begin() const { return patterns_.begin(); } | |
| 58 const_iterator end() const { return patterns_.end(); } | |
| 59 | |
| 60 // Adds a pattern to the set. Returns true if a new pattern was inserted, | |
| 61 // false if the pattern was already in the set. | |
| 62 bool AddPattern(const URLPattern& pattern); | |
| 63 | |
| 64 // Adds all patterns from |set| into this. | |
| 65 void AddPatterns(const URLPatternSet& set); | |
| 66 | |
| 67 void ClearPatterns(); | |
| 68 | |
| 69 // Returns true if the permission |set| is a subset of this. | |
| 70 bool Contains(const URLPatternSet& set) const; | |
| 71 | |
| 72 // Test if the extent contains a URL. | |
| 73 bool MatchesURL(const GURL& url) const; | |
| 74 | |
| 75 bool MatchesSecurityOrigin(const GURL& origin) const; | |
| 76 | |
| 77 // Returns true if there is a single URL that would be in two extents. | |
| 78 bool OverlapsWith(const URLPatternSet& other) const; | |
| 79 | |
| 80 // Converts to and from Value for serialization to preferences. | |
| 81 scoped_ptr<base::ListValue> ToValue() const; | |
| 82 bool Populate(const base::ListValue& value, | |
| 83 int valid_schemes, | |
| 84 bool allow_file_access, | |
| 85 std::string* error); | |
| 86 | |
| 87 bool Populate(const std::vector<std::string>& patterns, | |
| 88 int valid_schemes, | |
| 89 bool allow_file_access, | |
| 90 std::string* error); | |
| 91 | |
| 92 private: | |
| 93 // The list of URL patterns that comprise the extent. | |
| 94 std::set<URLPattern> patterns_; | |
| 95 }; | |
| 96 | |
| 97 #endif // CHROME_COMMON_EXTENSIONS_URL_PATTERN_SET_H_ | |
| OLD | NEW |