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

View File

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

View File

@@ -1730,7 +1730,7 @@ static nsresult PinCurrentAppToTaskbarImpl(
} }
auto pinWithWin11TaskbarAPIResults = auto pinWithWin11TaskbarAPIResults =
PinCurrentAppToTaskbarWin11(aCheckOnly, aAppUserModelId); PinCurrentAppToTaskbarWin11(aCheckOnly, aAppUserModelId, shortcutPath);
switch (pinWithWin11TaskbarAPIResults.result) { switch (pinWithWin11TaskbarAPIResults.result) {
case Win11PinToTaskBarResultStatus::NotSupported: case Win11PinToTaskBarResultStatus::NotSupported:
// Fall through to the win 10 mechanism // 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, // Although permanent Private Browsing mode is indeed Private Browsing,
// we choose to make it look like regular Firefox in terms of the icon // 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 // it uses (which also means we shouldn't use the Private Browsing
// AUMID). // AUMID).
bool usePrivateAumid = if (!StaticPrefs::browser_privatebrowsing_autostart()) {
Preferences::GetBool("browser.privateWindowSeparation.enabled", true) && RefPtr<IPropertyStore> pPropStore;
(aInitData->mIsPrivate) && if (!FAILED(SHGetPropertyStoreForWindow(mWnd, IID_IPropertyStore,
!StaticPrefs::browser_privatebrowsing_autostart(); getter_AddRefs(pPropStore)))) {
RefPtr<IPropertyStore> pPropStore; PROPVARIANT pv;
if (!FAILED(SHGetPropertyStoreForWindow(mWnd, IID_IPropertyStore, nsAutoString aumid;
getter_AddRefs(pPropStore)))) { // make sure we're using the private browsing AUMID so that taskbar
PROPVARIANT pv; // grouping works properly
nsAutoString aumid; Unused << NS_WARN_IF(
// Make sure we're using the correct AUMID so that taskbar !mozilla::widget::WinTaskbar::GenerateAppUserModelID(aumid, true));
// grouping works properly if (!FAILED(InitPropVariantFromString(aumid.get(), &pv))) {
Unused << NS_WARN_IF(!mozilla::widget::WinTaskbar::GenerateAppUserModelID( if (!FAILED(pPropStore->SetValue(PKEY_AppUserModel_ID, pv))) {
aumid, usePrivateAumid)); pPropStore->Commit();
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); mDeviceNotifyHandle = InputDeviceUtils::RegisterNotification(mWnd);