Bug 1811830 - Add a preference to force downloading of attachments. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D187285
This commit is contained in:
Mike Kaply 2023-09-06 19:44:10 +00:00
Родитель 859181dc99
Коммит b072c00ccb
3 изменённых файлов: 25 добавлений и 2 удалений

Просмотреть файл

@ -1362,6 +1362,12 @@
value: false
mirror: always
# See bug 1811830
- name: browser.download.force_save_internally_handled_attachments
type: bool
value: false
mirror: always
- name: browser.download.sanitize_non_media_extensions
type: bool
value: true

Просмотреть файл

@ -1273,6 +1273,7 @@ nsExternalAppHandler::nsExternalAppHandler(
mWindowContext(aWindowContext),
mSuggestedFileName(aSuggestedFileName),
mForceSave(aForceSave),
mForceSaveInternallyHandled(false),
mCanceled(false),
mStopRequestIssued(false),
mIsFileChannel(false),
@ -1740,6 +1741,16 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest* request) {
bool shouldAutomaticallyHandleInternally =
action == nsIMIMEInfo::handleInternally;
if (aChannel) {
uint32_t disposition = -1;
aChannel->GetContentDisposition(&disposition);
mForceSaveInternallyHandled =
shouldAutomaticallyHandleInternally &&
disposition == nsIChannel::DISPOSITION_ATTACHMENT &&
mozilla::StaticPrefs::
browser_download_force_save_internally_handled_attachments();
}
// If we're not asking, check we actually know what to do:
if (!alwaysAsk) {
alwaysAsk = action != nsIMIMEInfo::saveToDisk &&
@ -1777,7 +1788,7 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest* request) {
// if we were told that we _must_ save to disk without asking, all the stuff
// before this is irrelevant; override it
if (mForceSave) {
if (mForceSave || mForceSaveInternallyHandled) {
alwaysAsk = false;
action = nsIMIMEInfo::saveToDisk;
shouldAutomaticallyHandleInternally = false;
@ -2449,7 +2460,7 @@ void nsExternalAppHandler::RequestSaveDestination(
NS_IMETHODIMP nsExternalAppHandler::PromptForSaveDestination() {
if (mCanceled) return NS_OK;
if (mForceSave) {
if (mForceSave || mForceSaveInternallyHandled) {
mMimeInfo->SetPreferredAction(nsIMIMEInfo::saveToDisk);
}

Просмотреть файл

@ -362,6 +362,12 @@ class nsExternalAppHandler final : public nsIStreamListener,
*/
bool mForceSave;
/**
* If set, any internally handled type that has a disposition of
nsIChannel::DISPOSITION_ATTACHMENT will be saved to disk.
*/
bool mForceSaveInternallyHandled;
/**
* The canceled flag is set if the user canceled the launching of this
* application before we finished saving the data to a temp file.