Closed Bug 280947 Opened 20 years ago Closed 20 years ago

Fix for bug 279945 breaks dragging of dynamic images

Categories

(Core :: DOM: Copy & Paste and Drag & Drop, defect)

x86
Linux
defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: bzbarsky, Assigned: jst)

Details

(Keywords: fixed-aviary1.0.1, fixed1.7.6, regression)

Attachments

(3 files, 2 obsolete files)

The fix for bug 279945 disallowed dragging of images which don't have an image
extension.  I think that code should be removed and replaced with code that
changes the extension on the filename we save to appropriately.

Specifically, if we have an imgIRequest (if we don't, it's not an image) and if
the extension on the URI is not an image extension at
http://lxr.mozilla.org/seamonkey/source/content/base/src/nsContentAreaDragDrop.cpp#1108
or so we should get the type off the imgIRequest, then call
nsIMIMEService.getPrimaryExtension on it to get the extension we want to use and
append that to the URI.
Keywords: regression
Is dragging of images anything more than a convenience? This doesn't stop anyone
from doing a Save As for the "broken" images.
Dragging is a LOT more prevalent than using the context menu on Mac.  So on Mac,
this is a serious usability regression.

Further, Firefox has some known bugs with Save As that keep it from saving a lot
of dynamically generated pages (including images).  Those are exactly the ones
worst affected by the fix for bug 279945.

Finally, the fix for bug 279945 blocked dragging on all platforms, whereas the
security hole was not present on platforms where the extension doesn't determine
whether the file is executable (say Linux).

So in brief, we introduced usability issues on Linux and Mac to fix a Windows
security problem.  ;)

In any case, I'm not sure what the point of comment 1 is.  Are you arguing that
we shouldn't fix this the "right" way?
Boris is right; for some users, drag and drop is their primary means of saving
images. We should not break this.
Attachment #173340 - Flags: superreview?(dveditz)
Attachment #173340 - Flags: review?(bzbarsky)
Hmm.  So what happens if the image URI is data:?   Or some other non-nsIURL
type?  Should we perhaps just append the extension to the spec in that case, or
something? 

Do we really want to set mImage if mImageSourceString is not set?

Also, what's the purpose of the nodeToSerialize change?
Btw, I'm assuming that this was tested on Windows, right?
Probably want this on branches that got (or might get) the fix for bug 279945,
adding nomination flags
Flags: blocking1.7.6?
Flags: blocking-aviary1.0.1?
Plussing to ensure this bug doesn't exist on the branches.
Flags: blocking1.7.6?
Flags: blocking1.7.6+
Flags: blocking-aviary1.0.1?
Flags: blocking-aviary1.0.1+
(In reply to comment #5)
> Hmm.  So what happens if the image URI is data:?   Or some other non-nsIURL
> type?  Should we perhaps just append the extension to the spec in that case, or
> something? 

Currently we're unable to drop such an image into the file system (see
nsContentAreaDragDrop::SaveURIToFileInDirectory(), it bails if the uri is not an
nsIURL), and I see no reason to change that now.

> Do we really want to set mImage if mImageSourceString is not set?

Probably not, I moved the setting of mImage to the same place where
mImageSourceString is now set.

> Also, what's the purpose of the nodeToSerialize change?

Cut n' paste fun. Ignore those.

New patch coming up.
One other thing.  Even if we're failing to drop them into the filesystem, we may
be able to drop data: and such images into other apps or other Mozilla frames
(worth checking).  If so, we should not break that.  In other words, if the URI
is not a URL, I think we should just set mImageSourceString to the URI and set
mImage.  Bug 279945 won't reappear because we can't drop those into the
filesystem, but dragging elsewhere will work...
Attached patch Fix bz's issues. (obsolete) — Splinter Review
Attachment #173340 - Attachment is obsolete: true
Attachment #173629 - Flags: superreview?(dveditz)
Attachment #173629 - Flags: review?(bzbarsky)
Attachment #173340 - Flags: superreview?(dveditz)
Attachment #173340 - Flags: review?(bzbarsky)
+              mImageSourceString = NS_ConvertUTF8toUTF16(spec);

CopyUTF8toUTF16?
Comment on attachment 173629 [details] [diff] [review]
Fix bz's issues.

r=bzbarsky with biesi's nit....  Note that dragging of data: images is already
broken, even without this patch.  :(  Please file a followup bug to get it
fixed?
Attachment #173629 - Flags: review?(bzbarsky) → review+
Comment on attachment 173629 [details] [diff] [review]
Fix bz's issues.

sr=dveditz
Attachment #173629 - Flags: superreview?(dveditz)
Attachment #173629 - Flags: superreview+
Attachment #173629 - Flags: approval1.7.6?
Attachment #173629 - Flags: approval-aviary1.0.1?
Whiteboard: need approvals
Fix landed, data: URL bug on file as bug 281431.
Status: NEW → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Comment on attachment 173629 [details] [diff] [review]
Fix bz's issues.

a=asa for branches checkins.
Attachment #173629 - Flags: approval1.7.6?
Attachment #173629 - Flags: approval1.7.6+
Attachment #173629 - Flags: approval-aviary1.0.1?
Attachment #173629 - Flags: approval-aviary1.0.1+
Ahem, turns out that this fix wasn't right after all. We now properly update the
file extension in the URL, but we do that too early and we end up trying to
download the image data from the URL with the changed extension, and most likely
get no data. Fixing this won't be trivial as we need to either change this later
on in the drag n' drop process, or pass along not only the source of the image,
but also the target filename that we want, which may be different due to the
file extension differences.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
What's the status of this one? comment 18 implies we need a new patch, does that
mean the currently reviewed and approved one should be obsoleted?
Whiteboard: need approvals → need new patch? (see comment 18) need landing?
Comment on attachment 173629 [details] [diff] [review]
Fix bz's issues.

Yeah, this one ain't good for the branch, and we need this fixed on the trunk
too... I may get to looking at this tomorrow...
Attachment #173629 - Attachment is obsolete: true
Whiteboard: need new patch? (see comment 18) need landing? → need new patch
Attachment #174494 - Flags: superreview?(dveditz)
Attachment #174494 - Flags: review?(bzbarsky)
Comment on attachment 174494 [details] [diff] [review]
Additional patch needed to download the right file with the fixed extension

>Index: content/base/src/nsContentAreaDragDrop.cpp

>@@ -1130,38 +1120,51 @@ nsTransferableFactory::Produce(nsITransf

>+              // make the filename safe for the filesystem
>+              fileName.ReplaceChar('/', '_');
>+              fileName.ReplaceChar('\\', '_');
>+              fileName.ReplaceChar(':', '_');

I realize you just moved the existing code, but said code is wrong.  If nothing
else, it misses a whole bunch of characters that are not valid in filenames on
Windows.  The way nsExternalHelperAppService.cpp handles this is:

  mSuggestedFileName.ReplaceChar(FILE_PATH_SEPARATOR FILE_ILLEGAL_CHARACTERS,
'-');

(needs nsCRT.h for the FILE_* macros).	Do the same here (with fileName, of
course).

r=bzbarsky with that.
Attachment #174494 - Flags: review?(bzbarsky) → review+
Comment on attachment 174494 [details] [diff] [review]
Additional patch needed to download the right file with the fixed extension

sr=dveditz with the change requested by bz
a=dveditz for branches
Attachment #174494 - Flags: superreview?(dveditz)
Attachment #174494 - Flags: superreview+
Attachment #174494 - Flags: approval1.8b?
Attachment #174494 - Flags: approval1.7.6+
Attachment #174494 - Flags: approval-aviary1.0.1+
Whiteboard: need new patch → need checkin
Fixed on the branches.
Fixed.
Status: REOPENED → RESOLVED
Closed: 20 years ago20 years ago
Resolution: --- → FIXED
Whiteboard: need checkin
Comment on attachment 174494 [details] [diff] [review]
Additional patch needed to download the right file with the fixed extension

too late for 1.8b1; please land on trunk (which is now open)
Attachment #174494 - Flags: approval1.8b? → approval1.8b-
tested with 2005021806-1.0.1 firefox builds on Mac 10.3.8 and WinXP:

1. went to http://www.mikx.de/firedragging/
2. dragged the firefox image to the desktop

results: the file foximg.gif was saved to the desktop, and I was able to view it
using the default image viewer for the respective system.

question: is this correct behavior (I'm guessing yes, but want to be sure.)
Yes, that's the right behavior (extension is forced to correspond to the MIME type).
(In reply to comment #29)
> Yes, that's the right behavior (extension is forced to correspond to the MIME
type).

I just checked this on 2005021807-1.0.1 firefox on linux fc2, and when I d'n'd
the image onto the desktop, the filename remained foximg.bat. :-\  when I
double-clicked the image, it opened another tab in firefox (set as the default
browser), displaying the image, with "foximg.bat (GIF Image, 88x31 pixels)" in
the titlebar.

is this an acceptable result, or does that mean this hasn't been properly fixed?
 (or perhaps another bug?)
Hmm... Odd.  Could you do a log of the "HelperAppService" module for that
operation (just like
http://www.mozilla.org/projects/netlib/http/http-debugging.html says but set
NSPR_LOG_MODULES=HelperAppService:5) and email it to me?
Not sure what the deal is, but linux apparently never saves images to the system
when dragged, it just saves a shortcut to the URL of the image. That's why we
still see foximg.bat on linux, it's just a link to the image on the server.
so comment 30 would be expected behavior on linux? if that's the case, I can
verify this...
Yes, that sounds like the right behavior on Linux.
thanks!
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: