Bug 1761504 - Add setDefaultPDFHandlerOnlyReplaceBrowsers Nimbus feature. r=bhearsum

When enabled, this feature restricts the existing
`setDefaultPDFHandler` Nimbus feature to only set Firefox as the
default PDF handler when the existing handler is a known browser.

Depends on D142147

Differential Revision: https://phabricator.services.mozilla.com/D142148
This commit is contained in:
Nick Alexander
2022-03-29 03:57:00 +00:00
parent 3358d84729
commit d20c0ed4b1
6 changed files with 206 additions and 4 deletions

View File

@@ -242,6 +242,37 @@ nsWindowsShellService::IsDefaultHandlerFor(
return NS_OK;
}
NS_IMETHODIMP
nsWindowsShellService::QueryCurrentDefaultHandlerFor(
const nsAString& aFileExtensionOrProtocol, nsAString& aResult) {
aResult.Truncate();
RefPtr<IApplicationAssociationRegistration> pAAR;
HRESULT hr = CoCreateInstance(
CLSID_ApplicationAssociationRegistration, nullptr, CLSCTX_INPROC,
IID_IApplicationAssociationRegistration, getter_AddRefs(pAAR));
if (FAILED(hr)) {
return NS_OK;
}
const nsString& flatClass = PromiseFlatString(aFileExtensionOrProtocol);
LPWSTR registeredApp;
bool isProtocol = flatClass.First() != L'.';
ASSOCIATIONTYPE queryType = isProtocol ? AT_URLPROTOCOL : AT_FILEEXTENSION;
hr = pAAR->QueryCurrentDefault(flatClass.get(), queryType, AL_EFFECTIVE,
&registeredApp);
if (hr == HRESULT_FROM_WIN32(ERROR_NO_ASSOCIATION)) {
return NS_OK;
}
NS_ENSURE_HRESULT(hr, NS_ERROR_FAILURE);
aResult = registeredApp;
CoTaskMemFree(registeredApp);
return NS_OK;
}
nsresult nsWindowsShellService::LaunchControlPanelDefaultsSelectionUI() {
IApplicationAssociationRegistrationUI* pAARUI;
HRESULT hr = CoCreateInstance(