Bug 1156493 - e10s: move .cacheKey to nsICacheInfoChannel so child channels can get/set it, r=jduell

This commit is contained in:
Michal Novotny 2015-05-10 02:26:39 +02:00
parent 3daabba6ad
commit eaf3e06c3c
14 changed files with 176 additions and 72 deletions

View File

@ -10725,7 +10725,7 @@ nsDocShell::DoURILoad(nsIURI* aURI,
// (ie. POST data, referrer, ...)
//
if (httpChannel) {
nsCOMPtr<nsICachingChannel> cacheChannel(do_QueryInterface(httpChannel));
nsCOMPtr<nsICacheInfoChannel> cacheChannel(do_QueryInterface(httpChannel));
/* Get the cache Key from SH */
nsCOMPtr<nsISupports> cacheKey;
if (mLSHE) {
@ -11275,7 +11275,7 @@ nsDocShell::OnNewURI(nsIURI* aURI, nsIChannel* aChannel, nsISupports* aOwner,
"We shouldn't be updating session history for forced"
" reloads!");
nsCOMPtr<nsICachingChannel> cacheChannel(do_QueryInterface(aChannel));
nsCOMPtr<nsICacheInfoChannel> cacheChannel(do_QueryInterface(aChannel));
nsCOMPtr<nsISupports> cacheKey;
// Get the Cache Key and store it in SH.
if (cacheChannel) {
@ -11829,7 +11829,7 @@ nsDocShell::AddToSessionHistory(nsIURI* aURI, nsIChannel* aChannel,
nsCOMPtr<nsISupports> owner = aOwner;
bool expired = false;
bool discardLayoutState = false;
nsCOMPtr<nsICachingChannel> cacheChannel;
nsCOMPtr<nsICacheInfoChannel> cacheChannel;
if (aChannel) {
cacheChannel = do_QueryInterface(aChannel);

View File

@ -19,7 +19,7 @@
#include "nsIHttpChannelInternal.h"
#include "nsIEncodedChannel.h"
#include "nsIUploadChannel.h"
#include "nsICachingChannel.h"
#include "nsICacheInfoChannel.h"
#include "nsIFileChannel.h"
#include "nsEscape.h"
#include "nsUnicharUtils.h"
@ -1274,7 +1274,7 @@ nsresult nsWebBrowserPersist::SaveURIInternal(
}
// Cache key
nsCOMPtr<nsICachingChannel> cacheChannel(do_QueryInterface(httpChannel));
nsCOMPtr<nsICacheInfoChannel> cacheChannel(do_QueryInterface(httpChannel));
if (cacheChannel && cacheKey)
{
cacheChannel->SetCacheKey(cacheKey);

View File

@ -4,7 +4,7 @@
#include "nsISupports.idl"
[scriptable, uuid (299d69b4-ee86-4541-802d-7642671ebf97)]
[scriptable, uuid (c5f583f0-ae53-4e39-8af9-2c2d0d7af093)]
interface nsICacheInfoChannel : nsISupports
{
/**
@ -26,4 +26,23 @@ interface nsICacheInfoChannel : nsISupports
* and after the channel fires its OnStopRequest notification.
*/
boolean isFromCache();
/**
* Set/get the cache key... uniquely identifies the data in the cache
* for this channel. Holding a reference to this key does NOT prevent
* the cached data from being removed.
*
* A cache key retrieved from a particular instance of nsICachingChannel
* could be set on another instance of nsICachingChannel provided the
* underlying implementations are compatible and provided the new
* channel instance was created with the same URI. The implementation of
* nsICachingChannel would be expected to use the cache entry identified
* by the cache token. Depending on the value of nsIRequest::loadFlags,
* the cache entry may be validated, overwritten, or simply read.
*
* The cache key may be NULL indicating that the URI of the channel is
* sufficient to locate the same cache entry. Setting a NULL cache key
* is likewise valid.
*/
attribute nsISupports cacheKey;
};

View File

@ -17,7 +17,7 @@ interface nsIFile;
* 3) Support for uniquely identifying cached data in cases when the URL
* is insufficient (e.g., HTTP form submission).
*/
[scriptable, uuid(3d46b469-7405-416e-ba42-84899963b403)]
[scriptable, uuid(436b939d-e391-48e5-ba64-ab0e496e3400)]
interface nsICachingChannel : nsICacheInfoChannel
{
/**
@ -45,25 +45,6 @@ interface nsICachingChannel : nsICacheInfoChannel
*/
attribute nsISupports offlineCacheToken;
/**
* Set/get the cache key... uniquely identifies the data in the cache
* for this channel. Holding a reference to this key does NOT prevent
* the cached data from being removed.
*
* A cache key retrieved from a particular instance of nsICachingChannel
* could be set on another instance of nsICachingChannel provided the
* underlying implementations are compatible and provided the new
* channel instance was created with the same URI. The implementation of
* nsICachingChannel would be expected to use the cache entry identified
* by the cache token. Depending on the value of nsIRequest::loadFlags,
* the cache entry may be validated, overwritten, or simply read.
*
* The cache key may be NULL indicating that the URI of the channel is
* sufficient to locate the same cache entry. Setting a NULL cache key
* is likewise valid.
*/
attribute nsISupports cacheKey;
/**
* Instructs the channel to only store the metadata of the entry, and not
* the content. When reading an existing entry, this automatically sets

View File

@ -30,6 +30,18 @@ union OptionalHttpResponseHead
nsHttpResponseHead;
};
struct HttpChannelCacheKey
{
uint32_t postId;
nsCString key;
};
union OptionalHttpChannelCacheKey
{
void_t;
HttpChannelCacheKey;
};
struct HttpChannelOpenArgs
{
URIParams uri;
@ -67,6 +79,7 @@ struct HttpChannelOpenArgs
uint32_t contentPolicyType;
uint32_t innerWindowID;
OptionalHttpResponseHead synthesizedResponseHead;
OptionalHttpChannelCacheKey cacheKey;
};
struct HttpChannelConnectArgs

View File

@ -323,7 +323,8 @@ class StartRequestEvent : public ChannelEvent
const nsCString& cachedCharset,
const nsCString& securityInfoSerialization,
const NetAddr& selfAddr,
const NetAddr& peerAddr)
const NetAddr& peerAddr,
const HttpChannelCacheKey& cacheKey)
: mChild(child)
, mChannelStatus(channelStatus)
, mResponseHead(responseHead)
@ -336,6 +337,7 @@ class StartRequestEvent : public ChannelEvent
, mSecurityInfoSerialization(securityInfoSerialization)
, mSelfAddr(selfAddr)
, mPeerAddr(peerAddr)
, mCacheKey(cacheKey)
{}
void Run()
@ -344,7 +346,8 @@ class StartRequestEvent : public ChannelEvent
mChild->OnStartRequest(mChannelStatus, mResponseHead, mUseResponseHead,
mRequestHeaders, mIsFromCache, mCacheEntryAvailable,
mCacheExpirationTime, mCachedCharset,
mSecurityInfoSerialization, mSelfAddr, mPeerAddr);
mSecurityInfoSerialization, mSelfAddr, mPeerAddr,
mCacheKey);
}
private:
HttpChannelChild* mChild;
@ -359,6 +362,7 @@ class StartRequestEvent : public ChannelEvent
nsCString mSecurityInfoSerialization;
NetAddr mSelfAddr;
NetAddr mPeerAddr;
HttpChannelCacheKey mCacheKey;
};
bool
@ -373,7 +377,8 @@ HttpChannelChild::RecvOnStartRequest(const nsresult& channelStatus,
const nsCString& securityInfoSerialization,
const NetAddr& selfAddr,
const NetAddr& peerAddr,
const int16_t& redirectCount)
const int16_t& redirectCount,
const HttpChannelCacheKey& cacheKey)
{
LOG(("HttpChannelChild::RecvOnStartRequest [this=%p]\n", this));
// mFlushedForDiversion and mDivertingToParent should NEVER be set at this
@ -392,12 +397,12 @@ HttpChannelChild::RecvOnStartRequest(const nsresult& channelStatus,
isFromCache, cacheEntryAvailable,
cacheExpirationTime, cachedCharset,
securityInfoSerialization, selfAddr,
peerAddr));
peerAddr, cacheKey));
} else {
OnStartRequest(channelStatus, responseHead, useResponseHead, requestHeaders,
isFromCache, cacheEntryAvailable, cacheExpirationTime,
cachedCharset, securityInfoSerialization, selfAddr,
peerAddr);
peerAddr, cacheKey);
}
return true;
}
@ -413,7 +418,8 @@ HttpChannelChild::OnStartRequest(const nsresult& channelStatus,
const nsCString& cachedCharset,
const nsCString& securityInfoSerialization,
const NetAddr& selfAddr,
const NetAddr& peerAddr)
const NetAddr& peerAddr,
const HttpChannelCacheKey& cacheKey)
{
LOG(("HttpChannelChild::OnStartRequest [this=%p]\n", this));
@ -441,6 +447,10 @@ HttpChannelChild::OnStartRequest(const nsresult& channelStatus,
mCacheExpirationTime = cacheExpirationTime;
mCachedCharset = cachedCharset;
nsRefPtr<nsHttpChannelCacheKey> tmpKey = new nsHttpChannelCacheKey();
tmpKey->SetData(cacheKey.postId(), cacheKey.key());
CallQueryInterface(tmpKey.get(), getter_AddRefs(mCacheKey));
AutoEventEnqueuer ensureSerialDispatch(mEventQ);
// replace our request headers with what actually got sent in the parent
@ -1647,6 +1657,20 @@ HttpChannelChild::ContinueAsyncOpen()
openArgs.allowSpdy() = mAllowSpdy;
openArgs.allowAltSvc() = mAllowAltSvc;
if (mCacheKey) {
uint32_t postId;
nsAutoCString key;
nsresult rv = static_cast<nsHttpChannelCacheKey *>(
static_cast<nsISupportsPRUint32 *>(mCacheKey.get()))->GetData(&postId,
key);
if (NS_FAILED(rv)) {
return rv;
}
openArgs.cacheKey() = HttpChannelCacheKey(postId, key);
} else {
openArgs.cacheKey() = mozilla::void_t();
}
propagateLoadInfo(mLoadInfo, openArgs);
// The socket transport in the chrome process now holds a logical ref to us
@ -1789,6 +1813,21 @@ HttpChannelChild::IsFromCache(bool *value)
return NS_OK;
}
NS_IMETHODIMP
HttpChannelChild::GetCacheKey(nsISupports **cacheKey)
{
NS_IF_ADDREF(*cacheKey = mCacheKey);
return NS_OK;
}
NS_IMETHODIMP
HttpChannelChild::SetCacheKey(nsISupports *cacheKey)
{
ENSURE_CALLED_BEFORE_ASYNC_OPEN();
mCacheKey = cacheKey;
return NS_OK;
}
//-----------------------------------------------------------------------------
// HttpChannelChild::nsIResumableChannel
//-----------------------------------------------------------------------------

View File

@ -117,7 +117,8 @@ protected:
const nsCString& securityInfoSerialization,
const NetAddr& selfAddr,
const NetAddr& peerAddr,
const int16_t& redirectCount) override;
const int16_t& redirectCount,
const HttpChannelCacheKey& cacheKey) override;
bool RecvOnTransportAndData(const nsresult& channelStatus,
const nsresult& status,
const uint64_t& progress,
@ -176,6 +177,7 @@ private:
bool mCacheEntryAvailable;
uint32_t mCacheExpirationTime;
nsCString mCachedCharset;
nsCOMPtr<nsISupports> mCacheKey;
// If ResumeAt is called before AsyncOpen, we need to send extra data upstream
bool mSendResumeAt;
@ -208,7 +210,8 @@ private:
const nsCString& cachedCharset,
const nsCString& securityInfoSerialization,
const NetAddr& selfAddr,
const NetAddr& peerAddr);
const NetAddr& peerAddr,
const HttpChannelCacheKey& cacheKey);
void OnTransportAndData(const nsresult& channelStatus,
const nsresult& status,
const uint64_t progress,

View File

@ -113,7 +113,7 @@ HttpChannelParent::Init(const HttpChannelCreationArgs& aArgs)
a.appCacheClientID(), a.allowSpdy(), a.allowAltSvc(), a.fds(),
a.requestingPrincipalInfo(), a.triggeringPrincipalInfo(),
a.securityFlags(), a.contentPolicyType(), a.innerWindowID(),
a.synthesizedResponseHead());
a.synthesizedResponseHead(), a.cacheKey());
}
case HttpChannelCreationArgs::THttpChannelConnectArgs:
{
@ -267,7 +267,8 @@ HttpChannelParent::DoAsyncOpen( const URIParams& aURI,
const uint32_t& aSecurityFlags,
const uint32_t& aContentPolicyType,
const uint32_t& aInnerWindowID,
const OptionalHttpResponseHead& aSynthesizedResponseHead)
const OptionalHttpResponseHead& aSynthesizedResponseHead,
const OptionalHttpChannelCacheKey& aCacheKey)
{
nsCOMPtr<nsIURI> uri = DeserializeURI(aURI);
if (!uri) {
@ -389,6 +390,15 @@ HttpChannelParent::DoAsyncOpen( const URIParams& aURI,
mSynthesizedResponseHead = new nsHttpResponseHead(aSynthesizedResponseHead.get_nsHttpResponseHead());
}
if (aCacheKey.type() == OptionalHttpChannelCacheKey::THttpChannelCacheKey) {
nsRefPtr<nsHttpChannelCacheKey> cacheKey = new nsHttpChannelCacheKey();
cacheKey->SetData(aCacheKey.get_HttpChannelCacheKey().postId(),
aCacheKey.get_HttpChannelCacheKey().key());
nsCOMPtr<nsISupports> cacheKeySupp;
CallQueryInterface(cacheKey.get(), getter_AddRefs(cacheKeySupp));
mChannel->SetCacheKey(cacheKeySupp);
}
if (priority != nsISupportsPriority::PRIORITY_NORMAL) {
mChannel->SetPriority(priority);
}
@ -804,6 +814,21 @@ HttpChannelParent::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
uint16_t redirectCount = 0;
mChannel->GetRedirectCount(&redirectCount);
nsCOMPtr<nsISupports> cacheKeySupp;
mChannel->GetCacheKey(getter_AddRefs(cacheKeySupp));
uint32_t postId = 0;
nsAutoCString key;
if (cacheKeySupp) {
nsresult rv = static_cast<nsHttpChannelCacheKey *>(
static_cast<nsISupportsPRUint32 *>(cacheKeySupp.get()))->GetData(&postId,
key);
if (NS_FAILED(rv)) {
return rv;
}
}
HttpChannelCacheKey cacheKey = HttpChannelCacheKey(postId, key);
if (mIPCClosed ||
!SendOnStartRequest(channelStatus,
responseHead ? *responseHead : nsHttpResponseHead(),
@ -813,7 +838,8 @@ HttpChannelParent::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
mCacheEntry ? true : false,
expirationTime, cachedCharset, secInfoSerialization,
mChannel->GetSelfAddr(), mChannel->GetPeerAddr(),
redirectCount))
redirectCount,
cacheKey))
{
return NS_ERROR_UNEXPECTED;
}

View File

@ -121,7 +121,8 @@ protected:
const uint32_t& aSecurityFlags,
const uint32_t& aContentPolicyType,
const uint32_t& aInnerWindowID,
const OptionalHttpResponseHead& aSynthesizedResponseHead);
const OptionalHttpResponseHead& aSynthesizedResponseHead,
const OptionalHttpChannelCacheKey& aCacheKey);
virtual bool RecvSetPriority(const uint16_t& priority) override;
virtual bool RecvSetClassOfService(const uint32_t& cos) override;

View File

@ -8,15 +8,13 @@
include protocol PNecko;
include InputStreamParams;
include URIParams;
include NeckoChannelParams;
include protocol PBlob; //FIXME: bug #792908
include "mozilla/net/NeckoMessageUtils.h";
using RequestHeaderTuples from "mozilla/net/PHttpChannelParams.h";
using class nsHttpHeaderArray from "nsHttpHeaderArray.h";
using class nsHttpResponseHead from "nsHttpResponseHead.h";
using struct nsHttpAtom from "nsHttp.h";
using mozilla::net::NetAddr from "mozilla/net/DNS.h";
using struct mozilla::net::ResourceTimingStruct from "mozilla/net/TimingStruct.h";
@ -93,7 +91,8 @@ child:
nsCString securityInfoSerialization,
NetAddr selfAddr,
NetAddr peerAddr,
int16_t redirectCount);
int16_t redirectCount,
HttpChannelCacheKey cacheKey);
// Combines a single OnDataAvailable and its associated OnProgress &
// OnStatus calls into one IPDL message

View File

@ -6037,35 +6037,6 @@ nsHttpChannel::SetOfflineCacheToken(nsISupports *token)
return NS_ERROR_NOT_IMPLEMENTED;
}
class nsHttpChannelCacheKey final : public nsISupportsPRUint32,
public nsISupportsCString
{
NS_DECL_ISUPPORTS
NS_DECL_NSISUPPORTSPRIMITIVE
NS_FORWARD_NSISUPPORTSPRUINT32(mSupportsPRUint32->)
// Both interfaces declares toString method with the same signature.
// Thus we have to delegate only to nsISupportsPRUint32 implementation.
NS_IMETHOD GetData(nsACString & aData) override
{
return mSupportsCString->GetData(aData);
}
NS_IMETHOD SetData(const nsACString & aData) override
{
return mSupportsCString->SetData(aData);
}
public:
nsresult SetData(uint32_t aPostID, const nsACString& aKey);
protected:
~nsHttpChannelCacheKey() {}
nsCOMPtr<nsISupportsPRUint32> mSupportsPRUint32;
nsCOMPtr<nsISupportsCString> mSupportsCString;
};
NS_IMPL_ADDREF(nsHttpChannelCacheKey)
NS_IMPL_RELEASE(nsHttpChannelCacheKey)
NS_INTERFACE_TABLE_HEAD(nsHttpChannelCacheKey)
@ -6111,6 +6082,19 @@ nsresult nsHttpChannelCacheKey::SetData(uint32_t aPostID,
return NS_OK;
}
nsresult nsHttpChannelCacheKey::GetData(uint32_t *aPostID,
nsACString& aKey)
{
nsresult rv;
rv = mSupportsPRUint32->GetData(aPostID);
if (NS_FAILED(rv)) {
return rv;
}
return mSupportsCString->GetData(aKey);
}
NS_IMETHODIMP
nsHttpChannel::GetCacheKey(nsISupports **key)
{

View File

@ -40,6 +40,40 @@ public:
const nsAString& aMessageCategory) = 0;
};
//-----------------------------------------------------------------------------
// nsHttpChannelCacheKey
//-----------------------------------------------------------------------------
class nsHttpChannelCacheKey final : public nsISupportsPRUint32,
public nsISupportsCString
{
NS_DECL_ISUPPORTS
NS_DECL_NSISUPPORTSPRIMITIVE
NS_FORWARD_NSISUPPORTSPRUINT32(mSupportsPRUint32->)
// Both interfaces declares toString method with the same signature.
// Thus we have to delegate only to nsISupportsPRUint32 implementation.
NS_IMETHOD GetData(nsACString & aData) override
{
return mSupportsCString->GetData(aData);
}
NS_IMETHOD SetData(const nsACString & aData) override
{
return mSupportsCString->SetData(aData);
}
public:
nsresult SetData(uint32_t aPostID, const nsACString& aKey);
nsresult GetData(uint32_t *aPostID, nsACString& aKey);
protected:
~nsHttpChannelCacheKey() {}
nsCOMPtr<nsISupportsPRUint32> mSupportsPRUint32;
nsCOMPtr<nsISupportsCString> mSupportsCString;
};
//-----------------------------------------------------------------------------
// nsHttpChannel
//-----------------------------------------------------------------------------

View File

@ -25,6 +25,7 @@ NS_INTERFACE_MAP_BEGIN(nsViewSourceChannel)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannel, mHttpChannel)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIHttpChannelInternal, mHttpChannelInternal)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsICachingChannel, mCachingChannel)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsICacheInfoChannel, mCacheInfoChannel)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIApplicationCacheChannel, mApplicationCacheChannel)
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIUploadChannel, mUploadChannel)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIRequest, nsIViewSourceChannel)
@ -80,6 +81,7 @@ nsViewSourceChannel::Init(nsIURI* uri)
mHttpChannel = do_QueryInterface(mChannel);
mHttpChannelInternal = do_QueryInterface(mChannel);
mCachingChannel = do_QueryInterface(mChannel);
mCacheInfoChannel = do_QueryInterface(mChannel);
mApplicationCacheChannel = do_QueryInterface(mChannel);
mUploadChannel = do_QueryInterface(mChannel);
@ -117,6 +119,7 @@ nsViewSourceChannel::InitSrcdoc(nsIURI* aURI, const nsAString &aSrcdoc)
mHttpChannel = do_QueryInterface(mChannel);
mHttpChannelInternal = do_QueryInterface(mChannel);
mCachingChannel = do_QueryInterface(mChannel);
mCacheInfoChannel = do_QueryInterface(mChannel);
mApplicationCacheChannel = do_QueryInterface(mChannel);
mUploadChannel = do_QueryInterface(mChannel);
return NS_OK;
@ -544,6 +547,7 @@ nsViewSourceChannel::OnStartRequest(nsIRequest *aRequest, nsISupports *aContext)
mChannel = do_QueryInterface(aRequest);
mHttpChannel = do_QueryInterface(aRequest);
mCachingChannel = do_QueryInterface(aRequest);
mCacheInfoChannel = do_QueryInterface(mChannel);
mUploadChannel = do_QueryInterface(aRequest);
return mListener->OnStartRequest(static_cast<nsIViewSourceChannel*>

View File

@ -35,7 +35,7 @@ public:
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSIHTTPCHANNEL
NS_FORWARD_SAFE_NSICACHEINFOCHANNEL(mCachingChannel)
NS_FORWARD_SAFE_NSICACHEINFOCHANNEL(mCacheInfoChannel)
NS_FORWARD_SAFE_NSICACHINGCHANNEL(mCachingChannel)
NS_FORWARD_SAFE_NSIAPPLICATIONCACHECHANNEL(mApplicationCacheChannel)
NS_FORWARD_SAFE_NSIAPPLICATIONCACHECONTAINER(mApplicationCacheChannel)
@ -58,6 +58,7 @@ protected:
nsCOMPtr<nsIHttpChannel> mHttpChannel;
nsCOMPtr<nsIHttpChannelInternal> mHttpChannelInternal;
nsCOMPtr<nsICachingChannel> mCachingChannel;
nsCOMPtr<nsICacheInfoChannel> mCacheInfoChannel;
nsCOMPtr<nsIApplicationCacheChannel> mApplicationCacheChannel;
nsCOMPtr<nsIUploadChannel> mUploadChannel;
nsCOMPtr<nsIStreamListener> mListener;