Bug 666903 uriloader should use mozilla::Preferences r=bz

This commit is contained in:
Masayuki Nakano 2011-07-01 17:35:28 +09:00
parent 91f7fc26f5
commit 7e6f0bf53f
10 changed files with 192 additions and 321 deletions

View File

@ -118,7 +118,6 @@
#include "nsITextToSubURI.h" // to unescape the filename #include "nsITextToSubURI.h" // to unescape the filename
#include "nsIMIMEHeaderParam.h" #include "nsIMIMEHeaderParam.h"
#include "nsIPrefService.h"
#include "nsIWindowWatcher.h" #include "nsIWindowWatcher.h"
#include "nsIDownloadHistory.h" // to mark downloads as visited #include "nsIDownloadHistory.h" // to mark downloads as visited
@ -149,6 +148,10 @@
#include "AndroidBridge.h" #include "AndroidBridge.h"
#endif #endif
#include "mozilla/Preferences.h"
using namespace mozilla;
// Buffer file writes in 32kb chunks // Buffer file writes in 32kb chunks
#define BUFFERED_OUTPUT_SIZE (1024 * 32) #define BUFFERED_OUTPUT_SIZE (1024 * 32)
@ -172,9 +175,10 @@ PRLogModuleInfo* nsExternalHelperAppService::mLog = nsnull;
#define LOG(args) PR_LOG(mLog, 3, args) #define LOG(args) PR_LOG(mLog, 3, args)
#define LOG_ENABLED() PR_LOG_TEST(mLog, 3) #define LOG_ENABLED() PR_LOG_TEST(mLog, 3)
static const char NEVER_ASK_PREF_BRANCH[] = "browser.helperApps.neverAsk."; static const char NEVER_ASK_FOR_SAVE_TO_DISK_PREF[] =
static const char NEVER_ASK_FOR_SAVE_TO_DISK_PREF[] = "saveToDisk"; "browser.helperApps.neverAsk.saveToDisk";
static const char NEVER_ASK_FOR_OPEN_FILE_PREF[] = "openFile"; static const char NEVER_ASK_FOR_OPEN_FILE_PREF[] =
"browser.helperApps.neverAsk.openFile";
/** /**
* Contains a pointer to the helper app service, set in its constructor * Contains a pointer to the helper app service, set in its constructor
@ -420,21 +424,15 @@ static nsresult GetDownloadDirectory(nsIFile **_directory)
nsCOMPtr<nsIFile> dir; nsCOMPtr<nsIFile> dir;
#ifdef XP_MACOSX #ifdef XP_MACOSX
// On OS X, we first try to get the users download location, if it's set. // On OS X, we first try to get the users download location, if it's set.
nsCOMPtr<nsIPrefBranch> prefs = switch (Preferences::GetInt(NS_PREF_DOWNLOAD_FOLDERLIST, -1)) {
do_GetService(NS_PREFSERVICE_CONTRACTID);
NS_ENSURE_TRUE(prefs, NS_ERROR_UNEXPECTED);
PRInt32 folderValue = -1;
(void) prefs->GetIntPref(NS_PREF_DOWNLOAD_FOLDERLIST, &folderValue);
switch (folderValue) {
case NS_FOLDER_VALUE_DESKTOP: case NS_FOLDER_VALUE_DESKTOP:
(void) NS_GetSpecialDirectory(NS_OS_DESKTOP_DIR, getter_AddRefs(dir)); (void) NS_GetSpecialDirectory(NS_OS_DESKTOP_DIR, getter_AddRefs(dir));
break; break;
case NS_FOLDER_VALUE_CUSTOM: case NS_FOLDER_VALUE_CUSTOM:
{ {
(void) prefs->GetComplexValue(NS_PREF_DOWNLOAD_DIR, Preferences::GetComplex(NS_PREF_DOWNLOAD_DIR,
NS_GET_IID(nsILocalFile), NS_GET_IID(nsILocalFile),
getter_AddRefs(dir)); getter_AddRefs(dir));
if (!dir) break; if (!dir) break;
// We have the directory, and now we need to make sure it exists // We have the directory, and now we need to make sure it exists
@ -940,35 +938,23 @@ NS_IMETHODIMP nsExternalHelperAppService::ExternalProtocolHandlerExists(const ch
NS_IMETHODIMP nsExternalHelperAppService::IsExposedProtocol(const char * aProtocolScheme, PRBool * aResult) NS_IMETHODIMP nsExternalHelperAppService::IsExposedProtocol(const char * aProtocolScheme, PRBool * aResult)
{ {
// check the per protocol setting first. it always takes precedence.
// if not set, then use the global setting.
nsCAutoString prefName("network.protocol-handler.expose.");
prefName += aProtocolScheme;
PRBool val;
if (NS_SUCCEEDED(Preferences::GetBool(prefName.get(), &val))) {
*aResult = val;
return NS_OK;
}
// by default, no protocol is exposed. i.e., by default all link clicks must // by default, no protocol is exposed. i.e., by default all link clicks must
// go through the external protocol service. most applications override this // go through the external protocol service. most applications override this
// default behavior. // default behavior.
*aResult = PR_FALSE; *aResult =
Preferences::GetBool("network.protocol-handler.expose-all", PR_FALSE);
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs)
{
PRBool val;
nsresult rv;
// check the per protocol setting first. it always takes precidence.
// if not set, then use the global setting.
nsCAutoString name;
name = NS_LITERAL_CSTRING("network.protocol-handler.expose.")
+ nsDependentCString(aProtocolScheme);
rv = prefs->GetBoolPref(name.get(), &val);
if (NS_SUCCEEDED(rv))
{
*aResult = val;
}
else
{
rv = prefs->GetBoolPref("network.protocol-handler.expose-all", &val);
if (NS_SUCCEEDED(rv) && val)
*aResult = PR_TRUE;
}
}
return NS_OK; return NS_OK;
} }
@ -1010,22 +996,21 @@ nsExternalHelperAppService::LoadURI(nsIURI *aURI,
if (scheme.IsEmpty()) if (scheme.IsEmpty())
return NS_OK; // must have a scheme return NS_OK; // must have a scheme
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (!prefs)
return NS_OK; // deny if we can't check prefs
// Deny load if the prefs say to do so // Deny load if the prefs say to do so
nsCAutoString externalPref(kExternalProtocolPrefPrefix); nsCAutoString externalPref(kExternalProtocolPrefPrefix);
externalPref += scheme; externalPref += scheme;
PRBool allowLoad = PR_FALSE; PRBool allowLoad = PR_FALSE;
rv = prefs->GetBoolPref(externalPref.get(), &allowLoad); if (NS_FAILED(Preferences::GetBool(externalPref.get(), &allowLoad))) {
if (NS_FAILED(rv))
{
// no scheme-specific value, check the default // no scheme-specific value, check the default
rv = prefs->GetBoolPref(kExternalProtocolDefaultPref, &allowLoad); if (NS_FAILED(Preferences::GetBool(kExternalProtocolDefaultPref,
&allowLoad))) {
return NS_OK; // missing default pref
}
}
if (!allowLoad) {
return NS_OK; // explicitly denied
} }
if (NS_FAILED(rv) || !allowLoad)
return NS_OK; // explicitly denied or missing default pref
nsCOMPtr<nsIHandlerInfo> handler; nsCOMPtr<nsIHandlerInfo> handler;
@ -1167,20 +1152,15 @@ nsExternalHelperAppService::SetProtocolHandlerDefaults(nsIHandlerInfo *aHandlerI
aHandlerInfo->SetPreferredAction(nsIHandlerInfo::useSystemDefault); aHandlerInfo->SetPreferredAction(nsIHandlerInfo::useSystemDefault);
// whether or not to ask the user depends on the warning preference // whether or not to ask the user depends on the warning preference
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (!prefs)
return NS_OK; // deny if we can't check prefs
nsCAutoString scheme; nsCAutoString scheme;
aHandlerInfo->GetType(scheme); aHandlerInfo->GetType(scheme);
nsCAutoString warningPref(kExternalWarningPrefPrefix); nsCAutoString warningPref(kExternalWarningPrefPrefix);
warningPref += scheme; warningPref += scheme;
PRBool warn = PR_TRUE; PRBool warn;
nsresult rv = prefs->GetBoolPref(warningPref.get(), &warn); if (NS_FAILED(Preferences::GetBool(warningPref.get(), &warn))) {
if (NS_FAILED(rv)) {
// no scheme-specific value, check the default // no scheme-specific value, check the default
prefs->GetBoolPref(kExternalWarningDefaultPref, &warn); warn = Preferences::GetBool(kExternalWarningDefaultPref, PR_TRUE);
} }
aHandlerInfo->SetAlwaysAskBeforeHandling(warn); aHandlerInfo->SetAlwaysAskBeforeHandling(warn);
} else { } else {
@ -1276,17 +1256,7 @@ nsExternalAppHandler::nsExternalAppHandler(nsIMIMEInfo * aMIMEInfo,
gExtProtSvc->AddRef(); gExtProtSvc->AddRef();
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID)); mBufferSize = Preferences::GetUint("network.buffer.cache.size", 4096);
if (!prefs)
return;
mBufferSize = 4096;
PRInt32 size;
nsresult rv = prefs->GetIntPref("network.buffer.cache.size", &size);
if (NS_SUCCEEDED(rv)) {
mBufferSize = size;
}
mDataBuffer = (char*) malloc(mBufferSize); mDataBuffer = (char*) malloc(mBufferSize);
if (!mDataBuffer) if (!mDataBuffer)
return; return;
@ -2338,20 +2308,18 @@ nsresult nsExternalAppHandler::OpenWithApplication()
// if a stop request was already issued then proceed with launching the application. // if a stop request was already issued then proceed with launching the application.
if (mStopRequestIssued) if (mStopRequestIssued)
{ {
PRBool deleteTempFileOnExit;
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID)); // Note for the default value:
if (!prefs || NS_FAILED(prefs->GetBoolPref( // Mac users have been very verbal about temp files being deleted on
"browser.helperApps.deleteTempFileOnExit", &deleteTempFileOnExit))) { // app exit - they don't like it - but we'll continue to do this on
// No prefservice or no pref set; use default value // other platforms for now.
PRBool deleteTempFileOnExit =
Preferences::GetBool("browser.helperApps.deleteTempFileOnExit",
#if !defined(XP_MACOSX) #if !defined(XP_MACOSX)
// Mac users have been very verbal about temp files being deleted on PR_TRUE);
// app exit - they don't like it - but we'll continue to do this on
// other platforms for now.
deleteTempFileOnExit = PR_TRUE;
#else #else
deleteTempFileOnExit = PR_FALSE; PR_FALSE);
#endif #endif
}
// make the tmp file readonly so users won't edit it and lose the changes // make the tmp file readonly so users won't edit it and lose the changes
// only if we're going to delete the file // only if we're going to delete the file
@ -2528,28 +2496,18 @@ void nsExternalAppHandler::ProcessAnyRefreshTags()
PRBool nsExternalAppHandler::GetNeverAskFlagFromPref(const char * prefName, const char * aContentType) PRBool nsExternalAppHandler::GetNeverAskFlagFromPref(const char * prefName, const char * aContentType)
{ {
// Search the obsolete pref strings. // Search the obsolete pref strings.
nsresult rv; nsAdoptingCString prefCString = Preferences::GetCString(prefName);
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); if (prefCString.IsEmpty()) {
nsCOMPtr<nsIPrefBranch> prefBranch; // Default is true, if not found in the pref string.
if (prefs) return PR_TRUE;
rv = prefs->GetBranch(NEVER_ASK_PREF_BRANCH, getter_AddRefs(prefBranch));
if (NS_SUCCEEDED(rv) && prefBranch)
{
nsXPIDLCString prefCString;
nsCAutoString prefValue;
rv = prefBranch->GetCharPref(prefName, getter_Copies(prefCString));
if (NS_SUCCEEDED(rv) && !prefCString.IsEmpty())
{
NS_UnescapeURL(prefCString);
nsACString::const_iterator start, end;
prefCString.BeginReading(start);
prefCString.EndReading(end);
if (CaseInsensitiveFindInReadable(nsDependentCString(aContentType), start, end))
return PR_FALSE;
}
} }
// Default is true, if not found in the pref string.
return PR_TRUE; NS_UnescapeURL(prefCString);
nsACString::const_iterator start, end;
prefCString.BeginReading(start);
prefCString.EndReading(end);
return !CaseInsensitiveFindInReadable(nsDependentCString(aContentType),
start, end);
} }
nsresult nsExternalAppHandler::MaybeCloseWindow() nsresult nsExternalAppHandler::MaybeCloseWindow()

View File

@ -58,6 +58,9 @@
#include "nsArrayEnumerator.h" #include "nsArrayEnumerator.h"
#include "nsIRwsService.h" #include "nsIRwsService.h"
#include <stdlib.h> #include <stdlib.h>
#include "mozilla/Preferences.h"
using namespace mozilla;
//------------------------------------------------------------------------ //------------------------------------------------------------------------
@ -296,10 +299,7 @@ void nsMIMEInfoOS2::SetDefaultAppHandle(PRUint32 aHandle)
nsresult nsMIMEInfoOS2::LoadUriInternal(nsIURI *aURL) nsresult nsMIMEInfoOS2::LoadUriInternal(nsIURI *aURL)
{ {
nsresult rv; nsresult rv;
nsCOMPtr<nsIPrefService> thePrefsService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); NS_ENSURE_TRUE(Preferences::GetRootBranch(), NS_ERROR_FAILURE);
if (!thePrefsService) {
return NS_ERROR_FAILURE;
}
/* Convert SimpleURI to StandardURL */ /* Convert SimpleURI to StandardURL */
nsCOMPtr<nsIURI> uri = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv); nsCOMPtr<nsIURI> uri = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
@ -314,20 +314,14 @@ nsresult nsMIMEInfoOS2::LoadUriInternal(nsIURI *aURL)
nsCAutoString uProtocol; nsCAutoString uProtocol;
uri->GetScheme(uProtocol); uri->GetScheme(uProtocol);
nsCAutoString prefName; nsCAutoString branchName = NS_LITERAL_CSTRING("applications.") + uProtocol;
prefName = NS_LITERAL_CSTRING("applications.") + uProtocol; nsCAutoString prefName = branchName + branchName;
nsAdoptingCString prefString = Preferences::GetCString(prefName.get());
nsCOMPtr<nsIPrefBranch> prefBranch;
rv = thePrefsService->GetBranch(prefName.get(), getter_AddRefs(prefBranch));
nsXPIDLCString prefString;
if (NS_SUCCEEDED(rv)) {
rv = prefBranch->GetCharPref(prefName.get(), getter_Copies(prefString));
}
nsCAutoString applicationName; nsCAutoString applicationName;
nsCAutoString parameters; nsCAutoString parameters;
if (NS_FAILED(rv) || prefString.IsEmpty()) { if (prefString.IsEmpty()) {
char szAppFromINI[CCHMAXPATH]; char szAppFromINI[CCHMAXPATH];
char szParamsFromINI[MAXINIPARAMLENGTH]; char szParamsFromINI[MAXINIPARAMLENGTH];
/* did OS2.INI contain application? */ /* did OS2.INI contain application? */
@ -385,57 +379,58 @@ nsresult nsMIMEInfoOS2::LoadUriInternal(nsIURI *aURL)
/* Put application name in parameters */ /* Put application name in parameters */
applicationName.Append(prefString); applicationName.Append(prefString);
prefName.Append("."); branchName.Append(".");
nsCOMPtr<nsIPrefBranch> prefBranch; prefName = branchName + NS_LITERAL_CSTRING("parameters");
rv = thePrefsService->GetBranch(prefName.get(), getter_AddRefs(prefBranch)); prefString = Preferences::GetCString(prefName.get());
if (NS_SUCCEEDED(rv) && prefBranch) { /* If parameters have been specified, use them instead of the separate entities */
rv = prefBranch->GetCharPref("parameters", getter_Copies(prefString)); if (!prefString.IsEmpty()) {
/* If parameters have been specified, use them instead of the separate entities */ parameters.Append(" ");
if (NS_SUCCEEDED(rv) && !prefString.IsEmpty()) { parameters.Append(prefString);
parameters.Append(" ");
parameters.Append(prefString);
PRInt32 pos = parameters.Find(url.get()); PRInt32 pos = parameters.Find(url.get());
if (pos != kNotFound) { if (pos != kNotFound) {
nsCAutoString uURL; nsCAutoString uURL;
aURL->GetSpec(uURL); aURL->GetSpec(uURL);
NS_UnescapeURL(uURL); NS_UnescapeURL(uURL);
uURL.Cut(0, uProtocol.Length()+1); uURL.Cut(0, uProtocol.Length()+1);
parameters.Replace(pos, url.Length(), uURL); parameters.Replace(pos, url.Length(), uURL);
replaced = PR_TRUE; replaced = PR_TRUE;
}
} else {
/* port */
if (!uPort.IsEmpty()) {
prefName = branchName + NS_LITERAL_CSTRING("port");
prefString = Preferences::GetCString(prefName.get());
if (!prefString.IsEmpty()) {
parameters.Append(" ");
parameters.Append(prefString);
} }
} else { }
/* port */ /* username */
if (!uPort.IsEmpty()) { if (!uUsername.IsEmpty()) {
rv = prefBranch->GetCharPref("port", getter_Copies(prefString)); prefName = branchName + NS_LITERAL_CSTRING("username");
if (NS_SUCCEEDED(rv) && !prefString.IsEmpty()) { prefString = Preferences::GetCString(prefName.get());
parameters.Append(" "); if (!prefString.IsEmpty()) {
parameters.Append(prefString); parameters.Append(" ");
} parameters.Append(prefString);
} }
/* username */ }
if (!uUsername.IsEmpty()) { /* password */
rv = prefBranch->GetCharPref("username", getter_Copies(prefString)); if (!uPassword.IsEmpty()) {
if (NS_SUCCEEDED(rv) && !prefString.IsEmpty()) { prefName = branchName + NS_LITERAL_CSTRING("password");
parameters.Append(" "); prefString = Preferences::GetCString(prefName.get());
parameters.Append(prefString); if (!prefString.IsEmpty()) {
} parameters.Append(" ");
parameters.Append(prefString);
} }
/* password */ }
if (!uPassword.IsEmpty()) { /* host */
rv = prefBranch->GetCharPref("password", getter_Copies(prefString)); if (!uHost.IsEmpty()) {
if (NS_SUCCEEDED(rv) && !prefString.IsEmpty()) { prefName = branchName + NS_LITERAL_CSTRING("host");
parameters.Append(" "); prefString = Preferences::GetCString(prefName.get());
parameters.Append(prefString); if (!prefString.IsEmpty()) {
} parameters.Append(" ");
} parameters.Append(prefString);
/* host */
if (!uHost.IsEmpty()) {
rv = prefBranch->GetCharPref("host", getter_Copies(prefString));
if (NS_SUCCEEDED(rv) && !prefString.IsEmpty()) {
parameters.Append(" ");
parameters.Append(prefString);
}
} }
} }
} }

View File

@ -44,8 +44,6 @@
#include "nsMIMEInfoImpl.h" #include "nsMIMEInfoImpl.h"
#include "nsIPropertyBag.h" #include "nsIPropertyBag.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsNetCID.h" #include "nsNetCID.h"
#include "nsEscape.h" #include "nsEscape.h"

View File

@ -63,8 +63,11 @@
#include "nsIStringBundle.h" #include "nsIStringBundle.h"
#include "nsLocalHandlerApp.h" #include "nsLocalHandlerApp.h"
#include "mozilla/Services.h" #include "mozilla/Services.h"
#include "mozilla/Preferences.h"
#include <stdlib.h> // for system() #include <stdlib.h> // for system()
using namespace mozilla;
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// reduces overhead by preventing calls to nsRws when it isn't present // reduces overhead by preventing calls to nsRws when it isn't present
@ -196,39 +199,27 @@ ParseMIMEType(const nsAString::const_iterator& aStart_iter,
nsresult nsresult
nsOSHelperAppService::GetFileLocation(const char* aPrefName, nsOSHelperAppService::GetFileLocation(const char* aPrefName,
const char* aEnvVarName, const char* aEnvVarName,
PRUnichar** aFileLocation) { nsAString& aFileLocation) {
LOG(("-- GetFileLocation. Pref: '%s' EnvVar: '%s'\n", LOG(("-- GetFileLocation. Pref: '%s' EnvVar: '%s'\n",
aPrefName, aPrefName,
aEnvVarName)); aEnvVarName));
NS_PRECONDITION(aPrefName, "Null pref name passed; don't do that!"); NS_PRECONDITION(aPrefName, "Null pref name passed; don't do that!");
nsresult rv; aFileLocation.Truncate();
*aFileLocation = nsnull;
/* The lookup order is: /* The lookup order is:
1) user pref 1) user pref
2) env var 2) env var
3) pref 3) pref
*/ */
nsCOMPtr<nsIPrefService> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); NS_ENSURE_TRUE(Preferences::GetRootBranch(), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIPrefBranch> prefBranch;
rv = prefService->GetBranch(nsnull, getter_AddRefs(prefBranch));
NS_ENSURE_SUCCESS(rv, rv);
/* /*
If we have an env var we should check whether the pref is a user If we have an env var we should check whether the pref is a user
pref. If we do not, we don't care. pref. If we do not, we don't care.
*/ */
nsCOMPtr<nsISupportsString> prefFileName; if (Preferences::HasUserValue(aPrefName) &&
PRBool isUserPref = PR_FALSE; NS_SUCCEEDED(Preferences::GetString(aPrefName, &aFileLocation))) {
prefBranch->PrefHasUserValue(aPrefName, &isUserPref); return NS_OK;
if (isUserPref) {
rv = prefBranch->GetComplexValue(aPrefName,
NS_GET_IID(nsISupportsString),
getter_AddRefs(prefFileName));
if (NS_SUCCEEDED(rv)) {
return prefFileName->ToString(aFileLocation);
}
} }
if (aEnvVarName && *aEnvVarName) { if (aEnvVarName && *aEnvVarName) {
@ -244,25 +235,13 @@ nsOSHelperAppService::GetFileLocation(const char* aPrefName,
rv = file->InitWithNativePath(nsDependentCString(prefValue)); rv = file->InitWithNativePath(nsDependentCString(prefValue));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsAutoString unicodePath; rv = file->GetPath(aFileLocation);
rv = file->GetPath(unicodePath);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
*aFileLocation = ToNewUnicode(unicodePath);
if (!*aFileLocation)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK; return NS_OK;
} }
} }
rv = prefBranch->GetComplexValue(aPrefName, return Preferences::GetString(aPrefName, &aFileLocation);
NS_GET_IID(nsISupportsString),
getter_AddRefs(prefFileName));
if (NS_SUCCEEDED(rv)) {
return prefFileName->ToString(aFileLocation);
}
return rv;
} }
@ -277,11 +256,10 @@ nsOSHelperAppService::LookUpTypeAndDescription(const nsAString& aFileExtension,
LOG(("-- LookUpTypeAndDescription for extension '%s'\n", LOG(("-- LookUpTypeAndDescription for extension '%s'\n",
NS_LossyConvertUTF16toASCII(aFileExtension).get())); NS_LossyConvertUTF16toASCII(aFileExtension).get()));
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsXPIDLString mimeFileName; nsAutoString mimeFileName;
rv = GetFileLocation("helpers.private_mime_types_file", rv = GetFileLocation("helpers.private_mime_types_file",
nsnull, nsnull, mimeFileName);
getter_Copies(mimeFileName));
if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) { if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) {
rv = GetTypeAndDescriptionFromMimetypesFile(mimeFileName, rv = GetTypeAndDescriptionFromMimetypesFile(mimeFileName,
aFileExtension, aFileExtension,
@ -293,8 +271,7 @@ nsOSHelperAppService::LookUpTypeAndDescription(const nsAString& aFileExtension,
} }
if (NS_FAILED(rv) || aMajorType.IsEmpty()) { if (NS_FAILED(rv) || aMajorType.IsEmpty()) {
rv = GetFileLocation("helpers.global_mime_types_file", rv = GetFileLocation("helpers.global_mime_types_file",
nsnull, nsnull, mimeFileName);
getter_Copies(mimeFileName));
if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) { if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) {
rv = GetTypeAndDescriptionFromMimetypesFile(mimeFileName, rv = GetTypeAndDescriptionFromMimetypesFile(mimeFileName,
aFileExtension, aFileExtension,
@ -506,11 +483,10 @@ nsOSHelperAppService::LookUpExtensionsAndDescription(const nsAString& aMajorType
NS_LossyConvertUTF16toASCII(aMajorType).get(), NS_LossyConvertUTF16toASCII(aMajorType).get(),
NS_LossyConvertUTF16toASCII(aMinorType).get())); NS_LossyConvertUTF16toASCII(aMinorType).get()));
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsXPIDLString mimeFileName; nsAutoString mimeFileName;
rv = GetFileLocation("helpers.private_mime_types_file", rv = GetFileLocation("helpers.private_mime_types_file",
nsnull, nsnull, mimeFileName);
getter_Copies(mimeFileName));
if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) { if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) {
rv = GetExtensionsAndDescriptionFromMimetypesFile(mimeFileName, rv = GetExtensionsAndDescriptionFromMimetypesFile(mimeFileName,
aMajorType, aMajorType,
@ -522,8 +498,7 @@ nsOSHelperAppService::LookUpExtensionsAndDescription(const nsAString& aMajorType
} }
if (NS_FAILED(rv) || aFileExtensions.IsEmpty()) { if (NS_FAILED(rv) || aFileExtensions.IsEmpty()) {
rv = GetFileLocation("helpers.global_mime_types_file", rv = GetFileLocation("helpers.global_mime_types_file",
nsnull, nsnull, mimeFileName);
getter_Copies(mimeFileName));
if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) { if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) {
rv = GetExtensionsAndDescriptionFromMimetypesFile(mimeFileName, rv = GetExtensionsAndDescriptionFromMimetypesFile(mimeFileName,
aMajorType, aMajorType,
@ -909,11 +884,10 @@ nsOSHelperAppService::LookUpHandlerAndDescription(const nsAString& aMajorType,
NS_LossyConvertUTF16toASCII(aMajorType).get(), NS_LossyConvertUTF16toASCII(aMajorType).get(),
NS_LossyConvertUTF16toASCII(aMinorType).get())); NS_LossyConvertUTF16toASCII(aMinorType).get()));
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsXPIDLString mailcapFileName; nsAutoString mailcapFileName;
rv = GetFileLocation("helpers.private_mailcap_file", rv = GetFileLocation("helpers.private_mailcap_file",
"PERSONAL_MAILCAP", "PERSONAL_MAILCAP", mailcapFileName);
getter_Copies(mailcapFileName));
if (NS_SUCCEEDED(rv) && !mailcapFileName.IsEmpty()) { if (NS_SUCCEEDED(rv) && !mailcapFileName.IsEmpty()) {
rv = GetHandlerAndDescriptionFromMailcapFile(mailcapFileName, rv = GetHandlerAndDescriptionFromMailcapFile(mailcapFileName,
aMajorType, aMajorType,
@ -927,8 +901,7 @@ nsOSHelperAppService::LookUpHandlerAndDescription(const nsAString& aMajorType,
} }
if (NS_FAILED(rv) || aHandler.IsEmpty()) { if (NS_FAILED(rv) || aHandler.IsEmpty()) {
rv = GetFileLocation("helpers.global_mailcap_file", rv = GetFileLocation("helpers.global_mailcap_file",
"MAILCAP", "MAILCAP", mailcapFileName);
getter_Copies(mailcapFileName));
if (NS_SUCCEEDED(rv) && !mailcapFileName.IsEmpty()) { if (NS_SUCCEEDED(rv) && !mailcapFileName.IsEmpty()) {
rv = GetHandlerAndDescriptionFromMailcapFile(mailcapFileName, rv = GetHandlerAndDescriptionFromMailcapFile(mailcapFileName,
aMajorType, aMajorType,
@ -1145,22 +1118,16 @@ nsresult nsOSHelperAppService::OSProtocolHandlerExists(const char * aProtocolSch
/* if applications.protocol is in prefs, then we have an external protocol handler */ /* if applications.protocol is in prefs, then we have an external protocol handler */
nsresult rv; nsresult rv;
nsCAutoString prefName; nsCAutoString branchName =
prefName = NS_LITERAL_CSTRING("applications.") + nsDependentCString(aProtocolScheme); NS_LITERAL_CSTRING("applications.") + nsDependentCString(aProtocolScheme);
nsCAutoString prefName = branchName + branchName;
nsCOMPtr<nsIPrefService> thePrefsService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); nsAdoptingCString prefString = Preferences::GetCString(prefName.get());
if (NS_SUCCEEDED(rv)) { *aHandlerExists = !prefString.IsEmpty();
nsCOMPtr<nsIPrefBranch> prefBranch; if (*aHandlerExists) {
rv = thePrefsService->GetBranch(prefName.get(), getter_AddRefs(prefBranch)); return NS_OK;
if (NS_SUCCEEDED(rv)) {
nsXPIDLCString prefString;
rv = prefBranch->GetCharPref(prefName.get(), getter_Copies(prefString));
*aHandlerExists = NS_SUCCEEDED(rv) && !prefString.IsEmpty();
if (*aHandlerExists) {
return NS_OK;
}
}
} }
/* Check the OS/2 INI for the protocol */ /* Check the OS/2 INI for the protocol */
char szAppFromINI[CCHMAXPATH]; char szAppFromINI[CCHMAXPATH];
char szParamsFromINI[MAXINIPARAMLENGTH]; char szParamsFromINI[MAXINIPARAMLENGTH];
@ -1642,14 +1609,12 @@ NS_IMETHODIMP
nsOSHelperAppService::GetApplicationDescription(const nsACString& aScheme, nsAString& _retval) nsOSHelperAppService::GetApplicationDescription(const nsACString& aScheme, nsAString& _retval)
{ {
nsresult rv; nsresult rv;
nsCOMPtr<nsIPrefService> thePrefsService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); nsCAutoString branchName = NS_LITERAL_CSTRING("applications.") + aScheme;
NS_ENSURE_SUCCESS(rv, rv);
nsCAutoString prefName = NS_LITERAL_CSTRING("applications.") + aScheme;
nsCOMPtr<nsIPrefBranch> prefBranch;
nsCAutoString applicationName; nsCAutoString applicationName;
rv = thePrefsService->GetBranch(prefName.get(), getter_AddRefs(prefBranch)); nsCAutoString prefName = branchName + branchName;
if (NS_FAILED(rv)) { nsAdoptingCString prefString = Preferences::GetCString(prefName.get());
if (!prefString) { // failed
char szAppFromINI[CCHMAXPATH]; char szAppFromINI[CCHMAXPATH];
char szParamsFromINI[MAXINIPARAMLENGTH]; char szParamsFromINI[MAXINIPARAMLENGTH];
/* did OS2.INI contain application? */ /* did OS2.INI contain application? */
@ -1661,12 +1626,8 @@ nsOSHelperAppService::GetApplicationDescription(const nsACString& aScheme, nsASt
} else { } else {
return NS_ERROR_NOT_AVAILABLE; return NS_ERROR_NOT_AVAILABLE;
} }
} else { } else if (!prefString.IsEmpty()) { // succeeded and not empty
nsXPIDLCString prefString; applicationName.Append(prefString);
rv = prefBranch->GetCharPref(prefName.get(), getter_Copies(prefString));
if (NS_SUCCEEDED(rv) && !prefString.IsEmpty()) {
applicationName.Append(prefString);
}
} }

View File

@ -92,7 +92,7 @@ private:
nsACString& aUnEscapedCommand); nsACString& aUnEscapedCommand);
static nsresult GetFileLocation(const char* aPrefName, static nsresult GetFileLocation(const char* aPrefName,
const char* aEnvVarName, const char* aEnvVarName,
PRUnichar** aFileLocation); nsAString& aFileLocation);
static nsresult LookUpTypeAndDescription(const nsAString& aFileExtension, static nsresult LookUpTypeAndDescription(const nsAString& aFileExtension,
nsAString& aMajorType, nsAString& aMajorType,
nsAString& aMinorType, nsAString& aMinorType,

View File

@ -61,8 +61,6 @@
#include "nsILineInputStream.h" #include "nsILineInputStream.h"
#include "nsILocalFile.h" #include "nsILocalFile.h"
#include "nsIProcess.h" #include "nsIProcess.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsNetCID.h" #include "nsNetCID.h"
#include "nsXPCOM.h" #include "nsXPCOM.h"
#include "nsISupportsPrimitives.h" #include "nsISupportsPrimitives.h"
@ -72,6 +70,9 @@
#include "nsDirectoryServiceUtils.h" #include "nsDirectoryServiceUtils.h"
#include "prenv.h" // for PR_GetEnv() #include "prenv.h" // for PR_GetEnv()
#include "nsAutoPtr.h" #include "nsAutoPtr.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
#define LOG(args) PR_LOG(mLog, PR_LOG_DEBUG, args) #define LOG(args) PR_LOG(mLog, PR_LOG_DEBUG, args)
#define LOG_ENABLED() PR_LOG_TEST(mLog, PR_LOG_DEBUG) #define LOG_ENABLED() PR_LOG_TEST(mLog, PR_LOG_DEBUG)
@ -203,39 +204,27 @@ ParseMIMEType(const nsAString::const_iterator& aStart_iter,
nsresult nsresult
nsOSHelperAppService::GetFileLocation(const char* aPrefName, nsOSHelperAppService::GetFileLocation(const char* aPrefName,
const char* aEnvVarName, const char* aEnvVarName,
PRUnichar** aFileLocation) { nsAString& aFileLocation) {
LOG(("-- GetFileLocation. Pref: '%s' EnvVar: '%s'\n", LOG(("-- GetFileLocation. Pref: '%s' EnvVar: '%s'\n",
aPrefName, aPrefName,
aEnvVarName)); aEnvVarName));
NS_PRECONDITION(aPrefName, "Null pref name passed; don't do that!"); NS_PRECONDITION(aPrefName, "Null pref name passed; don't do that!");
nsresult rv; aFileLocation.Truncate();
*aFileLocation = nsnull;
/* The lookup order is: /* The lookup order is:
1) user pref 1) user pref
2) env var 2) env var
3) pref 3) pref
*/ */
nsCOMPtr<nsIPrefService> prefService(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); NS_ENSURE_TRUE(Preferences::GetRootBranch(), NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIPrefBranch> prefBranch;
rv = prefService->GetBranch(nsnull, getter_AddRefs(prefBranch));
NS_ENSURE_SUCCESS(rv, rv);
/* /*
If we have an env var we should check whether the pref is a user If we have an env var we should check whether the pref is a user
pref. If we do not, we don't care. pref. If we do not, we don't care.
*/ */
nsCOMPtr<nsISupportsString> prefFileName; if (Preferences::HasUserValue(aPrefName) &&
PRBool isUserPref = PR_FALSE; NS_SUCCEEDED(Preferences::GetString(aPrefName, &aFileLocation))) {
prefBranch->PrefHasUserValue(aPrefName, &isUserPref); return NS_OK;
if (isUserPref) {
rv = prefBranch->GetComplexValue(aPrefName,
NS_GET_IID(nsISupportsString),
getter_AddRefs(prefFileName));
if (NS_SUCCEEDED(rv)) {
return prefFileName->ToString(aFileLocation);
}
} }
if (aEnvVarName && *aEnvVarName) { if (aEnvVarName && *aEnvVarName) {
@ -245,31 +234,21 @@ nsOSHelperAppService::GetFileLocation(const char* aPrefName,
// natural way to do the charset conversion is by just initing // natural way to do the charset conversion is by just initing
// an nsIFile with the native path and asking it for the Unicode // an nsIFile with the native path and asking it for the Unicode
// version. // version.
nsresult rv;
nsCOMPtr<nsILocalFile> file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv)); nsCOMPtr<nsILocalFile> file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = file->InitWithNativePath(nsDependentCString(prefValue)); rv = file->InitWithNativePath(nsDependentCString(prefValue));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsAutoString unicodePath; rv = file->GetPath(aFileLocation);
rv = file->GetPath(unicodePath);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
*aFileLocation = ToNewUnicode(unicodePath);
if (!*aFileLocation)
return NS_ERROR_OUT_OF_MEMORY;
return NS_OK; return NS_OK;
} }
} }
rv = prefBranch->GetComplexValue(aPrefName, return Preferences::GetString(aPrefName, &aFileLocation);
NS_GET_IID(nsISupportsString),
getter_AddRefs(prefFileName));
if (NS_SUCCEEDED(rv)) {
return prefFileName->ToString(aFileLocation);
}
return rv;
} }
@ -285,14 +264,12 @@ nsOSHelperAppService::LookUpTypeAndDescription(const nsAString& aFileExtension,
LOG(("-- LookUpTypeAndDescription for extension '%s'\n", LOG(("-- LookUpTypeAndDescription for extension '%s'\n",
NS_LossyConvertUTF16toASCII(aFileExtension).get())); NS_LossyConvertUTF16toASCII(aFileExtension).get()));
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsXPIDLString mimeFileName; nsAutoString mimeFileName;
const char* filenamePref = aUserData ? const char* filenamePref = aUserData ?
"helpers.private_mime_types_file" : "helpers.global_mime_types_file"; "helpers.private_mime_types_file" : "helpers.global_mime_types_file";
rv = GetFileLocation(filenamePref, rv = GetFileLocation(filenamePref, nsnull, mimeFileName);
nsnull,
getter_Copies(mimeFileName));
if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) { if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) {
rv = GetTypeAndDescriptionFromMimetypesFile(mimeFileName, rv = GetTypeAndDescriptionFromMimetypesFile(mimeFileName,
aFileExtension, aFileExtension,
@ -503,11 +480,9 @@ nsOSHelperAppService::LookUpExtensionsAndDescription(const nsAString& aMajorType
NS_LossyConvertUTF16toASCII(aMajorType).get(), NS_LossyConvertUTF16toASCII(aMajorType).get(),
NS_LossyConvertUTF16toASCII(aMinorType).get())); NS_LossyConvertUTF16toASCII(aMinorType).get()));
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsXPIDLString mimeFileName; nsAutoString mimeFileName;
rv = GetFileLocation("helpers.private_mime_types_file", rv = GetFileLocation("helpers.private_mime_types_file", nsnull, mimeFileName);
nsnull,
getter_Copies(mimeFileName));
if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) { if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) {
rv = GetExtensionsAndDescriptionFromMimetypesFile(mimeFileName, rv = GetExtensionsAndDescriptionFromMimetypesFile(mimeFileName,
aMajorType, aMajorType,
@ -519,8 +494,7 @@ nsOSHelperAppService::LookUpExtensionsAndDescription(const nsAString& aMajorType
} }
if (NS_FAILED(rv) || aFileExtensions.IsEmpty()) { if (NS_FAILED(rv) || aFileExtensions.IsEmpty()) {
rv = GetFileLocation("helpers.global_mime_types_file", rv = GetFileLocation("helpers.global_mime_types_file",
nsnull, nsnull, mimeFileName);
getter_Copies(mimeFileName));
if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) { if (NS_SUCCEEDED(rv) && !mimeFileName.IsEmpty()) {
rv = GetExtensionsAndDescriptionFromMimetypesFile(mimeFileName, rv = GetExtensionsAndDescriptionFromMimetypesFile(mimeFileName,
aMajorType, aMajorType,
@ -964,16 +938,14 @@ nsOSHelperAppService::DoLookUpHandlerAndDescription(const nsAString& aMajorType,
NS_LossyConvertUTF16toASCII(aMajorType).get(), NS_LossyConvertUTF16toASCII(aMajorType).get(),
NS_LossyConvertUTF16toASCII(aMinorType).get())); NS_LossyConvertUTF16toASCII(aMinorType).get()));
nsresult rv = NS_OK; nsresult rv = NS_OK;
nsXPIDLString mailcapFileName; nsAutoString mailcapFileName;
const char * filenamePref = aUserData ? const char * filenamePref = aUserData ?
"helpers.private_mailcap_file" : "helpers.global_mailcap_file"; "helpers.private_mailcap_file" : "helpers.global_mailcap_file";
const char * filenameEnvVar = aUserData ? const char * filenameEnvVar = aUserData ?
"PERSONAL_MAILCAP" : "MAILCAP"; "PERSONAL_MAILCAP" : "MAILCAP";
rv = GetFileLocation(filenamePref, rv = GetFileLocation(filenamePref, filenameEnvVar, mailcapFileName);
filenameEnvVar,
getter_Copies(mailcapFileName));
if (NS_SUCCEEDED(rv) && !mailcapFileName.IsEmpty()) { if (NS_SUCCEEDED(rv) && !mailcapFileName.IsEmpty()) {
rv = GetHandlerAndDescriptionFromMailcapFile(mailcapFileName, rv = GetHandlerAndDescriptionFromMailcapFile(mailcapFileName,
aMajorType, aMajorType,

View File

@ -93,7 +93,7 @@ private:
nsACString& aUnEscapedCommand); nsACString& aUnEscapedCommand);
static nsresult GetFileLocation(const char* aPrefName, static nsresult GetFileLocation(const char* aPrefName,
const char* aEnvVarName, const char* aEnvVarName,
PRUnichar** aFileLocation); nsAString& aFileLocation);
static nsresult LookUpTypeAndDescription(const nsAString& aFileExtension, static nsresult LookUpTypeAndDescription(const nsAString& aFileExtension,
nsAString& aMajorType, nsAString& aMajorType,
nsAString& aMinorType, nsAString& aMinorType,

View File

@ -61,8 +61,6 @@
#include "nsICacheEntryDescriptor.h" #include "nsICacheEntryDescriptor.h"
#include "nsIPermissionManager.h" #include "nsIPermissionManager.h"
#include "nsIPrincipal.h" #include "nsIPrincipal.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsNetCID.h" #include "nsNetCID.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsServiceManagerUtils.h" #include "nsServiceManagerUtils.h"
@ -71,9 +69,12 @@
#include "nsProxyRelease.h" #include "nsProxyRelease.h"
#include "prlog.h" #include "prlog.h"
#include "nsIAsyncVerifyRedirectCallback.h" #include "nsIAsyncVerifyRedirectCallback.h"
#include "mozilla/Preferences.h"
#include "nsXULAppAPI.h" #include "nsXULAppAPI.h"
using namespace mozilla;
static const PRUint32 kRescheduleLimit = 3; static const PRUint32 kRescheduleLimit = 3;
#if defined(PR_LOGGING) #if defined(PR_LOGGING)
@ -1029,11 +1030,8 @@ nsOfflineManifestItem::CheckNewManifestContentHash(nsIRequest *aRequest)
void void
nsOfflineManifestItem::ReadStrictFileOriginPolicyPref() nsOfflineManifestItem::ReadStrictFileOriginPolicyPref()
{ {
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
mStrictFileOriginPolicy = mStrictFileOriginPolicy =
(!prefs || Preferences::GetBool("security.fileuri.strict_origin_policy", PR_TRUE);
NS_FAILED(prefs->GetBoolPref("security.fileuri.strict_origin_policy",
&mStrictFileOriginPolicy)));
} }
NS_IMETHODIMP NS_IMETHODIMP

View File

@ -64,8 +64,6 @@
#include "nsICacheEntryDescriptor.h" #include "nsICacheEntryDescriptor.h"
#include "nsIPermissionManager.h" #include "nsIPermissionManager.h"
#include "nsIPrincipal.h" #include "nsIPrincipal.h"
#include "nsIPrefBranch.h"
#include "nsIPrefService.h"
#include "nsNetCID.h" #include "nsNetCID.h"
#include "nsNetUtil.h" #include "nsNetUtil.h"
#include "nsServiceManagerUtils.h" #include "nsServiceManagerUtils.h"
@ -74,6 +72,9 @@
#include "nsProxyRelease.h" #include "nsProxyRelease.h"
#include "prlog.h" #include "prlog.h"
#include "nsIAsyncVerifyRedirectCallback.h" #include "nsIAsyncVerifyRedirectCallback.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
static nsOfflineCacheUpdateService *gOfflineCacheUpdateService = nsnull; static nsOfflineCacheUpdateService *gOfflineCacheUpdateService = nsnull;
@ -569,15 +570,11 @@ nsOfflineCacheUpdateService::OfflineAppAllowedForURI(nsIURI *aURI,
permissionManager->TestExactPermission(innerURI, "offline-app", &perm); permissionManager->TestExactPermission(innerURI, "offline-app", &perm);
if (perm == nsIPermissionManager::UNKNOWN_ACTION) { if (perm == nsIPermissionManager::UNKNOWN_ACTION) {
nsCOMPtr<nsIPrefBranch> branch = aPrefBranch; static const char kPrefName[] = "offline-apps.allow_by_default";
if (!branch) { if (aPrefBranch) {
branch = do_GetService(NS_PREFSERVICE_CONTRACTID); aPrefBranch->GetBoolPref(kPrefName, aAllowed);
} } else {
if (branch) { *aAllowed = Preferences::GetBool(kPrefName, PR_FALSE);
rv = branch->GetBoolPref("offline-apps.allow_by_default", aAllowed);
if (NS_FAILED(rv)) {
*aAllowed = PR_FALSE;
}
} }
return NS_OK; return NS_OK;

View File

@ -41,8 +41,6 @@
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
#include "nsICategoryManager.h" #include "nsICategoryManager.h"
#include "nsIObserverService.h" #include "nsIObserverService.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch2.h"
#include "nsIDocCharset.h" #include "nsIDocCharset.h"
#include "nsIWebProgress.h" #include "nsIWebProgress.h"
#include "nsCURILoader.h" #include "nsCURILoader.h"
@ -61,6 +59,9 @@
#include "prlog.h" #include "prlog.h"
#include "plstr.h" #include "plstr.h"
#include "nsIAsyncVerifyRedirectCallback.h" #include "nsIAsyncVerifyRedirectCallback.h"
#include "mozilla/Preferences.h"
using namespace mozilla;
#if defined(PR_LOGGING) #if defined(PR_LOGGING)
// //
@ -414,6 +415,7 @@ nsPrefetchService::nsPrefetchService()
nsPrefetchService::~nsPrefetchService() nsPrefetchService::~nsPrefetchService()
{ {
Preferences::RemoveObserver(this, PREFETCH_PREF);
// cannot reach destructor if prefetch in progress (listener owns reference // cannot reach destructor if prefetch in progress (listener owns reference
// to this service) // to this service)
EmptyQueue(); EmptyQueue();
@ -430,15 +432,8 @@ nsPrefetchService::Init()
nsresult rv; nsresult rv;
// read prefs and hook up pref observer // read prefs and hook up pref observer
nsCOMPtr<nsIPrefBranch2> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); mDisabled = !Preferences::GetBool(PREFETCH_PREF, !mDisabled);
if (NS_SUCCEEDED(rv)) { Preferences::AddWeakObserver(this, PREFETCH_PREF);
PRBool enabled;
rv = prefs->GetBoolPref(PREFETCH_PREF, &enabled);
if (NS_SUCCEEDED(rv) && enabled)
mDisabled = PR_FALSE;
prefs->AddObserver(PREFETCH_PREF, this, PR_TRUE);
}
// Observe xpcom-shutdown event // Observe xpcom-shutdown event
nsCOMPtr<nsIObserverService> observerService = nsCOMPtr<nsIObserverService> observerService =
@ -945,10 +940,7 @@ nsPrefetchService::Observe(nsISupports *aSubject,
mDisabled = PR_TRUE; mDisabled = PR_TRUE;
} }
else if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) { else if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
nsCOMPtr<nsIPrefBranch> prefs(do_QueryInterface(aSubject)); if (Preferences::GetBool(PREFETCH_PREF, PR_FALSE)) {
PRBool enabled;
nsresult rv = prefs->GetBoolPref(PREFETCH_PREF, &enabled);
if (NS_SUCCEEDED(rv) && enabled) {
if (mDisabled) { if (mDisabled) {
LOG(("enabling prefetching\n")); LOG(("enabling prefetching\n"));
mDisabled = PR_FALSE; mDisabled = PR_FALSE;