Bug 407559 - "Allow XUL apps launched with Firefox to override name & vendor" [p=mark.finkle@gmail.com (Mark Finkle) r=bsmedberg a1.9=schrep]
authorreed@reedloden.com
Wed, 19 Dec 2007 03:23:22 -0800
changeset 9468 65be8003e9cbe3990cc03fc12acb0f36b0aa6fdf
parent 9467 9f27e06bb0fd2adfce8f039d978d660079585a39
child 9469 6a5e5c123beb0257ea662af4f44b0c66bc7b476e
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs407559
milestone1.9b3pre
Bug 407559 - "Allow XUL apps launched with Firefox to override name & vendor" [p=mark.finkle@gmail.com (Mark Finkle) r=bsmedberg a1.9=schrep]
toolkit/xre/nsAppRunner.cpp
xulrunner/app/nsXULRunnerApp.cpp
xulrunner/stub/nsXULStub.cpp
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -2480,16 +2480,39 @@ XRE_main(int argc, char* argv[], const n
   // purpose into lying about the main bundle path. It will set
   // XRE_BINARY_PATH to inform us of our real location.
   gBinaryPath = getenv("XRE_BINARY_PATH");
 
   if (gBinaryPath && !*gBinaryPath)
     gBinaryPath = nsnull;
 #endif
 
+  // Check for application.ini overrides
+  const char* override = nsnull;
+  ar = CheckArg("override", PR_TRUE, &override);
+  if (ar == ARG_BAD) {
+    Output(PR_TRUE, "Incorrect number of arguments passed to -override");
+    return 1;
+  }
+  else if (ar == ARG_FOUND) {
+    nsCOMPtr<nsILocalFile> overrideLF;
+    rv = XRE_GetFileFromPath(override, getter_AddRefs(overrideLF));
+    if (NS_FAILED(rv)) {
+      Output(PR_TRUE, "Error: unrecognized override.ini path.\n");
+      return 1;
+    }
+
+    nsXREAppData* overrideAppData = const_cast<nsXREAppData*>(aAppData);
+    rv = XRE_ParseAppData(overrideLF, overrideAppData);
+    if (NS_FAILED(rv)) {
+      Output(PR_TRUE, "Couldn't read override.ini");
+      return 1;
+    }
+  }
+
   ScopedAppData appData(aAppData);
   gAppData = &appData;
 
   // Check sanity and correctness of app data.
 
   if (!appData.name) {
     Output(PR_TRUE, "Error: App:Name not specified in application.ini\n");
     return 1;
--- a/xulrunner/app/nsXULRunnerApp.cpp
+++ b/xulrunner/app/nsXULRunnerApp.cpp
@@ -262,21 +262,16 @@ public:
     if (NS_FAILED(rv))
       mAppData = nsnull;
   }
   ~AutoAppData() {
     if (mAppData)
       XRE_FreeAppData(mAppData);
   }
 
-  nsresult
-  Override(nsILocalFile* aINIFile) {
-    return XRE_ParseAppData(aINIFile, mAppData);
-  }
-
   operator nsXREAppData*() const { return mAppData; }
   nsXREAppData* operator -> () const { return mAppData; }
 
 private:
   nsXREAppData* mAppData;
 };
 
 int main(int argc, char* argv[])
@@ -443,40 +438,16 @@ int main(int argc, char* argv[])
   }
 
   AutoAppData appData(appDataLF);
   if (!appData) {
     Output(PR_TRUE, "Error: couldn't parse application.ini.\n");
     return 2;
   }
 
-  if (argc > 1 && IsArg(argv[1], "override")) {
-    if (argc == 2) {
-      Usage(argv[0]);
-      return 1;
-    }
-    argv[1] = argv[0];
-    ++argv;
-    --argc;
-
-    const char *ovrDataFile = argv[1];
-    argv[1] = argv[0];
-    ++argv;
-    --argc;
-
-    nsCOMPtr<nsILocalFile> ovrDataLF;
-    nsresult rv = XRE_GetFileFromPath(ovrDataFile, getter_AddRefs(ovrDataLF));
-    if (NS_FAILED(rv)) {
-      Output(PR_TRUE, "Error: unrecognized override.ini path.\n");
-      return 2;
-    }
-
-    appData.Override(ovrDataLF);
-  }
-
   return XRE_main(argc, argv, appData);
 }
 
 #if defined( XP_WIN ) && defined( WIN32 ) && !defined(__GNUC__)
 // We need WinMain in order to not be a console app.  This function is
 // unused if we are a console application.
 int WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR args, int )
 {
--- a/xulrunner/stub/nsXULStub.cpp
+++ b/xulrunner/stub/nsXULStub.cpp
@@ -45,17 +45,16 @@
 
 #include <stdarg.h>
 
 #ifdef XP_WIN
 #include <windows.h>
 #include <io.h>
 #define snprintf _snprintf
 #define vsnprintf _vsnprintf
-#define strcasecmp stricmp
 #define PATH_SEPARATOR_CHAR '\\'
 #include "nsWindowsRestart.cpp"
 #define R_OK 04
 #elif defined(XP_MACOSX)
 #include <CFBundle.h>
 #define PATH_SEPARATOR_CHAR '/'
 #elif defined (XP_OS2)
 #define INCL_DOS
@@ -93,61 +92,38 @@ static void Output(PRBool isError, const
   MessageBox(NULL, msg, "XULRunner", flags);
 #else
   vfprintf(stderr, fmt, ap);
 #endif
 
   va_end(ap);
 }
 
-static PRBool IsArg(const char* arg, const char* s)
-{
-  if (*arg == '-')
-  {
-    if (*++arg == '-')
-      ++arg;
-    return !strcasecmp(arg, s);
-  }
-
-#if defined(XP_WIN) || defined(XP_OS2)
-  if (*arg == '/')
-    return !strcasecmp(++arg, s);
-#endif
-
-  return PR_FALSE;
-}
-
 class AutoAppData
 {
 public:
   AutoAppData(nsILocalFile* aINIFile) : mAppData(nsnull) {
     nsresult rv = XRE_CreateAppData(aINIFile, &mAppData);
     if (NS_FAILED(rv))
       mAppData = nsnull;
   }
   ~AutoAppData() {
     if (mAppData)
       XRE_FreeAppData(mAppData);
   }
 
-  nsresult
-  Override(nsILocalFile* aINIFile) {
-    return XRE_ParseAppData(aINIFile, mAppData);
-  }
-
   operator nsXREAppData*() const { return mAppData; }
   nsXREAppData* operator -> () const { return mAppData; }
 
 private:
   nsXREAppData* mAppData;
 };
 
 XRE_CreateAppDataType XRE_CreateAppData;
 XRE_FreeAppDataType XRE_FreeAppData;
-XRE_ParseAppDataType XRE_ParseAppData;
 XRE_mainType XRE_main;
 
 int
 main(int argc, char **argv)
 {
   nsresult rv;
   char *lastSlash;
 
@@ -320,17 +296,16 @@ main(int argc, char **argv)
   if (NS_FAILED(rv)) {
     Output(PR_TRUE, "Couldn't load XPCOM.\n");
     return 1;
   }
 
   static const nsDynamicFunctionLoad kXULFuncs[] = {
     { "XRE_CreateAppData", (NSFuncPtr*) &XRE_CreateAppData },
     { "XRE_FreeAppData", (NSFuncPtr*) &XRE_FreeAppData },
-    { "XRE_ParseAppData", (NSFuncPtr*) &XRE_ParseAppData },
     { "XRE_main", (NSFuncPtr*) &XRE_main },
     { nsnull, nsnull }
   };
 
   rv = XPCOMGlueLoadXULFunctions(kXULFuncs);
   if (NS_FAILED(rv)) {
     Output(PR_TRUE, "Couldn't load XRE functions.\n");
     return 1;
@@ -362,35 +337,16 @@ main(int argc, char **argv)
       lastSlash = strrchr(greDir, PATH_SEPARATOR_CHAR);
       if (lastSlash) {
         *lastSlash = '\0';
       }
       NS_NewNativeLocalFile(nsDependentCString(greDir), PR_FALSE,
                             &appData->xreDirectory);
     }
 
-    if (argc > 1 && IsArg(argv[1], "override")) {
-      if (argc == 2) {
-        Output(PR_TRUE, "Error: missing override.ini file.\n");
-        return 1;
-      }
-
-      const char *ovrDataFile = argv[2];
-
-      nsCOMPtr<nsILocalFile> ovrDataLF;
-      nsresult rv = NS_NewNativeLocalFile(nsDependentCString(ovrDataFile), PR_FALSE,
-                               getter_AddRefs(ovrDataLF));
-      if (NS_FAILED(rv)) {
-        Output(PR_TRUE, "Error: unrecognized override.ini path.\n");
-        return 1;
-      }
-
-      appData.Override(ovrDataLF);
-    }
-
     retval = XRE_main(argc, argv, appData);
   }
 
   NS_LogTerm();
 
   XPCOMGlueShutdown();
 
   return retval;