Don't propagate LOAD_FROM_CACHE to the whole load group on charset reload.

This improves our cache consistency when the charset declaration is not within the first 1024 bytes of the document, properly re-fetching resources from the net where we should.
This commit is contained in:
Pale Moon
2017-11-24 14:44:34 +01:00
committed by Roy Tam
parent 69df8c876d
commit 04a1d5f15d
9 changed files with 67 additions and 7 deletions
+8 -2
View File
@@ -11044,9 +11044,15 @@ nsDocShell::DoChannelLoad(nsIChannel* aChannel,
break;
}
case LOAD_RELOAD_CHARSET_CHANGE:
loadFlags |= nsIRequest::LOAD_FROM_CACHE;
case LOAD_RELOAD_CHARSET_CHANGE: {
// Use SetAllowStaleCacheContent (not LOAD_FROM_CACHE flag) since we only want
// to force cache load for this channel, not the whole loadGroup.
nsCOMPtr<nsICacheInfoChannel> cachingChannel = do_QueryInterface(aChannel);
if (cachingChannel) {
cachingChannel->SetAllowStaleCacheContent(true);
}
break;
}
case LOAD_RELOAD_NORMAL:
case LOAD_REFRESH:
+8 -1
View File
@@ -4,7 +4,7 @@
#include "nsISupports.idl"
[scriptable, uuid (299d69b4-ee86-4541-802d-7642671ebf97)]
[scriptable, uuid(72c34415-c6eb-48af-851f-772fa9ee5972)]
interface nsICacheInfoChannel : nsISupports
{
/**
@@ -26,4 +26,11 @@ interface nsICacheInfoChannel : nsISupports
* and after the channel fires its OnStopRequest notification.
*/
boolean isFromCache();
/**
* Tells the channel to behave as if the LOAD_FROM_CACHE flag has been set,
* but without affecting the loads for the entire loadGroup in case of this
* channel being the default load group's channel.
*/
attribute boolean allowStaleCacheContent;
};
+1
View File
@@ -58,6 +58,7 @@ struct HttpChannelOpenArgs
uint32_t securityFlags;
uint32_t contentPolicyType;
uint32_t innerWindowID;
bool allowStaleCacheContent;
};
struct HttpChannelConnectArgs
@@ -72,6 +72,7 @@ HttpBaseChannel::HttpBaseChannel()
, mAllRedirectsSameOrigin(true)
, mAllRedirectsPassTimingAllowCheck(true)
, mForceNoIntercept(false)
, mAllowStaleCacheContent(false)
, mSuspendCount(0)
, mProxyResolveFlags(0)
, mProxyURI(nullptr)
+4
View File
@@ -370,6 +370,10 @@ protected:
// True if this channel should skip any interception checks
uint32_t mForceNoIntercept : 1;
// If true, we behave as if the LOAD_FROM_CACHE flag has been set.
// Used to enforce that flag's behavior but not expose it externally.
uint32_t mAllowStaleCacheContent : 1;
// Current suspension depth for this channel object
uint32_t mSuspendCount;
@@ -1630,6 +1630,8 @@ HttpChannelChild::ContinueAsyncOpen()
openArgs.chooseApplicationCache() = mChooseApplicationCache;
openArgs.appCacheClientID() = appCacheClientId;
openArgs.allowSpdy() = mAllowSpdy;
openArgs.allowStaleCacheContent() = mAllowStaleCacheContent;
propagateLoadInfo(mLoadInfo, openArgs);
@@ -1773,6 +1775,20 @@ HttpChannelChild::IsFromCache(bool *value)
return NS_OK;
}
NS_IMETHODIMP
HttpChannelChild::SetAllowStaleCacheContent(bool aAllowStaleCacheContent)
{
mAllowStaleCacheContent = aAllowStaleCacheContent;
return NS_OK;
}
NS_IMETHODIMP
HttpChannelChild::GetAllowStaleCacheContent(bool *aAllowStaleCacheContent)
{
NS_ENSURE_ARG(aAllowStaleCacheContent);
*aAllowStaleCacheContent = mAllowStaleCacheContent;
return NS_OK;
}
//-----------------------------------------------------------------------------
// HttpChannelChild::nsIResumableChannel
//-----------------------------------------------------------------------------
+6 -2
View File
@@ -110,7 +110,8 @@ HttpChannelParent::Init(const HttpChannelCreationArgs& aArgs)
a.entityID(), a.chooseApplicationCache(),
a.appCacheClientID(), a.allowSpdy(), a.fds(),
a.requestingPrincipalInfo(), a.triggeringPrincipalInfo(),
a.securityFlags(), a.contentPolicyType(), a.innerWindowID());
a.securityFlags(), a.contentPolicyType(), a.innerWindowID(),
a.allowStaleCacheContent());
}
case HttpChannelCreationArgs::THttpChannelConnectArgs:
{
@@ -201,7 +202,8 @@ HttpChannelParent::DoAsyncOpen( const URIParams& aURI,
const ipc::PrincipalInfo& aTriggeringPrincipalInfo,
const uint32_t& aSecurityFlags,
const uint32_t& aContentPolicyType,
const uint32_t& aInnerWindowID)
const uint32_t& aInnerWindowID,
const bool& aAllowStaleCacheContent)
{
nsCOMPtr<nsIURI> uri = DeserializeURI(aURI);
if (!uri) {
@@ -318,6 +320,8 @@ HttpChannelParent::DoAsyncOpen( const URIParams& aURI,
mChannel->SetUploadStreamHasHeaders(uploadStreamHasHeaders);
}
mChannel->SetAllowStaleCacheContent(aAllowStaleCacheContent);
if (priority != nsISupportsPriority::PRIORITY_NORMAL) {
mChannel->SetPriority(priority);
}
+2 -1
View File
@@ -115,7 +115,8 @@ protected:
const ipc::PrincipalInfo& aTriggeringPrincipalInfo,
const uint32_t& aSecurityFlags,
const uint32_t& aContentPolicyType,
const uint32_t& aInnerWindowID);
const uint32_t& aInnerWindowID,
const bool& aAllowStaleCacheContent);
virtual bool RecvSetPriority(const uint16_t& priority) override;
virtual bool RecvSetClassOfService(const uint32_t& cos) override;
+21 -1
View File
@@ -463,6 +463,10 @@ nsHttpChannel::SpeculativeConnect()
LOAD_NO_NETWORK_IO | LOAD_CHECK_OFFLINE_CACHE))
return;
if (mAllowStaleCacheContent) {
return;
}
nsCOMPtr<nsIInterfaceRequestor> callbacks;
NS_NewNotificationCallbacksAggregation(mCallbacks, mLoadGroup,
getter_AddRefs(callbacks));
@@ -3139,7 +3143,7 @@ nsHttpChannel::OnCacheEntryCheck(nsICacheEntry* entry, nsIApplicationCache* appC
doValidation = false;
}
// If the LOAD_FROM_CACHE flag is set, any cached data can simply be used
else if (mLoadFlags & nsIRequest::LOAD_FROM_CACHE) {
else if (mLoadFlags & nsIRequest::LOAD_FROM_CACHE || mAllowStaleCacheContent) {
LOG(("NOT validating based on LOAD_FROM_CACHE load flag\n"));
doValidation = false;
}
@@ -6080,6 +6084,22 @@ nsHttpChannel::SetCacheTokenCachedCharset(const nsACString &aCharset)
PromiseFlatCString(aCharset).get());
}
NS_IMETHODIMP
nsHttpChannel::SetAllowStaleCacheContent(bool aAllowStaleCacheContent)
{
LOG(("nsHttpChannel::SetAllowStaleCacheContent [this=%p, allow=%d]",
this, aAllowStaleCacheContent));
mAllowStaleCacheContent = aAllowStaleCacheContent;
return NS_OK;
}
NS_IMETHODIMP
nsHttpChannel::GetAllowStaleCacheContent(bool *aAllowStaleCacheContent)
{
NS_ENSURE_ARG(aAllowStaleCacheContent);
*aAllowStaleCacheContent = mAllowStaleCacheContent;
return NS_OK;
}
//-----------------------------------------------------------------------------
// nsHttpChannel::nsICachingChannel
//-----------------------------------------------------------------------------