Index: chrome/common/extensions/url_pattern.h |
diff --git a/chrome/common/extensions/url_pattern.h b/chrome/common/extensions/url_pattern.h |
index 6a83c017ce7c3b5a3dd2cd0348a16fd009352b14..210e33b1262e96ff86ec11b33294f03d2951210c 100644 |
--- a/chrome/common/extensions/url_pattern.h |
+++ b/chrome/common/extensions/url_pattern.h |
@@ -1,4 +1,4 @@ |
-// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
#ifndef CHROME_COMMON_EXTENSIONS_URL_PATTERN_H_ |
@@ -14,12 +14,14 @@ class GURL; |
// A pattern that can be used to match URLs. A URLPattern is a very restricted |
// subset of URL syntax: |
// |
-// <url-pattern> := <scheme>://<host><port><path> | '<all_urls>' |
+// <url-pattern> := [filesystem:]<scheme>://<host><port><path> | '<all_urls>' | |
+// <nonstandard-scheme>:<any chars> |
// <scheme> := '*' | 'http' | 'https' | 'file' | 'ftp' | 'chrome' | |
-// 'chrome-extension' | 'filesystem' |
+// 'chrome-extension' |
// <host> := '*' | '*.' <anychar except '/' and '*'>+ |
// <port> := [':' ('*' | <port number between 0 and 65535>)] |
// <path> := '/' <any chars> |
+// <nonstandard-scheme> := <any string except for "//" or those in scheme> |
// |
// * Host is not used when the scheme is 'file'. |
// * The path can have embedded '*' characters which act as glob wildcards. |
@@ -33,6 +35,7 @@ class GURL; |
// - https://*.google.com/foo*bar |
// - file://monkey* |
// - http://127.0.0.1/* |
+// - filesystem:*://*/* |
// |
// Examples of invalid patterns: |
// - http://* -- path not specified |
@@ -99,8 +102,16 @@ class URLPattern { |
// Gets the bitmask of valid schemes. |
int valid_schemes() const { return valid_schemes_; } |
+ |
+ // Sets the bitmask of valid schemes and inner_schemes. |
void SetValidSchemes(int valid_schemes); |
Aaron Boodman
2012/03/12 23:17:13
It's surprising that this would also set the inner
ericu
2012/03/13 21:58:47
Generally if you want to match http://google.com,
|
+ // Gets the bitmask of valid inner schemes. |
+ int valid_inner_schemes() const { return valid_inner_schemes_; } |
+ |
+ // Sets the bitmask of valid inner_schemes. |
+ void SetValidInnerSchemes(int valid_schemes); |
+ |
// Gets the host the pattern matches. This can be an empty string if the |
// pattern matches all hosts (the input was <scheme>://*/<whatever>). |
const std::string& host() const { return host_; } |
@@ -123,14 +134,31 @@ class URLPattern { |
// pattern matches all valid schemes (as defined by the valid_schemes_ |
// property). Returns false on failure (if the scheme is not valid). |
bool SetScheme(const std::string& scheme); |
- // Note: You should use MatchesScheme() instead of this getter unless you |
- // absolutely need the exact scheme. This is exposed for testing. |
+ // Sets the inner scheme for pattern matches; this can only be used for |
Aaron Boodman
2012/03/12 23:17:13
Add blank line before this comment block.
ericu
2012/03/13 21:58:47
Done.
|
+ // patterns whose scheme has already been set to "filesystem". This can be a |
Aaron Boodman
2012/03/12 23:17:13
"with a scheme that supports inner schemes."
ericu
2012/03/13 21:58:47
Done.
|
+ // single '*' if the pattern matches all valid schemes (as defined by the |
+ // valid_inner_schemes_ property). Returns false on failure (if the scheme is |
+ // not valid). |
+ bool SetInnerScheme(const std::string& scheme); |
+ |
+ // Returns the scheme component of the pattern. Note that it is usually |
+ // better to call MatchesScheme(), since that will also handle the case where |
+ // the scheme is a wildcard. |
const std::string& scheme() const { return scheme_; } |
+ // Returns the inner scheme component of the pattern. Note that it is usually |
+ // better to call MatchesInnerScheme(), since that will also handle the case |
+ // where the inner scheme is a wildcard. |
+ const std::string& inner_scheme() const { return inner_scheme_; } |
+ |
// Returns true if the specified scheme can be used in this URL pattern, and |
// false otherwise. Uses valid_schemes_ to determine validity. |
bool IsValidScheme(const std::string& scheme) const; |
+ // Returns true if the specified inner scheme can be used in this URL pattern, |
+ // and false otherwise. Uses valid_inner_schemes_ to determine validity. |
+ bool IsValidInnerScheme(const std::string& inner_scheme) const; |
+ |
// Returns true if this instance matches the specified URL. |
bool MatchesURL(const GURL& test) const; |
@@ -140,6 +168,10 @@ class URLPattern { |
// Returns true if |test| matches our scheme. |
bool MatchesScheme(const std::string& test) const; |
+ // Returns true if |test| matches our inner scheme. |
+ // Only use this if scheme is "filesystem". |
+ bool MatchesInnerScheme(const std::string& test) const; |
+ |
// Returns true if |test| matches our host. |
bool MatchesHost(const std::string& test) const; |
bool MatchesHost(const GURL& test) const; |
@@ -201,12 +233,21 @@ class URLPattern { |
// matches a given test scheme. |
int valid_schemes_; |
+ // A bitmask containing the inner schemes which are considered valid for this |
+ // pattern. Parse() uses this to decide whether a pattern contains a valid |
+ // scheme. MatchesInnerScheme uses this to decide whether a wildcard |
+ // inner_scheme_ matches a given test scheme. |
+ int valid_inner_schemes_; |
+ |
// True if this is a special-case "<all_urls>" pattern. |
bool match_all_urls_; |
// The scheme for the pattern. |
std::string scheme_; |
+ // The inner scheme for the pattern, used only when scheme_ is "filesystem". |
Aaron Boodman
2012/03/12 23:17:13
It would be better to create an array of schemes t
ericu
2012/03/13 21:58:47
I made a trivial inline function instead of an arr
|
+ std::string inner_scheme_; |
+ |
// The host without any leading "*" components. |
std::string host_; |