Update V8 to version 4.6.72.
[chromium-blink-merge.git] / content / common / appcache_interfaces.cc
blobaf0d8c1688336dc07344dd4c7dffb2053435622b
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"
7 #include <set>
9 #include "base/strings/pattern.h"
10 #include "base/strings/string_util.h"
11 #include "content/public/common/url_constants.h"
12 #include "net/url_request/url_request.h"
13 #include "url/gurl.h"
14 #include "url/url_constants.h"
16 namespace content {
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),
28 group_id(0),
29 status(APPCACHE_STATUS_UNCACHED),
30 size(0),
31 is_complete(false) {
34 AppCacheInfo::~AppCacheInfo() {
37 AppCacheResourceInfo::AppCacheResourceInfo()
38 : url(),
39 size(0),
40 is_master(false),
41 is_manifest(false),
42 is_intercept(false),
43 is_fallback(false),
44 is_foreign(false),
45 is_explicit(false),
46 response_id(kAppCacheNoResponseId) {
49 AppCacheResourceInfo::~AppCacheResourceInfo() {
52 AppCacheErrorDetails::AppCacheErrorDetails()
53 : message(),
54 reason(APPCACHE_UNKNOWN_ERROR),
55 url(),
56 status(0),
57 is_cross_origin(false) {}
59 AppCacheErrorDetails::AppCacheErrorDetails(
60 std::string in_message,
61 AppCacheErrorReason in_reason,
62 GURL in_url,
63 int in_status,
64 bool in_is_cross_origin)
65 : message(in_message),
66 reason(in_reason),
67 url(in_url),
68 status(in_status),
69 is_cross_origin(in_is_cross_origin) {}
71 AppCacheErrorDetails::~AppCacheErrorDetails() {}
73 AppCacheNamespace::AppCacheNamespace()
74 : type(APPCACHE_FALLBACK_NAMESPACE),
75 is_pattern(false),
76 is_executable(false) {
79 AppCacheNamespace::AppCacheNamespace(
80 AppCacheNamespaceType type, const GURL& url, const GURL& target,
81 bool is_pattern)
82 : type(type),
83 namespace_url(url),
84 target_url(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)
92 : type(type),
93 namespace_url(url),
94 target_url(target),
95 is_pattern(is_pattern),
96 is_executable(is_executable) {
99 AppCacheNamespace::~AppCacheNamespace() {
102 bool AppCacheNamespace::IsMatch(const GURL& url) const {
103 if (is_pattern) {
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 base::ReplaceSubstringsAfterOffset(&pattern, 0, "?", "\\?");
109 return base::MatchPattern(url.spec(), pattern);
111 return base::StartsWith(url.spec(), namespace_url.spec(),
112 base::CompareCase::SENSITIVE);
115 bool IsSchemeSupportedForAppCache(const GURL& url) {
116 bool supported = url.SchemeIs(url::kHttpScheme) ||
117 url.SchemeIs(url::kHttpsScheme) ||
118 url.SchemeIs(kChromeDevToolsScheme);
120 #ifndef NDEBUG
121 // TODO(michaeln): It would be really nice if this could optionally work for
122 // file and filesystem urls too to help web developers experiment and test
123 // their apps, perhaps enabled via a cmd line flag or some other developer
124 // tool setting. Unfortunately file scheme net::URLRequests don't produce the
125 // same signalling (200 response codes, headers) as http URLRequests, so this
126 // doesn't work just yet.
127 // supported |= url.SchemeIsFile();
128 #endif
129 return supported;
132 bool IsMethodSupportedForAppCache(const std::string& method) {
133 return (method == kHttpGETMethod) || (method == kHttpHEADMethod);
136 bool IsSchemeAndMethodSupportedForAppCache(const net::URLRequest* request) {
137 return IsSchemeSupportedForAppCache(request->url()) &&
138 IsMethodSupportedForAppCache(request->method());
141 } // namespace content