| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 PARSE_ERROR_INVALID_HOST_WILDCARD, | 116 PARSE_ERROR_INVALID_HOST_WILDCARD, |
| 117 PARSE_ERROR_EMPTY_PATH, | 117 PARSE_ERROR_EMPTY_PATH, |
| 118 PARSE_ERROR_HAS_COLON, // Only checked when parsing with ERROR_ON_PORTS. | 118 PARSE_ERROR_HAS_COLON, // Only checked when parsing with ERROR_ON_PORTS. |
| 119 PARSE_ERROR_INVALID_PORT, // Only checked when parsing with USE_PORTS. | 119 PARSE_ERROR_INVALID_PORT, // Only checked when parsing with USE_PORTS. |
| 120 NUM_PARSE_RESULTS | 120 NUM_PARSE_RESULTS |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 // The <all_urls> string pattern. | 123 // The <all_urls> string pattern. |
| 124 static const char kAllUrlsPattern[]; | 124 static const char kAllUrlsPattern[]; |
| 125 | 125 |
| 126 // Construct an URLPattern with the given set of allowable schemes. See | 126 explicit URLPattern(ParseOption parse_option, int valid_schemes); |
| 127 // valid_schemes_ for more info. | |
| 128 explicit URLPattern(int valid_schemes); | |
| 129 | 127 |
| 130 // Convenience to construct a URLPattern from a string. The string is expected | 128 // Convenience to construct a URLPattern from a string. The string is expected |
| 131 // to be a valid pattern. If the string is not known ahead of time, use | 129 // to be a valid pattern when parsed with USE_PORTS. If the string is not |
| 132 // Parse() instead, which returns success or failure. | 130 // known ahead of time, use Parse() instead, which returns success or failure. |
| 133 URLPattern(int valid_schemes, const std::string& pattern); | 131 URLPattern(int valid_schemes, const std::string& pattern); |
| 134 | 132 |
| 135 // Note: don't use this directly. This exists so URLPattern can be used | |
| 136 // with STL containers. | |
| 137 URLPattern(); | 133 URLPattern(); |
| 138 ~URLPattern(); | 134 ~URLPattern(); |
| 139 | 135 |
| 140 bool operator<(const URLPattern& other) const; | 136 bool operator<(const URLPattern& other) const; |
| 141 bool operator==(const URLPattern& other) const; | 137 bool operator==(const URLPattern& other) const; |
| 142 | 138 |
| 143 // Initializes this instance by parsing the provided string. Returns | 139 // Initializes this instance by parsing the provided string. Returns |
| 144 // URLPattern::PARSE_SUCCESS on success, or an error code otherwise. On | 140 // URLPattern::PARSE_SUCCESS on success, or an error code otherwise. On |
| 145 // failure, this instance will have some intermediate values and is in an | 141 // failure, this instance will have some intermediate values and is in an |
| 146 // invalid state. Adding error checks to URLPattern::Parse() can cause | 142 // invalid state. |
| 147 // patterns in installed extensions to fail. If an installed extension | 143 ParseResult Parse(const std::string& pattern_str); |
| 148 // uses a pattern that was valid but fails a new error check, the | |
| 149 // extension will fail to load when chrome is auto-updated. To avoid | |
| 150 // this, new parse checks are enabled only when |strictness| is | |
| 151 // OPTION_STRICT. OPTION_STRICT should be used when loading in developer | |
| 152 // mode, or when an extension's patterns are controlled by chrome (such | |
| 153 // as component extensions). | |
| 154 ParseResult Parse(const std::string& pattern_str, | |
| 155 ParseOption strictness); | |
| 156 | 144 |
| 157 // Gets the bitmask of valid schemes. | 145 // Gets the bitmask of valid schemes. |
| 158 int valid_schemes() const { return valid_schemes_; } | 146 int valid_schemes() const { return valid_schemes_; } |
| 159 void SetValidSchemes(int valid_schemes); | 147 void SetValidSchemes(int valid_schemes); |
| 160 | 148 |
| 149 // Gets or sets the parse option used with Parse(). |
| 150 ParseOption parse_option() const { return parse_option_; } |
| 151 void SetParseOption(ParseOption parse_option); |
| 152 |
| 161 // Gets the host the pattern matches. This can be an empty string if the | 153 // Gets the host the pattern matches. This can be an empty string if the |
| 162 // pattern matches all hosts (the input was <scheme>://*/<whatever>). | 154 // pattern matches all hosts (the input was <scheme>://*/<whatever>). |
| 163 const std::string& host() const { return host_; } | 155 const std::string& host() const { return host_; } |
| 164 void SetHost(const std::string& host); | 156 void SetHost(const std::string& host); |
| 165 | 157 |
| 166 // Gets whether to match subdomains of host(). | 158 // Gets whether to match subdomains of host(). |
| 167 bool match_subdomains() const { return match_subdomains_; } | 159 bool match_subdomains() const { return match_subdomains_; } |
| 168 void SetMatchSubdomains(bool val); | 160 void SetMatchSubdomains(bool val); |
| 169 | 161 |
| 170 // Gets the path the pattern matches with the leading slash. This can have | 162 // Gets the path the pattern matches with the leading slash. This can have |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 private: | 237 private: |
| 246 // Returns true if any of the |schemes| items matches our scheme. | 238 // Returns true if any of the |schemes| items matches our scheme. |
| 247 bool MatchesAnyScheme(const std::vector<std::string>& schemes) const; | 239 bool MatchesAnyScheme(const std::vector<std::string>& schemes) const; |
| 248 | 240 |
| 249 bool MatchesSecurityOriginHelper(const GURL& test) const; | 241 bool MatchesSecurityOriginHelper(const GURL& test) const; |
| 250 | 242 |
| 251 // If the URLPattern contains a wildcard scheme, returns a list of | 243 // If the URLPattern contains a wildcard scheme, returns a list of |
| 252 // equivalent literal schemes, otherwise returns the current scheme. | 244 // equivalent literal schemes, otherwise returns the current scheme. |
| 253 std::vector<std::string> GetExplicitSchemes() const; | 245 std::vector<std::string> GetExplicitSchemes() const; |
| 254 | 246 |
| 247 // Controls how to interpret the input to Parse(). |
| 248 ParseOption parse_option_; |
| 249 |
| 255 // A bitmask containing the schemes which are considered valid for this | 250 // A bitmask containing the schemes which are considered valid for this |
| 256 // pattern. Parse() uses this to decide whether a pattern contains a valid | 251 // pattern. Parse() uses this to decide whether a pattern contains a valid |
| 257 // scheme. MatchesScheme uses this to decide whether a wildcard scheme_ | 252 // scheme. MatchesScheme uses this to decide whether a wildcard scheme_ |
| 258 // matches a given test scheme. | 253 // matches a given test scheme. |
| 259 int valid_schemes_; | 254 int valid_schemes_; |
| 260 | 255 |
| 261 // True if this is a special-case "<all_urls>" pattern. | 256 // True if this is a special-case "<all_urls>" pattern. |
| 262 bool match_all_urls_; | 257 bool match_all_urls_; |
| 263 | 258 |
| 264 // The scheme for the pattern. | 259 // The scheme for the pattern. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 283 // MatchPattern() function. | 278 // MatchPattern() function. |
| 284 std::string path_escaped_; | 279 std::string path_escaped_; |
| 285 | 280 |
| 286 // A string representing this URLPattern. | 281 // A string representing this URLPattern. |
| 287 mutable std::string spec_; | 282 mutable std::string spec_; |
| 288 }; | 283 }; |
| 289 | 284 |
| 290 typedef std::vector<URLPattern> URLPatternList; | 285 typedef std::vector<URLPattern> URLPatternList; |
| 291 | 286 |
| 292 #endif // CHROME_COMMON_EXTENSIONS_URL_PATTERN_H_ | 287 #endif // CHROME_COMMON_EXTENSIONS_URL_PATTERN_H_ |
| OLD | NEW |