blob: c99eb87f2ff87dde053423f4317b340d5f59e084 [file] [log] [blame]
[email protected]7ee2e882012-06-04 08:54:101// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]f430b5712009-08-21 21:46:312// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]d5b2fdf2013-06-05 09:36:555#ifndef WEBKIT_COMMON_APPCACHE_APPCACHE_INTERFACES_H_
6#define WEBKIT_COMMON_APPCACHE_APPCACHE_INTERFACES_H_
[email protected]f430b5712009-08-21 21:46:317
[email protected]7e8e3dd2009-09-18 01:05:098#include <string>
[email protected]f430b5712009-08-21 21:46:319#include <vector>
[email protected]ad677772013-06-29 14:18:3810
[email protected]f430b5712009-08-21 21:46:3111#include "base/basictypes.h"
[email protected]57999812013-02-24 05:40:5212#include "base/files/file_path.h"
[email protected]0a8ebe12013-06-28 15:23:2313#include "base/time/time.h"
[email protected]ad677772013-06-29 14:18:3814#include "url/gurl.h"
[email protected]e5bf2fd2013-06-13 02:59:1815#include "webkit/common/webkit_storage_common_export.h"
[email protected]f430b5712009-08-21 21:46:3116
[email protected]edfe7fab2010-11-28 13:11:5217namespace net {
[email protected]7e8e3dd2009-09-18 01:05:0918class URLRequest;
[email protected]ad677772013-06-29 14:18:3819}
[email protected]f430b5712009-08-21 21:46:3120
21namespace appcache {
22
23// Defines constants, types, and abstract classes used in the main
24// process and in child processes.
25
26static const int kNoHostId = 0;
27static const int64 kNoCacheId = 0;
[email protected]e7dff7ba2009-10-09 03:25:5128static const int64 kNoResponseId = 0;
[email protected]f430b5712009-08-21 21:46:3129static const int64 kUnknownCacheId = -1;
30
31enum Status {
32 UNCACHED,
33 IDLE,
34 CHECKING,
35 DOWNLOADING,
36 UPDATE_READY,
[email protected]3aaa5b052014-01-30 08:53:3837 OBSOLETE,
38 STATUS_LAST = OBSOLETE
[email protected]f430b5712009-08-21 21:46:3139};
40
41enum 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]3aaa5b052014-01-30 08:53:3849 OBSOLETE_EVENT,
50 EVENT_ID_LAST = OBSOLETE_EVENT
[email protected]f430b5712009-08-21 21:46:3151};
52
[email protected]653889b2013-02-18 15:42:4353// Temporarily renumber them in wierd way, to help remove LOG_TIP from WebKit
[email protected]53c570b2010-06-18 02:02:0554enum LogLevel {
[email protected]653889b2013-02-18 15:42:4355 LOG_DEBUG = 4,
56 LOG_INFO = 1,
57 LOG_WARNING = 2,
58 LOG_ERROR = 3,
[email protected]53c570b2010-06-18 02:02:0559};
60
[email protected]e2cadec82011-12-13 02:00:5361enum NamespaceType {
62 FALLBACK_NAMESPACE,
[email protected]34e7dc62013-03-30 00:32:4263 INTERCEPT_NAMESPACE,
64 NETWORK_NAMESPACE
[email protected]e2cadec82011-12-13 02:00:5365};
66
[email protected]46aede52014-04-01 01:35:4467enum 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]e5bf2fd2013-06-13 02:59:1879struct WEBKIT_STORAGE_COMMON_EXPORT AppCacheInfo {
[email protected]20f0487a2010-09-30 20:06:3080 AppCacheInfo();
81 ~AppCacheInfo();
82
[email protected]ec5c1922010-07-28 03:14:3783 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]4252f602011-10-21 19:18:3688 int64 group_id;
[email protected]ec5c1922010-07-28 03:14:3789 Status status;
90 int64 size;
91 bool is_complete;
[email protected]ec5c1922010-07-28 03:14:3792};
93
94typedef std::vector<AppCacheInfo> AppCacheInfoVector;
95
[email protected]20f0487a2010-09-30 20:06:3096// Type to hold information about a single appcache resource.
[email protected]e5bf2fd2013-06-13 02:59:1897struct WEBKIT_STORAGE_COMMON_EXPORT AppCacheResourceInfo {
[email protected]20f0487a2010-09-30 20:06:3098 AppCacheResourceInfo();
99 ~AppCacheResourceInfo();
100
[email protected]ec5c1922010-07-28 03:14:37101 GURL url;
102 int64 size;
103 bool is_master;
104 bool is_manifest;
[email protected]e2cadec82011-12-13 02:00:53105 bool is_intercept;
[email protected]ec5c1922010-07-28 03:14:37106 bool is_fallback;
107 bool is_foreign;
108 bool is_explicit;
[email protected]5e5bbf402011-07-12 23:34:12109 int64 response_id;
[email protected]ec5c1922010-07-28 03:14:37110};
111
[email protected]46aede52014-04-01 01:35:44112struct 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]5e5bbf402011-07-12 23:34:12128typedef std::vector<AppCacheResourceInfo> AppCacheResourceInfoVector;
129
[email protected]e5bf2fd2013-06-13 02:59:18130struct WEBKIT_STORAGE_COMMON_EXPORT Namespace {
[email protected]e2cadec82011-12-13 02:00:53131 Namespace(); // Type is set to FALLBACK_NAMESPACE by default.
[email protected]34e7dc62013-03-30 00:32:42132 Namespace(NamespaceType type, const GURL& url, const GURL& target,
133 bool is_pattern);
[email protected]8fb8eeb92013-04-17 18:50:43134 Namespace(NamespaceType type, const GURL& url, const GURL& target,
135 bool is_pattern, bool is_executable);
[email protected]e2cadec82011-12-13 02:00:53136 ~Namespace();
137
[email protected]34e7dc62013-03-30 00:32:42138 bool IsMatch(const GURL& url) const;
139
[email protected]e2cadec82011-12-13 02:00:53140 NamespaceType type;
141 GURL namespace_url;
142 GURL target_url;
[email protected]34e7dc62013-03-30 00:32:42143 bool is_pattern;
[email protected]8fb8eeb92013-04-17 18:50:43144 bool is_executable;
[email protected]e2cadec82011-12-13 02:00:53145};
146
147typedef std::vector<Namespace> NamespaceVector;
148
[email protected]19251af2010-05-13 18:24:46149// Interface used by backend (browser-process) to talk to frontend (renderer).
[email protected]e5bf2fd2013-06-13 02:59:18150class WEBKIT_STORAGE_COMMON_EXPORT AppCacheFrontend {
[email protected]f430b5712009-08-21 21:46:31151 public:
[email protected]ec5c1922010-07-28 03:14:37152 virtual void OnCacheSelected(
153 int host_id, const appcache::AppCacheInfo& info) = 0;
[email protected]f430b5712009-08-21 21:46:31154 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]697af4a2010-05-25 21:15:31158 virtual void OnProgressEventRaised(const std::vector<int>& host_ids,
159 const GURL& url,
160 int num_total, int num_complete) = 0;
[email protected]097dde22010-07-14 02:31:55161 virtual void OnErrorEventRaised(const std::vector<int>& host_ids,
[email protected]46aede52014-04-01 01:35:44162 const appcache::ErrorDetails& details) = 0;
[email protected]5c7d5982010-07-12 09:12:59163 virtual void OnContentBlocked(int host_id,
164 const GURL& manifest_url) = 0;
[email protected]53c570b2010-06-18 02:02:05165 virtual void OnLogMessage(int host_id, LogLevel log_level,
166 const std::string& message) = 0;
[email protected]f430b5712009-08-21 21:46:31167 virtual ~AppCacheFrontend() {}
168};
169
[email protected]19251af2010-05-13 18:24:46170// Interface used by frontend (renderer) to talk to backend (browser-process).
[email protected]e5bf2fd2013-06-13 02:59:18171class WEBKIT_STORAGE_COMMON_EXPORT AppCacheBackend {
[email protected]f430b5712009-08-21 21:46:31172 public:
173 virtual void RegisterHost(int host_id) = 0;
174 virtual void UnregisterHost(int host_id) = 0;
[email protected]e16b8af72011-03-21 22:11:42175 virtual void SetSpawningHostId(int host_id, int spawning_host_id) = 0;
[email protected]f430b5712009-08-21 21:46:31176 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]19251af2010-05-13 18:24:46180 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]f430b5712009-08-21 21:46:31187 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]ec5c1922010-07-28 03:14:37192 virtual void GetResourceList(
193 int host_id, std::vector<AppCacheResourceInfo>* resource_infos) = 0;
[email protected]f430b5712009-08-21 21:46:31194
[email protected]7ee2e882012-06-04 08:54:10195 protected:
[email protected]f430b5712009-08-21 21:46:31196 virtual ~AppCacheBackend() {}
197};
198
[email protected]7e8e3dd2009-09-18 01:05:09199// 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]e5bf2fd2013-06-13 02:59:18203WEBKIT_STORAGE_COMMON_EXPORT extern const char kHttpScheme[];
204WEBKIT_STORAGE_COMMON_EXPORT extern const char kHttpsScheme[];
205WEBKIT_STORAGE_COMMON_EXPORT extern const char kHttpGETMethod[];
206WEBKIT_STORAGE_COMMON_EXPORT extern const char kHttpHEADMethod[];
[email protected]7e8e3dd2009-09-18 01:05:09207
[email protected]8fb8eeb92013-04-17 18:50:43208// CommandLine flag to turn this experimental feature on.
[email protected]e5bf2fd2013-06-13 02:59:18209WEBKIT_STORAGE_COMMON_EXPORT extern const char kEnableExecutableHandlers[];
[email protected]8fb8eeb92013-04-17 18:50:43210
[email protected]e5bf2fd2013-06-13 02:59:18211WEBKIT_STORAGE_COMMON_EXPORT bool IsSchemeSupported(const GURL& url);
212WEBKIT_STORAGE_COMMON_EXPORT bool IsMethodSupported(const std::string& method);
213WEBKIT_STORAGE_COMMON_EXPORT bool IsSchemeAndMethodSupported(
[email protected]35456abfb2013-06-11 10:57:39214 const net::URLRequest* request);
[email protected]7e8e3dd2009-09-18 01:05:09215
[email protected]e5bf2fd2013-06-13 02:59:18216WEBKIT_STORAGE_COMMON_EXPORT extern const base::FilePath::CharType
[email protected]a3ef4832013-02-02 05:12:33217 kAppCacheDatabaseName[];
[email protected]4cccc222010-04-02 22:12:56218
[email protected]f430b5712009-08-21 21:46:31219} // namespace
220
[email protected]d5b2fdf2013-06-05 09:36:55221#endif // WEBKIT_COMMON_APPCACHE_APPCACHE_INTERFACES_H_