Bug 486172 - Don't ignore a -p command line argument when using the Xremote protocol. r=bsmedberg
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 05 Mar 2015 15:09:33 +0900
changeset 232579 f1902c4276e1f32ba569c571481d75751edff6b2
parent 232578 d8e71284931bbbb03d81d66fc21f69a3f7fd1dc6
child 232580 48188cd36ed14bf983e1882b4432c37b492a6e33
push id56611
push usermh@glandium.org
push dateTue, 10 Mar 2015 01:02:34 +0000
treeherdermozilla-inbound@f1902c4276e1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs486172, 1080319
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -453,16 +453,18 @@ CheckArg(const char* aArg, bool aCheckOS
         ) {
       ++arg;
       if (*arg == '-')
         ++arg;
 
       if (strimatch(aArg, arg)) {
         if (aRemArg)
           RemoveArg(curarg);
+        else
+          ++curarg;
         if (!aParam) {
           ar = ARG_FOUND;
           break;
         }
 
         if (*curarg) {
           if (**curarg == '-'
 #if defined(XP_WIN)
@@ -1627,20 +1629,27 @@ DumpVersion()
 
 #ifdef MOZ_ENABLE_XREMOTE
 static RemoteResult
 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) {
     PR_fprintf(PR_STDERR, "Error: argument -a requires an application name\n");
     return REMOTE_ARG_BAD;
   } else if (ar == ARG_FOUND) {
     program.Assign(temp);
   }
@@ -1653,17 +1662,17 @@ RemoteCommandLine(const char* aDesktopSt
 
   XRemoteClient client;
   rv = client.Init();
   if (NS_FAILED(rv))
     return REMOTE_NOT_FOUND;
  
   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?
   if (NS_FAILED(rv) || !success)
     return REMOTE_NOT_FOUND;
 
   return REMOTE_FOUND;
 }