summaryrefslogtreecommitdiffstats
path: root/dom/xul/nsXULPrototypeCache.h
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/xul/nsXULPrototypeCache.h
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/xul/nsXULPrototypeCache.h')
-rw-r--r--dom/xul/nsXULPrototypeCache.h140
1 files changed, 140 insertions, 0 deletions
diff --git a/dom/xul/nsXULPrototypeCache.h b/dom/xul/nsXULPrototypeCache.h
new file mode 100644
index 000000000..f191c57ed
--- /dev/null
+++ b/dom/xul/nsXULPrototypeCache.h
@@ -0,0 +1,140 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* 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/. */
+
+#ifndef nsXULPrototypeCache_h__
+#define nsXULPrototypeCache_h__
+
+#include "nsCOMPtr.h"
+#include "nsIObserver.h"
+#include "nsXBLDocumentInfo.h"
+#include "nsJSThingHashtable.h"
+#include "nsInterfaceHashtable.h"
+#include "nsRefPtrHashtable.h"
+#include "nsURIHashKey.h"
+#include "nsXULPrototypeDocument.h"
+#include "nsIInputStream.h"
+#include "nsIStorageStream.h"
+
+#include "mozilla/scache/StartupCache.h"
+
+namespace mozilla {
+class CSSStyleSheet;
+} // namespace mozilla
+
+/**
+ * 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
+ * 2. The on-disk cache file.
+ */
+class nsXULPrototypeCache : public nsIObserver
+{
+public:
+ // nsISupports
+ NS_DECL_THREADSAFE_ISUPPORTS
+ NS_DECL_NSIOBSERVER
+
+ bool IsCached(nsIURI* aURI) {
+ return GetPrototype(aURI) != nullptr;
+ }
+ void AbortCaching();
+
+
+ /**
+ * Whether the prototype cache is enabled.
+ */
+ bool IsEnabled();
+
+ /**
+ * 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);
+
+ JSScript* GetScript(nsIURI* aURI);
+ nsresult PutScript(nsIURI* aURI, JS::Handle<JSScript*> aScriptObject);
+
+ nsXBLDocumentInfo* GetXBLDocumentInfo(nsIURI* aURL) {
+ return mXBLDocTable.GetWeak(aURL);
+ }
+ nsresult PutXBLDocumentInfo(nsXBLDocumentInfo* aDocumentInfo);
+
+ /**
+ * Get a style sheet by URI. If the style sheet is not in the cache,
+ * returns nullptr.
+ */
+ mozilla::CSSStyleSheet* GetStyleSheet(nsIURI* aURI) {
+ return mStyleSheetTable.GetWeak(aURI);
+ }
+
+ /**
+ * Store a style sheet in the cache. The key, style sheet's URI is obtained
+ * from the style sheet itself.
+ */
+ nsresult PutStyleSheet(mozilla::CSSStyleSheet* aStyleSheet);
+
+ /**
+ * 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);
+ nsresult HasData(nsIURI* aURI, bool* exists);
+
+ static nsXULPrototypeCache* GetInstance();
+ static nsXULPrototypeCache* MaybeGetInstance() { return sInstance; }
+
+ static void ReleaseGlobals()
+ {
+ NS_IF_RELEASE(sInstance);
+ }
+
+ void MarkInCCGeneration(uint32_t aGeneration);
+ void MarkInGC(JSTracer* aTrc);
+ void FlushScripts();
+protected:
+ friend nsresult
+ NS_NewXULPrototypeCache(nsISupports* aOuter, REFNSIID aIID, void** aResult);
+
+ nsXULPrototypeCache();
+ virtual ~nsXULPrototypeCache();
+
+ static nsXULPrototypeCache* sInstance;
+
+ void FlushSkinFiles();
+
+ nsRefPtrHashtable<nsURIHashKey,nsXULPrototypeDocument> mPrototypeTable; // owns the prototypes
+ nsRefPtrHashtable<nsURIHashKey,mozilla::CSSStyleSheet> mStyleSheetTable;
+ nsJSThingHashtable<nsURIHashKey, JSScript*> mScriptTable;
+ nsRefPtrHashtable<nsURIHashKey,nsXBLDocumentInfo> mXBLDocTable;
+
+ // URIs already written to the startup cache, to prevent double-caching.
+ nsTHashtable<nsURIHashKey> mStartupCacheURITable;
+
+ nsInterfaceHashtable<nsURIHashKey, nsIStorageStream> mOutputStreamTable;
+ nsInterfaceHashtable<nsURIHashKey, nsIObjectInputStream> mInputStreamTable;
+
+ // Bootstrap caching service
+ nsresult BeginCaching(nsIURI* aDocumentURI);
+};
+
+#endif // nsXULPrototypeCache_h__