OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 EXTENSIONS_COMMMON_URL_PATTERN_SET_H_ | 5 #ifndef EXTENSIONS_COMMMON_URL_PATTERN_SET_H_ |
6 #define EXTENSIONS_COMMMON_URL_PATTERN_SET_H_ | 6 #define EXTENSIONS_COMMMON_URL_PATTERN_SET_H_ |
7 | 7 |
8 #include <ostream> | |
8 #include <set> | 9 #include <set> |
9 | 10 |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "extensions/common/url_pattern.h" | 12 #include "extensions/common/url_pattern.h" |
12 | 13 |
13 class GURL; | 14 class GURL; |
14 | 15 |
15 namespace base { | 16 namespace base { |
16 class ListValue; | 17 class ListValue; |
17 class Value; | 18 class Value; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 // Adds a pattern to the set. Returns true if a new pattern was inserted, | 63 // 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 // false if the pattern was already in the set. |
64 bool AddPattern(const URLPattern& pattern); | 65 bool AddPattern(const URLPattern& pattern); |
65 | 66 |
66 // Adds all patterns from |set| into this. | 67 // Adds all patterns from |set| into this. |
67 void AddPatterns(const URLPatternSet& set); | 68 void AddPatterns(const URLPatternSet& set); |
68 | 69 |
69 void ClearPatterns(); | 70 void ClearPatterns(); |
70 | 71 |
71 // Returns true if the permission |set| is a subset of this. | 72 // Returns true if the permission |set| is a subset of this. |
73 // | |
74 // This is equality based, so {<all_urls>} is not considered to contain | |
75 // {google.com}. For that, use Encompasses. | |
Matt Perry
2013/02/12 01:14:47
This is a strange distinction. Why not just fix Co
not at google - send to devlin
2013/02/12 01:49:36
Yeah, it is strange. I had it like you said - just
| |
72 bool Contains(const URLPatternSet& set) const; | 76 bool Contains(const URLPatternSet& set) const; |
73 | 77 |
78 // Returns true if any pattern in this set encompasses |pattern|. | |
79 // | |
80 // This is more inclusive than Contains: while {all_urls} is not considered | |
81 // to contain {google.com}, it does encompass it. | |
82 bool EncompassesPattern(const URLPattern& pattern) const; | |
83 | |
84 // Returns true if every pattern in |other| is encompassed by some pattern | |
85 // in this set. | |
86 bool Encompasses(const URLPatternSet& other) const; | |
87 | |
74 // Test if the extent contains a URL. | 88 // Test if the extent contains a URL. |
75 bool MatchesURL(const GURL& url) const; | 89 bool MatchesURL(const GURL& url) const; |
76 | 90 |
77 bool MatchesSecurityOrigin(const GURL& origin) const; | 91 bool MatchesSecurityOrigin(const GURL& origin) const; |
78 | 92 |
79 // Returns true if there is a single URL that would be in two extents. | 93 // Returns true if there is a single URL that would be in two extents. |
80 bool OverlapsWith(const URLPatternSet& other) const; | 94 bool OverlapsWith(const URLPatternSet& other) const; |
81 | 95 |
82 // Converts to and from Value for serialization to preferences. | 96 // Converts to and from Value for serialization to preferences. |
83 scoped_ptr<base::ListValue> ToValue() const; | 97 scoped_ptr<base::ListValue> ToValue() const; |
84 bool Populate(const base::ListValue& value, | 98 bool Populate(const base::ListValue& value, |
85 int valid_schemes, | 99 int valid_schemes, |
86 bool allow_file_access, | 100 bool allow_file_access, |
87 std::string* error); | 101 std::string* error); |
88 | 102 |
89 bool Populate(const std::vector<std::string>& patterns, | 103 bool Populate(const std::vector<std::string>& patterns, |
90 int valid_schemes, | 104 int valid_schemes, |
91 bool allow_file_access, | 105 bool allow_file_access, |
92 std::string* error); | 106 std::string* error); |
93 | 107 |
94 private: | 108 private: |
95 // The list of URL patterns that comprise the extent. | 109 // The list of URL patterns that comprise the extent. |
96 std::set<URLPattern> patterns_; | 110 std::set<URLPattern> patterns_; |
97 }; | 111 }; |
98 | 112 |
113 std::ostream& operator<<(std::ostream& out, const URLPatternSet& set); | |
114 | |
99 } // namespace extensions | 115 } // namespace extensions |
100 | 116 |
101 #endif // EXTENSIONS_COMMMON_URL_PATTERN_SET_H_ | 117 #endif // EXTENSIONS_COMMMON_URL_PATTERN_SET_H_ |
OLD | NEW |