diff --git a/mozilla/content/base/public/nsIDocument.h b/mozilla/content/base/public/nsIDocument.h index 7db0a78ed96..271be432519 100644 --- a/mozilla/content/base/public/nsIDocument.h +++ b/mozilla/content/base/public/nsIDocument.h @@ -613,7 +613,7 @@ public: virtual void AddReference(void *aKey, nsISupports *aReference) = 0; virtual nsISupports *GetReference(void *aKey) = 0; - virtual already_AddRefed RemoveReference(void *aKey) = 0; + virtual void RemoveReference(void *aKey) = 0; /** * Set the container (docshell) for this document. diff --git a/mozilla/content/base/src/nsContentUtils.cpp b/mozilla/content/base/src/nsContentUtils.cpp index 85511b0718a..fee7dd0915a 100644 --- a/mozilla/content/base/src/nsContentUtils.cpp +++ b/mozilla/content/base/src/nsContentUtils.cpp @@ -719,11 +719,10 @@ nsContentUtils::doReparentContentWrapper(nsIContent *aNode, NS_ENSURE_SUCCESS(rv, rv); if (aOldDocument) { - nsCOMPtr old_ref = aOldDocument->RemoveReference(aNode); - + nsCOMPtr old_ref = aOldDocument->GetReference(aNode); if (old_ref) { // Transfer the reference from aOldDocument to aNewDocument - + aOldDocument->RemoveReference(aNode); aNewDocument->AddReference(aNode, old_ref); } } diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 4a555e22a38..c707231dcb8 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -4866,17 +4866,12 @@ nsDocument::GetReference(void *aKey) return nsnull; } -already_AddRefed +void nsDocument::RemoveReference(void *aKey) { - nsISupports* oldReference = nsnull; - if (mContentWrapperHash) { - mContentWrapperHash->Get(aKey, &oldReference); mContentWrapperHash->Remove(aKey); } - - return oldReference; } nsIScriptEventManager* diff --git a/mozilla/content/base/src/nsDocument.h b/mozilla/content/base/src/nsDocument.h index 65bbd26fd85..ba50ae3d6aa 100644 --- a/mozilla/content/base/src/nsDocument.h +++ b/mozilla/content/base/src/nsDocument.h @@ -497,7 +497,7 @@ public: virtual void FlushPendingNotifications(mozFlushType aType); virtual void AddReference(void *aKey, nsISupports *aReference); virtual nsISupports *GetReference(void *aKey); - virtual already_AddRefed RemoveReference(void *aKey); + virtual void RemoveReference(void *aKey); virtual nsIScriptEventManager* GetScriptEventManager(); virtual void SetXMLDeclaration(const PRUnichar *aVersion, const PRUnichar *aEncoding, diff --git a/mozilla/content/base/src/nsNodeUtils.cpp b/mozilla/content/base/src/nsNodeUtils.cpp index 5249e82ba3f..82e8b8ce84f 100755 --- a/mozilla/content/base/src/nsNodeUtils.cpp +++ b/mozilla/content/base/src/nsNodeUtils.cpp @@ -432,15 +432,30 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep, } } else if (nodeInfoManager) { + nsCOMPtr oldRef; + nsIDocument* oldDoc = aNode->GetOwnerDoc(); + if (oldDoc) { + oldRef = oldDoc->GetReference(aNode); + if (oldRef) { + oldDoc->RemoveReference(aNode); + } + } + aNode->mNodeInfo.swap(newNodeInfo); nsIDocument* newDoc = aNode->GetOwnerDoc(); - nsPIDOMWindow* window = newDoc ? newDoc->GetInnerWindow() : nsnull; - if (window) { - nsCOMPtr elm; - aNode->GetListenerManager(PR_FALSE, getter_AddRefs(elm)); - if (elm) { - window->SetMutationListeners(elm->MutationListenerBits()); + if (newDoc) { + if (oldRef) { + newDoc->AddReference(aNode, oldRef); + } + + nsPIDOMWindow* window = newDoc->GetInnerWindow(); + if (window) { + nsCOMPtr elm; + aNode->GetListenerManager(PR_FALSE, getter_AddRefs(elm)); + if (elm) { + window->SetMutationListeners(elm->MutationListenerBits()); + } } } diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index 26a976387ef..edcd65b42ac 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -779,11 +779,12 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsGlobalWindow) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mListenerManager) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mSessionStorage) NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDocumentPrincipal) - NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDoc) // Unlink any associated preserved wrapper. - if (tmp->mDoc) + if (tmp->mDoc) { tmp->mDoc->RemoveReference(tmp->mDoc.get()); + NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mDoc) + } // Unlink stuff from nsPIDOMWindow NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mChromeEventHandler)