Bug 1808918, use Untitled as the default filename when saving a file rather than index, r=mak

Differential Revision: https://phabricator.services.mozilla.com/D167028
This commit is contained in:
Neil Deakin 2023-01-23 14:53:21 +00:00
parent 126f48a2b0
commit 1d2e8169a6
13 changed files with 40 additions and 27 deletions

View File

@ -2056,6 +2056,14 @@ class nsContextMenu {
this.principal
);
} else if (this.onVideo || this.onAudio) {
let defaultFileName = "";
if (this.mediaURL.startsWith("data")) {
// Use default file name "Untitled" for data URIs
defaultFileName = ContentAreaUtils.stringBundle.GetStringFromName(
"UntitledSaveFileName"
);
}
var dialogTitle = this.onVideo ? "SaveVideoTitle" : "SaveAudioTitle";
this.saveHelper(
this.mediaURL,
@ -2066,7 +2074,7 @@ class nsContextMenu {
referrerInfo,
cookieJarSettings,
this.frameOuterWindowID,
this.mediaURL.startsWith("data") ? "index" : "", // use default file name "index" for data URIs
defaultFileName,
isContentWindowPrivate
);
}

View File

@ -161,7 +161,7 @@ function validateFileName(aFileName) {
if (processed.replace(/_/g, "").length <= processed.length / 2) {
// We purposefully do not use a localized default filename,
// which we could have done using
// ContentAreaUtils.stringBundle.GetStringFromName("DefaultSaveFileName")
// ContentAreaUtils.stringBundle.GetStringFromName("UntitledSaveFileName")
// since it may contain invalid characters.
let original = processed;
processed = "download";

View File

@ -139,7 +139,7 @@ add_task(async function() {
await addJsonViewTab(TEST_JSON_URL);
info("Checking that application/json adds .json extension by default.");
const data = awaitSavedFileContents("index.json", "json");
const data = awaitSavedFileContents("Untitled.json", "json");
await clickJsonNode(saveButton);
info("Clicked Save button.");
is(await data, "2", "JSON contents should have been saved.");
@ -152,7 +152,7 @@ add_task(async function() {
await addJsonViewTab(TEST_JSON_URL);
info("Checking that application/manifest+json does not add .json extension.");
const data = awaitSavedFileContents("index", null);
const data = awaitSavedFileContents("Untitled", null);
await clickJsonNode(saveButton);
info("Clicked Save button.");
is(await data, "3", "JSON contents should have been saved.");

View File

@ -49,7 +49,7 @@ add_task(async function test_with_pref_enabled() {
BrowserTestUtils.loadURIString(gBrowser, kTestURI);
let win = await windowPromise;
let expectedValue = "index.csv";
let expectedValue = "Untitled.csv";
is(
win.document.getElementById("location").value,
expectedValue,

View File

@ -7,7 +7,7 @@ add_task(async function() {
let tests = [
{
uri: "data:text/html,Test",
basename: "index",
basename: "Untitled",
},
{
uri: "data:text/html,<title>Hello There</title>Test",

View File

@ -1106,7 +1106,7 @@ function validateFileName(aFileName) {
if (processed.replace(/_/g, "").length <= processed.length / 2) {
// We purposefully do not use a localized default filename,
// which we could have done using
// ContentAreaUtils.stringBundle.GetStringFromName("DefaultSaveFileName")
// ContentAreaUtils.stringBundle.GetStringFromName("UntitledSaveFileName")
// since it may contain invalid characters.
var original = processed;
processed = "download";

View File

@ -40,9 +40,9 @@ add_task(async function() {
let showFilePickerPromise = new Promise(resolve => {
MockFilePicker.showCallback = function(fp) {
is(
fp.defaultString.startsWith("index"),
fp.defaultString.startsWith("Untitled"),
true,
"File name should be index"
"File name should be Untitled"
);
resolve();
};
@ -82,9 +82,9 @@ add_task(async function() {
let showFilePickerPromise = new Promise(resolve => {
MockFilePicker.showCallback = function(fp) {
is(
fp.defaultString.startsWith("index"),
fp.defaultString.startsWith("Untitled"),
true,
"File name should be index"
"File name should be Untitled"
);
resolve();
};

View File

@ -37,7 +37,7 @@ add_task(async function() {
let showFilePickerPromise = new Promise(resolve => {
MockFilePicker.showCallback = function(fp) {
is(fp.defaultString, "index.gif");
is(fp.defaultString, "Untitled.gif");
resolve();
};
});
@ -72,7 +72,7 @@ add_task(async function() {
async function(browser) {
let showFilePickerPromise = new Promise(resolve => {
MockFilePicker.showCallback = function(fp) {
is(fp.defaultString, "index.gif");
is(fp.defaultString, "Untitled.gif");
resolve();
};
});

View File

@ -9,13 +9,18 @@ SaveMediaTitle=Save Media
SaveVideoTitle=Save Video
SaveAudioTitle=Save Audio
SaveLinkTitle=Save As
DefaultSaveFileName=index
WebPageCompleteFilter=Web Page, complete
WebPageHTMLOnlyFilter=Web Page, HTML only
WebPageXHTMLOnlyFilter=Web Page, XHTML only
WebPageSVGOnlyFilter=Web Page, SVG only
WebPageXMLOnlyFilter=Web Page, XML only
# LOCALIZATION NOTE (UntitledSaveFileName):
# This is the default filename used when saving a file if a filename could
# not be determined or if a filename was invalid. A period and file
# extension may be appended to this string.
UntitledSaveFileName=Untitled
# LOCALIZATION NOTE (filesFolder):
# This is the name of the folder that is created parallel to a HTML file
# when it is saved "With Images". The %S section is replaced with the

View File

@ -3461,15 +3461,15 @@ nsExternalHelperAppService::ValidateFileNameForSaving(
"chrome://global/locale/contentAreaCommands.properties",
getter_AddRefs(bundle)))) {
nsAutoString defaultFileName;
bundle->GetStringFromName("DefaultSaveFileName", defaultFileName);
bundle->GetStringFromName("UntitledSaveFileName", defaultFileName);
// Append any existing extension to the default filename.
fileName = defaultFileName + fileName;
}
}
// Use 'index' as a last resort.
// Use 'Untitled' as a last resort.
if (!fileName.Length()) {
fileName.AssignLiteral("index");
fileName.AssignLiteral("Untitled");
}
}

View File

@ -49,8 +49,8 @@ const WEBP_DATA = atob(
"UklGRiIAAABXRUJQVlA4TBUAAAAvY8AYAAfQ/4j+B4CE8H+/ENH/VCIA"
);
const DEFAULT_INDEX_FILENAME =
AppConstants.platform == "win" ? "index.htm" : "index.html";
const DEFAULT_FILENAME =
AppConstants.platform == "win" ? "Untitled.htm" : "Untitled.html";
const PROMISE_FILENAME_TYPE = "application/x-moz-file-promise-dest-filename";
@ -279,7 +279,7 @@ add_task(async function save_document() {
// This is special-cased on Windows. The default filename will be used, since
// the filename is invalid, but since the previous test file has the same issue,
// this second file will be saved with a number suffix added to it.
filename = "index_002";
filename = "Untitled_002";
}
let file = tmpDir.clone();
@ -516,9 +516,9 @@ add_task(async function saveas_files() {
// Trying to open an unknown or binary type will just open a blank
// page, so trying to save will just save the blank page with the
// filename index.html.
// filename Untitled.html.
let expectedFilename = expectedItems[idx].unknown
? DEFAULT_INDEX_FILENAME
? DEFAULT_FILENAME
: expectedItems[idx].savepagename || expectedItems[idx].filename;
// When saving via contentAreaUtils.js, the content disposition name
@ -726,11 +726,11 @@ add_task(async function save_download_links() {
" was saved with the correct name when link has download attribute"
);
} else {
if (idx == 66 && filename == "index(1)") {
if (idx == 66 && filename == "Untitled(1)") {
// Sometimes, the previous test's file still exists or wasn't created in time
// and a non-duplicated name is created. Allow this rather than figuring out
// how to avoid it since it doesn't affect what is being tested here.
filename = "index";
filename = "Untitled";
}
is(

View File

@ -247,11 +247,11 @@
<!-- reserved filename on Windows -->
<img id="i65" src="http://localhost:8000/save_filename.sjs?type=text&filename=com1"
data-nodrag="true" data-filename="com1" data-filename-platformwin="index">
data-nodrag="true" data-filename="com1" data-filename-platformwin="Untitled">
<!-- reserved filename with extension on Windows -->
<img id="i66" src="http://localhost:8000/save_filename.sjs?type=text&filename=com2.any"
data-nodrag="true" data-filename="com2.any" data-filename-platformwin="index">
data-nodrag="true" data-filename="com2.any" data-filename-platformwin="Untitled">
<!-- simple zip file -->
<object id="i67" data="http://localhost:8000/save_filename.sjs?type=zip&filename=simple.zip" data-filename="simple.zip"

View File

@ -136,7 +136,7 @@ add_task(async function validate_filename_method() {
// no filename, so index is used by default.
Assert.equal(checkFilename(".png", 0), "png.png");
// sanitization only, so index is not added, but initial period is stripped.
// sanitization only, so Untitled is not added, but initial period is stripped.
Assert.equal(
checkFilename(".png", mimeService.VALIDATE_SANITIZE_ONLY),
"png"