Enable gesture editing visibile in options menu.
[chromium-blink-merge.git] / content / common / appcache_interfaces.cc
blob7f3f547139d920cedbc738c1999d764ba5cbe6c6
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/string_util.h"
10 #include "content/public/common/url_constants.h"
11 #include "net/url_request/url_request.h"
12 #include "url/gurl.h"
13 #include "url/url_constants.h"
15 namespace content {
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),
27 group_id(0),
28 status(APPCACHE_STATUS_UNCACHED),
29 size(0),
30 is_complete(false) {
33 AppCacheInfo::~AppCacheInfo() {
36 AppCacheResourceInfo::AppCacheResourceInfo()
37 : url(),
38 size(0),
39 is_master(false),
40 is_manifest(false),
41 is_intercept(false),
42 is_fallback(false),
43 is_foreign(false),
44 is_explicit(false),
45 response_id(kAppCacheNoResponseId) {
48 AppCacheResourceInfo::~AppCacheResourceInfo() {
51 AppCacheErrorDetails::AppCacheErrorDetails()
52 : message(),
53 reason(APPCACHE_UNKNOWN_ERROR),
54 url(),
55 status(0),
56 is_cross_origin(false) {}
58 AppCacheErrorDetails::AppCacheErrorDetails(
59 std::string in_message,
60 AppCacheErrorReason in_reason,
61 GURL in_url,
62 int in_status,
63 bool in_is_cross_origin)
64 : message(in_message),
65 reason(in_reason),
66 url(in_url),
67 status(in_status),
68 is_cross_origin(in_is_cross_origin) {}
70 AppCacheErrorDetails::~AppCacheErrorDetails() {}
72 AppCacheNamespace::AppCacheNamespace()
73 : type(APPCACHE_FALLBACK_NAMESPACE),
74 is_pattern(false),
75 is_executable(false) {
78 AppCacheNamespace::AppCacheNamespace(
79 AppCacheNamespaceType type, const GURL& url, const GURL& target,
80 bool is_pattern)
81 : type(type),
82 namespace_url(url),
83 target_url(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)
91 : type(type),
92 namespace_url(url),
93 target_url(target),
94 is_pattern(is_pattern),
95 is_executable(is_executable) {
98 AppCacheNamespace::~AppCacheNamespace() {
101 bool AppCacheNamespace::IsMatch(const GURL& url) const {
102 if (is_pattern) {
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);
118 #ifndef NDEBUG
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();
126 #endif
127 return supported;
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