Closed Bug 434998 Opened 16 years ago Closed 13 years ago

contentDocument.execCommand gives error in <editor> FF3 RC1 (NS_ERROR_FAILURE)

Categories

(Core :: DOM: Editor, defect)

defect
Not set
critical

Tracking

()

RESOLVED FIXED
mozilla8

People

(Reporter: pk, Assigned: ehsan.akhgari)

References

Details

(Keywords: dev-doc-complete)

Attachments

(3 files)

User-Agent:       Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; nb-NO; rv:1.9) Gecko/2008051202 Firefox/3.0
Build Identifier: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; nb-NO; rv:1.9) Gecko/2008051202 Firefox/3.0

I'm updating my extension for Firefox 3, and I have a XUL editor, where 
xulEditor.contentDocument.queryCommandState('bold') now fails and gives the following error:

Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMNSHTMLDocument.queryCommandState]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"

Worked fine in Firefox 2. Can't seem to get around this. Any ideas?


Reproducible: Always

Steps to Reproduce:
1. Set up a XUL editor field in chrome.
2. Try to query the commandstate within the editing document using xulEditor.contentDocument.queryCommandState('bold')
Component: General → Editor
Product: Firefox → Core
QA Contact: general → editor
Severity: normal → critical
Summary: queryCommandState crashes in regard to XUL editor (NS_ERROR_FAILURE) → contentDocument.queryCommandState and execCommand crashes in regard to XUL editor in chrome (NS_ERROR_FAILURE)
I can confirm that this worked in 1.9b2pre, but does not work in latest 1.9pre
Status: UNCONFIRMED → NEW
Ever confirmed: true
Per-Kristian - a narrowed regress range would be helpful. See if you can find the Firefox nightly that started throwing exceptions.
Thank you for the confirmation mfinkle, I'll see if I can find it.
Summary: contentDocument.queryCommandState and execCommand crashes in regard to XUL editor in chrome (NS_ERROR_FAILURE) → contentDocument.execCommand gives error in FF3 RC1 (NS_ERROR_FAILURE)
mfinkle found out that <browser> doesn't have these problems, so a temporary workaround is to user browser instead of editor. Then in order to get <editor> stuff:

var myBrowser = document.getElementById('myBrowser');
var editingSession = myBrowser.webNavigation.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIEditingSession);
myBrowser.contentDocument.designMode = 'on';
var editor = editingSession.getEditorForWindow(myBrowser.contentWindow);
var commandManager = myBrowser.webNavigation.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsICommandManager);
var htmlEditor = editor.QueryInterface(Components.interfaces.nsIHTMLEditor);

Works for now, until this bug is fixed.
Summary: contentDocument.execCommand gives error in FF3 RC1 (NS_ERROR_FAILURE) → contentDocument.execCommand gives error in <editor> FF3 RC1 (NS_ERROR_FAILURE)
For some reason the mEditingState is set to eOff when checked here:
http://mxr.mozilla.org/seamonkey/source/content/html/document/src/nsHTMLDocument.cpp#4450

I'm not sure why yet.
Maybe this was caused by Bug 428844, which was checked in on 2008-04-17? That changed how we tore down the editor. The old editor is tore down before the new one is setup, maybe that's failing...
mEditingState is eOff because SetDesignMode considers setting designMode='on' to be redundant for a document that is already editable, see http://bonsai.mozilla.org/cvsblame.cgi?file=/mozilla/content/html/document/src/nsHTMLDocument.cpp&rev=3.785&mark=4139-4140#4121 Fixing this will probably require quite a bit of changes.

What does using an editor element with designMode="on" give that a simple editor element or a browser element with designMode="on" doesn't? Unless there's an important advantage I don't think this is a high priority bug.
It has property commandManager, and methods getHTMLEditor and getEditor for instance.

But the critical point is that the editor element simply doesn't work for what it is designed for, to edit stuff. So all extensions and such using a <editor> will not work, and break stuff when it comes down to executing commands like bold, italic, link, etc. I can't see how that can not be critical?
Executing commands like cmd_bold, ... with the commandManager is broken?
Using the commandManager works fine for me?
Using commandManager like that works here too. But not contentDocument.execCommand (and similar calls) as it did before 2004-04-18.

Quote from http://developer.mozilla.org/en/docs/XUL:editor

<blockquote>
Once editable, the document can have special formatting and other HTML pieces added to it using the document.execCommand method:

    var editor = document.getElementById("myEditor");

    // toggle bold for the current selection
    editor.contentDocument.execCommand("bold", false, null);
</blockquote>

I suppse it's not only my code that will suffer from this bug.
I have a similar problem in FF3 when trying to use execCommand on an iframe editor see https://bugzilla.mozilla.org/show_bug.cgi?id=457332. This bug did not exist in FF1 or 2 and works in other browsers.
Same error with Fx 3.1 on linux. 
But I have fixed the problem by adding contenteditable="true" in a HTML element of the content document.
Attached patch Patch (v1)Splinter Review
For <xul:editor>, the HTML document's mEditingState ended up being eOff, which effectively disables the execCommand API.  This patch is a simple fix for that.
Assignee: nobody → ehsan
Status: NEW → ASSIGNED
Attachment #546023 - Flags: review?(roc)
Comment on attachment 546023 [details] [diff] [review]
Patch (v1)

Review of attachment 546023 [details] [diff] [review]:
-----------------------------------------------------------------
Attachment #546023 - Flags: review?(roc) → review+
http://hg.mozilla.org/mozilla-central/rev/901d098a58c6
Status: ASSIGNED → RESOLVED
Closed: 13 years ago
Flags: in-testsuite+
Keywords: dev-doc-needed
OS: Mac OS X → All
Hardware: PowerPC → All
Resolution: --- → FIXED
Target Milestone: --- → mozilla8
Version: unspecified → Trunk
Try run for fe3b8f619f5c is complete.
Detailed breakdown of the results available here:
    http://tbpl.mozilla.org/?tree=Try&rev=fe3b8f619f5c
Results:
    success: 148
    warnings: 13
    failure: 2
Total buildrequests: 163
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: