зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1836027 - Remove browser.download.improvements_to_download_panel migrations r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D180290
This commit is contained in:
Родитель
ae2b303e03
Коммит
fcc5b10abb
|
@ -4240,48 +4240,6 @@ 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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Bug 1769071: The UI Version 127 was used for a clean up code that is not
|
||||
// necessary anymore. Please do not use 127 because this number is probably
|
||||
// set in Nightly and Beta channel.
|
||||
|
||||
// Non-macOS only (on macOS we've never used the tmp folder for downloads):
|
||||
if (AppConstants.platform != "macosx" && currentUIVersion < 128) {
|
||||
// Bug 1738574 - Add a pref to start downloads in the tmp folder.
|
||||
// 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.start_downloads_in_tmp_dir",
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function migrateXULAttributeToStyle(url, id, attr) {
|
||||
try {
|
||||
let value = Services.xulStore.getValue(url, id, attr);
|
||||
|
|
|
@ -23,13 +23,6 @@ ChromeUtils.defineESModuleGetters(lazy, {
|
|||
FileUtils: "resource://gre/modules/FileUtils.sys.mjs",
|
||||
JSONFile: "resource://gre/modules/JSONFile.sys.mjs",
|
||||
});
|
||||
import { Integration } from "resource://gre/modules/Integration.sys.mjs";
|
||||
|
||||
Integration.downloads.defineESModuleGetter(
|
||||
lazy,
|
||||
"DownloadIntegration",
|
||||
"resource://gre/modules/DownloadIntegration.sys.mjs"
|
||||
);
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(
|
||||
lazy,
|
||||
|
@ -84,12 +77,6 @@ HandlerService.prototype = {
|
|||
this._migrateProtocolHandlersIfNeeded();
|
||||
|
||||
Services.obs.notifyObservers(null, "handlersvc-store-initialized");
|
||||
|
||||
// Bug 1736924: run migration for browser.download.improvements_to_download_panel if applicable.
|
||||
// Since we need DownloadsViewInternally to verify mimetypes, we run this after
|
||||
// DownloadsViewInternally is registered via the 'handlersvc-store-initialized' notification.
|
||||
this._migrateDownloadsImprovementsIfNeeded();
|
||||
this._migrateSVGXMLIfNeeded();
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -351,82 +338,6 @@ HandlerService.prototype = {
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Update already existing handlers for non-internal mimetypes to have prefs set from alwaysAsk
|
||||
* to saveToDisk. However, if reading an internal mimetype and set to alwaysAsk, update to use handleInternally.
|
||||
* This migration is needed since browser.download.improvements_to_download_panel does not
|
||||
* override user preferences if preferredAction = alwaysAsk. By doing so, we can ensure that file prompt
|
||||
* behaviours remain consistent for most files.
|
||||
*
|
||||
* See Bug 1736924 for more information.
|
||||
*/
|
||||
_noInternalHandlingDefault: new Set([
|
||||
"text/xml",
|
||||
"application/xml",
|
||||
"image/svg+xml",
|
||||
]),
|
||||
_migrateDownloadsImprovementsIfNeeded() {
|
||||
// Migrate if the migration has never been run before.
|
||||
// Otherwise, we risk overwriting preferences for existing profiles!
|
||||
if (
|
||||
Services.prefs.getBoolPref(
|
||||
"browser.download.improvements_to_download_panel",
|
||||
true
|
||||
) &&
|
||||
!Services.policies?.getActivePolicies()?.Handlers &&
|
||||
!this._store.data.isDownloadsImprovementsAlreadyMigrated &&
|
||||
AppConstants.MOZ_APP_NAME != "thunderbird"
|
||||
) {
|
||||
for (let [type, mimeInfo] of Object.entries(this._store.data.mimeTypes)) {
|
||||
let isViewableInternally =
|
||||
lazy.DownloadIntegration.shouldViewDownloadInternally(type) &&
|
||||
!this._noInternalHandlingDefault.has(type);
|
||||
let isAskOnly = mimeInfo && mimeInfo.ask;
|
||||
|
||||
if (isAskOnly) {
|
||||
if (isViewableInternally) {
|
||||
mimeInfo.action = handleInternally;
|
||||
} else {
|
||||
mimeInfo.action = saveToDisk;
|
||||
}
|
||||
|
||||
// Sets alwaysAskBeforeHandling to false. Needed to ensure that:
|
||||
// preferredAction appears as expected in preferences table; and
|
||||
// downloads behaviour is updated to never show UCT window.
|
||||
mimeInfo.ask = false;
|
||||
}
|
||||
}
|
||||
|
||||
this._store.data.isDownloadsImprovementsAlreadyMigrated = true;
|
||||
this._store.saveSoon();
|
||||
}
|
||||
},
|
||||
|
||||
_migrateSVGXMLIfNeeded() {
|
||||
// Migrate if the migration has never been run before.
|
||||
// We need to make sure we only run this once.
|
||||
if (
|
||||
Services.prefs.getBoolPref(
|
||||
"browser.download.improvements_to_download_panel",
|
||||
true
|
||||
) &&
|
||||
!Services.policies?.getActivePolicies()?.Handlers &&
|
||||
!this._store.data.isSVGXMLAlreadyMigrated
|
||||
) {
|
||||
for (let type of this._noInternalHandlingDefault) {
|
||||
if (Object.hasOwn(this._store.data.mimeTypes, type)) {
|
||||
let mimeInfo = this._store.data.mimeTypes[type];
|
||||
if (!mimeInfo.ask && mimeInfo.action == handleInternally) {
|
||||
mimeInfo.action = saveToDisk;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this._store.data.isSVGXMLAlreadyMigrated = true;
|
||||
this._store.saveSoon();
|
||||
}
|
||||
},
|
||||
|
||||
// nsIHandlerService
|
||||
enumerate() {
|
||||
let handlers = Cc["@mozilla.org/array;1"].createInstance(
|
||||
|
@ -493,11 +404,7 @@ HandlerService.prototype = {
|
|||
// For files (ie mimetype rather than protocol handling info), ensure
|
||||
// we can store the "always ask" state, too:
|
||||
(handlerInfo.preferredAction == alwaysAsk &&
|
||||
this._isMIMEInfo(handlerInfo) &&
|
||||
Services.prefs.getBoolPref(
|
||||
"browser.download.improvements_to_download_panel",
|
||||
true
|
||||
))
|
||||
this._isMIMEInfo(handlerInfo))
|
||||
) {
|
||||
storedHandlerInfo.action = handlerInfo.preferredAction;
|
||||
} else {
|
||||
|
|
|
@ -1,244 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const handlerSvc = Cc["@mozilla.org/uriloader/handler-service;1"].getService(
|
||||
Ci.nsIHandlerService
|
||||
);
|
||||
|
||||
const mimeSvc = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
|
||||
|
||||
const { Integration } = ChromeUtils.importESModule(
|
||||
"resource://gre/modules/Integration.sys.mjs"
|
||||
);
|
||||
|
||||
/* global DownloadIntegration */
|
||||
Integration.downloads.defineESModuleGetter(
|
||||
this,
|
||||
"DownloadIntegration",
|
||||
"resource://gre/modules/DownloadIntegration.sys.mjs"
|
||||
);
|
||||
|
||||
/**
|
||||
* Tests that the migration runs and that only
|
||||
* files with preferredAction alwaysAsk are updated.
|
||||
*/
|
||||
add_task(async function test_migration() {
|
||||
// Create mock implementation of shouldDownloadInternally for test case
|
||||
let oldShouldViewDownloadInternally =
|
||||
DownloadIntegration.shouldViewDownloadInternally;
|
||||
DownloadIntegration.shouldViewDownloadInternally = (mimeType, extension) => {
|
||||
let downloadTypesViewableInternally = [
|
||||
{
|
||||
extension: "pdf",
|
||||
mimeTypes: ["application/pdf"],
|
||||
},
|
||||
{
|
||||
extension: "webp",
|
||||
mimeTypes: ["image/webp"],
|
||||
},
|
||||
];
|
||||
|
||||
for (const mockHandler of downloadTypesViewableInternally) {
|
||||
if (mockHandler.mimeTypes.includes(mimeType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
registerCleanupFunction(async function () {
|
||||
Services.prefs.clearUserPref(
|
||||
"browser.download.improvements_to_download_panel"
|
||||
);
|
||||
DownloadIntegration.shouldViewDownloadInternally =
|
||||
oldShouldViewDownloadInternally;
|
||||
});
|
||||
|
||||
// For setup, set pref to false. Will be enabled later.
|
||||
Services.prefs.setBoolPref(
|
||||
"browser.download.improvements_to_download_panel",
|
||||
false
|
||||
);
|
||||
|
||||
// Plain text file
|
||||
let txtHandlerInfo = mimeSvc.getFromTypeAndExtension("text/plain", "txt");
|
||||
txtHandlerInfo.preferredAction = Ci.nsIHandlerInfo.alwaysAsk;
|
||||
txtHandlerInfo.alwaysAskBeforeHandling = true;
|
||||
// PDF file
|
||||
let pdfHandlerInfo = mimeSvc.getFromTypeAndExtension(
|
||||
"application/pdf",
|
||||
"pdf"
|
||||
);
|
||||
pdfHandlerInfo.preferredAction = Ci.nsIHandlerInfo.alwaysAsk;
|
||||
pdfHandlerInfo.alwaysAskBeforeHandling = true;
|
||||
// WebP file
|
||||
let webpHandlerInfo = mimeSvc.getFromTypeAndExtension("image/webp", "webp");
|
||||
webpHandlerInfo.preferredAction = Ci.nsIHandlerInfo.useSystemDefault;
|
||||
webpHandlerInfo.alwaysAskBeforeHandling = false;
|
||||
|
||||
handlerSvc.store(txtHandlerInfo);
|
||||
handlerSvc.store(pdfHandlerInfo);
|
||||
handlerSvc.store(webpHandlerInfo);
|
||||
|
||||
Services.prefs.setBoolPref(
|
||||
"browser.download.improvements_to_download_panel",
|
||||
true
|
||||
);
|
||||
gHandlerService.wrappedJSObject._migrateDownloadsImprovementsIfNeeded();
|
||||
|
||||
txtHandlerInfo = mimeSvc.getFromTypeAndExtension("text/plain", "txt");
|
||||
pdfHandlerInfo = mimeSvc.getFromTypeAndExtension("application/pdf", "pdf");
|
||||
webpHandlerInfo = mimeSvc.getFromTypeAndExtension("image/webp", "webp");
|
||||
let data = gHandlerService.wrappedJSObject._store.data;
|
||||
Assert.equal(
|
||||
data.isDownloadsImprovementsAlreadyMigrated,
|
||||
true,
|
||||
"isDownloadsImprovementsAlreadyMigrated should be set to true"
|
||||
);
|
||||
Assert.equal(
|
||||
pdfHandlerInfo.preferredAction,
|
||||
Ci.nsIHandlerInfo.handleInternally,
|
||||
"application/pdf - preferredAction should be handleInternally"
|
||||
);
|
||||
Assert.equal(
|
||||
pdfHandlerInfo.alwaysAskBeforeHandling,
|
||||
false,
|
||||
"application/pdf - alwaysAskBeforeHandling should be false"
|
||||
);
|
||||
Assert.equal(
|
||||
webpHandlerInfo.preferredAction,
|
||||
Ci.nsIHandlerInfo.useSystemDefault,
|
||||
"image/webp - preferredAction should be useSystemDefault"
|
||||
);
|
||||
Assert.equal(
|
||||
webpHandlerInfo.alwaysAskBeforeHandling,
|
||||
false,
|
||||
"image/webp - alwaysAskBeforeHandling should be false"
|
||||
);
|
||||
Assert.equal(
|
||||
txtHandlerInfo.preferredAction,
|
||||
Ci.nsIHandlerInfo.saveToDisk,
|
||||
"text/plain - preferredAction should be saveToDisk"
|
||||
);
|
||||
Assert.equal(
|
||||
txtHandlerInfo.alwaysAskBeforeHandling,
|
||||
false,
|
||||
"text/plain - alwaysAskBeforeHandling should be false"
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* Tests that the migration does not run if the migration was already run.
|
||||
*/
|
||||
add_task(async function test_migration_already_run() {
|
||||
let data = gHandlerService.wrappedJSObject._store.data;
|
||||
data.isDownloadsImprovementsAlreadyMigrated = true;
|
||||
|
||||
// Plain text file
|
||||
let txtHandlerInfo = mimeSvc.getFromTypeAndExtension("text/plain", "txt");
|
||||
txtHandlerInfo.preferredAction = Ci.nsIHandlerInfo.alwaysAsk;
|
||||
txtHandlerInfo.alwaysAskBeforeHandling = true;
|
||||
// PDF file
|
||||
let pdfHandlerInfo = mimeSvc.getFromTypeAndExtension(
|
||||
"application/pdf",
|
||||
"pdf"
|
||||
);
|
||||
pdfHandlerInfo.preferredAction = Ci.nsIHandlerInfo.alwaysAsk;
|
||||
pdfHandlerInfo.alwaysAskBeforeHandling = true;
|
||||
|
||||
handlerSvc.store(txtHandlerInfo);
|
||||
handlerSvc.store(pdfHandlerInfo);
|
||||
|
||||
gHandlerService.wrappedJSObject._migrateDownloadsImprovementsIfNeeded();
|
||||
|
||||
txtHandlerInfo = mimeSvc.getFromTypeAndExtension("text/plain", "txt");
|
||||
pdfHandlerInfo = mimeSvc.getFromTypeAndExtension("application/pdf", "pdf");
|
||||
data = gHandlerService.wrappedJSObject._store.data;
|
||||
Assert.equal(
|
||||
pdfHandlerInfo.preferredAction,
|
||||
Ci.nsIHandlerInfo.alwaysAsk,
|
||||
"application/pdf - preferredAction should be alwaysAsk"
|
||||
);
|
||||
Assert.equal(
|
||||
pdfHandlerInfo.alwaysAskBeforeHandling,
|
||||
true,
|
||||
"application/pdf - alwaysAskBeforeHandling should be true"
|
||||
);
|
||||
Assert.equal(
|
||||
txtHandlerInfo.preferredAction,
|
||||
Ci.nsIHandlerInfo.alwaysAsk,
|
||||
"text/plain - preferredAction should be alwaysAsk"
|
||||
);
|
||||
Assert.equal(
|
||||
txtHandlerInfo.alwaysAskBeforeHandling,
|
||||
true,
|
||||
"text/plain - alwaysAskBeforeHandling should be true"
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* Test migration of SVG and XML info.
|
||||
*/
|
||||
add_task(async function test_migration_xml_svg() {
|
||||
let data = gHandlerService.wrappedJSObject._store.data;
|
||||
// Plain text file
|
||||
let txtHandlerInfo = mimeSvc.getFromTypeAndExtension("text/plain", "txt");
|
||||
txtHandlerInfo.preferredAction = Ci.nsIHandlerInfo.alwaysAsk;
|
||||
txtHandlerInfo.alwaysAskBeforeHandling = true;
|
||||
// SVG file
|
||||
let svgHandlerInfo = mimeSvc.getFromTypeAndExtension("image/svg+xml", "svg");
|
||||
svgHandlerInfo.preferredAction = Ci.nsIHandlerInfo.handleInternally;
|
||||
svgHandlerInfo.alwaysAskBeforeHandling = false;
|
||||
// XML file
|
||||
let xmlHandlerInfo = mimeSvc.getFromTypeAndExtension("text/xml", "xml");
|
||||
xmlHandlerInfo.preferredAction = Ci.nsIHandlerInfo.handleInternally;
|
||||
xmlHandlerInfo.alwaysAskBeforeHandling = false;
|
||||
|
||||
handlerSvc.store(txtHandlerInfo);
|
||||
handlerSvc.store(svgHandlerInfo);
|
||||
handlerSvc.store(xmlHandlerInfo);
|
||||
|
||||
gHandlerService.wrappedJSObject._migrateSVGXMLIfNeeded();
|
||||
|
||||
txtHandlerInfo = mimeSvc.getFromTypeAndExtension("text/plain", "txt");
|
||||
svgHandlerInfo = mimeSvc.getFromTypeAndExtension("image/svg+xml", "svg");
|
||||
xmlHandlerInfo = mimeSvc.getFromTypeAndExtension("text/xml", "xml");
|
||||
data = gHandlerService.wrappedJSObject._store.data;
|
||||
Assert.equal(
|
||||
svgHandlerInfo.preferredAction,
|
||||
Ci.nsIHandlerInfo.saveToDisk,
|
||||
"image/svg+xml - preferredAction should be saveToDisk"
|
||||
);
|
||||
Assert.equal(
|
||||
svgHandlerInfo.alwaysAskBeforeHandling,
|
||||
false,
|
||||
"image/svg+xml - alwaysAskBeforeHandling should be false"
|
||||
);
|
||||
Assert.equal(
|
||||
xmlHandlerInfo.preferredAction,
|
||||
Ci.nsIHandlerInfo.saveToDisk,
|
||||
"text/xml - preferredAction should be saveToDisk"
|
||||
);
|
||||
Assert.equal(
|
||||
xmlHandlerInfo.alwaysAskBeforeHandling,
|
||||
false,
|
||||
"text/xml - alwaysAskBeforeHandling should be false"
|
||||
);
|
||||
Assert.equal(
|
||||
txtHandlerInfo.preferredAction,
|
||||
Ci.nsIHandlerInfo.alwaysAsk,
|
||||
"text/plain - preferredAction should be alwaysAsk"
|
||||
);
|
||||
Assert.equal(
|
||||
txtHandlerInfo.alwaysAskBeforeHandling,
|
||||
true,
|
||||
"text/plain - alwaysAskBeforeHandling should be true"
|
||||
);
|
||||
|
||||
ok(
|
||||
data.isSVGXMLAlreadyMigrated,
|
||||
"Should have stored migration state on the data object."
|
||||
);
|
||||
});
|
|
@ -6,12 +6,6 @@ firefox-appdir = browser
|
|||
[test_defaults_handlerService.js]
|
||||
# No default stored handlers on android given lack of support.
|
||||
# No default stored handlers on Thunderbird.
|
||||
skip-if =
|
||||
os == "android"
|
||||
appname == "thunderbird"
|
||||
[test_downloads_improvements_migration.js]
|
||||
# No default stored handlers on android given lack of support.
|
||||
# No default stored handlers on Thunderbird.
|
||||
skip-if =
|
||||
os == "android"
|
||||
appname == "thunderbird"
|
||||
|
|
Загрузка…
Ссылка в новой задаче