Bug 1761291: use private browsing wrapper as target for Private Browsing shortcuts r=mhowell
authorBen Hearsum <bhearsum@mozilla.com>
Wed, 03 Aug 2022 13:49:05 +0000
changeset 699324 23d27ffb8a811e38a46621aa06044ff3acaac2b9
parent 699323 84c998372e2fe77b250682628998917fd060dbf5
child 699325 fc0b5ff1637955705a824b5a509f6cd0809ed693
push id300140
push userbhearsum@mozilla.com
push dateWed, 03 Aug 2022 13:52:05 +0000
reviewersmhowell
bugs1761291
milestone105.0a1
Bug 1761291: use private browsing wrapper as target for Private Browsing shortcuts r=mhowell This ensure the shortcuts will use the correct Visual Elements on the off chance they get pinned to the Start Menu. Differential Revision: https://phabricator.services.mozilla.com/D151539
browser/components/BrowserGlue.jsm
browser/components/shell/nsWindowsShellService.cpp
browser/installer/windows/nsis/defines.nsi.in
browser/installer/windows/nsis/shared.nsh
--- a/browser/components/BrowserGlue.jsm
+++ b/browser/components/BrowserGlue.jsm
@@ -134,19 +134,20 @@ if (AppConstants.ENABLE_WEBDRIVER) {
   lazy.Marionette = { running: false };
   lazy.RemoteAgent = { running: false };
 }
 
 const PREF_PDFJS_ISDEFAULT_CACHE_STATE = "pdfjs.enabledCache.state";
 const PREF_DFPI_ENABLED_BY_DEFAULT =
   "privacy.restrict3rdpartystorage.rollout.enabledByDefault";
 
-// Index of Private Browsing icon in firefox.exe
-// Must line up with the one in nsNativeAppSupportWin.h.
-const PRIVATE_BROWSING_ICON_INDEX = 5;
+const PRIVATE_BROWSING_BINARY = "private_browsing.exe";
+// Index of Private Browsing icon in private_browsing.exe
+// Must line up with IDI_PBICON_PB_PB_EXE in nsNativeAppSupportWin.h.
+const PRIVATE_BROWSING_EXE_ICON_INDEX = 1;
 const PREF_PRIVATE_WINDOW_SEPARATION =
   "browser.privacySegmentation.windowSeparation.enabled";
 const PREF_PRIVATE_BROWSING_SHORTCUT_CREATED =
   "browser.privacySegmentation.createdShortcut";
 
 /**
  * Fission-compatible JSProcess implementations.
  * Each actor options object takes the form of a ProcessActorOptions dictionary.
@@ -2555,35 +2556,37 @@ BrowserGlue.prototype = {
           );
 
           if (
             !shellService.hasMatchingShortcut(
               winTaskbar.defaultPrivateGroupId,
               true
             )
           ) {
-            let exe = Services.dirsvc.get("XREExeF", Ci.nsIFile);
+            let appdir = Services.dirsvc.get("GreD", Ci.nsIFile);
+            let exe = appdir.clone();
+            exe.append(PRIVATE_BROWSING_BINARY);
             let strings = new Localization(
               ["branding/brand.ftl", "browser/browser.ftl"],
               true
             );
             let [desc] = await strings.formatValues([
               "private-browsing-shortcut-text",
             ]);
             shellService.createShortcut(
               exe,
-              ["-private-window"],
+              [],
               desc,
               exe,
               // The code we're calling indexes from 0 instead of 1
-              PRIVATE_BROWSING_ICON_INDEX - 1,
+              PRIVATE_BROWSING_EXE_ICON_INDEX - 1,
               winTaskbar.defaultPrivateGroupId,
               "Programs",
               desc + ".lnk",
-              Services.dirsvc.get("GreD", Ci.nsIFile)
+              appdir
             );
             Services.prefs.setBoolPref(
               PREF_PRIVATE_BROWSING_SHORTCUT_CREATED,
               true
             );
           }
         },
       },
--- a/browser/components/shell/nsWindowsShellService.cpp
+++ b/browser/components/shell/nsWindowsShellService.cpp
@@ -60,16 +60,17 @@ PSSTDAPI PropVariantToString(REFPROPVARI
 #include <shlobj.h>
 #include <knownfolders.h>
 #include "WinUtils.h"
 #include "mozilla/widget/WinTaskbar.h"
 
 #include <mbstring.h>
 
 #define PIN_TO_TASKBAR_SHELL_VERB 5386
+#define PRIVATE_BROWSING_BINARY L"private_browsing.exe"
 
 #undef ACCESS_READ
 
 #ifndef MAX_BUF
 #  define MAX_BUF 4096
 #endif
 
 #define REG_SUCCEEDED(val) (val == ERROR_SUCCESS)
@@ -1317,46 +1318,46 @@ static nsresult PinCurrentAppToTaskbarIm
   if (shortcutPath.IsEmpty()) {
     if (aCheckOnly) {
       // Later checks rely on a shortcut already existing.
       // We don't want to create a shortcut in check only mode
       // so the best we can do is assume those parts will work.
       return NS_OK;
     }
 
-    nsTArray<nsString> arguments;
-
-    if (aPrivateBrowsing) {
-      nsAutoString arg;
-      arg.AssignLiteral("-private-window");
-      arguments.AppendElement(arg);
-    }
-
     nsAutoString linkName(aShortcutName);
 
-    wchar_t exePath[MAXPATHLEN] = {};
-    if (NS_WARN_IF(NS_FAILED(BinaryPath::GetLong(exePath)))) {
-      return NS_ERROR_FAILURE;
+    nsCOMPtr<nsIFile> exeFile;
+    if (aPrivateBrowsing) {
+      nsresult rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(exeFile));
+      if (!NS_SUCCEEDED(rv)) {
+        return NS_ERROR_FAILURE;
+      }
+      nsAutoString pbExeStr(PRIVATE_BROWSING_BINARY);
+      rv = exeFile->Append(pbExeStr);
+      if (!NS_SUCCEEDED(rv)) {
+        return NS_ERROR_FAILURE;
+      }
+    } else {
+      wchar_t exePath[MAXPATHLEN] = {};
+      if (NS_WARN_IF(NS_FAILED(BinaryPath::GetLong(exePath)))) {
+        return NS_ERROR_FAILURE;
+      }
+      nsAutoString exeStr(exePath);
+      nsresult rv = NS_NewLocalFile(exeStr, true, getter_AddRefs(exeFile));
+      if (!NS_SUCCEEDED(rv)) {
+        return NS_ERROR_FILE_NOT_FOUND;
+      }
     }
 
-    nsAutoString exeStr;
-    nsCOMPtr<nsIFile> exeFile;
-    exeStr.Assign(exePath);
-    nsresult rv = NS_NewLocalFile(exeStr, true, getter_AddRefs(exeFile));
-    if (!NS_SUCCEEDED(rv)) {
-      return NS_ERROR_FILE_NOT_FOUND;
-    }
-
-    uint16_t iconIndex = aPrivateBrowsing ? IDI_PBMODE : IDI_APPICON;
-    // Icon indexes are defined as Resource IDs, but CreateShortcutImpl
-    // needs an index.
-    iconIndex--;
-
+    nsTArray<nsString> arguments;
     rv = CreateShortcutImpl(exeFile, arguments, aShortcutName, exeFile,
-                            iconIndex, aAppUserModelId, FOLDERID_Programs,
+                            // Icon indexes are defined as Resource IDs, but
+                            // CreateShortcutImpl needs an index.
+                            IDI_APPICON - 1, aAppUserModelId, FOLDERID_Programs,
                             linkName, shortcutPath);
     if (!NS_SUCCEEDED(rv)) {
       return NS_ERROR_FILE_NOT_FOUND;
     }
   }
 
   if (IsWin10OrLater()) {
     return PinCurrentAppToTaskbarWin10(aCheckOnly, shortcutPath);
--- a/browser/installer/windows/nsis/defines.nsi.in
+++ b/browser/installer/windows/nsis/defines.nsi.in
@@ -22,36 +22,41 @@
 
 # These defines should match application.ini settings
 !define AppName               "Firefox"
 !define AppVersion            "@APP_VERSION@"
 !define GREVersion            @MOZILLA_VERSION@
 !define AB_CD                 "@AB_CD@"
 
 !define FileMainEXE           "@MOZ_APP_NAME@.exe"
+!define PrivateBrowsingEXE    "private_browsing.exe"
 !define MainWindowClass       "MozillaWindowClass"
 !define DialogWindowClass     "MozillaDialogClass"
 !define DDEApplication        "Firefox"
 !define AppRegName            "Firefox"
 !define ToastAumidPrefix      "@MOZ_TOAST_APP_NAME@Toast-"
 
 !define BrandProductName      "Firefox"
 !ifndef DEV_EDITION
 !define BrandShortName        "@MOZ_APP_DISPLAYNAME@"
 !endif
 !ifndef BrandFullName
 !define BrandFullName         "${BrandFullNameInternal}"
 !endif
 
 ; The C++ defines in `nsNativeAppSupportWin.h` are 1-based.  The Windows
 ; resource IDs in the registry are 0-based.
-!define IDI_APPICON_ZERO_BASED      "0"
-!define IDI_DOCUMENT_ZERO_BASED     "1"
-!define IDI_PBICON_ZERO_BASED       "4"
-!define IDI_DOCUMENT_PDF_ZERO_BASED "5"
+!define IDI_APPICON_ZERO_BASED       "0"
+!define IDI_DOCUMENT_ZERO_BASED      "1"
+!define IDI_PBICON_ZERO_BASED        "4"
+!define IDI_DOCUMENT_PDF_ZERO_BASED  "5"
+
+; This one is the location of the Private Browsing icon in
+; private_browsing.exe (as opposed to @MOZ_APP_NAME@.exe)
+!define IDI_PBICON_PB_EXE_ZERO_BASED "0"
 
 !define CERTIFICATE_NAME            "Mozilla Corporation"
 !define CERTIFICATE_ISSUER          "DigiCert SHA2 Assured ID Code Signing CA"
 ; Changing the name or issuer requires us to have both the old and the new
 ;  in the registry at the same time, temporarily.
 !define CERTIFICATE_NAME_PREVIOUS   "Mozilla Corporation"
 !define CERTIFICATE_ISSUER_PREVIOUS "DigiCert Assured ID Code Signing CA-1"
 
--- a/browser/installer/windows/nsis/shared.nsh
+++ b/browser/installer/windows/nsis/shared.nsh
@@ -209,17 +209,17 @@
       FileClose $0
     ${EndIf}
   ${EndIf}
 !macroend
 !define TouchStartMenuShortcut "!insertmacro TouchStartMenuShortcut"
 
 !macro AddPrivateBrowsingShortcut
   ${IfNot} ${FileExists} "$SMPROGRAMS\$(PRIVATE_BROWSING_SHORTCUT_TITLE).lnk"
-    CreateShortcut "$SMPROGRAMS\$(PRIVATE_BROWSING_SHORTCUT_TITLE).lnk" "$INSTDIR\${FileMainEXE}" "-private-window" "$INSTDIR\${FileMainEXE}" ${IDI_PBICON_ZERO_BASED}
+    CreateShortcut "$SMPROGRAMS\$(PRIVATE_BROWSING_SHORTCUT_TITLE).lnk" "$INSTDIR\${PrivateBrowsingEXE}" "" "$INSTDIR\${PrivateBrowsingEXE}" ${IDI_PBICON_PB_EXE_ZERO_BASED}
     ShellLink::SetShortcutWorkingDirectory "$SMPROGRAMS\$(PRIVATE_BROWSING_SHORTCUT_TITLE).lnk" "$INSTDIR"
     ShellLink::SetShortcutDescription "$SMPROGRAMS\$(PRIVATE_BROWSING_SHORTCUT_TITLE).lnk" "$(PRIVATE_BROWSING_SHORTCUT_TITLE)"
     ApplicationID::Set "$SMPROGRAMS\$(PRIVATE_BROWSING_SHORTCUT_TITLE).lnk" "$AppUserModelID;PrivateBrowsingAUMID" "true"
     ${LogStartMenuShortcut} "$(PRIVATE_BROWSING_SHORTCUT_TITLE).lnk"
   ${EndIf}
 !macroend
 !define AddPrivateBrowsingShortcut "!insertmacro AddPrivateBrowsingShortcut"