Chromium Code Reviews| 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 #ifndef EXTENSIONS_COMMON_URL_PATTERN_H_ | 4 #ifndef EXTENSIONS_COMMON_URL_PATTERN_H_ |
| 5 #define EXTENSIONS_COMMON_URL_PATTERN_H_ | 5 #define EXTENSIONS_COMMON_URL_PATTERN_H_ |
| 6 | 6 |
| 7 #include <functional> | 7 #include <functional> |
| 8 #include <iosfwd> | 8 #include <iosfwd> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 URLPattern(const URLPattern& other); | 96 URLPattern(const URLPattern& other); |
| 97 ~URLPattern(); | 97 ~URLPattern(); |
| 98 | 98 |
| 99 bool operator<(const URLPattern& other) const; | 99 bool operator<(const URLPattern& other) const; |
| 100 bool operator>(const URLPattern& other) const; | 100 bool operator>(const URLPattern& other) const; |
| 101 bool operator==(const URLPattern& other) const; | 101 bool operator==(const URLPattern& other) const; |
| 102 | 102 |
| 103 // Initializes this instance by parsing the provided string. Returns | 103 // Initializes this instance by parsing the provided string. Returns |
| 104 // URLPattern::PARSE_SUCCESS on success, or an error code otherwise. On | 104 // URLPattern::PARSE_SUCCESS on success, or an error code otherwise. On |
| 105 // failure, this instance will have some intermediate values and is in an | 105 // failure, this instance will have some intermediate values and is in an |
| 106 // invalid state. | 106 // invalid state. If you want to allow the match pattern to specify a wildcard |
| 107 ParseResult Parse(const std::string& pattern_str); | 107 // for the effective TLD, make |allow_wildcard_effective_tld| true. |
| 108 ParseResult Parse(const std::string& pattern_str, | |
| 109 const bool allow_wildcard_effective_tld = false); | |
|
Devlin
2017/01/26 22:47:40
default parameters aren't allowed by style
nrpeter
2017/02/03 19:32:25
Done, switched to overloading.
| |
| 108 | 110 |
| 109 // Gets the bitmask of valid schemes. | 111 // Gets the bitmask of valid schemes. |
| 110 int valid_schemes() const { return valid_schemes_; } | 112 int valid_schemes() const { return valid_schemes_; } |
| 111 void SetValidSchemes(int valid_schemes); | 113 void SetValidSchemes(int valid_schemes); |
| 112 | 114 |
| 113 // Gets the host the pattern matches. This can be an empty string if the | 115 // Gets the host the pattern matches. This can be an empty string if the |
| 114 // pattern matches all hosts (the input was <scheme>://*/<whatever>). | 116 // pattern matches all hosts (the input was <scheme>://*/<whatever>). |
| 115 const std::string& host() const { return host_; } | 117 const std::string& host() const { return host_; } |
| 116 void SetHost(const std::string& host); | 118 void SetHost(const std::string& host); |
| 117 | 119 |
| 118 // Gets whether to match subdomains of host(). | 120 // Gets whether to match subdomains of host(). |
| 119 bool match_subdomains() const { return match_subdomains_; } | 121 bool match_subdomains() const { return match_subdomains_; } |
| 120 void SetMatchSubdomains(bool val); | 122 void SetMatchSubdomains(bool val); |
| 121 | 123 |
| 124 // Gets whether to match effective TLD of host(). If false, during a match we | |
|
Devlin
2017/01/26 22:47:40
This comment doesn't seem quite clear to me by its
nrpeter
2017/02/03 19:32:25
Done.
| |
| 125 // disregard any effective TLD present in host() and treat it as a wildcard. | |
| 126 bool match_effective_tld() const { return match_effective_tld_; } | |
| 127 void SetMatchEffectiveTld(bool val); | |
| 128 | |
| 122 // Gets the path the pattern matches with the leading slash. This can have | 129 // Gets the path the pattern matches with the leading slash. This can have |
| 123 // embedded asterisks which are interpreted using glob rules. | 130 // embedded asterisks which are interpreted using glob rules. |
| 124 const std::string& path() const { return path_; } | 131 const std::string& path() const { return path_; } |
| 125 void SetPath(const std::string& path); | 132 void SetPath(const std::string& path); |
| 126 | 133 |
| 127 // Returns true if this pattern matches all urls. | 134 // Returns true if this pattern matches all urls. |
| 128 bool match_all_urls() const { return match_all_urls_; } | 135 bool match_all_urls() const { return match_all_urls_; } |
| 129 void SetMatchAllURLs(bool val); | 136 void SetMatchAllURLs(bool val); |
| 130 | 137 |
| 131 // Sets the scheme for pattern matches. This can be a single '*' if the | 138 // Sets the scheme for pattern matches. This can be a single '*' if the |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 // The scheme for the pattern. | 243 // The scheme for the pattern. |
| 237 std::string scheme_; | 244 std::string scheme_; |
| 238 | 245 |
| 239 // The host without any leading "*" components. | 246 // The host without any leading "*" components. |
| 240 std::string host_; | 247 std::string host_; |
| 241 | 248 |
| 242 // Whether we should match subdomains of the host. This is true if the first | 249 // Whether we should match subdomains of the host. This is true if the first |
| 243 // component of the pattern's host was "*". | 250 // component of the pattern's host was "*". |
| 244 bool match_subdomains_; | 251 bool match_subdomains_; |
| 245 | 252 |
| 253 // Whether we should match the effective TLD of the host. This is true by | |
| 254 // default and only false if the the pattern's host ends with ".*" | |
| 255 // (e.g. https://example.*/*). | |
| 256 bool match_effective_tld_; | |
| 257 | |
| 246 // The port. | 258 // The port. |
| 247 std::string port_; | 259 std::string port_; |
| 248 | 260 |
| 249 // The path to match. This is everything after the host of the URL, or | 261 // The path to match. This is everything after the host of the URL, or |
| 250 // everything after the scheme in the case of file:// URLs. | 262 // everything after the scheme in the case of file:// URLs. |
| 251 std::string path_; | 263 std::string path_; |
| 252 | 264 |
| 253 // The path with "?" and "\" characters escaped for use with the | 265 // The path with "?" and "\" characters escaped for use with the |
| 254 // MatchPattern() function. | 266 // MatchPattern() function. |
| 255 std::string path_escaped_; | 267 std::string path_escaped_; |
| 256 | 268 |
| 257 // A string representing this URLPattern. | 269 // A string representing this URLPattern. |
| 258 mutable std::string spec_; | 270 mutable std::string spec_; |
| 259 }; | 271 }; |
| 260 | 272 |
| 261 std::ostream& operator<<(std::ostream& out, const URLPattern& url_pattern); | 273 std::ostream& operator<<(std::ostream& out, const URLPattern& url_pattern); |
| 262 | 274 |
| 263 typedef std::vector<URLPattern> URLPatternList; | 275 typedef std::vector<URLPattern> URLPatternList; |
| 264 | 276 |
| 265 #endif // EXTENSIONS_COMMON_URL_PATTERN_H_ | 277 #endif // EXTENSIONS_COMMON_URL_PATTERN_H_ |
| OLD | NEW |