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 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 112 |
113 // Gets the path the pattern matches with the leading slash. This can have | 113 // Gets the path the pattern matches with the leading slash. This can have |
114 // embedded asterisks which are interpreted using glob rules. | 114 // embedded asterisks which are interpreted using glob rules. |
115 const std::string& path() const { return path_; } | 115 const std::string& path() const { return path_; } |
116 void SetPath(const std::string& path); | 116 void SetPath(const std::string& path); |
117 | 117 |
118 // Returns true if this pattern matches all urls. | 118 // Returns true if this pattern matches all urls. |
119 bool match_all_urls() const { return match_all_urls_; } | 119 bool match_all_urls() const { return match_all_urls_; } |
120 void SetMatchAllURLs(bool val); | 120 void SetMatchAllURLs(bool val); |
121 | 121 |
122 // Returns true if this pattern matches inner URLs of filesystem: URLs only. | |
123 // Returns false if this pattern matches only non-filesystem URLs. | |
124 bool partial_filesystem_support_hack() const { | |
125 return partial_filesystem_support_hack_; | |
126 } | |
127 void set_partial_filesystem_support_hack(bool val) { | |
128 partial_filesystem_support_hack_ = val; | |
129 } | |
130 | |
131 // Sets the scheme for pattern matches. This can be a single '*' if the | 122 // Sets the scheme for pattern matches. This can be a single '*' if the |
132 // pattern matches all valid schemes (as defined by the valid_schemes_ | 123 // pattern matches all valid schemes (as defined by the valid_schemes_ |
133 // property). Returns false on failure (if the scheme is not valid). | 124 // property). Returns false on failure (if the scheme is not valid). |
134 bool SetScheme(const std::string& scheme); | 125 bool SetScheme(const std::string& scheme); |
135 // Note: You should use MatchesScheme() instead of this getter unless you | 126 // Note: You should use MatchesScheme() instead of this getter unless you |
136 // absolutely need the exact scheme. This is exposed for testing. | 127 // absolutely need the exact scheme. This is exposed for testing. |
137 const std::string& scheme() const { return scheme_; } | 128 const std::string& scheme() const { return scheme_; } |
138 | 129 |
139 // Returns true if the specified scheme can be used in this URL pattern, and | 130 // Returns true if the specified scheme can be used in this URL pattern, and |
140 // false otherwise. Uses valid_schemes_ to determine validity. | 131 // false otherwise. Uses valid_schemes_ to determine validity. |
141 bool IsValidScheme(const std::string& scheme) const; | 132 bool IsValidScheme(const std::string& scheme) const; |
142 | 133 |
143 // Returns true if this instance matches the specified URL. | 134 // Returns true if this instance matches the specified URL. |
144 bool MatchesURL(const GURL& test) const; | 135 bool MatchesURL(const GURL& test) const; |
145 | 136 |
146 // Returns true if this instance matches the specified security origin. | 137 // Returns true if this instance matches the specified security origin. |
147 bool MatchesSecurityOrigin(const GURL& test) const; | 138 bool MatchesSecurityOrigin(const GURL& test) const; |
148 | 139 |
149 // Returns true if |test| matches our scheme. | 140 // Returns true if |test| matches our scheme. |
| 141 // Note that if test is "filesystem", this may fail whereas MatchesURL |
| 142 // may succeed. MatchesURL is smart enough to look at the inner_url instead |
| 143 // of the outer "filesystem:" part. |
150 bool MatchesScheme(const std::string& test) const; | 144 bool MatchesScheme(const std::string& test) const; |
151 | 145 |
152 // Returns true if |test| matches our host. | 146 // Returns true if |test| matches our host. |
153 bool MatchesHost(const std::string& test) const; | 147 bool MatchesHost(const std::string& test) const; |
154 bool MatchesHost(const GURL& test) const; | 148 bool MatchesHost(const GURL& test) const; |
155 | 149 |
156 // Returns true if |test| matches our path. | 150 // Returns true if |test| matches our path. |
157 bool MatchesPath(const std::string& test) const; | 151 bool MatchesPath(const std::string& test) const; |
158 | 152 |
159 // Returns true if |port| matches our port. | 153 // Returns true if |port| matches our port. |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 | 200 |
207 // A bitmask containing the schemes which are considered valid for this | 201 // A bitmask containing the schemes which are considered valid for this |
208 // pattern. Parse() uses this to decide whether a pattern contains a valid | 202 // pattern. Parse() uses this to decide whether a pattern contains a valid |
209 // scheme. MatchesScheme uses this to decide whether a wildcard scheme_ | 203 // scheme. MatchesScheme uses this to decide whether a wildcard scheme_ |
210 // matches a given test scheme. | 204 // matches a given test scheme. |
211 int valid_schemes_; | 205 int valid_schemes_; |
212 | 206 |
213 // True if this is a special-case "<all_urls>" pattern. | 207 // True if this is a special-case "<all_urls>" pattern. |
214 bool match_all_urls_; | 208 bool match_all_urls_; |
215 | 209 |
216 // True if we're trying to match against the inner URL of a filesystem URL; | |
217 // this is a temporary hack so as not to break ChromeOS as we work on full | |
218 // support. | |
219 bool partial_filesystem_support_hack_; | |
220 | |
221 // The scheme for the pattern. | 210 // The scheme for the pattern. |
222 std::string scheme_; | 211 std::string scheme_; |
223 | 212 |
224 // The host without any leading "*" components. | 213 // The host without any leading "*" components. |
225 std::string host_; | 214 std::string host_; |
226 | 215 |
227 // Whether we should match subdomains of the host. This is true if the first | 216 // Whether we should match subdomains of the host. This is true if the first |
228 // component of the pattern's host was "*". | 217 // component of the pattern's host was "*". |
229 bool match_subdomains_; | 218 bool match_subdomains_; |
230 | 219 |
231 // The port. | 220 // The port. |
232 std::string port_; | 221 std::string port_; |
233 | 222 |
234 // The path to match. This is everything after the host of the URL, or | 223 // The path to match. This is everything after the host of the URL, or |
235 // everything after the scheme in the case of file:// URLs. | 224 // everything after the scheme in the case of file:// URLs. |
236 std::string path_; | 225 std::string path_; |
237 | 226 |
238 // The path with "?" and "\" characters escaped for use with the | 227 // The path with "?" and "\" characters escaped for use with the |
239 // MatchPattern() function. | 228 // MatchPattern() function. |
240 std::string path_escaped_; | 229 std::string path_escaped_; |
241 | 230 |
242 // A string representing this URLPattern. | 231 // A string representing this URLPattern. |
243 mutable std::string spec_; | 232 mutable std::string spec_; |
244 }; | 233 }; |
245 | 234 |
246 typedef std::vector<URLPattern> URLPatternList; | 235 typedef std::vector<URLPattern> URLPatternList; |
247 | 236 |
248 #endif // CHROME_COMMON_EXTENSIONS_URL_PATTERN_H_ | 237 #endif // CHROME_COMMON_EXTENSIONS_URL_PATTERN_H_ |
OLD | NEW |