From dd378b8d2cd1ea0ed7d49bcb243330912477bbd6 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Thu, 5 Mar 2015 15:09:33 +0900 Subject: [PATCH] Bug 486172 - Don't ignore a -p command line argument when using the Xremote protocol. r=bsmedberg On X11, when running firefox -p foo http://mozilla.org, and a window for another profile is already open, the -p argument is ignored and a new tab or window is opened in the unrelated session. Previously, the equivalent firefox -p foo -remote openurl(http://mozilla.org) would see that there is no window for the profile foo, complain about it, and abort. If a window for the profile foo was open, however, a new tab or windows would open in that session. Here, we modify the behaviour such that firefox -p foo http://mozilla.org never ignores the -p argument, and does the sensible thing depending on the context: - if a window is already open for the profile, use that session. - otherwise, open a new window for that profile. When no -p argument is given, the behaviour is unchanged. As RemoteCommandLine, which first attempts to open a connection with an existing firefox, falls through when there is no existing firefox, the -p argument must be kept in the command line. It turns out CheckArg didn't handle the case properly, so fix this as well. The changes in RemoteCommandLine otherwise match what used to be in HandleRemoteArgument before bug 1080319. --- toolkit/xre/nsAppRunner.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index 83f5cbfbf9b..9302e672154 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -458,6 +458,8 @@ CheckArg(const char* aArg, bool aCheckOSInt = false, const char **aParam = nullp if (strimatch(aArg, arg)) { if (aRemArg) RemoveArg(curarg); + else + ++curarg; if (!aParam) { ar = ARG_FOUND; break; @@ -1632,10 +1634,17 @@ RemoteCommandLine(const char* aDesktopStartupID) nsresult rv; ArgResult ar; + const char *profile = 0; nsAutoCString program(gAppData->remotingName); ToLowerCase(program); const char *username = getenv("LOGNAME"); + ar = CheckArg("p", false, &profile, false); + if (ar == ARG_BAD) { + PR_fprintf(PR_STDERR, "Error: argument -p requires a profile name\n"); + return REMOTE_ARG_BAD; + } + const char *temp = nullptr; ar = CheckArg("a", true, &temp); if (ar == ARG_BAD) { @@ -1658,7 +1667,7 @@ RemoteCommandLine(const char* aDesktopStartupID) nsXPIDLCString response; bool success = false; - rv = client.SendCommandLine(program.get(), username, nullptr, + rv = client.SendCommandLine(program.get(), username, profile, gArgc, gArgv, aDesktopStartupID, getter_Copies(response), &success); // did the command fail?