Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(543)

Side by Side Diff: chrome/common/extensions/url_pattern.h

Issue 7229012: Use extension match pattern syntax in content settings extension API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: unit test Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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><path> | '<all_urls>' 17 // <url-pattern> := <scheme>://<host><path> | '<all_urls>'
18 // <scheme> := '*' | 'http' | 'https' | 'file' | 'ftp' | 'chrome' 18 // <scheme> := '*' | 'http' | 'https' | 'file' | 'ftp' | 'chrome'
19 // <host> := '*' | '*.' <anychar except '/' and '*'>+ 19 // <host> := '*' | '*.' <anychar except '/' and '*'>+
Matt Perry 2011/06/24 18:53:58 add a mention of the <port> here, that explains wh
Bernhard Bauer 2011/06/28 16:46:31 Done.
20 // <path> := '/' <any chars> 20 // <path> := '/' <any chars>
21 // 21 //
22 // * Host is not used when the scheme is 'file'. 22 // * Host is not used when the scheme is 'file'.
23 // * The path can have embedded '*' characters which act as glob wildcards. 23 // * The path can have embedded '*' characters which act as glob wildcards.
24 // * '<all_urls>' is a special pattern that matches any URL that contains a 24 // * '<all_urls>' is a special pattern that matches any URL that contains a
25 // valid scheme (as specified by valid_schemes_). 25 // valid scheme (as specified by valid_schemes_).
26 // * The '*' scheme pattern excludes file URLs. 26 // * The '*' scheme pattern excludes file URLs.
27 // 27 //
28 // Examples of valid patterns: 28 // Examples of valid patterns:
29 // - http://*/* 29 // - http://*/*
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // Error codes returned from Parse(). 101 // Error codes returned from Parse().
102 enum ParseResult { 102 enum ParseResult {
103 PARSE_SUCCESS = 0, 103 PARSE_SUCCESS = 0,
104 PARSE_ERROR_MISSING_SCHEME_SEPARATOR, 104 PARSE_ERROR_MISSING_SCHEME_SEPARATOR,
105 PARSE_ERROR_INVALID_SCHEME, 105 PARSE_ERROR_INVALID_SCHEME,
106 PARSE_ERROR_WRONG_SCHEME_SEPARATOR, 106 PARSE_ERROR_WRONG_SCHEME_SEPARATOR,
107 PARSE_ERROR_EMPTY_HOST, 107 PARSE_ERROR_EMPTY_HOST,
108 PARSE_ERROR_INVALID_HOST_WILDCARD, 108 PARSE_ERROR_INVALID_HOST_WILDCARD,
109 PARSE_ERROR_EMPTY_PATH, 109 PARSE_ERROR_EMPTY_PATH,
110 PARSE_ERROR_HAS_COLON, // Only checked when strict checks are enabled. 110 PARSE_ERROR_HAS_COLON, // Only checked when strict checks are enabled.
111 PARSE_ERROR_INVALID_PORT,
111 NUM_PARSE_RESULTS 112 NUM_PARSE_RESULTS
112 }; 113 };
113 114
114 // The <all_urls> string pattern. 115 // The <all_urls> string pattern.
115 static const char kAllUrlsPattern[]; 116 static const char kAllUrlsPattern[];
116 117
117 // Construct an URLPattern with the given set of allowable schemes. See 118 // Construct an URLPattern with the given set of allowable schemes. See
118 // valid_schemes_ for more info. 119 // valid_schemes_ for more info.
119 explicit URLPattern(int valid_schemes); 120 explicit URLPattern(int valid_schemes);
120 121
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 // Returns true if |test| matches our scheme. 188 // Returns true if |test| matches our scheme.
188 bool MatchesScheme(const std::string& test) const; 189 bool MatchesScheme(const std::string& test) const;
189 190
190 // Returns true if |test| matches our host. 191 // Returns true if |test| matches our host.
191 bool MatchesHost(const std::string& test) const; 192 bool MatchesHost(const std::string& test) const;
192 bool MatchesHost(const GURL& test) const; 193 bool MatchesHost(const GURL& test) const;
193 194
194 // Returns true if |test| matches our path. 195 // Returns true if |test| matches our path.
195 bool MatchesPath(const std::string& test) const; 196 bool MatchesPath(const std::string& test) const;
196 197
198 // Sets the port. Returns false if the port is invalid.
199 bool SetPort(const std::string& port);
200 const std::string& port() const { return port_; }
201
197 // Returns a string representing this instance. 202 // Returns a string representing this instance.
198 std::string GetAsString() const; 203 std::string GetAsString() const;
199 204
200 // Determine whether there is a URL that would match this instance and another 205 // Determine whether there is a URL that would match this instance and another
201 // instance. This method is symmetrical: Calling other.OverlapsWith(this) 206 // instance. This method is symmetrical: Calling other.OverlapsWith(this)
202 // would result in the same answer. 207 // would result in the same answer.
203 bool OverlapsWith(const URLPattern& other) const; 208 bool OverlapsWith(const URLPattern& other) const;
204 209
205 // Convert this URLPattern into an equivalent set of URLPatterns that don't 210 // Convert this URLPattern into an equivalent set of URLPatterns that don't
206 // use a wildcard in the scheme component. If this URLPattern doesn't use a 211 // use a wildcard in the scheme component. If this URLPattern doesn't use a
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 // The scheme for the pattern. 258 // The scheme for the pattern.
254 std::string scheme_; 259 std::string scheme_;
255 260
256 // The host without any leading "*" components. 261 // The host without any leading "*" components.
257 std::string host_; 262 std::string host_;
258 263
259 // Whether we should match subdomains of the host. This is true if the first 264 // Whether we should match subdomains of the host. This is true if the first
260 // component of the pattern's host was "*". 265 // component of the pattern's host was "*".
261 bool match_subdomains_; 266 bool match_subdomains_;
262 267
268 // The port. URL patterns only support ports if they are parsed with the
269 // |PARSE_LENIENT| option.
270 std::string port_;
271
263 // The path to match. This is everything after the host of the URL, or 272 // The path to match. This is everything after the host of the URL, or
264 // everything after the scheme in the case of file:// URLs. 273 // everything after the scheme in the case of file:// URLs.
265 std::string path_; 274 std::string path_;
266 275
267 // The path with "?" and "\" characters escaped for use with the 276 // The path with "?" and "\" characters escaped for use with the
268 // MatchPattern() function. 277 // MatchPattern() function.
269 std::string path_escaped_; 278 std::string path_escaped_;
270 }; 279 };
271 280
272 typedef std::vector<URLPattern> URLPatternList; 281 typedef std::vector<URLPattern> URLPatternList;
273 282
274 #endif // CHROME_COMMON_EXTENSIONS_URL_PATTERN_H_ 283 #endif // CHROME_COMMON_EXTENSIONS_URL_PATTERN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698