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
3 // found in the LICENSE file.
5 #include "webkit/common/appcache/appcache_interfaces.h"
9 #include "base/strings/string_util.h"
10 #include "net/url_request/url_request.h"
15 const char kHttpScheme[] = "http";
16 const char kHttpsScheme[] = "https";
17 const char kDevToolsScheme[] = "chrome-devtools";
18 const char kHttpGETMethod[] = "GET";
19 const char kHttpHEADMethod[] = "HEAD";
21 const char kEnableExecutableHandlers[] = "enable-appcache-executable-handlers";
23 const base::FilePath::CharType kAppCacheDatabaseName[] =
24 FILE_PATH_LITERAL("Index");
26 AppCacheInfo::AppCacheInfo()
27 : cache_id(kNoCacheId),
34 AppCacheInfo::~AppCacheInfo() {
37 AppCacheResourceInfo::AppCacheResourceInfo()
46 response_id(kNoResponseId) {
49 AppCacheResourceInfo::~AppCacheResourceInfo() {
52 Namespace::Namespace()
53 : type(FALLBACK_NAMESPACE),
55 is_executable(false) {
59 NamespaceType type, const GURL& url, const GURL& target, bool is_pattern)
63 is_pattern(is_pattern),
64 is_executable(false) {
68 NamespaceType type, const GURL& url, const GURL& target,
69 bool is_pattern, bool is_executable)
73 is_pattern(is_pattern),
74 is_executable(is_executable) {
77 Namespace::~Namespace() {
80 bool Namespace::IsMatch(const GURL& url) const {
82 // We have to escape '?' characters since MatchPattern also treats those
83 // as wildcards which we don't want here, we only do '*'s.
84 std::string pattern = namespace_url.spec();
85 if (namespace_url.has_query())
86 ReplaceSubstringsAfterOffset(&pattern, 0, "?", "\\?");
87 return MatchPattern(url.spec(), pattern);
89 return StartsWithASCII(url.spec(), namespace_url.spec(), true);
92 bool IsSchemeSupported(const GURL& url) {
93 bool supported = url.SchemeIs(kHttpScheme) || url.SchemeIs(kHttpsScheme) ||
94 url.SchemeIs(kDevToolsScheme);
97 // TODO(michaeln): It would be really nice if this could optionally work for
98 // file and filesystem urls too to help web developers experiment and test
99 // their apps, perhaps enabled via a cmd line flag or some other developer
100 // tool setting. Unfortunately file scheme net::URLRequests don't produce the
101 // same signalling (200 response codes, headers) as http URLRequests, so this
102 // doesn't work just yet.
103 // supported |= url.SchemeIsFile();
108 bool IsMethodSupported(const std::string& method) {
109 return (method == kHttpGETMethod) || (method == kHttpHEADMethod);
112 bool IsSchemeAndMethodSupported(const net::URLRequest* request) {
113 return IsSchemeSupported(request->url()) &&
114 IsMethodSupported(request->method());
117 } // namespace appcache