Skip to content

Commit 119452b

Browse files
committed
Bug 1751010: Set AUMID correctly for private browsing windows r=mossop,mhowell
This is done differently depending on whether the Private Browsing window is the initial one, or if it's a new window from a running application. In the former case, we're still not setting it up early enough -- the window will initially show up in one icon, and then switch to the other one after we've adjusted the AUMID. Regardless, the fact that we're doing it for every new window appears to mean that other places that require it (such as GeckoChildProcessHost.cpp) will Do The Right Thing (because they'll pull the cached version that `GetAppUserModelID` finds). This behind a pref for now both because of the issue noted above, as well as the fact that we're waiting on finalized branding for this. Differential Revision: https://phabricator.services.mozilla.com/D138194
1 parent 811e939 commit 119452b

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

browser/components/BrowserContentHandler.jsm

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,11 @@ XPCOMUtils.defineLazyModuleGetters(this, {
2626
ShellService: "resource:///modules/ShellService.jsm",
2727
UpdatePing: "resource://gre/modules/UpdatePing.jsm",
2828
});
29-
XPCOMUtils.defineLazyServiceGetter(
30-
this,
31-
"WindowsUIUtils",
32-
"@mozilla.org/windows-ui-utils;1",
33-
"nsIWindowsUIUtils"
34-
);
35-
XPCOMUtils.defineLazyServiceGetter(
36-
this,
37-
"UpdateManager",
38-
"@mozilla.org/updates/update-manager;1",
39-
"nsIUpdateManager"
40-
);
29+
XPCOMUtils.defineLazyServiceGetters(this, {
30+
UpdateManager: ["@mozilla.org/updates/update-manager;1", "nsIUpdateManager"],
31+
WinTaskbar: ["@mozilla.org/windows-taskbar;1", "nsIWinTaskbar"],
32+
WindowsUIUtils: ["@mozilla.org/windows-ui-utils;1", "nsIWindowsUIUtils"],
33+
});
4134

4235
XPCOMUtils.defineLazyGetter(this, "gSystemPrincipal", () =>
4336
Services.scriptSecurityManager.getSystemPrincipal()
@@ -48,6 +41,8 @@ XPCOMUtils.defineLazyGlobalGetters(this, [URL]);
4841
const ONCE_DOMAINS = ["mozilla.org", "firefox.com"];
4942
const ONCE_PREF = "browser.startup.homepage_override.once";
5043

44+
const PRIVACY_SEGMENTATION_PREF = "browser.privacySegmentation.enabled";
45+
5146
function shouldLoadURI(aURI) {
5247
if (aURI && !aURI.schemeIs("chrome")) {
5348
return true;
@@ -276,6 +271,13 @@ function openBrowserWindow(
276271
win.docShell.QueryInterface(
277272
Ci.nsILoadContext
278273
).usePrivateBrowsing = true;
274+
if (Services.prefs.getBoolPref(PRIVACY_SEGMENTATION_PREF)) {
275+
// TODO: Changing this after the Window has been painted causes it to
276+
// change Taskbar icons if the original one had a different AUMID.
277+
// This must stay pref'ed off until this is resolved.
278+
// https://bugzilla.mozilla.org/show_bug.cgi?id=1751010
279+
WinTaskbar.setGroupIdForWindow(win, WinTaskbar.defaultPrivateGroupId);
280+
}
279281
}
280282

281283
let openTime = win.openTime;

widget/nsWidgetInitData.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ struct nsWidgetInitData {
107107
mAlwaysOnTop(false),
108108
mPIPWindow(false),
109109
mFissionWindow(false),
110-
mResizable(false) {}
110+
mResizable(false),
111+
mIsPrivate(false) {}
111112

112113
nsWindowType mWindowType;
113114
nsBorderStyle mBorderStyle;
@@ -137,6 +138,7 @@ struct nsWidgetInitData {
137138
bool mFissionWindow;
138139
// True if the window is user-resizable.
139140
bool mResizable;
141+
bool mIsPrivate;
140142
};
141143

142144
#endif // nsWidgetInitData_h__

widget/windows/nsWindow.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@
8686
#include <unknwn.h>
8787
#include <psapi.h>
8888
#include <rpc.h>
89+
#include <propvarutil.h>
90+
#include <propkey.h>
8991

9092
#include "mozilla/Logging.h"
9193
#include "prtime.h"
@@ -968,6 +970,28 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
968970
return NS_ERROR_FAILURE;
969971
}
970972

973+
if (aInitData->mIsPrivate) {
974+
if (Preferences::GetBool("browser.privacySegmentation.enabled", false)) {
975+
RefPtr<IPropertyStore> pPropStore;
976+
if (!FAILED(SHGetPropertyStoreForWindow(mWnd, IID_IPropertyStore,
977+
getter_AddRefs(pPropStore)))) {
978+
PROPVARIANT pv;
979+
nsAutoString aumid;
980+
// make sure we're using the private browsing AUMID so that taskbar
981+
// grouping works properly
982+
Unused << NS_WARN_IF(
983+
!mozilla::widget::WinTaskbar::GenerateAppUserModelID(aumid, true));
984+
if (!FAILED(InitPropVariantFromString(aumid.get(), &pv))) {
985+
if (!FAILED(pPropStore->SetValue(PKEY_AppUserModel_ID, pv))) {
986+
pPropStore->Commit();
987+
}
988+
989+
PropVariantClear(&pv);
990+
}
991+
}
992+
}
993+
}
994+
971995
mDeviceNotifyHandle = InputDeviceUtils::RegisterNotification(mWnd);
972996

973997
// If mDefaultScale is set before mWnd has been set, it will have the scale of

xpfe/appshell/nsAppShellService.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,10 @@ nsresult nsAppShellService::JustCreateTopWindow(
710710

711711
widgetInitData.mRTL = LocaleService::GetInstance()->IsAppLocaleRTL();
712712

713+
if (aChromeMask & nsIWebBrowserChrome::CHROME_PRIVATE_WINDOW) {
714+
widgetInitData.mIsPrivate = true;
715+
}
716+
713717
nsresult rv =
714718
window->Initialize(parent, center ? aParent : nullptr, aInitialWidth,
715719
aInitialHeight, aIsHiddenWindow, widgetInitData);

0 commit comments

Comments
 (0)