From 973a3fec8c47f5eb86ad57a51a6dbf975fc83c5b Mon Sep 17 00:00:00 2001 From: Stanca Serban Date: Thu, 25 Jul 2024 17:28:14 +0300 Subject: [PATCH] Backed out changeset 0218b28ab8ed (bug 1904436) for crashes related to taskbar pinning. a=backout --- .../shell/Windows11TaskbarPinning.cpp | 28 ++--------- .../shell/Windows11TaskbarPinning.h | 3 +- .../shell/nsWindowsShellService.cpp | 2 +- widget/windows/nsWindow.cpp | 46 +++++++++---------- 4 files changed, 29 insertions(+), 50 deletions(-) diff --git a/browser/components/shell/Windows11TaskbarPinning.cpp b/browser/components/shell/Windows11TaskbarPinning.cpp index 126ea20154dc..350a58d59aa9 100644 --- a/browser/components/shell/Windows11TaskbarPinning.cpp +++ b/browser/components/shell/Windows11TaskbarPinning.cpp @@ -9,13 +9,10 @@ #include "nsWindowsHelpers.h" #include "MainThreadUtils.h" #include "nsThreadUtils.h" -#include #include #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 # include -# include # include # include # include @@ -105,7 +101,8 @@ static Result, 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 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}; } diff --git a/browser/components/shell/Windows11TaskbarPinning.h b/browser/components/shell/Windows11TaskbarPinning.h index 938911dc247a..c45fd66a5bf4 100644 --- a/browser/components/shell/Windows11TaskbarPinning.h +++ b/browser/components/shell/Windows11TaskbarPinning.h @@ -29,6 +29,7 @@ struct Win11PinToTaskBarResult { }; Win11PinToTaskBarResult PinCurrentAppToTaskbarWin11( - bool aCheckOnly, const nsAString& aAppUserModelId); + bool aCheckOnly, const nsAString& aAppUserModelId, + nsAutoString aShortcutPath); #endif // SHELL_WINDOWS11TASKBARPINNING_H__ diff --git a/browser/components/shell/nsWindowsShellService.cpp b/browser/components/shell/nsWindowsShellService.cpp index ba44962a0f00..685290ae31e0 100644 --- a/browser/components/shell/nsWindowsShellService.cpp +++ b/browser/components/shell/nsWindowsShellService.cpp @@ -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 diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index 9ce388de7338..17d6d9256546 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -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 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 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);