Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 37c29fd

Browse files
committed
Bug 1685213 - Part 1: Save and access the startup shortcut. r=bytesized
A. The shell provides the startup shortcut in STARTUPINFOW when it starts a process. If the launcher process runs, we must pass this along to the real process being created. B. lpTitle can be overwritten, in particular when the AUMID is set for WinTaskbar, so save it in XREMain::XRE_mainStartup() in order to access it later. C. Add an accessor for the saved shortcut. Differential Revision: https://phabricator.services.mozilla.com/D106343
1 parent e01b214 commit 37c29fd

3 files changed

Lines changed: 51 additions & 0 deletions

File tree

browser/app/winlauncher/LauncherProcessWin.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,15 @@ Maybe<int> LauncherMain(int& argc, wchar_t* argv[],
356356
}
357357
}
358358

359+
// Pass on the path of the shortcut used to launch this process, if any.
360+
STARTUPINFOW currentStartupInfo;
361+
GetStartupInfoW(&currentStartupInfo);
362+
if ((currentStartupInfo.dwFlags & STARTF_TITLEISLINKNAME) &&
363+
currentStartupInfo.lpTitle) {
364+
siex.StartupInfo.dwFlags |= STARTF_TITLEISLINKNAME;
365+
siex.StartupInfo.lpTitle = currentStartupInfo.lpTitle;
366+
}
367+
359368
PROCESS_INFORMATION pi = {};
360369
BOOL createOk;
361370

toolkit/xre/nsAppRunner.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ bool gIsGtest = false;
302302

303303
nsString gAbsoluteArgv0Path;
304304

305+
#if defined(XP_WIN)
306+
nsString gProcessStartupShortcut;
307+
#endif
308+
305309
#if defined(MOZ_WIDGET_GTK)
306310
# include <glib.h>
307311
# if defined(DEBUG) || defined(NS_BUILD_REFCNT_LOGGING)
@@ -1307,6 +1311,17 @@ nsXULAppInfo::GetRestartedByOS(bool* aResult) {
13071311
return NS_OK;
13081312
}
13091313

1314+
NS_IMETHODIMP
1315+
nsXULAppInfo::GetProcessStartupShortcut(nsAString& aShortcut) {
1316+
#if defined(XP_WIN)
1317+
if (XRE_IsParentProcess()) {
1318+
aShortcut.Assign(gProcessStartupShortcut);
1319+
return NS_OK;
1320+
}
1321+
#endif
1322+
return NS_ERROR_NOT_AVAILABLE;
1323+
}
1324+
13101325
#if defined(XP_WIN) && defined(MOZ_LAUNCHER_PROCESS)
13111326
// Forward declaration
13121327
void SetupLauncherProcessPref();
@@ -4249,6 +4264,20 @@ int XREMain::XRE_mainStartup(bool* aExitFlag) {
42494264
}
42504265
#endif
42514266

4267+
#if defined(XP_WIN)
4268+
{
4269+
// Save the shortcut path before lpTitle is replaced by an AUMID,
4270+
// such as by WinTaskbar
4271+
STARTUPINFOW si;
4272+
GetStartupInfoW(&si);
4273+
if (si.dwFlags & STARTF_TITLEISAPPID) {
4274+
NS_WARNING("AUMID was already set, shortcut may have been lost.");
4275+
} else if ((si.dwFlags & STARTF_TITLEISLINKNAME) && si.lpTitle) {
4276+
gProcessStartupShortcut.Assign(si.lpTitle);
4277+
}
4278+
}
4279+
#endif /* XP_WIN */
4280+
42524281
#if defined(MOZ_WIDGET_GTK)
42534282
// setup for private colormap. Ideally we'd like to do this
42544283
// in nsAppShell::Create, but we need to get in before gtk

xpcom/system/nsIXULRuntime.idl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,19 @@ interface nsIXULRuntime : nsISupports
306306
*/
307307
readonly attribute boolean restartedByOS;
308308

309+
/**
310+
* The path of the shortcut used to start the current process, or "" if none.
311+
*
312+
* Windows Main process only, otherwise throws NS_ERROR_NOT_AVAILABLE
313+
*
314+
* May be mising in some cases where the user did launch from a shortcut:
315+
* - If the updater ran on startup
316+
* - If the AUMID was set before the shortcut could be saved
317+
*
318+
* @throw NS_ERROR_NOT_AVAILABLE if not available.
319+
*/
320+
readonly attribute AString processStartupShortcut;
321+
309322
/**
310323
* Returns a value corresponding to one of the
311324
* |mozilla::LauncherRegistryInfo::EnabledState| values.

0 commit comments

Comments
 (0)