Add native app support for OSX mach-o builds.

Fixes the 'Quit from dock not working' problem.
Allows certain files to be dragged to the dock icon.
Thanks to Mike Pinkerton <pinkerton@netscape.com> for the original patch.
Bug #111797 r=ccarlen sr=sfraser


git-svn-id: svn://10.0.0.236/trunk@134083 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
seawood%netscape.com 2002-11-19 05:16:50 +00:00
parent 858a4b56dd
commit 59b76c88ef
13 changed files with 255 additions and 47 deletions

View File

@ -28,5 +28,9 @@ include $(DEPTH)/config/autoconf.mk
DIRS = appshell browser components communicator global
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
DIRS := bootstrap/appleevents $(DIRS)
endif
include $(topsrcdir)/config/rules.mk

View File

@ -51,6 +51,10 @@ XPIDLSRCS = \
ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
XPIDLSRCS += nsINativeAppSupportWin.idl
endif
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
EXPORTS += nsAppleEvents.h
XPIDLSRCS += nsICloseAllWindows.idl
endif
include $(topsrcdir)/config/rules.mk

View File

@ -56,6 +56,7 @@ REQUIRES = xpcom \
profile \
unicharutil \
embed_base \
exthandler \
$(NULL)
CPPSRCS = \
@ -78,9 +79,18 @@ else
ifeq ($(OS_ARCH),WINNT)
CPPSRCS += nsUserInfoWin.cpp
else
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
CPPSRCS += \
nsUserInfoMac.cpp \
nsCommandLineServiceMac.cpp \
$(NULL)
OS_CXXFLAGS += -fexceptions
EXTRA_COMPONENTS += nsCloseAllWindows.js
else
CPPSRCS += nsUserInfoUnix.cpp
endif
endif
endif
ifeq ($(OS_ARCH),WINNT)
EXTRA_DSO_LIBS = gkgfx
@ -95,7 +105,9 @@ EXTRA_DSO_LDOPTS = \
$(NULL)
ifeq (,$(filter-out mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
EXTRA_DSO_LDOPTS += $(TK_LIBS)
SHARED_LIBRARY_LIBS = $(DIST)/lib/$(LIB_PREFIX)appleevents_s.$(LIB_SUFFIX)
EXTRA_DSO_LDOPTS += $(TK_LIBS)
LOCAL_INCLUDES = -I$(srcdir)/../../bootstrap/appleevents
endif
include $(topsrcdir)/config/rules.mk

View File

@ -43,6 +43,9 @@
#include "nsString.h"
#include "plstr.h"
#include "nsNetUtil.h"
#ifdef XP_MACOSX
#include "nsCommandLineServiceMac.h"
#endif
nsCmdLineService::nsCmdLineService()
: mArgCount(0), mArgc(0), mArgv(0)
@ -95,6 +98,11 @@ nsCmdLineService::Initialize(int aArgc, char ** aArgv)
PRInt32 i=0;
nsresult rv = nsnull;
#ifdef XP_MACOSX
rv = InitializeMacCommandLine(aArgc, aArgv);
NS_ASSERTION(NS_SUCCEEDED(rv), "Initializing AppleEvents failed");
#endif
// Save aArgc and argv
mArgc = aArgc;
mArgv = new char*[ aArgc ];

View File

@ -42,6 +42,8 @@
#include "nsCommandLineServiceMac.h"
// Mozilla
#include "nsDebug.h"
#include "nsILocalFileMac.h"
#include "nsFileSpec.h"
#include "nsFileStream.h"
#include "nsDebug.h"
@ -69,7 +71,9 @@
#include "prmem.h"
#include "plstr.h"
#include "prenv.h"
#ifdef XP_MAC
#include "pprio.h" // PR_Init_Log
#endif
#include "nsAppShellCIDs.h"
static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
@ -77,6 +81,33 @@ static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
// 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)
{
PRInt32 charsRead = 0;
int c;
if (bufSize < 2)
return -1;
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;
}
//----------------------------------------------------------------------------------------
nsMacCommandLine::nsMacCommandLine()
@ -105,11 +136,19 @@ nsresult nsMacCommandLine::Initialize(int& argc, char**& argv)
typedef char* charP;
mArgs = new charP[kMaxTokens];
mArgs[0] = nsnull;
argc = 0;
argv = mArgs;
#if defined(XP_MACOSX)
// Here, we may actually get useful args.
// Copy them before we reset argc & argv.
for (int arg = 0; arg < argc; arg++)
AddToCommandLine(argv[arg]);
#else
// init the args buffer with the program name
mTempArgsString.Assign("mozilla");
#endif
argc = 0;
argv = mArgs;
// Set up AppleEvent handling.
OSErr err = CreateAEHandlerClasses(false);
@ -223,23 +262,28 @@ nsresult nsMacCommandLine::AddToEnvironmentVars(const char* inArgText)
OSErr nsMacCommandLine::HandleOpenOneDoc(const FSSpec& inFileSpec, OSType inFileType)
//----------------------------------------------------------------------------------------
{
nsCOMPtr<nsILocalFileMac> inFile;
nsresult rv = NS_NewLocalFileWithFSSpec(&inFileSpec, PR_TRUE, getter_AddRefs(inFile));
if (NS_FAILED(rv))
return errAEEventNotHandled;
if (!mStartedUp)
{
// Is it the right type to be a command-line file?
if (inFileType == 'TEXT' || inFileType == 'CMDL')
{
// Can we open the file?
nsInputFileStream s(inFileSpec);
if (s.is_open())
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:";
s.readline(chars, sizeof(chars));
do
while (ReadLine(fp, chars, sizeof(chars)) != -1)
{ // See if there are any command line or environment var settings
if (PL_strstr(chars, kCommandLinePrefix) == chars)
{
@ -251,17 +295,15 @@ OSErr nsMacCommandLine::HandleOpenOneDoc(const FSSpec& inFileSpec, OSType inFile
(void)AddToEnvironmentVars(chars + sizeof(kEnvVarLinePrefix) - 1);
foundEnv = true;
}
}
// Clear the buffer and get the next line from the command line file
chars[0] = '\0';
s.readline(chars, sizeof(chars));
} while (chars && (chars[0] != '\0'));
fclose(fp);
#ifndef XP_MACOSX
// If we found any environment vars we need to re-init NSPR's logging
// so that it knows what the new vars are
if (foundEnv)
PR_Init_Log();
#endif
// If we found a command line or environment vars we want to return now
// raather than trying to open the file as a URL
if (foundArgs || foundEnv)
@ -274,13 +316,8 @@ OSErr nsMacCommandLine::HandleOpenOneDoc(const FSSpec& inFileSpec, OSType inFile
// way as if they had been typed on the command line in Unix or DOS.
return AddToCommandLine("-url", inFileSpec);
}
// Final case: we're not just starting up. How do we handle this?
nsresult rv;
FSSpec nonConstSpec = inFileSpec;
nsCOMPtr<nsILocalFileMac> inFile;
rv = NS_NewLocalFileWithFSSpec(&nonConstSpec, PR_TRUE, getter_AddRefs(inFile));
if (NS_FAILED(rv))
return errAEEventNotHandled;
nsCAutoString specBuf;
rv = NS_GetURLSpecFromFile(inFile, specBuf);
if (NS_FAILED(rv))
@ -337,13 +374,13 @@ nsresult nsMacCommandLine::OpenWindow(const char *chrome, const PRUnichar *url)
OSErr nsMacCommandLine::DispatchURLToNewBrowser(const char* url)
//----------------------------------------------------------------------------------------
{
OSErr err;
OSErr err = errAEEventNotHandled;
if (mStartedUp)
{
nsresult rv;
rv = OpenWindow("chrome://navigator/content", NS_ConvertASCIItoUCS2(url).get());
if (NS_FAILED(rv))
return errAEEventNotHandled;
return err;
}
else
err = AddToCommandLine(url);

View File

@ -160,6 +160,8 @@ RESFILE = splashos2.res
endif
ifeq ($(MOZ_WIDGET_TOOLKIT),mac)
CPPSRCS += nsNativeAppSupportMac.cpp
CPPSRCS += nsNativeAppSupportBase.cpp
LIBS += $(TK_LIBS)
endif
@ -344,6 +346,8 @@ endif
ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
INCLUDES += -I$(srcdir)/../appshell/src -I$(srcdir)/appleevents
ifdef MOZ_DEBUG
APP_NAME = MozillaDebug
else

View File

@ -0,0 +1,94 @@
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = appleevents
LIBRARY_NAME = appleevents_s
REQUIRES = xpcom \
string \
dom \
content \
gfx \
widget \
locale \
view \
necko \
webshell \
pref \
docshell \
plugin \
xuldoc \
imglib2 \
gfx2 \
webbrwsr \
appshell \
layout \
caps \
uriloader \
$(NULL)
# PatriciaTree.cpp \
# nsAppleEventsService.cpp \
CSRCS = \
patricia.c \
$(NULL)
CPPSRCS = \
nsAEApplicationClass.cpp \
nsAEClassDispatcher.cpp \
nsAEClassIterator.cpp \
nsAECoercionHandlers.cpp \
nsAECompare.cpp \
nsAECoreClass.cpp \
nsAEDocumentClass.cpp \
nsAEEventHandling.cpp \
nsAEGenericClass.cpp \
nsAEGetURLSuiteHandler.cpp \
nsAEMozillaSuiteHandler.cpp \
nsAESpyglassSuiteHandler.cpp \
nsAETokens.cpp \
nsAEUtils.cpp \
nsAEWindowClass.cpp \
nsMacUtils.cpp \
nsWindowUtils.cpp \
../nsDocLoadObserver.cpp \
$(NULL)
# we don't want the shared lib, but we want to force the creation of a static lib.
FORCE_STATIC_LIB = 1
LOCAL_INCLUDES = \
-I$(srcdir) \
-I$(srcdir)/.. \
-I$(srcdir)/../../appshell/src/ \
$(NULL)
include $(topsrcdir)/config/rules.mk
OS_CXXFLAGS += -fexceptions

View File

@ -37,7 +37,7 @@
* ***** END LICENSE BLOCK ***** */
#include "AEUtils.h"
#include <AEUtils.h>
#include "PatriciaTree.h"

View File

@ -181,7 +181,7 @@ OSErr GetShortVersionString(short rID, StringPtr version)
error = noErr;
}
else
CopyPascalString(version, "\p<unknown>");
CopyPascalString(version, (StringPtr)"\p<unknown>");
return error;
}

View File

@ -380,7 +380,7 @@ PRBool NS_CanRun()
// nsISplashScreen will be removed.
//
#if !defined( XP_PC ) && !defined(MOZ_WIDGET_GTK) && !defined(XP_MAC)
#if !defined( XP_PC ) && !defined(MOZ_WIDGET_GTK) && !defined(XP_MAC) && !defined(XP_MACOSX)
nsresult NS_CreateNativeAppSupport(nsINativeAppSupport **aResult)
{

View File

@ -468,7 +468,7 @@ nsNativeAppSupportMac::ReOpen()
nsCOMPtr<nsIAppShellService> appShell(do_GetService(kAppShellServiceCID, &rv));
if (!rv)
{
PRBool openedAWindow;
//PRBool openedAWindow;
// uncomment when bug 109811 is fixed
//appShell->DoCommandLines(cmdLineArgs, true, &openedAWindow);
}

View File

@ -43,6 +43,9 @@
#include "nsString.h"
#include "plstr.h"
#include "nsNetUtil.h"
#ifdef XP_MACOSX
#include "nsCommandLineServiceMac.h"
#endif
nsCmdLineService::nsCmdLineService()
: mArgCount(0), mArgc(0), mArgv(0)
@ -95,6 +98,11 @@ nsCmdLineService::Initialize(int aArgc, char ** aArgv)
PRInt32 i=0;
nsresult rv = nsnull;
#ifdef XP_MACOSX
rv = InitializeMacCommandLine(aArgc, aArgv);
NS_ASSERTION(NS_SUCCEEDED(rv), "Initializing AppleEvents failed");
#endif
// Save aArgc and argv
mArgc = aArgc;
mArgv = new char*[ aArgc ];

View File

@ -42,6 +42,8 @@
#include "nsCommandLineServiceMac.h"
// Mozilla
#include "nsDebug.h"
#include "nsILocalFileMac.h"
#include "nsFileSpec.h"
#include "nsFileStream.h"
#include "nsDebug.h"
@ -69,7 +71,9 @@
#include "prmem.h"
#include "plstr.h"
#include "prenv.h"
#ifdef XP_MAC
#include "pprio.h" // PR_Init_Log
#endif
#include "nsAppShellCIDs.h"
static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
@ -77,6 +81,33 @@ static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
// 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)
{
PRInt32 charsRead = 0;
int c;
if (bufSize < 2)
return -1;
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;
}
//----------------------------------------------------------------------------------------
nsMacCommandLine::nsMacCommandLine()
@ -105,11 +136,19 @@ nsresult nsMacCommandLine::Initialize(int& argc, char**& argv)
typedef char* charP;
mArgs = new charP[kMaxTokens];
mArgs[0] = nsnull;
argc = 0;
argv = mArgs;
#if defined(XP_MACOSX)
// Here, we may actually get useful args.
// Copy them before we reset argc & argv.
for (int arg = 0; arg < argc; arg++)
AddToCommandLine(argv[arg]);
#else
// init the args buffer with the program name
mTempArgsString.Assign("mozilla");
#endif
argc = 0;
argv = mArgs;
// Set up AppleEvent handling.
OSErr err = CreateAEHandlerClasses(false);
@ -223,23 +262,28 @@ nsresult nsMacCommandLine::AddToEnvironmentVars(const char* inArgText)
OSErr nsMacCommandLine::HandleOpenOneDoc(const FSSpec& inFileSpec, OSType inFileType)
//----------------------------------------------------------------------------------------
{
nsCOMPtr<nsILocalFileMac> inFile;
nsresult rv = NS_NewLocalFileWithFSSpec(&inFileSpec, PR_TRUE, getter_AddRefs(inFile));
if (NS_FAILED(rv))
return errAEEventNotHandled;
if (!mStartedUp)
{
// Is it the right type to be a command-line file?
if (inFileType == 'TEXT' || inFileType == 'CMDL')
{
// Can we open the file?
nsInputFileStream s(inFileSpec);
if (s.is_open())
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:";
s.readline(chars, sizeof(chars));
do
while (ReadLine(fp, chars, sizeof(chars)) != -1)
{ // See if there are any command line or environment var settings
if (PL_strstr(chars, kCommandLinePrefix) == chars)
{
@ -251,17 +295,15 @@ OSErr nsMacCommandLine::HandleOpenOneDoc(const FSSpec& inFileSpec, OSType inFile
(void)AddToEnvironmentVars(chars + sizeof(kEnvVarLinePrefix) - 1);
foundEnv = true;
}
}
// Clear the buffer and get the next line from the command line file
chars[0] = '\0';
s.readline(chars, sizeof(chars));
} while (chars && (chars[0] != '\0'));
fclose(fp);
#ifndef XP_MACOSX
// If we found any environment vars we need to re-init NSPR's logging
// so that it knows what the new vars are
if (foundEnv)
PR_Init_Log();
#endif
// If we found a command line or environment vars we want to return now
// raather than trying to open the file as a URL
if (foundArgs || foundEnv)
@ -274,13 +316,8 @@ OSErr nsMacCommandLine::HandleOpenOneDoc(const FSSpec& inFileSpec, OSType inFile
// way as if they had been typed on the command line in Unix or DOS.
return AddToCommandLine("-url", inFileSpec);
}
// Final case: we're not just starting up. How do we handle this?
nsresult rv;
FSSpec nonConstSpec = inFileSpec;
nsCOMPtr<nsILocalFileMac> inFile;
rv = NS_NewLocalFileWithFSSpec(&nonConstSpec, PR_TRUE, getter_AddRefs(inFile));
if (NS_FAILED(rv))
return errAEEventNotHandled;
nsCAutoString specBuf;
rv = NS_GetURLSpecFromFile(inFile, specBuf);
if (NS_FAILED(rv))
@ -337,13 +374,13 @@ nsresult nsMacCommandLine::OpenWindow(const char *chrome, const PRUnichar *url)
OSErr nsMacCommandLine::DispatchURLToNewBrowser(const char* url)
//----------------------------------------------------------------------------------------
{
OSErr err;
OSErr err = errAEEventNotHandled;
if (mStartedUp)
{
nsresult rv;
rv = OpenWindow("chrome://navigator/content", NS_ConvertASCIItoUCS2(url).get());
if (NS_FAILED(rv))
return errAEEventNotHandled;
return err;
}
else
err = AddToCommandLine(url);