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 ErrorDetails::ErrorDetails()
54 reason(UNKNOWN_ERROR
),
57 is_cross_origin(false) {}
59 ErrorDetails::ErrorDetails(
60 std::string in_message
,
61 ErrorReason in_reason
,
64 bool in_is_cross_origin
)
65 : message(in_message
),
69 is_cross_origin(in_is_cross_origin
) {}
71 ErrorDetails::~ErrorDetails() {}
73 Namespace::Namespace()
74 : type(FALLBACK_NAMESPACE
),
76 is_executable(false) {
80 NamespaceType type
, const GURL
& url
, const GURL
& target
, bool is_pattern
)
84 is_pattern(is_pattern
),
85 is_executable(false) {
89 NamespaceType type
, const GURL
& url
, const GURL
& target
,
90 bool is_pattern
, bool is_executable
)
94 is_pattern(is_pattern
),
95 is_executable(is_executable
) {
98 Namespace::~Namespace() {
101 bool Namespace::IsMatch(const GURL
& url
) const {
103 // We have to escape '?' characters since MatchPattern also treats those
104 // as wildcards which we don't want here, we only do '*'s.
105 std::string pattern
= namespace_url
.spec();
106 if (namespace_url
.has_query())
107 ReplaceSubstringsAfterOffset(&pattern
, 0, "?", "\\?");
108 return MatchPattern(url
.spec(), pattern
);
110 return StartsWithASCII(url
.spec(), namespace_url
.spec(), true);
113 bool IsSchemeSupported(const GURL
& url
) {
114 bool supported
= url
.SchemeIs(kHttpScheme
) || url
.SchemeIs(kHttpsScheme
) ||
115 url
.SchemeIs(kDevToolsScheme
);
118 // TODO(michaeln): It would be really nice if this could optionally work for
119 // file and filesystem urls too to help web developers experiment and test
120 // their apps, perhaps enabled via a cmd line flag or some other developer
121 // tool setting. Unfortunately file scheme net::URLRequests don't produce the
122 // same signalling (200 response codes, headers) as http URLRequests, so this
123 // doesn't work just yet.
124 // supported |= url.SchemeIsFile();
129 bool IsMethodSupported(const std::string
& method
) {
130 return (method
== kHttpGETMethod
) || (method
== kHttpHEADMethod
);
133 bool IsSchemeAndMethodSupported(const net::URLRequest
* request
) {
134 return IsSchemeSupported(request
->url()) &&
135 IsMethodSupported(request
->method());
138 } // namespace appcache