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 "content/common/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(kAppCacheNoCacheId
),
29 status(APPCACHE_STATUS_UNCACHED
),
34 AppCacheInfo::~AppCacheInfo() {
37 AppCacheResourceInfo::AppCacheResourceInfo()
46 response_id(kAppCacheNoResponseId
) {
49 AppCacheResourceInfo::~AppCacheResourceInfo() {
52 AppCacheErrorDetails::AppCacheErrorDetails()
54 reason(APPCACHE_UNKNOWN_ERROR
),
57 is_cross_origin(false) {}
59 AppCacheErrorDetails::AppCacheErrorDetails(
60 std::string in_message
,
61 AppCacheErrorReason in_reason
,
64 bool in_is_cross_origin
)
65 : message(in_message
),
69 is_cross_origin(in_is_cross_origin
) {}
71 AppCacheErrorDetails::~AppCacheErrorDetails() {}
73 AppCacheNamespace::AppCacheNamespace()
74 : type(APPCACHE_FALLBACK_NAMESPACE
),
76 is_executable(false) {
79 AppCacheNamespace::AppCacheNamespace(
80 AppCacheNamespaceType type
, const GURL
& url
, const GURL
& target
,
85 is_pattern(is_pattern
),
86 is_executable(false) {
89 AppCacheNamespace::AppCacheNamespace(
90 AppCacheNamespaceType type
, const GURL
& url
, const GURL
& target
,
91 bool is_pattern
, bool is_executable
)
95 is_pattern(is_pattern
),
96 is_executable(is_executable
) {
99 AppCacheNamespace::~AppCacheNamespace() {
102 bool AppCacheNamespace::IsMatch(const GURL
& url
) const {
104 // We have to escape '?' characters since MatchPattern also treats those
105 // as wildcards which we don't want here, we only do '*'s.
106 std::string pattern
= namespace_url
.spec();
107 if (namespace_url
.has_query())
108 ReplaceSubstringsAfterOffset(&pattern
, 0, "?", "\\?");
109 return MatchPattern(url
.spec(), pattern
);
111 return StartsWithASCII(url
.spec(), namespace_url
.spec(), true);
114 bool IsSchemeSupportedForAppCache(const GURL
& url
) {
115 bool supported
= url
.SchemeIs(kHttpScheme
) || url
.SchemeIs(kHttpsScheme
) ||
116 url
.SchemeIs(kDevToolsScheme
);
119 // TODO(michaeln): It would be really nice if this could optionally work for
120 // file and filesystem urls too to help web developers experiment and test
121 // their apps, perhaps enabled via a cmd line flag or some other developer
122 // tool setting. Unfortunately file scheme net::URLRequests don't produce the
123 // same signalling (200 response codes, headers) as http URLRequests, so this
124 // doesn't work just yet.
125 // supported |= url.SchemeIsFile();
130 bool IsMethodSupportedForAppCache(const std::string
& method
) {
131 return (method
== kHttpGETMethod
) || (method
== kHttpHEADMethod
);
134 bool IsSchemeAndMethodSupportedForAppCache(const net::URLRequest
* request
) {
135 return IsSchemeSupportedForAppCache(request
->url()) &&
136 IsMethodSupportedForAppCache(request
->method());
139 } // namespace content