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

Unified Diff: chrome/common/extensions/url_pattern.h

Issue 7811006: Add full support for filesystem URLs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed code review feedback. Created 8 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 side-by-side diff with in-line comments
Download patch
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..77ab3814501e17894ecabe276108c44decaadacf 100644
--- a/chrome/common/extensions/url_pattern.h
+++ b/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,7 +102,12 @@ 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);
+ // 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>).
@@ -123,14 +131,27 @@ 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);
+ // Sets the inner scheme for pattern matches; this can only be used for
+ // patterns whose scheme has already been set to "filesystem". This can be a
+ // 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);
// Note: You should use MatchesScheme() instead of this getter unless you
// absolutely need the exact scheme. This is exposed for testing.
const std::string& scheme() const { return scheme_; }
+ // Note: You should use MatchesInnerScheme() instead of this getter unless you
+ // absolutely need the exact scheme. This is exposed for testing.
+ 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 scheme can be used in this URL pattern, and
+ // false otherwise. Uses valid_inner_schemes_ to determine validity.
+ bool IsValidInnerScheme(const std::string& scheme) const;
+
// Returns true if this instance matches the specified URL.
bool MatchesURL(const GURL& test) const;
@@ -140,6 +161,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;
@@ -200,6 +225,11 @@ class URLPattern {
// scheme. MatchesScheme uses this to decide whether a wildcard scheme_
// 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_;
@@ -207,6 +237,9 @@ class URLPattern {
// The scheme for the pattern.
std::string scheme_;
+ // The inner scheme for the pattern, used only when scheme_ is "filesystem".
+ std::string inner_scheme_;
+
// The host without any leading "*" components.
std::string host_;

Powered by Google App Engine
This is Rietveld 408576698