Bug 616590 - Prevent documents loaded in mail editors to set up their own editors using the designMode or contentEditable APIs; r=bzbarsky a=blocking-final+
authorEhsan Akhgari <ehsan@mozilla.com>
Mon, 06 Dec 2010 14:27:14 -0500
changeset 58662 a7adfbb051fd913f777df204a19f2fce7154703b
parent 58661 2b63604957e2f5b9c01e47d4b2e1dfe153377627
child 58663 056814244cebfe62d9a2dfd20e4d0160b04b1e7a
push id17401
push usereakhgari@mozilla.com
push dateMon, 06 Dec 2010 19:44:13 +0000
treeherdermozilla-central@a7adfbb051fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky, blocking-final
bugs616590
milestone2.0b8pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 616590 - Prevent documents loaded in mail editors to set up their own editors using the designMode or contentEditable APIs; r=bzbarsky a=blocking-final+
content/html/document/src/nsHTMLDocument.cpp
editor/libeditor/html/tests/Makefile.in
editor/libeditor/html/tests/test_bug616590.xul
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -129,17 +129,18 @@
 
 #include "nsIPrompt.h"
 //AHMED 12-2
 #include "nsBidiUtils.h"
 
 #include "nsIEditingSession.h"
 #include "nsIEditor.h"
 #include "nsNodeInfoManager.h"
-#include "nsIEditor.h"
+#include "nsIPlaintextEditor.h"
+#include "nsIHTMLEditor.h"
 #include "nsIEditorDocShell.h"
 #include "nsIEditorStyleSheets.h"
 #include "nsIInlineSpellChecker.h"
 #include "nsRange.h"
 #include "mozAutoDocUpdate.h"
 #include "nsCCUncollectableMarker.h"
 #include "nsHtml5Module.h"
 #include "prprf.h"
@@ -3259,16 +3260,32 @@ nsHTMLDocument::EditingStateChanged()
   nsIDocShell *docshell = window->GetDocShell();
   if (!docshell)
     return NS_ERROR_FAILURE;
 
   nsresult rv;
   nsCOMPtr<nsIEditingSession> editSession = do_GetInterface(docshell, &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
+  nsCOMPtr<nsIEditor> existingEditor;
+  editSession->GetEditorForWindow(window, getter_AddRefs(existingEditor));
+  if (existingEditor) {
+    // We might already have an editor if it was set up for mail, let's see
+    // if this is actually the case.
+    nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(existingEditor);
+    NS_ABORT_IF_FALSE(htmlEditor, "If we have an editor, it must be an HTML editor");
+    PRUint32 flags = 0;
+    existingEditor->GetFlags(&flags);
+    if (flags & nsIPlaintextEditor::eEditorMailMask) {
+      // We already have a mail editor, then we should not attempt to create
+      // another one.
+      return NS_OK;
+    }
+  }
+
   if (!HasPresShell(window)) {
     // We should not make the window editable or setup its editor.
     // It's probably style=display:none.
     return NS_OK;
   }
 
   PRBool makeWindowEditable = mEditingState == eOff;
   PRBool updateState;
--- a/editor/libeditor/html/tests/Makefile.in
+++ b/editor/libeditor/html/tests/Makefile.in
@@ -83,16 +83,17 @@ include $(topsrcdir)/config/rules.mk
 		data/cfhtml-firefox.txt \
 		data/cfhtml-ie.txt \
 		data/cfhtml-ooo.txt \
 		$(NULL)
 
 _CHROME_TEST_FILES = \
 		test_bug490879.xul \
 		test_bug607584.xul \
+		test_bug616590.xul \
 		green.png \
 		$(NULL)
 
 libs:: $(_TEST_FILES)
 	$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
 	(cd $(srcdir) && tar $(TAR_CREATE_FLAGS) - browserscope 2> /dev/null) | (cd $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir) && tar -xf -)
 
 libs:: $(_DATA_FILES)
new file mode 100644
--- /dev/null
+++ b/editor/libeditor/html/tests/test_bug616590.xul
@@ -0,0 +1,106 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin"
+                 type="text/css"?>
+<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
+                 type="text/css"?>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=616590
+-->
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+        title="Mozilla Bug 616590" onload="runTest();">
+  <script type="application/javascript"
+          src="chrome://mochikit/content/MochiKit/packed.js"/>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
+  <script type="application/javascript"
+          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+  <body xmlns="http://www.w3.org/1999/xhtml">
+  <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=616590"
+     target="_blank">Mozilla Bug 616590</a>
+  <p/>
+  <editor xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
+          id="editor"
+          type="content"
+          editortype="htmlmail"
+          style="width: 400px; height: 100px;"/>
+  <p/>
+  <pre id="test">
+  </pre>
+  </body>
+  <script class="testbody" type="application/javascript">
+  <![CDATA[
+
+  SimpleTest.waitForExplicitFinish();
+
+  function EditorContentListener(aEditor)
+  {
+    this.init(aEditor);
+  }
+
+  EditorContentListener.prototype = {
+    init : function(aEditor)
+    {
+      this.mEditor = aEditor;
+    },
+
+    QueryInterface : function(aIID)
+    {
+      if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
+          aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
+          aIID.equals(Components.interfaces.nsISupports))
+        return this;
+      throw Components.results.NS_NOINTERFACE;
+    },
+
+    onStateChange : function(aWebProgress, aRequest, aStateFlags, aStatus)
+    {
+      if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP)
+      {
+        var editor = this.mEditor.getEditor(this.mEditor.contentWindow);
+        if (editor) {
+          editor.QueryInterface(Components.interfaces.nsIEditorMailSupport);
+          editor.insertAsCitedQuotation("<html><body><div contenteditable>foo</div></body></html>", "", true);
+          document.documentElement.clientWidth;
+          progress.removeProgressListener(this);
+          SimpleTest.finish();
+        }
+      }
+    },
+
+
+    onProgressChange : function(aWebProgress, aRequest,
+                                aCurSelfProgress, aMaxSelfProgress,
+                                aCurTotalProgress, aMaxTotalProgress)
+    {
+    },
+
+    onLocationChange : function(aWebProgress, aRequest, aLocation)
+    {
+    },
+
+    onStatusChange : function(aWebProgress, aRequest, aStatus, aMessage)
+    {
+    },
+
+    onSecurityChange : function(aWebProgress, aRequest, aState)
+    {
+    },
+
+    mEditor: null
+  };
+
+  var progress;
+
+  function runTest() {
+    var editorElement = document.getElementById("editor");
+    editorElement.makeEditable("htmlmail", true);
+    var docShell = editorElement.boxObject.QueryInterface(Components.interfaces.nsIEditorBoxObject).docShell;
+    progress = docShell.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIWebProgress);
+    var progressListener = new EditorContentListener(editorElement);
+    progress.addProgressListener(progressListener, Components.interfaces.nsIWebProgress.NOTIFY_ALL);
+    editorElement.setAttribute("src", "data:text/html,");
+  }
+]]>
+</script>
+</window>