Bug 1357791 - require mAppAssoc (Vista+) API for extension lookup from nsOSHelperAppService.cpp, r=gijs

--HG--
extra : rebase_source : 01fa5e3167e7daa42f93dd530ec27997db7f5836
This commit is contained in:
Ashish 2018-01-31 17:00:56 +00:00
Родитель bf08ef157c
Коммит 99623eaeaa
1 изменённых файлов: 35 добавлений и 90 удалений

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

@ -80,34 +80,16 @@ nsresult nsOSHelperAppService::OSProtocolHandlerExists(const char * aProtocolSch
*aHandlerExists = false;
if (aProtocolScheme && *aProtocolScheme)
{
// Vista: use new application association interface
if (mAppAssoc) {
wchar_t * pResult = nullptr;
NS_ConvertASCIItoUTF16 scheme(aProtocolScheme);
// We are responsible for freeing returned strings.
HRESULT hr = mAppAssoc->QueryCurrentDefault(scheme.get(),
AT_URLPROTOCOL, AL_EFFECTIVE,
&pResult);
if (SUCCEEDED(hr)) {
CoTaskMemFree(pResult);
*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);
NS_ENSURE_TRUE(mAppAssoc, NS_ERROR_NOT_AVAILABLE);
wchar_t * pResult = nullptr;
NS_ConvertASCIItoUTF16 scheme(aProtocolScheme);
// We are responsible for freeing returned strings.
HRESULT hr = mAppAssoc->QueryCurrentDefault(scheme.get(),
AT_URLPROTOCOL, AL_EFFECTIVE,
&pResult);
if (SUCCEEDED(hr)) {
CoTaskMemFree(pResult);
*aHandlerExists = true;
}
}
@ -138,40 +120,20 @@ NS_IMETHODIMP nsOSHelperAppService::GetApplicationDescription(const nsACString&
}
}
if (mAppAssoc) {
// Vista: use new application association interface
wchar_t * pResult = nullptr;
// We are responsible for freeing returned strings.
HRESULT hr = mAppAssoc->QueryCurrentDefault(buf.get(),
AT_URLPROTOCOL, AL_EFFECTIVE,
&pResult);
if (SUCCEEDED(hr)) {
nsCOMPtr<nsIFile> app;
nsAutoString appInfo(pResult);
CoTaskMemFree(pResult);
if (NS_SUCCEEDED(GetDefaultAppInfo(appInfo, _retval, getter_AddRefs(app))))
return NS_OK;
}
return NS_ERROR_NOT_AVAILABLE;
NS_ENSURE_TRUE(mAppAssoc, NS_ERROR_NOT_AVAILABLE);
wchar_t * pResult = nullptr;
// We are responsible for freeing returned strings.
HRESULT hr = mAppAssoc->QueryCurrentDefault(buf.get(),
AT_URLPROTOCOL, AL_EFFECTIVE,
&pResult);
if (SUCCEEDED(hr)) {
nsCOMPtr<nsIFile> app;
nsAutoString appInfo(pResult);
CoTaskMemFree(pResult);
if (NS_SUCCEEDED(GetDefaultAppInfo(appInfo, _retval, getter_AddRefs(app))))
return NS_OK;
}
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;
return NS_ERROR_NOT_AVAILABLE;
}
// GetMIMEInfoFromRegistry: This function obtains the values of some of the nsIMIMEInfo
@ -379,36 +341,19 @@ already_AddRefed<nsMIMEInfoWin> nsOSHelperAppService::GetByExtension(const nsStr
bool found;
// Retrieve the default application for this extension
if (mAppAssoc) {
// Vista: use the new application association COM interfaces
// for resolving helpers.
nsString assocType(fileExtToUse);
wchar_t * pResult = nullptr;
HRESULT hr = mAppAssoc->QueryCurrentDefault(assocType.get(),
AT_FILEEXTENSION, AL_EFFECTIVE,
&pResult);
if (SUCCEEDED(hr)) {
found = true;
appInfo.Assign(pResult);
CoTaskMemFree(pResult);
}
else {
found = false;
}
NS_ENSURE_TRUE(mAppAssoc, nullptr);
nsString assocType(fileExtToUse);
wchar_t * pResult = nullptr;
HRESULT hr = mAppAssoc->QueryCurrentDefault(assocType.get(),
AT_FILEEXTENSION, AL_EFFECTIVE,
&pResult);
if (SUCCEEDED(hr)) {
found = true;
appInfo.Assign(pResult);
CoTaskMemFree(pResult);
}
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));
}
else {
found = false;
}
// Bug 358297 - ignore the default handler, force the user to choose app