From 5b97511c945d895099ce96153d6a37cabac354af Mon Sep 17 00:00:00 2001 From: Chris Pearce Date: Thu, 19 Feb 2009 20:52:54 +1300 Subject: [PATCH] Bug 432114. Change style sheet owner to the document being edited. r+sr=peterv --HG-- extra : rebase_source : 1477b54a36bdb3c8d1f4f44801890707043b49ee --- docshell/base/crashtests/432114-1.html | 8 ++++++++ docshell/base/crashtests/432114-2.html | 9 +++++++++ docshell/base/crashtests/crashtests.list | 2 ++ docshell/base/nsWebShell.cpp | 20 +++++++++----------- editor/libeditor/base/nsEditor.cpp | 2 +- editor/libeditor/html/nsHTMLEditor.cpp | 17 ++++++++++------- 6 files changed, 39 insertions(+), 19 deletions(-) create mode 100644 docshell/base/crashtests/432114-1.html create mode 100644 docshell/base/crashtests/432114-2.html diff --git a/docshell/base/crashtests/432114-1.html b/docshell/base/crashtests/432114-1.html new file mode 100644 index 000000000000..8878d6605af3 --- /dev/null +++ b/docshell/base/crashtests/432114-1.html @@ -0,0 +1,8 @@ + + +Bug - Crash [@ PL_DHashTableOperate] with DOMNodeInserted event listener removing window and frameset contenteditable + + + + + diff --git a/docshell/base/crashtests/432114-2.html b/docshell/base/crashtests/432114-2.html new file mode 100644 index 000000000000..4dbb42205a60 --- /dev/null +++ b/docshell/base/crashtests/432114-2.html @@ -0,0 +1,9 @@ + + +testcase2 Bug 432114 – Crash [@ PL_DHashTableOperate] with DOMNodeInserted event listener removing window and frameset contenteditable + + + + + + diff --git a/docshell/base/crashtests/crashtests.list b/docshell/base/crashtests/crashtests.list index 1ba6026ee2ea..848b32d45a69 100644 --- a/docshell/base/crashtests/crashtests.list +++ b/docshell/base/crashtests/crashtests.list @@ -1,4 +1,6 @@ load 40929-1.html load 369126-1.html load 403574-1.xhtml +load 432114-1.html +load 432114-2.html load 436900-1.html diff --git a/docshell/base/nsWebShell.cpp b/docshell/base/nsWebShell.cpp index df9416499419..45c2a4843d7e 100644 --- a/docshell/base/nsWebShell.cpp +++ b/docshell/base/nsWebShell.cpp @@ -590,18 +590,16 @@ nsWebShell::EnsureCommandHandler() { if (!mCommandManager) { - mCommandManager = do_CreateInstance("@mozilla.org/embedcomp/command-manager;1"); - if (!mCommandManager) return NS_ERROR_OUT_OF_MEMORY; + nsCOMPtr commandUpdater = + do_CreateInstance("@mozilla.org/embedcomp/command-manager;1"); + if (!commandUpdater) return NS_ERROR_OUT_OF_MEMORY; - nsCOMPtr commandUpdater = do_QueryInterface(mCommandManager); - if (!commandUpdater) return NS_ERROR_FAILURE; - - nsCOMPtr domWindow = do_GetInterface(static_cast(this)); -#ifdef DEBUG - nsresult rv = -#endif - commandUpdater->Init(domWindow); - NS_ASSERTION(NS_SUCCEEDED(rv), "Initting command manager failed"); + nsCOMPtr domWindow = + do_GetInterface(static_cast(this)); + + nsresult rv = commandUpdater->Init(domWindow); + if (NS_SUCCEEDED(rv)) + mCommandManager = do_QueryInterface(commandUpdater); } return mCommandManager ? NS_OK : NS_ERROR_FAILURE; diff --git a/editor/libeditor/base/nsEditor.cpp b/editor/libeditor/base/nsEditor.cpp index 83bf137c3821..eba2ee5158e0 100644 --- a/editor/libeditor/base/nsEditor.cpp +++ b/editor/libeditor/base/nsEditor.cpp @@ -4344,7 +4344,7 @@ nsresult nsEditor::EndUpdateViewBatch() // the reflows we caused will get processed before the invalidates. if (flags & nsIPlaintextEditor::eEditorUseAsyncUpdatesMask) { updateFlag = NS_VMREFRESH_DEFERRED; - } else { + } else if (presShell) { // Flush out layout. Need to do this because if we have no invalidates // to flush the viewmanager code won't flush our reflow here, and we // have selection code that does sync caret scrolling in this case. diff --git a/editor/libeditor/html/nsHTMLEditor.cpp b/editor/libeditor/html/nsHTMLEditor.cpp index 82e7cc42f463..531d2a89347b 100644 --- a/editor/libeditor/html/nsHTMLEditor.cpp +++ b/editor/libeditor/html/nsHTMLEditor.cpp @@ -3613,12 +3613,6 @@ nsHTMLEditor::AddOverrideStyleSheet(const nsAString& aURL) // (This checks if already exists) ps->AddOverrideStyleSheet(sheet); - // Save doc pointer to be able to use nsIStyleSheet::SetEnabled() - nsIDocument *document = ps->GetDocument(); - if (!document) - return NS_ERROR_NULL_POINTER; - sheet->SetOwningDocument(document); - ps->ReconstructStyleData(); // Save as the last-loaded sheet @@ -3683,11 +3677,15 @@ nsHTMLEditor::EnableStyleSheet(const nsAString &aURL, PRBool aEnable) nsCOMPtr domSheet(do_QueryInterface(sheet)); NS_ASSERTION(domSheet, "Sheet not implementing nsIDOMStyleSheet!"); + + // Ensure the style sheet is owned by our document. + nsCOMPtr doc = do_QueryInterface(mDocWeak); + rv = sheet->SetOwningDocument(doc); + NS_ENSURE_SUCCESS(rv, rv); return domSheet->SetDisabled(!aEnable); } - PRBool nsHTMLEditor::EnableExistingStyleSheet(const nsAString &aURL) { @@ -3698,6 +3696,11 @@ nsHTMLEditor::EnableExistingStyleSheet(const nsAString &aURL) // Enable sheet if already loaded. if (sheet) { + // Ensure the style sheet is owned by our document. + nsCOMPtr doc = do_QueryInterface(mDocWeak); + rv = sheet->SetOwningDocument(doc); + NS_ENSURE_SUCCESS(rv, rv); + nsCOMPtr domSheet(do_QueryInterface(sheet)); NS_ASSERTION(domSheet, "Sheet not implementing nsIDOMStyleSheet!");