From b88ad7be0d0adf0a740f911c4b5b41b51ab620f2 Mon Sep 17 00:00:00 2001 From: "darin%meer.net" Date: Tue, 14 Sep 2004 21:05:46 +0000 Subject: [PATCH] landing patch for bug 259213 "Coalesce boolean fields into nsXREAppData::flags" r=bsmedberg --- browser/app/nsBrowserApp.cpp | 5 ++- calendar/sunbird/app/nsCalendarApp.cpp | 4 +-- mail/app/nsMailApp.cpp | 5 ++- toolkit/xre/nsAppRunner.cpp | 45 ++++++++++++++------------ toolkit/xre/nsXULAppAPI.h | 38 ++++++++++++++-------- 5 files changed, 54 insertions(+), 43 deletions(-) diff --git a/browser/app/nsBrowserApp.cpp b/browser/app/nsBrowserApp.cpp index 7800c2194b98..404c34d55561 100644 --- a/browser/app/nsBrowserApp.cpp +++ b/browser/app/nsBrowserApp.cpp @@ -49,9 +49,8 @@ static const nsXREAppData kAppData = { APP_VERSION, BUILD_ID, "Copyright (c) 2004 mozilla.org", - PR_TRUE, - PR_TRUE, - PR_FALSE + NS_XRE_ENABLE_PROFILE_MIGRATOR | + NS_XRE_ENABLE_EXTENSION_MANAGER }; diff --git a/calendar/sunbird/app/nsCalendarApp.cpp b/calendar/sunbird/app/nsCalendarApp.cpp index ad669906b524..59cec1c5b62b 100644 --- a/calendar/sunbird/app/nsCalendarApp.cpp +++ b/calendar/sunbird/app/nsCalendarApp.cpp @@ -51,9 +51,7 @@ static const nsXREAppData kAppData = { APP_VERSION, BUILD_ID, "Copyright (c) 2004 mozilla.org", - PR_FALSE, // no profile migration - PR_TRUE, - PR_FALSE + NS_XRE_ENABLE_EXTENSION_MANAGER }; diff --git a/mail/app/nsMailApp.cpp b/mail/app/nsMailApp.cpp index d7a58321083f..34e00325d2c9 100644 --- a/mail/app/nsMailApp.cpp +++ b/mail/app/nsMailApp.cpp @@ -50,9 +50,8 @@ static const nsXREAppData kAppData = { APP_VERSION, BUILD_ID, "Copyright (c) 2004 mozilla.org", - PR_TRUE, - PR_TRUE, - PR_FALSE + NS_XRE_ENABLE_PROFILE_MIGRATOR | + NS_XRE_ENABLE_EXTENSION_MANAGER }; int main(int argc, char* argv[]) diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp index f015624d0ce3..81cde67d4a24 100644 --- a/toolkit/xre/nsAppRunner.cpp +++ b/toolkit/xre/nsAppRunner.cpp @@ -386,9 +386,7 @@ CheckArg(const char* aArg, const char **aParam = nsnull) static const nsXREAppData* LoadAppData(const char* appDataFile) { static char vendor[256], name[256], version[32], buildID[32], copyright[512]; - static nsXREAppData data = { - vendor, name, version, buildID, copyright, PR_FALSE, PR_FALSE, PR_FALSE - }; + static nsXREAppData data = { vendor, name, version, buildID, copyright, 0 }; nsCOMPtr lf; NS_GetFileFromPath(appDataFile, getter_AddRefs(lf)); @@ -407,7 +405,7 @@ static const nsXREAppData* LoadAppData(const char* appDataFile) return nsnull; } - int i; + PRUint32 i; // Read string-valued fields const struct { @@ -422,7 +420,7 @@ static const nsXREAppData* LoadAppData(const char* appDataFile) { "BuildID", buildID, sizeof(buildID), PR_TRUE }, { "Copyright", copyright, sizeof(copyright), PR_FALSE } }; - for (i=0; i<5; ++i) { + for (i = 0; i < NS_ARRAY_LENGTH(string_fields); ++i) { rv = parser.GetString("App", string_fields[i].key, string_fields[i].buf, string_fields[i].bufLen); if (NS_FAILED(rv)) { @@ -439,17 +437,23 @@ static const nsXREAppData* LoadAppData(const char* appDataFile) // Read boolean-valued fields const struct { const char* key; - PRBool* value; + PRUint32 flag; } boolean_fields[] = { - { "EnableProfileMigrator", &data.enableProfileMigrator }, - { "EnableExtensionManager", &data.enableExtensionManager } + { "UseStartupPrefs", NS_XRE_USE_STARTUP_PREFS }, + { "EnableProfileMigrator", NS_XRE_ENABLE_PROFILE_MIGRATOR }, + { "EnableExtensionManager", NS_XRE_ENABLE_EXTENSION_MANAGER } }; - char buf[2]; - for (i=0; i<2; ++i) { + char buf[6]; // large enough to hold "false" + data.flags = 0; + for (i = 0; i < NS_ARRAY_LENGTH(boolean_fields); ++i) { rv = parser.GetString("XRE", boolean_fields[i].key, buf, sizeof(buf)); - if (NS_SUCCEEDED(rv)) - *(boolean_fields[i].value) = - buf[0] == '1' || buf[0] == 't' || buf[0] == 'T'; + // accept a truncated result since we are only interested in the + // first character. this is designed to allow the possibility of + // expanding these boolean attributes to express additional options. + if ((NS_SUCCEEDED(rv) || rv == NS_ERROR_LOSS_OF_SIGNIFICANT_DATA) && + (buf[0] == '1' || buf[0] == 't' || buf[0] == 'T')) { + data.flags |= boolean_fields[i].flag; + } } #ifdef DEBUG @@ -459,8 +463,7 @@ static const nsXREAppData* LoadAppData(const char* appDataFile) printf(" Version %s\n", data.appVersion); printf(" BuildID %s\n", data.appBuildID); printf(" Copyright %s\n", data.copyright); - printf(" EnablePM %u\n", data.enableProfileMigrator); - printf(" EnableEM %u\n", data.enableExtensionManager); + printf(" Flags %08x\n", data.flags); printf("---------------------------------------------------------\n"); #endif @@ -1861,7 +1864,7 @@ int xre_main(int argc, char* argv[], const nsXREAppData* aAppData) chromeReg->CheckForNewChrome(); - if (gAppData->enableExtensionManager) { + if (gAppData->flags & NS_XRE_ENABLE_EXTENSION_MANAGER) { nsCOMPtr em (do_GetService("@mozilla.org/extensions/manager;1")); NS_ENSURE_TRUE(em, 1); @@ -1964,7 +1967,7 @@ int xre_main(int argc, char* argv[], const nsXREAppData* aAppData) PRBool upgraded = PR_FALSE; PRBool componentsListChanged = PR_FALSE; - if (gAppData->enableExtensionManager) { + if (gAppData->flags & NS_XRE_ENABLE_EXTENSION_MANAGER) { // Check for version compatibility with the last version of the app this // profile was started with. char version[MAXPATHLEN]; @@ -2058,7 +2061,7 @@ int xre_main(int argc, char* argv[], const nsXREAppData* aAppData) appShellService->EnterLastWindowClosingSurvivalArea(); // Profile Migration - if (gAppData->enableProfileMigrator && gDoMigration) { + if (gAppData->flags & NS_XRE_ENABLE_PROFILE_MIGRATOR && gDoMigration) { gDoMigration = PR_FALSE; nsCOMPtr pm (do_CreateInstance(NS_PROFILEMIGRATOR_CONTRACTID)); @@ -2073,7 +2076,7 @@ int xre_main(int argc, char* argv[], const nsXREAppData* aAppData) NS_ENSURE_SUCCESS(rv, 1); // Extension Compatibility Checking and Startup - if (gAppData->enableExtensionManager) { + if (gAppData->flags & NS_XRE_ENABLE_EXTENSION_MANAGER) { nsCOMPtr em(do_GetService("@mozilla.org/extensions/manager;1")); NS_ENSURE_TRUE(em, 1); @@ -2130,7 +2133,9 @@ int xre_main(int argc, char* argv[], const nsXREAppData* aAppData) // if we had no command line arguments, argc == 1. PRBool windowOpened = PR_FALSE; - rv = DoCommandLines(cmdLineArgs, aAppData->useStartupPrefs, &windowOpened); + rv = DoCommandLines(cmdLineArgs, + aAppData->flags & NS_XRE_USE_STARTUP_PREFS, + &windowOpened); NS_ENSURE_SUCCESS(rv, 1); // Make sure there exists at least 1 window. diff --git a/toolkit/xre/nsXULAppAPI.h b/toolkit/xre/nsXULAppAPI.h index d9aa17699472..4bd1f7439d03 100644 --- a/toolkit/xre/nsXULAppAPI.h +++ b/toolkit/xre/nsXULAppAPI.h @@ -41,12 +41,32 @@ #define _nsXULAppAPI_h__ #include "prtypes.h" -class nsILocalFile; + +/** + * This API is "not even kinda frozen yet" + */ + +/** + * Indicates whether or not to heed "general.startup.*" prefs. + * XXXbsmedberg this is going away + */ +#define NS_XRE_USE_STARTUP_PREFS (1 << 0) + +/** + * Indicates whether or not the profile migrator service may be + * invoked at startup when creating a profile. + */ +#define NS_XRE_ENABLE_PROFILE_MIGRATOR (1 << 1) + +/** + * Indicates whether or not the extension manager service should be + * initialized at startup. + */ +#define NS_XRE_ENABLE_EXTENSION_MANAGER (1 << 2) /** * Application-specific data needed to start the apprunner. */ - struct nsXREAppData { /** @@ -78,18 +98,9 @@ struct nsXREAppData const char *copyright; /** - * Indicates whether or not the profile migrator service may be - * invoked at startup when creating a profile. + * Combination of NS_XRE_ prefixed flags (defined above). */ - PRBool enableProfileMigrator; - - /** - * Indicates whether or not the extension manager service should be - * initialized at startup. - */ - PRBool enableExtensionManager; - - PRBool useStartupPrefs; // XXXbsmedberg this is going away + PRUint32 flags; }; /** @@ -106,7 +117,6 @@ struct nsXREAppData * SetCurrentDirectory, and relative paths on the command line * won't be correct. */ - int xre_main(int argc, char* argv[], const nsXREAppData* aAppData); #endif // _nsXULAppAPI_h__