fixes bug 212598 "netwerk/ should not use nsIPref" r=dougt,caillon sr=bzbarsky

This commit is contained in:
darin%netscape.com 2003-07-14 21:36:24 +00:00
parent b5f774cdd4
commit 347f4e42e7
11 changed files with 169 additions and 182 deletions

View File

@ -43,14 +43,14 @@
#include "nsIIOService.h"
#include "nsIEventQueueService.h"
#include "nsIProtocolHandler.h"
#include "nsIPrefService.h"
#include "nsIPrefBranchInternal.h"
#include "nsReadableUtils.h"
#include "nsString.h"
#include "nsNetUtil.h"
#include "nsCRT.h"
#include "prnetdb.h"
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
#define IS_ASCII_SPACE(_c) ((_c) == ' ' || (_c) == '\t')
//
@ -58,7 +58,8 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
//
// NOTE: we do the byte swapping here to minimize overall swapping.
//
static void MaskIPv6Addr(PRIPv6Addr &addr, PRUint16 mask_len)
static void
proxy_MaskIPv6Addr(PRIPv6Addr &addr, PRUint16 mask_len)
{
if (mask_len == 128)
return;
@ -87,18 +88,41 @@ static void MaskIPv6Addr(PRIPv6Addr &addr, PRUint16 mask_len)
}
}
static const char PROXY_PREFS[] = "network.proxy";
static PRInt32 PR_CALLBACK ProxyPrefsCallback(const char* pref, void* instance)
static void
proxy_GetStringPref(nsIPrefBranch *aPrefBranch,
const char *aPref,
nsCString &aResult)
{
nsProtocolProxyService* proxyServ = (nsProtocolProxyService*) instance;
NS_ASSERTION(proxyServ, "bad instance data");
if (proxyServ) proxyServ->PrefsChanged(pref);
return 0;
nsXPIDLCString temp;
nsresult rv = aPrefBranch->GetCharPref(aPref, getter_Copies(temp));
if (NS_FAILED(rv))
aResult.Truncate();
else {
aResult.Assign(temp);
// all of our string prefs are hostnames, so we should remove any
// whitespace characters that the user might have unknowingly entered.
aResult.StripWhitespace();
}
}
NS_IMPL_THREADSAFE_ISUPPORTS1(nsProtocolProxyService, nsIProtocolProxyService);
NS_IMPL_THREADSAFE_ISUPPORTS1(nsProtocolProxyService::nsProxyInfo, nsIProxyInfo);
static void
proxy_GetIntPref(nsIPrefBranch *aPrefBranch,
const char *aPref,
PRInt32 &aResult)
{
PRInt32 temp;
nsresult rv = aPrefBranch->GetIntPref(aPref, &temp);
if (NS_FAILED(rv))
aResult = -1;
else
aResult = temp;
}
NS_IMPL_THREADSAFE_ISUPPORTS2(nsProtocolProxyService,
nsIProtocolProxyService,
nsIObserver);
NS_IMPL_THREADSAFE_ISUPPORTS1(nsProtocolProxyService::nsProxyInfo,
nsIProxyInfo);
nsProtocolProxyService::nsProtocolProxyService()
: mUseProxy(0)
@ -123,53 +147,36 @@ nsProtocolProxyService::~nsProtocolProxyService()
nsresult
nsProtocolProxyService::Init()
{
nsresult rv;
mPrefs = do_GetService(kPrefServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
// failure to access prefs is non-fatal
nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefBranch) {
// monitor proxy prefs
nsCOMPtr<nsIPrefBranchInternal> prefInt = do_QueryInterface(prefBranch);
if (prefInt)
prefInt->AddObserver("network.proxy", this, PR_FALSE);
// register for change callbacks
rv = mPrefs->RegisterCallback(PROXY_PREFS, ProxyPrefsCallback, (void*)this);
if (NS_FAILED(rv)) return rv;
// read all prefs
PrefsChanged(prefBranch, nsnull);
}
return NS_OK;
}
PrefsChanged(nsnull);
NS_IMETHODIMP
nsProtocolProxyService::Observe(nsISupports *aSubject,
const char *aTopic,
const PRUnichar *aData)
{
nsCOMPtr<nsIPrefBranch> prefs = do_QueryInterface(aSubject);
if (prefs)
PrefsChanged(prefs, NS_LossyConvertUTF16toASCII(aData).get());
return NS_OK;
}
void
nsProtocolProxyService::GetStringPref(const char *aPref, nsCString &aResult)
nsProtocolProxyService::PrefsChanged(nsIPrefBranch *prefBranch,
const char *pref)
{
nsXPIDLCString temp;
nsresult rv;
rv = mPrefs->CopyCharPref(aPref, getter_Copies(temp));
if (NS_FAILED(rv))
aResult.Truncate();
else {
aResult.Assign(temp);
// all of our string prefs are hostnames, so we should remove any
// whitespace characters that the user might have unknowingly entered.
aResult.StripWhitespace();
}
}
void
nsProtocolProxyService::GetIntPref(const char *aPref, PRInt32 &aResult)
{
PRInt32 temp;
nsresult rv;
rv = mPrefs->GetIntPref(aPref, &temp);
if (NS_FAILED(rv))
aResult = -1;
else
aResult = temp;
}
void
nsProtocolProxyService::PrefsChanged(const char* pref)
{
NS_ASSERTION(mPrefs, "No preference service available!");
if (!mPrefs) return;
printf(">>> PrefsChanged [pref=%s]\n", pref);
nsresult rv = NS_OK;
PRBool reloadPAC = PR_FALSE;
@ -177,7 +184,7 @@ nsProtocolProxyService::PrefsChanged(const char* pref)
if (!pref || !strcmp(pref, "network.proxy.type")) {
PRInt32 type = -1;
rv = mPrefs->GetIntPref("network.proxy.type",&type);
rv = prefBranch->GetIntPref("network.proxy.type",&type);
if (NS_SUCCEEDED(rv)) {
// bug 115720 - type 3 is the same as 0 (no proxy),
// for ns4.x backwards compatability
@ -188,7 +195,7 @@ nsProtocolProxyService::PrefsChanged(const char* pref)
// I'm paranoid about a loop of some sort - only do this
// if we're enumerating all prefs, and ignore any error
if (!pref)
mPrefs->SetIntPref("network.proxy.type", 0);
prefBranch->SetIntPref("network.proxy.type", 0);
}
mUseProxy = type; // type == 2 is autoconfig stuff
reloadPAC = PR_TRUE;
@ -196,38 +203,38 @@ nsProtocolProxyService::PrefsChanged(const char* pref)
}
if (!pref || !strcmp(pref, "network.proxy.http"))
GetStringPref("network.proxy.http", mHTTPProxyHost);
proxy_GetStringPref(prefBranch, "network.proxy.http", mHTTPProxyHost);
if (!pref || !strcmp(pref, "network.proxy.http_port"))
GetIntPref("network.proxy.http_port", mHTTPProxyPort);
proxy_GetIntPref(prefBranch, "network.proxy.http_port", mHTTPProxyPort);
if (!pref || !strcmp(pref, "network.proxy.ssl"))
GetStringPref("network.proxy.ssl", mHTTPSProxyHost);
proxy_GetStringPref(prefBranch, "network.proxy.ssl", mHTTPSProxyHost);
if (!pref || !strcmp(pref, "network.proxy.ssl_port"))
GetIntPref("network.proxy.ssl_port", mHTTPSProxyPort);
proxy_GetIntPref(prefBranch, "network.proxy.ssl_port", mHTTPSProxyPort);
if (!pref || !strcmp(pref, "network.proxy.ftp"))
GetStringPref("network.proxy.ftp", mFTPProxyHost);
proxy_GetStringPref(prefBranch, "network.proxy.ftp", mFTPProxyHost);
if (!pref || !strcmp(pref, "network.proxy.ftp_port"))
GetIntPref("network.proxy.ftp_port", mFTPProxyPort);
proxy_GetIntPref(prefBranch, "network.proxy.ftp_port", mFTPProxyPort);
if (!pref || !strcmp(pref, "network.proxy.gopher"))
GetStringPref("network.proxy.gopher", mGopherProxyHost);
proxy_GetStringPref(prefBranch, "network.proxy.gopher", mGopherProxyHost);
if (!pref || !strcmp(pref, "network.proxy.gopher_port"))
GetIntPref("network.proxy.gopher_port", mGopherProxyPort);
proxy_GetIntPref(prefBranch, "network.proxy.gopher_port", mGopherProxyPort);
if (!pref || !strcmp(pref, "network.proxy.socks"))
GetStringPref("network.proxy.socks", mSOCKSProxyHost);
proxy_GetStringPref(prefBranch, "network.proxy.socks", mSOCKSProxyHost);
if (!pref || !strcmp(pref, "network.proxy.socks_port"))
GetIntPref("network.proxy.socks_port", mSOCKSProxyPort);
proxy_GetIntPref(prefBranch, "network.proxy.socks_port", mSOCKSProxyPort);
if (!pref || !strcmp(pref, "network.proxy.socks_version")) {
PRInt32 version;
GetIntPref("network.proxy.socks_version", version);
proxy_GetIntPref(prefBranch, "network.proxy.socks_version", version);
// make sure this preference value remains sane
if (version == 5)
mSOCKSProxyVersion = 5;
@ -236,15 +243,15 @@ nsProtocolProxyService::PrefsChanged(const char* pref)
}
if (!pref || !strcmp(pref, "network.proxy.no_proxies_on")) {
rv = mPrefs->CopyCharPref("network.proxy.no_proxies_on",
getter_Copies(tempString));
rv = prefBranch->GetCharPref("network.proxy.no_proxies_on",
getter_Copies(tempString));
if (NS_SUCCEEDED(rv))
LoadFilters(tempString.get());
}
if ((!pref || !strcmp(pref, "network.proxy.autoconfig_url") || reloadPAC) && (mUseProxy == 2)) {
rv = mPrefs->CopyCharPref("network.proxy.autoconfig_url",
getter_Copies(tempString));
rv = prefBranch->GetCharPref("network.proxy.autoconfig_url",
getter_Copies(tempString));
if (NS_SUCCEEDED(rv) && (!reloadPAC || strcmp(tempString.get(), mPACURL.get())))
ConfigureFromPAC(tempString);
}
@ -275,7 +282,7 @@ nsProtocolProxyService::HandlePACLoadEvent(PLEvent* aEvent)
return NULL;
}
nsCOMPtr<nsIIOService> pIOService(do_GetService(kIOServiceCID, &rv));
nsCOMPtr<nsIIOService> pIOService(do_GetIOService(&rv));
if (!pIOService || NS_FAILED(rv)) {
NS_ERROR("Cannot get IO Service");
return NULL;
@ -358,7 +365,7 @@ nsProtocolProxyService::CanUseProxy(nsIURI *aURI, PRInt32 defaultPort)
// generate masked version of target IPv6 address
PRIPv6Addr masked;
memcpy(&masked, &ipv6, sizeof(PRIPv6Addr));
MaskIPv6Addr(masked, hinfo->ip.mask_len);
proxy_MaskIPv6Addr(masked, hinfo->ip.mask_len);
// check for a match
if (memcmp(&masked, &hinfo->ip.addr, sizeof(PRIPv6Addr)) == 0)
@ -727,7 +734,7 @@ nsProtocolProxyService::LoadFilters(const char *filters)
}
// apply mask to IPv6 address
MaskIPv6Addr(hinfo->ip.addr, hinfo->ip.mask_len);
proxy_MaskIPv6Addr(hinfo->ip.addr, hinfo->ip.mask_len);
}
else {
PRUint32 startIndex, endIndex;

View File

@ -41,27 +41,30 @@
#include "plevent.h"
#include "nsString.h"
#include "nsCOMPtr.h"
#include "nsIPref.h"
#include "nsVoidArray.h"
#include "nsIPrefBranch.h"
#include "nsIProtocolProxyService.h"
#include "nsIProxyAutoConfig.h"
#include "nsIProxyInfo.h"
#include "nsIIOService.h"
#include "nsIObserver.h"
#include "prmem.h"
#include "prio.h"
class nsProtocolProxyService : public nsIProtocolProxyService
, public nsIObserver
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIPROTOCOLPROXYSERVICE
NS_DECL_NSIOBSERVER
nsProtocolProxyService();
virtual ~nsProtocolProxyService();
nsresult Init();
void PrefsChanged(const char* pref);
void PrefsChanged(nsIPrefBranch *, const char* pref);
class nsProxyInfo : public nsIProxyInfo
{
@ -104,8 +107,6 @@ protected:
nsresult GetProtocolInfo(const char *scheme, PRUint32 &flags, PRInt32 &defaultPort);
nsresult NewProxyInfo_Internal(const char *type, char *host, PRInt32 port, nsIProxyInfo **);
void GetStringPref(const char *pref, nsCString &result);
void GetIntPref(const char *pref, PRInt32 &result);
void LoadFilters(const char *filters);
PRBool CanUseProxy(nsIURI *aURI, PRInt32 defaultPort);
@ -142,7 +143,6 @@ protected:
nsCOMPtr<nsIIOService> mIOService;
nsCOMPtr<nsIPref> mPrefs;
PRUint16 mUseProxy;
nsCString mHTTPProxyHost;

View File

@ -40,7 +40,6 @@
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIPrefBranchInternal.h"
#include "nsIPref.h"
#include "nsILocalFile.h"
#include "nsDirectoryServiceDefs.h"
#include "nsAppDirectoryServiceDefs.h"

View File

@ -48,7 +48,6 @@
#include "nsIDirectoryListing.h"
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
static NS_DEFINE_CID(kPrefServiceCID, NS_PREFSERVICE_CID);
//-----------------------------------------------------------------------------
@ -60,17 +59,12 @@ nsFileProtocolHandler::nsFileProtocolHandler()
nsresult
nsFileProtocolHandler::Init()
{
nsresult rv;
nsCOMPtr<nsIPrefService> prefService = do_GetService(kPrefServiceCID, &rv);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIPrefBranch> prefBranch;
rv = prefService->GetBranch(nsnull, getter_AddRefs(prefBranch));
if (NS_SUCCEEDED(rv)) {
PRInt32 sFormat;
rv = prefBranch->GetIntPref("network.dir.format", &sFormat);
if (NS_SUCCEEDED(rv) && sFormat == nsIDirectoryListing::FORMAT_HTML)
mGenerateHTMLDirs = PR_TRUE;
}
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
PRInt32 sFormat;
nsresult rv = prefs->GetIntPref("network.dir.format", &sFormat);
if (NS_SUCCEEDED(rv) && sFormat == nsIDirectoryListing::FORMAT_HTML)
mGenerateHTMLDirs = PR_TRUE;
}
return NS_OK;
}

View File

@ -44,7 +44,8 @@
#include "nsMimeTypes.h"
#include "nsIProxyObjectManager.h"
#include "nsReadableUtils.h"
#include "nsIPref.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIStreamConverterService.h"
#include "nsISocketTransport.h"
@ -742,38 +743,31 @@ nsFTPChannel::GetUploadStream(nsIInputStream **stream)
}
NS_IMETHODIMP
nsFTPChannel::SetListFormat(PRUint32 format) {
if (format != FORMAT_PREF &&
format != FORMAT_RAW &&
format != FORMAT_HTML &&
format != FORMAT_HTTP_INDEX) {
return NS_ERROR_FAILURE;
}
nsFTPChannel::SetListFormat(PRUint32 format)
{
// Convert the pref value
if (format == FORMAT_PREF) {
nsresult rv;
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
PRInt32 sFormat;
rv = prefs->GetIntPref("network.dir.format", &sFormat);
if (NS_FAILED(rv))
format = FORMAT_HTML; // default
else
format = sFormat;
if (format == FORMAT_PREF) {
NS_WARNING("Who set the directory format pref to 'read from prefs'??");
return NS_ERROR_FAILURE;
format = FORMAT_HTML; // default
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
PRInt32 sFormat;
if (NS_SUCCEEDED(prefs->GetIntPref("network.dir.format", &sFormat)))
format = sFormat;
}
}
if (format != FORMAT_RAW &&
format != FORMAT_HTML &&
format != FORMAT_HTTP_INDEX) {
NS_WARNING("invalid directory format");
return NS_ERROR_FAILURE;
}
mListFormat = format;
return NS_OK;
}
NS_IMETHODIMP
nsFTPChannel::GetListFormat(PRUint32 *format) {
nsFTPChannel::GetListFormat(PRUint32 *format)
{
*format = mListFormat;
return NS_OK;
}

View File

@ -64,7 +64,8 @@
#include "nsCPasswordManager.h"
#include "nsIMemory.h"
#include "nsIStringStream.h"
#include "nsIPref.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsMimeTypes.h"
#include "nsIStringBundle.h"
#include "nsEventQueueUtils.h"
@ -75,9 +76,8 @@
#include "nsIResumableChannel.h"
#include "nsIResumableEntityID.h"
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
static NS_DEFINE_CID(kStreamListenerTeeCID, NS_STREAMLISTENERTEE_CID);
static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
static NS_DEFINE_CID(kStreamListenerTeeCID, NS_STREAMLISTENERTEE_CID);
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
@ -1057,13 +1057,13 @@ nsFtpState::S_pass() {
if (mAnonymous) {
char* anonPassword = nsnull;
PRBool useRealEmail = PR_FALSE;
nsCOMPtr<nsIPref> pPref(do_GetService(kPrefCID, &rv));
if (NS_SUCCEEDED(rv) && pPref) {
rv = pPref->GetBoolPref("advanced.mailftp", &useRealEmail);
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
rv = prefs->GetBoolPref("advanced.mailftp", &useRealEmail);
if (NS_SUCCEEDED(rv) && useRealEmail)
rv = pPref->CopyCharPref("network.ftp.anonymous_password", &anonPassword);
prefs->GetCharPref("network.ftp.anonymous_password", &anonPassword);
}
if (NS_SUCCEEDED(rv) && useRealEmail && anonPassword && *anonPassword != '\0') {
if (useRealEmail && anonPassword && *anonPassword != '\0') {
passwordStr.Append(anonPassword);
nsMemory::Free(anonPassword);
}

View File

@ -43,7 +43,6 @@
#include "nsIInterfaceRequestorUtils.h"
#include "nsIProgressEventSink.h"
#include "prlog.h"
#include "nsIPref.h"
#include "nsNetUtil.h"
#include "nsIErrorService.h"
#include "nsIPrefService.h"

View File

@ -42,7 +42,8 @@
#include "nsITXTToHTMLConv.h"
#include "nsIEventQueue.h"
#include "nsEventQueueUtils.h"
#include "nsIPref.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
@ -758,31 +759,22 @@ nsGopherChannel::PushStreamConverters(nsIStreamListener *listener, nsIStreamList
NS_IMETHODIMP
nsGopherChannel::SetListFormat(PRUint32 format)
{
if (format != FORMAT_PREF &&
format != FORMAT_RAW &&
format != FORMAT_HTML &&
format != FORMAT_HTTP_INDEX) {
return NS_ERROR_FAILURE;
}
// Convert the pref value
if (format == FORMAT_PREF) {
nsresult rv;
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
PRInt32 sFormat;
rv = prefs->GetIntPref("network.dir.format", &sFormat);
if (NS_FAILED(rv))
format = FORMAT_HTML; // default
else
format = sFormat;
if (format == FORMAT_PREF) {
NS_WARNING("Who set the directory format pref to 'read from prefs'??");
return NS_ERROR_FAILURE;
format = FORMAT_HTML; // default
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
PRInt32 sFormat;
if (NS_SUCCEEDED(prefs->GetIntPref("network.dir.format", &sFormat)))
format = sFormat;
}
}
if (format != FORMAT_RAW &&
format != FORMAT_HTML &&
format != FORMAT_HTTP_INDEX) {
NS_WARNING("invalid directory format");
return NS_ERROR_FAILURE;
}
mListFormat = format;
return NS_OK;
}

View File

@ -42,14 +42,13 @@
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsEscape.h"
#include "nsIPref.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsNetUtil.h"
static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID);
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID);
////////////////////////////////////////////////////////////////////////////////
@ -58,17 +57,16 @@ nsKeywordProtocolHandler::nsKeywordProtocolHandler() {
nsresult
nsKeywordProtocolHandler::Init() {
nsresult rv = NS_OK;
nsCOMPtr<nsIPref> prefs(do_GetService(kPrefServiceCID, &rv));
nsresult rv;
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
nsXPIDLCString url;
rv = prefs->CopyCharPref("keyword.URL", getter_Copies(url));
rv = prefs->GetCharPref("keyword.URL", getter_Copies(url));
// if we can't find a keyword.URL keywords won't work.
if (NS_FAILED(rv) || !url || !*url) return NS_ERROR_FAILURE;
mKeywordURL.Assign(url);
return NS_OK;
}

View File

@ -51,7 +51,9 @@
#include "nsIChannel.h"
#include "nsIURI.h"
#include "nsCRT.h"
#include "nsIPref.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIPrefLocalizedString.h"
NS_IMPL_THREADSAFE_ISUPPORTS3(nsDirIndexParser,
nsIRequestObserver,
@ -63,38 +65,43 @@ nsDirIndexParser::nsDirIndexParser() {
nsresult
nsDirIndexParser::Init() {
nsresult rv = NS_OK;
mLineStart = 0;
mHasDescription = PR_FALSE;
mFormat = nsnull;
// get default charset to be used for directory listings (fallback to
// ISO-8859-1 if pref is unavailable).
NS_NAMED_LITERAL_CSTRING(kFallbackEncoding, "ISO-8859-1");
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID));
if (prefs) {
nsXPIDLString defCharset;
rv = prefs->GetLocalizedUnicharPref("intl.charset.default", getter_Copies(defCharset));
if (NS_SUCCEEDED(rv) && !defCharset.IsEmpty())
mEncoding.Assign(NS_ConvertUCS2toUTF8(defCharset).get());
else
mEncoding.Assign(kFallbackEncoding);
nsXPIDLString defCharset;
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (prefs) {
nsCOMPtr<nsIPrefLocalizedString> prefVal;
prefs->GetComplexValue("intl.charset.default",
NS_GET_IID(nsIPrefLocalizedString),
getter_AddRefs(prefVal));
if (prefVal)
prefVal->ToString(getter_Copies(defCharset));
}
if (!defCharset.IsEmpty())
LossyCopyUTF16toASCII(defCharset, mEncoding); // charset labels are always ASCII
else
mEncoding.Assign(kFallbackEncoding);
if (gRefCntParser++ == 0) {
nsresult rv;
// XXX not threadsafe
if (gRefCntParser++ == 0)
rv = nsServiceManager::GetService(NS_ITEXTTOSUBURI_CONTRACTID,
NS_GET_IID(nsITextToSubURI),
NS_REINTERPRET_CAST(nsISupports**, &gTextToSubURI));
if (NS_FAILED(rv)) return rv;
}
else
rv = NS_OK;
return rv;
}
nsDirIndexParser::~nsDirIndexParser() {
delete[] mFormat;
// XXX not threadsafe
if (--gRefCntParser == 0) {
NS_IF_RELEASE(gTextToSubURI);
}

View File

@ -45,7 +45,8 @@
#include "nsMimeTypes.h"
#include "netCore.h"
#include "nsXPIDLString.h"
#include "nsIPref.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "imgILoader.h"
#include "nsCRT.h"
@ -58,8 +59,6 @@
#define MAX_BUFFER_SIZE 1024
static NS_DEFINE_IID(kPrefServiceCID, NS_PREF_CID);
#if defined WORDS_BIGENDIAN || defined IS_BIG_ENDIAN
#define LITTLE_TO_NATIVE16(x) ((((x) & 0xFF) << 8) | ((x) >> 8))
#else
@ -67,18 +66,16 @@ static NS_DEFINE_IID(kPrefServiceCID, NS_PREF_CID);
#endif
nsUnknownDecoder::nsUnknownDecoder()
: mBuffer(nsnull)
, mBufferLen(0)
, mRequireHTMLsuffix(PR_FALSE)
{
mBuffer = nsnull;
mBufferLen = 0;
mRequireHTMLsuffix = PR_FALSE;
nsresult rv;
nsCOMPtr<nsIPref> pPrefService = do_GetService(kPrefServiceCID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = pPrefService->GetBoolPref("security.requireHTMLsuffix", &mRequireHTMLsuffix);
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
PRBool val;
if (NS_SUCCEEDED(prefs->GetBoolPref("security.requireHTMLsuffix", &val)))
mRequireHTMLsuffix = val;
}
}
nsUnknownDecoder::~nsUnknownDecoder()