Bug 587222 - Script caching in messageManager leaks. r=olli

This commit is contained in:
Alon Zakai 2010-08-16 13:05:42 -07:00
Родитель ceb3714398
Коммит d96af314f5
2 изменённых файлов: 34 добавлений и 0 удалений

Просмотреть файл

@ -510,6 +510,7 @@ NS_NewGlobalMessageManager(nsIChromeFrameMessageManager** aResult)
nsDataHashtable<nsStringHashKey, nsFrameScriptExecutorJSObjectHolder*>*
nsFrameScriptExecutor::sCachedScripts = nsnull;
nsRefPtr<nsScriptCacheCleaner> nsFrameScriptExecutor::sScriptCacheCleaner;
void
nsFrameScriptExecutor::DidCreateCx()
@ -519,6 +520,8 @@ nsFrameScriptExecutor::DidCreateCx()
sCachedScripts =
new nsDataHashtable<nsStringHashKey, nsFrameScriptExecutorJSObjectHolder*>;
sCachedScripts->Init();
sScriptCacheCleaner = new nsScriptCacheCleaner();
}
}
@ -564,6 +567,8 @@ nsFrameScriptExecutor::Shutdown()
delete sCachedScripts;
sCachedScripts = nsnull;
sScriptCacheCleaner = nsnull;
}
}
@ -672,3 +677,6 @@ nsFrameScriptExecutor::LoadFrameScriptInternal(const nsAString& aURL)
nsContentUtils::ThreadJSContextStack()->Pop(&unused);
}
}
NS_IMPL_ISUPPORTS1(nsScriptCacheCleaner, nsIObserver);

Просмотреть файл

@ -38,6 +38,7 @@
#define nsFrameMessageManager_h__
#include "nsIFrameMessageManager.h"
#include "nsIObserver.h"
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
#include "nsCOMArray.h"
@ -48,6 +49,8 @@
#include "nsIPrincipal.h"
#include "nsIXPConnect.h"
#include "nsDataHashtable.h"
#include "mozilla/Services.h"
#include "nsIObserverService.h"
class nsAXPCNativeCallContext;
struct JSContext;
@ -153,6 +156,8 @@ protected:
nsTArray<nsString> mPendingScripts;
};
class nsScriptCacheCleaner;
struct nsFrameScriptExecutorJSObjectHolder
{
nsFrameScriptExecutorJSObjectHolder(JSObject* aObject) : mObject(aObject) {}
@ -173,6 +178,27 @@ protected:
JSContext* mCx;
nsCOMPtr<nsIPrincipal> mPrincipal;
static nsDataHashtable<nsStringHashKey, nsFrameScriptExecutorJSObjectHolder*>* sCachedScripts;
static nsRefPtr<nsScriptCacheCleaner> sScriptCacheCleaner;
};
class nsScriptCacheCleaner : public nsIObserver
{
NS_DECL_ISUPPORTS
nsScriptCacheCleaner()
{
nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService();
if (obsSvc)
obsSvc->AddObserver(this, "xpcom-shutdown", PR_FALSE);
}
NS_IMETHODIMP Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *aData)
{
nsFrameScriptExecutor::Shutdown();
return NS_OK;
}
};
#endif