Skip to content

Commit

Permalink
Simplify nsCommandLineServiceMac, make it easier to understand and fa…
Browse files Browse the repository at this point in the history
…ster. Remove unused code. b=542936 r=mstange r=bsmedberg
  • Loading branch information
Josh Aas committed Jun 8, 2010
1 parent d456f23 commit e790a9f
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 352 deletions.
64 changes: 36 additions & 28 deletions toolkit/xre/MacApplicationDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#include "nsINativeAppSupport.h"
#include "nsAppRunner.h"
#include "nsComponentManagerUtils.h"
#include "nsCommandLineServiceMac.h"
#include "nsIServiceManager.h"
#include "nsServiceManagerUtils.h"
#include "nsIAppStartup.h"
Expand All @@ -63,6 +62,8 @@
#include "nsICommandLineRunner.h"
#include "nsIMacDockSupport.h"
#include "nsIStandaloneNativeMenu.h"
#include "nsILocalFileMac.h"
#include "nsString.h"

@interface MacApplicationDelegate : NSObject
{
Expand Down Expand Up @@ -152,14 +153,9 @@ - (void)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);
Expand All @@ -175,43 +171,55 @@ - (BOOL)applicationShouldHandleReopen:(NSApplication*)theApp hasVisibleWindows:(

// 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;
}

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;

return YES;
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;
Expand Down
6 changes: 2 additions & 4 deletions toolkit/xre/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,10 @@ endif

ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
CMMSRCS += MacLaunchHelper.mm
CPPSRCS += nsCommandLineServiceMac.cpp
OS_CXXFLAGS += -fexceptions
endif
ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
CMMSRCS += MacApplicationDelegate.mm
CMMSRCS += MacAutoreleasePool.mm
CPPSRCS += nsCommandLineServiceMac.cpp
OS_CXXFLAGS += -fexceptions
endif

ifdef MOZ_X11
Expand Down
16 changes: 7 additions & 9 deletions toolkit/xre/nsAppRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,7 @@ static nsresult LaunchChild(nsINativeAppSupport* aNative,
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;
Expand Down Expand Up @@ -1963,7 +1963,7 @@ ShowProfileManager(nsIToolkitProfileService* aProfileSvc,
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
Expand Down Expand Up @@ -2053,7 +2053,7 @@ ImportProfiles(nsIToolkitProfileService* aPService,
xpcom.RegisterProfileService();

#ifdef XP_MACOSX
SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
CommandLineServiceMac::SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
#endif

nsCOMPtr<nsIProfileMigrator> migrator
Expand Down Expand Up @@ -3571,14 +3571,13 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
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

Expand Down Expand Up @@ -3614,7 +3613,6 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
PromiseFlatCString(profileName).get());
#endif /* MOZ_ENABLE_XREMOTE */

// enable win32 DDE responses and Mac appleevents responses
nativeApp->Enable();
}

Expand Down Expand Up @@ -3670,7 +3668,7 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData)
#endif

#ifdef XP_MACOSX
SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
CommandLineServiceMac::SetupMacCommandLine(gRestartArgc, gRestartArgv, PR_TRUE);
#endif
}
}
Expand Down
Loading

0 comments on commit e790a9f

Please sign in to comment.