Bug 965860 - patch 5 - Console inner-window-destroyed observer, r=khuey

This commit is contained in:
Andrea Marchesini 2014-02-27 23:39:17 +00:00
Родитель edecafae28
Коммит 8a87e5bfed
3 изменённых файлов: 51 добавлений и 3 удалений

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

@ -133,7 +133,8 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(Console)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Console)
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
NS_INTERFACE_MAP_ENTRY(nsITimerCallback)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY(nsIObserver)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsITimerCallback)
NS_INTERFACE_MAP_END
Console::Console(nsPIDOMWindow* aWindow)
@ -150,6 +151,13 @@ Console::Console(nsPIDOMWindow* aWindow)
mOuterID = outerWindow->WindowID();
}
if (NS_IsMainThread()) {
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (obs) {
obs->AddObserver(this, "inner-window-destroyed", false);
}
}
SetIsDOMBinding();
mozilla::HoldJSObjects(this);
}
@ -159,6 +167,42 @@ Console::~Console()
mozilla::DropJSObjects(this);
}
NS_IMETHODIMP
Console::Observe(nsISupports* aSubject, const char* aTopic,
const char16_t* aData)
{
MOZ_ASSERT(NS_IsMainThread());
if (strcmp(aTopic, "inner-window-destroyed")) {
return NS_OK;
}
nsCOMPtr<nsISupportsPRUint64> wrapper = do_QueryInterface(aSubject);
NS_ENSURE_TRUE(wrapper, NS_ERROR_FAILURE);
uint64_t innerID;
nsresult rv = wrapper->GetData(&innerID);
NS_ENSURE_SUCCESS(rv, rv);
if (innerID == mInnerID) {
nsCOMPtr<nsIObserverService> obs =
do_GetService("@mozilla.org/observer-service;1");
if (obs) {
obs->RemoveObserver(this, "inner-window-destroyed");
}
mQueuedCalls.Clear();
mTimerRegistry.Clear();
if (mTimer) {
mTimer->Cancel();
mTimer = nullptr;
}
}
return NS_OK;
}
JSObject*
Console::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
{

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

@ -12,6 +12,7 @@
#include "nsCycleCollectionParticipant.h"
#include "nsDataHashtable.h"
#include "nsHashKeys.h"
#include "nsIObserver.h"
#include "nsITimer.h"
#include "nsWrapperCache.h"
@ -23,12 +24,15 @@ namespace dom {
class ConsoleCallData;
class Console MOZ_FINAL : public nsITimerCallback
, public nsIObserver
, public nsWrapperCache
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Console)
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Console,
nsITimerCallback)
NS_DECL_NSITIMERCALLBACK
NS_DECL_NSIOBSERVER
Console(nsPIDOMWindow* aWindow);
~Console();

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

@ -62,7 +62,7 @@ ConsoleAPIStorageService.prototype = {
}
else if (aTopic == "inner-window-destroyed") {
let innerWindowID = aSubject.QueryInterface(Ci.nsISupportsPRUint64).data;
this.clearEvents(innerWindowID);
this.clearEvents(innerWindowID + "");
}
else if (aTopic == "memory-pressure") {
this.clearEvents();