diff options
author | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-30 00:32:42 +0000 |
---|---|---|
committer | michaeln@google.com <michaeln@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-30 00:32:42 +0000 |
commit | 34e7dc62ff6abe114ec521cf735c2c7592cb16e5 (patch) | |
tree | c47066e8b9d47ac496afcfd8641159d5ffc35801 /webkit/appcache/appcache_interfaces.cc | |
parent | 13ac535324e020859ea18654a2b9f614fdcd20dc (diff) | |
download | chromium_src-34e7dc62ff6abe114ec521cf735c2c7592cb16e5.zip chromium_src-34e7dc62ff6abe114ec521cf735c2c7592cb16e5.tar.gz chromium_src-34e7dc62ff6abe114ec521cf735c2c7592cb16e5.tar.bz2 |
Chromium appcache pattern matching. Allow the INTERCEPT, FALLBACK, and NETWORK namespaces
to optionally be defined with glob matching semantics. To enable the new feature, entries
in those sections must be annotated with a trailing 'isPattern'. Up to 16 * characters in
the path or query parts of the <patternurl> will match zero or more characters of
requested urls. Without the 'isPattern' annotation, entries in those sections are
interpreted as prefixes (as usual).
FALLBACK:
<patternurl> <targeturl> isPattern
CHROMIUM-INTERCEPT:
<patternurl> return <targeturl> isPattern
NETWORK:
<patternurl> isPattern
# examples
FALLBACK:
/userpics/*.jpg /userpics/unavailablepic.jpg isPattern
/userpics?userid=*&size=120x120 /userpics_static/unavailablepic120x120.jpg isPattern
BUG=224426
Review URL: https://codereview.chromium.org/12628006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191480 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/appcache/appcache_interfaces.cc')
-rw-r--r-- | webkit/appcache/appcache_interfaces.cc | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/webkit/appcache/appcache_interfaces.cc b/webkit/appcache/appcache_interfaces.cc index bbc222c..a3b6f31 100644 --- a/webkit/appcache/appcache_interfaces.cc +++ b/webkit/appcache/appcache_interfaces.cc @@ -4,6 +4,7 @@ #include "webkit/appcache/appcache_interfaces.h" +#include "base/string_util.h" #include "googleurl/src/gurl.h" #include "net/url_request/url_request.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebApplicationCacheHost.h" @@ -49,16 +50,32 @@ AppCacheResourceInfo::~AppCacheResourceInfo() { } Namespace::Namespace() - : type(FALLBACK_NAMESPACE) { + : type(FALLBACK_NAMESPACE), + is_pattern(false) { } -Namespace::Namespace(NamespaceType type, const GURL& url, const GURL& target) - : type(type), namespace_url(url), target_url(target) { +Namespace::Namespace( + NamespaceType type, const GURL& url, const GURL& target, bool is_pattern) + : type(type), + namespace_url(url), + target_url(target), + is_pattern(is_pattern) { } Namespace::~Namespace() { } +bool Namespace::IsMatch(const GURL& url) const { + if (is_pattern) { + // We have to escape '?' characters since MatchPattern also treats those + // as wildcards which we don't want here, we only do '*'s. + std::string pattern = namespace_url.spec(); + if (namespace_url.has_query()) + ReplaceSubstringsAfterOffset(&pattern, 0, "?", "\\?"); + return MatchPattern(url.spec(), pattern); + } + return StartsWithASCII(url.spec(), namespace_url.spec(), true); +} bool IsSchemeSupported(const GURL& url) { bool supported = url.SchemeIs(kHttpScheme) || url.SchemeIs(kHttpsScheme); |