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 "content/public/common/url_constants.h"
11 #include "net/url_request/url_request.h"
13 #include "url/url_constants.h"
17 const char kHttpGETMethod
[] = "GET";
18 const char kHttpHEADMethod
[] = "HEAD";
20 const char kEnableExecutableHandlers
[] = "enable-appcache-executable-handlers";
22 const base::FilePath::CharType kAppCacheDatabaseName
[] =
23 FILE_PATH_LITERAL("Index");
25 AppCacheInfo::AppCacheInfo()
26 : cache_id(kAppCacheNoCacheId
),
28 status(APPCACHE_STATUS_UNCACHED
),
33 AppCacheInfo::~AppCacheInfo() {
36 AppCacheResourceInfo::AppCacheResourceInfo()
45 response_id(kAppCacheNoResponseId
) {
48 AppCacheResourceInfo::~AppCacheResourceInfo() {
51 AppCacheErrorDetails::AppCacheErrorDetails()
53 reason(APPCACHE_UNKNOWN_ERROR
),
56 is_cross_origin(false) {}
58 AppCacheErrorDetails::AppCacheErrorDetails(
59 std::string in_message
,
60 AppCacheErrorReason in_reason
,
63 bool in_is_cross_origin
)
64 : message(in_message
),
68 is_cross_origin(in_is_cross_origin
) {}
70 AppCacheErrorDetails::~AppCacheErrorDetails() {}
72 AppCacheNamespace::AppCacheNamespace()
73 : type(APPCACHE_FALLBACK_NAMESPACE
),
75 is_executable(false) {
78 AppCacheNamespace::AppCacheNamespace(
79 AppCacheNamespaceType type
, const GURL
& url
, const GURL
& target
,
84 is_pattern(is_pattern
),
85 is_executable(false) {
88 AppCacheNamespace::AppCacheNamespace(
89 AppCacheNamespaceType 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 AppCacheNamespace::~AppCacheNamespace() {
101 bool AppCacheNamespace::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 IsSchemeSupportedForAppCache(const GURL
& url
) {
114 bool supported
= url
.SchemeIs(url::kHttpScheme
) ||
115 url
.SchemeIs(url::kHttpsScheme
) ||
116 url
.SchemeIs(kChromeDevToolsScheme
);
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