From 9602e840452a19e49f5cb857adc9eb257c77c519 Mon Sep 17 00:00:00 2001 From: "dwitte@stanford.edu" Date: Sat, 12 Jan 2008 18:13:24 -0800 Subject: [PATCH] Bug 307437 - xpfe and suite should use the newer nsIPrefService APIs instead of nsIPref. r+sr=neil, suite-only change --- xpfe/appshell/src/nsWebShellWindow.cpp | 1 - xpfe/browser/src/nsBrowserInstance.cpp | 51 +++++++++++++------ xpfe/browser/src/nsBrowserInstance.h | 4 +- .../related/src/nsRelatedLinksHandler.cpp | 13 +++-- .../components/xremote/src/XRemoteService.cpp | 13 +++-- 5 files changed, 49 insertions(+), 33 deletions(-) diff --git a/xpfe/appshell/src/nsWebShellWindow.cpp b/xpfe/appshell/src/nsWebShellWindow.cpp index 6af05c54c32..643a459b6e8 100644 --- a/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/xpfe/appshell/src/nsWebShellWindow.cpp @@ -50,7 +50,6 @@ #include "nsIURL.h" #include "nsNetCID.h" #include "nsIStringBundle.h" -#include "nsIPref.h" #include "nsReadableUtils.h" #include "nsEscape.h" diff --git a/xpfe/browser/src/nsBrowserInstance.cpp b/xpfe/browser/src/nsBrowserInstance.cpp index 3148e61c739..546d4377d30 100644 --- a/xpfe/browser/src/nsBrowserInstance.cpp +++ b/xpfe/browser/src/nsBrowserInstance.cpp @@ -74,7 +74,9 @@ #include "nsReadableUtils.h" #include "nsThreadUtils.h" -#include "nsIPref.h" +#include "nsIPrefService.h" +#include "nsIPrefBranch.h" +#include "nsIPrefLocalizedString.h" #include "nsIServiceManager.h" #include "nsIURL.h" #include "nsIIOService.h" @@ -631,9 +633,9 @@ NS_IMETHODIMP nsBrowserContentHandler::GetChromeUrlForTask(char **aChromeUrlForT return NS_ERROR_NULL_POINTER; nsresult rv = NS_ERROR_FAILURE; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID)); if (prefs) { - rv = prefs->CopyCharPref("browser.chromeURL", aChromeUrlForTask); + rv = prefs->GetCharPref("browser.chromeURL", aChromeUrlForTask); if (NS_SUCCEEDED(rv) && (*aChromeUrlForTask)[0] == '\0') { PL_strfree(*aChromeUrlForTask); rv = NS_ERROR_FAILURE; @@ -645,7 +647,7 @@ NS_IMETHODIMP nsBrowserContentHandler::GetChromeUrlForTask(char **aChromeUrlForT return NS_OK; } -PRBool nsBrowserContentHandler::NeedHomepageOverride(nsIPref *aPrefService) +PRBool nsBrowserContentHandler::NeedHomepageOverride(nsIPrefBranch *aPrefService) { NS_ASSERTION(aPrefService, "Null pointer to prefs service!"); @@ -679,12 +681,14 @@ PRBool nsBrowserContentHandler::NeedHomepageOverride(nsIPref *aPrefService) return PR_FALSE; } -nsresult GetHomePageGroup(nsIPref* aPref, PRUnichar** aResult) +nsresult GetHomePageGroup(nsIPrefBranch* aPref, PRUnichar** aResult) { nsresult rv; - nsXPIDLString uri; - rv = aPref->GetLocalizedUnicharPref(PREF_BROWSER_STARTUP_HOMEPAGE, getter_Copies(uri)); + nsCOMPtr uri; + rv = aPref->GetComplexValue(PREF_BROWSER_STARTUP_HOMEPAGE, + NS_GET_IID(nsIPrefLocalizedString), + getter_AddRefs(uri)); if (NS_FAILED(rv)) return rv; @@ -693,23 +697,32 @@ nsresult GetHomePageGroup(nsIPref* aPref, PRUnichar** aResult) // if we couldn't get the pref (unlikely) or only have one homepage if (NS_FAILED(rv) || count <= 1) { - *aResult = ToNewUnicode(uri); - return NS_OK; + return uri->ToString(aResult); } // The "homepage" is a group of pages, put them in uriList separated by '\n' - nsAutoString uriList(uri); + nsString uriList; + rv = uri->GetData(getter_Copies(uriList)); + if (NS_FAILED(rv)) + return rv; for (PRInt32 i = 1; i < count; ++i) { nsCAutoString pref(NS_LITERAL_CSTRING("browser.startup.homepage.")); pref.AppendInt(i); - rv = aPref->GetLocalizedUnicharPref(pref.get(), getter_Copies(uri)); + rv = aPref->GetComplexValue(pref.get(), + NS_GET_IID(nsIPrefLocalizedString), + getter_AddRefs(uri)); + if (NS_FAILED(rv)) + return rv; + + nsString uriString; + rv = uri->GetData(getter_Copies(uriString)); if (NS_FAILED(rv)) return rv; uriList.Append(PRUnichar('\n')); - uriList.Append(uri); + uriList.Append(uriString); } *aResult = ToNewUnicode(uriList); @@ -723,12 +736,18 @@ NS_IMETHODIMP nsBrowserContentHandler::GetDefaultArgs(PRUnichar **aDefaultArgs) nsresult rv; - nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); + nsCOMPtr prefs(do_GetService(NS_PREFSERVICE_CONTRACTID)); if (prefs) { if (NeedHomepageOverride(prefs)) { - rv = prefs->GetLocalizedUnicharPref(PREF_HOMEPAGE_OVERRIDE_URL, aDefaultArgs); - if (NS_SUCCEEDED(rv) && *aDefaultArgs) - return NS_OK; + nsCOMPtr overrideURL; + rv = prefs->GetComplexValue(PREF_HOMEPAGE_OVERRIDE_URL, + NS_GET_IID(nsIPrefLocalizedString), + getter_AddRefs(overrideURL)); + if (NS_SUCCEEDED(rv)) { + rv = overrideURL->ToString(aDefaultArgs); + if (NS_SUCCEEDED(rv) && *aDefaultArgs) + return NS_OK; + } } PRInt32 choice = 0; diff --git a/xpfe/browser/src/nsBrowserInstance.h b/xpfe/browser/src/nsBrowserInstance.h index 3b1ba186151..a0f0a0bcc10 100644 --- a/xpfe/browser/src/nsBrowserInstance.h +++ b/xpfe/browser/src/nsBrowserInstance.h @@ -55,7 +55,7 @@ class nsIDocShell; class nsIDOMWindowInternal; -class nsIPref; +class nsIPrefBranch; //////////////////////////////////////////////////////////////////////////////// // nsBrowserInstance: @@ -114,7 +114,7 @@ public: CMDLINEHANDLER_REGISTERPROC_DECLS protected: - PRBool NeedHomepageOverride(nsIPref *aPrefService); + PRBool NeedHomepageOverride(nsIPrefBranch *aPrefService); }; #endif diff --git a/xpfe/components/related/src/nsRelatedLinksHandler.cpp b/xpfe/components/related/src/nsRelatedLinksHandler.cpp index 27c4e1e895a..dbbb46e2822 100644 --- a/xpfe/components/related/src/nsRelatedLinksHandler.cpp +++ b/xpfe/components/related/src/nsRelatedLinksHandler.cpp @@ -54,7 +54,8 @@ #include "nsIURL.h" #include "nsNetUtil.h" #include "nsIInputStream.h" -#include "nsIPref.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" #include "nsRDFCID.h" #include "nsVoidArray.h" #include "nsXPIDLString.h" @@ -631,17 +632,15 @@ RelatedLinksHandlerImpl::Init() gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "child"), &kNC_Child); - nsCOMPtr prefServ(do_GetService(NS_PREF_CONTRACTID, &rv)); + nsCOMPtr prefServ(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); mRLServerURL = new nsString(); if (NS_SUCCEEDED(rv) && (prefServ)) { - char *prefVal = nsnull; - if (NS_SUCCEEDED(rv = prefServ->CopyCharPref("browser.related.provider", - &prefVal)) && (prefVal)) + nsXPIDLCString prefVal; + if (NS_SUCCEEDED(rv = prefServ->GetCharPref("browser.related.provider", + getter_Copies(prefVal))) && (!prefVal.IsEmpty())) { mRLServerURL->AssignWithConversion(prefVal); - nsCRT::free(prefVal); - prefVal = nsnull; } else { diff --git a/xpfe/components/xremote/src/XRemoteService.cpp b/xpfe/components/xremote/src/XRemoteService.cpp index 8f3213682c0..e9ac0a868d8 100644 --- a/xpfe/components/xremote/src/XRemoteService.cpp +++ b/xpfe/components/xremote/src/XRemoteService.cpp @@ -50,7 +50,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -332,12 +333,11 @@ nsresult XRemoteService::GetBrowserLocation(char **_retval) { // get the browser chrome URL - nsCOMPtr prefs; - prefs = do_GetService(NS_PREF_CONTRACTID); + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); if (!prefs) return NS_ERROR_FAILURE; - prefs->CopyCharPref("browser.chromeURL", _retval); + prefs->GetCharPref("browser.chromeURL", _retval); // fallback if (!*_retval) @@ -369,12 +369,11 @@ nsresult XRemoteService::GetCalendarLocation(char **_retval) { // get the calendar chrome URL - nsCOMPtr prefs; - prefs = do_GetService(NS_PREF_CONTRACTID); + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID); if (!prefs) return NS_ERROR_FAILURE; - prefs->CopyCharPref("calendar.chromeURL", _retval); + prefs->GetCharPref("calendar.chromeURL", _retval); // fallback if (!*_retval)