mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
6ecfad14f8
- Bug 1140558 - Part 2 - Make the testing deepEqual implementation shared properly in ObjectUtils.jsm. r=yoric (f1a217e34a) - Bug 1154773 - Change undefined property a.prototype. r=Yoric (8a4dc37d6c) - Bug 1202971 (part 1) - Fix compile warnings in libmar. r=rstrong. (30cdf015c2) - bug 1200360 - fix $(DEFINES) usage in modules/libmar/tool/moz.build. r=mshal (26f1c5640b) - Bug 903135 - Updates to libmar needed to support B2G MAR signature verification. r=bbondy (81612e2200) - Bug 1228332 - Fix a potentially uninitialized pointer read, flagged by static analysis. r=spohl (9cac770c90) - Bug 1202971 (part 2) - Fix compile warnings in toolkit/mozapps/update/tests. r=rstrong. (814f2b3b8b) - Bug 973933 - Fix libmar warnings. r=rstrong. a=Callek (e0c2d3edcc) - Bug 1232219 (part 1) - Fix -Wunused warnings in libmar/. r=bbondy. (dc046504df) - Bug 1228281 - [GTK3] add padding to buttons. r=karlt (fe8ca55f58) - Bug 1232219 (part 2.5) - Fix -Wunused warnings in parser/expat/lib/. r=hsivonen. (e4d10c5d68) - Bug 1232219 (part 3) - Fix remaining -Wunused warnings. r=glandium. (35c5f3c38e) - Bug 1232219 (follow-up) - Fix nsinstall.c bustage in SM(e) builds. r=me. (d62c12cf35) - Bug 1186815 (part 1) - Replace nsBaseHashtable::Enumerate() calls in modules/libjar/ with iterators. r=mwu. (6959b19fab) - Bug 1186815 (part 2) - Replace nsBaseHashtable::Enumerate() calls in modules/libjar/ with iterators. r=mwu. (02c6f50482) - Bug 1181444 (part 1.5) - Remove dead PLDHashOperator declarations. r=froydnj. (c956e03dc0) - Bug 1225407 - Replace nsInterfaceHashtable::EnumerateRead() call in SubstitutingProtocolHandler with an iterator. r=michal (aa71f5499c) - Bug 1187781 (part 1) - Replace nsBaseHashtable::EnumerateRead() calls in dom/xbl/ with iterators. r=mrbkap. (68f51d05ba) - Bug 1187781 (part 2) - Replace nsBaseHashtable::EnumerateRead() calls in dom/xbl/ with iterators. r=mrbkap. (1dfc261267) - Bug 1187781 (part 3) - Replace nsBaseHashtable::EnumerateRead() calls in dom/xbl/ with iterators. r=mrbkap. (922fc4e4ef) - Bug 1187781 (part 4) - Replace nsBaseHashtable::EnumerateRead() calls in dom/xbl/ with iterators. r=mrbkap. (7b1915053f) - Bug 1187781 (part 5) - Replace nsBaseHashtable::EnumerateRead() calls in dom/xbl/ with iterators. r=mrbkap. (5df4cc1d09) - Bug 1181444 (part 2) - Remove nsBaseHashtable::Enumerate(). r=froydnj. (c606342f1d) - Bug 1243912 - Remove unused Loader::RemoveEntriesWithURI declaration. r=njn (e59b2ef892) - Bug 1187137 (part 4) - Replace nsBaseHashtable::Enumerate() calls in netwerk/protocol/ with iterators. r=valentin. (17fb17c48f) - Bug 1187137 (part 5) - Replace nsBaseHashtable::Enumerate() calls in netwerk/protocol/ with iterators. r=valentin. (89d430cf98) - Bug 1187137 (part 6) - Replace nsBaseHashtable::Enumerate() calls in netwerk/protocol/ with iterators. r=valentin. (37befe08c6) - Bug 1187137 (part 7) - Replace nsBaseHashtable::Enumerate() calls in netwerk/protocol/ with iterators. r=valentin (a8227c4b3e) - Bug 1187137 (part 1) - Replace nsBaseHashtable::Enumerate() calls in netwerk/protocol/ with iterators. r=michal. (05f71a4a94) - Bug 1187137 (part 2) - Replace nsBaseHashtable::Enumerate() calls in netwerk/protocol/ with iterators. r=michal. (5defa991b5) - Bug 1187137 (part 3) - Replace nsBaseHashtable::Enumerate() calls in netwerk/protocol/ with iterators. r=michal. (f2e0a4be0f) - Bug 1187137 (part 8) - Replace nsBaseHashtable::Enumerate() calls in netwerk/protocol/ with iterators. r=valentin. (11b77f3b67) - Bug 1187137 (part 9) - Replace nsBaseHashtable::Enumerate() calls in netwerk/protocol/ with iterators. r=valentin. (7a6bd9a17e) - Bug 1230743 - telemtry for nsConnectionEntry hit rate r=hurley (a75d6ec52c) - Bug 1218297 - eventtokenbucket shutdown leak r=valentin (1723059684) - Bug 1239961 - Minimize amount of PR_Poll and PR_Read calls during shutdown. r=mcmanus (127259afb6) - Bug 1187137 (part 10) - Replace nsBaseHashtable::Enumerate() calls in netwerk/protocol/ with iterators. r=valentin. (eee20459fb) - Bug 1187137 (part 11) - Replace nsBaseHashtable::Enumerate() calls in netwerk/protocol/ with iterators. r=valentin. (864bc96862) - Bug 1187137 (part 12) - Replace nsBaseHashtable::Enumerate() calls in netwerk/protocol/ with iterators. r=valentin. (4fd9540167) - Bug 1187137 (part 13) - Replace nsBaseHashtable::Enumerate() calls in netwerk/protocol/ with iterators. r=valentin. (65a01f4083) - Bug 1187151 (part 14) - Replace nsBaseHashtable::Enumerate() calls in dom/ with iterators. r=baku. (a71b4169a9) - Bug 1187141 - Replace nsBaseHashtable::Enumerate() calls in storage/ with iterators. r=mak. (d95fb168c9) - Bug 1187151 (part 11) - Replace nsBaseHashtable::Enumerate() calls in dom/ with iterators. r=khuey. (dda92d0455) - Bug 1187151 (part 10) - Replace nsBaseHashtable::Enumerate() calls in dom/ with iterators. r=khuey. (f59270049c) - Bug 1191460 Contextual Identity tests r=tanvi,r=ttaubert (03c079ede9) - Bug 1187151 (part 12) - Replace nsBaseHashtable::Enumerate() calls in dom/ with iterators. r=khuey. (0aa9356990) - Bug 1187151 (part 15) - Replace nsBaseHashtable::Enumerate() calls in dom/ with iterators. r=baku. (10e60a4b55) - Bug 1187151 (part 16) - Replace nsBaseHashtable::Enumerate() calls in dom/ with iterators. r=mccr8. (2ef1033aae) - Bug 1187151 (part 17) - Replace nsBaseHashtable::Enumerate() calls in dom/ with iterators. r=mccr8. (dc37dfc17b) - Bug 1241763: Don't fire dom-window-destroyed on outer windows. r=bz (ea30677af6) - Bug 1192128 - In DOM memory reporter, handle WindowID() being a uint64_t. r=mccr8. (b3f834b8f6) - Bug 1187151 (part 18) - Replace nsBaseHashtable::Enumerate() calls in dom/ with iterators. r=mccr8. (22d4fbe0f0) - Bug 1187138 (part 2) - Replace nsBaseHashtable::Enumerate() calls in toolkit/ with iterators. r=froydnj. (b4740ef44b) - Bug 1187138 (part 3) - Replace nsBaseHashtable::Enumerate() calls in toolkit/ with iterators. r=froydnj. (931eb9e813) - Bug 1187138 (part 4) - Replace nsBaseHashtable::Enumerate() calls in toolkit/ with iterators. r=froydnj. (a92fef3586) - Bug 1192189 - Fix assertion condition to use to-be-restyled element's composed document. r=dbaron (6c7733b7cc) - Bug 1187144 (part 10) - Replace nsBaseHashtable::Enumerate() calls in layout/ with iterators. r=heycam. (e93ad4330c) - Bug 1250525 - remove #IFDEF ENABLE_TESTS from dom/quota/ActorsParent.cpp. r=janv (22bc8fc0af) - Bug 1236632 - remove unused variable in FactoryOp::WaitForTransactions; r=janv (3c56b90fff) - Bug 1187116 (part 1) - Replace nsBaseHashtable::EnumerateRead() calls in dom/indexedDB/ with iterators. r=khuey. (f37ac71816) - Bug 1187116 (part 2) - Replace nsBaseHashtable::EnumerateRead() calls in dom/indexedDB/ with iterators. r=khuey. (6bf16c51fe) - Bug 1187116 (part 3) - Replace nsBaseHashtable::EnumerateRead() calls in dom/indexedDB/ with iterators. r=khuey. (351b7d5d34) - Bug 1187116 (part 4) - Replace nsBaseHashtable::EnumerateRead() calls in dom/indexedDB/ with iterators. r=khuey. (330678dde4) - Bug 1187116 (part 5) - Replace nsBaseHashtable::EnumerateRead() calls in dom/indexedDB/ with iterators. r=khuey. (43d20a7fa3) - Bug 1187116 (part 6) - Replace nsBaseHashtable::EnumerateRead() calls in dom/indexedDB/ with iterators. r=khuey. (d448d80726) - quick fix by revert of anticipated patch (00a093055d) - Bug 1186814 - Replace nsBaseHashtable::EnumerateRead() calls in extensions/spellcheck/ with iterators. r=ehsan. (ff78039ba0)
601 lines
16 KiB
C++
601 lines
16 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* 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/. */
|
|
|
|
#include "nsXULPrototypeCache.h"
|
|
|
|
#include "plstr.h"
|
|
#include "nsXULPrototypeDocument.h"
|
|
#include "nsIServiceManager.h"
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIChromeRegistry.h"
|
|
#include "nsIFile.h"
|
|
#include "nsIObjectInputStream.h"
|
|
#include "nsIObjectOutputStream.h"
|
|
#include "nsIObserverService.h"
|
|
#include "nsIStringStream.h"
|
|
#include "nsIStorageStream.h"
|
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
|
|
|
#include "js/TracingAPI.h"
|
|
|
|
#include "mozilla/CSSStyleSheet.h"
|
|
#include "mozilla/Preferences.h"
|
|
#include "mozilla/scache/StartupCache.h"
|
|
#include "mozilla/scache/StartupCacheUtils.h"
|
|
#include "mozilla/Telemetry.h"
|
|
|
|
using namespace mozilla;
|
|
using namespace mozilla::scache;
|
|
|
|
static bool gDisableXULCache = false; // enabled by default
|
|
static const char kDisableXULCachePref[] = "nglayout.debug.disable_xul_cache";
|
|
static const char kXULCacheInfoKey[] = "nsXULPrototypeCache.startupCache";
|
|
static const char kXULCachePrefix[] = "xulcache";
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
static void
|
|
UpdategDisableXULCache()
|
|
{
|
|
// Get the value of "nglayout.debug.disable_xul_cache" preference
|
|
gDisableXULCache =
|
|
Preferences::GetBool(kDisableXULCachePref, gDisableXULCache);
|
|
|
|
// Sets the flag if the XUL cache is disabled
|
|
if (gDisableXULCache) {
|
|
Telemetry::Accumulate(Telemetry::XUL_CACHE_DISABLED, true);
|
|
}
|
|
|
|
}
|
|
|
|
static void
|
|
DisableXULCacheChangedCallback(const char* aPref, void* aClosure)
|
|
{
|
|
bool wasEnabled = !gDisableXULCache;
|
|
UpdategDisableXULCache();
|
|
|
|
if (wasEnabled && gDisableXULCache) {
|
|
nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance();
|
|
if (cache) {
|
|
// AbortCaching() calls Flush() for us.
|
|
cache->AbortCaching();
|
|
}
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
nsXULPrototypeCache* nsXULPrototypeCache::sInstance = nullptr;
|
|
|
|
|
|
nsXULPrototypeCache::nsXULPrototypeCache()
|
|
{
|
|
}
|
|
|
|
|
|
nsXULPrototypeCache::~nsXULPrototypeCache()
|
|
{
|
|
FlushScripts();
|
|
}
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(nsXULPrototypeCache, nsIObserver)
|
|
|
|
/* static */ nsXULPrototypeCache*
|
|
nsXULPrototypeCache::GetInstance()
|
|
{
|
|
if (!sInstance) {
|
|
NS_ADDREF(sInstance = new nsXULPrototypeCache());
|
|
|
|
UpdategDisableXULCache();
|
|
|
|
Preferences::RegisterCallback(DisableXULCacheChangedCallback,
|
|
kDisableXULCachePref);
|
|
|
|
nsCOMPtr<nsIObserverService> obsSvc =
|
|
mozilla::services::GetObserverService();
|
|
if (obsSvc) {
|
|
nsXULPrototypeCache *p = sInstance;
|
|
obsSvc->AddObserver(p, "chrome-flush-skin-caches", false);
|
|
obsSvc->AddObserver(p, "chrome-flush-caches", false);
|
|
obsSvc->AddObserver(p, "startupcache-invalidate", false);
|
|
}
|
|
|
|
}
|
|
return sInstance;
|
|
}
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
|
nsXULPrototypeCache::Observe(nsISupports* aSubject,
|
|
const char *aTopic,
|
|
const char16_t *aData)
|
|
{
|
|
if (!strcmp(aTopic, "chrome-flush-skin-caches")) {
|
|
FlushSkinFiles();
|
|
}
|
|
else if (!strcmp(aTopic, "chrome-flush-caches")) {
|
|
Flush();
|
|
}
|
|
else if (!strcmp(aTopic, "startupcache-invalidate")) {
|
|
AbortCaching();
|
|
}
|
|
else {
|
|
NS_WARNING("Unexpected observer topic.");
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
nsXULPrototypeDocument*
|
|
nsXULPrototypeCache::GetPrototype(nsIURI* aURI)
|
|
{
|
|
if (!aURI)
|
|
return nullptr;
|
|
|
|
nsCOMPtr<nsIURI> uriWithoutRef;
|
|
aURI->CloneIgnoringRef(getter_AddRefs(uriWithoutRef));
|
|
|
|
nsXULPrototypeDocument* protoDoc = mPrototypeTable.GetWeak(uriWithoutRef);
|
|
if (protoDoc)
|
|
return protoDoc;
|
|
|
|
nsresult rv = BeginCaching(aURI);
|
|
if (NS_FAILED(rv))
|
|
return nullptr;
|
|
|
|
// No prototype in XUL memory cache. Spin up the cache Service.
|
|
nsCOMPtr<nsIObjectInputStream> ois;
|
|
rv = GetInputStream(aURI, getter_AddRefs(ois));
|
|
if (NS_FAILED(rv))
|
|
return nullptr;
|
|
|
|
RefPtr<nsXULPrototypeDocument> newProto;
|
|
rv = NS_NewXULPrototypeDocument(getter_AddRefs(newProto));
|
|
if (NS_FAILED(rv))
|
|
return nullptr;
|
|
|
|
rv = newProto->Read(ois);
|
|
if (NS_SUCCEEDED(rv)) {
|
|
rv = PutPrototype(newProto);
|
|
} else {
|
|
newProto = nullptr;
|
|
}
|
|
|
|
mInputStreamTable.Remove(aURI);
|
|
return newProto;
|
|
}
|
|
|
|
nsresult
|
|
nsXULPrototypeCache::PutPrototype(nsXULPrototypeDocument* aDocument)
|
|
{
|
|
if (!aDocument->GetURI()) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
aDocument->GetURI()->CloneIgnoringRef(getter_AddRefs(uri));
|
|
|
|
// Put() releases any old value and addrefs the new one
|
|
mPrototypeTable.Put(uri, aDocument);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
nsXULPrototypeCache::PutStyleSheet(CSSStyleSheet* aStyleSheet)
|
|
{
|
|
nsIURI* uri = aStyleSheet->GetSheetURI();
|
|
|
|
mStyleSheetTable.Put(uri, aStyleSheet);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
|
|
JSScript*
|
|
nsXULPrototypeCache::GetScript(nsIURI* aURI)
|
|
{
|
|
return mScriptTable.Get(aURI);
|
|
}
|
|
|
|
nsresult
|
|
nsXULPrototypeCache::PutScript(nsIURI* aURI,
|
|
JS::Handle<JSScript*> aScriptObject)
|
|
{
|
|
MOZ_ASSERT(aScriptObject, "Need a non-NULL script");
|
|
|
|
#ifdef DEBUG
|
|
if (mScriptTable.Get(aURI)) {
|
|
nsAutoCString scriptName;
|
|
aURI->GetSpec(scriptName);
|
|
nsAutoCString message("Loaded script ");
|
|
message += scriptName;
|
|
message += " twice (bug 392650)";
|
|
NS_WARNING(message.get());
|
|
}
|
|
#endif
|
|
|
|
mScriptTable.Put(aURI, aScriptObject);
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
nsXULPrototypeCache::PutXBLDocumentInfo(nsXBLDocumentInfo* aDocumentInfo)
|
|
{
|
|
nsIURI* uri = aDocumentInfo->DocumentURI();
|
|
|
|
RefPtr<nsXBLDocumentInfo> info;
|
|
mXBLDocTable.Get(uri, getter_AddRefs(info));
|
|
if (!info) {
|
|
mXBLDocTable.Put(uri, aDocumentInfo);
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
nsXULPrototypeCache::FlushSkinFiles()
|
|
{
|
|
// Flush out skin XBL files from the cache.
|
|
for (auto iter = mXBLDocTable.Iter(); !iter.Done(); iter.Next()) {
|
|
nsAutoCString str;
|
|
iter.Key()->GetPath(str);
|
|
if (strncmp(str.get(), "/skin", 5) == 0) {
|
|
iter.Remove();
|
|
}
|
|
}
|
|
|
|
// Now flush out our skin stylesheets from the cache.
|
|
for (auto iter = mStyleSheetTable.Iter(); !iter.Done(); iter.Next()) {
|
|
nsAutoCString str;
|
|
iter.Data()->GetSheetURI()->GetPath(str);
|
|
if (strncmp(str.get(), "/skin", 5) == 0) {
|
|
iter.Remove();
|
|
}
|
|
}
|
|
|
|
// Iterate over all the remaining XBL and make sure cached
|
|
// scoped skin stylesheets are flushed and refetched by the
|
|
// prototype bindings.
|
|
for (auto iter = mXBLDocTable.Iter(); !iter.Done(); iter.Next()) {
|
|
iter.Data()->FlushSkinStylesheets();
|
|
}
|
|
}
|
|
|
|
void
|
|
nsXULPrototypeCache::FlushScripts()
|
|
{
|
|
mScriptTable.Clear();
|
|
}
|
|
|
|
void
|
|
nsXULPrototypeCache::Flush()
|
|
{
|
|
mPrototypeTable.Clear();
|
|
mScriptTable.Clear();
|
|
mStyleSheetTable.Clear();
|
|
mXBLDocTable.Clear();
|
|
}
|
|
|
|
|
|
bool
|
|
nsXULPrototypeCache::IsEnabled()
|
|
{
|
|
return !gDisableXULCache;
|
|
}
|
|
|
|
void
|
|
nsXULPrototypeCache::AbortCaching()
|
|
{
|
|
#ifdef DEBUG_brendan
|
|
NS_BREAK();
|
|
#endif
|
|
|
|
// Flush the XUL cache for good measure, in case we cached a bogus/downrev
|
|
// script, somehow.
|
|
Flush();
|
|
|
|
// Clear the cache set
|
|
mStartupCacheURITable.Clear();
|
|
}
|
|
|
|
|
|
nsresult
|
|
nsXULPrototypeCache::WritePrototype(nsXULPrototypeDocument* aPrototypeDocument)
|
|
{
|
|
nsresult rv = NS_OK, rv2 = NS_OK;
|
|
|
|
if (!StartupCache::GetSingleton())
|
|
return NS_OK;
|
|
|
|
nsCOMPtr<nsIURI> protoURI = aPrototypeDocument->GetURI();
|
|
|
|
nsCOMPtr<nsIObjectOutputStream> oos;
|
|
rv = GetOutputStream(protoURI, getter_AddRefs(oos));
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
rv = aPrototypeDocument->Write(oos);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
FinishOutputStream(protoURI);
|
|
return NS_FAILED(rv) ? rv : rv2;
|
|
}
|
|
|
|
nsresult
|
|
nsXULPrototypeCache::GetInputStream(nsIURI* uri, nsIObjectInputStream** stream)
|
|
{
|
|
nsAutoCString spec(kXULCachePrefix);
|
|
nsresult rv = PathifyURI(uri, spec);
|
|
if (NS_FAILED(rv))
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
nsAutoArrayPtr<char> buf;
|
|
uint32_t len;
|
|
nsCOMPtr<nsIObjectInputStream> ois;
|
|
StartupCache* sc = StartupCache::GetSingleton();
|
|
if (!sc)
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
rv = sc->GetBuffer(spec.get(), getter_Transfers(buf), &len);
|
|
if (NS_FAILED(rv))
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
rv = NewObjectInputStreamFromBuffer(buf, len, getter_AddRefs(ois));
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
buf.forget();
|
|
|
|
mInputStreamTable.Put(uri, ois);
|
|
|
|
ois.forget(stream);
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
nsXULPrototypeCache::FinishInputStream(nsIURI* uri) {
|
|
mInputStreamTable.Remove(uri);
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
nsXULPrototypeCache::GetOutputStream(nsIURI* uri, nsIObjectOutputStream** stream)
|
|
{
|
|
nsresult rv;
|
|
nsCOMPtr<nsIObjectOutputStream> objectOutput;
|
|
nsCOMPtr<nsIStorageStream> storageStream;
|
|
bool found = mOutputStreamTable.Get(uri, getter_AddRefs(storageStream));
|
|
if (found) {
|
|
objectOutput = do_CreateInstance("mozilla.org/binaryoutputstream;1");
|
|
if (!objectOutput) return NS_ERROR_OUT_OF_MEMORY;
|
|
nsCOMPtr<nsIOutputStream> outputStream
|
|
= do_QueryInterface(storageStream);
|
|
objectOutput->SetOutputStream(outputStream);
|
|
} else {
|
|
rv = NewObjectOutputWrappedStorageStream(getter_AddRefs(objectOutput),
|
|
getter_AddRefs(storageStream),
|
|
false);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
mOutputStreamTable.Put(uri, storageStream);
|
|
}
|
|
objectOutput.forget(stream);
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
nsXULPrototypeCache::FinishOutputStream(nsIURI* uri)
|
|
{
|
|
nsresult rv;
|
|
StartupCache* sc = StartupCache::GetSingleton();
|
|
if (!sc)
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
nsCOMPtr<nsIStorageStream> storageStream;
|
|
bool found = mOutputStreamTable.Get(uri, getter_AddRefs(storageStream));
|
|
if (!found)
|
|
return NS_ERROR_UNEXPECTED;
|
|
nsCOMPtr<nsIOutputStream> outputStream
|
|
= do_QueryInterface(storageStream);
|
|
outputStream->Close();
|
|
|
|
nsAutoArrayPtr<char> buf;
|
|
uint32_t len;
|
|
rv = NewBufferFromStorageStream(storageStream, getter_Transfers(buf),
|
|
&len);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
if (!mStartupCacheURITable.GetEntry(uri)) {
|
|
nsAutoCString spec(kXULCachePrefix);
|
|
rv = PathifyURI(uri, spec);
|
|
if (NS_FAILED(rv))
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
rv = sc->PutBuffer(spec.get(), buf, len);
|
|
if (NS_SUCCEEDED(rv)) {
|
|
mOutputStreamTable.Remove(uri);
|
|
mStartupCacheURITable.PutEntry(uri);
|
|
}
|
|
}
|
|
|
|
return rv;
|
|
}
|
|
|
|
// We have data if we're in the middle of writing it or we already
|
|
// have it in the cache.
|
|
nsresult
|
|
nsXULPrototypeCache::HasData(nsIURI* uri, bool* exists)
|
|
{
|
|
if (mOutputStreamTable.Get(uri, nullptr)) {
|
|
*exists = true;
|
|
return NS_OK;
|
|
}
|
|
nsAutoCString spec(kXULCachePrefix);
|
|
nsresult rv = PathifyURI(uri, spec);
|
|
if (NS_FAILED(rv)) {
|
|
*exists = false;
|
|
return NS_OK;
|
|
}
|
|
nsAutoArrayPtr<char> buf;
|
|
uint32_t len;
|
|
StartupCache* sc = StartupCache::GetSingleton();
|
|
if (sc)
|
|
rv = sc->GetBuffer(spec.get(), getter_Transfers(buf), &len);
|
|
else {
|
|
*exists = false;
|
|
return NS_OK;
|
|
}
|
|
*exists = NS_SUCCEEDED(rv);
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult
|
|
nsXULPrototypeCache::BeginCaching(nsIURI* aURI)
|
|
{
|
|
nsresult rv, tmp;
|
|
|
|
nsAutoCString path;
|
|
aURI->GetPath(path);
|
|
if (!StringEndsWith(path, NS_LITERAL_CSTRING(".xul")))
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
StartupCache* startupCache = StartupCache::GetSingleton();
|
|
if (!startupCache)
|
|
return NS_ERROR_FAILURE;
|
|
|
|
if (gDisableXULCache)
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
// Get the chrome directory to validate against the one stored in the
|
|
// cache file, or to store there if we're generating a new file.
|
|
nsCOMPtr<nsIFile> chromeDir;
|
|
rv = NS_GetSpecialDirectory(NS_APP_CHROME_DIR, getter_AddRefs(chromeDir));
|
|
if (NS_FAILED(rv))
|
|
return rv;
|
|
nsAutoCString chromePath;
|
|
rv = chromeDir->GetNativePath(chromePath);
|
|
if (NS_FAILED(rv))
|
|
return rv;
|
|
|
|
// XXXbe we assume the first package's locale is the same as the locale of
|
|
// all subsequent packages of cached chrome URIs....
|
|
nsAutoCString package;
|
|
rv = aURI->GetHost(package);
|
|
if (NS_FAILED(rv))
|
|
return rv;
|
|
nsCOMPtr<nsIXULChromeRegistry> chromeReg
|
|
= do_GetService(NS_CHROMEREGISTRY_CONTRACTID, &rv);
|
|
nsAutoCString locale;
|
|
rv = chromeReg->GetSelectedLocale(package, locale);
|
|
if (NS_FAILED(rv))
|
|
return rv;
|
|
|
|
nsAutoCString fileChromePath, fileLocale;
|
|
|
|
nsAutoArrayPtr<char> buf;
|
|
uint32_t len, amtRead;
|
|
nsCOMPtr<nsIObjectInputStream> objectInput;
|
|
|
|
rv = startupCache->GetBuffer(kXULCacheInfoKey, getter_Transfers(buf),
|
|
&len);
|
|
if (NS_SUCCEEDED(rv))
|
|
rv = NewObjectInputStreamFromBuffer(buf, len, getter_AddRefs(objectInput));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
buf.forget();
|
|
rv = objectInput->ReadCString(fileLocale);
|
|
tmp = objectInput->ReadCString(fileChromePath);
|
|
if (NS_FAILED(tmp)) {
|
|
rv = tmp;
|
|
}
|
|
if (NS_FAILED(rv) ||
|
|
(!fileChromePath.Equals(chromePath) ||
|
|
!fileLocale.Equals(locale))) {
|
|
// Our cache won't be valid in this case, we'll need to rewrite.
|
|
// XXX This blows away work that other consumers (like
|
|
// mozJSComponentLoader) have done, need more fine-grained control.
|
|
startupCache->InvalidateCache();
|
|
mStartupCacheURITable.Clear();
|
|
rv = NS_ERROR_UNEXPECTED;
|
|
}
|
|
} else if (rv != NS_ERROR_NOT_AVAILABLE)
|
|
// NS_ERROR_NOT_AVAILABLE is normal, usually if there's no cachefile.
|
|
return rv;
|
|
|
|
if (NS_FAILED(rv)) {
|
|
// Either the cache entry was invalid or it didn't exist, so write it now.
|
|
nsCOMPtr<nsIObjectOutputStream> objectOutput;
|
|
nsCOMPtr<nsIInputStream> inputStream;
|
|
nsCOMPtr<nsIStorageStream> storageStream;
|
|
rv = NewObjectOutputWrappedStorageStream(getter_AddRefs(objectOutput),
|
|
getter_AddRefs(storageStream),
|
|
false);
|
|
if (NS_SUCCEEDED(rv)) {
|
|
rv = objectOutput->WriteStringZ(locale.get());
|
|
tmp = objectOutput->WriteStringZ(chromePath.get());
|
|
if (NS_FAILED(tmp)) {
|
|
rv = tmp;
|
|
}
|
|
tmp = objectOutput->Close();
|
|
if (NS_FAILED(tmp)) {
|
|
rv = tmp;
|
|
}
|
|
tmp = storageStream->NewInputStream(0, getter_AddRefs(inputStream));
|
|
if (NS_FAILED(tmp)) {
|
|
rv = tmp;
|
|
}
|
|
}
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
uint64_t len64;
|
|
rv = inputStream->Available(&len64);
|
|
if (NS_SUCCEEDED(rv)) {
|
|
if (len64 <= UINT32_MAX)
|
|
len = (uint32_t)len64;
|
|
else
|
|
rv = NS_ERROR_FILE_TOO_BIG;
|
|
}
|
|
}
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
buf = new char[len];
|
|
rv = inputStream->Read(buf, len, &amtRead);
|
|
if (NS_SUCCEEDED(rv) && len == amtRead)
|
|
rv = startupCache->PutBuffer(kXULCacheInfoKey, buf, len);
|
|
else {
|
|
rv = NS_ERROR_UNEXPECTED;
|
|
}
|
|
}
|
|
|
|
// Failed again, just bail.
|
|
if (NS_FAILED(rv)) {
|
|
startupCache->InvalidateCache();
|
|
mStartupCacheURITable.Clear();
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
nsXULPrototypeCache::MarkInCCGeneration(uint32_t aGeneration)
|
|
{
|
|
for (auto iter = mXBLDocTable.Iter(); !iter.Done(); iter.Next()) {
|
|
iter.Data()->MarkInCCGeneration(aGeneration);
|
|
}
|
|
for (auto iter = mPrototypeTable.Iter(); !iter.Done(); iter.Next()) {
|
|
iter.Data()->MarkInCCGeneration(aGeneration);
|
|
}
|
|
}
|
|
|
|
void
|
|
nsXULPrototypeCache::MarkInGC(JSTracer* aTrc)
|
|
{
|
|
for (auto iter = mScriptTable.Iter(); !iter.Done(); iter.Next()) {
|
|
JS::Heap<JSScript*>& script = iter.Data();
|
|
JS::TraceEdge(aTrc, &script, "nsXULPrototypeCache script");
|
|
}
|
|
}
|