Bug 1709671 - Remove redundant ProgID check from IsDefaultBrowser. r=agashlin

Also switch to removing the quotes and command-line parameters from the command
string obtained from the registry before comparing it to our path, instead of
*adding* those things to our path, to make the comparison more reliable.

Differential Revision: https://phabricator.services.mozilla.com/D114383
This commit is contained in:
Molly Howell
2021-07-07 17:33:06 +00:00
parent 2bc9dad000
commit 3d996db854

View File

@@ -32,6 +32,7 @@
#include "mozilla/gfx/2D.h"
#include "WindowsDefaultBrowser.h"
#include "WindowsUserChoice.h"
#include "nsLocalFile.h"
#include <windows.h>
#include <shellapi.h>
@@ -144,7 +145,6 @@ nsresult LaunchHelper(nsAutoString& aPath) {
static bool IsPathDefaultForClass(
const RefPtr<IApplicationAssociationRegistration>& pAAR, wchar_t* exePath,
LPCWSTR aClassName) {
// Make sure the Prog ID matches what we have
LPWSTR registeredApp;
bool isProtocol = *aClassName != L'.';
ASSOCIATIONTYPE queryType = isProtocol ? AT_URLPROTOCOL : AT_FILEEXTENSION;
@@ -154,37 +154,30 @@ static bool IsPathDefaultForClass(
return false;
}
LPCWSTR progID = isProtocol ? L"FirefoxURL" : L"FirefoxHTML";
bool isDefault = !wcsnicmp(registeredApp, progID, wcslen(progID));
nsAutoString regAppName(registeredApp);
CoTaskMemFree(registeredApp);
if (isDefault) {
// Make sure the application path for this progID is this installation.
regAppName.AppendLiteral("\\shell\\open\\command");
HKEY theKey;
nsresult rv = OpenKeyForReading(HKEY_CLASSES_ROOT, regAppName, &theKey);
if (NS_FAILED(rv)) {
return false;
}
wchar_t cmdFromReg[MAX_BUF] = L"";
DWORD len = sizeof(cmdFromReg);
DWORD res = ::RegQueryValueExW(theKey, nullptr, nullptr, nullptr,
(LPBYTE)cmdFromReg, &len);
::RegCloseKey(theKey);
if (REG_FAILED(res)) {
return false;
}
wchar_t fullCmd[MAX_BUF] = L"";
_snwprintf(fullCmd, MAX_BUF, L"\"%s\" -osint -url \"%%1\"", exePath);
isDefault = _wcsicmp(fullCmd, cmdFromReg) == 0;
// Make sure the application path for this progID is this installation.
regAppName.AppendLiteral("\\shell\\open\\command");
HKEY theKey;
nsresult rv = OpenKeyForReading(HKEY_CLASSES_ROOT, regAppName, &theKey);
if (NS_FAILED(rv)) {
return false;
}
return isDefault;
wchar_t cmdFromReg[MAX_BUF] = L"";
DWORD len = sizeof(cmdFromReg);
DWORD res = ::RegQueryValueExW(theKey, nullptr, nullptr, nullptr,
(LPBYTE)cmdFromReg, &len);
::RegCloseKey(theKey);
if (REG_FAILED(res)) {
return false;
}
nsAutoString pathFromReg(cmdFromReg);
nsLocalFile::CleanupCmdHandlerPath(pathFromReg);
return _wcsicmp(exePath, pathFromReg.Data()) == 0;
}
NS_IMETHODIMP