Bug 307437 - xpfe and suite should use the newer nsIPrefService APIs instead of nsIPref. r+sr=neil, suite-only change

This commit is contained in:
dwitte@stanford.edu 2008-01-12 18:13:24 -08:00
Родитель 5e46822ed4
Коммит 9602e84045
5 изменённых файлов: 49 добавлений и 33 удалений

Просмотреть файл

@ -50,7 +50,6 @@
#include "nsIURL.h"
#include "nsNetCID.h"
#include "nsIStringBundle.h"
#include "nsIPref.h"
#include "nsReadableUtils.h"
#include "nsEscape.h"

Просмотреть файл

@ -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<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID));
nsCOMPtr<nsIPrefBranch> 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<nsIPrefLocalizedString> 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<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID));
nsCOMPtr<nsIPrefBranch> 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<nsIPrefLocalizedString> 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;

Просмотреть файл

@ -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

Просмотреть файл

@ -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<nsIPref> prefServ(do_GetService(NS_PREF_CONTRACTID, &rv));
nsCOMPtr<nsIPrefBranch> 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
{

Просмотреть файл

@ -50,7 +50,8 @@
#include <nsIServiceManager.h>
#include <nsString.h>
#include <nsCRT.h>
#include <nsIPref.h>
#include <nsIPrefBranch.h>
#include <nsIPrefService.h>
#include <nsIWindowWatcher.h>
#include <nsXPCOM.h>
#include <nsISupportsPrimitives.h>
@ -332,12 +333,11 @@ nsresult
XRemoteService::GetBrowserLocation(char **_retval)
{
// get the browser chrome URL
nsCOMPtr<nsIPref> prefs;
prefs = do_GetService(NS_PREF_CONTRACTID);
nsCOMPtr<nsIPrefBranch> 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<nsIPref> prefs;
prefs = do_GetService(NS_PREF_CONTRACTID);
nsCOMPtr<nsIPrefBranch> 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)