[email protected] | 7ee2e88 | 2012-06-04 08:54:10 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | d5b2fdf | 2013-06-05 09:36:55 | [diff] [blame] | 5 | #ifndef WEBKIT_COMMON_APPCACHE_APPCACHE_INTERFACES_H_ |
| 6 | #define WEBKIT_COMMON_APPCACHE_APPCACHE_INTERFACES_H_ |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 7 | |
[email protected] | 7e8e3dd | 2009-09-18 01:05:09 | [diff] [blame] | 8 | #include <string> |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 9 | #include <vector> |
[email protected] | ad67777 | 2013-06-29 14:18:38 | [diff] [blame] | 10 | |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 11 | #include "base/basictypes.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 12 | #include "base/files/file_path.h" |
[email protected] | 0a8ebe1 | 2013-06-28 15:23:23 | [diff] [blame] | 13 | #include "base/time/time.h" |
[email protected] | ad67777 | 2013-06-29 14:18:38 | [diff] [blame] | 14 | #include "url/gurl.h" |
[email protected] | e5bf2fd | 2013-06-13 02:59:18 | [diff] [blame] | 15 | #include "webkit/common/webkit_storage_common_export.h" |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 16 | |
[email protected] | edfe7fab | 2010-11-28 13:11:52 | [diff] [blame] | 17 | namespace net { |
[email protected] | 7e8e3dd | 2009-09-18 01:05:09 | [diff] [blame] | 18 | class URLRequest; |
[email protected] | ad67777 | 2013-06-29 14:18:38 | [diff] [blame] | 19 | } |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 20 | |
| 21 | namespace appcache { |
| 22 | |
| 23 | // Defines constants, types, and abstract classes used in the main |
| 24 | // process and in child processes. |
| 25 | |
| 26 | static const int kNoHostId = 0; |
| 27 | static const int64 kNoCacheId = 0; |
[email protected] | e7dff7ba | 2009-10-09 03:25:51 | [diff] [blame] | 28 | static const int64 kNoResponseId = 0; |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 29 | static const int64 kUnknownCacheId = -1; |
| 30 | |
| 31 | enum Status { |
| 32 | UNCACHED, |
| 33 | IDLE, |
| 34 | CHECKING, |
| 35 | DOWNLOADING, |
| 36 | UPDATE_READY, |
[email protected] | 3aaa5b05 | 2014-01-30 08:53:38 | [diff] [blame] | 37 | OBSOLETE, |
| 38 | STATUS_LAST = OBSOLETE |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | enum EventID { |
| 42 | CHECKING_EVENT, |
| 43 | ERROR_EVENT, |
| 44 | NO_UPDATE_EVENT, |
| 45 | DOWNLOADING_EVENT, |
| 46 | PROGRESS_EVENT, |
| 47 | UPDATE_READY_EVENT, |
| 48 | CACHED_EVENT, |
[email protected] | 3aaa5b05 | 2014-01-30 08:53:38 | [diff] [blame] | 49 | OBSOLETE_EVENT, |
| 50 | EVENT_ID_LAST = OBSOLETE_EVENT |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 51 | }; |
| 52 | |
[email protected] | 653889b | 2013-02-18 15:42:43 | [diff] [blame] | 53 | // Temporarily renumber them in wierd way, to help remove LOG_TIP from WebKit |
[email protected] | 53c570b | 2010-06-18 02:02:05 | [diff] [blame] | 54 | enum LogLevel { |
[email protected] | 653889b | 2013-02-18 15:42:43 | [diff] [blame] | 55 | LOG_DEBUG = 4, |
| 56 | LOG_INFO = 1, |
| 57 | LOG_WARNING = 2, |
| 58 | LOG_ERROR = 3, |
[email protected] | 53c570b | 2010-06-18 02:02:05 | [diff] [blame] | 59 | }; |
| 60 | |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 61 | enum NamespaceType { |
| 62 | FALLBACK_NAMESPACE, |
[email protected] | 34e7dc6 | 2013-03-30 00:32:42 | [diff] [blame] | 63 | INTERCEPT_NAMESPACE, |
| 64 | NETWORK_NAMESPACE |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 65 | }; |
| 66 | |
[email protected] | 46aede5 | 2014-04-01 01:35:44 | [diff] [blame^] | 67 | enum ErrorReason { |
| 68 | MANIFEST_ERROR, |
| 69 | SIGNATURE_ERROR, |
| 70 | RESOURCE_ERROR, |
| 71 | CHANGED_ERROR, |
| 72 | ABORT_ERROR, |
| 73 | QUOTA_ERROR, |
| 74 | POLICY_ERROR, |
| 75 | UNKNOWN_ERROR, |
| 76 | ERROR_REASON_LAST = UNKNOWN_ERROR |
| 77 | }; |
| 78 | |
[email protected] | e5bf2fd | 2013-06-13 02:59:18 | [diff] [blame] | 79 | struct WEBKIT_STORAGE_COMMON_EXPORT AppCacheInfo { |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 80 | AppCacheInfo(); |
| 81 | ~AppCacheInfo(); |
| 82 | |
[email protected] | ec5c192 | 2010-07-28 03:14:37 | [diff] [blame] | 83 | GURL manifest_url; |
| 84 | base::Time creation_time; |
| 85 | base::Time last_update_time; |
| 86 | base::Time last_access_time; |
| 87 | int64 cache_id; |
[email protected] | 4252f60 | 2011-10-21 19:18:36 | [diff] [blame] | 88 | int64 group_id; |
[email protected] | ec5c192 | 2010-07-28 03:14:37 | [diff] [blame] | 89 | Status status; |
| 90 | int64 size; |
| 91 | bool is_complete; |
[email protected] | ec5c192 | 2010-07-28 03:14:37 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | typedef std::vector<AppCacheInfo> AppCacheInfoVector; |
| 95 | |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 96 | // Type to hold information about a single appcache resource. |
[email protected] | e5bf2fd | 2013-06-13 02:59:18 | [diff] [blame] | 97 | struct WEBKIT_STORAGE_COMMON_EXPORT AppCacheResourceInfo { |
[email protected] | 20f0487a | 2010-09-30 20:06:30 | [diff] [blame] | 98 | AppCacheResourceInfo(); |
| 99 | ~AppCacheResourceInfo(); |
| 100 | |
[email protected] | ec5c192 | 2010-07-28 03:14:37 | [diff] [blame] | 101 | GURL url; |
| 102 | int64 size; |
| 103 | bool is_master; |
| 104 | bool is_manifest; |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 105 | bool is_intercept; |
[email protected] | ec5c192 | 2010-07-28 03:14:37 | [diff] [blame] | 106 | bool is_fallback; |
| 107 | bool is_foreign; |
| 108 | bool is_explicit; |
[email protected] | 5e5bbf40 | 2011-07-12 23:34:12 | [diff] [blame] | 109 | int64 response_id; |
[email protected] | ec5c192 | 2010-07-28 03:14:37 | [diff] [blame] | 110 | }; |
| 111 | |
[email protected] | 46aede5 | 2014-04-01 01:35:44 | [diff] [blame^] | 112 | struct WEBKIT_STORAGE_COMMON_EXPORT ErrorDetails { |
| 113 | ErrorDetails(); |
| 114 | ErrorDetails(std::string message, |
| 115 | ErrorReason reason, |
| 116 | GURL url, |
| 117 | int status, |
| 118 | bool is_cross_origin); |
| 119 | ~ErrorDetails(); |
| 120 | |
| 121 | std::string message; |
| 122 | ErrorReason reason; |
| 123 | GURL url; |
| 124 | int status; |
| 125 | bool is_cross_origin; |
| 126 | }; |
| 127 | |
[email protected] | 5e5bbf40 | 2011-07-12 23:34:12 | [diff] [blame] | 128 | typedef std::vector<AppCacheResourceInfo> AppCacheResourceInfoVector; |
| 129 | |
[email protected] | e5bf2fd | 2013-06-13 02:59:18 | [diff] [blame] | 130 | struct WEBKIT_STORAGE_COMMON_EXPORT Namespace { |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 131 | Namespace(); // Type is set to FALLBACK_NAMESPACE by default. |
[email protected] | 34e7dc6 | 2013-03-30 00:32:42 | [diff] [blame] | 132 | Namespace(NamespaceType type, const GURL& url, const GURL& target, |
| 133 | bool is_pattern); |
[email protected] | 8fb8eeb9 | 2013-04-17 18:50:43 | [diff] [blame] | 134 | Namespace(NamespaceType type, const GURL& url, const GURL& target, |
| 135 | bool is_pattern, bool is_executable); |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 136 | ~Namespace(); |
| 137 | |
[email protected] | 34e7dc6 | 2013-03-30 00:32:42 | [diff] [blame] | 138 | bool IsMatch(const GURL& url) const; |
| 139 | |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 140 | NamespaceType type; |
| 141 | GURL namespace_url; |
| 142 | GURL target_url; |
[email protected] | 34e7dc6 | 2013-03-30 00:32:42 | [diff] [blame] | 143 | bool is_pattern; |
[email protected] | 8fb8eeb9 | 2013-04-17 18:50:43 | [diff] [blame] | 144 | bool is_executable; |
[email protected] | e2cadec8 | 2011-12-13 02:00:53 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | typedef std::vector<Namespace> NamespaceVector; |
| 148 | |
[email protected] | 19251af | 2010-05-13 18:24:46 | [diff] [blame] | 149 | // Interface used by backend (browser-process) to talk to frontend (renderer). |
[email protected] | e5bf2fd | 2013-06-13 02:59:18 | [diff] [blame] | 150 | class WEBKIT_STORAGE_COMMON_EXPORT AppCacheFrontend { |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 151 | public: |
[email protected] | ec5c192 | 2010-07-28 03:14:37 | [diff] [blame] | 152 | virtual void OnCacheSelected( |
| 153 | int host_id, const appcache::AppCacheInfo& info) = 0; |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 154 | virtual void OnStatusChanged(const std::vector<int>& host_ids, |
| 155 | Status status) = 0; |
| 156 | virtual void OnEventRaised(const std::vector<int>& host_ids, |
| 157 | EventID event_id) = 0; |
[email protected] | 697af4a | 2010-05-25 21:15:31 | [diff] [blame] | 158 | virtual void OnProgressEventRaised(const std::vector<int>& host_ids, |
| 159 | const GURL& url, |
| 160 | int num_total, int num_complete) = 0; |
[email protected] | 097dde2 | 2010-07-14 02:31:55 | [diff] [blame] | 161 | virtual void OnErrorEventRaised(const std::vector<int>& host_ids, |
[email protected] | 46aede5 | 2014-04-01 01:35:44 | [diff] [blame^] | 162 | const appcache::ErrorDetails& details) = 0; |
[email protected] | 5c7d598 | 2010-07-12 09:12:59 | [diff] [blame] | 163 | virtual void OnContentBlocked(int host_id, |
| 164 | const GURL& manifest_url) = 0; |
[email protected] | 53c570b | 2010-06-18 02:02:05 | [diff] [blame] | 165 | virtual void OnLogMessage(int host_id, LogLevel log_level, |
| 166 | const std::string& message) = 0; |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 167 | virtual ~AppCacheFrontend() {} |
| 168 | }; |
| 169 | |
[email protected] | 19251af | 2010-05-13 18:24:46 | [diff] [blame] | 170 | // Interface used by frontend (renderer) to talk to backend (browser-process). |
[email protected] | e5bf2fd | 2013-06-13 02:59:18 | [diff] [blame] | 171 | class WEBKIT_STORAGE_COMMON_EXPORT AppCacheBackend { |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 172 | public: |
| 173 | virtual void RegisterHost(int host_id) = 0; |
| 174 | virtual void UnregisterHost(int host_id) = 0; |
[email protected] | e16b8af7 | 2011-03-21 22:11:42 | [diff] [blame] | 175 | virtual void SetSpawningHostId(int host_id, int spawning_host_id) = 0; |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 176 | virtual void SelectCache(int host_id, |
| 177 | const GURL& document_url, |
| 178 | const int64 cache_document_was_loaded_from, |
| 179 | const GURL& manifest_url) = 0; |
[email protected] | 19251af | 2010-05-13 18:24:46 | [diff] [blame] | 180 | virtual void SelectCacheForWorker( |
| 181 | int host_id, |
| 182 | int parent_process_id, |
| 183 | int parent_host_id) = 0; |
| 184 | virtual void SelectCacheForSharedWorker( |
| 185 | int host_id, |
| 186 | int64 appcache_id) = 0; |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 187 | virtual void MarkAsForeignEntry(int host_id, const GURL& document_url, |
| 188 | int64 cache_document_was_loaded_from) = 0; |
| 189 | virtual Status GetStatus(int host_id) = 0; |
| 190 | virtual bool StartUpdate(int host_id) = 0; |
| 191 | virtual bool SwapCache(int host_id) = 0; |
[email protected] | ec5c192 | 2010-07-28 03:14:37 | [diff] [blame] | 192 | virtual void GetResourceList( |
| 193 | int host_id, std::vector<AppCacheResourceInfo>* resource_infos) = 0; |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 194 | |
[email protected] | 7ee2e88 | 2012-06-04 08:54:10 | [diff] [blame] | 195 | protected: |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 196 | virtual ~AppCacheBackend() {} |
| 197 | }; |
| 198 | |
[email protected] | 7e8e3dd | 2009-09-18 01:05:09 | [diff] [blame] | 199 | // Useful string constants. |
| 200 | // Note: These are also defined elsewhere in the chrome code base in |
| 201 | // url_contants.h .cc, however the appcache library doesn't not have |
| 202 | // any dependencies on the chrome library, so we can't use them in here. |
[email protected] | e5bf2fd | 2013-06-13 02:59:18 | [diff] [blame] | 203 | WEBKIT_STORAGE_COMMON_EXPORT extern const char kHttpScheme[]; |
| 204 | WEBKIT_STORAGE_COMMON_EXPORT extern const char kHttpsScheme[]; |
| 205 | WEBKIT_STORAGE_COMMON_EXPORT extern const char kHttpGETMethod[]; |
| 206 | WEBKIT_STORAGE_COMMON_EXPORT extern const char kHttpHEADMethod[]; |
[email protected] | 7e8e3dd | 2009-09-18 01:05:09 | [diff] [blame] | 207 | |
[email protected] | 8fb8eeb9 | 2013-04-17 18:50:43 | [diff] [blame] | 208 | // CommandLine flag to turn this experimental feature on. |
[email protected] | e5bf2fd | 2013-06-13 02:59:18 | [diff] [blame] | 209 | WEBKIT_STORAGE_COMMON_EXPORT extern const char kEnableExecutableHandlers[]; |
[email protected] | 8fb8eeb9 | 2013-04-17 18:50:43 | [diff] [blame] | 210 | |
[email protected] | e5bf2fd | 2013-06-13 02:59:18 | [diff] [blame] | 211 | WEBKIT_STORAGE_COMMON_EXPORT bool IsSchemeSupported(const GURL& url); |
| 212 | WEBKIT_STORAGE_COMMON_EXPORT bool IsMethodSupported(const std::string& method); |
| 213 | WEBKIT_STORAGE_COMMON_EXPORT bool IsSchemeAndMethodSupported( |
[email protected] | 35456abfb | 2013-06-11 10:57:39 | [diff] [blame] | 214 | const net::URLRequest* request); |
[email protected] | 7e8e3dd | 2009-09-18 01:05:09 | [diff] [blame] | 215 | |
[email protected] | e5bf2fd | 2013-06-13 02:59:18 | [diff] [blame] | 216 | WEBKIT_STORAGE_COMMON_EXPORT extern const base::FilePath::CharType |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 217 | kAppCacheDatabaseName[]; |
[email protected] | 4cccc22 | 2010-04-02 22:12:56 | [diff] [blame] | 218 | |
[email protected] | f430b571 | 2009-08-21 21:46:31 | [diff] [blame] | 219 | } // namespace |
| 220 | |
[email protected] | d5b2fdf | 2013-06-05 09:36:55 | [diff] [blame] | 221 | #endif // WEBKIT_COMMON_APPCACHE_APPCACHE_INTERFACES_H_ |