Bug 1950734 - Make MSIX builds skip the AUMID altering steps in taskbar pinning as it's unnecessary r=nrishel

Differential Revision: https://phabricator.services.mozilla.com/D239827
This commit is contained in:
Eric Chen
2025-03-12 23:45:49 +00:00
parent 2efa3bdd22
commit 3fa85c5c7a
5 changed files with 81 additions and 17 deletions

View File

@@ -17,6 +17,7 @@
#include "mozilla/UniquePtr.h"
#include "mozilla/WinHeaderOnlyUtils.h"
#include "mozilla/widget/WinTaskbar.h"
#include "WinUtils.h"
#include "mozilla/Logging.h"
@@ -213,6 +214,7 @@ Win11PinToTaskBarResult PinCurrentAppToTaskbarWin11(
primaryAumid = nsString(primaryAumid)](
Win11PinToTaskBarResultStatus status) {
// Set AUMID back and ensure the icon is set correctly
if (!widget::WinUtils::HasPackageIdentity()) {
HRESULT hr =
SetCurrentProcessExplicitAppUserModelID(primaryAumid.get());
if (FAILED(hr)) {
@@ -221,14 +223,19 @@ Win11PinToTaskBarResult PinCurrentAppToTaskbarWin11(
"operation failed. HRESULT = 0x%lx",
hr);
}
}
resultStatus = status;
event.Set();
};
// Set the process to have the AUMID of the shortcut we want to pin,
// this is only necessary for Win32 builds
if (!widget::WinUtils::HasPackageIdentity()) {
hr = SetCurrentProcessExplicitAppUserModelID(aumid.get());
if (FAILED(hr)) {
return CompletedOperations(Win11PinToTaskBarResultStatus::Failed);
}
}
ComPtr<ITaskbarManager> taskbar;
Win11PinToTaskBarResultStatus allowed =
@@ -264,6 +271,7 @@ Win11PinToTaskBarResult PinCurrentAppToTaskbarWin11(
[&event, &resultStatus,
primaryAumid](Win11PinToTaskBarResultStatus status) -> HRESULT {
// Set AUMID back and ensure the icon is set correctly
if (!widget::WinUtils::HasPackageIdentity()) {
HRESULT hr =
SetCurrentProcessExplicitAppUserModelID(primaryAumid.get());
if (FAILED(hr)) {
@@ -272,6 +280,7 @@ Win11PinToTaskBarResult PinCurrentAppToTaskbarWin11(
"operation failed. HRESULT = 0x%lx",
hr);
}
}
resultStatus = status;
event.Set();
return S_OK;

View File

@@ -424,6 +424,16 @@ interface nsIWindowsShellService : nsIShellService
boolean checkAllProgIDsExist();
boolean checkBrowserUserChoiceHashes();
/*
* Retrieves the application-defined, explicit Application User Model ID
* for the current process. This function is only to be used on
* Windows for testing purposes
*
* @return string AUMID
* @throws NS_ERROR_FAILURE when the AUMID cannot be fetched
*/
AString checkCurrentProcessAUMIDForTesting();
/*
* Determines whether or not Firefox is the "Default Handler", i.e.,
* is registered to handle, the given file extension (like ".pdf")

View File

@@ -377,6 +377,21 @@ nsWindowsShellService::CheckBrowserUserChoiceHashes(bool* aResult) {
return NS_OK;
}
NS_IMETHODIMP
nsWindowsShellService::CheckCurrentProcessAUMIDForTesting(
nsAString& aRetAumid) {
PWSTR id;
HRESULT hr = GetCurrentProcessExplicitAppUserModelID(&id);
if (FAILED(hr)) {
return NS_ERROR_FAILURE;
}
aRetAumid.Assign(id);
CoTaskMemFree(id);
return NS_OK;
}
NS_IMETHODIMP
nsWindowsShellService::CanSetDefaultBrowserUserChoice(bool* aResult) {
*aResult = false;

View File

@@ -91,6 +91,9 @@ skip-if = [
run-if = ["os == 'win'"]
tags = "os_integration"
["browser_processAUMID.js"]
run-if = ["os == 'win'"]
["browser_setDefaultBrowser.js"]
tags = "os_integration"

View File

@@ -0,0 +1,27 @@
/* Any copyright is dedicated to the Public Domain.
* https://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Bug 1950734 tracks how calling PinCurrentAppToTaskbarWin11
* on MSIX may cause the process AUMID to be unnecessarily changed.
* This test verifies that the behaviour will no longer happen
*/
ChromeUtils.defineESModuleGetters(this, {
ShellService: "resource:///modules/ShellService.sys.mjs",
});
add_task(async function test_processAUMID() {
let processAUMID = ShellService.checkCurrentProcessAUMIDForTesting();
// This function will trigger the relevant code paths that
// incorrectly changes the process AUMID on MSIX, prior to
// Bug 1950734 being fixed
await ShellService.checkPinCurrentAppToTaskbarAsync(false);
is(
processAUMID,
ShellService.checkCurrentProcessAUMIDForTesting(),
"The process AUMID should not be changed"
);
});