Ignore non-active fullscreen windows for shelf state.
[chromium-blink-merge.git] / extensions / common / url_pattern_set.h
blobda6ad132db183433d726363f5d291b9e412e0158
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_
8 #include <set>
10 #include "base/memory/scoped_ptr.h"
11 #include "extensions/common/url_pattern.h"
13 class GURL;
15 namespace base {
16 class ListValue;
17 class Value;
20 namespace extensions {
22 // Represents the set of URLs an extension uses for web content.
23 class URLPatternSet {
24 public:
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,
31 URLPatternSet* out);
33 // Clears |out| and populates the set with the intersection of |set1|
34 // and |set2|.
35 static void CreateIntersection(const URLPatternSet& set1,
36 const URLPatternSet& set2,
37 URLPatternSet* out);
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,
42 URLPatternSet* out);
44 // Clears |out| and populates it with the union of all sets in |sets|.
45 static void CreateUnion(const std::vector<URLPatternSet>& sets,
46 URLPatternSet* out);
48 URLPatternSet();
49 URLPatternSet(const URLPatternSet& rhs);
50 explicit URLPatternSet(const std::set<URLPattern>& patterns);
51 ~URLPatternSet();
53 URLPatternSet& operator=(const URLPatternSet& rhs);
54 bool operator==(const URLPatternSet& rhs) const;
56 bool is_empty() const;
57 size_t size() 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);
69 void ClearPatterns();
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,
89 int valid_schemes,
90 bool allow_file_access,
91 std::string* error);
93 bool Populate(const std::vector<std::string>& patterns,
94 int valid_schemes,
95 bool allow_file_access,
96 std::string* error);
98 private:
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_