Files.app: Dispatch 'drive-connection-changed' event on initialization of VolumeManag...
[chromium-blink-merge.git] / extensions / common / url_pattern_set.h
blob30db55827b9268ddd2df76e0da4d72bda311b3f1
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_COMMON_URL_PATTERN_SET_H_
6 #define EXTENSIONS_COMMON_URL_PATTERN_SET_H_
8 #include <iosfwd>
9 #include <set>
11 #include "base/memory/scoped_ptr.h"
12 #include "extensions/common/url_pattern.h"
14 class GURL;
16 namespace base {
17 class ListValue;
18 class Value;
21 namespace extensions {
23 // Represents the set of URLs an extension uses for web content.
24 class URLPatternSet {
25 public:
26 typedef std::set<URLPattern>::const_iterator const_iterator;
27 typedef std::set<URLPattern>::iterator iterator;
29 // Clears |out| and populates the set with |set1| - |set2|.
30 static void CreateDifference(const URLPatternSet& set1,
31 const URLPatternSet& set2,
32 URLPatternSet* out);
34 // Clears |out| and populates the set with the intersection of |set1|
35 // and |set2|.
36 static void CreateIntersection(const URLPatternSet& set1,
37 const URLPatternSet& set2,
38 URLPatternSet* out);
40 // Clears |out| and populates the set with the union of |set1| and |set2|.
41 static void CreateUnion(const URLPatternSet& set1,
42 const URLPatternSet& set2,
43 URLPatternSet* out);
45 // Clears |out| and populates it with the union of all sets in |sets|.
46 static void CreateUnion(const std::vector<URLPatternSet>& sets,
47 URLPatternSet* out);
49 URLPatternSet();
50 URLPatternSet(const URLPatternSet& rhs);
51 explicit URLPatternSet(const std::set<URLPattern>& patterns);
52 ~URLPatternSet();
54 URLPatternSet& operator=(const URLPatternSet& rhs);
55 bool operator==(const URLPatternSet& rhs) const;
57 bool is_empty() const;
58 size_t size() const;
59 const std::set<URLPattern>& patterns() const { return patterns_; }
60 const_iterator begin() const { return patterns_.begin(); }
61 const_iterator end() const { return patterns_.end(); }
63 // Adds a pattern to the set. Returns true if a new pattern was inserted,
64 // false if the pattern was already in the set.
65 bool AddPattern(const URLPattern& pattern);
67 // Adds all patterns from |set| into this.
68 void AddPatterns(const URLPatternSet& set);
70 void ClearPatterns();
72 // Adds a pattern based on |origin| to the set.
73 bool AddOrigin(int valid_schemes, const GURL& origin);
75 // Returns true if every URL that matches |set| is matched by this. In other
76 // words, if every pattern in |set| is encompassed by a pattern in this.
77 bool Contains(const URLPatternSet& set) const;
79 // Returns true if any pattern in this set encompasses |pattern|.
80 bool ContainsPattern(const URLPattern& pattern) const;
82 // Test if the extent contains a URL.
83 bool MatchesURL(const GURL& url) const;
85 // Test if the extent matches all URLs (for example, <all_urls>).
86 bool MatchesAllURLs() const;
88 bool MatchesSecurityOrigin(const GURL& origin) const;
90 // Returns true if there is a single URL that would be in two extents.
91 bool OverlapsWith(const URLPatternSet& other) const;
93 // Converts to and from Value for serialization to preferences.
94 scoped_ptr<base::ListValue> ToValue() const;
95 bool Populate(const base::ListValue& value,
96 int valid_schemes,
97 bool allow_file_access,
98 std::string* error);
100 // Converts to and from a vector of strings.
101 scoped_ptr<std::vector<std::string> > ToStringVector() const;
102 bool Populate(const std::vector<std::string>& patterns,
103 int valid_schemes,
104 bool allow_file_access,
105 std::string* error);
107 private:
108 // The list of URL patterns that comprise the extent.
109 std::set<URLPattern> patterns_;
112 std::ostream& operator<<(std::ostream& out,
113 const URLPatternSet& url_pattern_set);
115 } // namespace extensions
117 #endif // EXTENSIONS_COMMON_URL_PATTERN_SET_H_