Simplify nsCommandLineServiceMac, make it easier to understand and faster. Remove unused code. b=542936 r=mstange r=bsmedberg
authorJosh Aas <joshmoz@gmail.com>
Tue, 08 Jun 2010 18:26:12 -0400
changeset 43334 c448572f61cfe18328f80c720589b038ade06dc4
parent 43333 f6f0a6bba978c4c3ea2b70d4f123cfa421758748
child 43335 aa113516d8f91cace4a85e4a68c135edb011c198
push id13658
push userjosh@mozilla.com
push dateTue, 08 Jun 2010 22:26:27 +0000
treeherdermozilla-central@c448572f61cf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange, bsmedberg
bugs542936
milestone1.9.3a5pre
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
Simplify nsCommandLineServiceMac, make it easier to understand and faster. Remove unused code. b=542936 r=mstange r=bsmedberg
toolkit/xre/MacApplicationDelegate.mm
toolkit/xre/Makefile.in
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsCommandLineServiceMac.cpp
toolkit/xre/nsCommandLineServiceMac.h
toolkit/xre/nsUpdateDriver.cpp
--- a/toolkit/xre/MacApplicationDelegate.mm
+++ b/toolkit/xre/MacApplicationDelegate.mm
@@ -46,28 +46,29 @@
 
 #import <Cocoa/Cocoa.h>
 #import <Carbon/Carbon.h>
 
 #include "nsCOMPtr.h"
 #include "nsINativeAppSupport.h"
 #include "nsAppRunner.h"
 #include "nsComponentManagerUtils.h"
-#include "nsCommandLineServiceMac.h"
 #include "nsIServiceManager.h"
 #include "nsServiceManagerUtils.h"
 #include "nsIAppStartup.h"
 #include "nsIObserverService.h"
 #include "nsISupportsPrimitives.h"
 #include "nsObjCExceptions.h"
 #include "nsIFile.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsICommandLineRunner.h"
 #include "nsIMacDockSupport.h"
 #include "nsIStandaloneNativeMenu.h"
+#include "nsILocalFileMac.h"
+#include "nsString.h"
 
 @interface MacApplicationDelegate : NSObject
 {
 }
 
 @end
 
 // Something to call from non-objective code.
@@ -147,76 +148,83 @@ SetupMacApplicationDelegate()
   NSAppleEventManager *aeMgr = [NSAppleEventManager sharedAppleEventManager];
   [aeMgr removeEventHandlerForEventClass:kInternetEventClass andEventID:kAEGetURL];
   [aeMgr removeEventHandlerForEventClass:'WWW!' andEventID:'OURL'];
   [super dealloc];
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
-// Opening the application is handled specially elsewhere,
-// don't define applicationOpenUntitledFile: .
-
 // The method that NSApplication calls upon a request to reopen, such as when
-// the Dock icon is clicked and no windows are open.
-
-// A "visible" window may be miniaturized, so we can't skip
-// nsCocoaNativeReOpen() if 'flag' is 'true'.
+// the Dock icon is clicked and no windows are open. A "visible" window may be
+// miniaturized, so we can't skip nsCocoaNativeReOpen() if 'flag' is 'true'.
 - (BOOL)applicationShouldHandleReopen:(NSApplication*)theApp hasVisibleWindows:(BOOL)flag
 {
   nsCOMPtr<nsINativeAppSupport> nas = do_CreateInstance(NS_NATIVEAPPSUPPORT_CONTRACTID);
   NS_ENSURE_TRUE(nas, NO);
 
   // Go to the common Carbon/Cocoa reopen method.
   nsresult rv = nas->ReOpen();
   NS_ENSURE_SUCCESS(rv, NO);
 
   // NO says we don't want NSApplication to do anything else for us.
   return NO;
 }
 
 // The method that NSApplication calls when documents are requested to be opened.
 // It will be called once for each selected document.
-
 - (BOOL)application:(NSApplication*)theApplication openFile:(NSString*)filename
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
 
-  // Take advantage of the existing "command line" code for Macs.
-  nsMacCommandLine& cmdLine = nsMacCommandLine::GetMacCommandLine();
-  // URLWithString expects our string to be a legal URL with percent escapes.
-  filename = [filename stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-  // We don't actually care about Mac filetypes in this context, just pass a placeholder.
-  cmdLine.HandleOpenOneDoc((CFURLRef)[NSURL URLWithString:filename], 'abcd');
+  NSString *escapedPath = [filename stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+
+  nsCOMPtr<nsILocalFileMac> inFile;
+  nsresult rv = NS_NewLocalFileWithCFURL((CFURLRef)[NSURL URLWithString:escapedPath], PR_TRUE, getter_AddRefs(inFile));
+  if (NS_FAILED(rv))
+    return NO;
+
+  nsCOMPtr<nsICommandLineRunner> cmdLine(do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
+  if (!cmdLine) {
+    NS_ERROR("Couldn't create command line!");
+    return NO;
+  }
 
-  return YES;
+  nsCString filePath;
+  rv = inFile->GetNativePath(filePath);
+  if (NS_FAILED(rv))
+    return NO;
+
+  nsCOMPtr<nsIFile> workingDir;
+  rv = NS_GetSpecialDirectory(NS_OS_CURRENT_WORKING_DIR, getter_AddRefs(workingDir));
+  if (NS_FAILED(rv))
+    return NO;
+
+  const char *argv[3] = {nsnull, "-file", filePath.get()};
+  rv = cmdLine->Init(3, const_cast<char**>(argv), workingDir, nsICommandLine::STATE_REMOTE_EXPLICIT);
+  if (NS_FAILED(rv))
+    return NO;
+
+  if (NS_SUCCEEDED(cmdLine->Run()))
+    return YES;
+
+  return NO;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
 }
 
 // The method that NSApplication calls when documents are requested to be printed
 // from the Finder (under the "File" menu).
 // It will be called once for each selected document.
-
 - (BOOL)application:(NSApplication*)theApplication printFile:(NSString*)filename
 {
-  NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
-
-  // Take advantage of the existing "command line" code for Macs.
-  nsMacCommandLine& cmdLine = nsMacCommandLine::GetMacCommandLine();
-  // We don't actually care about Mac filetypes in this context, just pass a placeholder.
-  cmdLine.HandlePrintOneDoc((CFURLRef)[NSURL URLWithString:filename], 'abcd');
-
-  return YES;
-
-  NS_OBJC_END_TRY_ABORT_BLOCK_RETURN(NO);
+  return NO;
 }
 
 // Create the menu that shows up in the Dock.
-
 - (NSMenu*)applicationDockMenu:(NSApplication*)sender
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
 
   // Create the NSMenu that will contain the dock menu items.
   NSMenu *menu = [[[NSMenu alloc] initWithTitle:@""] autorelease];
   [menu setAutoenablesItems:NO];
 
--- a/toolkit/xre/Makefile.in
+++ b/toolkit/xre/Makefile.in
@@ -112,23 +112,21 @@ endif
 endif
 endif
 endif
 endif
 endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
 CMMSRCS += MacLaunchHelper.mm
+CMMSRCS += MacApplicationDelegate.mm
+CMMSRCS += MacAutoreleasePool.mm
 CPPSRCS += nsCommandLineServiceMac.cpp
 OS_CXXFLAGS += -fexceptions
 endif
-ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
-CMMSRCS += MacApplicationDelegate.mm
-CMMSRCS += MacAutoreleasePool.mm
-endif
 
 ifdef MOZ_X11
 CPPSRCS += nsX11ErrorHandler.cpp
 endif
 
 ifeq ($(OS_TARGET),Android)
 CPPSRCS += nsAndroidStartup.cpp
 endif
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -1752,17 +1752,17 @@ static nsresult LaunchChild(nsINativeApp
   }
 
   SaveToEnv("MOZ_LAUNCHED_CHILD=1");
 
 #if defined(ANDROID)
   mozilla::AndroidBridge::Bridge()->ScheduleRestart();
 #else
 #if defined(XP_MACOSX)
-  SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
+  CommandLineServiceMac::SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
   LaunchChildMac(gRestartArgc, gRestartArgv);
 #else
   nsCOMPtr<nsILocalFile> lf;
   nsresult rv = XRE_GetBinaryPath(gArgv[0], getter_AddRefs(lf));
   if (NS_FAILED(rv))
     return rv;
 
 #if defined(XP_WIN)
@@ -1958,17 +1958,17 @@ ShowProfileManager(nsIToolkitProfileServ
     NS_ENSURE_SUCCESS(rv, rv);
 
     rv = xpcom.DoAutoreg();
     rv |= xpcom.RegisterProfileService();
     rv |= xpcom.SetWindowCreator(aNative);
     NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
 
 #ifdef XP_MACOSX
-    SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
+    CommandLineServiceMac::SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
 #endif
 
 #ifdef XP_WIN
     // we don't have to wait here because profile manager window will pump
     // and DDE message will be handled
     ProcessDDE(aNative, PR_FALSE);
 #endif
 
@@ -2048,17 +2048,17 @@ ImportProfiles(nsIToolkitProfileService*
   { // scope XPCOM
     ScopedXPCOMStartup xpcom;
     rv = xpcom.Initialize();
     if (NS_SUCCEEDED(rv)) {
       xpcom.DoAutoreg();
       xpcom.RegisterProfileService();
 
 #ifdef XP_MACOSX
-      SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
+      CommandLineServiceMac::SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
 #endif
 
       nsCOMPtr<nsIProfileMigrator> migrator
         (do_GetService(NS_PROFILEMIGRATOR_CONTRACTID));
       if (migrator) {
         migrator->Import();
       }
     }
@@ -3566,24 +3566,23 @@ XRE_main(int argc, char* argv[], const n
 #endif
 
 #ifdef XP_MACOSX
             // we re-initialize the command-line service and do appleevents munging
             // after we are sure that we're not restarting
             cmdLine = do_CreateInstance("@mozilla.org/toolkit/command-line;1");
             NS_ENSURE_TRUE(cmdLine, 1);
 
-            SetupMacCommandLine(gArgc, gArgv, PR_FALSE);
+            CommandLineServiceMac::SetupMacCommandLine(gArgc, gArgv, PR_FALSE);
 
             rv = cmdLine->Init(gArgc, gArgv,
                                workingDir, nsICommandLine::STATE_INITIAL_LAUNCH);
             NS_ENSURE_SUCCESS(rv, 1);
-#endif
-#ifdef MOZ_WIDGET_COCOA
-            // Prepare Cocoa's form of Apple Event handling.
+            
+            // Set up ability to respond to system (Apple) events.
             SetupMacApplicationDelegate();
 #endif
 
             MOZ_SPLASHSCREEN_UPDATE(70);
 
             nsCOMPtr<nsIObserverService> obsService =
               mozilla::services::GetObserverService();
             if (obsService)
@@ -3609,17 +3608,16 @@ XRE_main(int argc, char* argv[], const n
             // if we have X remote support, start listening for requests on the
             // proxy window.
             remoteService = do_GetService("@mozilla.org/toolkit/remote-service;1");
             if (remoteService)
               remoteService->Startup(gAppData->name,
                                      PromiseFlatCString(profileName).get());
 #endif /* MOZ_ENABLE_XREMOTE */
 
-            // enable win32 DDE responses and Mac appleevents responses
             nativeApp->Enable();
           }
 
           NS_TIME_FUNCTION_MARK("Next: Run");
 
           NS_TIME_FUNCTION_MARK("appStartup->Run");
 
           MOZ_SPLASHSCREEN_UPDATE(90);
@@ -3665,17 +3663,17 @@ XRE_main(int argc, char* argv[], const n
           // registry - major milestone vs. build id. 
           needsRestart = PR_TRUE;
 
 #ifdef XP_WIN
           ProcessDDE(nativeApp, PR_TRUE);
 #endif
 
 #ifdef XP_MACOSX
-          SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
+          CommandLineServiceMac::SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
 #endif
         }
       }
     }
 
     // unlock the profile after ScopedXPCOMStartup object (xpcom) 
     // has gone out of scope.  see bug #386739 for more details
     profileLock->Unlock();
--- a/toolkit/xre/nsCommandLineServiceMac.cpp
+++ b/toolkit/xre/nsCommandLineServiceMac.cpp
@@ -33,298 +33,78 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-// Special stuff for the Macintosh implementation of command-line service.
-
 #include "nsCommandLineServiceMac.h"
 
-#include "nsDebug.h"
-#include "nsILocalFileMac.h"
-#include "nsDebug.h"
-#include "nsNetUtil.h"
-#include "nsIAppStartup.h"
-#include "nsIServiceManager.h"
-#include "nsIURL.h"
-#include "nsIIOService.h"
-#include "nsIURL.h"
-#include "nsIServiceManager.h"
-#include "nsNetCID.h"
-#include "nsIDOMWindow.h"
-#include "nsXPCOM.h"
-#include "nsISupportsPrimitives.h"
-#include "nsIWindowWatcher.h"
-#include "jsapi.h"
-#include "nsReadableUtils.h"
-#include "nsIObserverService.h"
-#include "nsIPrefService.h"
-#include "nsICommandLineRunner.h"
-#include "nsDirectoryServiceDefs.h"
+#include <CoreFoundation/CoreFoundation.h>
+#include <Carbon/Carbon.h>
+
+namespace CommandLineServiceMac {
 
-#include "prmem.h"
-#include "plstr.h"
-#include "prenv.h"
+static const int kArgsGrowSize = 20;
+
+static char** sArgs = NULL;
+static int sArgsAllocated = 0;
+static int sArgsUsed = 0;
 
-// the static instance
-nsMacCommandLine nsMacCommandLine::sMacCommandLine;
-
-/*
- * ReadLine --
- *
- * Read in a line of text, terminated by CR or LF, from inStream into buf.
- * The terminating CR or LF is not included.  The text in buf is terminated
- * by a null byte.
- * Returns the number of bytes in buf.  If EOF and zero bytes were read, returns -1.
- */
-
-static PRInt32 ReadLine(FILE* inStream, char* buf, PRInt32 bufSize)
+void AddToCommandLine(const char* inArgText)
 {
-  PRInt32 charsRead = 0;
-  int c;
-  
-  if (bufSize < 2)
-    return -1;
+  if (sArgsUsed >= sArgsAllocated - 1) {
+    // realloc does not free the given pointer if allocation fails
+    char **temp = static_cast<char**>(realloc(sArgs, (sArgsAllocated + kArgsGrowSize) * sizeof(char*)));
+    if (!temp)
+      return;
+    sArgs = temp;
+    sArgsAllocated += kArgsGrowSize;
+  }
 
-  while (charsRead < (bufSize-1)) {
-    c = getc(inStream);
-    if (c == EOF || c == '\n' || c == '\r')
-      break;
-    buf[charsRead++] = c;
-  }
-  buf[charsRead] = '\0';
-  
-  return (c == EOF && !charsRead) ? -1 : charsRead; 
+  char *temp2 = strdup(inArgText);
+  if (!temp2)
+    return;
+
+  sArgs[sArgsUsed++] = temp2;
+  sArgs[sArgsUsed] = NULL;
+
+  return;
 }
 
-nsMacCommandLine::nsMacCommandLine()
-: mArgs(NULL)
-, mArgsAllocated(0)
-, mArgsUsed(0)
-, mStartedUp(PR_FALSE)
-{
-}
-
-nsMacCommandLine::~nsMacCommandLine()
+void SetupMacCommandLine(int& argc, char**& argv, PRBool forRestart)
 {
-  if (mArgs) {
-    for (PRUint32 i = 0; i < mArgsUsed; i++)
-      free(mArgs[i]);
-    free(mArgs);
-  }
-}
+  sArgs = static_cast<char **>(malloc(kArgsGrowSize * sizeof(char*)));
+  if (!sArgs)
+    return;
+  sArgsAllocated = kArgsGrowSize;
+  sArgs[0] = NULL;
+  sArgsUsed = 0;
 
-nsresult nsMacCommandLine::Initialize(int& argc, char**& argv)
-{
-  mArgs = static_cast<char **>(malloc(kArgsGrowSize * sizeof(char *)));
-  if (!mArgs)
-    return NS_ERROR_FAILURE;
-  mArgs[0] = nsnull;
-  mArgsAllocated = kArgsGrowSize;
-  mArgsUsed = 0;
-  
-  // Here, we may actually get useful args.
-  // Copy them first to mArgv.
+  // Copy args, stripping anything we don't want.
   for (int arg = 0; arg < argc; arg++) {
     char* flag = argv[arg];
-    // don't pass on the psn (Process Serial Number) flag from the OS
+    // Don't pass on the psn (Process Serial Number) flag from the OS.
     if (strncmp(flag, "-psn_", 5) != 0)
       AddToCommandLine(flag);
   }
 
-  // we've started up now
-  mStartedUp = PR_TRUE;
-  
-  argc = mArgsUsed;
-  argv = mArgs;
-  
-  return NS_OK;
-}
-
-void nsMacCommandLine::SetupCommandLine(int& argc, char**& argv, PRBool forRestart)
-{
-  // Initializes the command line from Apple Events and other sources,
-  // as appropriate for OS X.
-  //
-  // IMPORTANT: This must be done before XPCOM shutdown if the app is to
-  // relaunch (i.e. before the ScopedXPCOMStartup object goes out of scope).
-  // XPCOM shutdown can cause other things to process native events, and
-  // native event processing can cause the waiting Apple Events to be
-  // discarded.
-
-  // Process Apple Events and put them into the arguments.
-  Initialize(argc, argv);
-
   if (forRestart) {
-    Boolean isForeground = PR_FALSE;
-    ProcessSerialNumber psnSelf, psnFront;
-
     // If the process will be relaunched, the child should be in the foreground
     // if the parent is in the foreground.  This will be communicated in a
     // command-line argument to the child.
+    Boolean isForeground = false;
+    ProcessSerialNumber psnSelf, psnFront;
     if (::GetCurrentProcess(&psnSelf) == noErr &&
         ::GetFrontProcess(&psnFront) == noErr &&
         ::SameProcess(&psnSelf, &psnFront, &isForeground) == noErr &&
         isForeground) {
-      // The process is currently in the foreground.  The relaunched
-      // process should come to the front, too.
       AddToCommandLine("-foreground");
     }
   }
 
-  argc = mArgsUsed;
-  argv = mArgs;
-}
-
-nsresult nsMacCommandLine::AddToCommandLine(const char* inArgText)
-{
-  if (mArgsUsed >= mArgsAllocated - 1) {
-    // realloc does not free the given pointer if allocation fails.
-    char **temp = static_cast<char **>(realloc(mArgs, (mArgsAllocated + kArgsGrowSize) * sizeof(char *)));
-    if (!temp)
-      return NS_ERROR_OUT_OF_MEMORY;
-    mArgs = temp;
-    mArgsAllocated += kArgsGrowSize;
-  }
-  char *temp2 = strdup(inArgText);
-  if (!temp2)
-    return NS_ERROR_OUT_OF_MEMORY;
-  mArgs[mArgsUsed++] = temp2;
-  mArgs[mArgsUsed] = nsnull;
-  return NS_OK;
-}
-
-nsresult nsMacCommandLine::AddToCommandLine(const char* inOptionString, const CFURLRef file)
-{
-  CFStringRef string = ::CFURLGetString(file);
-  if (!string)
-    return NS_ERROR_FAILURE;
-
-  CFIndex length = ::CFStringGetLength(string);
-  CFIndex bufLen = 0;
-  ::CFStringGetBytes(string, CFRangeMake(0, length), kCFStringEncodingUTF8,
-                     0, PR_FALSE, nsnull, 0, &bufLen);
-
-  UInt8 buffer[bufLen + 1];
-  if (!buffer)
-    return NS_ERROR_OUT_OF_MEMORY;
-
-  ::CFStringGetBytes(string, CFRangeMake(0, length), kCFStringEncodingUTF8,
-                     0, PR_FALSE, buffer, bufLen, nsnull);
-  buffer[bufLen] = 0;
-
-  AddToCommandLine(inOptionString);  
-  AddToCommandLine((char*)buffer);
-
-  return NS_OK;
-}
-
-nsresult nsMacCommandLine::AddToEnvironmentVars(const char* inArgText)
-{
-  (void)PR_SetEnv(inArgText);
-  return NS_OK;
+  argc = sArgsUsed;
+  argv = sArgs;
 }
 
-nsresult nsMacCommandLine::HandleOpenOneDoc(const CFURLRef file, OSType inFileType)
-{
-  nsCOMPtr<nsILocalFileMac> inFile;
-  nsresult rv = NS_NewLocalFileWithCFURL(file, PR_TRUE, getter_AddRefs(inFile));
-  if (NS_FAILED(rv))
-    return rv;
-
-  if (!mStartedUp) {
-    // Is it the right type to be a command-line file?
-    if (inFileType == 'TEXT' || inFileType == 'CMDL') {
-      // Can we open the file?
-      FILE *fp = 0;
-      rv = inFile->OpenANSIFileDesc("r", &fp);
-      if (NS_SUCCEEDED(rv)) {
-        Boolean foundArgs = false;
-        Boolean foundEnv = false;
-        char chars[1024];
-        static const char kCommandLinePrefix[] = "ARGS:";
-        static const char kEnvVarLinePrefix[] = "ENV:";
-
-        while (ReadLine(fp, chars, sizeof(chars)) != -1) {
-          // See if there are any command line or environment var settings
-          if (PL_strstr(chars, kCommandLinePrefix) == chars) {
-            AddToCommandLine(chars + sizeof(kCommandLinePrefix) - 1);
-            foundArgs = true;
-          }
-          else if (PL_strstr(chars, kEnvVarLinePrefix) == chars) {
-            AddToEnvironmentVars(chars + sizeof(kEnvVarLinePrefix) - 1);
-            foundEnv = true;
-          }
-        }
-
-        fclose(fp);
-        // If we found a command line or environment vars we want to return now
-        // rather than trying to open the file as a URL
-        if (foundArgs || foundEnv)
-          return NS_OK;
-      }
-    }
-    // If it's not a command-line argument, and we are starting up the application,
-    // add a command-line "-url" argument to the global list. This means that if
-    // the app is opened with documents on the mac, they'll be handled the same
-    // way as if they had been typed on the command line in Unix or DOS.
-    return AddToCommandLine("-url", file);
-  }
-
-  // Final case: we're not just starting up, use the arg as a -file <arg>
-  nsCOMPtr<nsICommandLineRunner> cmdLine
-    (do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
-  if (!cmdLine) {
-    NS_ERROR("Couldn't create command line!");
-    return NS_ERROR_FAILURE;
-  }
-  nsCString filePath;
-  rv = inFile->GetNativePath(filePath);
-  if (NS_FAILED(rv))
-    return rv;
-
-  nsCOMPtr<nsIFile> workingDir;
-  rv = NS_GetSpecialDirectory(NS_OS_CURRENT_WORKING_DIR, getter_AddRefs(workingDir));
-  if (NS_FAILED(rv))
-    return rv;
-
-  const char *argv[3] = {nsnull, "-file", filePath.get()};
-  rv = cmdLine->Init(3, const_cast<char**>(argv), workingDir, nsICommandLine::STATE_REMOTE_EXPLICIT);
-  if (NS_FAILED(rv))
-    return rv;
-  rv = cmdLine->Run();
-  return rv;
-}
-
-nsresult nsMacCommandLine::HandlePrintOneDoc(const CFURLRef file, OSType fileType)
-{
-  // If  we are starting up the application,
-  // add a command-line "-print" argument to the global list. This means that if
-  // the app is opened with documents on the mac, they'll be handled the same
-  // way as if they had been typed on the command line in Unix or DOS.
-  if (!mStartedUp)
-    return AddToCommandLine("-print", file);
-
-  // Final case: we're not just starting up. How do we handle this?
-  NS_NOTYETIMPLEMENTED("Write Me");
-  return NS_ERROR_FAILURE;
-}
-
-nsresult nsMacCommandLine::DispatchURLToNewBrowser(const char* url)
-{
-  nsresult rv = AddToCommandLine("-url");
-  if (NS_SUCCEEDED(rv))
-    rv = AddToCommandLine(url);
-
-  return rv;
-}
-
-#pragma mark -
-
-void SetupMacCommandLine(int& argc, char**& argv, PRBool forRestart)
-{
-  nsMacCommandLine& cmdLine = nsMacCommandLine::GetMacCommandLine();
-  return cmdLine.SetupCommandLine(argc, argv, forRestart);
-}
+} // namespace CommandLineServiceMac
--- a/toolkit/xre/nsCommandLineServiceMac.h
+++ b/toolkit/xre/nsCommandLineServiceMac.h
@@ -30,68 +30,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-// Special stuff for the Macintosh implementation of command-line service.
-
 #ifndef nsCommandLineServiceMac_h_
 #define nsCommandLineServiceMac_h_
 
-#include <CoreFoundation/CoreFoundation.h>
-
 #include "nscore.h"
-#include "nsError.h"
-#include "nsString.h"
-
-class nsMacCommandLine
-{
-public:
-
-  enum
-  {
-    kArgsGrowSize      = 20  
-  };
-
-                  nsMacCommandLine();
-                  ~nsMacCommandLine();
-
-  nsresult        Initialize(int& argc, char**& argv);
-  void            SetupCommandLine(int& argc, char**& argv, PRBool forRestart);
-  
-  nsresult        AddToCommandLine(const char* inArgText);
-  nsresult        AddToCommandLine(const char* inOptionString, const CFURLRef file);
-  nsresult        AddToEnvironmentVars(const char* inArgText);
 
-  nsresult        HandleOpenOneDoc(const CFURLRef file, OSType inFileType);
-  nsresult        HandlePrintOneDoc(const CFURLRef file, OSType fileType);
-
-  nsresult        DispatchURLToNewBrowser(const char* url);
-
-protected:
-
-  nsresult        OpenURL(const char* aURL);
-
-  nsresult        OpenWindow(const char *chrome, const PRUnichar *url);
-    
-  char**          mArgs;              // array of arg pointers (augmented argv)
-  PRUint32        mArgsAllocated;     // number of slots available in mArgs
-  PRUint32        mArgsUsed;          // number of slots used in mArgs
-
-  PRBool          mStartedUp;
-
-public:
-
-  static nsMacCommandLine& GetMacCommandLine() { return sMacCommandLine; }
-
-private:
-
-  static nsMacCommandLine sMacCommandLine;
-  
-};
-
-void SetupMacCommandLine(int& argc, char**& argv, PRBool forRestart);
+namespace CommandLineServiceMac {
+  void SetupMacCommandLine(int& argc, char**& argv, PRBool forRestart);
+}
 
 #endif // nsCommandLineServiceMac_h_
--- a/toolkit/xre/nsUpdateDriver.cpp
+++ b/toolkit/xre/nsUpdateDriver.cpp
@@ -537,17 +537,17 @@ ApplyUpdate(nsIFile *greDir, nsIFile *up
   if (!attr)
     goto end;
 
   status = PR_ProcessAttrSetCurrentDirectory(attr, applyToDir.get());
   if (status != PR_SUCCESS)
     goto end;
 
 #ifdef XP_MACOSX
-  SetupMacCommandLine(argc, argv, PR_TRUE);
+  CommandLineServiceMac::SetupMacCommandLine(argc, argv, PR_TRUE);
 #endif
 
   PR_CreateProcessDetached(updaterPath.get(), argv, nsnull, attr);
   exit(0);
 
 end:
   PR_DestroyProcessAttr(attr); 
   delete[] argv;