restore pre-vista logic that is deleted in 3c02dbad94

This commit is contained in:
Roy Tam 2019-03-24 07:24:27 +08:00
commit aa7849b372

View file

@ -81,7 +81,8 @@ nsresult nsOSHelperAppService::OSProtocolHandlerExists(const char * aProtocolSch
*aHandlerExists = false; *aHandlerExists = false;
if (aProtocolScheme && *aProtocolScheme) if (aProtocolScheme && *aProtocolScheme)
{ {
NS_ENSURE_TRUE(mAppAssoc, NS_ERROR_NOT_AVAILABLE); // Vista: use new application association interface
if (mAppAssoc) {
wchar_t * pResult = nullptr; wchar_t * pResult = nullptr;
NS_ConvertASCIItoUTF16 scheme(aProtocolScheme); NS_ConvertASCIItoUTF16 scheme(aProtocolScheme);
// We are responsible for freeing returned strings. // We are responsible for freeing returned strings.
@ -90,31 +91,25 @@ nsresult nsOSHelperAppService::OSProtocolHandlerExists(const char * aProtocolSch
&pResult); &pResult);
if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) {
CoTaskMemFree(pResult); CoTaskMemFree(pResult);
// Check the registry to see if it's a valid handler.
nsCOMPtr<nsIWindowsRegKey> regKey = do_CreateInstance("@mozilla.org/windows-registry-key;1");
if (!regKey) {
return NS_ERROR_NOT_AVAILABLE;
}
nsresult rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
nsDependentString(scheme.get()),
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
if (NS_FAILED(rv)) {
// Open will fail if the registry key path doesn't exist.
return NS_OK;
}
bool hasValue;
rv = regKey->HasValue(NS_LITERAL_STRING("URL Protocol"), &hasValue);
if (NS_FAILED(rv)) {
return NS_ERROR_FAILURE;
}
if (!hasValue) {
return NS_OK;
}
*aHandlerExists = true; *aHandlerExists = true;
} }
return NS_OK;
}
HKEY hKey;
LONG err = ::RegOpenKeyExW(HKEY_CLASSES_ROOT,
NS_ConvertASCIItoUTF16(aProtocolScheme).get(),
0,
KEY_QUERY_VALUE,
&hKey);
if (err == ERROR_SUCCESS)
{
err = ::RegQueryValueExW(hKey, L"URL Protocol",
nullptr, nullptr, nullptr, nullptr);
*aHandlerExists = (err == ERROR_SUCCESS);
// close the key
::RegCloseKey(hKey);
}
} }
return NS_OK; return NS_OK;
@ -144,7 +139,8 @@ NS_IMETHODIMP nsOSHelperAppService::GetApplicationDescription(const nsACString&
} }
} }
NS_ENSURE_TRUE(mAppAssoc, NS_ERROR_NOT_AVAILABLE); if (mAppAssoc) {
// Vista: use new application association interface
wchar_t * pResult = nullptr; wchar_t * pResult = nullptr;
// We are responsible for freeing returned strings. // We are responsible for freeing returned strings.
HRESULT hr = mAppAssoc->QueryCurrentDefault(buf.get(), HRESULT hr = mAppAssoc->QueryCurrentDefault(buf.get(),
@ -157,8 +153,26 @@ NS_IMETHODIMP nsOSHelperAppService::GetApplicationDescription(const nsACString&
if (NS_SUCCEEDED(GetDefaultAppInfo(appInfo, _retval, getter_AddRefs(app)))) if (NS_SUCCEEDED(GetDefaultAppInfo(appInfo, _retval, getter_AddRefs(app))))
return NS_OK; return NS_OK;
} }
return NS_ERROR_NOT_AVAILABLE; return NS_ERROR_NOT_AVAILABLE;
}
nsCOMPtr<nsIFile> app;
GetDefaultAppInfo(buf, _retval, getter_AddRefs(app));
if (!_retval.Equals(buf))
return NS_OK;
// Fall back to full path
buf.AppendLiteral("\\shell\\open\\command");
nsresult rv = regKey->Open(nsIWindowsRegKey::ROOT_KEY_CLASSES_ROOT,
buf,
nsIWindowsRegKey::ACCESS_QUERY_VALUE);
if (NS_FAILED(rv))
return NS_ERROR_NOT_AVAILABLE;
rv = regKey->ReadStringValue(EmptyString(), _retval);
return NS_SUCCEEDED(rv) ? NS_OK : NS_ERROR_NOT_AVAILABLE;
} }
// GetMIMEInfoFromRegistry: This function obtains the values of some of the nsIMIMEInfo // GetMIMEInfoFromRegistry: This function obtains the values of some of the nsIMIMEInfo
@ -366,7 +380,9 @@ already_AddRefed<nsMIMEInfoWin> nsOSHelperAppService::GetByExtension(const nsAFl
bool found; bool found;
// Retrieve the default application for this extension // Retrieve the default application for this extension
NS_ENSURE_TRUE(mAppAssoc, nullptr); if (mAppAssoc) {
// Vista: use the new application association COM interfaces
// for resolving helpers.
nsString assocType(fileExtToUse); nsString assocType(fileExtToUse);
wchar_t * pResult = nullptr; wchar_t * pResult = nullptr;
HRESULT hr = mAppAssoc->QueryCurrentDefault(assocType.get(), HRESULT hr = mAppAssoc->QueryCurrentDefault(assocType.get(),
@ -376,9 +392,25 @@ already_AddRefed<nsMIMEInfoWin> nsOSHelperAppService::GetByExtension(const nsAFl
found = true; found = true;
appInfo.Assign(pResult); appInfo.Assign(pResult);
CoTaskMemFree(pResult); CoTaskMemFree(pResult);
} else { }
else {
found = false; found = false;
} }
}
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));
}
}
// Bug 358297 - ignore the default handler, force the user to choose app // Bug 358297 - ignore the default handler, force the user to choose app
if (appInfo.EqualsLiteral("XPSViewer.Document")) if (appInfo.EqualsLiteral("XPSViewer.Document"))