Skip to content

Commit

Permalink
Bug 1660636 - Use download attribute filename instead of File.name. r…
Browse files Browse the repository at this point in the history
…=baku

Differential Revision: https://phabricator.services.mozilla.com/D88571

UltraBlame original commit: 2bfe670b275d5236feca9af1b50d225cf7f4a448
  • Loading branch information
marco-c committed Sep 16, 2020
1 parent 92a5efa commit ea7b312
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
4 changes: 3 additions & 1 deletion browser/base/content/test/general/browser_bug676619.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async function testLink(link, name) {
await BrowserTestUtils.closeWindow(win);
}


async function testLocation(link, url) {
let tabPromise = BrowserTestUtils.waitForNewTab(gBrowser);

Expand All @@ -78,11 +79,12 @@ async function runTest(url) {
await testLink("link4", "with-target.txt");
await testLink("link5", "javascript.txt");
await testLink("link6", "test.blob");
await testLocation("link7", "http://example.com/");
await testLink("link7", "test.file");
await testLink("link8", "download_page_3.txt");
await testLink("link9", "download_page_3.txt");
await testLink("link10", "download_page_4.txt");
await testLink("link11", "download_page_4.txt");
await testLocation("link12", "http://example.com/");

BrowserTestUtils.removeTab(tab);
}
Expand Down
25 changes: 11 additions & 14 deletions browser/base/content/test/general/download_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
download="with-target.txt" id="link4">Download "with-target.txt"</a></li>
<li><a href="javascript:(1+2)+''"
download="javascript.txt" id="link5">Download "javascript.txt"</a></li>
<li><a href="#" download="test.blob" id=link6>Download "test.blob"</a></li>
<li><a href="#" download="test.file" id=link7>Download "test.file"</a></li>
<li><a href="download_with_content_disposition_header.sjs?inline=download_page_3.txt"
download="not_used.txt" id="link8">Download "download_page_3.txt"</a></li>
<li><a href="download_with_content_disposition_header.sjs?attachment=download_page_3.txt"
Expand All @@ -29,27 +31,22 @@
download="download_page_4.txt" id="link10">Download "download_page_4.txt"</a></li>
<li><a href="download_with_content_disposition_header.sjs?attachment=none"
download="download_page_4.txt" id="link11">Download "download_page_4.txt"</a></li>
<li><a href="http://example.com/"
download="example.com" id="link12" target="_blank">Download "example.com"</a></li>
</ul>
<script>
var li = document.createElement("li");
var a = document.createElement("a");
<div id="unload-flag">Okay</div>

a.href = window.URL.createObjectURL(new Blob(["just text"]));
a.download = "test.blob";
a.id = "link6";
a.textContent = 'Download "test.blob"';
<script>
let blobURL = window.URL.createObjectURL(new Blob(["just text"]));
document.getElementById("link6").href = blobURL;

li.appendChild(a);
document.getElementsByTagName("ul")[0].appendChild(li);
let fileURL = window.URL.createObjectURL(new File(["just text"],
"wrong-file-name"));
document.getElementById("link7").href = fileURL;

window.addEventListener("beforeunload", function(evt) {
document.getElementById("unload-flag").textContent = "Fail";
});
</script>
<ul>
<li><a href="http://example.com/"
download="example.com" id="link7" target="_blank">Download "example.com"</a></li>
<ul>
<div id="unload-flag">Okay</div>
</body>
</html>
8 changes: 7 additions & 1 deletion dom/file/uri/BlobURLInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,13 @@ nsresult BlobURLInputStream::StoreBlobImplStream(
if (blobImpl->IsFile()) {
nsAutoString filename;
blobImpl->GetName(filename);
if (!filename.IsEmpty()) {


nsString ignored;
bool hasName =
NS_SUCCEEDED(mChannel->GetContentDispositionFilename(ignored));

if (!filename.IsEmpty() && !hasName) {
mChannel->SetContentDispositionFilename(filename);
}
}
Expand Down

0 comments on commit ea7b312

Please sign in to comment.