зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1609466 - offer 'open with' options even when Windows is clueless about the mimetype, r=bzbarsky
We currently fail to offer 'open with' options for application/zip mimetype .zip files, because out of the box, the Windows registry does not contain mimetype entries for application/zip. In fact, it contains comparatively few entries, and right now we bail out with an empty mime info object if we cannot find the server-provided mimetype in the registry (or cannot find an associated extension for that mimetype). Prior to the changes from bug 1597985, we would first try to find a handler based on the default extension for the mimetype, and used the file extension if that failed. The changes in this commit will cause us to fetch the default file extension for the mimetype, but continue with the provided extension if no mimetype information is available, restoring functionality in the case where Windows has no mimetype information. Differential Revision: https://phabricator.services.mozilla.com/D60139 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
063ff0ea9e
Коммит
94f489a33f
|
@ -0,0 +1,32 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
// Zip files can be opened by Windows explorer, so we should always be able to
|
||||
// determine a description and default handler for them. However, things can
|
||||
// get messy if they are sent to us with a mime type other than what Windows
|
||||
// considers the "right" mimetype (application/x-zip-compressed), like
|
||||
// application/zip, which is what most places (IANA, macOS, probably all linux
|
||||
// distros, Apache, etc.) think is the "right" mimetype.
|
||||
add_task(async function test_check_unknown_mime_type() {
|
||||
const mimeService = Cc["@mozilla.org/mime;1"].getService(Ci.nsIMIMEService);
|
||||
let zipType = mimeService.getTypeFromExtension("zip");
|
||||
Assert.equal(zipType, "application/x-zip-compressed");
|
||||
try {
|
||||
let extension = mimeService.getPrimaryExtension("application/zip", "");
|
||||
Assert.ok(!extension, "Expect no known extension for zip files.");
|
||||
} catch (ex) {
|
||||
Assert.ok(
|
||||
ex,
|
||||
"We'll take an exception instead of an empty string, I guess."
|
||||
);
|
||||
}
|
||||
let found = {};
|
||||
let mimeInfo = mimeService.getMIMEInfoFromOS("application/zip", "zip", found);
|
||||
Assert.ok(
|
||||
found.value,
|
||||
"Should be able to find mime info even for the unknown mimetype."
|
||||
);
|
||||
Assert.ok(mimeInfo.hasDefaultHandler, "Should have a default app");
|
||||
});
|
|
@ -3,9 +3,11 @@ head = head.js
|
|||
run-sequentially = Bug 912235 - Intermittent failures
|
||||
firefox-appdir = browser
|
||||
|
||||
[test_getMIMEInfo_unknown_mime_type.js]
|
||||
run-if = os == "win" # Windows only test
|
||||
[test_getTypeFromExtension_ext_to_type_mapping.js]
|
||||
[test_getTypeFromExtension_with_empty_Content_Type.js]
|
||||
skip-if = os != "win" # Windows only test
|
||||
run-if = os == "win" # Windows only test
|
||||
[test_badMIMEType.js]
|
||||
[test_handlerService.js]
|
||||
skip-if = (verify && (os == 'win'))
|
||||
|
|
|
@ -447,25 +447,21 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aMIMEType,
|
|||
RefPtr<nsMIMEInfoWin> mi;
|
||||
|
||||
// We should have *something* to go on here.
|
||||
if (fileExtension.IsEmpty() && !haveMeaningfulMimeType) {
|
||||
nsAutoString extensionFromMimeType;
|
||||
if (haveMeaningfulMimeType) {
|
||||
GetExtensionFromWindowsMimeDatabase(aMIMEType, extensionFromMimeType);
|
||||
}
|
||||
if (fileExtension.IsEmpty() && extensionFromMimeType.IsEmpty()) {
|
||||
// Without an extension from the mimetype or the file, we can't
|
||||
// do anything here.
|
||||
mi = new nsMIMEInfoWin(flatType.get());
|
||||
if (!aFileExt.IsEmpty()) {
|
||||
mi->AppendExtension(aFileExt);
|
||||
}
|
||||
mi.forget(aMIMEInfo);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsAutoString extensionFromMimeType;
|
||||
if (haveMeaningfulMimeType) {
|
||||
GetExtensionFromWindowsMimeDatabase(aMIMEType, extensionFromMimeType);
|
||||
if (extensionFromMimeType.IsEmpty()) {
|
||||
// We can't verify the mime type and file extension make sense.
|
||||
mi = new nsMIMEInfoWin(flatType.get());
|
||||
if (!aFileExt.IsEmpty()) {
|
||||
mi->AppendExtension(aFileExt);
|
||||
}
|
||||
mi.forget(aMIMEInfo);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
// Either fileExtension or extensionFromMimeType must now be non-empty.
|
||||
|
||||
*aFound = true;
|
||||
|
@ -476,7 +472,7 @@ nsOSHelperAppService::GetMIMEInfoFromOS(const nsACString& aMIMEType,
|
|||
// mime type's default file extension instead.
|
||||
bool usedMimeTypeExtensionForLookup = false;
|
||||
if (fileExtension.IsEmpty() ||
|
||||
(haveMeaningfulMimeType &&
|
||||
(!extensionFromMimeType.IsEmpty() &&
|
||||
!typeFromExtEquals(fileExtension.get(), flatType.get()))) {
|
||||
usedMimeTypeExtensionForLookup = true;
|
||||
fileExtension = extensionFromMimeType;
|
||||
|
|
Загрузка…
Ссылка в новой задаче