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

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

Issue 2499493004: Communicate ExtensionSettings policy to renderers (Closed)
Patch Set: -Added unit tests for PermissionsUpdater and PermissionsData, Removed unnecessary lock assertion, p… Created 3 years, 8 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, specify in |parse_options|.
107 ParseResult Parse(const std::string& pattern_str); 114 ParseResult Parse(const std::string& pattern_str);
115 ParseResult Parse(const std::string& pattern_str, ParseOptions parse_options);
108 116
109 // Gets the bitmask of valid schemes. 117 // Gets the bitmask of valid schemes.
110 int valid_schemes() const { return valid_schemes_; } 118 int valid_schemes() const { return valid_schemes_; }
111 void SetValidSchemes(int valid_schemes); 119 void SetValidSchemes(int valid_schemes);
112 120
113 // Gets the host the pattern matches. This can be an empty string if the 121 // Gets the host the pattern matches. This can be an empty string if the
114 // pattern matches all hosts (the input was <scheme>://*/<whatever>). 122 // pattern matches all hosts (the input was <scheme>://*/<whatever>).
115 const std::string& host() const { return host_; } 123 const std::string& host() const { return host_; }
116 void SetHost(const std::string& host); 124 void SetHost(const std::string& host);
117 125
118 // Gets whether to match subdomains of host(). 126 // Gets whether to match subdomains of host().
119 bool match_subdomains() const { return match_subdomains_; } 127 bool match_subdomains() const { return match_subdomains_; }
120 void SetMatchSubdomains(bool val); 128 void SetMatchSubdomains(bool val);
121 129
130 // Gets whether host() contains an effective TLD. If false, during
131 // a match, the URL you're comparing must have its TLD removed
132 // prior to comparison.
133 // e.g. For the match pattern https://google.com/*
134 // If this is true: host() would be google.com
135 // If this is false host() would be google
Devlin 2017/04/07 00:40:27 nitty nit: my orderly persona requires a ':' after
nrpeter 2017/04/12 23:35:45 Done.
136 bool match_effective_tld() const { return match_effective_tld_; }
137 void SetMatchEffectiveTld(bool val);
138
122 // Gets the path the pattern matches with the leading slash. This can have 139 // Gets the path the pattern matches with the leading slash. This can have
123 // embedded asterisks which are interpreted using glob rules. 140 // embedded asterisks which are interpreted using glob rules.
124 const std::string& path() const { return path_; } 141 const std::string& path() const { return path_; }
125 void SetPath(const std::string& path); 142 void SetPath(const std::string& path);
126 143
127 // Returns true if this pattern matches all urls. 144 // Returns true if this pattern matches all urls.
128 bool match_all_urls() const { return match_all_urls_; } 145 bool match_all_urls() const { return match_all_urls_; }
129 void SetMatchAllURLs(bool val); 146 void SetMatchAllURLs(bool val);
130 147
131 // Sets the scheme for pattern matches. This can be a single '*' if the 148 // 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. 253 // The scheme for the pattern.
237 std::string scheme_; 254 std::string scheme_;
238 255
239 // The host without any leading "*" components. 256 // The host without any leading "*" components.
240 std::string host_; 257 std::string host_;
241 258
242 // Whether we should match subdomains of the host. This is true if the first 259 // Whether we should match subdomains of the host. This is true if the first
243 // component of the pattern's host was "*". 260 // component of the pattern's host was "*".
244 bool match_subdomains_; 261 bool match_subdomains_;
245 262
263 // Whether we should match the effective TLD of the host. This is true by
264 // default and only false if the the pattern's host ends with ".*"
Devlin 2017/04/07 00:40:27 nit: This isn't false if the patterns host ends wi
nrpeter 2017/04/12 23:35:45 Done.
265 // (e.g. https://example.*/*).
266 bool match_effective_tld_;
267
246 // The port. 268 // The port.
247 std::string port_; 269 std::string port_;
248 270
249 // The path to match. This is everything after the host of the URL, or 271 // 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. 272 // everything after the scheme in the case of file:// URLs.
251 std::string path_; 273 std::string path_;
252 274
253 // The path with "?" and "\" characters escaped for use with the 275 // The path with "?" and "\" characters escaped for use with the
254 // MatchPattern() function. 276 // MatchPattern() function.
255 std::string path_escaped_; 277 std::string path_escaped_;
256 278
257 // A string representing this URLPattern. 279 // A string representing this URLPattern.
258 mutable std::string spec_; 280 mutable std::string spec_;
259 }; 281 };
260 282
261 std::ostream& operator<<(std::ostream& out, const URLPattern& url_pattern); 283 std::ostream& operator<<(std::ostream& out, const URLPattern& url_pattern);
262 284
263 typedef std::vector<URLPattern> URLPatternList; 285 typedef std::vector<URLPattern> URLPatternList;
264 286
265 #endif // EXTENSIONS_COMMON_URL_PATTERN_H_ 287 #endif // EXTENSIONS_COMMON_URL_PATTERN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698