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> |
| 11 | 11 |
| 12 class GURL; | 12 class GURL; |
| 13 | 13 |
| 14 // 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 |
| 15 // subset of URL syntax: | 15 // subset of URL syntax: |
| 16 // | 16 // |
| 17 // <url-pattern> := <scheme>://<host><port><path> | '<all_urls>' | 17 // <url-pattern> := <scheme>://<host><port><path> | '<all_urls>' |
| 18 // <scheme> := '*' | 'http' | 'https' | 'file' | 'ftp' | 'chrome' | 18 // <scheme> := '*' | 'http' | 'https' | 'file' | 'ftp' | 'chrome' | |
| 19 // 'chrome-extension' | 'filesystem' | |
| 19 // <host> := '*' | '*.' <anychar except '/' and '*'>+ | 20 // <host> := '*' | '*.' <anychar except '/' and '*'>+ |
| 20 // <port> := [':' ('*' | <port number between 0 and 65535>)] | 21 // <port> := [':' ('*' | <port number between 0 and 65535>)] |
| 21 // <path> := '/' <any chars> | 22 // <path> := '/' <any chars> |
| 22 // | 23 // |
| 23 // * Host is not used when the scheme is 'file'. | 24 // * Host is not used when the scheme is 'file'. |
| 24 // * The port is only used if the pattern is parsed with the USE_PORTS option. | 25 // * The port is only used if the pattern is parsed with the USE_PORTS option. |
| 25 // If the patterns is parsed with the ERROR_ON_PORTS option, the port is not | 26 // If the patterns is parsed with the ERROR_ON_PORTS option, the port is not |
| 26 // allowed, and the resulting pattern matches any port. If it is parsed with | 27 // allowed, and the resulting pattern matches any port. If it is parsed with |
| 27 // the IGNORE_PORTS option, the port (including colon) is kept as part of the | 28 // the IGNORE_PORTS option, the port (including colon) is kept as part of the |
| 28 // host to maintain backwards compatibility with previous versions, which | 29 // host to maintain backwards compatibility with previous versions, which |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 class URLPattern { | 84 class URLPattern { |
| 84 public: | 85 public: |
| 85 // A collection of scheme bitmasks for use with valid_schemes. | 86 // A collection of scheme bitmasks for use with valid_schemes. |
| 86 enum SchemeMasks { | 87 enum SchemeMasks { |
| 87 SCHEME_NONE = 0, | 88 SCHEME_NONE = 0, |
| 88 SCHEME_HTTP = 1 << 0, | 89 SCHEME_HTTP = 1 << 0, |
| 89 SCHEME_HTTPS = 1 << 1, | 90 SCHEME_HTTPS = 1 << 1, |
| 90 SCHEME_FILE = 1 << 2, | 91 SCHEME_FILE = 1 << 2, |
| 91 SCHEME_FTP = 1 << 3, | 92 SCHEME_FTP = 1 << 3, |
| 92 SCHEME_CHROMEUI = 1 << 4, | 93 SCHEME_CHROMEUI = 1 << 4, |
| 93 SCHEME_FILESYSTEM = 1 << 5, | 94 SCHEME_EXTENSION = 1 << 5, |
| 95 SCHEME_FILESYSTEM = 1 << 6, | |
| 94 // SCHEME_ALL will match every scheme, including chrome://, chrome- | 96 // SCHEME_ALL will match every scheme, including chrome://, chrome- |
| 95 // extension://, about:, etc. Because this has lots of security | 97 // extension://, about:, etc. Because this has lots of security |
| 96 // implications, third-party extensions should never be able to get access | 98 // implications, third-party extensions should usually not be able to get |
| 97 // to URL patterns initialized this way. It should only be used for internal | 99 // access to URL patterns initialized this way. If there is a reason |
| 98 // Chrome code. | 100 // for violating this general rule, document why this it safe. |
| 101 | |
| 102 // !!! SCHEME_ALL SHOULD ONLY BE USED FOR INTERNAL CHROME CODE !!! | |
|
Aaron Boodman
2011/12/09 16:28:25
This last sentence seems to conflict with the abov
battre
2011/12/09 17:07:51
Done.
| |
| 99 SCHEME_ALL = -1, | 103 SCHEME_ALL = -1, |
| 100 }; | 104 }; |
| 101 | 105 |
| 102 // Options for URLPattern::Parse(). | 106 // Options for URLPattern::Parse(). |
| 103 enum ParseOption { | 107 enum ParseOption { |
| 104 ERROR_ON_PORTS, | 108 ERROR_ON_PORTS, |
| 105 IGNORE_PORTS, | 109 IGNORE_PORTS, |
| 106 USE_PORTS, | 110 USE_PORTS, |
| 107 }; | 111 }; |
| 108 | 112 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 // MatchPattern() function. | 287 // MatchPattern() function. |
| 284 std::string path_escaped_; | 288 std::string path_escaped_; |
| 285 | 289 |
| 286 // A string representing this URLPattern. | 290 // A string representing this URLPattern. |
| 287 mutable std::string spec_; | 291 mutable std::string spec_; |
| 288 }; | 292 }; |
| 289 | 293 |
| 290 typedef std::vector<URLPattern> URLPatternList; | 294 typedef std::vector<URLPattern> URLPatternList; |
| 291 | 295 |
| 292 #endif // CHROME_COMMON_EXTENSIONS_URL_PATTERN_H_ | 296 #endif // CHROME_COMMON_EXTENSIONS_URL_PATTERN_H_ |
| OLD | NEW |