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