Last Comment Bug 555176 - Provide the same formats we do on drag when copying images
: Provide the same formats we do on drag when copying images
Status: RESOLVED FIXED
:
Product: Firefox
Classification: Client Software
Component: Menus (show other bugs)
: unspecified
: All All
: -- enhancement (vote)
: Firefox 12
Assigned To: Brian R. Bondy [:bbondy]
:
Mentors:
Depends on: 749527
Blocks:
  Show dependency treegraph
 
Reported: 2010-03-26 04:25 PDT by Rasmus Faber
Modified: 2012-04-27 13:36 PDT (History)
8 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments
Patch for "copy image" menu item not providing CF_HTML format (1.30 KB, patch)
2011-08-22 18:22 PDT, Brian R. Bondy [:bbondy]
jmathies: review+
Details | Diff | Splinter Review

Description Rasmus Faber 2010-03-26 04:25:56 PDT
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 4.0.20506)
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 4.0.20506)

If I try to copy an image from a webpage and paste it into Gmail it does not work.

If I copy the image in IE or Chrome, paste works - I can even paste the copied image into an instance of Gmail opened in Firefox.

A little investigation shows that Firefox adds the following formats to the clipboard when copying an image:
 * application/x-moz-nativeimage
 * DeviceIndependentBitmap

IE7 adds the following formats:
 * UntrustedDragDrop
 * FileDrop
 * UniformResourceLocatorW
 * DeviceIndependentBitmap
 * HTML Format

and Chrome adds the following formats:
 * HTML Format
 * UniformResourceLocatorW
 * Bitmap
 * DeviceIndependentBitmap
 * Format17

A little test shows that the element needed to get Gmail paste working is the "HTML Format".

Chrome adds the following under the "HTML Format" when copying an image:

Version:0.9
StartHTML:0000000105
EndHTML:0000000336
StartFragment:0000000143
EndFragment:0000000298
<html>
<body>
<!--StartFragment-->
<img src="http://icanhascheezburger.files.wordpress.com/2010/03/funny-pictures-c
at-pretends-to-be-a-book1.jpg" alt="funny pictures of cats with captions"/>
<!--EndFragment-->
</body>
</html>

Reproducible: Always

Steps to Reproduce:
1. Copy image in firefox
2. Use gmail to write a mail and try to paste the image into the mail (nothing happens)
3. Copy image in IE or Chrome
4. Try to paste the image into the mail (now it works)
Comment 1 Kyle Huey [:khuey] (Exited; not receiving bugmail, email if necessary) 2010-04-02 16:07:09 PDT
We provide all of these on drag operations, but not on the clipboard.
Comment 2 Brian R. Bondy [:bbondy] 2011-08-22 16:59:35 PDT
Slight modification to the steps to reproduce.

1. Copy the image in Firefox by right clicking and selecting "Copy Image"
2. Use gmail to write a mail and try to paste the image into the compose box.

Reproducible: Always
Actual Results: Nothing happens
Expected Results: Image shows up.

If you select the image by highlighting and copying it does supply the needed CF_HTML format.  If you right click and select Copy Image it does not.
Comment 3 Brian R. Bondy [:bbondy] 2011-08-22 18:22:17 PDT
Created attachment 555006 [details] [diff] [review]
Patch for "copy image" menu item not providing CF_HTML format
Comment 4 Brian R. Bondy [:bbondy] 2011-08-22 18:25:03 PDT
By the way I can clean-up the naming of the ID etc, I just wanted to make sure that this strategy is good for the fix first.
Comment 5 Brian R. Bondy [:bbondy] 2011-09-29 07:34:59 PDT
Review ping
Comment 6 Brian R. Bondy [:bbondy] 2011-10-01 12:45:17 PDT
Note this task will also fix Bug 460969
Comment 7 Vladimir Vukicevic [:vlad] [:vladv] 2011-10-02 07:50:25 PDT
The patch doesn't seem to be complete... all it does is change the name of a command, without implementing it anywhere that I can see?
Comment 8 Brian R. Bondy [:bbondy] 2011-10-02 12:22:03 PDT
> The patch doesn't seem to be complete...

The patch is that one small change only on purpose. 

You can find the existing command here:
mozilla-central\dom\base\nsGlobalWindowCommands.cpp

Inside the function: nsClipboardImageCommands::DoClipboardCommand

In particular this command will copy both the image HTML Format and image data.
The old one would copy only the image data.  

The problem with only the image data is that it won't paste properly in various other programs that support only HTML Format.
Comment 9 Brian R. Bondy [:bbondy] 2011-10-24 13:33:35 PDT
review feedback ping as per Comment 8.
Comment 10 Brian R. Bondy [:bbondy] 2012-01-03 19:42:17 PST
Pushed to mozilla-inbound:
http://hg.mozilla.org/integration/mozilla-inbound/rev/52d9d7bbfad1
Comment 11 Marco Bonardo [::mak] 2012-01-04 04:56:52 PST
https://hg.mozilla.org/mozilla-central/rev/52d9d7bbfad1
Comment 12 Jefferson 2012-04-27 13:32:39 PDT
This fix is causing some Windows programs that normally paste bitmap data to instead paste a URL. SuMo threads:

Copy and Paste of Images NOT working.
https://support.mozilla.org/en-US/questions/926093

Firefox 12 won't allow Corel PhotoPaint X5 to paste 'New From Clipboard'
https://support.mozilla.org/en-US/questions/926113

The fix adds Text, Unicode Text, and HTML formats to the Bitmap format. Can the fix be fine-tuned to ONLY add the HTML format?
Comment 13 Brian R. Bondy [:bbondy] 2012-04-27 13:36:41 PDT
Yes, please see the fix already posted in bug 749527 which does that.

Note You need to log in before you can comment on or make changes to this bug.