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;