Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <functional> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 bool operator==(const URLPattern& other) const; | 92 bool operator==(const URLPattern& other) const; |
| 93 | 93 |
| 94 // Initializes this instance by parsing the provided string. Returns | 94 // Initializes this instance by parsing the provided string. Returns |
| 95 // URLPattern::PARSE_SUCCESS on success, or an error code otherwise. On | 95 // URLPattern::PARSE_SUCCESS on success, or an error code otherwise. On |
| 96 // failure, this instance will have some intermediate values and is in an | 96 // failure, this instance will have some intermediate values and is in an |
| 97 // invalid state. | 97 // invalid state. |
| 98 ParseResult Parse(const std::string& pattern_str); | 98 ParseResult Parse(const std::string& pattern_str); |
| 99 | 99 |
| 100 // Gets the bitmask of valid schemes. | 100 // Gets the bitmask of valid schemes. |
| 101 int valid_schemes() const { return valid_schemes_; } | 101 int valid_schemes() const { return valid_schemes_; } |
| 102 // Sets the bitmask of valid schemes and inner_schemes. | |
|
Aaron Boodman
2012/02/15 21:31:18
Please put an empty line before each of these comm
| |
| 102 void SetValidSchemes(int valid_schemes); | 103 void SetValidSchemes(int valid_schemes); |
| 104 // Gets the bitmask of valid inner schemes. | |
| 105 int valid_inner_schemes() const { return valid_inner_schemes_; } | |
| 106 // Sets the bitmask of valid inner_schemes. | |
| 107 void SetValidInnerSchemes(int valid_schemes); | |
| 103 | 108 |
| 104 // Gets the host the pattern matches. This can be an empty string if the | 109 // Gets the host the pattern matches. This can be an empty string if the |
| 105 // pattern matches all hosts (the input was <scheme>://*/<whatever>). | 110 // pattern matches all hosts (the input was <scheme>://*/<whatever>). |
| 106 const std::string& host() const { return host_; } | 111 const std::string& host() const { return host_; } |
| 107 void SetHost(const std::string& host); | 112 void SetHost(const std::string& host); |
| 108 | 113 |
| 109 // Gets whether to match subdomains of host(). | 114 // Gets whether to match subdomains of host(). |
| 110 bool match_subdomains() const { return match_subdomains_; } | 115 bool match_subdomains() const { return match_subdomains_; } |
| 111 void SetMatchSubdomains(bool val); | 116 void SetMatchSubdomains(bool val); |
| 112 | 117 |
| 113 // Gets the path the pattern matches with the leading slash. This can have | 118 // Gets the path the pattern matches with the leading slash. This can have |
| 114 // embedded asterisks which are interpreted using glob rules. | 119 // embedded asterisks which are interpreted using glob rules. |
| 115 const std::string& path() const { return path_; } | 120 const std::string& path() const { return path_; } |
| 116 void SetPath(const std::string& path); | 121 void SetPath(const std::string& path); |
| 117 | 122 |
| 118 // Returns true if this pattern matches all urls. | 123 // Returns true if this pattern matches all urls. |
| 119 bool match_all_urls() const { return match_all_urls_; } | 124 bool match_all_urls() const { return match_all_urls_; } |
| 120 void SetMatchAllURLs(bool val); | 125 void SetMatchAllURLs(bool val); |
| 121 | 126 |
| 122 // Sets the scheme for pattern matches. This can be a single '*' if the | 127 // Sets the scheme for pattern matches. This can be a single '*' if the |
| 123 // pattern matches all valid schemes (as defined by the valid_schemes_ | 128 // pattern matches all valid schemes (as defined by the valid_schemes_ |
| 124 // property). Returns false on failure (if the scheme is not valid). | 129 // property). Returns false on failure (if the scheme is not valid). |
| 125 bool SetScheme(const std::string& scheme); | 130 bool SetScheme(const std::string& scheme); |
| 131 // Sets the inner scheme for pattern matches; this can only be used for | |
| 132 // patterns whose scheme has already been set to "filesystem". This can be a | |
|
Aaron Boodman
2012/02/15 21:31:18
Why make this restriction? It seems easier to just
ericu
2012/02/16 01:42:56
If you're doing something that's obviously wrong,
| |
| 133 // single '*' if the pattern matches all valid schemes (as defined by the | |
| 134 // valid_inner_schemes_ property). Returns false on failure (if the scheme is | |
| 135 // not valid). | |
| 136 bool SetInnerScheme(const std::string& scheme); | |
| 126 // Note: You should use MatchesScheme() instead of this getter unless you | 137 // Note: You should use MatchesScheme() instead of this getter unless you |
|
Aaron Boodman
2012/02/15 21:31:18
In retrospect, these warnings are overly scary. Ma
ericu
2012/02/22 00:00:51
Done.
| |
| 127 // absolutely need the exact scheme. This is exposed for testing. | 138 // absolutely need the exact scheme. This is exposed for testing. |
| 128 const std::string& scheme() const { return scheme_; } | 139 const std::string& scheme() const { return scheme_; } |
| 140 // Note: You should use MatchesInnerScheme() instead of this getter unless you | |
| 141 // absolutely need the exact scheme. This is exposed for testing. | |
| 142 const std::string& inner_scheme() const { return inner_scheme_; } | |
| 129 | 143 |
| 130 // Returns true if the specified scheme can be used in this URL pattern, and | 144 // Returns true if the specified scheme can be used in this URL pattern, and |
| 131 // false otherwise. Uses valid_schemes_ to determine validity. | 145 // false otherwise. Uses valid_schemes_ to determine validity. |
| 132 bool IsValidScheme(const std::string& scheme) const; | 146 bool IsValidScheme(const std::string& scheme) const; |
| 133 | 147 |
| 148 // Returns true if the specified scheme can be used in this URL pattern, and | |
|
Aaron Boodman
2012/02/15 21:31:18
.replace("specified scheme", "specified inner sche
ericu
2012/02/22 00:00:51
Done.
| |
| 149 // false otherwise. Uses valid_inner_schemes_ to determine validity. | |
| 150 bool IsValidInnerScheme(const std::string& scheme) const; | |
| 151 | |
| 134 // Returns true if this instance matches the specified URL. | 152 // Returns true if this instance matches the specified URL. |
| 135 bool MatchesURL(const GURL& test) const; | 153 bool MatchesURL(const GURL& test) const; |
| 136 | 154 |
| 137 // Returns true if this instance matches the specified security origin. | 155 // Returns true if this instance matches the specified security origin. |
| 138 bool MatchesSecurityOrigin(const GURL& test) const; | 156 bool MatchesSecurityOrigin(const GURL& test) const; |
| 139 | 157 |
| 140 // Returns true if |test| matches our scheme. | 158 // Returns true if |test| matches our scheme. |
| 141 bool MatchesScheme(const std::string& test) const; | 159 bool MatchesScheme(const std::string& test) const; |
| 142 | 160 |
| 161 // Returns true if |test| matches our inner scheme. | |
| 162 // Only use this if scheme is "filesystem". | |
| 163 bool MatchesInnerScheme(const std::string& test) const; | |
| 164 | |
| 143 // Returns true if |test| matches our host. | 165 // Returns true if |test| matches our host. |
| 144 bool MatchesHost(const std::string& test) const; | 166 bool MatchesHost(const std::string& test) const; |
| 145 bool MatchesHost(const GURL& test) const; | 167 bool MatchesHost(const GURL& test) const; |
| 146 | 168 |
| 147 // Returns true if |test| matches our path. | 169 // Returns true if |test| matches our path. |
| 148 bool MatchesPath(const std::string& test) const; | 170 bool MatchesPath(const std::string& test) const; |
| 149 | 171 |
| 150 // Returns true if |port| matches our port. | 172 // Returns true if |port| matches our port. |
| 151 bool MatchesPort(int port) const; | 173 bool MatchesPort(int port) const; |
| 152 | 174 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 | 215 |
| 194 // If the URLPattern contains a wildcard scheme, returns a list of | 216 // If the URLPattern contains a wildcard scheme, returns a list of |
| 195 // equivalent literal schemes, otherwise returns the current scheme. | 217 // equivalent literal schemes, otherwise returns the current scheme. |
| 196 std::vector<std::string> GetExplicitSchemes() const; | 218 std::vector<std::string> GetExplicitSchemes() const; |
| 197 | 219 |
| 198 // A bitmask containing the schemes which are considered valid for this | 220 // A bitmask containing the schemes which are considered valid for this |
| 199 // pattern. Parse() uses this to decide whether a pattern contains a valid | 221 // pattern. Parse() uses this to decide whether a pattern contains a valid |
| 200 // scheme. MatchesScheme uses this to decide whether a wildcard scheme_ | 222 // scheme. MatchesScheme uses this to decide whether a wildcard scheme_ |
| 201 // matches a given test scheme. | 223 // matches a given test scheme. |
| 202 int valid_schemes_; | 224 int valid_schemes_; |
| 225 // A bitmask containing the inner schemes which are considered valid for this | |
|
Aaron Boodman
2012/02/15 21:31:18
.insertBefore("\n");
ericu
2012/02/22 00:00:51
Done.
| |
| 226 // pattern. Parse() uses this to decide whether a pattern contains a valid | |
| 227 // scheme. MatchesInnerScheme uses this to decide whether a wildcard | |
| 228 // inner_scheme_ matches a given test scheme. | |
| 229 int valid_inner_schemes_; | |
| 203 | 230 |
| 204 // True if this is a special-case "<all_urls>" pattern. | 231 // True if this is a special-case "<all_urls>" pattern. |
| 205 bool match_all_urls_; | 232 bool match_all_urls_; |
| 206 | 233 |
| 207 // The scheme for the pattern. | 234 // The scheme for the pattern. |
| 208 std::string scheme_; | 235 std::string scheme_; |
| 209 | 236 |
| 237 // The inner scheme for the pattern, used only when scheme_ is "filesystem". | |
| 238 std::string inner_scheme_; | |
| 239 | |
| 210 // The host without any leading "*" components. | 240 // The host without any leading "*" components. |
| 211 std::string host_; | 241 std::string host_; |
| 212 | 242 |
| 213 // Whether we should match subdomains of the host. This is true if the first | 243 // Whether we should match subdomains of the host. This is true if the first |
| 214 // component of the pattern's host was "*". | 244 // component of the pattern's host was "*". |
| 215 bool match_subdomains_; | 245 bool match_subdomains_; |
| 216 | 246 |
| 217 // The port. | 247 // The port. |
| 218 std::string port_; | 248 std::string port_; |
| 219 | 249 |
| 220 // The path to match. This is everything after the host of the URL, or | 250 // The path to match. This is everything after the host of the URL, or |
| 221 // everything after the scheme in the case of file:// URLs. | 251 // everything after the scheme in the case of file:// URLs. |
| 222 std::string path_; | 252 std::string path_; |
| 223 | 253 |
| 224 // The path with "?" and "\" characters escaped for use with the | 254 // The path with "?" and "\" characters escaped for use with the |
| 225 // MatchPattern() function. | 255 // MatchPattern() function. |
| 226 std::string path_escaped_; | 256 std::string path_escaped_; |
| 227 | 257 |
| 228 // A string representing this URLPattern. | 258 // A string representing this URLPattern. |
| 229 mutable std::string spec_; | 259 mutable std::string spec_; |
| 230 }; | 260 }; |
| 231 | 261 |
| 232 typedef std::vector<URLPattern> URLPatternList; | 262 typedef std::vector<URLPattern> URLPatternList; |
| 233 | 263 |
| 234 #endif // CHROME_COMMON_EXTENSIONS_URL_PATTERN_H_ | 264 #endif // CHROME_COMMON_EXTENSIONS_URL_PATTERN_H_ |
| OLD | NEW |