Backed out changeset 4d700219feab (bug 1571247) for xpcshell failures on test_getMIMEInfo_pdf.js. CLOSED TREE

This commit is contained in:
Cosmin Sabou 2020-08-20 06:20:21 +03:00
Родитель 862e95da94
Коммит d54210d490
2 изменённых файлов: 6 добавлений и 46 удалений

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

@ -487,7 +487,7 @@ static const nsExtraMimeTypeEntry extraMimeEntries[] = {
{IMAGE_BMP, "bmp", "BMP Image"}, {IMAGE_BMP, "bmp", "BMP Image"},
{IMAGE_GIF, "gif", "GIF Image"}, {IMAGE_GIF, "gif", "GIF Image"},
{IMAGE_ICO, "ico,cur", "ICO Image"}, {IMAGE_ICO, "ico,cur", "ICO Image"},
{IMAGE_JPEG, "jpg,jpeg,jfif,pjpeg,pjp", "JPEG Image"}, {IMAGE_JPEG, "jpeg,jpg,jfif,pjpeg,pjp", "JPEG Image"},
{IMAGE_PNG, "png", "PNG Image"}, {IMAGE_PNG, "png", "PNG Image"},
{IMAGE_APNG, "apng", "APNG Image"}, {IMAGE_APNG, "apng", "APNG Image"},
{IMAGE_TIFF, "tiff,tif", "TIFF Image"}, {IMAGE_TIFF, "tiff,tif", "TIFF Image"},
@ -528,9 +528,6 @@ static const nsExtraMimeTypeEntry extraMimeEntries[] = {
{AUDIO_MIDI, "mid", "Standard MIDI Audio"}, {AUDIO_MIDI, "mid", "Standard MIDI Audio"},
{APPLICATION_WASM, "wasm", "WebAssembly Module"}}; {APPLICATION_WASM, "wasm", "WebAssembly Module"}};
static const nsDefaultMimeTypeEntry sForbiddenPrimaryExtensions[] = {
{IMAGE_JPEG, "jfif"}};
/** /**
* File extensions for which decoding should be disabled. * File extensions for which decoding should be disabled.
* NOTE: These MUST be lower-case and ASCII. * NOTE: These MUST be lower-case and ASCII.
@ -2634,18 +2631,6 @@ NS_IMETHODIMP nsExternalHelperAppService::GetFromTypeAndExtension(
LOG(("Falling back to 'File' file description\n")); LOG(("Falling back to 'File' file description\n"));
} }
// Sometimes, OSes give us bad data. We have a set of forbidden extensions
// for some MIME types. If the primary extension is forbidden,
// overwrite it with a known-good one. See bug 1571247 for context.
nsAutoCString primaryExtension;
(*_retval)->GetPrimaryExtension(primaryExtension);
if (!primaryExtension.LowerCaseEqualsASCII(
PromiseFlatCString(aFileExt).get())) {
if (MaybeReplacePrimaryExtension(primaryExtension, *_retval)) {
(*_retval)->GetPrimaryExtension(primaryExtension);
}
}
// Finally, check if we got a file extension and if yes, if it is an // Finally, check if we got a file extension and if yes, if it is an
// extension on the mimeinfo, in which case we want it to be the primary one // extension on the mimeinfo, in which case we want it to be the primary one
if (!aFileExt.IsEmpty()) { if (!aFileExt.IsEmpty()) {
@ -2657,7 +2642,6 @@ NS_IMETHODIMP nsExternalHelperAppService::GetFromTypeAndExtension(
nsAutoCString fileExt; nsAutoCString fileExt;
ToLowerCase(aFileExt, fileExt); ToLowerCase(aFileExt, fileExt);
(*_retval)->SetPrimaryExtension(fileExt); (*_retval)->SetPrimaryExtension(fileExt);
primaryExtension = fileExt;
} }
} }
@ -2665,6 +2649,8 @@ NS_IMETHODIMP nsExternalHelperAppService::GetFromTypeAndExtension(
// type is in our list; these are file formats supported by Firefox and // type is in our list; these are file formats supported by Firefox and
// we don't want other brands positioning themselves as the sole viewer // we don't want other brands positioning themselves as the sole viewer
// for a system. // for a system.
nsAutoCString primaryExtension;
rv = (*_retval)->GetPrimaryExtension(primaryExtension);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
for (const char* ext : descriptionOverwriteExtensions) { for (const char* ext : descriptionOverwriteExtensions) {
if (primaryExtension.Equals(ext)) { if (primaryExtension.Equals(ext)) {
@ -2694,8 +2680,10 @@ NS_IMETHODIMP nsExternalHelperAppService::GetFromTypeAndExtension(
nsAutoCString type; nsAutoCString type;
(*_retval)->GetMIMEType(type); (*_retval)->GetMIMEType(type);
nsAutoCString ext;
(*_retval)->GetPrimaryExtension(ext);
LOG(("MIME Info Summary: Type '%s', Primary Ext '%s'\n", type.get(), LOG(("MIME Info Summary: Type '%s', Primary Ext '%s'\n", type.get(),
primaryExtension.get())); ext.get()));
} }
return NS_OK; return NS_OK;
@ -2902,26 +2890,6 @@ nsresult nsExternalHelperAppService::FillMIMEInfoForExtensionFromExtras(
return FillMIMEInfoForMimeTypeFromExtras(type, true, aMIMEInfo); return FillMIMEInfoForMimeTypeFromExtras(type, true, aMIMEInfo);
} }
bool nsExternalHelperAppService::MaybeReplacePrimaryExtension(
const nsACString& aPrimaryExtension, nsIMIMEInfo* aMIMEInfo) {
for (const auto& entry : sForbiddenPrimaryExtensions) {
if (aPrimaryExtension.LowerCaseEqualsASCII(entry.mFileExtension)) {
nsDependentCString mime(entry.mMimeType);
for (const auto& extraEntry : extraMimeEntries) {
if (mime.LowerCaseEqualsASCII(extraEntry.mMimeType)) {
nsDependentCString goodExts(extraEntry.mFileExtensions);
int32_t commaPos = goodExts.FindChar(',');
commaPos = commaPos == kNotFound ? goodExts.Length() : commaPos;
auto goodExt = Substring(goodExts, 0, commaPos);
aMIMEInfo->SetPrimaryExtension(goodExt);
return true;
}
}
}
}
return false;
}
bool nsExternalHelperAppService::GetTypeFromExtras(const nsACString& aExtension, bool nsExternalHelperAppService::GetTypeFromExtras(const nsACString& aExtension,
nsACString& aMIMEType) { nsACString& aMIMEType) {
NS_ASSERTION(!aExtension.IsEmpty(), "Empty aExtension parameter!"); NS_ASSERTION(!aExtension.IsEmpty(), "Empty aExtension parameter!");

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

@ -143,14 +143,6 @@ class nsExternalHelperAppService : public nsIExternalHelperAppService,
nsresult FillMIMEInfoForExtensionFromExtras(const nsACString& aExtension, nsresult FillMIMEInfoForExtensionFromExtras(const nsACString& aExtension,
nsIMIMEInfo* aMIMEInfo); nsIMIMEInfo* aMIMEInfo);
/**
* Replace the primary extension of the mimeinfo object if it's in our
* list of forbidden extensions. This fixes up broken information
* provided to us by the OS.
*/
bool MaybeReplacePrimaryExtension(const nsACString& aPrimaryExtension,
nsIMIMEInfo* aMIMEInfo);
/** /**
* Searches the "extra" array for a MIME type, and gets its extension. * Searches the "extra" array for a MIME type, and gets its extension.
* @param aExtension The extension to search for * @param aExtension The extension to search for