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

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

Issue 12792005: Allow extensions on chrome:// URLs, when flag is set and permission is explicitly requested (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More cleanup Created 7 years, 9 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
« no previous file with comments | « chrome/common/extensions/user_script.cc ('k') | extensions/common/url_pattern.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // Initializes this instance by parsing the provided string. Returns 93 // Initializes this instance by parsing the provided string. Returns
94 // URLPattern::PARSE_SUCCESS on success, or an error code otherwise. On 94 // URLPattern::PARSE_SUCCESS on success, or an error code otherwise. On
95 // failure, this instance will have some intermediate values and is in an 95 // failure, this instance will have some intermediate values and is in an
96 // invalid state. 96 // invalid state.
97 ParseResult Parse(const std::string& pattern_str); 97 ParseResult Parse(const std::string& pattern_str);
98 98
99 // Gets the bitmask of valid schemes. 99 // Gets the bitmask of valid schemes.
100 int valid_schemes() const { return valid_schemes_; } 100 int valid_schemes() const { return valid_schemes_; }
101 void SetValidSchemes(int valid_schemes); 101 void SetValidSchemes(int valid_schemes);
102 102
103 int allowed_schemes() const { return allowed_schemes_; }
104 void SetAllowedSchemes(int allowed_schemes);
105
103 // Gets the host the pattern matches. This can be an empty string if the 106 // Gets the host the pattern matches. This can be an empty string if the
104 // pattern matches all hosts (the input was <scheme>://*/<whatever>). 107 // pattern matches all hosts (the input was <scheme>://*/<whatever>).
105 const std::string& host() const { return host_; } 108 const std::string& host() const { return host_; }
106 void SetHost(const std::string& host); 109 void SetHost(const std::string& host);
107 110
108 // Gets whether to match subdomains of host(). 111 // Gets whether to match subdomains of host().
109 bool match_subdomains() const { return match_subdomains_; } 112 bool match_subdomains() const { return match_subdomains_; }
110 void SetMatchSubdomains(bool val); 113 void SetMatchSubdomains(bool val);
111 114
112 // Gets the path the pattern matches with the leading slash. This can have 115 // Gets the path the pattern matches with the leading slash. This can have
(...skipping 10 matching lines...) Expand all
123 // property). Returns false on failure (if the scheme is not valid). 126 // property). Returns false on failure (if the scheme is not valid).
124 bool SetScheme(const std::string& scheme); 127 bool SetScheme(const std::string& scheme);
125 // Note: You should use MatchesScheme() instead of this getter unless you 128 // Note: You should use MatchesScheme() instead of this getter unless you
126 // absolutely need the exact scheme. This is exposed for testing. 129 // absolutely need the exact scheme. This is exposed for testing.
127 const std::string& scheme() const { return scheme_; } 130 const std::string& scheme() const { return scheme_; }
128 131
129 // Returns true if the specified scheme can be used in this URL pattern, and 132 // Returns true if the specified scheme can be used in this URL pattern, and
130 // false otherwise. Uses valid_schemes_ to determine validity. 133 // false otherwise. Uses valid_schemes_ to determine validity.
131 bool IsValidScheme(const std::string& scheme) const; 134 bool IsValidScheme(const std::string& scheme) const;
132 135
136 // Returns true if the specified scheme is allowed by this URL pattern, and
137 // false otherwise. Uses allowed_schemes_ to determine status.
138 bool IsAllowedScheme(const std::string& scheme) const;
139
133 // Returns true if this instance matches the specified URL. 140 // Returns true if this instance matches the specified URL.
134 bool MatchesURL(const GURL& test) const; 141 bool MatchesURL(const GURL& test) const;
135 142
136 // Returns true if this instance matches the specified security origin. 143 // Returns true if this instance matches the specified security origin.
137 bool MatchesSecurityOrigin(const GURL& test) const; 144 bool MatchesSecurityOrigin(const GURL& test) const;
138 145
139 // Returns true if |test| matches our scheme. 146 // Returns true if |test| matches our scheme.
140 // Note that if test is "filesystem", this may fail whereas MatchesURL 147 // Note that if test is "filesystem", this may fail whereas MatchesURL
141 // may succeed. MatchesURL is smart enough to look at the inner_url instead 148 // may succeed. MatchesURL is smart enough to look at the inner_url instead
142 // of the outer "filesystem:" part. 149 // of the outer "filesystem:" part.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 class EffectiveHostCompareFunctor { 188 class EffectiveHostCompareFunctor {
182 public: 189 public:
183 bool operator()(const URLPattern& a, const URLPattern& b) const { 190 bool operator()(const URLPattern& a, const URLPattern& b) const {
184 return EffectiveHostCompare(a, b); 191 return EffectiveHostCompare(a, b);
185 }; 192 };
186 }; 193 };
187 194
188 // Get an error string for a ParseResult. 195 // Get an error string for a ParseResult.
189 static const char* GetParseResultString(URLPattern::ParseResult parse_result); 196 static const char* GetParseResultString(URLPattern::ParseResult parse_result);
190 197
198 // Checks whether the bit is set for the given scheme in the given scheme mask
199 static bool IsSchemeBitSet(const std::string& scheme, const int mask);
200
191 private: 201 private:
192 // Returns true if any of the |schemes| items matches our scheme. 202 // Returns true if any of the |schemes| items matches our scheme.
193 bool MatchesAnyScheme(const std::vector<std::string>& schemes) const; 203 bool MatchesAnyScheme(const std::vector<std::string>& schemes) const;
194 204
195 // Returns true if all of the |schemes| items matches our scheme. 205 // Returns true if all of the |schemes| items matches our scheme.
196 bool MatchesAllSchemes(const std::vector<std::string>& schemes) const; 206 bool MatchesAllSchemes(const std::vector<std::string>& schemes) const;
197 207
198 bool MatchesSecurityOriginHelper(const GURL& test) const; 208 bool MatchesSecurityOriginHelper(const GURL& test) const;
199 209
200 // Returns true if our port matches the |port| pattern (it may be "*"). 210 // Returns true if our port matches the |port| pattern (it may be "*").
201 bool MatchesPortPattern(const std::string& port) const; 211 bool MatchesPortPattern(const std::string& port) const;
202 212
203 // If the URLPattern contains a wildcard scheme, returns a list of 213 // If the URLPattern contains a wildcard scheme, returns a list of
204 // equivalent literal schemes, otherwise returns the current scheme. 214 // equivalent literal schemes, otherwise returns the current scheme.
205 std::vector<std::string> GetExplicitSchemes() const; 215 std::vector<std::string> GetExplicitSchemes() const;
206 216
207 // A bitmask containing the schemes which are considered valid for this 217 // A bitmask containing the schemes which are considered valid for this
208 // pattern. Parse() uses this to decide whether a pattern contains a valid 218 // pattern. Parse() uses this to decide whether a pattern contains a valid
209 // scheme. MatchesScheme uses this to decide whether a wildcard scheme_ 219 // scheme.
220 int valid_schemes_;
221
222 // A bitmask containing the schemes which return a positive match for this
223 // pattern. MatchesScheme uses this to decide whether a wildcard scheme_
210 // matches a given test scheme. 224 // matches a given test scheme.
211 int valid_schemes_; 225 int allowed_schemes_;
212 226
213 // True if this is a special-case "<all_urls>" pattern. 227 // True if this is a special-case "<all_urls>" pattern.
214 bool match_all_urls_; 228 bool match_all_urls_;
215 229
216 // The scheme for the pattern. 230 // The scheme for the pattern.
217 std::string scheme_; 231 std::string scheme_;
218 232
219 // The host without any leading "*" components. 233 // The host without any leading "*" components.
220 std::string host_; 234 std::string host_;
221 235
(...skipping 12 matching lines...) Expand all
234 // MatchPattern() function. 248 // MatchPattern() function.
235 std::string path_escaped_; 249 std::string path_escaped_;
236 250
237 // A string representing this URLPattern. 251 // A string representing this URLPattern.
238 mutable std::string spec_; 252 mutable std::string spec_;
239 }; 253 };
240 254
241 typedef std::vector<URLPattern> URLPatternList; 255 typedef std::vector<URLPattern> URLPatternList;
242 256
243 #endif // EXTENSIONS_COMMON_URL_PATTERN_H_ 257 #endif // EXTENSIONS_COMMON_URL_PATTERN_H_
OLDNEW
« no previous file with comments | « chrome/common/extensions/user_script.cc ('k') | extensions/common/url_pattern.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698