зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1710941 - Show UnknownContentType dialog only if user set alwaysAsk to true. r=mtigley
Differential Revision: https://phabricator.services.mozilla.com/D117295
This commit is contained in:
Родитель
6a8d7828db
Коммит
382905583f
|
@ -449,7 +449,11 @@ HandlerService.prototype = {
|
|||
if (
|
||||
handlerInfo.preferredAction == Ci.nsIHandlerInfo.saveToDisk ||
|
||||
handlerInfo.preferredAction == Ci.nsIHandlerInfo.useSystemDefault ||
|
||||
handlerInfo.preferredAction == Ci.nsIHandlerInfo.handleInternally
|
||||
handlerInfo.preferredAction == Ci.nsIHandlerInfo.handleInternally ||
|
||||
(handlerInfo.preferredAction == Ci.nsIHandlerInfo.alwaysAsk &&
|
||||
Services.prefs.getBoolPref(
|
||||
"browser.download.improvements_to_download_panel"
|
||||
))
|
||||
) {
|
||||
storedHandlerInfo.action = handlerInfo.preferredAction;
|
||||
} else {
|
||||
|
|
|
@ -1813,7 +1813,19 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest* request) {
|
|||
// check mReason and the preferred action to see what we should do.
|
||||
|
||||
bool alwaysAsk = true;
|
||||
mMimeInfo->GetAlwaysAskBeforeHandling(&alwaysAsk);
|
||||
|
||||
// Skip showing UnknownContentType dialog, unless it is explicitly
|
||||
// set in preferences.
|
||||
bool skipShowingDialog =
|
||||
Preferences::GetBool("browser.download.useDownloadDir") &&
|
||||
StaticPrefs::browser_download_improvements_to_download_panel();
|
||||
|
||||
if (skipShowingDialog) {
|
||||
alwaysAsk = false;
|
||||
} else {
|
||||
mMimeInfo->GetAlwaysAskBeforeHandling(&alwaysAsk);
|
||||
}
|
||||
|
||||
if (alwaysAsk) {
|
||||
// But we *don't* ask if this mimeInfo didn't come from
|
||||
// our user configuration datastore and the user has said
|
||||
|
@ -1860,18 +1872,28 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest* request) {
|
|||
int32_t action = nsIMIMEInfo::saveToDisk;
|
||||
mMimeInfo->GetPreferredAction(&action);
|
||||
|
||||
bool forcePrompt =
|
||||
mReason == nsIHelperAppLauncherDialog::REASON_TYPESNIFFED ||
|
||||
(mReason == nsIHelperAppLauncherDialog::REASON_SERVERREQUEST &&
|
||||
!skipShowingDialog);
|
||||
|
||||
// OK, now check why we're here
|
||||
if (!alwaysAsk && mReason != nsIHelperAppLauncherDialog::REASON_CANTHANDLE) {
|
||||
if (!alwaysAsk && forcePrompt) {
|
||||
// Force asking if we're not saving. See comment back when we fetched the
|
||||
// alwaysAsk boolean for details.
|
||||
alwaysAsk = (action != nsIMIMEInfo::saveToDisk);
|
||||
}
|
||||
|
||||
bool shouldAutomaticallyHandleInternally =
|
||||
action == nsIMIMEInfo::handleInternally &&
|
||||
StaticPrefs::browser_download_improvements_to_download_panel();
|
||||
|
||||
// If we're not asking, check we actually know what to do:
|
||||
if (!alwaysAsk) {
|
||||
alwaysAsk = action != nsIMIMEInfo::saveToDisk &&
|
||||
action != nsIMIMEInfo::useHelperApp &&
|
||||
action != nsIMIMEInfo::useSystemDefault;
|
||||
action != nsIMIMEInfo::useSystemDefault &&
|
||||
!shouldAutomaticallyHandleInternally;
|
||||
}
|
||||
|
||||
// if we were told that we _must_ save to disk without asking, all the stuff
|
||||
|
@ -1934,8 +1956,9 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest* request) {
|
|||
|
||||
#endif
|
||||
if (action == nsIMIMEInfo::useHelperApp ||
|
||||
action == nsIMIMEInfo::useSystemDefault) {
|
||||
rv = LaunchWithApplication(mHandleInternally);
|
||||
action == nsIMIMEInfo::useSystemDefault ||
|
||||
shouldAutomaticallyHandleInternally) {
|
||||
rv = LaunchWithApplication(shouldAutomaticallyHandleInternally);
|
||||
} else {
|
||||
rv = PromptForSaveDestination();
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ support-files =
|
|||
file_xml_attachment_binary_octet_stream.xml^headers^
|
||||
file_xml_attachment_test.xml
|
||||
file_xml_attachment_test.xml^headers^
|
||||
[browser_download_skips_dialog.js]
|
||||
[browser_download_urlescape.js]
|
||||
support-files =
|
||||
file_with@@funny_name.png
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
const { DownloadIntegration } = ChromeUtils.import(
|
||||
"resource://gre/modules/DownloadIntegration.jsm"
|
||||
);
|
||||
|
||||
const TEST_PATH = getRootDirectory(gTestPath).replace(
|
||||
"chrome://mochitests/content",
|
||||
"https://example.com"
|
||||
);
|
||||
|
||||
// New file is being downloaded and no dialogs are shown in the way.
|
||||
add_task(async function skipDialogAndDownloadFile() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.download.improvements_to_download_panel", true],
|
||||
["browser.download.useDownloadDir", true],
|
||||
],
|
||||
});
|
||||
|
||||
let publicList = await Downloads.getList(Downloads.PUBLIC);
|
||||
registerCleanupFunction(async () => {
|
||||
await publicList.removeFinished();
|
||||
});
|
||||
let downloadFinishedPromise = promiseDownloadFinished(publicList);
|
||||
|
||||
let loadingTab = await BrowserTestUtils.openNewForegroundTab(
|
||||
gBrowser,
|
||||
TEST_PATH + "file_pdf_application_pdf.pdf"
|
||||
);
|
||||
// We just open the file to be downloaded... and wait for it to be downloaded!
|
||||
// We see no dialogs to be accepted in the process.
|
||||
let download = await downloadFinishedPromise;
|
||||
|
||||
gBrowser.removeCurrentTab();
|
||||
BrowserTestUtils.removeTab(loadingTab);
|
||||
|
||||
Assert.ok(
|
||||
await OS.File.exists(download.target.path),
|
||||
"The file should have been downloaded."
|
||||
);
|
||||
|
||||
try {
|
||||
info("removing " + download.target.path);
|
||||
if (Services.appinfo.OS === "WINNT") {
|
||||
// We need to make the file writable to delete it on Windows.
|
||||
await IOUtils.setPermissions(download.target.path, 0o600);
|
||||
}
|
||||
await IOUtils.remove(download.target.path);
|
||||
} catch (ex) {
|
||||
info("The file " + download.target.path + " is not removed, " + ex);
|
||||
}
|
||||
});
|
|
@ -2,6 +2,10 @@ const { DownloadIntegration } = ChromeUtils.import(
|
|||
"resource://gre/modules/DownloadIntegration.jsm"
|
||||
);
|
||||
|
||||
const { TestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/TestUtils.jsm"
|
||||
);
|
||||
|
||||
const TEST_PATH = getRootDirectory(gTestPath).replace(
|
||||
"chrome://mochitests/content",
|
||||
"https://example.com"
|
||||
|
@ -11,7 +15,10 @@ const TEST_PATH = getRootDirectory(gTestPath).replace(
|
|||
// is actually saved in default Downloads directory.
|
||||
add_task(async function aDownloadLaunchedWithAppIsSavedInDownloadsFolder() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [["browser.download.improvements_to_download_panel", true]],
|
||||
set: [
|
||||
["browser.download.improvements_to_download_panel", true],
|
||||
["browser.download.useDownloadDir", false],
|
||||
],
|
||||
});
|
||||
|
||||
let publicList = await Downloads.getList(Downloads.PUBLIC);
|
||||
|
|
Загрузка…
Ссылка в новой задаче