зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1747343 - Add pref to set default action for new mimetypes. r=Gijs,fluent-reviewers,preferences-reviewers
When downloading a file, we check for existing mime types and construct a new one if it's unrecognized. Mime types have a flag, alwaysAskBeforeHandling, that determines whether the unknown content type dialog should be opened before handling the file. Before bug 1733492, the default value for that flag was simply true. Since the new downloads flow is intended to avoid unnecessary steps, the default value was changed to the inverted value of the new downloads panel improvements pref. This patch adds a new pref that the mime info constructor will read in configuring the flag's value. If the improvements pref is not enabled, then the flag will be true, so the UCT dialog will open. If the improvements pref is enabled, then it'll use the value of the new pref. Also add a an interface for the pref to the about:preferences UI, and automatically migrate a false value for browser.download.improvements_to_download_panel to a true value for this pref. I'm updating some tangentially related test files since they happen to be touched slightly by this change. Strictly speaking they would still work, but if the pref value was somehow changed from the default they would fail. Differential Revision: https://phabricator.services.mozilla.com/D143002
This commit is contained in:
Родитель
febe1bc2e2
Коммит
9a0bc90754
|
@ -3376,7 +3376,7 @@ BrowserGlue.prototype = {
|
|||
_migrateUI: function BG__migrateUI() {
|
||||
// Use an increasing number to keep track of the current migration state.
|
||||
// Completely unrelated to the current Firefox release number.
|
||||
const UI_VERSION = 125;
|
||||
const UI_VERSION = 126;
|
||||
const BROWSER_DOCURL = AppConstants.BROWSER_CHROME_URL;
|
||||
|
||||
const PROFILE_DIR = Services.dirsvc.get("ProfD", Ci.nsIFile).path;
|
||||
|
@ -4152,6 +4152,25 @@ BrowserGlue.prototype = {
|
|||
}
|
||||
}
|
||||
|
||||
if (currentUIVersion < 126) {
|
||||
// Bug 1747343 - Add a pref to set the default download action to "Always
|
||||
// ask" so the UCT dialog will be opened for mime types that are not
|
||||
// stored already. Users who wanted this behavior would have disabled the
|
||||
// experimental pref browser.download.improvements_to_download_panel so we
|
||||
// can migrate its inverted value to this new pref.
|
||||
if (
|
||||
!Services.prefs.getBoolPref(
|
||||
"browser.download.improvements_to_download_panel",
|
||||
true
|
||||
)
|
||||
) {
|
||||
Services.prefs.setBoolPref(
|
||||
"browser.download.always_ask_before_handling_new_types",
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Update the migration version.
|
||||
Services.prefs.setIntPref("browser.migration.version", UI_VERSION);
|
||||
},
|
||||
|
|
|
@ -449,6 +449,17 @@
|
|||
</listheader>
|
||||
<richlistbox id="handlersView"
|
||||
preference="pref.downloads.disable_button.edit_actions"/>
|
||||
<description id="handleNewFileTypesDesc"
|
||||
data-l10n-id="applications-handle-new-file-types-description"/>
|
||||
<radiogroup id="handleNewFileTypes"
|
||||
preference="browser.download.always_ask_before_handling_new_types">
|
||||
<radio id="saveForNewTypes"
|
||||
value="false"
|
||||
data-l10n-id="applications-save-for-new-types"/>
|
||||
<radio id="askBeforeHandling"
|
||||
value="true"
|
||||
data-l10n-id="applications-ask-before-handling"/>
|
||||
</radiogroup>
|
||||
</groupbox>
|
||||
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ Preferences.addAll([
|
|||
|
||||
// Downloads
|
||||
{ id: "browser.download.useDownloadDir", type: "bool" },
|
||||
{ id: "browser.download.always_ask_before_handling_new_types", type: "bool" },
|
||||
{ id: "browser.download.folderList", type: "int" },
|
||||
{ id: "browser.download.dir", type: "file" },
|
||||
|
||||
|
@ -2906,6 +2907,12 @@ var gMainPane = {
|
|||
* browser.download.folderList preference.
|
||||
* False - Always ask the user where to save a file and default to
|
||||
* browser.download.lastDir when displaying a folder picker dialog.
|
||||
* browser.download.always_ask_before_handling_new_types - bool
|
||||
* Defines the default behavior for new file handlers.
|
||||
* True - When downloading a file that doesn't match any existing
|
||||
* handlers, ask the user whether to save or open the file.
|
||||
* False - Save the file. The user can change the default action in
|
||||
* the Applications section in the preferences UI.
|
||||
* browser.download.dir - local file handle
|
||||
* A local folder the user may have selected for downloaded files to be
|
||||
* saved. Migration of other browser settings may also set this path.
|
||||
|
|
|
@ -454,6 +454,16 @@ applications-use-os-default-label =
|
|||
|
||||
##
|
||||
|
||||
applications-handle-new-file-types-description = What should { -brand-short-name } do with other files?
|
||||
|
||||
applications-save-for-new-types =
|
||||
.label = Save files
|
||||
.accesskey = S
|
||||
|
||||
applications-ask-before-handling =
|
||||
.label = Ask whether to open or save files
|
||||
.accesskey = A
|
||||
|
||||
drm-content-header = Digital Rights Management (DRM) Content
|
||||
|
||||
play-drm-content =
|
||||
|
|
|
@ -1153,6 +1153,12 @@
|
|||
value: true
|
||||
mirror: always
|
||||
|
||||
# See bug 1747343
|
||||
- name: browser.download.always_ask_before_handling_new_types
|
||||
type: bool
|
||||
value: false
|
||||
mirror: always
|
||||
|
||||
# See bug 1731668
|
||||
- name: browser.download.enable_spam_prevention
|
||||
type: bool
|
||||
|
|
|
@ -81,14 +81,16 @@ nsMIMEInfoBase::nsMIMEInfoBase(const char* aMIMEType)
|
|||
mClass(eMIMEInfo),
|
||||
mPreferredAction(nsIMIMEInfo::saveToDisk),
|
||||
mAlwaysAskBeforeHandling(
|
||||
!StaticPrefs::browser_download_improvements_to_download_panel()) {}
|
||||
StaticPrefs::
|
||||
browser_download_always_ask_before_handling_new_types()) {}
|
||||
|
||||
nsMIMEInfoBase::nsMIMEInfoBase(const nsACString& aMIMEType)
|
||||
: mSchemeOrType(aMIMEType),
|
||||
mClass(eMIMEInfo),
|
||||
mPreferredAction(nsIMIMEInfo::saveToDisk),
|
||||
mAlwaysAskBeforeHandling(
|
||||
!StaticPrefs::browser_download_improvements_to_download_panel()) {}
|
||||
StaticPrefs::
|
||||
browser_download_always_ask_before_handling_new_types()) {}
|
||||
|
||||
// Constructor for a handler that lets the caller specify whether this is a
|
||||
// MIME handler or a protocol handler. In the long run, these will be distinct
|
||||
|
@ -100,7 +102,8 @@ nsMIMEInfoBase::nsMIMEInfoBase(const nsACString& aType, HandlerClass aClass)
|
|||
mClass(aClass),
|
||||
mPreferredAction(nsIMIMEInfo::saveToDisk),
|
||||
mAlwaysAskBeforeHandling(
|
||||
!StaticPrefs::browser_download_improvements_to_download_panel() ||
|
||||
StaticPrefs::
|
||||
browser_download_always_ask_before_handling_new_types() ||
|
||||
aClass != eMIMEInfo) {}
|
||||
|
||||
nsMIMEInfoBase::~nsMIMEInfoBase() {}
|
||||
|
|
|
@ -155,11 +155,10 @@ var HandlerServiceTestUtils = {
|
|||
};
|
||||
} else {
|
||||
// On Desktop, the default preferredAction for MIME types is saveToDisk,
|
||||
// while for protocols it is alwaysAsk.
|
||||
// With the new download improvements, for MIME types we default to not
|
||||
// asking before handling
|
||||
alwaysAskBeforeHandling = !Services.prefs.getBoolPref(
|
||||
"browser.download.improvements_to_download_panel",
|
||||
// while for protocols it is alwaysAsk. Since Bug 1735843, for new MIME
|
||||
// types we default to not asking before handling unless a pref is set.
|
||||
alwaysAskBeforeHandling = Services.prefs.getBoolPref(
|
||||
"browser.download.always_ask_before_handling_new_types",
|
||||
false
|
||||
);
|
||||
|
||||
|
|
|
@ -58,3 +58,68 @@ add_task(async function skipDialogAndDownloadFile() {
|
|||
info("The file " + download.target.path + " is not removed, " + ex);
|
||||
}
|
||||
});
|
||||
|
||||
// Test that pref browser.download.always_ask_before_handling_new_types causes
|
||||
// the UCT dialog to be opened for unrecognized mime types
|
||||
add_task(async function skipDialogAndDownloadFile() {
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.download.improvements_to_download_panel", true],
|
||||
["browser.download.always_ask_before_handling_new_types", true],
|
||||
["browser.download.useDownloadDir", true],
|
||||
],
|
||||
});
|
||||
|
||||
let UCTObserver = {
|
||||
opened: PromiseUtils.defer(),
|
||||
closed: PromiseUtils.defer(),
|
||||
observe(aSubject, aTopic, aData) {
|
||||
let win = aSubject;
|
||||
switch (aTopic) {
|
||||
case "domwindowopened":
|
||||
win.addEventListener(
|
||||
"load",
|
||||
function onLoad(event) {
|
||||
// Let the dialog initialize
|
||||
SimpleTest.executeSoon(function() {
|
||||
UCTObserver.opened.resolve(win);
|
||||
});
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
break;
|
||||
case "domwindowclosed":
|
||||
if (
|
||||
win.location ==
|
||||
"chrome://mozapps/content/downloads/unknownContentType.xhtml"
|
||||
) {
|
||||
this.closed.resolve();
|
||||
}
|
||||
break;
|
||||
}
|
||||
},
|
||||
};
|
||||
Services.ww.registerNotification(UCTObserver);
|
||||
|
||||
info("Opening new tab with file of unknown content type");
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{
|
||||
gBrowser,
|
||||
url:
|
||||
"http://mochi.test:8888/browser/toolkit/mozapps/downloads/tests/browser/unknownContentType_dialog_layout_data.pif",
|
||||
waitForLoad: false,
|
||||
waitForStateStop: true,
|
||||
},
|
||||
async function() {
|
||||
let uctWindow = await UCTObserver.opened.promise;
|
||||
info("Unknown content type dialog opened");
|
||||
let focusOnDialog = SimpleTest.promiseFocus(uctWindow);
|
||||
uctWindow.focus();
|
||||
await focusOnDialog;
|
||||
uctWindow.document.getElementById("unknownContentType").cancelDialog();
|
||||
info("Unknown content type dialog canceled");
|
||||
uctWindow = null;
|
||||
Services.ww.unregisterNotification(UCTObserver);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -105,8 +105,8 @@ function run_test() {
|
|||
Assert.equal(handlerInfo.possibleApplicationHandlers.length, 0);
|
||||
Assert.equal(
|
||||
handlerInfo.alwaysAskBeforeHandling,
|
||||
!prefSvc.getBoolPref(
|
||||
"browser.download.improvements_to_download_panel",
|
||||
prefSvc.getBoolPref(
|
||||
"browser.download.always_ask_before_handling_new_types",
|
||||
false
|
||||
)
|
||||
);
|
||||
|
|
Загрузка…
Ссылка в новой задаче