Bug 458861. Validate TrueType headers before activating downloaded font. r=roc, sr...
[wine-gecko.git] / netwerk / cache / src / nsDiskCacheDeviceSQL.h
blob0dc94886d0833a6358db4005f14471cd200b3d0e
1 /* vim:set ts=2 sw=2 sts=2 et cin: */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Mozilla.
17 * The Initial Developer of the Original Code is IBM Corporation.
18 * Portions created by IBM Corporation are Copyright (C) 2004
19 * IBM Corporation. All Rights Reserved.
21 * Contributor(s):
22 * Darin Fisher <darin@meer.net>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsOfflineCacheDevice_h__
39 #define nsOfflineCacheDevice_h__
41 #include "nsCacheDevice.h"
42 #include "nsIApplicationCache.h"
43 #include "nsIApplicationCacheService.h"
44 #include "nsILocalFile.h"
45 #include "nsIObserver.h"
46 #include "mozIStorageConnection.h"
47 #include "mozIStorageFunction.h"
48 #include "nsIFile.h"
49 #include "nsAutoPtr.h"
50 #include "nsCOMPtr.h"
51 #include "nsCOMArray.h"
52 #include "nsVoidArray.h"
53 #include "nsInterfaceHashtable.h"
54 #include "nsClassHashtable.h"
55 #include "nsHashSets.h"
56 #include "nsWeakReference.h"
58 class nsIURI;
59 class nsOfflineCacheDevice;
61 class nsApplicationCacheNamespace : public nsIApplicationCacheNamespace
63 public:
64 NS_DECL_ISUPPORTS
65 NS_DECL_NSIAPPLICATIONCACHENAMESPACE
67 nsApplicationCacheNamespace() : mItemType(0) {}
69 private:
70 PRUint32 mItemType;
71 nsCString mNamespaceSpec;
72 nsCString mData;
75 class nsOfflineCacheEvictionFunction : public mozIStorageFunction {
76 public:
77 NS_DECL_ISUPPORTS
78 NS_DECL_MOZISTORAGEFUNCTION
80 nsOfflineCacheEvictionFunction(nsOfflineCacheDevice *device)
81 : mDevice(device)
84 void Reset() { mItems.Clear(); }
85 void Apply();
87 private:
88 nsOfflineCacheDevice *mDevice;
89 nsCOMArray<nsIFile> mItems;
93 class nsOfflineCacheDevice : public nsCacheDevice
94 , public nsIApplicationCacheService
96 public:
97 nsOfflineCacheDevice();
99 NS_DECL_ISUPPORTS
100 NS_DECL_NSIAPPLICATIONCACHESERVICE
103 * nsCacheDevice methods
106 virtual ~nsOfflineCacheDevice();
108 static nsOfflineCacheDevice *GetInstance();
110 virtual nsresult Init();
111 virtual nsresult Shutdown();
113 virtual const char * GetDeviceID(void);
114 virtual nsCacheEntry * FindEntry(nsCString * key, PRBool *collision);
115 virtual nsresult DeactivateEntry(nsCacheEntry * entry);
116 virtual nsresult BindEntry(nsCacheEntry * entry);
117 virtual void DoomEntry( nsCacheEntry * entry );
119 virtual nsresult OpenInputStreamForEntry(nsCacheEntry * entry,
120 nsCacheAccessMode mode,
121 PRUint32 offset,
122 nsIInputStream ** result);
124 virtual nsresult OpenOutputStreamForEntry(nsCacheEntry * entry,
125 nsCacheAccessMode mode,
126 PRUint32 offset,
127 nsIOutputStream ** result);
129 virtual nsresult GetFileForEntry(nsCacheEntry * entry,
130 nsIFile ** result);
132 virtual nsresult OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize);
134 virtual nsresult Visit(nsICacheVisitor * visitor);
136 virtual nsresult EvictEntries(const char * clientID);
139 /* Entry ownership */
140 nsresult GetOwnerDomains(const char * clientID,
141 PRUint32 * count,
142 char *** domains);
143 nsresult GetOwnerURIs(const char * clientID,
144 const nsACString & ownerDomain,
145 PRUint32 * count,
146 char *** uris);
147 nsresult SetOwnedKeys(const char * clientID,
148 const nsACString & ownerDomain,
149 const nsACString & ownerUrl,
150 PRUint32 count,
151 const char ** keys);
152 nsresult GetOwnedKeys(const char * clientID,
153 const nsACString & ownerDomain,
154 const nsACString & ownerUrl,
155 PRUint32 * count,
156 char *** keys);
157 nsresult AddOwnedKey(const char * clientID,
158 const nsACString & ownerDomain,
159 const nsACString & ownerURI,
160 const nsACString & key);
161 nsresult RemoveOwnedKey(const char * clientID,
162 const nsACString & ownerDomain,
163 const nsACString & ownerURI,
164 const nsACString & key);
165 nsresult KeyIsOwned(const char * clientID,
166 const nsACString & ownerDomain,
167 const nsACString & ownerURI,
168 const nsACString & key,
169 PRBool * isOwned);
171 nsresult ClearKeysOwnedByDomain(const char *clientID,
172 const nsACString &ownerDomain);
173 nsresult EvictUnownedEntries(const char *clientID);
175 nsresult ActivateCache(const nsCSubstring &group,
176 const nsCSubstring &clientID);
177 PRBool IsActiveCache(const nsCSubstring &group,
178 const nsCSubstring &clientID);
179 nsresult DeactivateGroup(const nsCSubstring &group);
180 nsresult GetGroupForCache(const nsCSubstring &clientID,
181 nsCString &out);
184 * Preference accessors
187 void SetCacheParentDirectory(nsILocalFile * parentDir);
188 void SetCapacity(PRUint32 capacity);
190 nsILocalFile * CacheDirectory() { return mCacheDirectory; }
191 PRUint32 CacheCapacity() { return mCacheCapacity; }
192 PRUint32 CacheSize();
193 PRUint32 EntryCount();
195 private:
196 friend class nsApplicationCache;
198 static PLDHashOperator ShutdownApplicationCache(const nsACString &key,
199 nsIWeakReference *weakRef,
200 void *ctx);
202 static PRBool GetStrictFileOriginPolicy();
204 PRBool Initialized() { return mDB != nsnull; }
206 nsresult InitActiveCaches();
207 nsresult UpdateEntry(nsCacheEntry *entry);
208 nsresult UpdateEntrySize(nsCacheEntry *entry, PRUint32 newSize);
209 nsresult DeleteEntry(nsCacheEntry *entry, PRBool deleteData);
210 nsresult DeleteData(nsCacheEntry *entry);
211 nsresult EnableEvictionObserver();
212 nsresult DisableEvictionObserver();
214 PRBool CanUseCache(nsIURI *keyURI, const nsCString &clientID);
216 nsresult MarkEntry(const nsCString &clientID,
217 const nsACString &key,
218 PRUint32 typeBits);
219 nsresult UnmarkEntry(const nsCString &clientID,
220 const nsACString &key,
221 PRUint32 typeBits);
223 nsresult CacheOpportunistically(const nsCString &clientID,
224 const nsACString &key);
225 nsresult GetTypes(const nsCString &clientID,
226 const nsACString &key,
227 PRUint32 *typeBits);
229 nsresult GetMatchingNamespace(const nsCString &clientID,
230 const nsACString &key,
231 nsIApplicationCacheNamespace **out);
232 nsresult GatherEntries(const nsCString &clientID,
233 PRUint32 typeBits,
234 PRUint32 *count,
235 char *** values);
236 nsresult AddNamespace(const nsCString &clientID,
237 nsIApplicationCacheNamespace *ns);
239 nsresult RunSimpleQuery(mozIStorageStatement *statment,
240 PRUint32 resultIndex,
241 PRUint32 * count,
242 char *** values);
244 nsCOMPtr<mozIStorageConnection> mDB;
245 nsRefPtr<nsOfflineCacheEvictionFunction> mEvictionFunction;
247 nsCOMPtr<mozIStorageStatement> mStatement_CacheSize;
248 nsCOMPtr<mozIStorageStatement> mStatement_DomainSize;
249 nsCOMPtr<mozIStorageStatement> mStatement_EntryCount;
250 nsCOMPtr<mozIStorageStatement> mStatement_UpdateEntry;
251 nsCOMPtr<mozIStorageStatement> mStatement_UpdateEntrySize;
252 nsCOMPtr<mozIStorageStatement> mStatement_UpdateEntryFlags;
253 nsCOMPtr<mozIStorageStatement> mStatement_DeleteEntry;
254 nsCOMPtr<mozIStorageStatement> mStatement_FindEntry;
255 nsCOMPtr<mozIStorageStatement> mStatement_BindEntry;
256 nsCOMPtr<mozIStorageStatement> mStatement_ClearDomain;
257 nsCOMPtr<mozIStorageStatement> mStatement_MarkEntry;
258 nsCOMPtr<mozIStorageStatement> mStatement_UnmarkEntry;
259 nsCOMPtr<mozIStorageStatement> mStatement_GetTypes;
260 nsCOMPtr<mozIStorageStatement> mStatement_FindNamespaceEntry;
261 nsCOMPtr<mozIStorageStatement> mStatement_InsertNamespaceEntry;
262 nsCOMPtr<mozIStorageStatement> mStatement_CleanupUnmarked;
263 nsCOMPtr<mozIStorageStatement> mStatement_GatherEntries;
264 nsCOMPtr<mozIStorageStatement> mStatement_ActivateClient;
265 nsCOMPtr<mozIStorageStatement> mStatement_DeactivateGroup;
266 nsCOMPtr<mozIStorageStatement> mStatement_FindClient;
267 nsCOMPtr<mozIStorageStatement> mStatement_FindClientByNamespace;
269 nsCOMPtr<nsILocalFile> mCacheDirectory;
270 PRUint32 mCacheCapacity;
271 PRInt32 mDeltaCounter;
273 nsInterfaceHashtable<nsCStringHashKey, nsIWeakReference> mCaches;
274 nsClassHashtable<nsCStringHashKey, nsCString> mActiveCachesByGroup;
275 nsCStringHashSet mActiveCaches;
278 #endif // nsOfflineCacheDevice_h__