Files
palemoon27/dom/cache/TypeUtils.cpp
T
roytam1 c0011dadb2 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1160013 CachePushStreamChild should hold the parent DOM object alive. r=baku (07626c5e44)
- Bug 1179772 Make Cache API honor devtools SW testing flag in SW itself. r=ehsan (4d915be43c)
- Bug 1181577 Delay creation of QuotaInitRunnable until Cache Context actually started. r=ehsan (9991aafa07)
- Bug 1210128 Ensure Cache API context internal state is consistent when shutdown during initialization. r=janv (25fbcf3136)
- Bug 1138916 Fix Cache::MatchAll() assertion in WorkerFeature handling. r=baku (73fe25803b)
- Bug 1186312 - Cache API should not accept system principals for child processes. r=bkelly (c140f627f8)
- align (acb75b3a8d)
- Bug 1215290 Cache API should store unfiltered Response URL. r=ehsan (55238dd04a)
- Bug 1217501 P4 Fill headers before setting guard when reading response from Cache. r=ehsan (787cb31d84)
- bits of  Bug 1202902 (82e2e451cc)
- Bug 1147329 - Handle in-process case for Cut/Copy/Paste feature. r=kanru (66cabbf705)
- Bug 1199161 - Add selectedTextContent to CaretStateChangedEvent. r=kanru, sr=smaug (5eb99e303b)
- Bug 1217515 - Clean up the way touch event support is configured. r=roc (24a7db4a42)
- Bug 1216937 - Assign default URL for mozbrowseropenwindow event. r=smaug (fc7aaa533b)
- Bug 1101115, implement nsChromeRegistryContent::IsLocaleRTL so that file directory view works in e10s rtl mode, r=bsmedberg (c0eb12391f)
- Bug 1186787 (part 1) - Replace nsBaseHashtable::EnumerateRead() calls in chrome/ with iterators. r=froydnj. (2508253415)
- Bug 1186787 (part 2) - Replace nsBaseHashtable::EnumerateRead() calls in chrome/ with iterators. r=froydnj. (193c37c478)
- Bug 1170207 - allow overrides of chrome://../skin/ URIs with other chrome://../skin/ URIs within skin manifests, r=bsmedberg (3c24e2006c)
- Bug 1210463 - part 3 - Remove the very obsolete NS_IMPL_MOZILLA192_NSGETMODULE. r=froydnj (c7300c145b)
- Bug 1210463 - part 1 - Remove some unneeded null checks on new in ModuleUtils. r=froydnj (73affb8e34)
- Bug 1210463 - part 2 - Use some smart pointers in ModuleUtils.h. r=froydnj (f5eeb12cb3)
- Bug 1210463 - part 2 - Use some smart pointers in ModuleUtils.h. r=froydnj (788f944a41)
- Bug 1215143 - FF Android VR returns orientation that is 90deg off on x-axis. r=vlad (fc0d86c800)
- Bug 1166667 - Remove LangGroupFromUnicodeRange due to unused. r=jfkthame (e3bb039e41)
- Bug 1119062 - enable unicode-range in release builds. r=dbaron (8d48c7ab14)
- bits of 1117227 in headers (ad920e2094)
- Bug 1220020. Recompute the current animated geometry root when a child scroll frame forces us to be layerized, and therefore turns us into an animated geometry root. r=mstange (4cfb015eb7)
- Bug 1220114. Part 1. Change ScrollFrameHelper::DecideScrollableLayer to recompute the current animated geometry root any time mWillBuildScrollableLayer changes in addition to when usingDisplayPort changes. r=mstange (9e8512babe)
- Bug 1220114. Part 2. If a scroll frame is forced to layerize because of an active descendant scroll frame then set a displayport on the ancestor scroll frame so that next paint we don't have to force layerization after the fact and we can do a fully proper paint. r=mstange (a3d7734f75)
- Bug 1228357 - When saving/restoring a scrollframe's state, only save/restore resolution for the root scrollframe. r=roc (7018d5bcae)
- Bug 1224307 - Fix page scrolling for non-full-width fixed headers/footers [r=tn]  Please enter the commit message for your changes. Lines starting (55eebe3d49)
- Bug 1081272 - Include position and transform when computing header/footer size [r=tn] (c91104a099)
- Bug 1145546: take auto-direction into account in GetScrolledRect, r=jfkthame (a5bf400639)
- spaces (4a2918cb4c)
- Bug 1225376 part 1 - [css-align] Don't compute left/right to start in the style system anymore (due to pending spec change). Map the used value instead (in layout). r=dholbert (677b9eba16)
- Bug 1225376 part 2 - [css-align] Add mochitests for align/justify-items/self/content computed values. (580ef62eb6)
- Bug 1225376 part 3 - [css-grid] Crashtest. (3e5b06dce4)
- Bug 1148515 - Do the scrollbar thumb layer wrapping in nsSliderFrameso that the thumb's event region is wrapped, too. r=tn (0ff596193e)
- Bug 1133732. Header include got missed in rebase. on CLOSED TREE (b870504066)
- Bug 1133732. Make button box frames listen for blurs so they de-activate on blur. r=smaug (5c6274f99d)
- Bug 1170052 part 1: Refactor nsImageBoxFrame::PaintImage() so its final failure case is an early return. r=seth (7308f3f32e)
- Bug 1170052 part 2: Support object-fit & object-position on XUL <image src=""> elements. r=seth (74ab4c8813)
- Bug 1170052 part 3: Add scripts to generate reftests for object-fit/object-position applied to XUL <image>. (NPOTB) (5b1e1b6b90)
- Bug 1170052 part 4: Add reftests for object-fit/object-position on XUL <image> element (as modified copies of existing <img> tests). (test-only) (7f678646e8)
- Bug 1170052 part 5: Mark new reftests as "skip-if(Mulet)" to avoid impacting reftest chunking on that platform in a way that makes SVG reftests fail mysteriously. (d6c7e5ff05)
- Bug 1170052 part 6: Skip new XUL reftests on B2G Emulator as well, since XUL reftests trigger error pages on that platform. (3f4ddeddcd)
- Bug 1194493 - Ensure the 'mVertical' flag is set appropriately on the nsFontMetrics we use to draw text for an nsTextBoxFrame. r=smontagu (a6eed3f9b8)
- Bug 1155359 - Set NS_FRAME_IS_BIDI on nsTextBoxFrame if text direction is set to RTL r=roc (2715d47271)
- crash reporter (015ee49944)
2023-03-20 16:03:44 +08:00

568 lines
16 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/cache/TypeUtils.h"
#include "mozilla/unused.h"
#include "mozilla/dom/CacheBinding.h"
#include "mozilla/dom/InternalRequest.h"
#include "mozilla/dom/Request.h"
#include "mozilla/dom/Response.h"
#include "mozilla/dom/cache/CachePushStreamChild.h"
#include "mozilla/dom/cache/CacheTypes.h"
#include "mozilla/dom/cache/ReadStream.h"
#include "mozilla/ipc/BackgroundChild.h"
#include "mozilla/ipc/PBackgroundChild.h"
#include "mozilla/ipc/PFileDescriptorSetChild.h"
#include "mozilla/ipc/InputStreamUtils.h"
#include "nsCOMPtr.h"
#include "nsIAsyncInputStream.h"
#include "nsIAsyncOutputStream.h"
#include "nsIIPCSerializableInputStream.h"
#include "nsQueryObject.h"
#include "nsPromiseFlatString.h"
#include "nsStreamUtils.h"
#include "nsString.h"
#include "nsURLParsers.h"
#include "nsCRT.h"
#include "nsHttp.h"
namespace mozilla {
namespace dom {
namespace cache {
using mozilla::ipc::BackgroundChild;
using mozilla::ipc::FileDescriptor;
using mozilla::ipc::PBackgroundChild;
using mozilla::ipc::PFileDescriptorSetChild;
namespace {
static bool
HasVaryStar(mozilla::dom::InternalHeaders* aHeaders)
{
nsAutoTArray<nsCString, 16> varyHeaders;
ErrorResult rv;
aHeaders->GetAll(NS_LITERAL_CSTRING("vary"), varyHeaders, rv);
MOZ_ALWAYS_TRUE(!rv.Failed());
for (uint32_t i = 0; i < varyHeaders.Length(); ++i) {
nsAutoCString varyValue(varyHeaders[i]);
char* rawBuffer = varyValue.BeginWriting();
char* token = nsCRT::strtok(rawBuffer, NS_HTTP_HEADER_SEPS, &rawBuffer);
for (; token;
token = nsCRT::strtok(rawBuffer, NS_HTTP_HEADER_SEPS, &rawBuffer)) {
nsDependentCString header(token);
if (header.EqualsLiteral("*")) {
return true;
}
}
}
return false;
}
void
SerializeNormalStream(nsIInputStream* aStream, CacheReadStream& aReadStreamOut)
{
nsAutoTArray<FileDescriptor, 4> fds;
SerializeInputStream(aStream, aReadStreamOut.params(), fds);
PFileDescriptorSetChild* fdSet = nullptr;
if (!fds.IsEmpty()) {
// We should not be serializing until we have an actor ready
PBackgroundChild* manager = BackgroundChild::GetForCurrentThread();
MOZ_ASSERT(manager);
fdSet = manager->SendPFileDescriptorSetConstructor(fds[0]);
for (uint32_t i = 1; i < fds.Length(); ++i) {
Unused << fdSet->SendAddFileDescriptor(fds[i]);
}
}
if (fdSet) {
aReadStreamOut.fds() = fdSet;
} else {
aReadStreamOut.fds() = void_t();
}
}
void
ToHeadersEntryList(nsTArray<HeadersEntry>& aOut, InternalHeaders* aHeaders)
{
MOZ_ASSERT(aHeaders);
nsAutoTArray<InternalHeaders::Entry, 16> entryList;
aHeaders->GetEntries(entryList);
for (uint32_t i = 0; i < entryList.Length(); ++i) {
InternalHeaders::Entry& entry = entryList[i];
aOut.AppendElement(HeadersEntry(entry.mName, entry.mValue));
}
}
} // namespace
already_AddRefed<InternalRequest>
TypeUtils::ToInternalRequest(const RequestOrUSVString& aIn,
BodyAction aBodyAction, ErrorResult& aRv)
{
if (aIn.IsRequest()) {
Request& request = aIn.GetAsRequest();
// Check and set bodyUsed flag immediately because its on Request
// instead of InternalRequest.
CheckAndSetBodyUsed(&request, aBodyAction, aRv);
if (aRv.Failed()) { return nullptr; }
return request.GetInternalRequest();
}
return ToInternalRequest(aIn.GetAsUSVString(), aRv);
}
already_AddRefed<InternalRequest>
TypeUtils::ToInternalRequest(const OwningRequestOrUSVString& aIn,
BodyAction aBodyAction, ErrorResult& aRv)
{
if (aIn.IsRequest()) {
RefPtr<Request> request = aIn.GetAsRequest().get();
// Check and set bodyUsed flag immediately because its on Request
// instead of InternalRequest.
CheckAndSetBodyUsed(request, aBodyAction, aRv);
if (aRv.Failed()) { return nullptr; }
return request->GetInternalRequest();
}
return ToInternalRequest(aIn.GetAsUSVString(), aRv);
}
void
TypeUtils::ToCacheRequest(CacheRequest& aOut, InternalRequest* aIn,
BodyAction aBodyAction, SchemeAction aSchemeAction,
ErrorResult& aRv)
{
MOZ_ASSERT(aIn);
aIn->GetMethod(aOut.method());
nsAutoCString url;
aIn->GetURL(url);
bool schemeValid;
ProcessURL(url, &schemeValid, &aOut.urlWithoutQuery(), &aOut.urlQuery(), aRv);
if (aRv.Failed()) {
return;
}
if (!schemeValid) {
if (aSchemeAction == TypeErrorOnInvalidScheme) {
NS_ConvertUTF8toUTF16 urlUTF16(url);
aRv.ThrowTypeError<MSG_INVALID_URL_SCHEME>(NS_LITERAL_STRING("Request"),
urlUTF16);
return;
}
}
aIn->GetReferrer(aOut.referrer());
RefPtr<InternalHeaders> headers = aIn->Headers();
MOZ_ASSERT(headers);
ToHeadersEntryList(aOut.headers(), headers);
aOut.headersGuard() = headers->Guard();
aOut.mode() = aIn->Mode();
aOut.credentials() = aIn->GetCredentialsMode();
aOut.contentPolicyType() = aIn->ContentPolicyType();
aOut.requestCache() = aIn->GetCacheMode();
aOut.requestRedirect() = aIn->GetRedirectMode();
if (aBodyAction == IgnoreBody) {
aOut.body() = void_t();
return;
}
// BodyUsed flag is checked and set previously in ToInternalRequest()
nsCOMPtr<nsIInputStream> stream;
aIn->GetBody(getter_AddRefs(stream));
SerializeCacheStream(stream, &aOut.body(), aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
}
void
TypeUtils::ToCacheResponseWithoutBody(CacheResponse& aOut,
InternalResponse& aIn, ErrorResult& aRv)
{
aOut.type() = aIn.Type();
aIn.GetUnfilteredUrl(aOut.url());
if (aOut.url() != EmptyCString()) {
// Pass all Response URL schemes through... The spec only requires we take
// action on invalid schemes for Request objects.
ProcessURL(aOut.url(), nullptr, nullptr, nullptr, aRv);
if (aRv.Failed()) {
return;
}
}
aOut.status() = aIn.GetUnfilteredStatus();
aOut.statusText() = aIn.GetUnfilteredStatusText();
RefPtr<InternalHeaders> headers = aIn.UnfilteredHeaders();
MOZ_ASSERT(headers);
if (HasVaryStar(headers)) {
aRv.ThrowTypeError<MSG_RESPONSE_HAS_VARY_STAR>();
return;
}
ToHeadersEntryList(aOut.headers(), headers);
aOut.headersGuard() = headers->Guard();
aOut.channelInfo() = aIn.GetChannelInfo().AsIPCChannelInfo();
if (aIn.GetPrincipalInfo()) {
aOut.principalInfo() = *aIn.GetPrincipalInfo();
} else {
aOut.principalInfo() = void_t();
}
}
void
TypeUtils::ToCacheResponse(CacheResponse& aOut, Response& aIn, ErrorResult& aRv)
{
if (aIn.BodyUsed()) {
aRv.ThrowTypeError<MSG_FETCH_BODY_CONSUMED_ERROR>();
return;
}
RefPtr<InternalResponse> ir = aIn.GetInternalResponse();
ToCacheResponseWithoutBody(aOut, *ir, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
nsCOMPtr<nsIInputStream> stream;
ir->GetUnfilteredBody(getter_AddRefs(stream));
if (stream) {
aIn.SetBodyUsed();
}
SerializeCacheStream(stream, &aOut.body(), aRv);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
}
// static
void
TypeUtils::ToCacheQueryParams(CacheQueryParams& aOut,
const CacheQueryOptions& aIn)
{
aOut.ignoreSearch() = aIn.mIgnoreSearch;
aOut.ignoreMethod() = aIn.mIgnoreMethod;
aOut.ignoreVary() = aIn.mIgnoreVary;
aOut.cacheNameSet() = aIn.mCacheName.WasPassed();
if (aOut.cacheNameSet()) {
aOut.cacheName() = aIn.mCacheName.Value();
} else {
aOut.cacheName() = NS_LITERAL_STRING("");
}
}
already_AddRefed<Response>
TypeUtils::ToResponse(const CacheResponse& aIn)
{
if (aIn.type() == ResponseType::Error) {
RefPtr<InternalResponse> error = InternalResponse::NetworkError();
RefPtr<Response> r = new Response(GetGlobalObject(), error);
return r.forget();
}
RefPtr<InternalResponse> ir = new InternalResponse(aIn.status(),
aIn.statusText());
ir->SetUrl(aIn.url());
RefPtr<InternalHeaders> internalHeaders =
ToInternalHeaders(aIn.headers(), aIn.headersGuard());
ErrorResult result;
ir->Headers()->SetGuard(aIn.headersGuard(), result);
MOZ_ASSERT(!result.Failed());
ir->Headers()->Fill(*internalHeaders, result);
MOZ_ASSERT(!result.Failed());
ir->InitChannelInfo(aIn.channelInfo());
if (aIn.principalInfo().type() == mozilla::ipc::OptionalPrincipalInfo::TPrincipalInfo) {
UniquePtr<mozilla::ipc::PrincipalInfo> info(new mozilla::ipc::PrincipalInfo(aIn.principalInfo().get_PrincipalInfo()));
ir->SetPrincipalInfo(Move(info));
}
nsCOMPtr<nsIInputStream> stream = ReadStream::Create(aIn.body());
ir->SetBody(stream);
switch (aIn.type())
{
case ResponseType::Basic:
ir = ir->BasicResponse();
break;
case ResponseType::Cors:
ir = ir->CORSResponse();
break;
case ResponseType::Default:
break;
case ResponseType::Opaque:
ir = ir->OpaqueResponse();
break;
case ResponseType::Opaqueredirect:
ir = ir->OpaqueRedirectResponse();
break;
default:
MOZ_CRASH("Unexpected ResponseType!");
}
MOZ_ASSERT(ir);
RefPtr<Response> ref = new Response(GetGlobalObject(), ir);
return ref.forget();
}
already_AddRefed<InternalRequest>
TypeUtils::ToInternalRequest(const CacheRequest& aIn)
{
RefPtr<InternalRequest> internalRequest = new InternalRequest();
internalRequest->SetMethod(aIn.method());
nsAutoCString url(aIn.urlWithoutQuery());
url.Append(aIn.urlQuery());
internalRequest->SetURL(url);
internalRequest->SetReferrer(aIn.referrer());
internalRequest->SetMode(aIn.mode());
internalRequest->SetCredentialsMode(aIn.credentials());
internalRequest->SetContentPolicyType(aIn.contentPolicyType());
internalRequest->SetCacheMode(aIn.requestCache());
internalRequest->SetRedirectMode(aIn.requestRedirect());
RefPtr<InternalHeaders> internalHeaders =
ToInternalHeaders(aIn.headers(), aIn.headersGuard());
ErrorResult result;
// Be careful to fill the headers before setting the guard in order to
// correctly re-create the original headers.
internalRequest->Headers()->Fill(*internalHeaders, result);
MOZ_ASSERT(!result.Failed());
internalRequest->Headers()->SetGuard(aIn.headersGuard(), result);
MOZ_ASSERT(!result.Failed());
nsCOMPtr<nsIInputStream> stream = ReadStream::Create(aIn.body());
internalRequest->SetBody(stream);
return internalRequest.forget();
}
already_AddRefed<Request>
TypeUtils::ToRequest(const CacheRequest& aIn)
{
RefPtr<InternalRequest> internalRequest = ToInternalRequest(aIn);
RefPtr<Request> request = new Request(GetGlobalObject(), internalRequest);
return request.forget();
}
// static
already_AddRefed<InternalHeaders>
TypeUtils::ToInternalHeaders(const nsTArray<HeadersEntry>& aHeadersEntryList,
HeadersGuardEnum aGuard)
{
nsTArray<InternalHeaders::Entry> entryList(aHeadersEntryList.Length());
for (uint32_t i = 0; i < aHeadersEntryList.Length(); ++i) {
const HeadersEntry& headersEntry = aHeadersEntryList[i];
entryList.AppendElement(InternalHeaders::Entry(headersEntry.name(),
headersEntry.value()));
}
RefPtr<InternalHeaders> ref = new InternalHeaders(Move(entryList), aGuard);
return ref.forget();
}
// Utility function to remove the fragment from a URL, check its scheme, and optionally
// provide a URL without the query. We're not using nsIURL or URL to do this because
// they require going to the main thread.
// static
void
TypeUtils::ProcessURL(nsACString& aUrl, bool* aSchemeValidOut,
nsACString* aUrlWithoutQueryOut,nsACString* aUrlQueryOut,
ErrorResult& aRv)
{
const nsAFlatCString& flatURL = PromiseFlatCString(aUrl);
const char* url = flatURL.get();
// off the main thread URL parsing using nsStdURLParser.
nsCOMPtr<nsIURLParser> urlParser = new nsStdURLParser();
uint32_t pathPos;
int32_t pathLen;
uint32_t schemePos;
int32_t schemeLen;
aRv = urlParser->ParseURL(url, flatURL.Length(), &schemePos, &schemeLen,
nullptr, nullptr, // ignore authority
&pathPos, &pathLen);
if (NS_WARN_IF(aRv.Failed())) { return; }
if (aSchemeValidOut) {
nsAutoCString scheme(Substring(flatURL, schemePos, schemeLen));
*aSchemeValidOut = scheme.LowerCaseEqualsLiteral("http") ||
scheme.LowerCaseEqualsLiteral("https");
}
uint32_t queryPos;
int32_t queryLen;
aRv = urlParser->ParsePath(url + pathPos, flatURL.Length() - pathPos,
nullptr, nullptr, // ignore filepath
&queryPos, &queryLen,
nullptr, nullptr);
if (NS_WARN_IF(aRv.Failed())) {
return;
}
if (!aUrlWithoutQueryOut) {
return;
}
MOZ_ASSERT(aUrlQueryOut);
if (queryLen < 0) {
*aUrlWithoutQueryOut = aUrl;
*aUrlQueryOut = EmptyCString();
return;
}
// ParsePath gives us query position relative to the start of the path
queryPos += pathPos;
*aUrlWithoutQueryOut = Substring(aUrl, 0, queryPos - 1);
*aUrlQueryOut = Substring(aUrl, queryPos - 1, queryLen + 1);
}
void
TypeUtils::CheckAndSetBodyUsed(Request* aRequest, BodyAction aBodyAction,
ErrorResult& aRv)
{
MOZ_ASSERT(aRequest);
if (aBodyAction == IgnoreBody) {
return;
}
if (aRequest->BodyUsed()) {
aRv.ThrowTypeError<MSG_FETCH_BODY_CONSUMED_ERROR>();
return;
}
nsCOMPtr<nsIInputStream> stream;
aRequest->GetBody(getter_AddRefs(stream));
if (stream) {
aRequest->SetBodyUsed();
}
}
already_AddRefed<InternalRequest>
TypeUtils::ToInternalRequest(const nsAString& aIn, ErrorResult& aRv)
{
RequestOrUSVString requestOrString;
requestOrString.SetAsUSVString().Rebind(aIn.Data(), aIn.Length());
// Re-create a GlobalObject stack object so we can use webidl Constructors.
AutoJSAPI jsapi;
if (NS_WARN_IF(!jsapi.Init(GetGlobalObject()))) {
aRv.Throw(NS_ERROR_UNEXPECTED);
return nullptr;
}
JSContext* cx = jsapi.cx();
GlobalObject global(cx, GetGlobalObject()->GetGlobalJSObject());
MOZ_ASSERT(!global.Failed());
RefPtr<Request> request = Request::Constructor(global, requestOrString,
RequestInit(), aRv);
if (NS_WARN_IF(aRv.Failed())) { return nullptr; }
return request->GetInternalRequest();
}
void
TypeUtils::SerializeCacheStream(nsIInputStream* aStream,
CacheReadStreamOrVoid* aStreamOut,
ErrorResult& aRv)
{
*aStreamOut = void_t();
if (!aStream) {
return;
}
// Option 1: Send a cache-specific ReadStream if we can.
RefPtr<ReadStream> controlled = do_QueryObject(aStream);
if (controlled) {
controlled->Serialize(aStreamOut);
return;
}
CacheReadStream readStream;
readStream.controlChild() = nullptr;
readStream.controlParent() = nullptr;
readStream.pushStreamChild() = nullptr;
readStream.pushStreamParent() = nullptr;
// Option 2: Do normal stream serialization if its supported.
nsCOMPtr<nsIIPCSerializableInputStream> serial = do_QueryInterface(aStream);
if (serial) {
SerializeNormalStream(aStream, readStream);
// Option 3: As a last resort push data across manually. Should only be
// needed for nsPipe input stream. Only works for async,
// non-blocking streams.
} else {
SerializePushStream(aStream, readStream, aRv);
if (NS_WARN_IF(aRv.Failed())) { return; }
}
*aStreamOut = readStream;
}
void
TypeUtils::SerializePushStream(nsIInputStream* aStream,
CacheReadStream& aReadStreamOut,
ErrorResult& aRv)
{
nsCOMPtr<nsIAsyncInputStream> asyncStream = do_QueryInterface(aStream);
if (NS_WARN_IF(!asyncStream)) {
aRv = NS_ERROR_FAILURE;
return;
}
bool nonBlocking = false;
aRv = asyncStream->IsNonBlocking(&nonBlocking);
if (NS_WARN_IF(aRv.Failed())) { return; }
if (NS_WARN_IF(!nonBlocking)) {
aRv = NS_ERROR_FAILURE;
return;
}
aReadStreamOut.pushStreamChild() = CreatePushStream(asyncStream);
MOZ_ASSERT(aReadStreamOut.pushStreamChild());
aReadStreamOut.params() = void_t();
aReadStreamOut.fds() = void_t();
// CachePushStreamChild::Start() must be called after sending the stream
// across to the parent side.
}
} // namespace cache
} // namespace dom
} // namespace mozilla