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+

This commit is contained in:
Ehsan Akhgari 2010-12-06 14:27:14 -05:00
Родитель 0e50f704ba
Коммит 3f59fe5bf3
3 изменённых файлов: 125 добавлений и 1 удалений

Просмотреть файл

@ -134,7 +134,8 @@
#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"
@ -3264,6 +3265,22 @@ nsHTMLDocument::EditingStateChanged()
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.

Просмотреть файл

@ -88,6 +88,7 @@ _DATA_FILES = \
_CHROME_TEST_FILES = \
test_bug490879.xul \
test_bug607584.xul \
test_bug616590.xul \
green.png \
$(NULL)

Просмотреть файл

@ -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>