Bug 666901 docshell should use mozilla::Preferences r=bz

This commit is contained in:
Masayuki Nakano
2011-06-25 10:55:46 +09:00
parent 2a1d826014
commit 128640d8a5
7 changed files with 131 additions and 196 deletions

View File

@@ -95,9 +95,6 @@
#include "nsXPCOMCID.h"
#include "nsISeekableStream.h"
#include "nsAutoPtr.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIPrefBranch2.h"
#include "nsIWritablePropertyBag2.h"
#include "nsIAppShell.h"
#include "nsWidgetsCID.h"
@@ -111,6 +108,7 @@
#include "nsJSON.h"
#include "IHistory.h"
#include "mozilla/Services.h"
#include "mozilla/Preferences.h"
// we want to explore making the document own the load group
// so we can associate the document URI with the load group.
@@ -307,21 +305,14 @@ FavorPerformanceHint(PRBool perfOverStarvation, PRUint32 starvationDelay)
static PRBool
PingsEnabled(PRInt32 *maxPerLink, PRBool *requireSameHost)
{
PRBool allow = PR_FALSE;
PRBool allow = Preferences::GetBool(PREF_PINGS_ENABLED, PR_FALSE);
*maxPerLink = 1;
*requireSameHost = PR_TRUE;
nsCOMPtr<nsIPrefBranch> prefs =
do_GetService(NS_PREFSERVICE_CONTRACTID);
if (prefs) {
PRBool val;
if (NS_SUCCEEDED(prefs->GetBoolPref(PREF_PINGS_ENABLED, &val)))
allow = val;
if (allow) {
prefs->GetIntPref(PREF_PINGS_MAX_PER_LINK, maxPerLink);
prefs->GetBoolPref(PREF_PINGS_REQUIRE_SAME_HOST, requireSameHost);
}
if (allow) {
Preferences::GetInt(PREF_PINGS_MAX_PER_LINK, maxPerLink);
Preferences::GetBool(PREF_PINGS_REQUIRE_SAME_HOST, requireSameHost);
}
return allow;
@@ -739,6 +730,7 @@ nsDocShell::nsDocShell():
mPreviousTransIndex(-1),
mLoadType(0),
mLoadedTransIndex(-1),
mCreated(PR_FALSE),
mAllowSubframes(PR_TRUE),
mAllowPlugins(PR_TRUE),
mAllowJavascript(PR_TRUE),
@@ -1600,9 +1592,7 @@ nsDocShell::MaybeInitTiming()
return NS_OK;
}
PRBool enabled;
nsresult rv = mPrefs->GetBoolPref("dom.enable_performance", &enabled);
if (NS_SUCCEEDED(rv) && enabled) {
if (Preferences::GetBool("dom.enable_performance", PR_FALSE)) {
mTiming = new nsDOMNavigationTiming();
mTiming->NotifyNavigationStart();
}
@@ -2201,11 +2191,8 @@ nsDocShell::SetUseErrorPages(PRBool aUseErrorPages)
{
// If mUseErrorPages is set explicitly, stop observing the pref.
if (mObserveErrorPages) {
nsCOMPtr<nsIPrefBranch2> prefs(do_QueryInterface(mPrefs));
if (prefs) {
prefs->RemoveObserver("browser.xul.error_pages.enabled", this);
mObserveErrorPages = PR_FALSE;
}
Preferences::RemoveObserver(this, "browser.xul.error_pages.enabled");
mObserveErrorPages = PR_FALSE;
}
mUseErrorPages = aUseErrorPages;
return NS_OK;
@@ -3919,17 +3906,15 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI *aURI,
if (isStsHost)
cssClass.AssignLiteral("badStsCert");
PRBool expert = PR_FALSE;
mPrefs->GetBoolPref("browser.xul.error_pages.expert_bad_cert",
&expert);
if (expert) {
if (Preferences::GetBool(
"browser.xul.error_pages.expert_bad_cert", PR_FALSE)) {
cssClass.AssignLiteral("expertBadCert");
}
// See if an alternate cert error page is registered
nsXPIDLCString alternateErrorPage;
mPrefs->GetCharPref("security.alternate_certificate_error_page",
getter_Copies(alternateErrorPage));
nsAdoptingCString alternateErrorPage =
Preferences::GetCString(
"security.alternate_certificate_error_page");
if (alternateErrorPage)
errorPage.Assign(alternateErrorPage);
} else {
@@ -3944,9 +3929,8 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI *aURI,
// Malware and phishing detectors may want to use an alternate error
// page, but if the pref's not set, we'll fall back on the standard page
nsXPIDLCString alternateErrorPage;
mPrefs->GetCharPref("urlclassifier.alternate_error_page",
getter_Copies(alternateErrorPage));
nsAdoptingCString alternateErrorPage =
Preferences::GetCString("urlclassifier.alternate_error_page");
if (alternateErrorPage)
errorPage.Assign(alternateErrorPage);
@@ -4492,7 +4476,7 @@ nsDocShell::InitWindow(nativeWindow parentNativeWindow,
NS_IMETHODIMP
nsDocShell::Create()
{
if (mPrefs) {
if (mCreated) {
// We've already been created
return NS_OK;
}
@@ -4500,34 +4484,24 @@ nsDocShell::Create()
NS_ASSERTION(mItemType == typeContent || mItemType == typeChrome,
"Unexpected item type in docshell");
nsresult rv = NS_ERROR_FAILURE;
mPrefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(Preferences::GetRootBranch(), NS_ERROR_FAILURE);
mCreated = PR_TRUE;
PRBool tmpbool;
rv = mPrefs->GetBoolPref("browser.frames.enabled", &tmpbool);
if (NS_SUCCEEDED(rv))
mAllowSubframes = tmpbool;
mAllowSubframes =
Preferences::GetBool("browser.frames.enabled", mAllowSubframes);
if (gValidateOrigin == (PRBool)0xffffffff) {
// Check pref to see if we should prevent frameset spoofing
rv = mPrefs->GetBoolPref("browser.frame.validate_origin", &tmpbool);
if (NS_SUCCEEDED(rv)) {
gValidateOrigin = tmpbool;
} else {
gValidateOrigin = PR_TRUE;
}
gValidateOrigin =
Preferences::GetBool("browser.frame.validate_origin", PR_TRUE);
}
// Should we use XUL error pages instead of alerts if possible?
rv = mPrefs->GetBoolPref("browser.xul.error_pages.enabled", &tmpbool);
if (NS_SUCCEEDED(rv))
mUseErrorPages = tmpbool;
mUseErrorPages =
Preferences::GetBool("browser.xul.error_pages.enabled", mUseErrorPages);
nsCOMPtr<nsIPrefBranch2> prefs(do_QueryInterface(mPrefs, &rv));
if (NS_SUCCEEDED(rv) && mObserveErrorPages) {
prefs->AddObserver("browser.xul.error_pages.enabled", this, PR_FALSE);
if (mObserveErrorPages) {
Preferences::AddStrongObserver(this, "browser.xul.error_pages.enabled");
}
nsCOMPtr<nsIObserverService> serv = do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
@@ -4560,11 +4534,8 @@ nsDocShell::Destroy()
// Remove our pref observers
if (mObserveErrorPages) {
nsCOMPtr<nsIPrefBranch2> prefs(do_QueryInterface(mPrefs));
if (prefs) {
prefs->RemoveObserver("browser.xul.error_pages.enabled", this);
mObserveErrorPages = PR_FALSE;
}
Preferences::RemoveObserver(this, "browser.xul.error_pages.enabled");
mObserveErrorPages = PR_FALSE;
}
// Make sure to blow away our mLoadingURI just in case. No loads
@@ -5971,9 +5942,7 @@ nsDocShell::OnStateChange(nsIWebProgress * aProgress, nsIRequest * aRequest,
if ((aStateFlags & STATE_RESTORING) == 0) {
// Show the progress cursor if the pref is set
PRBool tmpBool = PR_FALSE;
if (NS_SUCCEEDED(mPrefs->GetBoolPref("ui.use_activity_cursor", &tmpBool))
&& tmpBool) {
if (Preferences::GetBool("ui.use_activity_cursor", PR_FALSE)) {
nsCOMPtr<nsIWidget> mainWidget;
GetMainWidget(getter_AddRefs(mainWidget));
if (mainWidget) {
@@ -5991,9 +5960,7 @@ nsDocShell::OnStateChange(nsIWebProgress * aProgress, nsIRequest * aRequest,
mBusyFlags = BUSY_FLAGS_NONE;
// Hide the progress cursor if the pref is set
PRBool tmpBool = PR_FALSE;
if (NS_SUCCEEDED(mPrefs->GetBoolPref("ui.use_activity_cursor", &tmpBool))
&& tmpBool) {
if (Preferences::GetBool("ui.use_activity_cursor", PR_FALSE)) {
nsCOMPtr<nsIWidget> mainWidget;
GetMainWidget(getter_AddRefs(mainWidget));
if (mainWidget) {
@@ -6240,12 +6207,8 @@ nsDocShell::EndPageLoad(nsIWebProgress * aProgress,
// First try keyword fixup
//
if (aStatus == NS_ERROR_UNKNOWN_HOST && mAllowKeywordFixup) {
PRBool keywordsEnabled = PR_FALSE;
if (mPrefs &&
NS_FAILED(mPrefs->GetBoolPref("keyword.enabled",
&keywordsEnabled)))
keywordsEnabled = PR_FALSE;
PRBool keywordsEnabled =
Preferences::GetBool("keyword.enabled", PR_FALSE);
nsCAutoString host;
url->GetHost(host);
@@ -6700,9 +6663,9 @@ nsDocShell::CanSavePresentation(PRUint32 aLoadType,
// Don't cache the content viewer if we're in a subframe and the subframe
// pref is disabled.
PRBool cacheFrames = PR_FALSE;
mPrefs->GetBoolPref("browser.sessionhistory.cache_subframes",
&cacheFrames);
PRBool cacheFrames =
Preferences::GetBool("browser.sessionhistory.cache_subframes",
PR_FALSE);
if (!cacheFrames) {
nsCOMPtr<nsIDocShellTreeItem> root;
GetSameTypeParent(getter_AddRefs(root));
@@ -9212,22 +9175,16 @@ nsresult nsDocShell::DoChannelLoad(nsIChannel * aChannel,
case LOAD_NORMAL:
case LOAD_LINK:
// Set cache checking flags
PRInt32 prefSetting;
if (NS_SUCCEEDED
(mPrefs->
GetIntPref("browser.cache.check_doc_frequency",
&prefSetting))) {
switch (prefSetting) {
case 0:
loadFlags |= nsIRequest::VALIDATE_ONCE_PER_SESSION;
break;
case 1:
loadFlags |= nsIRequest::VALIDATE_ALWAYS;
break;
case 2:
loadFlags |= nsIRequest::VALIDATE_NEVER;
break;
}
switch (Preferences::GetInt("browser.cache.check_doc_frequency", -1)) {
case 0:
loadFlags |= nsIRequest::VALIDATE_ONCE_PER_SESSION;
break;
case 1:
loadFlags |= nsIRequest::VALIDATE_ALWAYS;
break;
case 2:
loadFlags |= nsIRequest::VALIDATE_NEVER;
break;
}
break;
}
@@ -9700,11 +9657,8 @@ nsDocShell::AddState(nsIVariant *aData, const nsAString& aTitle,
// Check that the state object isn't too long.
// Default max length: 640k bytes.
PRInt32 maxStateObjSize = 0xA0000;
if (mPrefs) {
mPrefs->GetIntPref("browser.history.maxStateObjectSize",
&maxStateObjSize);
}
PRInt32 maxStateObjSize =
Preferences::GetInt("browser.history.maxStateObjectSize", 0xA0000);
if (maxStateObjSize < 0) {
maxStateObjSize = 0;
}
@@ -11206,11 +11160,8 @@ nsDocShell::Observe(nsISupports *aSubject, const char *aTopic,
!nsCRT::strcmp(aData,
NS_LITERAL_STRING("browser.xul.error_pages.enabled").get())) {
nsCOMPtr<nsIPrefBranch> prefs(do_QueryInterface(aSubject, &rv));
NS_ENSURE_SUCCESS(rv, rv);
PRBool tmpbool;
rv = prefs->GetBoolPref("browser.xul.error_pages.enabled", &tmpbool);
rv = Preferences::GetBool("browser.xul.error_pages.enabled", &tmpbool);
if (NS_SUCCEEDED(rv))
mUseErrorPages = tmpbool;