diff --git a/content/xul/templates/src/nsXULTemplateBuilder.cpp b/content/xul/templates/src/nsXULTemplateBuilder.cpp index 64ef9527528..2a350c97397 100644 --- a/content/xul/templates/src/nsXULTemplateBuilder.cpp +++ b/content/xul/templates/src/nsXULTemplateBuilder.cpp @@ -1139,13 +1139,8 @@ nsXULTemplateBuilder::AttributeChanged(nsIDocument* aDocument, // Check for a change to the 'datasources' attribute. If so, setup // mDB by parsing the new value and rebuild. else if (aAttribute == nsGkAtoms::datasources) { - Uninit(PR_FALSE); // Reset results - - PRBool shouldDelay; - LoadDataSources(aDocument, &shouldDelay); - if (!shouldDelay) - nsContentUtils::AddScriptRunner( - NS_NewRunnableMethod(this, &nsXULTemplateBuilder::RunnableRebuild)); + nsContentUtils::AddScriptRunner( + NS_NewRunnableMethod(this, &nsXULTemplateBuilder::RunnableLoadAndRebuild)); } } } @@ -1163,8 +1158,9 @@ nsXULTemplateBuilder::ContentRemoved(nsIDocument* aDocument, if (mQueryProcessor) mQueryProcessor->Done(); - // use false since content is going away anyway - Uninit(PR_FALSE); + // Pass false to Uninit since content is going away anyway + nsContentUtils::AddScriptRunner( + NS_NewRunnableMethod(this, &nsXULTemplateBuilder::UninitFalse)); aDocument->RemoveObserver(this); @@ -1201,7 +1197,8 @@ nsXULTemplateBuilder::NodeWillBeDestroyed(const nsINode* aNode) mCompDB = nsnull; mRoot = nsnull; - Uninit(PR_TRUE); + nsContentUtils::AddScriptRunner( + NS_NewRunnableMethod(this, &nsXULTemplateBuilder::UninitTrue)); } diff --git a/content/xul/templates/src/nsXULTemplateBuilder.h b/content/xul/templates/src/nsXULTemplateBuilder.h index 627f47d44d3..4eeca920429 100644 --- a/content/xul/templates/src/nsXULTemplateBuilder.h +++ b/content/xul/templates/src/nsXULTemplateBuilder.h @@ -152,6 +152,20 @@ public: RebuildAll() = 0; // must be implemented by subclasses void RunnableRebuild() { Rebuild(); } + void RunnableLoadAndRebuild() { + Uninit(PR_FALSE); // Reset results + + nsCOMPtr doc = mRoot ? mRoot->GetDocument() : nsnull; + if (doc) { + PRBool shouldDelay; + LoadDataSources(doc, &shouldDelay); + if (!shouldDelay) { + Rebuild(); + } + } + } + void UninitFalse() { Uninit(PR_FALSE); } + void UninitTrue() { Uninit(PR_TRUE); } /** * Find the