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

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

Issue 12209094: Support requesting subsets of host permissions using the permissions API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: are you happy yet?!?!? Created 7 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 | Annotate | Revision Log
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 // of the outer "filesystem:" part. 142 // of the outer "filesystem:" part.
143 bool MatchesScheme(const std::string& test) const; 143 bool MatchesScheme(const std::string& test) const;
144 144
145 // Returns true if |test| matches our host. 145 // Returns true if |test| matches our host.
146 bool MatchesHost(const std::string& test) const; 146 bool MatchesHost(const std::string& test) const;
147 bool MatchesHost(const GURL& test) const; 147 bool MatchesHost(const GURL& test) const;
148 148
149 // Returns true if |test| matches our path. 149 // Returns true if |test| matches our path.
150 bool MatchesPath(const std::string& test) const; 150 bool MatchesPath(const std::string& test) const;
151 151
152 // Returns true if |port| matches our port.
153 bool MatchesPort(int port) const;
154
155 // Sets the port. Returns false if the port is invalid. 152 // Sets the port. Returns false if the port is invalid.
156 bool SetPort(const std::string& port); 153 bool SetPort(const std::string& port);
157 const std::string& port() const { return port_; } 154 const std::string& port() const { return port_; }
158 155
159 // Returns a string representing this instance. 156 // Returns a string representing this instance.
160 const std::string& GetAsString() const; 157 const std::string& GetAsString() const;
161 158
162 // Determine whether there is a URL that would match this instance and another 159 // Determines whether there is a URL that would match this instance and
163 // instance. This method is symmetrical: Calling other.OverlapsWith(this) 160 // another instance. This method is symmetrical: Calling
164 // would result in the same answer. 161 // other.OverlapsWith(this) would result in the same answer.
165 bool OverlapsWith(const URLPattern& other) const; 162 bool OverlapsWith(const URLPattern& other) const;
166 163
167 // Convert this URLPattern into an equivalent set of URLPatterns that don't 164 // Returns true if this pattern matches all possible URLs that |other| can
165 // match. For example, http://*.google.com encompasses http://www.google.com.
166 bool Contains(const URLPattern& other) const;
167
168 // Converts this URLPattern into an equivalent set of URLPatterns that don't
168 // use a wildcard in the scheme component. If this URLPattern doesn't use a 169 // use a wildcard in the scheme component. If this URLPattern doesn't use a
169 // wildcard scheme, then the returned set will contain one element that is 170 // wildcard scheme, then the returned set will contain one element that is
170 // equivalent to this instance. 171 // equivalent to this instance.
171 std::vector<URLPattern> ConvertToExplicitSchemes() const; 172 std::vector<URLPattern> ConvertToExplicitSchemes() const;
172 173
173 static bool EffectiveHostCompare(const URLPattern& a, const URLPattern& b) { 174 static bool EffectiveHostCompare(const URLPattern& a, const URLPattern& b) {
174 if (a.match_all_urls_ && b.match_all_urls_) 175 if (a.match_all_urls_ && b.match_all_urls_)
175 return false; 176 return false;
176 return a.host_.compare(b.host_) < 0; 177 return a.host_.compare(b.host_) < 0;
177 }; 178 };
178 179
179 // Used for origin comparisons in a std::set. 180 // Used for origin comparisons in a std::set.
180 class EffectiveHostCompareFunctor { 181 class EffectiveHostCompareFunctor {
181 public: 182 public:
182 bool operator()(const URLPattern& a, const URLPattern& b) const { 183 bool operator()(const URLPattern& a, const URLPattern& b) const {
183 return EffectiveHostCompare(a, b); 184 return EffectiveHostCompare(a, b);
184 }; 185 };
185 }; 186 };
186 187
187 // Get an error string for a ParseResult. 188 // Get an error string for a ParseResult.
188 static const char* GetParseResultString(URLPattern::ParseResult parse_result); 189 static const char* GetParseResultString(URLPattern::ParseResult parse_result);
189 190
190 private: 191 private:
191 // Returns true if any of the |schemes| items matches our scheme. 192 // Returns true if any of the |schemes| items matches our scheme.
192 bool MatchesAnyScheme(const std::vector<std::string>& schemes) const; 193 bool MatchesAnyScheme(const std::vector<std::string>& schemes) const;
193 194
195 // Returns true if all of the |schemes| items matches our scheme.
196 bool MatchesAllSchemes(const std::vector<std::string>& schemes) const;
197
194 bool MatchesSecurityOriginHelper(const GURL& test) const; 198 bool MatchesSecurityOriginHelper(const GURL& test) const;
195 199
200 // Returns true if our port matches the |port| pattern (it may be "*").
201 bool MatchesPortPattern(const std::string& port) const;
202
196 // If the URLPattern contains a wildcard scheme, returns a list of 203 // If the URLPattern contains a wildcard scheme, returns a list of
197 // equivalent literal schemes, otherwise returns the current scheme. 204 // equivalent literal schemes, otherwise returns the current scheme.
198 std::vector<std::string> GetExplicitSchemes() const; 205 std::vector<std::string> GetExplicitSchemes() const;
199 206
200 // A bitmask containing the schemes which are considered valid for this 207 // A bitmask containing the schemes which are considered valid for this
201 // pattern. Parse() uses this to decide whether a pattern contains a valid 208 // pattern. Parse() uses this to decide whether a pattern contains a valid
202 // scheme. MatchesScheme uses this to decide whether a wildcard scheme_ 209 // scheme. MatchesScheme uses this to decide whether a wildcard scheme_
203 // matches a given test scheme. 210 // matches a given test scheme.
204 int valid_schemes_; 211 int valid_schemes_;
205 212
(...skipping 21 matching lines...) Expand all
227 // MatchPattern() function. 234 // MatchPattern() function.
228 std::string path_escaped_; 235 std::string path_escaped_;
229 236
230 // A string representing this URLPattern. 237 // A string representing this URLPattern.
231 mutable std::string spec_; 238 mutable std::string spec_;
232 }; 239 };
233 240
234 typedef std::vector<URLPattern> URLPatternList; 241 typedef std::vector<URLPattern> URLPatternList;
235 242
236 #endif // EXTENSIONS_COMMON_URL_PATTERN_H_ 243 #endif // EXTENSIONS_COMMON_URL_PATTERN_H_
OLDNEW
« no previous file with comments | « chrome/test/data/extensions/api_test/permissions/host_subsets/manifest.json ('k') | extensions/common/url_pattern.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698