| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/common/appcache/appcache_interfaces.h" | 5 #include "content/common/appcache_interfaces.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "net/url_request/url_request.h" | 10 #include "net/url_request/url_request.h" |
| 11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
| 12 | 12 |
| 13 namespace appcache { | 13 namespace content { |
| 14 | 14 |
| 15 const char kHttpScheme[] = "http"; | 15 const char kHttpScheme[] = "http"; |
| 16 const char kHttpsScheme[] = "https"; | 16 const char kHttpsScheme[] = "https"; |
| 17 const char kDevToolsScheme[] = "chrome-devtools"; | 17 const char kDevToolsScheme[] = "chrome-devtools"; |
| 18 const char kHttpGETMethod[] = "GET"; | 18 const char kHttpGETMethod[] = "GET"; |
| 19 const char kHttpHEADMethod[] = "HEAD"; | 19 const char kHttpHEADMethod[] = "HEAD"; |
| 20 | 20 |
| 21 const char kEnableExecutableHandlers[] = "enable-appcache-executable-handlers"; | 21 const char kEnableExecutableHandlers[] = "enable-appcache-executable-handlers"; |
| 22 | 22 |
| 23 const base::FilePath::CharType kAppCacheDatabaseName[] = | 23 const base::FilePath::CharType kAppCacheDatabaseName[] = |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 int in_status, | 63 int in_status, |
| 64 bool in_is_cross_origin) | 64 bool in_is_cross_origin) |
| 65 : message(in_message), | 65 : message(in_message), |
| 66 reason(in_reason), | 66 reason(in_reason), |
| 67 url(in_url), | 67 url(in_url), |
| 68 status(in_status), | 68 status(in_status), |
| 69 is_cross_origin(in_is_cross_origin) {} | 69 is_cross_origin(in_is_cross_origin) {} |
| 70 | 70 |
| 71 AppCacheErrorDetails::~AppCacheErrorDetails() {} | 71 AppCacheErrorDetails::~AppCacheErrorDetails() {} |
| 72 | 72 |
| 73 Namespace::Namespace() | 73 AppCacheNamespace::AppCacheNamespace() |
| 74 : type(APPCACHE_FALLBACK_NAMESPACE), | 74 : type(APPCACHE_FALLBACK_NAMESPACE), |
| 75 is_pattern(false), | 75 is_pattern(false), |
| 76 is_executable(false) { | 76 is_executable(false) { |
| 77 } | 77 } |
| 78 | 78 |
| 79 Namespace::Namespace( | 79 AppCacheNamespace::AppCacheNamespace( |
| 80 AppCacheNamespaceType type, const GURL& url, const GURL& target, | 80 AppCacheNamespaceType type, const GURL& url, const GURL& target, |
| 81 bool is_pattern) | 81 bool is_pattern) |
| 82 : type(type), | 82 : type(type), |
| 83 namespace_url(url), | 83 namespace_url(url), |
| 84 target_url(target), | 84 target_url(target), |
| 85 is_pattern(is_pattern), | 85 is_pattern(is_pattern), |
| 86 is_executable(false) { | 86 is_executable(false) { |
| 87 } | 87 } |
| 88 | 88 |
| 89 Namespace::Namespace( | 89 AppCacheNamespace::AppCacheNamespace( |
| 90 AppCacheNamespaceType type, const GURL& url, const GURL& target, | 90 AppCacheNamespaceType type, const GURL& url, const GURL& target, |
| 91 bool is_pattern, bool is_executable) | 91 bool is_pattern, bool is_executable) |
| 92 : type(type), | 92 : type(type), |
| 93 namespace_url(url), | 93 namespace_url(url), |
| 94 target_url(target), | 94 target_url(target), |
| 95 is_pattern(is_pattern), | 95 is_pattern(is_pattern), |
| 96 is_executable(is_executable) { | 96 is_executable(is_executable) { |
| 97 } | 97 } |
| 98 | 98 |
| 99 Namespace::~Namespace() { | 99 AppCacheNamespace::~AppCacheNamespace() { |
| 100 } | 100 } |
| 101 | 101 |
| 102 bool Namespace::IsMatch(const GURL& url) const { | 102 bool AppCacheNamespace::IsMatch(const GURL& url) const { |
| 103 if (is_pattern) { | 103 if (is_pattern) { |
| 104 // We have to escape '?' characters since MatchPattern also treats those | 104 // We have to escape '?' characters since MatchPattern also treats those |
| 105 // as wildcards which we don't want here, we only do '*'s. | 105 // as wildcards which we don't want here, we only do '*'s. |
| 106 std::string pattern = namespace_url.spec(); | 106 std::string pattern = namespace_url.spec(); |
| 107 if (namespace_url.has_query()) | 107 if (namespace_url.has_query()) |
| 108 ReplaceSubstringsAfterOffset(&pattern, 0, "?", "\\?"); | 108 ReplaceSubstringsAfterOffset(&pattern, 0, "?", "\\?"); |
| 109 return MatchPattern(url.spec(), pattern); | 109 return MatchPattern(url.spec(), pattern); |
| 110 } | 110 } |
| 111 return StartsWithASCII(url.spec(), namespace_url.spec(), true); | 111 return StartsWithASCII(url.spec(), namespace_url.spec(), true); |
| 112 } | 112 } |
| 113 | 113 |
| 114 bool IsSchemeSupported(const GURL& url) { | 114 bool IsSchemeSupportedForAppCache(const GURL& url) { |
| 115 bool supported = url.SchemeIs(kHttpScheme) || url.SchemeIs(kHttpsScheme) || | 115 bool supported = url.SchemeIs(kHttpScheme) || url.SchemeIs(kHttpsScheme) || |
| 116 url.SchemeIs(kDevToolsScheme); | 116 url.SchemeIs(kDevToolsScheme); |
| 117 | 117 |
| 118 #ifndef NDEBUG | 118 #ifndef NDEBUG |
| 119 // TODO(michaeln): It would be really nice if this could optionally work for | 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 | 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 | 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 | 122 // tool setting. Unfortunately file scheme net::URLRequests don't produce the |
| 123 // same signalling (200 response codes, headers) as http URLRequests, so this | 123 // same signalling (200 response codes, headers) as http URLRequests, so this |
| 124 // doesn't work just yet. | 124 // doesn't work just yet. |
| 125 // supported |= url.SchemeIsFile(); | 125 // supported |= url.SchemeIsFile(); |
| 126 #endif | 126 #endif |
| 127 return supported; | 127 return supported; |
| 128 } | 128 } |
| 129 | 129 |
| 130 bool IsMethodSupported(const std::string& method) { | 130 bool IsMethodSupportedForAppCache(const std::string& method) { |
| 131 return (method == kHttpGETMethod) || (method == kHttpHEADMethod); | 131 return (method == kHttpGETMethod) || (method == kHttpHEADMethod); |
| 132 } | 132 } |
| 133 | 133 |
| 134 bool IsSchemeAndMethodSupported(const net::URLRequest* request) { | 134 bool IsSchemeAndMethodSupportedForAppCache(const net::URLRequest* request) { |
| 135 return IsSchemeSupported(request->url()) && | 135 return IsSchemeSupportedForAppCache(request->url()) && |
| 136 IsMethodSupported(request->method()); | 136 IsMethodSupportedForAppCache(request->method()); |
| 137 } | 137 } |
| 138 | 138 |
| 139 } // namespace appcache | 139 } // namespace content |
| OLD | NEW |