зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1487113 - nsICacheInfoChannel.preferAlternativeDataType() should expose alt-data as optional if required, r=valentin
Differential Revision: https://phabricator.services.mozilla.com/D20200 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
1951a6690b
Коммит
64d3f6f9da
|
@ -34,6 +34,7 @@
|
|||
#include "mozilla/dom/File.h"
|
||||
#include "mozilla/dom/PerformanceStorage.h"
|
||||
#include "mozilla/dom/WorkerCommon.h"
|
||||
#include "mozilla/net/NeckoChannelParams.h"
|
||||
#include "mozilla/EventStateManager.h"
|
||||
#include "mozilla/ipc/PBackgroundSharedTypes.h"
|
||||
#include "mozilla/Unused.h"
|
||||
|
@ -699,7 +700,7 @@ nsresult FetchDriver::HttpFetch(
|
|||
nsCOMPtr<nsICacheInfoChannel> cic = do_QueryInterface(chan);
|
||||
if (cic) {
|
||||
cic->PreferAlternativeDataType(aPreferredAlternativeDataType,
|
||||
EmptyCString());
|
||||
EmptyCString(), true);
|
||||
MOZ_ASSERT(!mAltDataListener);
|
||||
mAltDataListener = new AlternativeDataStreamListener(
|
||||
this, chan, aPreferredAlternativeDataType);
|
||||
|
@ -714,7 +715,7 @@ nsresult FetchDriver::HttpFetch(
|
|||
if (cic) {
|
||||
cic->PreferAlternativeDataType(
|
||||
NS_LITERAL_CSTRING(WASM_ALT_DATA_TYPE_V1),
|
||||
NS_LITERAL_CSTRING(WASM_CONTENT_TYPE));
|
||||
NS_LITERAL_CSTRING(WASM_CONTENT_TYPE), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -947,10 +948,11 @@ FetchDriver::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext) {
|
|||
}
|
||||
} else if (!cic->PreferredAlternativeDataTypes().IsEmpty()) {
|
||||
MOZ_ASSERT(cic->PreferredAlternativeDataTypes().Length() == 1);
|
||||
MOZ_ASSERT(Get<0>(cic->PreferredAlternativeDataTypes()[0])
|
||||
.EqualsLiteral(WASM_ALT_DATA_TYPE_V1));
|
||||
MOZ_ASSERT(Get<1>(cic->PreferredAlternativeDataTypes()[0])
|
||||
.EqualsLiteral(WASM_CONTENT_TYPE));
|
||||
MOZ_ASSERT(cic->PreferredAlternativeDataTypes()[0].type().EqualsLiteral(
|
||||
WASM_ALT_DATA_TYPE_V1));
|
||||
MOZ_ASSERT(
|
||||
cic->PreferredAlternativeDataTypes()[0].contentType().EqualsLiteral(
|
||||
WASM_CONTENT_TYPE));
|
||||
|
||||
if (contentType.EqualsLiteral(WASM_CONTENT_TYPE)) {
|
||||
// We want to attach the CacheInfoChannel to the response object such
|
||||
|
|
|
@ -1293,7 +1293,7 @@ nsresult ScriptLoader::StartLoad(ScriptLoadRequest* aRequest) {
|
|||
// registered.
|
||||
LOG(("ScriptLoadRequest (%p): Maybe request bytecode", aRequest));
|
||||
cic->PreferAlternativeDataType(nsContentUtils::JSBytecodeMimeType(),
|
||||
EmptyCString());
|
||||
EmptyCString(), true);
|
||||
} else {
|
||||
// If we are explicitly loading from the sources, such as after a
|
||||
// restarted request, we might still want to save the bytecode after.
|
||||
|
@ -1302,7 +1302,7 @@ nsresult ScriptLoader::StartLoad(ScriptLoadRequest* aRequest) {
|
|||
// does not exist, such that we can later save the bytecode with a
|
||||
// different alternative data type.
|
||||
LOG(("ScriptLoadRequest (%p): Request saving bytecode later", aRequest));
|
||||
cic->PreferAlternativeDataType(kNullMimeType, EmptyCString());
|
||||
cic->PreferAlternativeDataType(kNullMimeType, EmptyCString(), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "mozilla/dom/Response.h"
|
||||
#include "mozilla/dom/WorkerScope.h"
|
||||
#include "mozilla/dom/WorkerPrivate.h"
|
||||
#include "mozilla/net/NeckoChannelParams.h"
|
||||
|
||||
#include "js/Conversions.h"
|
||||
#include "js/TypeDecls.h"
|
||||
|
@ -319,7 +320,7 @@ class StartResponse final : public Runnable {
|
|||
!outerChannel->PreferredAlternativeDataTypes().IsEmpty()) {
|
||||
// TODO: handle multiple types properly.
|
||||
preferredAltDataType.Assign(
|
||||
mozilla::Get<0>(outerChannel->PreferredAlternativeDataTypes()[0]));
|
||||
outerChannel->PreferredAlternativeDataTypes()[0].type());
|
||||
}
|
||||
|
||||
// Get the alternative data type saved in the InternalResponse
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include "mozilla/dom/WorkerRunnable.h"
|
||||
#include "mozilla/dom/WorkerScope.h"
|
||||
#include "mozilla/dom/ipc/StructuredCloneData.h"
|
||||
#include "mozilla/net/NeckoChannelParams.h"
|
||||
#include "mozilla/StaticPrefs.h"
|
||||
#include "mozilla/Unused.h"
|
||||
|
||||
|
@ -1444,7 +1445,7 @@ class FetchEventRunnable : public ExtendableFunctionalEventWorkerRunnable,
|
|||
// TODO: the internal request probably needs all the preferred types.
|
||||
nsAutoCString alternativeDataType;
|
||||
alternativeDataType.Assign(
|
||||
mozilla::Get<0>(cic->PreferredAlternativeDataTypes()[0]));
|
||||
cic->PreferredAlternativeDataTypes()[0].type());
|
||||
internalReq->SetPreferredAlternativeDataType(alternativeDataType);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,11 +9,13 @@ interface nsIInputStream;
|
|||
|
||||
%{C++
|
||||
namespace mozilla {
|
||||
template<typename... Elements> class Tuple;
|
||||
namespace net {
|
||||
class PreferredAlternativeDataTypeParams;
|
||||
}
|
||||
} // namespace mozilla
|
||||
%}
|
||||
|
||||
[ref] native ConstPreferenceArray(const nsTArray<mozilla::Tuple<nsCString, nsCString>>);
|
||||
[ref] native ConstPreferredAlternativeDataTypeArray(const nsTArray<mozilla::net::PreferredAlternativeDataTypeParams>);
|
||||
|
||||
[scriptable, uuid(1fb8ccf2-5fa5-45ec-bc57-8c8022a5d0d3)]
|
||||
interface nsIInputStreamReceiver : nsISupports
|
||||
|
@ -99,12 +101,16 @@ interface nsICacheInfoChannel : nsISupports
|
|||
* @param contentType
|
||||
* the contentType for which the preference applies.
|
||||
* an empty contentType means the preference applies for ANY contentType
|
||||
* @param deliverAltData
|
||||
* if false, also if alt-data is available, the channel will deliver
|
||||
* the original data.
|
||||
*
|
||||
* The method may be called several times, with different type and contentType.
|
||||
*
|
||||
* Must be called before AsyncOpen.
|
||||
*/
|
||||
void preferAlternativeDataType(in ACString type, in ACString contentType);
|
||||
void preferAlternativeDataType(in ACString type, in ACString contentType,
|
||||
in boolean deliverAltData);
|
||||
|
||||
/**
|
||||
* Get the preferred alternative data type set by preferAlternativeDataType().
|
||||
|
@ -112,7 +118,7 @@ interface nsICacheInfoChannel : nsISupports
|
|||
* information retrieved from the network stack.
|
||||
*/
|
||||
[noscript, notxpcom, nostdcall]
|
||||
ConstPreferenceArray preferredAlternativeDataTypes();
|
||||
ConstPreferredAlternativeDataTypeArray preferredAlternativeDataTypes();
|
||||
|
||||
/**
|
||||
* Holds the type of the alternative data representation that the channel
|
||||
|
@ -123,6 +129,14 @@ interface nsICacheInfoChannel : nsISupports
|
|||
*/
|
||||
readonly attribute ACString alternativeDataType;
|
||||
|
||||
/**
|
||||
* If preferAlternativeDataType() has been called passing deliverAltData
|
||||
* equal to false, this method will expose the alt-data inputStream if
|
||||
* aviable.
|
||||
*/
|
||||
void getAltDataInputStream(in ACString type,
|
||||
in nsIInputStreamReceiver aReceiver);
|
||||
|
||||
/**
|
||||
* Sometimes when the channel is delivering alt-data, we may want to somehow
|
||||
* access the original content too. This method asynchronously opens the
|
||||
|
|
|
@ -19,7 +19,6 @@ include DOMTypes;
|
|||
using mozilla::OriginAttributes from "mozilla/ipc/BackgroundUtils.h";
|
||||
using struct mozilla::void_t from "ipc/IPCMessageUtils.h";
|
||||
using RequestHeaderTuples from "mozilla/net/PHttpChannelParams.h";
|
||||
using ArrayOfStringPairs from "mozilla/net/PHttpChannelParams.h";
|
||||
using struct nsHttpAtom from "nsHttp.h";
|
||||
using class mozilla::net::nsHttpResponseHead from "nsHttpResponseHead.h";
|
||||
using class mozilla::TimeStamp from "mozilla/TimeStamp.h";
|
||||
|
@ -28,6 +27,17 @@ using nsILoadInfo::CrossOriginOpenerPolicy from "ipc/IPCMessageUtils.h";
|
|||
namespace mozilla {
|
||||
namespace net {
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Preferrer alternative data type
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct PreferredAlternativeDataTypeParams
|
||||
{
|
||||
nsCString type;
|
||||
nsCString contentType;
|
||||
bool deliverAltData;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// LoadInfo IPDL structs
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -250,7 +260,7 @@ struct HttpChannelOpenArgs
|
|||
uint64_t channelId;
|
||||
nsString integrityMetadata;
|
||||
uint64_t contentWindowId;
|
||||
ArrayOfStringPairs preferredAlternativeTypes;
|
||||
PreferredAlternativeDataTypeParams[] preferredAlternativeTypes;
|
||||
uint64_t topLevelOuterContentWindowId;
|
||||
TimeStamp launchServiceWorkerStart;
|
||||
TimeStamp launchServiceWorkerEnd;
|
||||
|
|
|
@ -3762,9 +3762,9 @@ nsresult HttpBaseChannel::SetupReplacementChannel(nsIURI* newURI,
|
|||
// Pass the preferred alt-data type on to the new channel.
|
||||
nsCOMPtr<nsICacheInfoChannel> cacheInfoChan(do_QueryInterface(newChannel));
|
||||
if (cacheInfoChan) {
|
||||
for (auto& pair : mPreferredCachedAltDataTypes) {
|
||||
cacheInfoChan->PreferAlternativeDataType(mozilla::Get<0>(pair),
|
||||
mozilla::Get<1>(pair));
|
||||
for (auto& data : mPreferredCachedAltDataTypes) {
|
||||
cacheInfoChan->PreferAlternativeDataType(data.type(), data.contentType(),
|
||||
data.deliverAltData());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ class LogCollector;
|
|||
namespace net {
|
||||
extern mozilla::LazyLogModule gHttpLog;
|
||||
|
||||
typedef nsTArray<Tuple<nsCString, nsCString>> ArrayOfStringPairs;
|
||||
class PreferredAlternativeDataTypeParams;
|
||||
|
||||
enum CacheDisposition : uint8_t {
|
||||
kCacheUnresolved = 0,
|
||||
|
@ -580,7 +580,7 @@ class HttpBaseChannel : public nsHashPropertyBag,
|
|||
// the HTML file.
|
||||
nsString mInitiatorType;
|
||||
// Holds the name of the preferred alt-data type for each contentType.
|
||||
ArrayOfStringPairs mPreferredCachedAltDataTypes;
|
||||
nsTArray<PreferredAlternativeDataTypeParams> mPreferredCachedAltDataTypes;
|
||||
// Holds the name of the alternative data type the channel returned.
|
||||
nsCString mAvailableCachedAltDataType;
|
||||
nsString mIntegrityMetadata;
|
||||
|
|
|
@ -3029,20 +3029,21 @@ HttpChannelChild::GetAllowStaleCacheContent(bool* aAllowStaleCacheContent) {
|
|||
|
||||
NS_IMETHODIMP
|
||||
HttpChannelChild::PreferAlternativeDataType(const nsACString& aType,
|
||||
const nsACString& aContentType) {
|
||||
const nsACString& aContentType,
|
||||
bool aDeliverAltData) {
|
||||
ENSURE_CALLED_BEFORE_ASYNC_OPEN();
|
||||
|
||||
if (mSynthesizedCacheInfo) {
|
||||
return mSynthesizedCacheInfo->PreferAlternativeDataType(aType,
|
||||
aContentType);
|
||||
return mSynthesizedCacheInfo->PreferAlternativeDataType(aType, aContentType,
|
||||
aDeliverAltData);
|
||||
}
|
||||
|
||||
mPreferredCachedAltDataTypes.AppendElement(
|
||||
MakePair(nsCString(aType), nsCString(aContentType)));
|
||||
mPreferredCachedAltDataTypes.AppendElement(PreferredAlternativeDataTypeParams(
|
||||
nsCString(aType), nsCString(aContentType), aDeliverAltData));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
const nsTArray<mozilla::Tuple<nsCString, nsCString>>&
|
||||
const nsTArray<PreferredAlternativeDataTypeParams>&
|
||||
HttpChannelChild::PreferredAlternativeDataTypes() {
|
||||
return mPreferredCachedAltDataTypes;
|
||||
}
|
||||
|
@ -3107,17 +3108,46 @@ HttpChannelChild::GetOriginalInputStream(nsIInputStreamReceiver* aReceiver) {
|
|||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
mInputStreamReceiver = aReceiver;
|
||||
mOriginalInputStreamReceiver = aReceiver;
|
||||
Unused << SendOpenOriginalCacheInputStream();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
HttpChannelChild::GetAltDataInputStream(const nsACString& aType,
|
||||
nsIInputStreamReceiver* aReceiver) {
|
||||
if (aReceiver == nullptr) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (!mIPCOpen) {
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
mAltDataInputStreamReceiver = aReceiver;
|
||||
Unused << SendOpenAltDataCacheInputStream(nsCString(aType));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult HttpChannelChild::RecvOriginalCacheInputStreamAvailable(
|
||||
const OptionalIPCStream& aStream) {
|
||||
nsCOMPtr<nsIInputStream> stream = DeserializeIPCStream(aStream);
|
||||
nsCOMPtr<nsIInputStreamReceiver> receiver;
|
||||
receiver.swap(mInputStreamReceiver);
|
||||
receiver.swap(mOriginalInputStreamReceiver);
|
||||
if (receiver) {
|
||||
receiver->OnInputStreamReady(stream);
|
||||
}
|
||||
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult HttpChannelChild::RecvAltDataCacheInputStreamAvailable(
|
||||
const OptionalIPCStream& aStream) {
|
||||
nsCOMPtr<nsIInputStream> stream = DeserializeIPCStream(aStream);
|
||||
nsCOMPtr<nsIInputStreamReceiver> receiver;
|
||||
receiver.swap(mAltDataInputStreamReceiver);
|
||||
if (receiver) {
|
||||
receiver->OnInputStreamReady(stream);
|
||||
}
|
||||
|
|
|
@ -178,6 +178,9 @@ class HttpChannelChild final : public PHttpChannelChild,
|
|||
mozilla::ipc::IPCResult RecvOriginalCacheInputStreamAvailable(
|
||||
const OptionalIPCStream& aStream) override;
|
||||
|
||||
mozilla::ipc::IPCResult RecvAltDataCacheInputStreamAvailable(
|
||||
const OptionalIPCStream& aStream) override;
|
||||
|
||||
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
|
||||
|
||||
virtual void DoNotifyListenerCleanup() override;
|
||||
|
@ -338,7 +341,8 @@ class HttpChannelChild final : public PHttpChannelChild,
|
|||
nsCOMPtr<nsICacheInfoChannel> mSynthesizedCacheInfo;
|
||||
RefPtr<ChannelEventQueue> mEventQ;
|
||||
|
||||
nsCOMPtr<nsIInputStreamReceiver> mInputStreamReceiver;
|
||||
nsCOMPtr<nsIInputStreamReceiver> mOriginalInputStreamReceiver;
|
||||
nsCOMPtr<nsIInputStreamReceiver> mAltDataInputStreamReceiver;
|
||||
|
||||
// Used to ensure atomicity of mBgChild and mBgInitFailCallback
|
||||
Mutex mBgChildMutex;
|
||||
|
|
|
@ -405,7 +405,8 @@ bool HttpChannelParent::DoAsyncOpen(
|
|||
const uint32_t& aCorsMode, const uint32_t& aRedirectMode,
|
||||
const uint64_t& aChannelId, const nsString& aIntegrityMetadata,
|
||||
const uint64_t& aContentWindowId,
|
||||
const ArrayOfStringPairs& aPreferredAlternativeTypes,
|
||||
const nsTArray<PreferredAlternativeDataTypeParams>&
|
||||
aPreferredAlternativeTypes,
|
||||
const uint64_t& aTopLevelOuterContentWindowId,
|
||||
const TimeStamp& aLaunchServiceWorkerStart,
|
||||
const TimeStamp& aLaunchServiceWorkerEnd,
|
||||
|
@ -570,9 +571,9 @@ bool HttpChannelParent::DoAsyncOpen(
|
|||
do_QueryInterface(static_cast<nsIChannel*>(httpChannel.get()));
|
||||
if (cacheChannel) {
|
||||
cacheChannel->SetCacheKey(aCacheKey);
|
||||
for (auto& pair : aPreferredAlternativeTypes) {
|
||||
cacheChannel->PreferAlternativeDataType(mozilla::Get<0>(pair),
|
||||
mozilla::Get<1>(pair));
|
||||
for (auto& data : aPreferredAlternativeTypes) {
|
||||
cacheChannel->PreferAlternativeDataType(data.type(), data.contentType(),
|
||||
data.deliverAltData());
|
||||
}
|
||||
|
||||
cacheChannel->SetAllowStaleCacheContent(aAllowStaleCacheContent);
|
||||
|
@ -1704,6 +1705,28 @@ mozilla::ipc::IPCResult HttpChannelParent::RecvOpenOriginalCacheInputStream() {
|
|||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult HttpChannelParent::RecvOpenAltDataCacheInputStream(
|
||||
const nsCString& aType) {
|
||||
if (mIPCClosed) {
|
||||
return IPC_OK();
|
||||
}
|
||||
AutoIPCStream autoStream;
|
||||
if (mCacheEntry) {
|
||||
nsCOMPtr<nsIInputStream> inputStream;
|
||||
nsresult rv = mCacheEntry->OpenAlternativeInputStream(
|
||||
aType, getter_AddRefs(inputStream));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
PContentParent* pcp = Manager()->Manager();
|
||||
Unused << autoStream.Serialize(inputStream,
|
||||
static_cast<ContentParent*>(pcp));
|
||||
}
|
||||
}
|
||||
|
||||
Unused << SendAltDataCacheInputStreamAvailable(
|
||||
autoStream.TakeOptionalValue());
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// HttpChannelParent::nsIProgressEventSink
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
@ -163,7 +163,8 @@ class HttpChannelParent final : public nsIInterfaceRequestor,
|
|||
const uint32_t& aCorsMode, const uint32_t& aRedirectMode,
|
||||
const uint64_t& aChannelId, const nsString& aIntegrityMetadata,
|
||||
const uint64_t& aContentWindowId,
|
||||
const ArrayOfStringPairs& aPreferredAlternativeTypes,
|
||||
const nsTArray<PreferredAlternativeDataTypeParams>&
|
||||
aPreferredAlternativeTypes,
|
||||
const uint64_t& aTopLevelOuterContentWindowId,
|
||||
const TimeStamp& aLaunchServiceWorkerStart,
|
||||
const TimeStamp& aLaunchServiceWorkerEnd,
|
||||
|
@ -207,6 +208,8 @@ class HttpChannelParent final : public nsIInterfaceRequestor,
|
|||
const mozilla::ipc::PrincipalInfo& requestingPrincipal) override;
|
||||
virtual mozilla::ipc::IPCResult RecvBytesRead(const int32_t& aCount) override;
|
||||
virtual mozilla::ipc::IPCResult RecvOpenOriginalCacheInputStream() override;
|
||||
virtual mozilla::ipc::IPCResult RecvOpenAltDataCacheInputStream(
|
||||
const nsCString& aType) override;
|
||||
virtual void ActorDestroy(ActorDestroyReason why) override;
|
||||
|
||||
// Supporting function for ADivertableParentChannel.
|
||||
|
|
|
@ -1245,14 +1245,15 @@ InterceptedHttpChannel::GetAllowStaleCacheContent(
|
|||
|
||||
NS_IMETHODIMP
|
||||
InterceptedHttpChannel::PreferAlternativeDataType(
|
||||
const nsACString& aType, const nsACString& aContentType) {
|
||||
const nsACString& aType, const nsACString& aContentType,
|
||||
bool aDeliverAltData) {
|
||||
ENSURE_CALLED_BEFORE_ASYNC_OPEN();
|
||||
mPreferredCachedAltDataTypes.AppendElement(
|
||||
MakePair(nsCString(aType), nsCString(aContentType)));
|
||||
mPreferredCachedAltDataTypes.AppendElement(PreferredAlternativeDataTypeParams(
|
||||
nsCString(aType), nsCString(aContentType), aDeliverAltData));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
const nsTArray<mozilla::Tuple<nsCString, nsCString>>&
|
||||
const nsTArray<PreferredAlternativeDataTypeParams>&
|
||||
InterceptedHttpChannel::PreferredAlternativeDataTypes() {
|
||||
return mPreferredCachedAltDataTypes;
|
||||
}
|
||||
|
@ -1285,6 +1286,15 @@ InterceptedHttpChannel::GetOriginalInputStream(
|
|||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InterceptedHttpChannel::GetAltDataInputStream(
|
||||
const nsACString& aType, nsIInputStreamReceiver* aReceiver) {
|
||||
if (mSynthesizedCacheInfo) {
|
||||
return mSynthesizedCacheInfo->GetAltDataInputStream(aType, aReceiver);
|
||||
}
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InterceptedHttpChannel::GetCacheKey(uint32_t* key) {
|
||||
if (mSynthesizedCacheInfo) {
|
||||
|
|
|
@ -97,6 +97,9 @@ parent:
|
|||
// Called to get the input stream when altData was delivered.
|
||||
async OpenOriginalCacheInputStream();
|
||||
|
||||
// Called to get the input stream when altData is available.
|
||||
async OpenAltDataCacheInputStream(nsCString aType);
|
||||
|
||||
// Tell the parent the amount bytes read by child for the e10s back pressure
|
||||
// flow control
|
||||
async BytesRead(int32_t count);
|
||||
|
@ -180,6 +183,9 @@ child:
|
|||
async CancelDiversion();
|
||||
|
||||
async OriginalCacheInputStreamAvailable(OptionalIPCStream stream);
|
||||
|
||||
async AltDataCacheInputStreamAvailable(OptionalIPCStream stream);
|
||||
|
||||
both:
|
||||
// After receiving this message, the parent also calls
|
||||
// SendFinishInterceptedRedirect, and makes sure not to send any more messages
|
||||
|
|
|
@ -35,8 +35,6 @@ struct RequestHeaderTuple {
|
|||
|
||||
typedef nsTArray<RequestHeaderTuple> RequestHeaderTuples;
|
||||
|
||||
typedef nsTArray<Tuple<nsCString, nsCString>> ArrayOfStringPairs;
|
||||
|
||||
} // namespace net
|
||||
} // namespace mozilla
|
||||
|
||||
|
|
|
@ -122,6 +122,7 @@
|
|||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/ServiceWorkerUtils.h"
|
||||
#include "mozilla/net/AsyncUrlChannelClassifier.h"
|
||||
#include "mozilla/net/NeckoChannelParams.h"
|
||||
#include "mozilla/net/UrlClassifierFeatureFactory.h"
|
||||
#include "nsIWebNavigation.h"
|
||||
|
||||
|
@ -4904,27 +4905,33 @@ nsresult nsHttpChannel::OpenCacheInputStream(nsICacheEntry *cacheEntry,
|
|||
mCachedResponseHead->ContentType(contentType);
|
||||
|
||||
bool foundAltData = false;
|
||||
bool deliverAltData = true;
|
||||
if (!altDataType.IsEmpty() && !mPreferredCachedAltDataTypes.IsEmpty() &&
|
||||
altDataFromChild == mAltDataForChild) {
|
||||
for (auto &pref : mPreferredCachedAltDataTypes) {
|
||||
if (mozilla::Get<0>(pref) == altDataType &&
|
||||
(mozilla::Get<1>(pref).IsEmpty() ||
|
||||
mozilla::Get<1>(pref) == contentType)) {
|
||||
if (pref.type() == altDataType &&
|
||||
(pref.contentType().IsEmpty() || pref.contentType() == contentType)) {
|
||||
foundAltData = true;
|
||||
deliverAltData = pref.deliverAltData();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIInputStream> altData;
|
||||
int64_t altDataSize;
|
||||
if (foundAltData) {
|
||||
rv = cacheEntry->OpenAlternativeInputStream(altDataType,
|
||||
getter_AddRefs(stream));
|
||||
getter_AddRefs(altData));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
LOG(("Opened alt-data input stream type=%s", altDataType.get()));
|
||||
// We have succeeded.
|
||||
mAvailableCachedAltDataType = altDataType;
|
||||
// Set the correct data size on the channel.
|
||||
int64_t altDataSize;
|
||||
if (NS_SUCCEEDED(cacheEntry->GetAltDataSize(&altDataSize))) {
|
||||
|
||||
if (deliverAltData) {
|
||||
// Set the correct data size on the channel.
|
||||
Unused << cacheEntry->GetAltDataSize(&altDataSize);
|
||||
stream = altData;
|
||||
mAltDataLength = altDataSize;
|
||||
}
|
||||
}
|
||||
|
@ -8341,14 +8348,15 @@ nsHttpChannel::GetAllowStaleCacheContent(bool *aAllowStaleCacheContent) {
|
|||
|
||||
NS_IMETHODIMP
|
||||
nsHttpChannel::PreferAlternativeDataType(const nsACString &aType,
|
||||
const nsACString &aContentType) {
|
||||
const nsACString &aContentType,
|
||||
bool aDeliverAltData) {
|
||||
ENSURE_CALLED_BEFORE_ASYNC_OPEN();
|
||||
mPreferredCachedAltDataTypes.AppendElement(
|
||||
MakePair(nsCString(aType), nsCString(aContentType)));
|
||||
mPreferredCachedAltDataTypes.AppendElement(PreferredAlternativeDataTypeParams(
|
||||
nsCString(aType), nsCString(aContentType), aDeliverAltData));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
const nsTArray<mozilla::Tuple<nsCString, nsCString>>
|
||||
const nsTArray<PreferredAlternativeDataTypeParams>
|
||||
&nsHttpChannel::PreferredAlternativeDataTypes() {
|
||||
return mPreferredCachedAltDataTypes;
|
||||
}
|
||||
|
@ -8400,6 +8408,26 @@ nsHttpChannel::GetOriginalInputStream(nsIInputStreamReceiver *aReceiver) {
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHttpChannel::GetAltDataInputStream(const nsACString &aType,
|
||||
nsIInputStreamReceiver *aReceiver) {
|
||||
if (aReceiver == nullptr) {
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
nsCOMPtr<nsIInputStream> inputStream;
|
||||
|
||||
nsCOMPtr<nsICacheEntry> cacheEntry =
|
||||
mCacheEntry ? mCacheEntry : mAltDataCacheEntry;
|
||||
if (cacheEntry) {
|
||||
nsresult rv = cacheEntry->OpenAlternativeInputStream(
|
||||
aType, getter_AddRefs(inputStream));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
aReceiver->OnInputStreamReady(inputStream);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// nsHttpChannel::nsICachingChannel
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
@ -19,3 +19,5 @@ FINAL_LIBRARY = 'xul'
|
|||
LOCAL_INCLUDES += [
|
||||
'/netwerk/base',
|
||||
]
|
||||
|
||||
include('/ipc/chromium/chromium-config.mozbuild')
|
||||
|
|
|
@ -1045,7 +1045,7 @@ nsViewSourceChannel::LogMimeTypeMismatch(const nsACString &aMessageName,
|
|||
aContentType);
|
||||
}
|
||||
|
||||
const nsTArray<mozilla::Tuple<nsCString, nsCString>>
|
||||
const nsTArray<mozilla::net::PreferredAlternativeDataTypeParams>
|
||||
&nsViewSourceChannel::PreferredAlternativeDataTypes() {
|
||||
if (mCacheInfoChannel) {
|
||||
return mCacheInfoChannel->PreferredAlternativeDataTypes();
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "nsIApplicationCacheChannel.h"
|
||||
#include "nsIFormPOSTActionChannel.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/net/NeckoChannelParams.h"
|
||||
|
||||
class nsViewSourceChannel final : public nsIViewSourceChannel,
|
||||
public nsIStreamListener,
|
||||
|
@ -60,7 +61,7 @@ class nsViewSourceChannel final : public nsIViewSourceChannel,
|
|||
|
||||
protected:
|
||||
~nsViewSourceChannel() = default;
|
||||
nsTArray<mozilla::Tuple<nsCString, nsCString>> mEmptyArray;
|
||||
nsTArray<mozilla::net::PreferredAlternativeDataTypeParams> mEmptyArray;
|
||||
|
||||
// Clones aURI and prefixes it with "view-source:" schema,
|
||||
nsresult BuildViewSourceURI(nsIURI* aURI, nsIURI** aResult);
|
||||
|
|
|
@ -84,7 +84,7 @@ function asyncOpen()
|
|||
var chan = make_channel(URL);
|
||||
|
||||
var cc = chan.QueryInterface(Ci.nsICacheInfoChannel);
|
||||
cc.preferAlternativeDataType(altContentType, "");
|
||||
cc.preferAlternativeDataType(altContentType, "", true);
|
||||
|
||||
chan.asyncOpen(new ChannelListener(readServerContent, null));
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ function flushAndOpenAltChannel()
|
|||
function openAltChannel() {
|
||||
var chan = make_channel(URL);
|
||||
var cc = chan.QueryInterface(Ci.nsICacheInfoChannel);
|
||||
cc.preferAlternativeDataType(altContentType, "");
|
||||
cc.preferAlternativeDataType(altContentType, "", true);
|
||||
|
||||
chan.asyncOpen(new ChannelListener(readAltContent, null));
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ function make_and_open_channel(url, altContentType, callback) {
|
|||
let chan = NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true});
|
||||
if (altContentType) {
|
||||
let cc = chan.QueryInterface(Ci.nsICacheInfoChannel);
|
||||
cc.preferAlternativeDataType(altContentType, "");
|
||||
cc.preferAlternativeDataType(altContentType, "", true);
|
||||
}
|
||||
chan.asyncOpen(new ChannelListener(callback, null));
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ function asyncOpen()
|
|||
var chan = make_channel(URL);
|
||||
|
||||
var cc = chan.QueryInterface(Ci.nsICacheInfoChannel);
|
||||
cc.preferAlternativeDataType(altContentType, "");
|
||||
cc.preferAlternativeDataType(altContentType, "", true);
|
||||
|
||||
chan.asyncOpen(new ChannelListener(readServerContent, null));
|
||||
}
|
||||
|
@ -135,9 +135,9 @@ function flushAndOpenAltChannel()
|
|||
function openAltChannel() {
|
||||
var chan = make_channel(URL);
|
||||
var cc = chan.QueryInterface(Ci.nsICacheInfoChannel);
|
||||
cc.preferAlternativeDataType("dummy1", "text/javascript");
|
||||
cc.preferAlternativeDataType(altContentType, "text/plain");
|
||||
cc.preferAlternativeDataType("dummy2", "");
|
||||
cc.preferAlternativeDataType("dummy1", "text/javascript", true);
|
||||
cc.preferAlternativeDataType(altContentType, "text/plain", true);
|
||||
cc.preferAlternativeDataType("dummy2", "", true);
|
||||
|
||||
chan.asyncOpen(new ChannelListener(readAltContent, null));
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ function requestAgain()
|
|||
shouldPassRevalidation = false;
|
||||
var chan = make_channel(URL);
|
||||
var cc = chan.QueryInterface(Ci.nsICacheInfoChannel);
|
||||
cc.preferAlternativeDataType(altContentType, "");
|
||||
cc.preferAlternativeDataType(altContentType, "", true);
|
||||
chan.asyncOpen(new ChannelListener(readEmptyAltContent, null));
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ function run_test()
|
|||
var chan = make_channel(URL);
|
||||
|
||||
var cc = chan.QueryInterface(Ci.nsICacheInfoChannel);
|
||||
cc.preferAlternativeDataType(altContentType, "");
|
||||
cc.preferAlternativeDataType(altContentType, "", true);
|
||||
|
||||
chan.asyncOpen(new ChannelListener(readServerContent, null));
|
||||
do_test_pending();
|
||||
|
@ -88,7 +88,7 @@ function openAltChannel()
|
|||
{
|
||||
var chan = make_channel(URL);
|
||||
var cc = chan.QueryInterface(Ci.nsICacheInfoChannel);
|
||||
cc.preferAlternativeDataType(altContentType, "");
|
||||
cc.preferAlternativeDataType(altContentType, "", true);
|
||||
|
||||
chan.asyncOpen(listener);
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ function fetch(preferredDataType = null)
|
|||
|
||||
if (preferredDataType) {
|
||||
var cc = chan.QueryInterface(Ci.nsICacheInfoChannel);
|
||||
cc.preferAlternativeDataType(altContentType, "");
|
||||
cc.preferAlternativeDataType(altContentType, "", true);
|
||||
}
|
||||
|
||||
chan.asyncOpen(new ChannelListener((request,
|
||||
|
|
|
@ -32,7 +32,7 @@ function load_channel(url) {
|
|||
URL = url; // save this to open the alt data channel later
|
||||
var chan = make_channel(url);
|
||||
var cc = chan.QueryInterface(Ci.nsICacheInfoChannel);
|
||||
cc.preferAlternativeDataType("text/binary", "");
|
||||
cc.preferAlternativeDataType("text/binary", "", true);
|
||||
chan.asyncOpen(new ChannelListener(readTextData, null));
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ function readTextData(request, buffer)
|
|||
function openAltChannel() {
|
||||
var chan = make_channel(URL);
|
||||
var cc = chan.QueryInterface(Ci.nsICacheInfoChannel);
|
||||
cc.preferAlternativeDataType("text/parent-binary", "");
|
||||
cc.preferAlternativeDataType("text/parent-binary", "", true);
|
||||
chan.asyncOpen(new ChannelListener(readAltData, null));
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче