diff --git a/browser/app/nsBrowserApp.cpp b/browser/app/nsBrowserApp.cpp index 5df1289b8cc..14f992d0540 100644 --- a/browser/app/nsBrowserApp.cpp +++ b/browser/app/nsBrowserApp.cpp @@ -46,6 +46,10 @@ #include #endif +#ifdef XP_MACOSX +#include "MacQuirks.h" +#endif + #include #include #include @@ -208,6 +212,10 @@ int main(int argc, char* argv[]) { char exePath[MAXPATHLEN]; +#ifdef XP_MACOSX + TriggerQuirks(); +#endif + nsresult rv = mozilla::BinaryPath::Get(argv[0], exePath); if (NS_FAILED(rv)) { Output("Couldn't calculate the application directory.\n"); diff --git a/dom/plugins/ipc/interpose/plugin_child_quirks.mm b/dom/plugins/ipc/interpose/plugin_child_quirks.mm index f5fdadddf0e..3897ad949d0 100644 --- a/dom/plugins/ipc/interpose/plugin_child_quirks.mm +++ b/dom/plugins/ipc/interpose/plugin_child_quirks.mm @@ -37,10 +37,6 @@ * * ***** END LICENSE BLOCK ***** */ -// This file is a copy and paste from existing methods from -// libxul. This is intentional because this interpose -// library does not link with libxul. - #include #include #import "CoreFoundation/CoreFoundation.h" @@ -49,9 +45,6 @@ #define PRInt32 int32_t #define PRUint32 uint32_t -PRInt32 -NS_CompareVersions(const char *A, const char *B); - #include "MacQuirks.h" int static_init() { @@ -59,189 +52,3 @@ int static_init() { return 0; } int run = static_init(); - -struct VersionPart { - PRInt32 numA; - - const char *strB; // NOT null-terminated, can be a null pointer - PRUint32 strBlen; - - PRInt32 numC; - - char *extraD; // null-terminated -}; - -/** - * Parse a version part into a number and "extra text". - * - * @returns A pointer to the next versionpart, or null if none. - */ -static char* -ParseVP(char *part, VersionPart &result) -{ - char *dot; - - result.numA = 0; - result.strB = NULL; - result.strBlen = 0; - result.numC = 0; - result.extraD = NULL; - - if (!part) - return part; - - dot = strchr(part, '.'); - if (dot) - *dot = '\0'; - - if (part[0] == '*' && part[1] == '\0') { - result.numA = INT32_MAX; - result.strB = ""; - } - else { - result.numA = strtol(part, const_cast(&result.strB), 10); - } - - if (!*result.strB) { - result.strB = NULL; - result.strBlen = 0; - } - else { - if (result.strB[0] == '+') { - static const char kPre[] = "pre"; - - ++result.numA; - result.strB = kPre; - result.strBlen = sizeof(kPre) - 1; - } - else { - const char *numstart = strpbrk(result.strB, "0123456789+-"); - if (!numstart) { - result.strBlen = strlen(result.strB); - } - else { - result.strBlen = numstart - result.strB; - - result.numC = strtol(numstart, &result.extraD, 10); - if (!*result.extraD) - result.extraD = NULL; - } - } - } - - if (dot) { - ++dot; - - if (!*dot) - dot = NULL; - } - - return dot; -} - - -// compare two null-terminated strings, which may be null pointers -static PRInt32 -ns_strcmp(const char *str1, const char *str2) -{ - // any string is *before* no string - if (!str1) - return str2 != 0; - - if (!str2) - return -1; - - return strcmp(str1, str2); -} - -// compare two length-specified string, which may be null pointers -static PRInt32 -ns_strnncmp(const char *str1, PRUint32 len1, const char *str2, PRUint32 len2) -{ - // any string is *before* no string - if (!str1) - return str2 != 0; - - if (!str2) - return -1; - - for (; len1 && len2; --len1, --len2, ++str1, ++str2) { - if (*str1 < *str2) - return -1; - - if (*str1 > *str2) - return 1; - } - - if (len1 == 0) - return len2 == 0 ? 0 : -1; - - return 1; -} - -// compare two PRInt32 -static PRInt32 -ns_cmp(PRInt32 n1, PRInt32 n2) -{ - if (n1 < n2) - return -1; - - return n1 != n2; -} - -/** - * Compares two VersionParts - */ -static PRInt32 -CompareVP(VersionPart &v1, VersionPart &v2) -{ - PRInt32 r = ns_cmp(v1.numA, v2.numA); - if (r) - return r; - - r = ns_strnncmp(v1.strB, v1.strBlen, v2.strB, v2.strBlen); - if (r) - return r; - - r = ns_cmp(v1.numC, v2.numC); - if (r) - return r; - - return ns_strcmp(v1.extraD, v2.extraD); -} - -PRInt32 -NS_CompareVersions(const char *A, const char *B) -{ - char *A2 = strdup(A); - if (!A2) - return 1; - - char *B2 = strdup(B); - if (!B2) { - free(A2); - return 1; - } - - PRInt32 result; - char *a = A2, *b = B2; - - do { - VersionPart va, vb; - - a = ParseVP(a, va); - b = ParseVP(b, vb); - - result = CompareVP(va, vb); - if (result) - break; - - } while (a || b); - - free(A2); - free(B2); - - return result; -} - - diff --git a/toolkit/xre/MacQuirks.h b/toolkit/xre/MacQuirks.h index c3060ad824c..b8d6b13767f 100644 --- a/toolkit/xre/MacQuirks.h +++ b/toolkit/xre/MacQuirks.h @@ -47,6 +47,197 @@ #include "CoreServices/CoreServices.h" #include "Carbon/Carbon.h" +// This file is a copy and paste from existing methods from +// libxul. This is intentional because this interpose +// library does not link with libxul. + +struct VersionPart { + PRInt32 numA; + + const char *strB; // NOT null-terminated, can be a null pointer + PRUint32 strBlen; + + PRInt32 numC; + + char *extraD; // null-terminated +}; + +/** + * Parse a version part into a number and "extra text". + * + * @returns A pointer to the next versionpart, or null if none. + */ +static char* +ParseVP(char *part, VersionPart &result) +{ + char *dot; + + result.numA = 0; + result.strB = NULL; + result.strBlen = 0; + result.numC = 0; + result.extraD = NULL; + + if (!part) + return part; + + dot = strchr(part, '.'); + if (dot) + *dot = '\0'; + + if (part[0] == '*' && part[1] == '\0') { + result.numA = INT32_MAX; + result.strB = ""; + } + else { + result.numA = strtol(part, const_cast(&result.strB), 10); + } + + if (!*result.strB) { + result.strB = NULL; + result.strBlen = 0; + } + else { + if (result.strB[0] == '+') { + static const char kPre[] = "pre"; + + ++result.numA; + result.strB = kPre; + result.strBlen = sizeof(kPre) - 1; + } + else { + const char *numstart = strpbrk(result.strB, "0123456789+-"); + if (!numstart) { + result.strBlen = strlen(result.strB); + } + else { + result.strBlen = numstart - result.strB; + + result.numC = strtol(numstart, &result.extraD, 10); + if (!*result.extraD) + result.extraD = NULL; + } + } + } + + if (dot) { + ++dot; + + if (!*dot) + dot = NULL; + } + + return dot; +} + + +// compare two null-terminated strings, which may be null pointers +static PRInt32 +ns_strcmp(const char *str1, const char *str2) +{ + // any string is *before* no string + if (!str1) + return str2 != 0; + + if (!str2) + return -1; + + return strcmp(str1, str2); +} + +// compare two length-specified string, which may be null pointers +static PRInt32 +ns_strnncmp(const char *str1, PRUint32 len1, const char *str2, PRUint32 len2) +{ + // any string is *before* no string + if (!str1) + return str2 != 0; + + if (!str2) + return -1; + + for (; len1 && len2; --len1, --len2, ++str1, ++str2) { + if (*str1 < *str2) + return -1; + + if (*str1 > *str2) + return 1; + } + + if (len1 == 0) + return len2 == 0 ? 0 : -1; + + return 1; +} + +// compare two PRInt32 +static PRInt32 +ns_cmp(PRInt32 n1, PRInt32 n2) +{ + if (n1 < n2) + return -1; + + return n1 != n2; +} + +/** + * Compares two VersionParts + */ +static PRInt32 +CompareVP(VersionPart &v1, VersionPart &v2) +{ + PRInt32 r = ns_cmp(v1.numA, v2.numA); + if (r) + return r; + + r = ns_strnncmp(v1.strB, v1.strBlen, v2.strB, v2.strBlen); + if (r) + return r; + + r = ns_cmp(v1.numC, v2.numC); + if (r) + return r; + + return ns_strcmp(v1.extraD, v2.extraD); +} + +/* this is intentionally not static so that we don't end up making copies + * anywhere */ +PRInt32 +NS_CompareVersions(const char *A, const char *B) +{ + char *A2 = strdup(A); + if (!A2) + return 1; + + char *B2 = strdup(B); + if (!B2) { + free(A2); + return 1; + } + + PRInt32 result; + char *a = A2, *b = B2; + + do { + VersionPart va, vb; + + a = ParseVP(a, va); + b = ParseVP(b, vb); + + result = CompareVP(va, vb); + if (result) + break; + + } while (a || b); + + free(A2); + free(B2); + + return result; +} + + static void TriggerQuirks() { diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index 24a682a501b..a9d103755bf 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -69,7 +69,6 @@ #ifdef XP_MACOSX #include "nsVersionComparator.h" -#include "MacQuirks.h" #include "MacLaunchHelper.h" #include "MacApplicationDelegate.h" #include "MacAutoreleasePool.h" @@ -2594,10 +2593,6 @@ XRE_main(int argc, char* argv[], const nsXREAppData* aAppData) NS_BREAK(); #endif -#ifdef XP_MACOSX - TriggerQuirks(); -#endif - // see bug 639842 // it's very important to fire this process BEFORE we set up error handling. // indeed, this process is expected to be crashy, and we don't want the user to see its crashes. diff --git a/toolkit/xre/nsEmbedFunctions.cpp b/toolkit/xre/nsEmbedFunctions.cpp index 8c24bba2e82..8337b710dda 100644 --- a/toolkit/xre/nsEmbedFunctions.cpp +++ b/toolkit/xre/nsEmbedFunctions.cpp @@ -79,7 +79,6 @@ #include "mozilla/Omnijar.h" #if defined(XP_MACOSX) #include "nsVersionComparator.h" -#include "MacQuirks.h" #include "chrome/common/mach_ipc_mac.h" #endif #include "nsX11ErrorHandler.h" @@ -314,10 +313,6 @@ XRE_InitChildProcess(int aArgc, NS_ENSURE_ARG_POINTER(aArgv); NS_ENSURE_ARG_POINTER(aArgv[0]); -#ifdef XP_MACOSX - TriggerQuirks(); -#endif - sChildProcessType = aProcess; // Complete 'task_t' exchange for Mac OS X. This structure has the same size