From 642143012b9bfa9d772d123540805cba37401e09 Mon Sep 17 00:00:00 2001 From: "reed@reedloden.com" Date: Wed, 19 Dec 2007 03:23:22 -0800 Subject: [PATCH] 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 | 23 +++++++++++++++++ xulrunner/app/nsXULRunnerApp.cpp | 29 --------------------- xulrunner/stub/nsXULStub.cpp | 44 -------------------------------- 3 files changed, 23 insertions(+), 73 deletions(-) diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index 4b8b81797215..4b95fb952f32 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -2485,6 +2485,29 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData) 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 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(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; diff --git a/xulrunner/app/nsXULRunnerApp.cpp b/xulrunner/app/nsXULRunnerApp.cpp index 0b0fe4b573c9..2b91c22211e4 100644 --- a/xulrunner/app/nsXULRunnerApp.cpp +++ b/xulrunner/app/nsXULRunnerApp.cpp @@ -267,11 +267,6 @@ public: XRE_FreeAppData(mAppData); } - nsresult - Override(nsILocalFile* aINIFile) { - return XRE_ParseAppData(aINIFile, mAppData); - } - operator nsXREAppData*() const { return mAppData; } nsXREAppData* operator -> () const { return mAppData; } @@ -448,30 +443,6 @@ int main(int argc, char* argv[]) 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 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); } diff --git a/xulrunner/stub/nsXULStub.cpp b/xulrunner/stub/nsXULStub.cpp index 8d9e9e056585..31daab479d53 100644 --- a/xulrunner/stub/nsXULStub.cpp +++ b/xulrunner/stub/nsXULStub.cpp @@ -50,7 +50,6 @@ #include #define snprintf _snprintf #define vsnprintf _vsnprintf -#define strcasecmp stricmp #define PATH_SEPARATOR_CHAR '\\' #include "nsWindowsRestart.cpp" #define R_OK 04 @@ -98,23 +97,6 @@ static void Output(PRBool isError, const char *fmt, ... ) 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: @@ -128,11 +110,6 @@ public: XRE_FreeAppData(mAppData); } - nsresult - Override(nsILocalFile* aINIFile) { - return XRE_ParseAppData(aINIFile, mAppData); - } - operator nsXREAppData*() const { return mAppData; } nsXREAppData* operator -> () const { return mAppData; } @@ -142,7 +119,6 @@ private: XRE_CreateAppDataType XRE_CreateAppData; XRE_FreeAppDataType XRE_FreeAppData; -XRE_ParseAppDataType XRE_ParseAppData; XRE_mainType XRE_main; int @@ -325,7 +301,6 @@ main(int argc, char **argv) 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 } }; @@ -367,25 +342,6 @@ main(int argc, char **argv) &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 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); }