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.
5 #ifndef EXTENSIONS_COMMMON_URL_PATTERN_SET_H_
6 #define EXTENSIONS_COMMMON_URL_PATTERN_SET_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "extensions/common/url_pattern.h"
20 namespace extensions
{
22 // Represents the set of URLs an extension uses for web content.
25 typedef std::set
<URLPattern
>::const_iterator const_iterator
;
26 typedef std::set
<URLPattern
>::iterator iterator
;
28 // Clears |out| and populates the set with |set1| - |set2|.
29 static void CreateDifference(const URLPatternSet
& set1
,
30 const URLPatternSet
& set2
,
33 // Clears |out| and populates the set with the intersection of |set1|
35 static void CreateIntersection(const URLPatternSet
& set1
,
36 const URLPatternSet
& set2
,
39 // Clears |out| and populates the set with the union of |set1| and |set2|.
40 static void CreateUnion(const URLPatternSet
& set1
,
41 const URLPatternSet
& set2
,
44 // Clears |out| and populates it with the union of all sets in |sets|.
45 static void CreateUnion(const std::vector
<URLPatternSet
>& sets
,
49 URLPatternSet(const URLPatternSet
& rhs
);
50 explicit URLPatternSet(const std::set
<URLPattern
>& patterns
);
53 URLPatternSet
& operator=(const URLPatternSet
& rhs
);
54 bool operator==(const URLPatternSet
& rhs
) const;
56 bool is_empty() const;
58 const std::set
<URLPattern
>& patterns() const { return patterns_
; }
59 const_iterator
begin() const { return patterns_
.begin(); }
60 const_iterator
end() const { return patterns_
.end(); }
62 // Adds a pattern to the set. Returns true if a new pattern was inserted,
63 // false if the pattern was already in the set.
64 bool AddPattern(const URLPattern
& pattern
);
66 // Adds all patterns from |set| into this.
67 void AddPatterns(const URLPatternSet
& set
);
71 // Returns true if every URL that matches |set| is matched by this. In other
72 // words, if every pattern in |set| is encompassed by a pattern in this.
73 bool Contains(const URLPatternSet
& set
) const;
75 // Returns true if any pattern in this set encompasses |pattern|.
76 bool ContainsPattern(const URLPattern
& pattern
) const;
78 // Test if the extent contains a URL.
79 bool MatchesURL(const GURL
& url
) const;
81 bool MatchesSecurityOrigin(const GURL
& origin
) const;
83 // Returns true if there is a single URL that would be in two extents.
84 bool OverlapsWith(const URLPatternSet
& other
) const;
86 // Converts to and from Value for serialization to preferences.
87 scoped_ptr
<base::ListValue
> ToValue() const;
88 bool Populate(const base::ListValue
& value
,
90 bool allow_file_access
,
93 bool Populate(const std::vector
<std::string
>& patterns
,
95 bool allow_file_access
,
99 // The list of URL patterns that comprise the extent.
100 std::set
<URLPattern
> patterns_
;
103 } // namespace extensions
105 #endif // EXTENSIONS_COMMMON_URL_PATTERN_SET_H_