1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
15 * The Original Code is Mozilla Communicator client code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * Chris Waterson <waterson@netscape.com>
24 * Brendan Eich <brendan@mozilla.org>
25 * Ben Goodger <ben@netscape.com>
26 * Benjamin Smedberg <bsmedberg@covad.net>
27 * Mark Hammond <mhammond@skippinet.com.au>
29 * Alternatively, the contents of this file may be used under the terms of
30 * either of the GNU General Public License Version 2 or later (the "GPL"),
31 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
32 * in which case the provisions of the GPL or the LGPL are applicable instead
33 * of those above. If you wish to allow use of your version of this file only
34 * under the terms of either the GPL or the LGPL, and not to allow others to
35 * use your version of this file under the terms of the MPL, indicate your
36 * decision by deleting the provisions above and replace them with the notice
37 * and other provisions required by the GPL or the LGPL. If you do not delete
38 * the provisions above, a recipient may use your version of this file under
39 * the terms of any one of the MPL, the GPL or the LGPL.
41 * ***** END LICENSE BLOCK ***** */
43 #ifndef nsXULPrototypeCache_h__
44 #define nsXULPrototypeCache_h__
47 #include "nsICSSStyleSheet.h"
48 #include "nsIObserver.h"
49 #include "nsIXBLDocumentInfo.h"
50 #include "nsIXULPrototypeCache.h"
51 #include "nsDataHashtable.h"
52 #include "nsInterfaceHashtable.h"
53 #include "nsRefPtrHashtable.h"
54 #include "nsURIHashKey.h"
55 #include "nsXULPrototypeDocument.h"
57 class nsIFastLoadService
;
59 struct CacheScriptEntry
61 PRUint32 mScriptTypeID
; // the script language ID.
62 void* mScriptObject
; // the script object.
66 * The XUL prototype cache can be used to store and retrieve shared data for
67 * XUL documents, style sheets, XBL, and scripts.
69 * The cache has two levels:
70 * 1. In-memory hashtables
71 * 2. The on-disk fastload file.
73 class nsXULPrototypeCache
: public nsIXULPrototypeCache
,
81 // nsIXULPrototypeCache
82 virtual PRBool
IsCached(nsIURI
* aURI
) {
83 return GetPrototype(aURI
) != nsnull
;
85 virtual void AbortFastLoads();
89 * Whether the prototype cache is enabled.
94 * Flush the cache; remove all XUL prototype documents, style
95 * sheets, and scripts.
100 * Remove a XUL document from the set of loading documents.
102 void RemoveFromFastLoadSet(nsIURI
* aDocumentURI
);
105 * Write the XUL prototype document to fastload file. The proto must be
108 nsresult
WritePrototype(nsXULPrototypeDocument
* aPrototypeDocument
);
110 // The following methods are used to put and retrive various items into and
113 nsXULPrototypeDocument
* GetPrototype(nsIURI
* aURI
);
114 nsresult
PutPrototype(nsXULPrototypeDocument
* aDocument
);
116 void* GetScript(nsIURI
* aURI
, PRUint32
* langID
);
117 nsresult
PutScript(nsIURI
* aURI
, PRUint32 langID
, void* aScriptObject
);
119 nsIXBLDocumentInfo
* GetXBLDocumentInfo(nsIURI
* aURL
) {
120 return mXBLDocTable
.GetWeak(aURL
);
122 nsresult
PutXBLDocumentInfo(nsIXBLDocumentInfo
* aDocumentInfo
);
125 * Get a style sheet by URI. If the style sheet is not in the cache,
128 nsICSSStyleSheet
* GetStyleSheet(nsIURI
* aURI
) {
129 return mStyleSheetTable
.GetWeak(aURI
);
133 * Store a style sheet in the cache. The key, style sheet's URI is obtained
134 * from the style sheet itself.
136 nsresult
PutStyleSheet(nsICSSStyleSheet
* aStyleSheet
);
139 static nsXULPrototypeCache
* GetInstance();
140 static nsIFastLoadService
* GetFastLoadService();
142 static void ReleaseGlobals()
144 NS_IF_RELEASE(sInstance
);
149 NS_NewXULPrototypeCache(nsISupports
* aOuter
, REFNSIID aIID
, void** aResult
);
151 nsXULPrototypeCache();
152 virtual ~nsXULPrototypeCache();
154 static nsXULPrototypeCache
* sInstance
;
157 void FlushSkinFiles();
159 nsRefPtrHashtable
<nsURIHashKey
,nsXULPrototypeDocument
> mPrototypeTable
; // owns the prototypes
160 nsInterfaceHashtable
<nsURIHashKey
,nsICSSStyleSheet
> mStyleSheetTable
;
161 nsDataHashtable
<nsURIHashKey
,CacheScriptEntry
> mScriptTable
;
162 nsInterfaceHashtable
<nsURIHashKey
,nsIXBLDocumentInfo
> mXBLDocTable
;
164 ///////////////////////////////////////////////////////////////////////////
166 // this is really a hash set, with a dummy data parameter
167 nsDataHashtable
<nsURIHashKey
,PRUint32
> mFastLoadURITable
;
169 static nsIFastLoadService
* gFastLoadService
;
170 static nsIFile
* gFastLoadFile
;
172 // Bootstrap FastLoad Service
173 nsresult
StartFastLoad(nsIURI
* aDocumentURI
);
174 nsresult
StartFastLoadingURI(nsIURI
* aURI
, PRInt32 aDirectionFlags
);
177 #endif // nsXULPrototypeCache_h__