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.
This commit is contained in:
Mike Hommey 2015-03-05 15:09:33 +09:00
parent 9ceb4a0a92
commit dd378b8d2c

View File

@ -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?