NS_IMETHODIMP nsXREDirProvider::DoStartup() { if (!mProfileNotified) { nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService(); if (!obsSvc) return NS_ERROR_FAILURE; mProfileNotified = true; /* Setup prefs before profile-do-change to be able to use them to track crashes and because we want to begin crash tracking before other code run from this notification since they may cause crashes. */ nsresult rv = mozilla::Preferences::ResetAndReadUserPrefs(); if (NS_FAILED(rv)) NS_WARNING("Failed to setup pref service."); bool safeModeNecessary = false; nsCOMPtr<nsIAppStartup> appStartup (do_GetService(NS_APPSTARTUP_CONTRACTID)); if (appStartup) { rv = appStartup->TrackStartupCrashBegin(&safeModeNecessary); if (NS_FAILED(rv) && rv != NS_ERROR_NOT_AVAILABLE) NS_WARNING("Error while beginning startup crash tracking"); if (!gSafeMode && safeModeNecessary) { appStartup->RestartInSafeMode(nsIAppStartup::eForceQuit); return NS_OK; } } static const PRUnichar kStartup[] = {'s','t','a','r','t','u','p','\0'}; obsSvc->NotifyObservers(nsnull, "profile-do-change", kStartup); // Init the Extension Manager nsCOMPtr<nsIObserver> em = do_GetService("@mozilla.org/addons/integration;1"); if (em) { em->Observe(nsnull, "addons-startup", nsnull); } else { NS_WARNING("Failed to create Addons Manager."); } LoadExtensionBundleDirectories(); obsSvc->NotifyObservers(nsnull, "load-extension-defaults", nsnull); obsSvc->NotifyObservers(nsnull, "profile-after-change", kStartup); // Any component that has registered for the profile-after-change category // should also be created at this time. (void)NS_CreateServicesFromCategory("profile-after-change", nsnull, "profile-after-change"); if (gSafeMode && safeModeNecessary) { static const PRUnichar kCrashed[] = {'c','r','a','s','h','e','d','\0'}; obsSvc->NotifyObservers(nsnull, "safemode-forced", kCrashed); } obsSvc->NotifyObservers(nsnull, "profile-initial-state", nsnull); } return NS_OK; }
NS_IMETHODIMP nsXREDirProvider::DoStartup() { if (!mProfileNotified) { nsCOMPtr<nsIObserverService> obsSvc = mozilla::services::GetObserverService(); if (!obsSvc) return NS_ERROR_FAILURE; mProfileNotified = PR_TRUE; static const PRUnichar kStartup[] = {'s','t','a','r','t','u','p','\0'}; obsSvc->NotifyObservers(nsnull, "profile-do-change", kStartup); // Init the Extension Manager nsCOMPtr<nsIObserver> em = do_GetService("@mozilla.org/addons/integration;1"); if (em) { em->Observe(nsnull, "addons-startup", nsnull); } else { NS_WARNING("Failed to create Addons Manager."); } LoadExtensionBundleDirectories(); obsSvc->NotifyObservers(nsnull, "load-extension-defaults", nsnull); obsSvc->NotifyObservers(nsnull, "profile-after-change", kStartup); // Any component that has registered for the profile-after-change category // should also be created at this time. (void)NS_CreateServicesFromCategory("profile-after-change", nsnull, "profile-after-change"); obsSvc->NotifyObservers(nsnull, "profile-initial-state", nsnull); } return NS_OK; }
// XXX This may be more efficient as a HashTable instead of linear search nsObserverEntry* nsParserService::GetEntry(const nsAString& aTopic) { if (!mHaveNotifiedCategoryObservers) { mHaveNotifiedCategoryObservers = PR_TRUE; NS_CreateServicesFromCategory("parser-service-category", static_cast<nsISupports*>(static_cast<void*>(this)), "parser-service-start"); } nsMatchesTopic matchesTopic(aTopic); mEntries.FirstThat(*&matchesTopic); return matchesTopic.matched?matchesTopic.entry:nsnull; }
NS_INTERFACE_MAP_END /* * nsIPrefService Implementation */ nsresult nsPrefService::Init() { nsPrefBranch *rootBranch = new nsPrefBranch("", PR_FALSE); if (!rootBranch) return NS_ERROR_OUT_OF_MEMORY; mRootBranch = (nsIPrefBranch2 *)rootBranch; nsXPIDLCString lockFileName; nsresult rv; rv = PREF_Init(); NS_ENSURE_SUCCESS(rv, rv); rv = pref_InitInitialObjects(); NS_ENSURE_SUCCESS(rv, rv); /* * The following is a small hack which will allow us to only load the library * which supports the netscape.cfg file if the preference is defined. We * test for the existence of the pref, set in the all.js (mozilla) or * all-ns.js (netscape 6), and if it exists we startup the pref config * category which will do the rest. */ rv = mRootBranch->GetCharPref("general.config.filename", getter_Copies(lockFileName)); if (NS_SUCCEEDED(rv)) NS_CreateServicesFromCategory("pref-config-startup", static_cast<nsISupports *>(static_cast<void *>(this)), "pref-config-startup"); nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1", &rv); if (observerService) { rv = observerService->AddObserver(this, "profile-before-change", PR_TRUE); if (NS_SUCCEEDED(rv)) { rv = observerService->AddObserver(this, "profile-do-change", PR_TRUE); } } return(rv); }
nsresult nsAbQueryLDAPMessageListener::OnLDAPMessageBind (nsILDAPMessage *aMessage) { if (mBound) return NS_OK; // see whether the bind actually succeeded // PRInt32 errCode; nsresult rv = aMessage->GetErrorCode(&errCode); NS_ENSURE_SUCCESS(rv, rv); if (errCode != nsILDAPErrors::SUCCESS) { // if the login failed, tell the wallet to forget this password // if ( errCode == nsILDAPErrors::INAPPROPRIATE_AUTH || errCode == nsILDAPErrors::INVALID_CREDENTIALS ) { // make sure the wallet service has been created, and in doing so, // pass in a login-failed message to tell it to forget this passwd. // // apparently getting passwords stored in the wallet // doesn't require the service to be running, which is why // this might not exist yet. // if (!mDirectoryQuery) return NS_ERROR_NULL_POINTER; rv = NS_CreateServicesFromCategory( "passwordmanager", mDirectoryQuery->mDirectoryUrl, "login-failed"); if (NS_FAILED(rv)) { NS_ERROR("nsLDAPAutoCompleteSession::ForgetPassword(): error" " creating password manager service"); // not much to do at this point, though conceivably we could // pop up a dialog telling the user to go manually delete // this password in the password manager. } } // XXX this error should be propagated back to the UI somehow return NS_OK; } mBound = PR_TRUE; return DoSearch(); }
//---------------------------------------------------------------------------------------- // Initialize default preference JavaScript buffers from // appropriate TEXT resources //---------------------------------------------------------------------------------------- static nsresult pref_InitInitialObjects() { nsCOMPtr<nsIFile> aFile; nsCOMPtr<nsIFile> defaultPrefDir; nsresult rv; // first we parse the GRE default prefs. This also works if we're not using a GRE, rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(defaultPrefDir)); NS_ENSURE_SUCCESS(rv, rv); rv = defaultPrefDir->AppendNative(NS_LITERAL_CSTRING("greprefs")); NS_ENSURE_SUCCESS(rv, rv); rv = pref_LoadPrefsInDir(defaultPrefDir, nsnull, 0); if (NS_FAILED(rv)) { NS_WARNING("Error parsing GRE default preferences. Is this an old-style embedding app?"); } // now parse the "application" default preferences rv = NS_GetSpecialDirectory(NS_APP_PREF_DEFAULTS_50_DIR, getter_AddRefs(defaultPrefDir)); NS_ENSURE_SUCCESS(rv, rv); /* these pref file names should not be used: we process them after all other application pref files for backwards compatibility */ static const char* specialFiles[] = { #if defined(XP_MAC) || defined(XP_MACOSX) "macprefs.js" #elif defined(XP_WIN) "winpref.js" #elif defined(XP_UNIX) "unix.js" #if defined(VMS) , "openvms.js" #elif defined(_AIX) , "aix.js" #endif #if defined(MOZ_WIDGET_PHOTON) , "photon.js" #endif #elif defined(XP_OS2) "os2pref.js" #elif defined(XP_BEOS) "beos.js" #endif }; rv = pref_LoadPrefsInDir(defaultPrefDir, specialFiles, NS_ARRAY_LENGTH(specialFiles)); if (NS_FAILED(rv)) { NS_WARNING("Error parsing application default preferences."); } rv = pref_LoadPrefsInDirList(NS_APP_PREFS_DEFAULTS_DIR_LIST); NS_ENSURE_SUCCESS(rv, rv); NS_CreateServicesFromCategory(NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID, nsnull, NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID); nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1", &rv); if (NS_FAILED(rv) || !observerService) return rv; observerService->NotifyObservers(nsnull, NS_PREFSERVICE_APPDEFAULTS_TOPIC_ID, nsnull); return pref_LoadPrefsInDirList(NS_EXT_PREFS_DEFAULTS_DIR_LIST); }