2006-12-22 19:11:16 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-12-22 19:11:16 +03:00
|
|
|
|
|
|
|
#ifndef nsXULPrototypeCache_h__
|
|
|
|
#define nsXULPrototypeCache_h__
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIObserver.h"
|
2010-07-15 05:53:11 +04:00
|
|
|
#include "nsXBLDocumentInfo.h"
|
2013-07-23 13:58:27 +04:00
|
|
|
#include "nsJSThingHashtable.h"
|
2006-12-22 19:11:16 +03:00
|
|
|
#include "nsInterfaceHashtable.h"
|
2007-03-12 08:53:33 +03:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2006-12-22 19:11:16 +03:00
|
|
|
#include "nsURIHashKey.h"
|
2007-03-12 08:53:33 +03:00
|
|
|
#include "nsXULPrototypeDocument.h"
|
2010-08-12 23:42:36 +04:00
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsIStorageStream.h"
|
2011-10-30 00:14:13 +04:00
|
|
|
|
2010-08-12 23:42:36 +04:00
|
|
|
#include "mozilla/scache/StartupCache.h"
|
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
namespace mozilla {
|
|
|
|
class CSSStyleSheet;
|
|
|
|
} // namespace mozilla
|
2006-12-22 19:11:16 +03:00
|
|
|
|
2007-03-12 08:53:33 +03:00
|
|
|
/**
|
|
|
|
* The XUL prototype cache can be used to store and retrieve shared data for
|
|
|
|
* XUL documents, style sheets, XBL, and scripts.
|
|
|
|
*
|
|
|
|
* The cache has two levels:
|
|
|
|
* 1. In-memory hashtables
|
2010-08-12 23:42:36 +04:00
|
|
|
* 2. The on-disk cache file.
|
2007-03-12 08:53:33 +03:00
|
|
|
*/
|
2011-08-26 23:50:23 +04:00
|
|
|
class nsXULPrototypeCache : public nsIObserver
|
2006-12-22 19:11:16 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
// nsISupports
|
2013-07-19 06:21:19 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2006-12-22 19:11:16 +03:00
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsCached(nsIURI* aURI) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return GetPrototype(aURI) != nullptr;
|
2007-03-12 08:53:33 +03:00
|
|
|
}
|
2011-08-26 23:50:23 +04:00
|
|
|
void AbortCaching();
|
2007-03-12 08:53:33 +03:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the prototype cache is enabled.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsEnabled();
|
2007-03-12 08:53:33 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Flush the cache; remove all XUL prototype documents, style
|
|
|
|
* sheets, and scripts.
|
|
|
|
*/
|
|
|
|
void Flush();
|
|
|
|
|
|
|
|
|
|
|
|
// The following methods are used to put and retrive various items into and
|
|
|
|
// from the cache.
|
|
|
|
|
|
|
|
nsXULPrototypeDocument* GetPrototype(nsIURI* aURI);
|
|
|
|
nsresult PutPrototype(nsXULPrototypeDocument* aDocument);
|
|
|
|
|
2012-04-25 02:31:28 +04:00
|
|
|
JSScript* GetScript(nsIURI* aURI);
|
2013-05-20 16:40:06 +04:00
|
|
|
nsresult PutScript(nsIURI* aURI, JS::Handle<JSScript*> aScriptObject);
|
2007-03-12 08:53:33 +03:00
|
|
|
|
2010-07-15 05:53:11 +04:00
|
|
|
nsXBLDocumentInfo* GetXBLDocumentInfo(nsIURI* aURL) {
|
2007-03-12 08:53:33 +03:00
|
|
|
return mXBLDocTable.GetWeak(aURL);
|
|
|
|
}
|
2010-07-15 05:53:11 +04:00
|
|
|
nsresult PutXBLDocumentInfo(nsXBLDocumentInfo* aDocumentInfo);
|
2007-03-12 08:53:33 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a style sheet by URI. If the style sheet is not in the cache,
|
2012-07-30 18:20:58 +04:00
|
|
|
* returns nullptr.
|
2007-03-12 08:53:33 +03:00
|
|
|
*/
|
2014-06-20 14:32:49 +04:00
|
|
|
mozilla::CSSStyleSheet* GetStyleSheet(nsIURI* aURI) {
|
2007-03-12 08:53:33 +03:00
|
|
|
return mStyleSheetTable.GetWeak(aURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a style sheet in the cache. The key, style sheet's URI is obtained
|
|
|
|
* from the style sheet itself.
|
|
|
|
*/
|
2014-06-20 14:32:49 +04:00
|
|
|
nsresult PutStyleSheet(mozilla::CSSStyleSheet* aStyleSheet);
|
2007-03-12 08:53:33 +03:00
|
|
|
|
2010-08-12 23:42:36 +04:00
|
|
|
/**
|
|
|
|
* Write the XUL prototype document to a cache file. The proto must be
|
|
|
|
* fully loaded.
|
|
|
|
*/
|
|
|
|
nsresult WritePrototype(nsXULPrototypeDocument* aPrototypeDocument);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This interface allows partial reads and writes from the buffers in the
|
|
|
|
* startupCache.
|
|
|
|
*/
|
|
|
|
nsresult GetInputStream(nsIURI* aURI, nsIObjectInputStream** objectInput);
|
|
|
|
nsresult FinishInputStream(nsIURI* aURI);
|
|
|
|
nsresult GetOutputStream(nsIURI* aURI, nsIObjectOutputStream** objectOutput);
|
|
|
|
nsresult FinishOutputStream(nsIURI* aURI);
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult HasData(nsIURI* aURI, bool* exists);
|
2010-08-12 23:42:36 +04:00
|
|
|
|
2007-03-12 08:53:33 +03:00
|
|
|
static nsXULPrototypeCache* GetInstance();
|
2013-03-19 21:20:21 +04:00
|
|
|
static nsXULPrototypeCache* MaybeGetInstance() { return sInstance; }
|
2007-03-12 08:53:33 +03:00
|
|
|
|
|
|
|
static void ReleaseGlobals()
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(sInstance);
|
|
|
|
}
|
2006-12-22 19:11:16 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
void MarkInCCGeneration(uint32_t aGeneration);
|
2013-03-19 21:20:21 +04:00
|
|
|
void MarkInGC(JSTracer* aTrc);
|
|
|
|
void FlushScripts();
|
2006-12-22 19:11:16 +03:00
|
|
|
protected:
|
2010-06-10 22:11:40 +04:00
|
|
|
friend nsresult
|
2006-12-22 19:11:16 +03:00
|
|
|
NS_NewXULPrototypeCache(nsISupports* aOuter, REFNSIID aIID, void** aResult);
|
|
|
|
|
|
|
|
nsXULPrototypeCache();
|
|
|
|
virtual ~nsXULPrototypeCache();
|
|
|
|
|
2007-03-12 08:53:33 +03:00
|
|
|
static nsXULPrototypeCache* sInstance;
|
|
|
|
|
2006-12-22 19:11:16 +03:00
|
|
|
void FlushSkinFiles();
|
|
|
|
|
2013-07-23 13:58:27 +04:00
|
|
|
nsRefPtrHashtable<nsURIHashKey,nsXULPrototypeDocument> mPrototypeTable; // owns the prototypes
|
2014-06-20 14:32:49 +04:00
|
|
|
nsRefPtrHashtable<nsURIHashKey,mozilla::CSSStyleSheet> mStyleSheetTable;
|
2013-07-23 13:58:27 +04:00
|
|
|
nsJSThingHashtable<nsURIHashKey, JSScript*> mScriptTable;
|
|
|
|
nsRefPtrHashtable<nsURIHashKey,nsXBLDocumentInfo> mXBLDocTable;
|
2006-12-22 19:11:16 +03:00
|
|
|
|
2015-06-17 02:45:29 +03:00
|
|
|
// URIs already written to the startup cache, to prevent double-caching.
|
|
|
|
nsTHashtable<nsURIHashKey> mStartupCacheURITable;
|
2010-08-12 23:42:36 +04:00
|
|
|
|
2013-07-23 13:58:27 +04:00
|
|
|
nsInterfaceHashtable<nsURIHashKey, nsIStorageStream> mOutputStreamTable;
|
2010-08-12 23:42:36 +04:00
|
|
|
nsInterfaceHashtable<nsURIHashKey, nsIObjectInputStream> mInputStreamTable;
|
2013-03-19 21:20:21 +04:00
|
|
|
|
2010-08-12 23:42:36 +04:00
|
|
|
// Bootstrap caching service
|
|
|
|
nsresult BeginCaching(nsIURI* aDocumentURI);
|
2006-12-22 19:11:16 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsXULPrototypeCache_h__
|