Closed Bug 789550 Opened 14 years ago Closed 5 years ago

data:image/gif URI `Save Page As` and `Save Image As` do not use the same filename

Categories

(Firefox :: File Handling, enhancement, P3)

enhancement

Tracking

()

VERIFIED FIXED
90 Branch
Tracking Status
firefox-esr78 --- wontfix
firefox87 --- wontfix
firefox88 --- wontfix
firefox89 --- wontfix
firefox90 --- verified

People

(Reporter: cpeterson, Assigned: ava8katushka)

Details

(Whiteboard: [outreachy-2021-downloads])

Attachments

(2 files, 4 obsolete files)

This bug was forked from bug 254139 comment 62. STR: 1. View a data:image URI 2. Selecting `File menu > Save Page As` will save a file called something like "(GIF Image, 16 × 14 pixels).gif" (named after the document's title). 3. But right-clicking on the image and selecting `Save Image As` will save a file called simply "index.gif" (because the image does not have its own name or title). In contrast, Chrome will save both files as "download.gif" and Safari will save them as "Unknown.gif". ER: `Save Page As` and `Save Image As` should use the same filename when you are viewing an image directly (even if it is a data:image/gif).
This is all Firefox code, not core code.
Product: Core → Firefox
Assignee: nobody → raymond
When we try to save an image, it would call saveImageURL/saveDocument => internalSave => initFileInfo => getDefaultFilename (http://mxr.mozilla.org/mozilla-central/source/toolkit/content/contentAreaUtils.js#822). For data:image, when saving a document (File -> save page as), it would extract the file name from the document'stitle. However, when saving an image via content menu, the document is not passed into that method so it returns a default name "index". It seems logical to me.
We could special case images that are in image documents and have them use the document filename.
Attached patch v1 (obsolete) — — Splinter Review
Attachment #664846 - Flags: review?(gavin.sharp)
Comment on attachment 664846 [details] [diff] [review] v1 Didn't pass try, fixing it
Attachment #664846 - Flags: review?(gavin.sharp)
Attached patch v2 (obsolete) — — Splinter Review
Pushed to try and waiting for results. https://tbpl.mozilla.org/?tree=Try&rev=e43d82d32185
Attachment #664846 - Attachment is obsolete: true
Attachment #665044 - Flags: review?(gavin.sharp)
Status: NEW → ASSIGNED
Comment on attachment 665044 [details] [diff] [review] v2 Seems to me like it would be better to fix this in getDefaultFileName, assuming that's possible (it gets passed the document being saved, so looks like it should be).
Attachment #665044 - Flags: review?(gavin.sharp) → review-
(In reply to :Gavin Sharp (use gavin@gavinsharp.com for email) from comment #7) > Comment on attachment 665044 [details] [diff] [review] > v2 > > Seems to me like it would be better to fix this in getDefaultFileName, > assuming that's possible (it gets passed the document being saved, so looks > like it should be). if we pass a document to getDefaultFileName(), it would think that we are trying to save a document and returns the document.title. However, there is a case which we want to save a normal image in a document using the "Save Image As" context menu item (the same method call as saving data:image: saveImageURL => internalSave => initFileInfo => getDefaultFilename); if we pass in the document to getDefaultFileName, it would return the document.title instead of the actual image title.
How about making getDefaultFilename not use document.title for image documents?
Attached patch v3 (obsolete) — — Splinter Review
OK, when using `Save Page As` and `Save Image As`for data:image, it would use index.*
Attachment #665044 - Attachment is obsolete: true
Attachment #669178 - Flags: review?(gavin.sharp)
Comment on attachment 669178 [details] [diff] [review] v3 Looks reasonable to me, but I wonder whether we want to check aDocument.mozSyntheticDocument instead (to also catch e.g. standalone video documents). Chris has looked at this code recently, let's see what he has to say!
Attachment #669178 - Flags: review?(gavin.sharp) → review?(cpeterson)
Comment on attachment 669178 [details] [diff] [review] v3 Review of attachment 669178 [details] [diff] [review]: ----------------------------------------------------------------- LGTM. I agree with Gavin's comment that other document types (such as video) might not be covered, but your patch would not make those rare cases any worse. :)
Attachment #669178 - Flags: review?(cpeterson) → review+
Attached patch Patch for checkin (obsolete) — — Splinter Review
Attachment #669178 - Attachment is obsolete: true
(In reply to Chris Peterson (:cpeterson) from comment #12) > LGTM. I agree with Gavin's comment that other document types (such as video) > might not be covered, but your patch would not make those rare cases any > worse. :) It's easy enough to fix that by just switching to checking mozSyntheticDocument, as I suggested. Is that the behavior that we want, for audio and video?
Keywords: checkin-needed
(In reply to :Gavin Sharp (use gavin@gavinsharp.com for email) from comment #14) > (In reply to Chris Peterson (:cpeterson) from comment #12) > > LGTM. I agree with Gavin's comment that other document types (such as video) > > might not be covered, but your patch would not make those rare cases any > > worse. :) > > It's easy enough to fix that by just switching to checking > mozSyntheticDocument, as I suggested. Is that the behavior that we want, for > audio and video? I think the issue of this bug is that data:image doesn't have a filename so the 'save image as' context menu item uses the default string "index" and the 'save page as' document.title. For audios and videos, I haven't seen data:mp3, data:mp4 (I am not sure whether it's possible or not) so those files would have filenames and I believe it should be handled correctly.
This patch doesn't only affect the behavior for data: URIs, as I understand it. If you're viewing a standalone video, using the filename instead of the title makes more sense in theory (though at the moment, AFAICT the document title *is* the filename, so this doesn't matter in practice). So let's just change the check to use mozSyntheticDocument.
Attached patch v4 — — Splinter Review
Attachment #669873 - Attachment is obsolete: true
Attachment #669998 - Flags: review?(gavin.sharp)
Comment on attachment 669998 [details] [diff] [review] v4 Are there any tests for this functionality? If not there probably should be...
Attachment #669998 - Flags: review?(gavin.sharp) → review+
Here are some data: URI tests, including a data:mp3 file. Unfortunately, data:mp3 is handled by the QuickTime plugin, so I can't compare "Save Page As" versus right-click "Save As". http://www-archive.mozilla.org/quality/networking/testing/datatests.html
Assignee: raymond → bellindira
Assignee: bellindira → nobody
Status: ASSIGNED → NEW
Whiteboard: [outreachy-2021-downloads]

Hello, I'm Ava, an outreachy intern, and I would like to take this bug to work on.

I have mozilla local build set up, but I'm not sure I can reproduce the issue.

  1. I use photo of the dog: https://pocket-syndicated-images.s3.amazonaws.com/60639cdae32bd.jpg for the testing purposes.
  2. When I save it through right-click + "Save image as..." file is saved as "60639cdae32bd.jpg".
  3. Also when I click File > Save page as... file is saved as "60639cdae32bd.jpg".
  4. I also have the same names through bough paths while attempting to save an audio: https://www.mediacollege.com/audio/_assets/white-noise.mp3. In both cases, the file name is "white-noise.mp3".

ER:
Save Page As and Save Image As should use the same filename when you are viewing an image directly (even if it is a data:image/gif).

The names are identical, so is this bug still actionable? Please tell me, if I'm missing something.

Hi, Ava, thanks for taking on this bug! I'll assign this bug report to you.

I see that my bug summary does not match my steps to reproduce in comment 0. I'll fix that. This bug is specifically about a "data:image" URI (where the image data is actually encoded in the URI itself as Base64 text), not a URL pointing to an image file like https://pocket-syndicated-images.s3.amazonaws.com/60639cdae32bd.jpg.

Here is the "data:image" URI that I originally tested with. Just copy this URI, paste it into the address bar, and press Enter to load:

data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7

I can still reproduce this bug in Firefox 89 Nightly:

  • File menu > "Save Page As" defaults to filename (GIF Image, 16 × 14 pixels).gif.
  • Right-click on the tiny (folder) icon > "Save Page As" defaults to filename index.gif. (Right-clicking on the page's black background and selecting "Save Page As" defaults to filename (GIF Image, 16 × 14 pixels).gif.

Open question: while we agree that the saved file should probably have the same filename, regardless of how it was saved, what do we actually want that filename to be? (GIF Image, 16 × 14 pixels).gif, index.gif, or something else?

Precedents from other browsers for comparison:

  • Chrome (and Microsoft's Chromium Edge) on Windows and macOS default to filename download.gif.
  • Safari on macOS defaults to filename Unknown.gif.

As a user, if I see a data:image URI in the address bar and save it to a file, I would probably expect a filename like data.gif or image.gif. However, copying the precedent set by Chrome (download.gif) is always a safe choice. The engineer who reviews your code will probably have their own opinion. :) (We can't use a filename like data:image.gif because colon characters are not allowed in filenames on Windows or macOS.)

This bug report has an attachment with ancient code patch that apparently fixed this bug (nine years ago). I suggest reading that patch to get an idea of where to begin fixing this bug now. But beware that the Firefox code has changed a lot in the last nine years, so that patch's code changes might not be the fix needed today.

Assignee: nobody → ava8katushka
Type: defect → enhancement
Flags: needinfo?(ava8katushka)
Summary: `Save Page As` and `Save Image As` do not use the same filename → data:image/gif URI `Save Page As` and `Save Image As` do not use the same filename

Thank you so much Chris for giving the detailed explanations on how to reproduce the bug and also guidance for my first bug as I'm trying to contribute. That was super, super helpful!!

Previous patches

I've tested the previous patches to this bug,

  • !(aDocument instanceof Ci.nsIImageDocument) [669178]
  • !aDocument.mozSyntheticDocument [669998]
    None of them seems to work now.

Idea & Implementation

My idea is to check if it's a data URI of image/audio/video and return some standart response in this case.

Current implementation: https://phabricator.services.mozilla.com/D111857

I tested several cases with data URIs.

Test sketch

Image (Works with patch)

Currently: image data file, if saved through "Save page as", saves it as title, e.g "(GIF Image ..).gif" and when saved through "Save image as" saves as "index.gif"

Should be: saved in the same way through "Save page as" and "Save audio as" as "index.gif"

Audio (Doesn't work)

Currently: audio data mp3 file, if saved through "Save page as" is saved as "index.mp3" and if saved as "Save audio as" saves as "mp3.mp3".

Should be saved in the same way through "Save page as" and "Save audio as" as "index.mp3"

Problem

I figured out that while audio is saved, it doesn't use the same functions the images do. So it doesn't use the result of "getDefaultFileName" function or any functions two levels up. There it goes, I didn't still understand.

I hope my patch for images at least makes sense, and I'll wait the reviewer's feedback on it.

Flags: needinfo?(ava8katushka)
Attachment #9215503 - Attachment description: Bug 789550 - Avoid using document title while saving data URIs. r?mccr8 → Bug 789550 - Avoid using document title while saving data URIs. r?gijs
Attachment #9215503 - Attachment description: Bug 789550 - Avoid using document title while saving data URIs. r?gijs → Bug 789550 - Avoid using document title while saving data URIs. r?mccr8
Severity: normal → S3
Priority: -- → P3
Pushed by gijskruitbosch@gmail.com: https://hg.mozilla.org/integration/autoland/rev/714e6e7b8eef Avoid using document title while saving data URIs. r=Gijs

Ava, looks like your patch was backed out because your browser_default_audio_filename.js test is failing:

TEST-UNEXPECTED-FAIL | toolkit/content/tests/browser/browser_default_audio_filename.js | undefined assertion name - Got "index", expected "index.mp3"

You will need to fix your patch or the test and submit the new fix to Phabricator for a second review.

Pushed by gijskruitbosch@gmail.com: https://hg.mozilla.org/integration/autoland/rev/16b7ab3bd643 Avoid using document title while saving data URIs. r=Gijs
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → 90 Branch
Flags: needinfo?(ava8katushka)
QA Whiteboard: [qa-90b-p2]

Reproduced the initial issue using old Nightly from 2021-04-07, verified that saving the image and audio file from both page context menu or Main Menu will have the same name proposed to save. Verified on 90.0b5 across platforms (Windows 10, macOS 11.3 and Ubuntu 18.04).

Status: RESOLVED → VERIFIED
QA Whiteboard: [qa-90b-p2]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: