OLD | NEW |
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 #ifndef CHROME_COMMON_EXTENSIONS_URL_PATTERN_H_ | 4 #ifndef CHROME_COMMON_EXTENSIONS_URL_PATTERN_H_ |
5 #define CHROME_COMMON_EXTENSIONS_URL_PATTERN_H_ | 5 #define CHROME_COMMON_EXTENSIONS_URL_PATTERN_H_ |
6 | 6 |
7 #include <functional> | |
8 #include <string> | 7 #include <string> |
9 #include <vector> | 8 #include <vector> |
10 | 9 |
11 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
12 | 11 |
13 // A pattern that can be used to match URLs. A URLPattern is a very restricted | 12 // A pattern that can be used to match URLs. A URLPattern is a very restricted |
14 // subset of URL syntax: | 13 // subset of URL syntax: |
15 // | 14 // |
16 // <url-pattern> := <scheme>://<host><path> | '<all_urls>' | 15 // <url-pattern> := <scheme>://<host><path> | '<all_urls>' |
17 // <scheme> := '*' | 'http' | 'https' | 'file' | 'ftp' | 'chrome' | 16 // <scheme> := '*' | 'http' | 'https' | 'file' | 'ftp' | 'chrome' |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // instance. This method is symmetrical: Calling other.OverlapsWith(this) | 156 // instance. This method is symmetrical: Calling other.OverlapsWith(this) |
158 // would result in the same answer. | 157 // would result in the same answer. |
159 bool OverlapsWith(const URLPattern& other) const; | 158 bool OverlapsWith(const URLPattern& other) const; |
160 | 159 |
161 // Conver this URLPattern into an equivalent set of URLPatterns that don't use | 160 // Conver this URLPattern into an equivalent set of URLPatterns that don't use |
162 // a wildcard in the scheme component. If this URLPattern doesn't use a | 161 // a wildcard in the scheme component. If this URLPattern doesn't use a |
163 // wildcard scheme, then the returned set will contain one element that is | 162 // wildcard scheme, then the returned set will contain one element that is |
164 // equivalent to this instance. | 163 // equivalent to this instance. |
165 std::vector<URLPattern> ConvertToExplicitSchemes() const; | 164 std::vector<URLPattern> ConvertToExplicitSchemes() const; |
166 | 165 |
167 static bool EffectiveHostCompare(const URLPattern& a, const URLPattern& b) { | |
168 if (a.match_all_urls_ && b.match_all_urls_) | |
169 return false; | |
170 return a.host_.compare(b.host_) < 0; | |
171 }; | |
172 | |
173 // Used for origin comparisons in a std::set. | |
174 class EffectiveHostCompareFunctor : | |
175 public std::binary_function<URLPattern, URLPattern, bool> { | |
176 public: | |
177 bool operator()(const URLPattern& a, const URLPattern& b) const { | |
178 return EffectiveHostCompare(a, b); | |
179 }; | |
180 }; | |
181 | |
182 private: | 166 private: |
183 // A bitmask containing the schemes which are considered valid for this | 167 // A bitmask containing the schemes which are considered valid for this |
184 // pattern. Parse() uses this to decide whether a pattern contains a valid | 168 // pattern. Parse() uses this to decide whether a pattern contains a valid |
185 // scheme. MatchesScheme uses this to decide whether a wildcard scheme_ | 169 // scheme. MatchesScheme uses this to decide whether a wildcard scheme_ |
186 // matches a given test scheme. | 170 // matches a given test scheme. |
187 int valid_schemes_; | 171 int valid_schemes_; |
188 | 172 |
189 // True if this is a special-case "<all_urls>" pattern. | 173 // True if this is a special-case "<all_urls>" pattern. |
190 bool match_all_urls_; | 174 bool match_all_urls_; |
191 | 175 |
(...skipping 11 matching lines...) Expand all Loading... |
203 // everything after the scheme in the case of file:// URLs. | 187 // everything after the scheme in the case of file:// URLs. |
204 std::string path_; | 188 std::string path_; |
205 | 189 |
206 // The path with "?" and "\" characters escaped for use with the | 190 // The path with "?" and "\" characters escaped for use with the |
207 // MatchPatternASCII() function. This is populated lazily, the first time it | 191 // MatchPatternASCII() function. This is populated lazily, the first time it |
208 // is needed. | 192 // is needed. |
209 mutable std::string path_escaped_; | 193 mutable std::string path_escaped_; |
210 }; | 194 }; |
211 | 195 |
212 #endif // CHROME_COMMON_EXTENSIONS_URL_PATTERN_H_ | 196 #endif // CHROME_COMMON_EXTENSIONS_URL_PATTERN_H_ |
OLD | NEW |