Bug 756786 - Use XPCOM standalone glue in nsXULRunnerApp.cpp. r=bsmedberg,a=akeybl
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 07 Jun 2012 10:41:59 +0200
changeset 96464 f11c642254b244844b4cac8ce4c3eabe91203cd2
parent 96463 db2d1dd99271df6b914ab64fa0e6cd696bae69b2
child 96465 62cad754d3903d62d546743959beea4e5a9ebc8f
push id160
push userlsblakk@mozilla.com
push dateFri, 13 Jul 2012 18:18:57 +0000
treeherdermozilla-release@228ba1a111fc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg, akeybl
bugs756786
milestone14.0
Bug 756786 - Use XPCOM standalone glue in nsXULRunnerApp.cpp. r=bsmedberg,a=akeybl
xulrunner/app/Makefile.in
xulrunner/app/nsXULRunnerApp.cpp
--- a/xulrunner/app/Makefile.in
+++ b/xulrunner/app/Makefile.in
@@ -62,34 +62,35 @@ PROGRAM = xulrunner-bin$(BIN_SUFFIX)
 endif
 
 DEFINES += -DXULRUNNER_PROGNAME=\"xulrunner\"
 
 ifdef TARGET_XPCOM_ABI
 DEFINES += -DTARGET_XPCOM_ABI=\"$(TARGET_XPCOM_ABI)\"
 endif
 
+DEFINES += -DXPCOM_GLUE
+STL_FLAGS=
 
 CPPSRCS = nsXULRunnerApp.cpp
 
 LOCAL_INCLUDES += \
   -I$(topsrcdir)/toolkit/xre \
   -I$(topsrcdir)/toolkit/profile \
   -I$(topsrcdir)/xpcom/base \
+  -I$(topsrcdir)/xpcom/build \
   $(NULL)
 
 ifeq (cocoa,$(MOZ_WIDGET_TOOLKIT))
 TK_LIBS := -framework Cocoa $(TK_LIBS)
 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
 ifdef MOZ_DEBUG
 MOZ_WINCONSOLE = 1
 else
 MOZ_WINCONSOLE = 0
 endif
--- a/xulrunner/app/nsXULRunnerApp.cpp
+++ b/xulrunner/app/nsXULRunnerApp.cpp
@@ -30,16 +30,18 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+#include "nsXULAppAPI.h"
+#include "nsXPCOMGlue.h"
 #include <stdio.h>
 #include <stdlib.h>
 #ifdef XP_WIN
 #include <windows.h>
 #endif
 
 #include "nsXULAppAPI.h"
 #include "nsXPCOMGlue.h"
@@ -55,16 +57,22 @@
 #include "prprf.h"
 #include "prenv.h"
 #include "nsINIParser.h"
 
 #ifdef XP_WIN
 #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.
  *
  * @param isError
  *        Pass true to indicate severe errors.
  * @param fmt
  *        printf-style format string followed by arguments.
@@ -118,17 +126,17 @@ GetGREVersion(const char *argv0,
               nsACString *aVersion)
 {
   if (aMilestone)
     aMilestone->Assign("<Error>");
   if (aVersion)
     aVersion->Assign("<Error>");
 
   nsCOMPtr<nsILocalFile> iniFile;
-  nsresult rv = XRE_GetBinaryPath(argv0, getter_AddRefs(iniFile));
+  nsresult rv = BinaryPath::GetFile(argv0, getter_AddRefs(iniFile));
   if (NS_FAILED(rv))
     return rv;
 
   iniFile->SetNativeLeafName(NS_LITERAL_CSTRING("platform.ini"));
 
   nsINIParser parser;
   rv = parser.Init(iniFile);
   if (NS_FAILED(rv))
@@ -169,23 +177,36 @@ static void Usage(const char *argv0)
            "APP-FILE\n"
            "  Application initialization file.\n"
            "\n"
            "APP-OPTIONS\n"
            "  Application specific options.\n",
            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<nsILocalFile> 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;
   }
 
   rv = appFile->GetParent(aResult);
   if (NS_FAILED(rv)) {
     Output(true, "Could not find XULRunner installation dir.\n");
@@ -258,16 +279,35 @@ public:
   nsXREAppData* operator -> () const { return mAppData; }
 
 private:
   nsXREAppData* mAppData;
 };
 
 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], "?")))
   {
     Usage(argv[0]);
     return 0;
   }
 
@@ -276,19 +316,25 @@ int main(int argc, char* argv[])
     nsCAutoString milestone;
     nsCAutoString version;
     GetGREVersion(argv[0], &milestone, &version);
     Output(false, "Mozilla XULRunner %s - %s\n",
            milestone.get(), version.get());
     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;
 
     if (IsArg(argv[1], "gre-version")) {
       if (argc != 2) {
         Usage(argv[0]);
         return 1;
       }
@@ -352,17 +398,17 @@ int main(int argc, char* argv[])
     --argc;
 
     static char kAppEnv[MAXPATHLEN];
     snprintf(kAppEnv, MAXPATHLEN, "XUL_APP_FILE=%s", appDataFile);
     putenv(kAppEnv);
   }
 
   nsCOMPtr<nsILocalFile> 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;
   }
 
   AutoAppData appData(appDataLF);
   if (!appData) {
     Output(true, "Error: couldn't parse application.ini.\n");