Backed out changeset db7e931c4410 to see if it is responsible for bug 584273. (CLOSED TREE)
authorJosh Aas <joshmoz@gmail.com>
Wed, 04 Aug 2010 00:40:02 -0400
changeset 48793 faa353db92a2e8fff8878e1d2860a2d4948cb451
parent 48416 db7e931c4410ea9d77374a793dfeed43b8bbe65e
child 48794 dfd4d8582ef3fb07f7b8720066976924a6cbe347
push idunknown
push userunknown
push dateunknown
bugs584273
milestone2.0b3pre
backs outdb7e931c4410ea9d77374a793dfeed43b8bbe65e
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
Backed out changeset db7e931c4410 to see if it is responsible for bug 584273. (CLOSED TREE)
toolkit/xre/MacApplicationDelegate.mm
toolkit/xre/nsAppRunner.cpp
toolkit/xre/nsCommandLineServiceMac.cpp
toolkit/xre/nsCommandLineServiceMac.h
--- a/toolkit/xre/MacApplicationDelegate.mm
+++ b/toolkit/xre/MacApplicationDelegate.mm
@@ -59,31 +59,16 @@
 #include "nsObjCExceptions.h"
 #include "nsIFile.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsICommandLineRunner.h"
 #include "nsIMacDockSupport.h"
 #include "nsIStandaloneNativeMenu.h"
 #include "nsILocalFileMac.h"
 #include "nsString.h"
-#include "nsCommandLineServiceMac.h"
-
-class AutoAutoreleasePool {
-public:
-  AutoAutoreleasePool()
-  {
-    mLocalPool = [[NSAutoreleasePool alloc] init];
-  }
-  ~AutoAutoreleasePool()
-  {
-    [mLocalPool release];
-  }
-private:
-  NSAutoreleasePool *mLocalPool;
-};
 
 @interface MacApplicationDelegate : NSObject
 {
 }
 
 @end
 
 // Something to call from non-objective code.
@@ -102,28 +87,30 @@ EnsureUseCocoaDockAPI()
 
 void
 SetupMacApplicationDelegate()
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   // this is called during startup, outside an event loop, and therefore
   // needs an autorelease pool to avoid cocoa object leakage (bug 559075)
-  AutoAutoreleasePool pool;
+  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 
   // This call makes it so that application:openFile: doesn't get bogus calls
   // from Cocoa doing its own parsing of the argument string. And yes, we need
   // to use a string with a boolean value in it. That's just how it works.
   [[NSUserDefaults standardUserDefaults] setObject:@"NO"
                                             forKey:@"NSTreatUnknownArgumentsAsOpen"];
 
   // Create the delegate. This should be around for the lifetime of the app.
   MacApplicationDelegate *delegate = [[MacApplicationDelegate alloc] init];
   [NSApp setDelegate:delegate];
 
+  [pool release];
+
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 @implementation MacApplicationDelegate
 
 - (id)init
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
@@ -136,21 +123,16 @@ SetupMacApplicationDelegate()
              forEventClass:kInternetEventClass
                 andEventID:kAEGetURL];
 
     [aeMgr setEventHandler:self
                andSelector:@selector(handleAppleEvent:withReplyEvent:)
              forEventClass:'WWW!'
                 andEventID:'OURL'];
 
-    [aeMgr setEventHandler:self
-               andSelector:@selector(handleAppleEvent:withReplyEvent:)
-             forEventClass:kCoreEventClass
-                andEventID:kAEOpenDocuments];
-
     if (![NSApp windowsMenu]) {
       // If the application has a windows menu, it will keep it up to date and
       // prepend the window list to the Dock menu automatically.
       NSMenu* windowsMenu = [[NSMenu alloc] initWithTitle:@"Window"];
       [NSApp setWindowsMenu:windowsMenu];
       [windowsMenu release];
     }
   }
@@ -161,17 +143,16 @@ SetupMacApplicationDelegate()
 
 - (void)dealloc
 {
   NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
 
   NSAppleEventManager *aeMgr = [NSAppleEventManager sharedAppleEventManager];
   [aeMgr removeEventHandlerForEventClass:kInternetEventClass andEventID:kAEGetURL];
   [aeMgr removeEventHandlerForEventClass:'WWW!' andEventID:'OURL'];
-  [aeMgr removeEventHandlerForEventClass:kCoreEventClass andEventID:kAEOpenDocuments];
   [super dealloc];
 
   NS_OBJC_END_TRY_ABORT_BLOCK;
 }
 
 // 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'.
@@ -189,30 +170,20 @@ SetupMacApplicationDelegate()
 }
 
 // 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;
 
-  NSURL *url = [NSURL fileURLWithPath:filename];
-  if (!url)
-    return NO;
-
-  NSString *urlString = [url absoluteString];
-  if (!urlString)
-    return NO;
-
-  // Add the URL to any command line we're currently setting up.
-  if (CommandLineServiceMac::AddURLToCurrentCommandLine([urlString UTF8String]))
-    return YES;
+  NSString *escapedPath = [filename stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
 
   nsCOMPtr<nsILocalFileMac> inFile;
-  nsresult rv = NS_NewLocalFileWithCFURL((CFURLRef)url, PR_TRUE, getter_AddRefs(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;
   }
@@ -331,65 +302,39 @@ SetupMacApplicationDelegate()
   return NSTerminateNow;
 }
 
 - (void)handleAppleEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent
 {
   if (!event)
     return;
 
-  AutoAutoreleasePool pool;
-
   if (([event eventClass] == kInternetEventClass && [event eventID] == kAEGetURL) ||
       ([event eventClass] == 'WWW!' && [event eventID] == 'OURL')) {
     NSString* urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
 
     // don't open chrome URLs
     NSString* schemeString = [[NSURL URLWithString:urlString] scheme];
     if (!schemeString ||
         [schemeString compare:@"chrome"
                       options:NSCaseInsensitiveSearch
                         range:NSMakeRange(0, [schemeString length])] == NSOrderedSame) {
       return;
     }
 
-    // Add the URL to any command line we're currently setting up.
-    if (CommandLineServiceMac::AddURLToCurrentCommandLine([urlString UTF8String]))
-      return;
-
     nsCOMPtr<nsICommandLineRunner> cmdLine(do_CreateInstance("@mozilla.org/toolkit/command-line;1"));
     if (!cmdLine) {
       NS_ERROR("Couldn't create command line!");
       return;
     }
     nsCOMPtr<nsIFile> workingDir;
     nsresult rv = NS_GetSpecialDirectory(NS_OS_CURRENT_WORKING_DIR, getter_AddRefs(workingDir));
     if (NS_FAILED(rv))
       return;
     const char *argv[3] = {nsnull, "-url", [urlString UTF8String]};
     rv = cmdLine->Init(3, const_cast<char**>(argv), workingDir, nsICommandLine::STATE_REMOTE_EXPLICIT);
     if (NS_FAILED(rv))
       return;
     rv = cmdLine->Run();
   }
-  else if ([event eventClass] == kCoreEventClass && [event eventID] == kAEOpenDocuments) {
-    NSAppleEventDescriptor* fileListDescriptor = [event paramDescriptorForKeyword:keyDirectObject];
-    if (!fileListDescriptor)
-      return;
-
-    // Descriptor list indexing is one-based...
-    NSInteger numberOfFiles = [fileListDescriptor numberOfItems];
-    for (NSInteger i = 1; i <= numberOfFiles; i++) {
-      NSString* urlString = [[fileListDescriptor descriptorAtIndex:i] stringValue];
-      if (!urlString)
-        continue;
-
-      // We need a path, not a URL
-      NSURL* url = [NSURL URLWithString:urlString];
-      if (!url)
-        continue;
-
-      [self application:NSApp openFile:[url path]];
-    }
-  }
 }
 
 @end
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -3560,30 +3560,29 @@ XRE_main(int argc, char* argv[], const n
 #if defined(HAVE_DESKTOP_STARTUP_ID) && defined(MOZ_WIDGET_GTK2)
           nsRefPtr<nsGTKToolkit> toolkit = GetGTKToolkit();
           if (toolkit && !desktopStartupID.IsEmpty()) {
             toolkit->SetDesktopStartupID(desktopStartupID);
           }
 #endif
 
 #ifdef XP_MACOSX
-          // Set up ability to respond to system (Apple) events. This must be
-          // done before setting up the command line service.
-          SetupMacApplicationDelegate();
-
           // 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);
 
           CommandLineServiceMac::SetupMacCommandLine(gArgc, gArgv, PR_FALSE);
 
           rv = cmdLine->Init(gArgc, gArgv,
                              workingDir, nsICommandLine::STATE_INITIAL_LAUNCH);
           NS_ENSURE_SUCCESS(rv, 1);
+          
+          // Set up ability to respond to system (Apple) events.
+          SetupMacApplicationDelegate();
 #endif
 
           MOZ_SPLASHSCREEN_UPDATE(70);
 
           nsCOMPtr<nsIObserverService> obsService =
             mozilla::services::GetObserverService();
           if (obsService)
             obsService->NotifyObservers(nsnull, "final-ui-startup", nsnull);
--- a/toolkit/xre/nsCommandLineServiceMac.cpp
+++ b/toolkit/xre/nsCommandLineServiceMac.cpp
@@ -46,18 +46,16 @@
 namespace CommandLineServiceMac {
 
 static const int kArgsGrowSize = 20;
 
 static char** sArgs = NULL;
 static int sArgsAllocated = 0;
 static int sArgsUsed = 0;
 
-static PRBool sBuildingCommandLine = PR_FALSE;
-
 void AddToCommandLine(const char* inArgText)
 {
   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;
@@ -78,68 +76,35 @@ void SetupMacCommandLine(int& argc, char
 {
   sArgs = static_cast<char **>(malloc(kArgsGrowSize * sizeof(char*)));
   if (!sArgs)
     return;
   sArgsAllocated = kArgsGrowSize;
   sArgs[0] = NULL;
   sArgsUsed = 0;
 
-  sBuildingCommandLine = PR_TRUE;
-
   // 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.
     if (strncmp(flag, "-psn_", 5) != 0)
       AddToCommandLine(flag);
   }
 
-  // Force processing of any pending Apple Events while we're building the
-  // command line. The handlers will append to the command line rather than
-  // act directly so there is no chance we'll process them during a XUL window
-  // load and accidentally open unnecessary windows and home pages.
-  const EventTypeSpec kAppleEventList[] = {
-    { kEventClassAppleEvent, kEventAppleEvent },
-  };
-  EventRef carbonEvent;
-  while (::ReceiveNextEvent(GetEventTypeCount(kAppleEventList),
-                            kAppleEventList,
-                            kEventDurationNoWait,
-                            PR_TRUE,
-                            &carbonEvent) == noErr) {
-    ::AEProcessEvent(carbonEvent);
-    ::ReleaseEvent(carbonEvent);
-  }
-
-  // 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.
   if (forRestart) {
+    // 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) {
       AddToCommandLine("-foreground");
     }
   }
 
-  sBuildingCommandLine = PR_FALSE;
-
   argc = sArgsUsed;
   argv = sArgs;
 }
 
-PRBool AddURLToCurrentCommandLine(const char* aURL)
-{
-  if (!sBuildingCommandLine) {
-    return PR_FALSE;
-  }
-
-  AddToCommandLine("-url");
-  AddToCommandLine(aURL);
-
-  return PR_TRUE;
-}
-
 } // namespace CommandLineServiceMac
--- a/toolkit/xre/nsCommandLineServiceMac.h
+++ b/toolkit/xre/nsCommandLineServiceMac.h
@@ -37,16 +37,11 @@
 
 #ifndef nsCommandLineServiceMac_h_
 #define nsCommandLineServiceMac_h_
 
 #include "nscore.h"
 
 namespace CommandLineServiceMac {
   void SetupMacCommandLine(int& argc, char**& argv, PRBool forRestart);
-
-  // Add a URL to the command line currently being set up via
-  // SetupMacCommandLine. Returns false if no command line is
-  // being set up or the addition fails for any other reason.
-  PRBool AddURLToCurrentCommandLine(const char* aURL);
 }
 
 #endif // nsCommandLineServiceMac_h_