diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp
index efeaf646c26..a5740de4942 100644
--- a/mozilla/content/html/document/src/nsHTMLDocument.cpp
+++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp
@@ -2005,6 +2005,16 @@ nsHTMLDocument::OpenCommon(const nsACString& aContentType, PRBool aReplace)
mRootContent = root;
}
+ if (mEditingIsOn) {
+ // Reset() blows away all event listeners in the document, and our
+ // editor relies heavily on those. Midas is turned on, to make it
+ // work, re-initialize it to give it a chance to add its event
+ // listeners again.
+
+ SetDesignMode(NS_LITERAL_STRING("off"));
+ SetDesignMode(NS_LITERAL_STRING("on"));
+ }
+
// Store the security info of the caller now that we're done
// resetting the document.
mSecurityInfo = securityInfo;
@@ -2076,8 +2086,17 @@ nsHTMLDocument::OpenCommon(const nsACString& aContentType, PRBool aReplace)
// Add a wyciwyg channel request into the document load group
NS_ASSERTION(!mWyciwygChannel, "nsHTMLDocument::OpenCommon(): wyciwyg "
"channel already exists!");
+
+ // In case the editor is listening and will see the new channel
+ // being added, make sure mWriteLevel is non-zero so that the editor
+ // knows that document.open/write/close() is being called on this
+ // document.
+ ++mWriteLevel;
+
CreateAndAddWyciwygChannel();
+ --mWriteLevel;
+
return rv;
}
diff --git a/mozilla/editor/composer/src/nsEditingSession.cpp b/mozilla/editor/composer/src/nsEditingSession.cpp
index 856a5463b8c..5d9af5687eb 100644
--- a/mozilla/editor/composer/src/nsEditingSession.cpp
+++ b/mozilla/editor/composer/src/nsEditingSession.cpp
@@ -44,6 +44,7 @@
#include "nsIDOMWindowInternal.h"
#include "nsIDOMNSHTMLDocument.h"
#include "nsIDocument.h"
+#include "nsIHTMLDocument.h"
#include "nsIDOMDocument.h"
#include "nsIURI.h"
#include "nsIScriptGlobalObject.h"
@@ -721,11 +722,36 @@ nsEditingSession::OnStateChange(nsIWebProgress *aWebProgress,
}
// Document level notification...
- if (aStateFlags & nsIWebProgressListener::STATE_IS_DOCUMENT)
- {
+ if (aStateFlags & nsIWebProgressListener::STATE_IS_DOCUMENT) {
+ PRBool progressIsForTargetDocument =
+ IsProgressForTargetDocument(aWebProgress);
+
+ if (progressIsForTargetDocument) {
+ nsCOMPtr window;
+ aWebProgress->GetDOMWindow(getter_AddRefs(window));
+
+ nsCOMPtr doc;
+ window->GetDocument(getter_AddRefs(doc));
+
+ nsCOMPtr htmlDoc(do_QueryInterface(doc));
+
+ if (htmlDoc && htmlDoc->IsWriting()) {
+ nsCOMPtr htmlDomDoc(do_QueryInterface(doc));
+ nsAutoString designMode;
+
+ htmlDomDoc->GetDesignMode(designMode);
+
+ if (designMode.EqualsLiteral("on")) {
+ // This notification is for data coming in through
+ // document.open/write/close(), ignore it.
+
+ return NS_OK;
+ }
+ }
+ }
+
mCanCreateEditor = PR_TRUE;
- (void)StartDocumentLoad(aWebProgress,
- IsProgressForTargetDocument(aWebProgress));
+ StartDocumentLoad(aWebProgress, progressIsForTargetDocument);
#ifdef NOISY_DOC_LOADING
printf("STATE_START & STATE_IS_DOCUMENT flags=%x\n", aStateFlags);
#endif
diff --git a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp
index 9f9edfb78d5..edf02cb892f 100644
--- a/mozilla/editor/libeditor/html/nsHTMLEditor.cpp
+++ b/mozilla/editor/libeditor/html/nsHTMLEditor.cpp
@@ -278,11 +278,6 @@ NS_IMETHODIMP nsHTMLEditor::Init(nsIDOMDocument *aDoc,
if (!(mFlags & eEditorPlaintextMask))
context->SetLinkHandler(0);
- nsCOMPtr bodyElement;
- result = nsEditor::GetRootElement(getter_AddRefs(bodyElement));
- if (NS_FAILED(result)) { return result; }
- if (!bodyElement) { return NS_ERROR_NULL_POINTER; }
-
// init the type-in state
mTypeInState = new TypeInState();
if (!mTypeInState) {return NS_ERROR_NULL_POINTER;}
diff --git a/mozilla/editor/libeditor/text/nsTextEditUtils.cpp b/mozilla/editor/libeditor/text/nsTextEditUtils.cpp
index ffbaca6ce46..ec08e4c4944 100644
--- a/mozilla/editor/libeditor/text/nsTextEditUtils.cpp
+++ b/mozilla/editor/libeditor/text/nsTextEditUtils.cpp
@@ -107,11 +107,12 @@ nsTextEditUtils::InBody(nsIDOMNode *node, nsIEditor *editor)
if (node)
{
nsCOMPtr rootElement;
- nsresult res = editor->GetRootElement(getter_AddRefs(rootElement));
- if (NS_FAILED(res))
- return res;
+ editor->GetRootElement(getter_AddRefs(rootElement));
+
nsCOMPtr rootNode = do_QueryInterface(rootElement);
- if (!rootNode) return NS_ERROR_NULL_POINTER;
+ if (!rootNode)
+ return PR_FALSE;
+
nsCOMPtr tmp;
nsCOMPtr p = node;
while (p && p != rootNode)