Backed out changeset 1e5f2ea404fe (bug 1352348)

This commit is contained in:
Sebastian Hengst 2017-04-19 14:09:06 +02:00
parent 55974edf67
commit 87f4f1adf2
4 changed files with 39 additions and 84 deletions

View File

@ -2729,12 +2729,14 @@ nsExternalHelperAppService::GetTypeFromExtension(const nsACString& aFileExt,
}
// Ask OS.
if (GetMIMETypeFromOSForExtension(aFileExt, aContentType)) {
return NS_OK;
bool found = false;
nsCOMPtr<nsIMIMEInfo> mi = GetMIMEInfoFromOS(EmptyCString(), aFileExt, &found);
if (mi && found) {
return mi->GetMIMEType(aContentType);
}
// Check extras array.
bool found = GetTypeFromExtras(aFileExt, aContentType);
found = GetTypeFromExtras(aFileExt, aContentType);
if (found) {
return NS_OK;
}
@ -2933,11 +2935,3 @@ bool nsExternalHelperAppService::GetTypeFromExtras(const nsACString& aExtension,
return false;
}
bool
nsExternalHelperAppService::GetMIMETypeFromOSForExtension(const nsACString& aExtension, nsACString& aMIMEType)
{
bool found = false;
nsCOMPtr<nsIMIMEInfo> mimeInfo = GetMIMEInfoFromOS(EmptyCString(), aExtension, &found);
return found && mimeInfo && NS_SUCCEEDED(mimeInfo->GetMIMEType(aMIMEType));
}

View File

@ -108,15 +108,6 @@ public:
virtual nsresult OSProtocolHandlerExists(const char *aScheme,
bool *aExists) = 0;
/**
* Given an extension, get a MIME type string. If not overridden by
* the OS-specific nsOSHelperAppService, will call into GetMIMEInfoFromOS
* with an empty mimetype.
* @return true if we successfully found a mimetype.
*/
virtual bool GetMIMETypeFromOSForExtension(const nsACString& aExtension,
nsACString& aMIMEType);
protected:
virtual ~nsExternalHelperAppService();

View File

@ -392,28 +392,46 @@ nsOSHelperAppService::GetDefaultAppInfo(const nsAString& aAppInfo,
already_AddRefed<nsMIMEInfoWin> nsOSHelperAppService::GetByExtension(const nsAFlatString& aFileExt, const char *aTypeHint)
{
if (aExtension.IsEmpty())
if (aFileExt.IsEmpty())
return nullptr;
// Determine the mime type.
nsAutoCString typeToUse;
if (aTypeHint && *aTypeHint) {
typeToUse.Assign(aTypeHint);
} else if (!GetMIMETypeFromOSForExtension(NS_ConvertUTF16toUTF8(aFileExt), typeToUse)) {
return nullptr;
}
RefPtr<nsMIMEInfoWin> mimeInfo = new nsMIMEInfoWin(typeToUse);
// windows registry assumes your file extension is going to include the '.',
// but our APIs expect it to not be there, so make sure we normalize that bit.
// windows registry assumes your file extension is going to include the '.'.
// so make sure it's there...
nsAutoString fileExtToUse;
if (aFileExt.First() != char16_t('.'))
fileExtToUse = char16_t('.');
fileExtToUse.Append(aFileExt);
// don't append the '.' for our APIs.
// Try to get an entry from the windows registry.
nsCOMPtr<nsIWindowsRegKey> regKey =
do_CreateInstance("@mozilla.org/windows-registry-key;1");
if (!regKey)
return nullptr;
nsresult rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
fileExtToUse,
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
if (NS_FAILED(rv))
return nullptr;
nsAutoCString typeToUse;
if (aTypeHint && *aTypeHint) {
typeToUse.Assign(aTypeHint);
}
else {
nsAutoString temp;
if (NS_FAILED(regKey->ReadStringValue(NS_LITERAL_STRING("Content Type"),
temp)) || temp.IsEmpty()) {
return nullptr;
}
// Content-Type is always in ASCII
LossyAppendUTF16toASCII(temp, typeToUse);
}
RefPtr<nsMIMEInfoWin> mimeInfo = new nsMIMEInfoWin(typeToUse);
// don't append the '.'
mimeInfo->AppendExtension(NS_ConvertUTF16toUTF8(Substring(fileExtToUse, 1)));
mimeInfo->SetPreferredAction(nsIMIMEInfo::useSystemDefault);
@ -440,17 +458,8 @@ already_AddRefed<nsMIMEInfoWin> nsOSHelperAppService::GetByExtension(const nsAFl
}
else
{
nsCOMPtr<nsIWindowsRegKey> regKey =
do_CreateInstance("@mozilla.org/windows-registry-key;1");
if (!regKey)
return nullptr;
nsresult rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
fileExtToUse,
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
if (NS_SUCCEEDED(rv)) {
found = NS_SUCCEEDED(regKey->ReadStringValue(EmptyString(),
appInfo));
}
found = NS_SUCCEEDED(regKey->ReadStringValue(EmptyString(),
appInfo));
}
// Bug 358297 - ignore the default handler, force the user to choose app
@ -588,40 +597,3 @@ nsOSHelperAppService::GetProtocolHandlerInfoFromOS(const nsACString &aScheme,
return NS_OK;
}
bool
nsOSHelperAppService::GetMIMETypeFromOSForExtension(const nsACString& aExtension,
nsACString& aMIMEType)
{
if (aExtension.IsEmpty())
return false;
// windows registry assumes your file extension is going to include the '.'.
// so make sure it's there...
nsAutoString fileExtToUse;
if (aExtension.First() != '.')
fileExtToUse = char16_t('.');
AppendUTF8toUTF16(aExtension, fileExtToUse);
// Try to get an entry from the windows registry.
nsCOMPtr<nsIWindowsRegKey> regKey =
do_CreateInstance("@mozilla.org/windows-registry-key;1");
if (!regKey)
return false;
nsresult rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
fileExtToUse,
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
if (NS_FAILED(rv))
return false;
nsAutoString mimeType;
if (NS_FAILED(regKey->ReadStringValue(NS_LITERAL_STRING("Content Type"),
mimeType)) || mimeType.IsEmpty()) {
return false;
}
// Content-Type is always in ASCII
aMIMEType.Truncate();
LossyAppendUTF16toASCII(mimeType, aMIMEType);
return true;
}

View File

@ -40,8 +40,6 @@ public:
NS_IMETHOD GetProtocolHandlerInfoFromOS(const nsACString &aScheme,
bool *found,
nsIHandlerInfo **_retval);
virtual bool GetMIMETypeFromOSForExtension(const nsACString& aExtension,
nsACString& aMIMEType) override;
/** Get the string value of a registry value and store it in result.
* @return true on success, false on failure