Bug 906282 - Replace pref observer with var cache and remove nsIObserver inheritance. r=bz
This commit is contained in:
@@ -99,7 +99,6 @@
|
|||||||
#include "nsISHEntry.h"
|
#include "nsISHEntry.h"
|
||||||
#include "nsIWindowWatcher.h"
|
#include "nsIWindowWatcher.h"
|
||||||
#include "nsIPromptFactory.h"
|
#include "nsIPromptFactory.h"
|
||||||
#include "nsIObserver.h"
|
|
||||||
#include "nsITransportSecurityInfo.h"
|
#include "nsITransportSecurityInfo.h"
|
||||||
#include "nsINSSErrorsService.h"
|
#include "nsINSSErrorsService.h"
|
||||||
#include "nsIApplicationCacheChannel.h"
|
#include "nsIApplicationCacheChannel.h"
|
||||||
@@ -197,6 +196,11 @@ static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
|
|||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
using namespace mozilla::dom;
|
using namespace mozilla::dom;
|
||||||
|
|
||||||
|
// True means sUseErrorPages has been added to preferences var cache.
|
||||||
|
static bool gAddedPreferencesVarCache = false;
|
||||||
|
|
||||||
|
bool nsDocShell::sUseErrorPages = false;
|
||||||
|
|
||||||
// Number of documents currently loading
|
// Number of documents currently loading
|
||||||
static int32_t gNumberOfDocumentsLoading = 0;
|
static int32_t gNumberOfDocumentsLoading = 0;
|
||||||
|
|
||||||
@@ -898,7 +902,6 @@ NS_INTERFACE_MAP_BEGIN(nsDocShell)
|
|||||||
NS_INTERFACE_MAP_ENTRY(nsIContentViewerContainer)
|
NS_INTERFACE_MAP_ENTRY(nsIContentViewerContainer)
|
||||||
NS_INTERFACE_MAP_ENTRY(nsIWebPageDescriptor)
|
NS_INTERFACE_MAP_ENTRY(nsIWebPageDescriptor)
|
||||||
NS_INTERFACE_MAP_ENTRY(nsIAuthPromptProvider)
|
NS_INTERFACE_MAP_ENTRY(nsIAuthPromptProvider)
|
||||||
NS_INTERFACE_MAP_ENTRY(nsIObserver)
|
|
||||||
NS_INTERFACE_MAP_ENTRY(nsILoadContext)
|
NS_INTERFACE_MAP_ENTRY(nsILoadContext)
|
||||||
NS_INTERFACE_MAP_ENTRY(nsIWebShellServices)
|
NS_INTERFACE_MAP_ENTRY(nsIWebShellServices)
|
||||||
NS_INTERFACE_MAP_ENTRY(nsILinkHandler)
|
NS_INTERFACE_MAP_ENTRY(nsILinkHandler)
|
||||||
@@ -2573,16 +2576,15 @@ nsDocShell::SetSecurityUI(nsISecureBrowserUI *aSecurityUI)
|
|||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsDocShell::GetUseErrorPages(bool *aUseErrorPages)
|
nsDocShell::GetUseErrorPages(bool *aUseErrorPages)
|
||||||
{
|
{
|
||||||
*aUseErrorPages = mUseErrorPages;
|
*aUseErrorPages = UseErrorPages();
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsDocShell::SetUseErrorPages(bool aUseErrorPages)
|
nsDocShell::SetUseErrorPages(bool aUseErrorPages)
|
||||||
{
|
{
|
||||||
// If mUseErrorPages is set explicitly, stop observing the pref.
|
// If mUseErrorPages is set explicitly, stop using sUseErrorPages.
|
||||||
if (mObserveErrorPages) {
|
if (mObserveErrorPages) {
|
||||||
Preferences::RemoveObserver(this, "browser.xul.error_pages.enabled");
|
|
||||||
mObserveErrorPages = false;
|
mObserveErrorPages = false;
|
||||||
}
|
}
|
||||||
mUseErrorPages = aUseErrorPages;
|
mUseErrorPages = aUseErrorPages;
|
||||||
@@ -4486,7 +4488,8 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI *aURI,
|
|||||||
|
|
||||||
// Display the error as a page or an alert prompt
|
// Display the error as a page or an alert prompt
|
||||||
NS_ENSURE_FALSE(messageStr.IsEmpty(), NS_ERROR_FAILURE);
|
NS_ENSURE_FALSE(messageStr.IsEmpty(), NS_ERROR_FAILURE);
|
||||||
if (mUseErrorPages) {
|
|
||||||
|
if (UseErrorPages()) {
|
||||||
// Display an error page
|
// Display an error page
|
||||||
LoadErrorPage(aURI, aURL, errorPage.get(), error.get(),
|
LoadErrorPage(aURI, aURL, errorPage.get(), error.get(),
|
||||||
messageStr.get(), cssClass.get(), aFailedChannel);
|
messageStr.get(), cssClass.get(), aFailedChannel);
|
||||||
@@ -4939,8 +4942,11 @@ nsDocShell::Create()
|
|||||||
mUseErrorPages =
|
mUseErrorPages =
|
||||||
Preferences::GetBool("browser.xul.error_pages.enabled", mUseErrorPages);
|
Preferences::GetBool("browser.xul.error_pages.enabled", mUseErrorPages);
|
||||||
|
|
||||||
if (mObserveErrorPages) {
|
if(!gAddedPreferencesVarCache) {
|
||||||
Preferences::AddStrongObserver(this, "browser.xul.error_pages.enabled");
|
Preferences::AddBoolVarCache(&sUseErrorPages,
|
||||||
|
"browser.xul.error_pages.enabled",
|
||||||
|
mUseErrorPages);
|
||||||
|
gAddedPreferencesVarCache = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIObserverService> serv = services::GetObserverService();
|
nsCOMPtr<nsIObserverService> serv = services::GetObserverService();
|
||||||
@@ -4972,7 +4978,6 @@ nsDocShell::Destroy()
|
|||||||
|
|
||||||
// Remove our pref observers
|
// Remove our pref observers
|
||||||
if (mObserveErrorPages) {
|
if (mObserveErrorPages) {
|
||||||
Preferences::RemoveObserver(this, "browser.xul.error_pages.enabled");
|
|
||||||
mObserveErrorPages = false;
|
mObserveErrorPages = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6976,7 +6981,7 @@ nsDocShell::EndPageLoad(nsIWebProgress * aProgress,
|
|||||||
aStatus == NS_ERROR_CONNECTION_REFUSED ||
|
aStatus == NS_ERROR_CONNECTION_REFUSED ||
|
||||||
aStatus == NS_ERROR_UNKNOWN_PROXY_HOST ||
|
aStatus == NS_ERROR_UNKNOWN_PROXY_HOST ||
|
||||||
aStatus == NS_ERROR_PROXY_CONNECTION_REFUSED) &&
|
aStatus == NS_ERROR_PROXY_CONNECTION_REFUSED) &&
|
||||||
(isTopFrame || mUseErrorPages)) {
|
(isTopFrame || UseErrorPages())) {
|
||||||
DisplayLoadError(aStatus, url, nullptr, aChannel);
|
DisplayLoadError(aStatus, url, nullptr, aChannel);
|
||||||
}
|
}
|
||||||
// Errors to be shown for any frame
|
// Errors to be shown for any frame
|
||||||
@@ -11947,31 +11952,6 @@ nsDocShell::GetAuthPrompt(uint32_t aPromptReason, const nsIID& iid,
|
|||||||
reinterpret_cast<void**>(aResult));
|
reinterpret_cast<void**>(aResult));
|
||||||
}
|
}
|
||||||
|
|
||||||
//*****************************************************************************
|
|
||||||
// nsDocShell::nsIObserver
|
|
||||||
//*****************************************************************************
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsDocShell::Observe(nsISupports *aSubject, const char *aTopic,
|
|
||||||
const PRUnichar *aData)
|
|
||||||
{
|
|
||||||
nsresult rv = NS_OK;
|
|
||||||
if (mObserveErrorPages &&
|
|
||||||
!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) &&
|
|
||||||
!nsCRT::strcmp(aData,
|
|
||||||
NS_LITERAL_STRING("browser.xul.error_pages.enabled").get())) {
|
|
||||||
|
|
||||||
bool tmpbool;
|
|
||||||
rv = Preferences::GetBool("browser.xul.error_pages.enabled", &tmpbool);
|
|
||||||
if (NS_SUCCEEDED(rv))
|
|
||||||
mUseErrorPages = tmpbool;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
rv = NS_ERROR_UNEXPECTED;
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
//*****************************************************************************
|
//*****************************************************************************
|
||||||
// nsDocShell::nsILoadContext
|
// nsDocShell::nsILoadContext
|
||||||
//*****************************************************************************
|
//*****************************************************************************
|
||||||
|
|||||||
@@ -39,7 +39,6 @@
|
|||||||
#include "nsIWebProgressListener.h"
|
#include "nsIWebProgressListener.h"
|
||||||
#include "nsIDocShellLoadInfo.h"
|
#include "nsIDocShellLoadInfo.h"
|
||||||
#include "nsIAuthPromptProvider.h"
|
#include "nsIAuthPromptProvider.h"
|
||||||
#include "nsIObserver.h"
|
|
||||||
#include "nsILoadContext.h"
|
#include "nsILoadContext.h"
|
||||||
#include "nsIWebShellServices.h"
|
#include "nsIWebShellServices.h"
|
||||||
#include "nsILinkHandler.h"
|
#include "nsILinkHandler.h"
|
||||||
@@ -136,7 +135,6 @@ class nsDocShell : public nsDocLoader,
|
|||||||
public nsIWebProgressListener,
|
public nsIWebProgressListener,
|
||||||
public nsIWebPageDescriptor,
|
public nsIWebPageDescriptor,
|
||||||
public nsIAuthPromptProvider,
|
public nsIAuthPromptProvider,
|
||||||
public nsIObserver,
|
|
||||||
public nsILoadContext,
|
public nsILoadContext,
|
||||||
public nsIWebShellServices,
|
public nsIWebShellServices,
|
||||||
public nsILinkHandler,
|
public nsILinkHandler,
|
||||||
@@ -169,7 +167,6 @@ public:
|
|||||||
NS_DECL_NSICONTENTVIEWERCONTAINER
|
NS_DECL_NSICONTENTVIEWERCONTAINER
|
||||||
NS_DECL_NSIWEBPAGEDESCRIPTOR
|
NS_DECL_NSIWEBPAGEDESCRIPTOR
|
||||||
NS_DECL_NSIAUTHPROMPTPROVIDER
|
NS_DECL_NSIAUTHPROMPTPROVIDER
|
||||||
NS_DECL_NSIOBSERVER
|
|
||||||
NS_DECL_NSICLIPBOARDCOMMANDS
|
NS_DECL_NSICLIPBOARDCOMMANDS
|
||||||
NS_DECL_NSIWEBSHELLSERVICES
|
NS_DECL_NSIWEBSHELLSERVICES
|
||||||
NS_FORWARD_SAFE_NSIDOMSTORAGEMANAGER(TopSessionStorageManager())
|
NS_FORWARD_SAFE_NSIDOMSTORAGEMANAGER(TopSessionStorageManager())
|
||||||
@@ -527,6 +524,11 @@ protected:
|
|||||||
return uint32_t(t_usec /= usec_per_sec);
|
return uint32_t(t_usec /= usec_per_sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool UseErrorPages()
|
||||||
|
{
|
||||||
|
return (mObserveErrorPages ? sUseErrorPages : mUseErrorPages);
|
||||||
|
}
|
||||||
|
|
||||||
bool IsFrame();
|
bool IsFrame();
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -789,6 +791,9 @@ protected:
|
|||||||
};
|
};
|
||||||
FullscreenAllowedState mFullscreenAllowed;
|
FullscreenAllowedState mFullscreenAllowed;
|
||||||
|
|
||||||
|
// Cached value of the "browser.xul.error_pages.enabled" preference.
|
||||||
|
static bool sUseErrorPages;
|
||||||
|
|
||||||
bool mCreated;
|
bool mCreated;
|
||||||
bool mAllowSubframes;
|
bool mAllowSubframes;
|
||||||
bool mAllowPlugins;
|
bool mAllowPlugins;
|
||||||
|
|||||||
Reference in New Issue
Block a user