| 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 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> |
| 8 | 9 |
| 9 #include "googleurl/src/gurl.h" | 10 #include "googleurl/src/gurl.h" |
| 10 | 11 |
| 11 // A pattern that can be used to match URLs. A URLPattern is a very restricted | 12 // A pattern that can be used to match URLs. A URLPattern is a very restricted |
| 12 // subset of URL syntax: | 13 // subset of URL syntax: |
| 13 // | 14 // |
| 14 // <url-pattern> := <scheme>://<host><path> | '<all_urls>' | 15 // <url-pattern> := <scheme>://<host><path> | '<all_urls>' |
| 15 // <scheme> := '*' | 'http' | 'https' | 'file' | 'ftp' | 'chrome' | 16 // <scheme> := '*' | 'http' | 'https' | 'file' | 'ftp' | 'chrome' |
| 16 // <host> := '*' | '*.' <anychar except '/' and '*'>+ | 17 // <host> := '*' | '*.' <anychar except '/' and '*'>+ |
| 17 // <path> := '/' <any chars> | 18 // <path> := '/' <any chars> |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 void set_match_subdomains(bool val) { match_subdomains_ = val; } | 112 void set_match_subdomains(bool val) { match_subdomains_ = val; } |
| 112 | 113 |
| 113 // Gets the path the pattern matches with the leading slash. This can have | 114 // Gets the path the pattern matches with the leading slash. This can have |
| 114 // embedded asterisks which are interpreted using glob rules. | 115 // embedded asterisks which are interpreted using glob rules. |
| 115 const std::string& path() const { return path_; } | 116 const std::string& path() const { return path_; } |
| 116 void set_path(const std::string& path) { | 117 void set_path(const std::string& path) { |
| 117 path_ = path; | 118 path_ = path; |
| 118 path_escaped_ = ""; | 119 path_escaped_ = ""; |
| 119 } | 120 } |
| 120 | 121 |
| 122 // Returns true if this pattern matches all urls. |
| 123 bool match_all_urls() const { return match_all_urls_; } |
| 124 void set_match_all_urls(bool val) { match_all_urls_ = val; } |
| 125 |
| 121 // Initializes this instance by parsing the provided string. On failure, the | 126 // Initializes this instance by parsing the provided string. On failure, the |
| 122 // instance will have some intermediate values and is in an invalid state. | 127 // instance will have some intermediate values and is in an invalid state. |
| 123 bool Parse(const std::string& pattern_str); | 128 bool Parse(const std::string& pattern_str); |
| 124 | 129 |
| 125 // Sets the scheme for pattern matches. This can be a single '*' if the | 130 // Sets the scheme for pattern matches. This can be a single '*' if the |
| 126 // pattern matches all valid schemes (as defined by the valid_schemes_ | 131 // pattern matches all valid schemes (as defined by the valid_schemes_ |
| 127 // property). Returns false on failure (if the scheme is not valid). | 132 // property). Returns false on failure (if the scheme is not valid). |
| 128 bool SetScheme(const std::string& scheme); | 133 bool SetScheme(const std::string& scheme); |
| 129 // Note: You should use MatchesScheme() instead of this getter unless you | 134 // Note: You should use MatchesScheme() instead of this getter unless you |
| 130 // absolutely need the exact scheme. This is exposed for testing. | 135 // absolutely need the exact scheme. This is exposed for testing. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 148 bool MatchesPath(const std::string& test) const; | 153 bool MatchesPath(const std::string& test) const; |
| 149 | 154 |
| 150 // Returns a string representing this instance. | 155 // Returns a string representing this instance. |
| 151 std::string GetAsString() const; | 156 std::string GetAsString() const; |
| 152 | 157 |
| 153 // Determine whether there is a URL that would match this instance and another | 158 // Determine whether there is a URL that would match this instance and another |
| 154 // instance. This method is symmetrical: Calling other.OverlapsWith(this) | 159 // instance. This method is symmetrical: Calling other.OverlapsWith(this) |
| 155 // would result in the same answer. | 160 // would result in the same answer. |
| 156 bool OverlapsWith(const URLPattern& other) const; | 161 bool OverlapsWith(const URLPattern& other) const; |
| 157 | 162 |
| 163 // Conver this URLPattern into an equivalent set of URLPatterns that don't use |
| 164 // a wildcard in the scheme component. If this URLPattern doesn't use a |
| 165 // wildcard scheme, then the returned set will contain one element that is |
| 166 // equivalent to this instance. |
| 167 std::vector<URLPattern> ConvertToExplicitSchemes() const; |
| 168 |
| 158 private: | 169 private: |
| 159 // A bitmask containing the schemes which are considered valid for this | 170 // A bitmask containing the schemes which are considered valid for this |
| 160 // pattern. Parse() uses this to decide whether a pattern contains a valid | 171 // pattern. Parse() uses this to decide whether a pattern contains a valid |
| 161 // scheme. MatchesScheme uses this to decide whether a wildcard scheme_ | 172 // scheme. MatchesScheme uses this to decide whether a wildcard scheme_ |
| 162 // matches a given test scheme. | 173 // matches a given test scheme. |
| 163 int valid_schemes_; | 174 int valid_schemes_; |
| 164 | 175 |
| 165 // True if this is a special-case "<all_urls>" pattern. | 176 // True if this is a special-case "<all_urls>" pattern. |
| 166 bool match_all_urls_; | 177 bool match_all_urls_; |
| 167 | 178 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 179 // everything after the scheme in the case of file:// URLs. | 190 // everything after the scheme in the case of file:// URLs. |
| 180 std::string path_; | 191 std::string path_; |
| 181 | 192 |
| 182 // The path with "?" and "\" characters escaped for use with the | 193 // The path with "?" and "\" characters escaped for use with the |
| 183 // MatchPatternASCII() function. This is populated lazily, the first time it | 194 // MatchPatternASCII() function. This is populated lazily, the first time it |
| 184 // is needed. | 195 // is needed. |
| 185 mutable std::string path_escaped_; | 196 mutable std::string path_escaped_; |
| 186 }; | 197 }; |
| 187 | 198 |
| 188 #endif // CHROME_COMMON_EXTENSIONS_URL_PATTERN_H_ | 199 #endif // CHROME_COMMON_EXTENSIONS_URL_PATTERN_H_ |
| OLD | NEW |