From be6b93ebc964d2993d4b2e0933c7cf4736b824b1 Mon Sep 17 00:00:00 2001 From: "bryner%brianryner.com" Date: Wed, 10 Nov 2004 07:53:17 +0000 Subject: [PATCH] Fix pref observer usage so that nsFormHistory notices when the user has turned off form autofill (bug 254485). r=ben. --- toolkit/components/satchel/src/nsFormHistory.cpp | 16 +++++++++------- toolkit/components/satchel/src/nsFormHistory.h | 2 ++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/toolkit/components/satchel/src/nsFormHistory.cpp b/toolkit/components/satchel/src/nsFormHistory.cpp index 87df6e1e737..290949db1bb 100644 --- a/toolkit/components/satchel/src/nsFormHistory.cpp +++ b/toolkit/components/satchel/src/nsFormHistory.cpp @@ -143,12 +143,15 @@ nsFormHistory::FormHistoryEnabled() { if (!gPrefsInitialized) { nsCOMPtr prefService = do_GetService(NS_PREFSERVICE_CONTRACTID); - nsCOMPtr branch; - prefService->GetBranch(PREF_FORMFILL_BRANCH, getter_AddRefs(branch)); - branch->GetBoolPref(PREF_FORMFILL_ENABLE, &gFormHistoryEnabled); - nsCOMPtr branchInternal = do_QueryInterface(branch); - branchInternal->AddObserver(PREF_FORMFILL_BRANCH, gFormHistory, PR_TRUE); + prefService->GetBranch(PREF_FORMFILL_BRANCH, + getter_AddRefs(gFormHistory->mPrefBranch)); + gFormHistory->mPrefBranch->GetBoolPref(PREF_FORMFILL_ENABLE, + &gFormHistoryEnabled); + + nsCOMPtr branchInternal = + do_QueryInterface(gFormHistory->mPrefBranch); + branchInternal->AddObserver(PREF_FORMFILL_ENABLE, gFormHistory, PR_TRUE); gPrefsInitialized = PR_TRUE; } @@ -338,8 +341,7 @@ NS_IMETHODIMP nsFormHistory::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData) { if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) { - nsCOMPtr branch = do_QueryInterface(aSubject); - branch->GetBoolPref(PREF_FORMFILL_ENABLE, &gFormHistoryEnabled); + mPrefBranch->GetBoolPref(PREF_FORMFILL_ENABLE, &gFormHistoryEnabled); } return NS_OK; diff --git a/toolkit/components/satchel/src/nsFormHistory.h b/toolkit/components/satchel/src/nsFormHistory.h index 5a13ceb18be..09ef27fbedb 100644 --- a/toolkit/components/satchel/src/nsFormHistory.h +++ b/toolkit/components/satchel/src/nsFormHistory.h @@ -44,6 +44,7 @@ #include "nsString.h" #include "nsCOMPtr.h" #include "nsIObserver.h" +#include "nsIPrefBranch.h" #include "nsWeakReference.h" #include "mdb.h" @@ -101,6 +102,7 @@ protected: static PRBool gPrefsInitialized; nsCOMPtr mMdbFactory; + nsCOMPtr mPrefBranch; nsIMdbEnv* mEnv; nsIMdbStore* mStore; nsIMdbTable* mTable;