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

RESOLVED FIXED in mozilla8

Status

()

Core
Editor
--
critical
RESOLVED FIXED
9 years ago
6 years ago

People

(Reporter: Per-Kristian Nordnes (skogsmaskin), Assigned: Ehsan)

Tracking

({dev-doc-complete})

Trunk
mozilla8
dev-doc-complete
Points:
---
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(3 attachments)

(Reporter)

Description

9 years ago
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
(Reporter)

Comment 1

9 years ago
Created attachment 322137 [details]
A test XUL file. Please put it in chrome.
(Reporter)

Updated

9 years ago
Severity: normal → critical
(Reporter)

Updated

9 years ago
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.
(Reporter)

Comment 4

9 years ago
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)
(Reporter)

Comment 5

9 years ago
It happened in https://ftp.mozilla.org/pub/mozilla.org/firefox/nightly/2008/04/2008-04-18-04-trunk/
(Reporter)

Comment 6

9 years ago
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.
(Reporter)

Comment 10

9 years ago
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?
Created attachment 322786 [details]
Testcase using commandManager

Using the commandManager works fine for me?
(Reporter)

Comment 13

9 years ago
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.

Comment 14

9 years ago
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.

Comment 15

8 years ago
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.
Duplicate of this bug: 671248
Created attachment 546023 [details] [diff] [review]
Patch (v1)

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
Last Resolved: 6 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

Comment 20

6 years ago
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
This bug fix is noted here:

https://developer.mozilla.org/en/Firefox_8_for_developers#XUL
Keywords: dev-doc-needed → dev-doc-complete
You need to log in before you can comment on or make changes to this bug.