Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 362835 - [firefox] Pasted HTML shows twice (with clipboard privileges)
Summary: [firefox] Pasted HTML shows twice (with clipboard privileges)
Status: RESOLVED FIXED
Alias: None
Product: Orion
Classification: ECD
Component: Editor (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 0.4 M1   Edit
Assignee: Mihai Sucan CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-03 15:34 EDT by Mihai Sucan CLA
Modified: 2011-12-01 17:00 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mihai Sucan CLA 2011-11-03 15:34:22 EDT
Since the new Orion landed in Firefox 10 nightlies one can see HTML pastes showing twice.

STR:

1. Get the latest Firefox nightly, open Scratchpad.
2. Select some HTML from any tab and Paste into Scratchpad.
3. Notice how the pasted text shows twice.

If you use Edit > Paste you also get:

Error: An error occurred executing the cmd_paste command: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIController.doCommand]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"  location: "JS frame :: chrome://global/content/globalOverlay.js :: goDoCommand :: line 96"  data: no]
Source File: chrome://global/content/globalOverlay.js
Line: 100

(in the Error Console)

If I select some plain text from other apps, it works without issues.

Problem: Orion runs with clipboard privileges enabled in Scratchpad and the call to execCommand("paste") works, but Orion fails to detect it works. It does not cancel the original paste event and during the timeout _getText() finds the same text pasted twice in the clipboardDiv.

The reason why Orion fails to detect that execCommand("paste") works is that the call throws. The reason it throws is not because clipboard privileges are not given, but because Firefox has some internal failure when you try to paste HTML into the PRE, and it goes out of the PRE. You can construct a minimal page with a <div><pre contenteditable=""> and paste HTML into this element - you get the same error (provided that you use Edit > Paste from the Firefox menu). Ctrl-V hides the error.

Nonetheless, paste works even if the execCommand() throws. Two ways to fix the bug:

A. check in the try-catch if paste worked (see if there are new childNodes in clipboardDiv or in the PRE).

B. always clear clipboardDiv when execCommand() throws - to remove anything that execCommand() did.
Comment 1 Mihai Sucan CLA 2011-11-03 16:05:03 EDT
Proposed fix:

https://github.com/mihaisucan/orion.client/tree/bug-362835

Please let me know if further changes are needed. Thank you!
Comment 2 Mihai Sucan CLA 2011-11-03 16:13:43 EDT
For reference the Mozilla bug is:

https://bugzilla.mozilla.org/show_bug.cgi?id=699541
Comment 3 Felipe Heidrich CLA 2011-11-04 10:32:49 EDT
I'm okay with the fix. Feel free to push to master and thank you for one more fix.