From 7d79d7ba8b71e1274c8989abf60f081f92278d6a Mon Sep 17 00:00:00 2001 From: "bsmedberg%covad.net" Date: Wed, 28 Jan 2004 23:45:17 +0000 Subject: [PATCH] Bug 232201 part 2 - update consumers to use inherited nsIPrefBranchInternal interface. This should be happy for codesize. r=alecf sr=darin --- content/events/src/nsEventStateManager.cpp | 9 ++--- content/events/src/nsEventStateManager.h | 4 +-- dom/src/base/nsGlobalWindow.cpp | 1 - .../activex/src/plugin/PrefObserver.cpp | 34 +++++++------------ extensions/cookie/nsCookiePermission.cpp | 15 ++++---- extensions/cookie/nsImgManager.cpp | 18 +++++----- extensions/cookie/nsPopupWindowManager.cpp | 5 +-- extensions/cookie/nsPopupWindowManager.h | 4 +-- extensions/p3p/src/nsP3PService.cpp | 7 ++-- .../typeaheadfind/src/nsTypeAheadFind.cpp | 10 +++--- .../webservices/wsdl/src/nsWSDLLoader.cpp | 1 - layout/generic/nsFrameSetFrame.cpp | 17 +++------- layout/html/document/src/nsFrameSetFrame.cpp | 17 +++------- layout/xul/base/src/nsXULTooltipListener.cpp | 5 ++- modules/libpref/src/nsPrefService.cpp | 31 ++--------------- modules/libpref/src/nsPrefService.h | 4 +-- netwerk/base/src/nsIOService.cpp | 18 ++++------ netwerk/base/src/nsIOService.h | 3 +- netwerk/base/src/nsProtocolProxyService.cpp | 6 ++-- netwerk/base/src/nsStandardURL.cpp | 25 +++++--------- netwerk/cache/src/nsCacheService.cpp | 26 ++++---------- netwerk/cookie/src/nsCookieService.cpp | 8 ++--- netwerk/dns/src/nsDNSService2.cpp | 11 +++--- .../protocol/ftp/src/nsFtpProtocolHandler.cpp | 12 +++---- netwerk/protocol/http/src/nsHttpHandler.cpp | 29 +++++----------- netwerk/protocol/http/src/nsHttpHandler.h | 1 - uriloader/prefetch/nsPrefetchService.cpp | 18 ++++------ 27 files changed, 105 insertions(+), 234 deletions(-) diff --git a/content/events/src/nsEventStateManager.cpp b/content/events/src/nsEventStateManager.cpp index c49f50234824..1bbb3a6aee7d 100644 --- a/content/events/src/nsEventStateManager.cpp +++ b/content/events/src/nsEventStateManager.cpp @@ -47,7 +47,6 @@ #include "nsIWidget.h" #include "nsIPresContext.h" #include "nsIPresShell.h" -#include "nsIPrefBranchInternal.h" #include "nsDOMEvent.h" #include "nsHTMLAtoms.h" #include "nsIEditorDocShell.h" @@ -214,9 +213,7 @@ nsEventStateManager::Init() &nsEventStateManager::gGeneralAccesskeyModifier); } - nsCOMPtr prefBranchInt(do_QueryInterface(mPrefBranch)); - if (prefBranchInt) - prefBranchInt->AddObserver("accessibility.browsewithcaret", this, PR_TRUE); + mPrefBranch->AddObserver("accessibility.browsewithcaret", this, PR_TRUE); } if (nsEventStateManager::sTextfieldSelectModel == eTextfieldSelect_unset) { @@ -272,9 +269,7 @@ nsEventStateManager::~nsEventStateManager() nsresult nsEventStateManager::Shutdown() { - nsCOMPtr prefBranchInt(do_QueryInterface(mPrefBranch)); - if (prefBranchInt) - prefBranchInt->RemoveObserver("accessibility.browsewithcaret", this); + mPrefBranch->RemoveObserver("accessibility.browsewithcaret", this); mPrefBranch = nsnull; diff --git a/content/events/src/nsEventStateManager.h b/content/events/src/nsEventStateManager.h index 9754abbfa3a0..3cc9c7ef7fe7 100644 --- a/content/events/src/nsEventStateManager.h +++ b/content/events/src/nsEventStateManager.h @@ -42,7 +42,7 @@ #include "nsIEventStateManager.h" #include "nsGUIEvent.h" #include "nsIContent.h" -#include "nsIPrefBranch.h" +#include "nsIPrefBranchInternal.h" #include "nsIObserver.h" #include "nsWeakReference.h" #include "nsHashtable.h" @@ -306,7 +306,7 @@ protected: static PRInt32 gGeneralAccesskeyModifier; // For preferences handling - nsCOMPtr mPrefBranch; + nsCOMPtr mPrefBranch; PRPackedBool m_haveShutdown; // To inform people that dispatched events that frames have been cleared and diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index 468c5bfa4f0f..d1bd86829fae 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -99,7 +99,6 @@ #include "nsIMarkupDocumentViewer.h" #include "nsIPrefService.h" #include "nsIPrefBranch.h" -#include "nsIPrefBranchInternal.h" #include "nsIPrefLocalizedString.h" #include "nsIPresShell.h" #include "nsIPrivateDOMEvent.h" diff --git a/embedding/browser/activex/src/plugin/PrefObserver.cpp b/embedding/browser/activex/src/plugin/PrefObserver.cpp index 3e88f9a9444e..4d92344bef3e 100644 --- a/embedding/browser/activex/src/plugin/PrefObserver.cpp +++ b/embedding/browser/activex/src/plugin/PrefObserver.cpp @@ -77,7 +77,7 @@ protected: void Sync(nsIPrefBranch *aPrefBranch); PRUint32 mHostingFlags; - nsCOMPtr mPrefService; + nsCOMPtr mPrefBranch; public: NS_DECL_ISUPPORTS NS_DECL_NSIOBSERVER @@ -99,8 +99,8 @@ PrefObserver::PrefObserver() : mHostingFlags(kDefaultHostingFlags) { nsresult rv = NS_OK; - mPrefService = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); - NS_ASSERTION(mPrefService, "where is the pref service?"); + mPrefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); + NS_ASSERTION(mPrefBranch, "where is the pref service?"); } PrefObserver::~PrefObserver() @@ -164,19 +164,14 @@ void PrefObserver::Sync(nsIPrefBranch *aPrefBranch) nsresult PrefObserver::Subscribe() { - NS_ENSURE_TRUE(mPrefService, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(mPrefBranch, NS_ERROR_FAILURE); nsresult rv; - nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); - if (NS_FAILED(rv)) return rv; - nsCOMPtr prefInternal = do_QueryInterface(prefBranch, &rv); - if (NS_FAILED(rv)) return rv; + mPrefBranch->AddObserver(kProxyPref, this, PR_TRUE); + mPrefBranch->AddObserver(kUserAgentPref, this, PR_TRUE); + mPrefBranch->AddObserver(kActiveXHostingFlags, this, PR_TRUE); - prefInternal->AddObserver(kProxyPref, this, PR_TRUE); - prefInternal->AddObserver(kUserAgentPref, this, PR_TRUE); - prefInternal->AddObserver(kActiveXHostingFlags, this, PR_TRUE); - - Sync(prefBranch); + Sync(mPrefBranch); return S_OK; } @@ -184,17 +179,12 @@ PrefObserver::Subscribe() nsresult PrefObserver::Unsubscribe() { - NS_ENSURE_TRUE(mPrefService, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(mPrefBranch, NS_ERROR_FAILURE); nsresult rv; - nsCOMPtr prefBranch = do_QueryInterface(mPrefService, &rv); - if (NS_FAILED(rv)) return rv; - nsCOMPtr prefInternal = do_QueryInterface(prefBranch, &rv); - if (NS_FAILED(rv)) return rv; - - prefInternal->RemoveObserver(kProxyPref, this); - prefInternal->RemoveObserver(kUserAgentPref, this); - prefInternal->RemoveObserver(kActiveXHostingFlags, this); + mPrefBranch->RemoveObserver(kProxyPref, this); + mPrefBranch->RemoveObserver(kUserAgentPref, this); + mPrefBranch->RemoveObserver(kActiveXHostingFlags, this); return NS_OK; } diff --git a/extensions/cookie/nsCookiePermission.cpp b/extensions/cookie/nsCookiePermission.cpp index 367f21b8fc05..87153f502789 100644 --- a/extensions/cookie/nsCookiePermission.cpp +++ b/extensions/cookie/nsCookiePermission.cpp @@ -137,19 +137,16 @@ nsCookiePermission::Init() if (NS_FAILED(rv)) return rv; // failure to access the pref service is non-fatal... - nsCOMPtr prefBranch = + nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); if (prefBranch) { - nsCOMPtr prefInt = do_QueryInterface(prefBranch); - if (prefInt) { - prefInt->AddObserver(kCookiesAskPermission, this, PR_FALSE); - prefInt->AddObserver(kCookiesLifetimeEnabled, this, PR_FALSE); + prefBranch->AddObserver(kCookiesAskPermission, this, PR_FALSE); + prefBranch->AddObserver(kCookiesLifetimeEnabled, this, PR_FALSE); #ifndef MOZ_PHOENIX - prefInt->AddObserver(kCookiesLifetimeCurrentSession, this, PR_FALSE); - prefInt->AddObserver(kCookiesLifetimeDays, this, PR_FALSE); - prefInt->AddObserver(kCookiesDisabledForMailNews, this, PR_FALSE); + prefBranch->AddObserver(kCookiesLifetimeCurrentSession, this, PR_FALSE); + prefBranch->AddObserver(kCookiesLifetimeDays, this, PR_FALSE); + prefBranch->AddObserver(kCookiesDisabledForMailNews, this, PR_FALSE); #endif - } PrefChanged(prefBranch, nsnull); } diff --git a/extensions/cookie/nsImgManager.cpp b/extensions/cookie/nsImgManager.cpp index 956c0eda6ac6..ef41d04a9584 100644 --- a/extensions/cookie/nsImgManager.cpp +++ b/extensions/cookie/nsImgManager.cpp @@ -116,19 +116,17 @@ nsresult nsImgManager::Init() // other things, like mailnews blocking mPermissionManager = do_GetService(NS_PERMISSIONMANAGER_CONTRACTID); - nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); + nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); if (prefBranch) { - nsCOMPtr prefInternal = do_QueryInterface(prefBranch); - if (prefInternal) { - prefInternal->AddObserver(kImageBehaviorPrefName, this, PR_TRUE); + prefBranch->AddObserver(kImageBehaviorPrefName, this, PR_TRUE); - // We don't do anything with it yet, but let it be. (bug 110112, 146513) - prefInternal->AddObserver(kImageWarningPrefName, this, PR_TRUE); + // We don't do anything with it yet, but let it be. (bug 110112, 146513) + prefBranch->AddObserver(kImageWarningPrefName, this, PR_TRUE); + + // What is this pref, and how do you set it? + prefBranch->AddObserver(kImageBlockerPrefName, this, PR_TRUE); + prefBranch->AddObserver(kImageBlockImageInMailNewsPrefName, this, PR_TRUE); - // What is this pref, and how do you set it? - prefInternal->AddObserver(kImageBlockerPrefName, this, PR_TRUE); - prefInternal->AddObserver(kImageBlockImageInMailNewsPrefName, this, PR_TRUE); - } PrefChanged(prefBranch, nsnull); } diff --git a/extensions/cookie/nsPopupWindowManager.cpp b/extensions/cookie/nsPopupWindowManager.cpp index 450bf04beeef..36b3f9e7967b 100644 --- a/extensions/cookie/nsPopupWindowManager.cpp +++ b/extensions/cookie/nsPopupWindowManager.cpp @@ -88,10 +88,7 @@ nsPopupWindowManager::Init() } mPolicy = permission ? (PRUint32) DENY_POPUP : (PRUint32) ALLOW_POPUP; - nsCOMPtr prefInternal = do_QueryInterface(mPrefBranch, &rv); - if (NS_SUCCEEDED(rv)) { - prefInternal->AddObserver(kPopupDisablePref, this, PR_TRUE); - } + mPrefBranch->AddObserver(kPopupDisablePref, this, PR_TRUE); } return NS_OK; diff --git a/extensions/cookie/nsPopupWindowManager.h b/extensions/cookie/nsPopupWindowManager.h index 2098ea2cb158..652a0812105a 100644 --- a/extensions/cookie/nsPopupWindowManager.h +++ b/extensions/cookie/nsPopupWindowManager.h @@ -44,7 +44,7 @@ #include "nsIObserverService.h" #include "nsIPermissionManager.h" #include "nsIPopupWindowManager.h" -#include "nsIPrefBranch.h" +#include "nsIPrefBranchInternal.h" #include "nsWeakReference.h" class nsIURI; @@ -65,7 +65,7 @@ public: private: PRUint32 mPolicy; nsCOMPtr mPermissionManager; - nsCOMPtr mPrefBranch; + nsCOMPtr mPrefBranch; }; // {4275d3f4-752a-427a-b432-14d5dda1c20b} diff --git a/extensions/p3p/src/nsP3PService.cpp b/extensions/p3p/src/nsP3PService.cpp index 0ddad32dac44..d08f6bd9b822 100644 --- a/extensions/p3p/src/nsP3PService.cpp +++ b/extensions/p3p/src/nsP3PService.cpp @@ -58,12 +58,9 @@ NS_IMPL_ISUPPORTS2(nsP3PService, nsICookieConsent, nsIObserver) nsP3PService::nsP3PService() { // we can live without a prefservice, so errors here aren't fatal - nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); + nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); if (prefBranch) { - nsCOMPtr prefInternal = do_QueryInterface(prefBranch); - if (prefInternal) { - prefInternal->AddObserver(kCookiesP3PStringPref, this, PR_TRUE); - } + prefBranch->AddObserver(kCookiesP3PStringPref, this, PR_TRUE); } PrefChanged(prefBranch); } diff --git a/extensions/typeaheadfind/src/nsTypeAheadFind.cpp b/extensions/typeaheadfind/src/nsTypeAheadFind.cpp index 370fd002038e..64cc8ce772a8 100644 --- a/extensions/typeaheadfind/src/nsTypeAheadFind.cpp +++ b/extensions/typeaheadfind/src/nsTypeAheadFind.cpp @@ -174,8 +174,7 @@ nsTypeAheadFind::~nsTypeAheadFind() RemoveDocListeners(); mTimer = nsnull; - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - nsCOMPtr prefInternal(do_QueryInterface(prefBranch)); + nsCOMPtr prefInternal(do_GetService(NS_PREFSERVICE_CONTRACTID)); if (prefInternal) { prefInternal->RemoveObserver("accessibility.typeaheadfind", this); prefInternal->RemoveObserver("accessibility.browsewithcaret", this); @@ -189,13 +188,12 @@ nsTypeAheadFind::Init() NS_ENSURE_SUCCESS(rv, rv); - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); - nsCOMPtr prefInternal(do_QueryInterface(prefBranch)); + nsCOMPtr prefInternal(do_GetService(NS_PREFSERVICE_CONTRACTID)); mSearchRange = do_CreateInstance(kRangeCID); mStartPointRange = do_CreateInstance(kRangeCID); mEndPointRange = do_CreateInstance(kRangeCID); mFind = do_CreateInstance(NS_FIND_CONTRACTID); - if (!prefBranch || !prefInternal || !mSearchRange || !mStartPointRange || + if (!prefInternal || !mSearchRange || !mStartPointRange || !mEndPointRange || !mFind) { return NS_ERROR_FAILURE; } @@ -209,7 +207,7 @@ nsTypeAheadFind::Init() // ----------- Get accel key -------------------- - rv = prefBranch->GetIntPref("ui.key.accelKey", &sAccelKey); + rv = prefInternal->GetIntPref("ui.key.accelKey", &sAccelKey); NS_ENSURE_SUCCESS(rv, rv); // ----------- Get initial preferences ---------- diff --git a/extensions/webservices/wsdl/src/nsWSDLLoader.cpp b/extensions/webservices/wsdl/src/nsWSDLLoader.cpp index 63edfe39d5f5..89a75c392644 100644 --- a/extensions/webservices/wsdl/src/nsWSDLLoader.cpp +++ b/extensions/webservices/wsdl/src/nsWSDLLoader.cpp @@ -51,7 +51,6 @@ // pref. includes #include "nsIPrefService.h" -#include "nsIPrefBranchInternal.h" #define SCHEMA_2001_NAMESPACE "http://www.w3.org/2001/XMLSchema" #define SCHEMA_1999_NAMESPACE "http://www.w3.org/1999/XMLSchema" diff --git a/layout/generic/nsFrameSetFrame.cpp b/layout/generic/nsFrameSetFrame.cpp index 4cf82af24dc2..8b0663596373 100644 --- a/layout/generic/nsFrameSetFrame.cpp +++ b/layout/generic/nsFrameSetFrame.cpp @@ -993,18 +993,11 @@ nsHTMLFramesetFrame::Reflow(nsIPresContext* aPresContext, PRBool firstTime = (eReflowReason_Initial == aReflowState.reason); if (firstTime) { - nsCOMPtr prefService(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefService) { - nsCOMPtr prefBranch; - prefService->GetBranch(nsnull, getter_AddRefs(prefBranch)); - if (prefBranch) { - nsCOMPtr prefBranchInternal(do_QueryInterface(prefBranch)); - if (prefBranchInternal) { - mPrefBranchWeakRef = do_GetWeakReference(prefBranchInternal); - prefBranchInternal->AddObserver(kFrameResizePref, this, PR_FALSE); - } - prefBranch->GetBoolPref(kFrameResizePref, &mForceFrameResizability); - } + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) { + mPrefBranchWeakRef = do_GetWeakReference(prefBranch); + prefBranch->AddObserver(kFrameResizePref, this, PR_FALSE); + prefBranch->GetBoolPref(kFrameResizePref, &mForceFrameResizability); } } diff --git a/layout/html/document/src/nsFrameSetFrame.cpp b/layout/html/document/src/nsFrameSetFrame.cpp index 4cf82af24dc2..8b0663596373 100644 --- a/layout/html/document/src/nsFrameSetFrame.cpp +++ b/layout/html/document/src/nsFrameSetFrame.cpp @@ -993,18 +993,11 @@ nsHTMLFramesetFrame::Reflow(nsIPresContext* aPresContext, PRBool firstTime = (eReflowReason_Initial == aReflowState.reason); if (firstTime) { - nsCOMPtr prefService(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (prefService) { - nsCOMPtr prefBranch; - prefService->GetBranch(nsnull, getter_AddRefs(prefBranch)); - if (prefBranch) { - nsCOMPtr prefBranchInternal(do_QueryInterface(prefBranch)); - if (prefBranchInternal) { - mPrefBranchWeakRef = do_GetWeakReference(prefBranchInternal); - prefBranchInternal->AddObserver(kFrameResizePref, this, PR_FALSE); - } - prefBranch->GetBoolPref(kFrameResizePref, &mForceFrameResizability); - } + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) { + mPrefBranchWeakRef = do_GetWeakReference(prefBranch); + prefBranch->AddObserver(kFrameResizePref, this, PR_FALSE); + prefBranch->GetBoolPref(kFrameResizePref, &mForceFrameResizability); } } diff --git a/layout/xul/base/src/nsXULTooltipListener.cpp b/layout/xul/base/src/nsXULTooltipListener.cpp index 43dec1fa10f2..435bca26f5d2 100644 --- a/layout/xul/base/src/nsXULTooltipListener.cpp +++ b/layout/xul/base/src/nsXULTooltipListener.cpp @@ -294,14 +294,13 @@ nsXULTooltipListener::Init(nsIContent* aSourceNode, nsIRootBox* aRootBox) // Only the first time, register the callback and get the initial value of the pref if (!prefChangeRegistered) { - nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); if (prefBranch) { // get the initial value of the pref nsresult rv = prefBranch->GetBoolPref("browser.chrome.toolbar_tips", &sShowTooltips); if (NS_SUCCEEDED(rv)) { // register the callback so we get notified of updates - nsCOMPtr prefInternal(do_QueryInterface(prefBranch)); - rv = prefInternal->AddObserver("browser.chrome.toolbar_tips", this, PR_FALSE); + rv = prefBranch->AddObserver("browser.chrome.toolbar_tips", this, PR_FALSE); if (NS_SUCCEEDED(rv)) prefChangeRegistered = PR_TRUE; } diff --git a/modules/libpref/src/nsPrefService.cpp b/modules/libpref/src/nsPrefService.cpp index 7a7da710cb27..7807563792cc 100644 --- a/modules/libpref/src/nsPrefService.cpp +++ b/modules/libpref/src/nsPrefService.cpp @@ -141,7 +141,7 @@ nsresult nsPrefService::Init() if (!rootBranch) return NS_ERROR_OUT_OF_MEMORY; - mRootBranch = (nsIPrefBranch *)rootBranch; + mRootBranch = (nsIPrefBranchInternal *)rootBranch; nsXPIDLCString lockFileName; nsresult rv; @@ -271,11 +271,7 @@ NS_IMETHODIMP nsPrefService::GetBranch(const char *aPrefRoot, nsIPrefBranch **_r rv = CallQueryInterface(prefBranch, _retval); } else { // special case caching the default root - nsCOMPtr prefBranch = do_QueryInterface(mRootBranch, &rv); - if (NS_SUCCEEDED(rv)) { - *_retval = prefBranch; - NS_ADDREF(*_retval); - } + rv = CallQueryInterface(mRootBranch, _retval); } return rv; } @@ -294,29 +290,6 @@ NS_IMETHODIMP nsPrefService::GetDefaultBranch(const char *aPrefRoot, nsIPrefBran } -// Forward these methods through the nsIPrefBranchInternal headers - -NS_IMETHODIMP nsPrefService::AddObserver(const char *aDomain, nsIObserver *aObserver, PRBool aHoldWeak) -{ - nsresult rv; - - nsCOMPtr prefBranch = do_QueryInterface(mRootBranch, &rv); - if (NS_SUCCEEDED(rv)) - rv = prefBranch->AddObserver(aDomain, aObserver, aHoldWeak); - return rv; -} - -NS_IMETHODIMP nsPrefService::RemoveObserver(const char *aDomain, nsIObserver *aObserver) -{ - nsresult rv; - - nsCOMPtr prefBranch = do_QueryInterface(mRootBranch, &rv); - if (NS_SUCCEEDED(rv)) - rv = prefBranch->RemoveObserver(aDomain, aObserver); - return rv; -} - - nsresult nsPrefService::NotifyServiceObservers(const char *aTopic) { nsresult rv; diff --git a/modules/libpref/src/nsPrefService.h b/modules/libpref/src/nsPrefService.h index 7b66e81fd6c3..b8de5519483a 100644 --- a/modules/libpref/src/nsPrefService.h +++ b/modules/libpref/src/nsPrefService.h @@ -56,7 +56,7 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIPREFSERVICE NS_FORWARD_NSIPREFBRANCH(mRootBranch->) - NS_DECL_NSIPREFBRANCHINTERNAL + NS_FORWARD_NSIPREFBRANCHINTERNAL(mRootBranch->) NS_DECL_NSIOBSERVER nsPrefService(); @@ -74,7 +74,7 @@ protected: nsresult WritePrefFile(nsIFile* aFile); private: - nsCOMPtr mRootBranch; + nsCOMPtr mRootBranch; nsIFile* mCurrentFile; PRPackedBool mErrorOpeningUserPrefs; diff --git a/netwerk/base/src/nsIOService.cpp b/netwerk/base/src/nsIOService.cpp index 3305392f03cb..5de129c3d5d0 100644 --- a/netwerk/base/src/nsIOService.cpp +++ b/netwerk/base/src/nsIOService.cpp @@ -219,14 +219,11 @@ nsIOService::Init() mRestrictedPortList.AppendElement(NS_REINTERPRET_CAST(void *, gBadPortList[i])); // Further modifications to the port list come from prefs - nsCOMPtr prefBranch; + nsCOMPtr prefBranch; GetPrefBranch(getter_AddRefs(prefBranch)); if (prefBranch) { - nsCOMPtr pbi = do_QueryInterface(prefBranch); - if (pbi) { - pbi->AddObserver(PORT_PREF_PREFIX, this, PR_TRUE); - pbi->AddObserver(AUTODIAL_PREF, this, PR_TRUE); - } + prefBranch->AddObserver(PORT_PREF_PREFIX, this, PR_TRUE); + prefBranch->AddObserver(AUTODIAL_PREF, this, PR_TRUE); PrefsChanged(prefBranch); } @@ -319,7 +316,7 @@ nsIOService::GetProtocolHandler(const char* scheme, nsIProtocolHandler* *result) PRBool externalProtocol = PR_FALSE; PRBool listedProtocol = PR_TRUE; - nsCOMPtr prefBranch; + nsCOMPtr prefBranch; GetPrefBranch(getter_AddRefs(prefBranch)); if (prefBranch) { nsCAutoString externalProtocolPref("network.protocol-handler.external."); @@ -634,13 +631,10 @@ nsIOService::ParsePortList(nsIPrefBranch *prefBranch, const char *pref, PRBool r } void -nsIOService::GetPrefBranch(nsIPrefBranch **result) +nsIOService::GetPrefBranch(nsIPrefBranchInternal **result) { *result = nsnull; - nsCOMPtr prefService = - do_GetService(NS_PREFSERVICE_CONTRACTID); - if (prefService) - prefService->GetBranch(nsnull, result); + CallGetService(NS_PREFSERVICE_CONTRACTID, result); } // nsIObserver interface diff --git a/netwerk/base/src/nsIOService.h b/netwerk/base/src/nsIOService.h index e355c05fbdec..6ce1353f6639 100644 --- a/netwerk/base/src/nsIOService.h +++ b/netwerk/base/src/nsIOService.h @@ -67,6 +67,7 @@ static const char *gScheme[] = {"chrome", "file", "http", "jar", "resource"}; class nsIPrefBranch; +class nsIPrefBranchInternal; class nsIOService : public nsIIOService , public nsIObserver @@ -102,7 +103,7 @@ protected: // Prefs wrangling void PrefsChanged(nsIPrefBranch *prefs, const char *pref = nsnull); - void GetPrefBranch(nsIPrefBranch **); + void GetPrefBranch(nsIPrefBranchInternal **); void ParsePortList(nsIPrefBranch *prefBranch, const char *pref, PRBool remove); protected: diff --git a/netwerk/base/src/nsProtocolProxyService.cpp b/netwerk/base/src/nsProtocolProxyService.cpp index 8aa27b9beccb..91894a2ad6d3 100644 --- a/netwerk/base/src/nsProtocolProxyService.cpp +++ b/netwerk/base/src/nsProtocolProxyService.cpp @@ -148,12 +148,10 @@ nsresult nsProtocolProxyService::Init() { // failure to access prefs is non-fatal - nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); + nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); if (prefBranch) { // monitor proxy prefs - nsCOMPtr prefInt = do_QueryInterface(prefBranch); - if (prefInt) - prefInt->AddObserver("network.proxy", this, PR_FALSE); + prefBranch->AddObserver("network.proxy", this, PR_FALSE); // read all prefs PrefsChanged(prefBranch, nsnull); diff --git a/netwerk/base/src/nsStandardURL.cpp b/netwerk/base/src/nsStandardURL.cpp index 61fe44fb036c..cad05ede5bda 100644 --- a/netwerk/base/src/nsStandardURL.cpp +++ b/netwerk/base/src/nsStandardURL.cpp @@ -302,22 +302,15 @@ nsStandardURL::~nsStandardURL() void nsStandardURL::InitGlobalObjects() { - nsCOMPtr prefService( do_GetService(NS_PREFSERVICE_CONTRACTID) ); - if (prefService) { - nsCOMPtr prefBranch; - prefService->GetBranch(nsnull, getter_AddRefs(prefBranch)); - if (prefBranch) { - nsCOMPtr pbi( do_QueryInterface(prefBranch) ); - if (pbi) { - nsCOMPtr obs( new nsPrefObserver() ); - pbi->AddObserver(NS_NET_PREF_ESCAPEUTF8, obs.get(), PR_FALSE); - pbi->AddObserver(NS_NET_PREF_ENABLEIDN, obs.get(), PR_FALSE); - // initialize IDN - nsCOMPtr serv(do_GetService(NS_IDNSERVICE_CONTRACTID)); - if (serv) - NS_ADDREF(gIDNService = serv.get()); - } - } + nsCOMPtr prefBranch( do_GetService(NS_PREFSERVICE_CONTRACTID) ); + if (prefBranch) { + nsCOMPtr obs( new nsPrefObserver() ); + prefBranch->AddObserver(NS_NET_PREF_ESCAPEUTF8, obs.get(), PR_FALSE); + prefBranch->AddObserver(NS_NET_PREF_ENABLEIDN, obs.get(), PR_FALSE); + // initialize IDN + nsCOMPtr serv(do_GetService(NS_IDNSERVICE_CONTRACTID)); + if (serv) + NS_ADDREF(gIDNService = serv.get()); } } diff --git a/netwerk/cache/src/nsCacheService.cpp b/netwerk/cache/src/nsCacheService.cpp index add9a81593ce..42c9d11f7d6b 100644 --- a/netwerk/cache/src/nsCacheService.cpp +++ b/netwerk/cache/src/nsCacheService.cpp @@ -87,7 +87,7 @@ public: nsresult Install(); nsresult Remove(); - nsresult ReadPrefs(); + nsresult ReadPrefs(nsIPrefBranch* branch); PRBool DiskCacheEnabled(); PRInt32 DiskCacheCapacity() { return mDiskCacheCapacity; } @@ -133,10 +133,7 @@ nsCacheProfilePrefObserver::Install() // install preferences observer - nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); - if (!prefs) return NS_ERROR_FAILURE; - - nsCOMPtr branch = do_QueryInterface(prefs); + nsCOMPtr branch = do_GetService(NS_PREFSERVICE_CONTRACTID); if (!branch) return NS_ERROR_FAILURE; char * prefList[] = { @@ -167,7 +164,7 @@ nsCacheProfilePrefObserver::Install() mHaveProfile = PR_TRUE; } - rv = ReadPrefs(); + rv = ReadPrefs(branch); return NS_SUCCEEDED(rv) ? rv2 : rv; } @@ -194,11 +191,7 @@ nsCacheProfilePrefObserver::Remove() // remove Pref Service observers - nsCOMPtr prefService = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr prefInternal = do_QueryInterface(prefService, &rv); - if (NS_FAILED(rv)) return rv; + nsCOMPtr prefInternal = do_GetService(NS_PREFSERVICE_CONTRACTID); // remove Disk cache pref observers rv = prefInternal->RemoveObserver(DISK_CACHE_ENABLE_PREF, this); @@ -246,7 +239,8 @@ nsCacheProfilePrefObserver::Observe(nsISupports * subject, } else if (!strcmp("profile-after-change", topic)) { // profile after change mHaveProfile = PR_TRUE; - ReadPrefs(); + nsCOMPtr branch = do_GetService(NS_PREFSERVICE_CONTRACTID); + ReadPrefs(branch); nsCacheService::OnProfileChanged(); } else if (!strcmp(NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, topic)) { @@ -302,16 +296,10 @@ nsCacheProfilePrefObserver::Observe(nsISupports * subject, nsresult -nsCacheProfilePrefObserver::ReadPrefs() +nsCacheProfilePrefObserver::ReadPrefs(nsIPrefBranch* branch) { nsresult rv = NS_OK; - nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); - if (!prefs) return NS_ERROR_FAILURE; - - nsCOMPtr branch = do_QueryInterface(prefs); - if (!branch) return NS_ERROR_FAILURE; - #ifdef NECKO_DISK_CACHE // read disk cache device prefs mDiskCacheEnabled = PR_TRUE; // presume disk cache is enabled diff --git a/netwerk/cookie/src/nsCookieService.cpp b/netwerk/cookie/src/nsCookieService.cpp index ace785b253e1..cb7438f4764c 100644 --- a/netwerk/cookie/src/nsCookieService.cpp +++ b/netwerk/cookie/src/nsCookieService.cpp @@ -379,13 +379,9 @@ nsCookieService::Init() } // init our pref and observer - nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); + nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); if (prefBranch) { - // add observers - nsCOMPtr prefInternal = do_QueryInterface(prefBranch); - if (prefInternal) - prefInternal->AddObserver(kCookiesPermissions, this, PR_TRUE); - + prefBranch->AddObserver(kCookiesPermissions, this, PR_TRUE); PrefChanged(prefBranch); } diff --git a/netwerk/dns/src/nsDNSService2.cpp b/netwerk/dns/src/nsDNSService2.cpp index aa95184b5baa..1f5d173629f1 100644 --- a/netwerk/dns/src/nsDNSService2.cpp +++ b/netwerk/dns/src/nsDNSService2.cpp @@ -283,7 +283,7 @@ nsDNSService::Init() PRBool enableIDN = PR_TRUE; // read prefs - nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); if (prefs) { PRInt32 val; if (NS_SUCCEEDED(prefs->GetIntPref(kPrefDnsCacheEntries, &val))) @@ -307,12 +307,9 @@ nsDNSService::Init() return NS_ERROR_OUT_OF_MEMORY; // register as prefs observer - nsCOMPtr prefsInt = do_QueryInterface(prefs); - if (prefsInt) { - prefsInt->AddObserver(kPrefDnsCacheEntries, this, PR_FALSE); - prefsInt->AddObserver(kPrefDnsCacheExpiration, this, PR_FALSE); - prefsInt->AddObserver(kPrefEnableIDN, this, PR_FALSE); - } + prefs->AddObserver(kPrefDnsCacheEntries, this, PR_FALSE); + prefs->AddObserver(kPrefDnsCacheExpiration, this, PR_FALSE); + prefs->AddObserver(kPrefEnableIDN, this, PR_FALSE); } return nsHostResolver::Create(maxCacheEntries, diff --git a/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp b/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp index f4d7961cd715..bf2092e82620 100644 --- a/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp +++ b/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp @@ -121,18 +121,14 @@ nsFtpProtocolHandler::Init() } if (mIdleTimeout == -1) { - nsCOMPtr prefSrv = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - nsCOMPtr branch; - // I have to get the root pref branch because of bug 107617 - rv = prefSrv->GetBranch(nsnull, getter_AddRefs(branch)); + nsCOMPtr branch = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; + rv = branch->GetIntPref(IDLE_TIMEOUT_PREF, &mIdleTimeout); if (NS_FAILED(rv)) mIdleTimeout = 5*60; // 5 minute default - prefSrv->GetBranch(nsnull, getter_AddRefs(branch)); - nsCOMPtr pbi = do_QueryInterface(branch); - rv = pbi->AddObserver(IDLE_TIMEOUT_PREF, this, PR_TRUE); + + rv = branch->AddObserver(IDLE_TIMEOUT_PREF, this, PR_TRUE); if (NS_FAILED(rv)) return rv; } diff --git a/netwerk/protocol/http/src/nsHttpHandler.cpp b/netwerk/protocol/http/src/nsHttpHandler.cpp index eed152e2a791..127b5d788bf3 100644 --- a/netwerk/protocol/http/src/nsHttpHandler.cpp +++ b/netwerk/protocol/http/src/nsHttpHandler.cpp @@ -191,18 +191,15 @@ nsHttpHandler::Init() InitUserAgentComponents(); // monitor some preference changes - nsCOMPtr prefBranch; - GetPrefBranch(getter_AddRefs(prefBranch)); + nsCOMPtr prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID); if (prefBranch) { - nsCOMPtr pbi = do_QueryInterface(prefBranch); - if (pbi) { - pbi->AddObserver(HTTP_PREF_PREFIX, this, PR_TRUE); - pbi->AddObserver(UA_PREF_PREFIX, this, PR_TRUE); - pbi->AddObserver(INTL_ACCEPT_LANGUAGES, this, PR_TRUE); - pbi->AddObserver(INTL_ACCEPT_CHARSET, this, PR_TRUE); - pbi->AddObserver(NETWORK_ENABLEIDN, this, PR_TRUE); - pbi->AddObserver(BROWSER_PREF("disk_cache_ssl"), this, PR_TRUE); - } + prefBranch->AddObserver(HTTP_PREF_PREFIX, this, PR_TRUE); + prefBranch->AddObserver(UA_PREF_PREFIX, this, PR_TRUE); + prefBranch->AddObserver(INTL_ACCEPT_LANGUAGES, this, PR_TRUE); + prefBranch->AddObserver(INTL_ACCEPT_CHARSET, this, PR_TRUE); + prefBranch->AddObserver(NETWORK_ENABLEIDN, this, PR_TRUE); + prefBranch->AddObserver(BROWSER_PREF("disk_cache_ssl"), this, PR_TRUE); + PrefsChanged(prefBranch, nsnull); } @@ -1027,16 +1024,6 @@ nsHttpHandler::PrefsChanged(nsIPrefBranch *prefs, const char *pref) #undef PREF_CHANGED } -void -nsHttpHandler::GetPrefBranch(nsIPrefBranch **result) -{ - *result = nsnull; - nsCOMPtr prefService = - do_GetService(NS_PREFSERVICE_CONTRACTID); - if (prefService) - prefService->GetBranch(nsnull, result); -} - /** * Allocates a C string into that contains a ISO 639 language list * notated with HTTP "q" values for output with a HTTP Accept-Language diff --git a/netwerk/protocol/http/src/nsHttpHandler.h b/netwerk/protocol/http/src/nsHttpHandler.h index c21cd795c09a..d84cb8492e20 100644 --- a/netwerk/protocol/http/src/nsHttpHandler.h +++ b/netwerk/protocol/http/src/nsHttpHandler.h @@ -181,7 +181,6 @@ private: void BuildUserAgent(); void InitUserAgentComponents(); void PrefsChanged(nsIPrefBranch *prefs, const char *pref); - void GetPrefBranch(nsIPrefBranch **); nsresult SetAccept(const char *); nsresult SetAcceptLanguages(const char *); diff --git a/uriloader/prefetch/nsPrefetchService.cpp b/uriloader/prefetch/nsPrefetchService.cpp index c04563c072d7..92560eac22d5 100644 --- a/uriloader/prefetch/nsPrefetchService.cpp +++ b/uriloader/prefetch/nsPrefetchService.cpp @@ -227,20 +227,14 @@ nsPrefetchService::Init() nsresult rv; // read prefs and hook up pref observer - nsCOMPtr prefServ(do_GetService(kPrefServiceCID, &rv)); + nsCOMPtr prefs(do_GetService(kPrefServiceCID, &rv)); if (NS_SUCCEEDED(rv)) { - nsCOMPtr prefs; - rv = prefServ->GetBranch(nsnull, getter_AddRefs(prefs)); - if (NS_SUCCEEDED(rv)) { - PRBool enabled; - rv = prefs->GetBoolPref(PREFETCH_PREF, &enabled); - if (NS_SUCCEEDED(rv) && enabled) - mDisabled = PR_FALSE; + PRBool enabled; + rv = prefs->GetBoolPref(PREFETCH_PREF, &enabled); + if (NS_SUCCEEDED(rv) && enabled) + mDisabled = PR_FALSE; - nsCOMPtr prefsInt(do_QueryInterface(prefs)); - if (prefsInt) - prefsInt->AddObserver(PREFETCH_PREF, this, PR_TRUE); - } + prefs->AddObserver(PREFETCH_PREF, this, PR_TRUE); } // Observe xpcom-shutdown event