From f0b5e3a8185ef044693b754f8a0294454f6a46d2 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Thu, 7 Jun 2012 10:41:59 +0200 Subject: [PATCH] Bug 756786 - Use XPCOM standalone glue in nsXULRunnerApp.cpp. r=bsmedberg --- xulrunner/app/Makefile.in | 7 +++-- xulrunner/app/nsXULRunnerApp.cpp | 54 +++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/xulrunner/app/Makefile.in b/xulrunner/app/Makefile.in index b4c77172059..35225d65934 100644 --- a/xulrunner/app/Makefile.in +++ b/xulrunner/app/Makefile.in @@ -29,6 +29,8 @@ ifdef TARGET_XPCOM_ABI DEFINES += -DTARGET_XPCOM_ABI=\"$(TARGET_XPCOM_ABI)\" endif +DEFINES += -DXPCOM_GLUE +STL_FLAGS= CPPSRCS = nsXULRunnerApp.cpp @@ -36,6 +38,7 @@ LOCAL_INCLUDES += \ -I$(topsrcdir)/toolkit/xre \ -I$(topsrcdir)/toolkit/profile \ -I$(topsrcdir)/xpcom/base \ + -I$(topsrcdir)/xpcom/build \ $(NULL) ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT)) @@ -44,9 +47,7 @@ endif LIBS += \ $(EXTRA_DSO_LIBS) \ - $(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \ - $(XPCOM_LIBS) \ - $(NSPR_LIBS) \ + $(XPCOM_STANDALONE_GLUE_LDOPTS) \ $(NULL) ifndef MOZ_WINCONSOLE diff --git a/xulrunner/app/nsXULRunnerApp.cpp b/xulrunner/app/nsXULRunnerApp.cpp index b063de32cf4..4c8f10671e7 100644 --- a/xulrunner/app/nsXULRunnerApp.cpp +++ b/xulrunner/app/nsXULRunnerApp.cpp @@ -2,6 +2,8 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "nsXULAppAPI.h" +#include "nsXPCOMGlue.h" #include #include #ifdef XP_WIN @@ -27,6 +29,12 @@ #include "nsWindowsWMain.cpp" #endif +#include "BinaryPath.h" + +#include "nsXPCOMPrivate.h" // for MAXPATHLEN and XPCOM_DLL + +using namespace mozilla; + /** * Output a string to the user. This method is really only meant to be used to * output last-ditch error messages designed for developers NOT END USERS. @@ -90,7 +98,7 @@ GetGREVersion(const char *argv0, aVersion->Assign(""); nsCOMPtr iniFile; - nsresult rv = XRE_GetBinaryPath(argv0, getter_AddRefs(iniFile)); + nsresult rv = BinaryPath::GetFile(argv0, getter_AddRefs(iniFile)); if (NS_FAILED(rv)) return rv; @@ -141,13 +149,26 @@ static void Usage(const char *argv0) milestone.get()); } +XRE_GetFileFromPathType XRE_GetFileFromPath; +XRE_CreateAppDataType XRE_CreateAppData; +XRE_FreeAppDataType XRE_FreeAppData; +XRE_mainType XRE_main; + +static const nsDynamicFunctionLoad kXULFuncs[] = { + { "XRE_GetFileFromPath", (NSFuncPtr*) &XRE_GetFileFromPath }, + { "XRE_CreateAppData", (NSFuncPtr*) &XRE_CreateAppData }, + { "XRE_FreeAppData", (NSFuncPtr*) &XRE_FreeAppData }, + { "XRE_main", (NSFuncPtr*) &XRE_main }, + { nsnull, nsnull } +}; + static nsresult GetXULRunnerDir(const char *argv0, nsIFile* *aResult) { nsresult rv; nsCOMPtr appFile; - rv = XRE_GetBinaryPath(argv0, getter_AddRefs(appFile)); + rv = BinaryPath::GetFile(argv0, getter_AddRefs(appFile)); if (NS_FAILED(rv)) { Output(true, "Could not find XULRunner application path.\n"); return rv; @@ -230,6 +251,25 @@ private: int main(int argc, char* argv[]) { + char exePath[MAXPATHLEN]; + nsresult rv = mozilla::BinaryPath::Get(argv[0], exePath); + if (NS_FAILED(rv)) { + Output(true, "Couldn't calculate the application directory.\n"); + return 255; + } + + char *lastSlash = strrchr(exePath, XPCOM_FILE_PATH_SEPARATOR[0]); + if (!lastSlash || (size_t(lastSlash - exePath) > MAXPATHLEN - sizeof(XPCOM_DLL) - 1)) + return 255; + + strcpy(++lastSlash, XPCOM_DLL); + + rv = XPCOMGlueStartup(exePath); + if (NS_FAILED(rv)) { + Output(true, "Couldn't load XPCOM.\n"); + return 255; + } + if (argc > 1 && (IsArg(argv[1], "h") || IsArg(argv[1], "help") || IsArg(argv[1], "?"))) @@ -248,9 +288,15 @@ int main(int argc, char* argv[]) return 0; } + rv = XPCOMGlueLoadXULFunctions(kXULFuncs); + if (NS_FAILED(rv)) { + Output(true, "Couldn't load XRE functions.\n"); + return 255; + } + if (argc > 1) { nsCAutoString milestone; - nsresult rv = GetGREVersion(argv[0], &milestone, nsnull); + rv = GetGREVersion(argv[0], &milestone, nsnull); if (NS_FAILED(rv)) return 2; @@ -324,7 +370,7 @@ int main(int argc, char* argv[]) } nsCOMPtr appDataLF; - nsresult rv = XRE_GetFileFromPath(appDataFile, getter_AddRefs(appDataLF)); + rv = XRE_GetFileFromPath(appDataFile, getter_AddRefs(appDataLF)); if (NS_FAILED(rv)) { Output(true, "Error: unrecognized application.ini path.\n"); return 2;