Backed out changeset 0218b28ab8ed (bug 1904436) for crashes related to taskbar pinning. a=backout

This commit is contained in:
Stanca Serban
2024-07-25 17:28:14 +03:00
parent 267a9c02e8
commit 973a3fec8c
4 changed files with 29 additions and 50 deletions

View File

@@ -9,13 +9,10 @@
#include "nsWindowsHelpers.h"
#include "MainThreadUtils.h"
#include "nsThreadUtils.h"
#include <shobjidl.h>
#include <strsafe.h>
#include "mozilla/Result.h"
#include "mozilla/ResultVariant.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/WinHeaderOnlyUtils.h"
#include "mozilla/Logging.h"
@@ -30,7 +27,6 @@ static mozilla::LazyLogModule sLog("Windows11TaskbarPinning");
# include <inspectable.h>
# include <roapi.h>
# include <shlobj_core.h>
# include <windows.services.store.h>
# include <windows.foundation.h>
# include <windows.ui.shell.h>
@@ -105,7 +101,8 @@ static Result<ComPtr<ITaskbarManager>, HRESULT> InitializeTaskbar() {
}
Win11PinToTaskBarResult PinCurrentAppToTaskbarWin11(
bool aCheckOnly, const nsAString& aAppUserModelId) {
bool aCheckOnly, const nsAString& aAppUserModelId,
nsAutoString aShortcutPath) {
MOZ_DIAGNOSTIC_ASSERT(!NS_IsMainThread(),
"PinCurrentAppToTaskbarWin11 should be called off main "
"thread only. It blocks, waiting on things to execute "
@@ -137,21 +134,6 @@ Win11PinToTaskBarResult PinCurrentAppToTaskbarWin11(
EventWrapper event;
// Get and store current app model ID
PWSTR rawCurrentIdPtr = nullptr;
hr = GetCurrentProcessExplicitAppUserModelID(&rawCurrentIdPtr);
if (FAILED(hr) || rawCurrentIdPtr == nullptr) {
return {hr, Win11PinToTaskBarResultStatus::Failed};
}
mozilla::UniquePtr<wchar_t, mozilla::CoTaskMemFreeDeleter> currentIdPtr(
rawCurrentIdPtr);
nsString currentId(currentIdPtr.get());
hr = SetCurrentProcessExplicitAppUserModelID(
PromiseFlatString(aAppUserModelId).get());
if (FAILED(hr)) {
return {hr, Win11PinToTaskBarResultStatus::Failed};
}
// Everything related to the taskbar and pinning must be done on the main /
// user interface thread or Windows will cause them to fail.
NS_DispatchToMainThread(NS_NewRunnableFunction(
@@ -348,16 +330,14 @@ Win11PinToTaskBarResult PinCurrentAppToTaskbarWin11(
// block until the pinning is completed on the main thread
event.Wait();
// Set AUMID back and ensure the icon is set correctly
SetCurrentProcessExplicitAppUserModelID(currentId.get());
return {hr, resultStatus};
}
#else // MINGW32 implementation below
Win11PinToTaskBarResult PinCurrentAppToTaskbarWin11(
bool aCheckOnly, const nsAString& aAppUserModelId) {
bool aCheckOnly, const nsAString& aAppUserModelId,
nsAutoString aShortcutPath) {
return {S_OK, Win11PinToTaskBarResultStatus::NotSupported};
}

View File

@@ -29,6 +29,7 @@ struct Win11PinToTaskBarResult {
};
Win11PinToTaskBarResult PinCurrentAppToTaskbarWin11(
bool aCheckOnly, const nsAString& aAppUserModelId);
bool aCheckOnly, const nsAString& aAppUserModelId,
nsAutoString aShortcutPath);
#endif // SHELL_WINDOWS11TASKBARPINNING_H__

View File

@@ -1730,7 +1730,7 @@ static nsresult PinCurrentAppToTaskbarImpl(
}
auto pinWithWin11TaskbarAPIResults =
PinCurrentAppToTaskbarWin11(aCheckOnly, aAppUserModelId);
PinCurrentAppToTaskbarWin11(aCheckOnly, aAppUserModelId, shortcutPath);
switch (pinWithWin11TaskbarAPIResults.result) {
case Win11PinToTaskBarResultStatus::NotSupported:
// Fall through to the win 10 mechanism

View File

@@ -992,37 +992,35 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
}
}
{
if (Preferences::GetBool("browser.privateWindowSeparation.enabled", true) &&
(aInitData->mIsPrivate)) {
// Although permanent Private Browsing mode is indeed Private Browsing,
// we choose to make it look like regular Firefox in terms of the icon
// it uses (which also means we shouldn't use the Private Browsing
// AUMID).
bool usePrivateAumid =
Preferences::GetBool("browser.privateWindowSeparation.enabled", true) &&
(aInitData->mIsPrivate) &&
!StaticPrefs::browser_privatebrowsing_autostart();
RefPtr<IPropertyStore> pPropStore;
if (!FAILED(SHGetPropertyStoreForWindow(mWnd, IID_IPropertyStore,
getter_AddRefs(pPropStore)))) {
PROPVARIANT pv;
nsAutoString aumid;
// Make sure we're using the correct AUMID so that taskbar
// grouping works properly
Unused << NS_WARN_IF(!mozilla::widget::WinTaskbar::GenerateAppUserModelID(
aumid, usePrivateAumid));
if (!FAILED(InitPropVariantFromString(aumid.get(), &pv))) {
if (!FAILED(pPropStore->SetValue(PKEY_AppUserModel_ID, pv))) {
pPropStore->Commit();
}
if (!StaticPrefs::browser_privatebrowsing_autostart()) {
RefPtr<IPropertyStore> pPropStore;
if (!FAILED(SHGetPropertyStoreForWindow(mWnd, IID_IPropertyStore,
getter_AddRefs(pPropStore)))) {
PROPVARIANT pv;
nsAutoString aumid;
// make sure we're using the private browsing AUMID so that taskbar
// grouping works properly
Unused << NS_WARN_IF(
!mozilla::widget::WinTaskbar::GenerateAppUserModelID(aumid, true));
if (!FAILED(InitPropVariantFromString(aumid.get(), &pv))) {
if (!FAILED(pPropStore->SetValue(PKEY_AppUserModel_ID, pv))) {
pPropStore->Commit();
}
PropVariantClear(&pv);
PropVariantClear(&pv);
}
}
HICON icon = ::LoadIconW(::GetModuleHandleW(nullptr),
MAKEINTRESOURCEW(IDI_PBMODE));
SetBigIcon(icon);
SetSmallIcon(icon);
}
HICON icon = ::LoadIconW(
::GetModuleHandleW(nullptr),
MAKEINTRESOURCEW(usePrivateAumid ? IDI_PBMODE : IDI_APPICON));
SetBigIcon(icon);
SetSmallIcon(icon);
}
mDeviceNotifyHandle = InputDeviceUtils::RegisterNotification(mWnd);