mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-04 02:57:38 +00:00
Bug 940426 - part 1 - properly stop observing all the sources in nsXULTemplateBuilder; r=bz
This commit is contained in:
parent
72d3b87910
commit
3441f8f6d6
@ -171,6 +171,25 @@ nsXULTemplateBuilder::InitGlobals()
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsXULTemplateBuilder::StartObserving(nsIDocument* aDocument)
|
||||
{
|
||||
aDocument->AddObserver(this);
|
||||
mObservedDocument = aDocument;
|
||||
gObserverService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, false);
|
||||
gObserverService->AddObserver(this, DOM_WINDOW_DESTROYED_TOPIC, false);
|
||||
}
|
||||
|
||||
void
|
||||
nsXULTemplateBuilder::StopObserving()
|
||||
{
|
||||
MOZ_ASSERT(mObservedDocument);
|
||||
mObservedDocument->RemoveObserver(this);
|
||||
mObservedDocument = nullptr;
|
||||
gObserverService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
|
||||
gObserverService->RemoveObserver(this, DOM_WINDOW_DESTROYED_TOPIC);
|
||||
}
|
||||
|
||||
void
|
||||
nsXULTemplateBuilder::CleanUp(bool aIsFinal)
|
||||
{
|
||||
@ -193,10 +212,7 @@ void
|
||||
nsXULTemplateBuilder::Uninit(bool aIsFinal)
|
||||
{
|
||||
if (mObservedDocument && aIsFinal) {
|
||||
gObserverService->RemoveObserver(this, DOM_WINDOW_DESTROYED_TOPIC);
|
||||
gObserverService->RemoveObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID);
|
||||
mObservedDocument->RemoveObserver(this);
|
||||
mObservedDocument = nullptr;
|
||||
StopObserving();
|
||||
}
|
||||
|
||||
if (mQueryProcessor)
|
||||
@ -428,14 +444,7 @@ nsXULTemplateBuilder::Init(nsIContent* aElement)
|
||||
nsresult rv = LoadDataSources(doc, &shouldDelay);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// Add ourselves as a document observer
|
||||
doc->AddObserver(this);
|
||||
|
||||
mObservedDocument = doc;
|
||||
gObserverService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID,
|
||||
false);
|
||||
gObserverService->AddObserver(this, DOM_WINDOW_DESTROYED_TOPIC,
|
||||
false);
|
||||
StartObserving(doc);
|
||||
}
|
||||
|
||||
return rv;
|
||||
@ -1124,7 +1133,8 @@ nsXULTemplateBuilder::ContentRemoved(nsIDocument* aDocument,
|
||||
nsContentUtils::AddScriptRunner(
|
||||
NS_NewRunnableMethod(this, &nsXULTemplateBuilder::UninitFalse));
|
||||
|
||||
aDocument->RemoveObserver(this);
|
||||
MOZ_ASSERT(aDocument == mObservedDocument);
|
||||
StopObserving();
|
||||
|
||||
nsCOMPtr<nsIXULDocument> xuldoc = do_QueryInterface(aDocument);
|
||||
if (xuldoc)
|
||||
|
@ -480,6 +480,20 @@ protected:
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Start observing events from the observer service and the given
|
||||
* document.
|
||||
*
|
||||
* @param aDocument the document to observe
|
||||
*/
|
||||
void StartObserving(nsIDocument* aDocument);
|
||||
|
||||
/**
|
||||
* Stop observing events from the observer service and any associated
|
||||
* document.
|
||||
*/
|
||||
void StopObserving();
|
||||
|
||||
/**
|
||||
* Document that we're observing. Weak ref!
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user