Skip to content

Commit fec02f3

Browse files
committed
Bug 1751010: Use a unique icon for the Private Browsing taskbar pin r=mhowell
This is subject to the same issue as an earlier patch in this series -- the icon will be wrong briefly at first launch, before the code in `BrowserContentHandler.jsm` replaces the default icon with the correct one. Differential Revision: https://phabricator.services.mozilla.com/D138601
1 parent 6649a57 commit fec02f3

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

browser/components/BrowserContentHandler.jsm

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ XPCOMUtils.defineLazyGlobalGetters(this, [URL]);
4141
const ONCE_DOMAINS = ["mozilla.org", "firefox.com"];
4242
const ONCE_PREF = "browser.startup.homepage_override.once";
4343

44+
// Index of Private Browsing icon in firefox.exe
45+
// Must line up with the one in nsNativeAppSupportWin.h.
46+
const PRIVATE_BROWSING_ICON_INDEX = 5;
4447
const PRIVACY_SEGMENTATION_PREF = "browser.privacySegmentation.enabled";
4548

4649
function shouldLoadURI(aURI) {
@@ -277,6 +280,13 @@ function openBrowserWindow(
277280
// This must stay pref'ed off until this is resolved.
278281
// https://bugzilla.mozilla.org/show_bug.cgi?id=1751010
279282
WinTaskbar.setGroupIdForWindow(win, WinTaskbar.defaultPrivateGroupId);
283+
WindowsUIUtils.setWindowIconFromExe(
284+
win,
285+
Services.dirsvc.get("XREExeF", Ci.nsIFile).path,
286+
// This corresponds to the definitions in
287+
// nsNativeAppSupportWin.h
288+
PRIVATE_BROWSING_ICON_INDEX
289+
);
280290
}
281291
}
282292

toolkit/xre/nsNativeAppSupportWin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#define IDI_DOCUMENT 2
1818
#define IDI_NEWWINDOW 3
1919
#define IDI_NEWTAB 4
20+
// If IDI_PBMODE's index changes, PRIVATE_BROWSING_ICON_INDEX
21+
// in BrowserContentHandler.jsm must also be updated.
2022
#define IDI_PBMODE 5
2123
#ifndef IDI_APPLICATION
2224
# define IDI_APPLICATION 32512

widget/nsIWindowsUIUtils.idl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ interface nsIWindowsUIUtils : nsISupports
1717

1818
void setWindowIcon(in mozIDOMWindowProxy aWindow, in imgIContainer aSmallIcon, in imgIContainer aLargeIcon);
1919

20+
void setWindowIconFromExe(in mozIDOMWindowProxy aWindow, in AString aExe, in unsigned short aIndex);
21+
2022
void setWindowIconNoData(in mozIDOMWindowProxy aWindow);
2123

2224
/**

widget/windows/WindowsUIUtils.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,23 @@ WindowsUIUtils::SetWindowIcon(mozIDOMWindowProxy* aWindow,
198198
return NS_OK;
199199
}
200200

201+
NS_IMETHODIMP
202+
WindowsUIUtils::SetWindowIconFromExe(mozIDOMWindowProxy* aWindow,
203+
const nsAString& aExe, uint16_t aIndex) {
204+
NS_ENSURE_ARG(aWindow);
205+
206+
nsCOMPtr<nsIWidget> widget =
207+
nsGlobalWindowOuter::Cast(aWindow)->GetMainWidget();
208+
nsWindow* window = static_cast<nsWindow*>(widget.get());
209+
210+
HICON icon = ::LoadIconW(::GetModuleHandleW(PromiseFlatString(aExe).get()),
211+
MAKEINTRESOURCEW(aIndex));
212+
window->SetBigIcon(icon);
213+
window->SetSmallIcon(icon);
214+
215+
return NS_OK;
216+
}
217+
201218
NS_IMETHODIMP
202219
WindowsUIUtils::SetWindowIconNoData(mozIDOMWindowProxy* aWindow) {
203220
NS_ENSURE_ARG(aWindow);

widget/windows/nsWindow.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
#include "mozilla/StaticPrefs_dom.h"
158158
#include "mozilla/StaticPrefs_gfx.h"
159159
#include "mozilla/StaticPrefs_layout.h"
160+
#include "nsNativeAppSupportWin.h"
160161

161162
#include "nsIGfxInfo.h"
162163
#include "nsUXThemeConstants.h"
@@ -990,6 +991,10 @@ nsresult nsWindow::Create(nsIWidget* aParent, nsNativeWidget aNativeParent,
990991
}
991992
}
992993
}
994+
HICON icon =
995+
::LoadIconW(::GetModuleHandleW(nullptr), MAKEINTRESOURCEW(IDI_PBMODE));
996+
SetBigIcon(icon);
997+
SetSmallIcon(icon);
993998
}
994999

9951000
mDeviceNotifyHandle = InputDeviceUtils::RegisterNotification(mWnd);

0 commit comments

Comments
 (0)