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

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

Issue 2499493004: Communicate ExtensionSettings policy to renderers (Closed)
Patch Set: Style fixes, prevent heap leak. Created 3 years, 10 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
OLDNEW
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 EXTENSIONS_COMMON_URL_PATTERN_H_ 4 #ifndef EXTENSIONS_COMMON_URL_PATTERN_H_
5 #define EXTENSIONS_COMMON_URL_PATTERN_H_ 5 #define EXTENSIONS_COMMON_URL_PATTERN_H_
6 6
7 #include <functional> 7 #include <functional>
8 #include <iosfwd> 8 #include <iosfwd>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 PARSE_ERROR_INVALID_SCHEME, 70 PARSE_ERROR_INVALID_SCHEME,
71 PARSE_ERROR_WRONG_SCHEME_SEPARATOR, 71 PARSE_ERROR_WRONG_SCHEME_SEPARATOR,
72 PARSE_ERROR_EMPTY_HOST, 72 PARSE_ERROR_EMPTY_HOST,
73 PARSE_ERROR_INVALID_HOST_WILDCARD, 73 PARSE_ERROR_INVALID_HOST_WILDCARD,
74 PARSE_ERROR_EMPTY_PATH, 74 PARSE_ERROR_EMPTY_PATH,
75 PARSE_ERROR_INVALID_PORT, 75 PARSE_ERROR_INVALID_PORT,
76 PARSE_ERROR_INVALID_HOST, 76 PARSE_ERROR_INVALID_HOST,
77 NUM_PARSE_RESULTS 77 NUM_PARSE_RESULTS
78 }; 78 };
79 79
80 // Types of URLPattern that Parse() considers valid.
81 enum ParseOptions {
82 DENY_WILDCARD_FOR_EFFECTIVE_TLD,
83 ALLOW_WILDCARD_FOR_EFFECTIVE_TLD,
84 };
85
80 // The <all_urls> string pattern. 86 // The <all_urls> string pattern.
81 static const char kAllUrlsPattern[]; 87 static const char kAllUrlsPattern[];
82 88
83 // Returns true if the given |scheme| is considered valid for extensions. 89 // Returns true if the given |scheme| is considered valid for extensions.
84 static bool IsValidSchemeForExtensions(const std::string& scheme); 90 static bool IsValidSchemeForExtensions(const std::string& scheme);
85 91
86 // Returns the mask for all schemes considered valid for extensions. 92 // Returns the mask for all schemes considered valid for extensions.
87 static int GetValidSchemeMaskForExtensions(); 93 static int GetValidSchemeMaskForExtensions();
88 94
89 explicit URLPattern(int valid_schemes); 95 explicit URLPattern(int valid_schemes);
90 96
91 // Convenience to construct a URLPattern from a string. If the string is not 97 // Convenience to construct a URLPattern from a string. If the string is not
92 // known ahead of time, use Parse() instead, which returns success or failure. 98 // known ahead of time, use Parse() instead, which returns success or failure.
93 URLPattern(int valid_schemes, const std::string& pattern); 99 URLPattern(int valid_schemes, const std::string& pattern);
94 100
95 URLPattern(); 101 URLPattern();
96 URLPattern(const URLPattern& other); 102 URLPattern(const URLPattern& other);
97 ~URLPattern(); 103 ~URLPattern();
98 104
99 bool operator<(const URLPattern& other) const; 105 bool operator<(const URLPattern& other) const;
100 bool operator>(const URLPattern& other) const; 106 bool operator>(const URLPattern& other) const;
101 bool operator==(const URLPattern& other) const; 107 bool operator==(const URLPattern& other) const;
102 108
103 // Initializes this instance by parsing the provided string. Returns 109 // Initializes this instance by parsing the provided string. Returns
104 // URLPattern::PARSE_SUCCESS on success, or an error code otherwise. On 110 // URLPattern::PARSE_SUCCESS on success, or an error code otherwise. On
105 // failure, this instance will have some intermediate values and is in an 111 // failure, this instance will have some intermediate values and is in an
106 // invalid state. 112 // invalid state. If you want to allow the match pattern to specify a wildcard
113 // for the effective TLD, make |allow_wildcard_effective_tld| true.
Devlin 2017/02/14 23:17:10 allow_wildcard_effective_tld doesn't exist. :)
nrpeter 2017/03/22 23:47:39 Done.
107 ParseResult Parse(const std::string& pattern_str); 114 ParseResult Parse(const std::string& pattern_str);
115 ParseResult Parse(const std::string& pattern_str,
116 const ParseOptions parse_options);
Devlin 2017/02/14 23:17:10 no need to pass an enum as const
nrpeter 2017/03/22 23:47:39 Done.
108 117
109 // Gets the bitmask of valid schemes. 118 // Gets the bitmask of valid schemes.
110 int valid_schemes() const { return valid_schemes_; } 119 int valid_schemes() const { return valid_schemes_; }
111 void SetValidSchemes(int valid_schemes); 120 void SetValidSchemes(int valid_schemes);
112 121
113 // Gets the host the pattern matches. This can be an empty string if the 122 // Gets the host the pattern matches. This can be an empty string if the
114 // pattern matches all hosts (the input was <scheme>://*/<whatever>). 123 // pattern matches all hosts (the input was <scheme>://*/<whatever>).
115 const std::string& host() const { return host_; } 124 const std::string& host() const { return host_; }
116 void SetHost(const std::string& host); 125 void SetHost(const std::string& host);
117 126
118 // Gets whether to match subdomains of host(). 127 // Gets whether to match subdomains of host().
119 bool match_subdomains() const { return match_subdomains_; } 128 bool match_subdomains() const { return match_subdomains_; }
120 void SetMatchSubdomains(bool val); 129 void SetMatchSubdomains(bool val);
121 130
131 // Gets whether host() contains an effective TLD. If false, durring
Devlin 2017/02/14 23:17:10 s/durring/during
nrpeter 2017/03/22 23:47:39 Done.
132 // a match, the URL you're comparing must have its TLD removed
133 // prior to comparison.
134 // e.g. For the match pattern https://google.com/*
135 // If this is true: host() would be google.com
136 // If this is false host() would be google
137 bool match_effective_tld() const { return match_effective_tld_; }
138 void SetMatchEffectiveTld(bool val);
139
122 // Gets the path the pattern matches with the leading slash. This can have 140 // Gets the path the pattern matches with the leading slash. This can have
123 // embedded asterisks which are interpreted using glob rules. 141 // embedded asterisks which are interpreted using glob rules.
124 const std::string& path() const { return path_; } 142 const std::string& path() const { return path_; }
125 void SetPath(const std::string& path); 143 void SetPath(const std::string& path);
126 144
127 // Returns true if this pattern matches all urls. 145 // Returns true if this pattern matches all urls.
128 bool match_all_urls() const { return match_all_urls_; } 146 bool match_all_urls() const { return match_all_urls_; }
129 void SetMatchAllURLs(bool val); 147 void SetMatchAllURLs(bool val);
130 148
131 // Sets the scheme for pattern matches. This can be a single '*' if the 149 // Sets the scheme for pattern matches. This can be a single '*' if the
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // The scheme for the pattern. 254 // The scheme for the pattern.
237 std::string scheme_; 255 std::string scheme_;
238 256
239 // The host without any leading "*" components. 257 // The host without any leading "*" components.
240 std::string host_; 258 std::string host_;
241 259
242 // Whether we should match subdomains of the host. This is true if the first 260 // Whether we should match subdomains of the host. This is true if the first
243 // component of the pattern's host was "*". 261 // component of the pattern's host was "*".
244 bool match_subdomains_; 262 bool match_subdomains_;
245 263
264 // Whether we should match the effective TLD of the host. This is true by
265 // default and only false if the the pattern's host ends with ".*"
266 // (e.g. https://example.*/*).
267 bool match_effective_tld_;
268
246 // The port. 269 // The port.
247 std::string port_; 270 std::string port_;
248 271
249 // 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
250 // everything after the scheme in the case of file:// URLs. 273 // everything after the scheme in the case of file:// URLs.
251 std::string path_; 274 std::string path_;
252 275
253 // The path with "?" and "\" characters escaped for use with the 276 // The path with "?" and "\" characters escaped for use with the
254 // MatchPattern() function. 277 // MatchPattern() function.
255 std::string path_escaped_; 278 std::string path_escaped_;
256 279
257 // A string representing this URLPattern. 280 // A string representing this URLPattern.
258 mutable std::string spec_; 281 mutable std::string spec_;
259 }; 282 };
260 283
261 std::ostream& operator<<(std::ostream& out, const URLPattern& url_pattern); 284 std::ostream& operator<<(std::ostream& out, const URLPattern& url_pattern);
262 285
263 typedef std::vector<URLPattern> URLPatternList; 286 typedef std::vector<URLPattern> URLPatternList;
264 287
265 #endif // EXTENSIONS_COMMON_URL_PATTERN_H_ 288 #endif // EXTENSIONS_COMMON_URL_PATTERN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698