diff --git a/accessible/src/base/nsDocAccessible.cpp b/accessible/src/base/nsDocAccessible.cpp index 88d39d91ba66..a3c892adc475 100644 --- a/accessible/src/base/nsDocAccessible.cpp +++ b/accessible/src/base/nsDocAccessible.cpp @@ -569,11 +569,29 @@ void nsDocAccessible::RemoveContentDocListeners() target->RemoveEventListener(NS_LITERAL_STRING("DOMNodeInsertedIntoDocument"), this, PR_TRUE); target->RemoveEventListener(NS_LITERAL_STRING("DOMNodeRemovedFromDocument"), this, PR_TRUE); + if (mScrollWatchTimer) { + mScrollWatchTimer->Cancel(); + mScrollWatchTimer = nsnull; + } + + if (mDocLoadTimer) { + mDocLoadTimer->Cancel(); + mDocLoadTimer = nsnull; + } + nsCOMPtr container; mDocument->GetContainer(getter_AddRefs(container)); - nsCOMPtr commandManager = do_GetInterface(container); - if (commandManager) { - commandManager->RemoveCommandObserver(this, "obs_documentCreated"); + nsCOMPtr docShellTreeItem(do_QueryInterface(container)); + if (!docShellTreeItem) + return; + + PRInt32 itemType; + docShellTreeItem->GetItemType(&itemType); + if (itemType == nsIDocShellTreeItem::typeContent) { + nsCOMPtr commandManager = do_GetInterface(container); + if (commandManager) { + commandManager->RemoveCommandObserver(this, "obs_documentCreated"); + } } } diff --git a/accessible/src/base/nsRootAccessible.cpp b/accessible/src/base/nsRootAccessible.cpp index 323a68358272..98b27a190f36 100644 --- a/accessible/src/base/nsRootAccessible.cpp +++ b/accessible/src/base/nsRootAccessible.cpp @@ -203,16 +203,6 @@ NS_IMETHODIMP nsRootAccessible::RemoveEventListeners() target->RemoveEventListener(NS_LITERAL_STRING("ListitemStateChange"), NS_STATIC_CAST(nsIDOMXULListener*, this), PR_TRUE); } - if (mScrollWatchTimer) { - mScrollWatchTimer->Cancel(); - mScrollWatchTimer = nsnull; - } - - if (mDocLoadTimer) { - mDocLoadTimer->Cancel(); - mDocLoadTimer = nsnull; - } - RemoveContentDocListeners(); if (mCaretAccessible) {