Bug 392967: Load app and extension prefs separately. r=bsmedberg

This commit is contained in:
thunder@mozilla.com 2007-08-31 19:16:47 -07:00
Родитель b9778e31fc
Коммит 9d45a8e240
4 изменённых файлов: 54 добавлений и 24 удалений

Просмотреть файл

@ -179,4 +179,11 @@ interface nsIPrefService : nsISupports
*/
#define NS_PREFSERVICE_RESET_TOPIC_ID "prefservice:before-reset"
/**
* Notification sent when after reading app-provided default
* preferences, but before user profile override defaults or extension
* defaults are loaded.
*/
#define NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID "prefservice:after-app-defaults"
%}

Просмотреть файл

@ -717,6 +717,32 @@ pref_LoadPrefsInDir(nsIFile* aDir, char const *const *aSpecialFiles, PRUint32 aS
return rv;
}
static nsresult pref_LoadPrefsInDirList(const char *listId)
{
nsresult rv;
nsCOMPtr<nsIProperties> dirSvc(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv));
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsISimpleEnumerator> dirList;
dirSvc->Get(listId,
NS_GET_IID(nsISimpleEnumerator),
getter_AddRefs(dirList));
if (dirList) {
PRBool hasMore;
while (NS_SUCCEEDED(dirList->HasMoreElements(&hasMore)) && hasMore) {
nsCOMPtr<nsISupports> elem;
dirList->GetNext(getter_AddRefs(elem));
if (elem) {
nsCOMPtr<nsIFile> dir = do_QueryInterface(elem);
if (dir) {
// Do we care if a file provided by this process fails to load?
pref_LoadPrefsInDir(dir, nsnull, 0);
}
}
}
}
return NS_OK;
}
//----------------------------------------------------------------------------------------
// Initialize default preference JavaScript buffers from
@ -773,30 +799,19 @@ static nsresult pref_InitInitialObjects()
NS_WARNING("Error parsing application default preferences.");
}
// xxxbsmedberg: TODO load default prefs from a category
// but the architecture is not quite there yet
rv = pref_LoadPrefsInDirList(NS_APP_PREFS_DEFAULTS_DIR_LIST);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIProperties> dirSvc(do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv));
if (NS_FAILED(rv)) return rv;
NS_CreateServicesFromCategory(NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID,
nsnull, NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID);
nsCOMPtr<nsISimpleEnumerator> dirList;
dirSvc->Get(NS_APP_PREFS_DEFAULTS_DIR_LIST,
NS_GET_IID(nsISimpleEnumerator),
getter_AddRefs(dirList));
if (dirList) {
PRBool hasMore;
while (NS_SUCCEEDED(dirList->HasMoreElements(&hasMore)) && hasMore) {
nsCOMPtr<nsISupports> elem;
dirList->GetNext(getter_AddRefs(elem));
if (elem) {
nsCOMPtr<nsIFile> dir = do_QueryInterface(elem);
if (dir) {
// Do we care if a file provided by this process fails to load?
pref_LoadPrefsInDir(dir, nsnull, 0);
}
}
}
}
nsCOMPtr<nsIObserverService> observerService =
do_GetService("@mozilla.org/observer-service;1", &rv);
if (NS_FAILED(rv) || !observerService)
return rv;
return NS_OK;
observerService->NotifyObservers(nsnull, NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID, nsnull);
return pref_LoadPrefsInDirList(NS_EXT_PREFS_DEFAULTS_DIR_LIST);
}

Просмотреть файл

@ -640,7 +640,14 @@ nsXREDirProvider::GetFilesInternal(const char* aProperty,
LoadAppPlatformDirIntoArray(mXULAppDir, kAppendPrefDir, directories);
}
rv = NS_NewArrayEnumerator(aResult, directories);
}
else if (!strcmp(aProperty, NS_EXT_PREFS_DEFAULTS_DIR_LIST)) {
static const char *const kAppendPrefDir[] = { "defaults", "preferences", nsnull };
nsCOMArray<nsIFile> directories;
PRBool exists;
if (mProfileDir) {
nsCOMPtr<nsIFile> overrideFile;
mProfileDir->Clone(getter_AddRefs(overrideFile));

Просмотреть файл

@ -96,6 +96,7 @@
#define NS_APP_PREFS_50_DIR "PrefD" // Directory which contains user prefs
#define NS_APP_PREFS_50_FILE "PrefF"
#define NS_APP_PREFS_DEFAULTS_DIR_LIST "PrefDL"
#define NS_EXT_PREFS_DEFAULTS_DIR_LIST "ExtPrefDL"
#define NS_APP_PREFS_OVERRIDE_DIR "PrefDOverride" // Directory for per-profile defaults
#define NS_APP_USER_PROFILE_50_DIR "ProfD"