Bug 1246291 - Add property to nsIWebProgress to indicate that a refresh was blocked. r?bz
This property is useful for cases where refreshes are caused by
the "refresh" key in an HTTP response header. When that occurs,
onRefreshAttempted for nsIWebProgressListener's are fired before
onLocationChange. For meta-tag refreshes, however, onRefreshAttempted
is fired _after_ onLocationChange.
So this allows us to detect refreshes having been blocked in the
first case for onLocationChange handlers.
MozReview-Commit-ID: F0jjQrDSWsq
--- a/toolkit/components/statusfilter/nsBrowserStatusFilter.cpp
+++ b/toolkit/components/statusfilter/nsBrowserStatusFilter.cpp
@@ -100,16 +100,24 @@ nsBrowserStatusFilter::GetIsLoadingDocum
NS_IMETHODIMP
nsBrowserStatusFilter::GetLoadType(uint32_t *aLoadType)
{
*aLoadType = 0;
NS_NOTREACHED("nsBrowserStatusFilter::GetLoadType");
return NS_ERROR_NOT_IMPLEMENTED;
}
+NS_IMETHODIMP
+nsBrowserStatusFilter::GetRefreshWasBlocked(bool *aRefreshWasBlocked)
+{
+ *aRefreshWasBlocked = false;
+ NS_NOTREACHED("nsBrowserStatusFilter::GetRefreshWasBlocked");
+ return NS_ERROR_NOT_IMPLEMENTED;
+}
+
//-----------------------------------------------------------------------------
// nsBrowserStatusFilter::nsIWebProgressListener
//-----------------------------------------------------------------------------
NS_IMETHODIMP
nsBrowserStatusFilter::OnStateChange(nsIWebProgress *aWebProgress,
nsIRequest *aRequest,
uint32_t aStateFlags,
--- a/uriloader/base/nsDocLoader.cpp
+++ b/uriloader/base/nsDocLoader.cpp
@@ -108,17 +108,18 @@ nsDocLoader::nsDocLoader()
mMaxSelfProgress(0),
mCurrentTotalProgress(0),
mMaxTotalProgress(0),
mRequestInfoHash(&sRequestInfoHashOps, sizeof(nsRequestInfo)),
mCompletedTotalProgress(0),
mIsLoadingDocument(false),
mIsRestoringDocument(false),
mDontFlushLayout(false),
- mIsFlushingLayout(false)
+ mIsFlushingLayout(false),
+ mRefreshWasBlocked(false)
{
if (nullptr == gDocLoaderLog) {
gDocLoaderLog = PR_NewLogModule("DocLoader");
}
ClearInternalProgress();
MOZ_LOG(gDocLoaderLog, LogLevel::Debug,
@@ -409,16 +410,17 @@ nsDocLoader::OnStartRequest(nsIRequest *
bool bJustStartedLoading = false;
nsLoadFlags loadFlags = 0;
request->GetLoadFlags(&loadFlags);
if (!mIsLoadingDocument && (loadFlags & nsIChannel::LOAD_DOCUMENT_URI)) {
bJustStartedLoading = true;
mIsLoadingDocument = true;
+ mRefreshWasBlocked = false;
ClearInternalProgress(); // only clear our progress if we are starting a new load....
}
//
// Create a new nsRequestInfo for the request that is starting to
// load...
//
AddRequestInfo(request);
@@ -930,16 +932,24 @@ nsDocLoader::GetIsLoadingDocument(bool *
NS_IMETHODIMP
nsDocLoader::GetLoadType(uint32_t *aLoadType)
{
*aLoadType = 0;
return NS_ERROR_NOT_IMPLEMENTED;
}
+NS_IMETHODIMP
+nsDocLoader::GetRefreshWasBlocked(bool *aRefreshWasBlocked)
+{
+ *aRefreshWasBlocked = mRefreshWasBlocked;
+
+ return NS_OK;
+}
+
int64_t nsDocLoader::GetMaxTotalProgress()
{
int64_t newMaxTotal = 0;
uint32_t count = mChildList.Length();
nsCOMPtr<nsIWebProgress> webProgress;
for (uint32_t i=0; i < count; i++)
{
@@ -1319,16 +1329,18 @@ nsDocLoader::RefreshAttempted(nsIWebProg
);
// Pass the notification up to the parent...
if (mParent) {
allowRefresh = allowRefresh &&
mParent->RefreshAttempted(aWebProgress, aURI, aDelay, aSameURI);
}
+ mRefreshWasBlocked = !allowRefresh;
+
return allowRefresh;
}
nsresult nsDocLoader::AddRequestInfo(nsIRequest *aRequest)
{
if (!mRequestInfoHash.Add(aRequest, mozilla::fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
}
--- a/uriloader/base/nsDocLoader.h
+++ b/uriloader/base/nsDocLoader.h
@@ -323,13 +323,15 @@ private:
void RemoveRequestInfo(nsIRequest* aRequest);
nsRequestInfo *GetRequestInfo(nsIRequest* aRequest);
void ClearRequestInfoHash();
int64_t CalculateMaxProgress();
/// void DumpChannelInfo(void);
// used to clear our internal progress state between loads...
void ClearInternalProgress();
+
+ bool mRefreshWasBlocked;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsDocLoader, NS_THIS_DOCLOADER_IMPL_CID)
#endif /* nsDocLoader_h__ */
--- a/uriloader/base/nsIWebProgress.idl
+++ b/uriloader/base/nsIWebProgress.idl
@@ -145,9 +145,15 @@ interface nsIWebProgress : nsISupports
*/
readonly attribute boolean isLoadingDocument;
/**
* Contains a load type as specified by the load* constants in
* nsIDocShellLoadInfo.idl.
*/
readonly attribute unsigned long loadType;
+
+ /**
+ * Indicates whether the refresh was blocked by an
+ * nsIWebProgressListener listening for onRefreshAttempted.
+ */
+ readonly attribute boolean refreshWasBlocked;
};