Bug 267455 - toolkit-only follow from app-startup (237745) - for mac re-launch code r=darin

This commit is contained in:
bsmedberg%covad.net 2004-11-08 05:00:27 +00:00
Родитель a16a40b07b
Коммит db0973dd63
4 изменённых файлов: 81 добавлений и 8 удалений

Просмотреть файл

@ -947,6 +947,50 @@ ScopedXPCOMStartup::DoAutoreg()
return NS_OK;
}
/**
* This is a little factory class that serves as a singleton-service-factory
* for the nativeappsupport object.
*/
class nsSingletonFactory : public nsIFactory
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIFACTORY
nsSingletonFactory(nsISupports* aSingleton);
~nsSingletonFactory();
private:
nsCOMPtr<nsISupports> mSingleton;
};
nsSingletonFactory::nsSingletonFactory(nsISupports* aSingleton)
: mSingleton(aSingleton)
{
NS_ASSERTION(mSingleton, "Singleton was null!");
}
nsSingletonFactory::~nsSingletonFactory()
{ }
NS_IMPL_ISUPPORTS1(nsSingletonFactory, nsIFactory)
NS_IMETHODIMP
nsSingletonFactory::CreateInstance(nsISupports* aOuter,
const nsIID& aIID,
void* *aResult)
{
NS_ENSURE_NO_AGGREGATION(aOuter);
return mSingleton->QueryInterface(aIID, aResult);
}
NS_IMETHODIMP
nsSingletonFactory::LockFactory(PRBool)
{
return NS_OK;
}
/**
* Set our windowcreator on the WindowWatcher service.
*/
@ -955,6 +999,19 @@ ScopedXPCOMStartup::SetWindowCreator(nsINativeAppSupport* native)
{
nsresult rv;
nsCOMPtr<nsIComponentRegistrar> registrar
(do_QueryInterface(mServiceManager));
NS_ASSERTION(registrar, "Where's the component registrar?");
nsCOMPtr<nsIFactory> nativeFactory = new nsSingletonFactory(native);
NS_ENSURE_TRUE(nativeFactory, NS_ERROR_OUT_OF_MEMORY);
rv = registrar->RegisterFactory(kNativeAppSupportCID,
"Native App Support",
NS_NATIVEAPPSUPPORT_CONTRACTID,
nativeFactory);
NS_ENSURE_SUCCESS(rv, rv);
// Initialize the cmd line service
nsCOMPtr<nsICmdLineService> cmdLineArgs
(do_GetService("@mozilla.org/app-startup/commandLineService;1"));

Просмотреть файл

@ -90,4 +90,6 @@ NS_GetFileFromPath(const char *aPath, nsILocalFile* *aResult);
NS_HIDDEN_(nsresult)
NS_LockProfilePath(nsILocalFile* aPath, nsIProfileLock* *aResult);
#define NS_NATIVEAPPSUPPORT_CONTRACTID "@mozilla.org/toolkit/native-app-support;1"
#endif // nsAppRunner_h__

Просмотреть файл

@ -96,9 +96,17 @@ FORCE_STATIC_LIB = 1
LOCAL_INCLUDES = \
-I$(srcdir) \
-I$(srcdir)/.. \
-I$(srcdir)/../../components/startup/src \
$(NULL)
ifdef MOZ_XUL_APP
LOCAL_INCLUDES += \
-I$(topsrcdir)/toolkit/xre \
-I$(topsrcdir)/toolkit/components/startup/src \
$(NULL)
else
LOCAL_INCLUDEs += -I$(topsrcdir)/xpfe/components/startup/src
endif
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -55,6 +55,10 @@
#include "nsIAppStartup.h"
#include "nsXPFEComponentsCID.h"
#ifdef MOZ_XUL_APP
#include "nsAppRunner.h"
#endif
/*----------------------------------------------------------------------------
AEApplicationClass
@ -323,26 +327,28 @@ void AEApplicationClass::HandleRun(AEDesc *token, const AppleEvent *appleEvent,
----------------------------------------------------------------------------*/
void AEApplicationClass::HandleReOpen(AEDesc *token, const AppleEvent *appleEvent, AppleEvent *reply)
{
// XXXbsmedberg this is just a hack to turn the tbox green, I will fix this tomorrow.
#ifndef MOZ_XUL_APP
OSErr err = noErr;
nsresult rv = NS_OK;
nsCOMPtr<nsINativeAppSupport> nas;
#ifdef MOZ_XUL_APP
nas = do_CreateInstance(NS_NATIVEAPPSUPPORT_CONTRACTID);
if (!nas) ThrowIfOSErr(errAEEventNotHandled);
#else
nsCOMPtr<nsIAppStartup> appStartup(do_GetService(NS_APPSTARTUP_CONTRACTID));
NS_WARN_IF_FALSE(appStartup, "Failed to get appstartup service");
if(!appStartup) ThrowIfOSErr(errAEEventNotHandled);
rv = appStartup->GetNativeAppSupport(getter_AddRefs(nas));
NS_WARN_IF_FALSE(rv==NS_OK, "Failed to get NativeAppSupport");
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to get NativeAppSupport");
if(NS_FAILED(rv)) ThrowIfOSErr(errAEEventNotHandled);
#endif
rv = nas->ReOpen();
if(NS_FAILED(rv)) ThrowIfOSErr(errAEEventNotHandled);
err = CheckForUnusedParameters(appleEvent);
ThrowIfOSErr(err);
#endif
}
/*----------------------------------------------------------------------------