mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 05:37:11 +00:00
8f529f64f5
- Bug 932865 - Add ThreadHangStats for collecting background hang telemetry; r=vladan (2f08a076b)
- Bug 932865 - Add way for telemetry to iterate over active threads; r=froydnj (535615d3d)
- Bug 1128768: Part 3 - Update BHR to allow for hang annotations; r=vladan (0b880a667)
- Bug 935092 - Add ThreadStackHelper to get a thread's pesudo-stack; r=BenWa (1422cfe4d)
- Bug 942488 - Don't report pseudo-stacks without SPS profiler. r=nchen (e160a7a08)
- Bug 946817 - Don't assert mPseudoStack on B2G. r=BenWa (9f846df3b)
- Bug 951431 - Don't get stacks during profiler runs on Linux; r=BenWa (15036e907)
- Bug 978262 - Ignore duplicate frames when getting BHR stack. r=froydnj (964721b1b)
- Bug 985155 - Add signal trampoline on ARM Linux to work around kernel bug. r=snorp (cb8a7846c)
- Bug 995730 - Convert xpcom/threads/ to Gecko style. r=froydnj (fe150404e)
- Bug 1013326 - Distinguish chrome and content scripts in pseudostack; r=snorp (81273c977)
- Bug 1023461 - Remove temporary stack buffer in ThreadStackHelper; r=snorp (cf5a717c2)
- Bug 1023461 - Record filename and line number for chrome JS entries; r=snorp (10c89808f)
- Bug 1022456 - Fix modelines in xpcom/{base,glue,io,string,threads}/. (48dbc0416)
- Bug 1016441 - Switch to using real-time signal in ThreadStackHelper; (2c5f818be)
- Bug 1016629 - b. Use RAII class to assign mStackToFill; r=snorp (769eae130)
- Bug 1016629 - c. Add define for ThreadStackHelper pseudostack support; r=snorp (67def0d2f)
- Bug 1016629 - d. Add and implement GetNativeStack method in ThreadStackHelper; r=snorp r=jseward (46c52f2be)
- Bug 1016629 - e. Implement platform-specific code for filling in context; r=snorp r=jseward (e6a66858b)
- Bug 1016629 - g. Avoid ASan flag when copying stack; r=snorp (0159628b5)
- Bug 1045176 - Unbreak build on non-SPS platforms after bug 1016629. (f1d60d838)
- Bug 1047123 - ThreadStackHelper should use UniquePtr<uint8_t[]>, not ScopedDeleteArray. r=jchen (0e4af313c)
- Bug 1049161 - Fix ThreadStackHelper thread handle permissions on Windows; r=snorp (c05172b1c)
- Bug 1050185 - Make ThreadStackHelper::FillThreadContext Valgrind-friendly. r=nchen (368725774)
- Bug 1050440 - Remove repeated js::RunScript frames in ThreadStackHelper (2a79600b3)
- Bug 1046841 - Fix more style violations in previously touched .cpp files in xpcom/. r=froydnj (02afe2493)
- Bug 1069694 - Remove or move around functions in OldDebugAPI. r=shu (177197302)
- Bug 1069694 - Remove OldDebugAPI from the browser. r=shu (b8c917d42)
- Bug 1100911 - For MacOS builds running on Valgrind, make ThreadStackHelper::GetStack be a no-op. r=nchen. (d99c02e16)
- Bug 1091758 - Report full paths for most chrome scripts; r=snorp (2b72e7878)
- Bug 1109291 - Include better paths for hanging chrome scripts in profile extensions directory; r=snorp r=bsmedberg (1997b9532)
- Bug 1113416 - Don't read stack labels inside hang monitor sighandler; r=nfroyd r=snorp (9688f6069)
- bug 1146027 - more final r=froydnj (7b0f295e5)
- Bug 1164090 - Check for Windows path separator in BHR file name; r=snorp (f014b4d78)
- Bug 1169034 - include <cstdlib> in ThreadStackHelper.cpp to declare correct overload for std::abs; r=jseward (874d4447e)
- Bug 1182996 - Fix and add missing namespace comments. rs=ehsan (054fc00b2)
- Bug 932865 - Collect thread hang stats in BackgroundHangMonitor; (ac80c8e9f)
- minor anticipated fixes to get it compiling (2bd701d15)
582 lines
17 KiB
C++
582 lines
17 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/FileDescriptorSetChild.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 "nsStreamUtils.h"
|
|
#include "nsString.h"
|
|
#include "nsURLParsers.h"
|
|
#include "nsCRT.h"
|
|
#include "nsHttp.h"
|
|
|
|
namespace {
|
|
|
|
using mozilla::ErrorResult;
|
|
using mozilla::unused;
|
|
using mozilla::void_t;
|
|
using mozilla::dom::InternalHeaders;
|
|
using mozilla::dom::cache::CacheReadStream;
|
|
using mozilla::dom::cache::HeadersEntry;
|
|
using mozilla::ipc::BackgroundChild;
|
|
using mozilla::ipc::FileDescriptor;
|
|
using mozilla::ipc::PBackgroundChild;
|
|
using mozilla::ipc::PFileDescriptorSetChild;
|
|
|
|
// 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
|
|
ProcessURL(nsAString& aUrl, bool* aSchemeValidOut,
|
|
nsAString* aUrlWithoutQueryOut, ErrorResult& aRv)
|
|
{
|
|
NS_ConvertUTF16toUTF8 flatURL(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;
|
|
uint32_t refPos;
|
|
int32_t refLen;
|
|
|
|
aRv = urlParser->ParsePath(url + pathPos, flatURL.Length() - pathPos,
|
|
nullptr, nullptr, // ignore filepath
|
|
&queryPos, &queryLen,
|
|
&refPos, &refLen);
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
return;
|
|
}
|
|
|
|
// TODO: Remove this once Request/Response properly strip the fragment (bug 1110476)
|
|
if (refLen >= 0) {
|
|
// ParsePath gives us ref position relative to the start of the path
|
|
refPos += pathPos;
|
|
|
|
aUrl = Substring(aUrl, 0, refPos - 1);
|
|
}
|
|
|
|
if (!aUrlWithoutQueryOut) {
|
|
return;
|
|
}
|
|
|
|
if (queryLen < 0) {
|
|
*aUrlWithoutQueryOut = aUrl;
|
|
return;
|
|
}
|
|
|
|
// ParsePath gives us query position relative to the start of the path
|
|
queryPos += pathPos;
|
|
|
|
// We want everything before the query sine we already removed the trailing
|
|
// fragment
|
|
*aUrlWithoutQueryOut = Substring(aUrl, 0, queryPos - 1);
|
|
}
|
|
|
|
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
|
|
|
|
namespace mozilla {
|
|
namespace dom {
|
|
namespace cache {
|
|
|
|
using mozilla::ipc::BackgroundChild;
|
|
using mozilla::ipc::FileDescriptor;
|
|
using mozilla::ipc::FileDescriptorSetChild;
|
|
using mozilla::ipc::PFileDescriptorSetChild;
|
|
using mozilla::ipc::PBackgroundChild;
|
|
using mozilla::ipc::OptionalFileDescriptorSet;
|
|
|
|
|
|
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()) {
|
|
nsRefPtr<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,
|
|
ReferrerAction aReferrerAction,
|
|
SchemeAction aSchemeAction, ErrorResult& aRv)
|
|
{
|
|
MOZ_ASSERT(aIn);
|
|
|
|
aIn->GetMethod(aOut.method());
|
|
|
|
nsAutoCString url;
|
|
aIn->GetURL(url);
|
|
CopyUTF8toUTF16(url, aOut.url());
|
|
|
|
bool schemeValid;
|
|
ProcessURL(aOut.url(), &schemeValid, &aOut.urlWithoutQuery(), aRv);
|
|
if (aRv.Failed()) {
|
|
return;
|
|
}
|
|
|
|
if (!schemeValid) {
|
|
if (aSchemeAction == TypeErrorOnInvalidScheme) {
|
|
NS_NAMED_LITERAL_STRING(label, "Request");
|
|
aRv.ThrowTypeError(MSG_INVALID_URL_SCHEME, &label, &aOut.url());
|
|
return;
|
|
}
|
|
|
|
if (aSchemeAction == NetworkErrorOnInvalidScheme) {
|
|
aRv.Throw(NS_ERROR_DOM_NETWORK_ERR);
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (aReferrerAction == ExpandReferrer) {
|
|
UpdateRequestReferrer(GetGlobalObject(), aIn);
|
|
}
|
|
aIn->GetReferrer(aOut.referrer());
|
|
|
|
nsRefPtr<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.context() = aIn->Context();
|
|
aOut.requestCache() = aIn->GetCacheMode();
|
|
|
|
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();
|
|
|
|
nsAutoCString url;
|
|
aIn.GetUrl(url);
|
|
CopyUTF8toUTF16(url, aOut.url());
|
|
|
|
if (aOut.url() != EmptyString()) {
|
|
// Pass all Response URL schemes through... The spec only requires we take
|
|
// action on invalid schemes for Request objects.
|
|
ProcessURL(aOut.url(), nullptr, nullptr, aRv);
|
|
if (aRv.Failed()) {
|
|
return;
|
|
}
|
|
}
|
|
|
|
aOut.status() = aIn.GetStatus();
|
|
aOut.statusText() = aIn.GetStatusText();
|
|
nsRefPtr<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.securityInfo() = aIn.GetSecurityInfo();
|
|
}
|
|
|
|
void
|
|
TypeUtils::ToCacheResponse(CacheResponse& aOut, Response& aIn, ErrorResult& aRv)
|
|
{
|
|
if (aIn.BodyUsed()) {
|
|
aRv.ThrowTypeError(MSG_FETCH_BODY_CONSUMED_ERROR);
|
|
return;
|
|
}
|
|
|
|
nsRefPtr<InternalResponse> ir = aIn.GetInternalResponse();
|
|
ToCacheResponseWithoutBody(aOut, *ir, aRv);
|
|
if (NS_WARN_IF(aRv.Failed())) {
|
|
return;
|
|
}
|
|
|
|
nsCOMPtr<nsIInputStream> stream;
|
|
aIn.GetBody(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.prefixMatch() = aIn.mPrefixMatch;
|
|
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) {
|
|
nsRefPtr<InternalResponse> error = InternalResponse::NetworkError();
|
|
nsRefPtr<Response> r = new Response(GetGlobalObject(), error);
|
|
return r.forget();
|
|
}
|
|
|
|
nsRefPtr<InternalResponse> ir = new InternalResponse(aIn.status(),
|
|
aIn.statusText());
|
|
ir->SetUrl(NS_ConvertUTF16toUTF8(aIn.url()));
|
|
|
|
nsRefPtr<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->SetSecurityInfo(aIn.securityInfo());
|
|
|
|
nsCOMPtr<nsIInputStream> stream = ReadStream::Create(aIn.body());
|
|
ir->SetBody(stream);
|
|
|
|
switch (aIn.type())
|
|
{
|
|
case ResponseType::Default:
|
|
break;
|
|
case ResponseType::Opaque:
|
|
ir = ir->OpaqueResponse();
|
|
break;
|
|
case ResponseType::Basic:
|
|
ir = ir->BasicResponse();
|
|
break;
|
|
case ResponseType::Cors:
|
|
ir = ir->CORSResponse();
|
|
break;
|
|
default:
|
|
MOZ_CRASH("Unexpected ResponseType!");
|
|
}
|
|
MOZ_ASSERT(ir);
|
|
|
|
nsRefPtr<Response> ref = new Response(GetGlobalObject(), ir);
|
|
return ref.forget();
|
|
}
|
|
|
|
already_AddRefed<InternalRequest>
|
|
TypeUtils::ToInternalRequest(const CacheRequest& aIn)
|
|
{
|
|
nsRefPtr<InternalRequest> internalRequest = new InternalRequest();
|
|
|
|
internalRequest->SetMethod(aIn.method());
|
|
internalRequest->SetURL(NS_ConvertUTF16toUTF8(aIn.url()));
|
|
internalRequest->SetReferrer(aIn.referrer());
|
|
internalRequest->SetMode(aIn.mode());
|
|
internalRequest->SetCredentialsMode(aIn.credentials());
|
|
internalRequest->SetContentPolicyType(aIn.contentPolicyType());
|
|
DebugOnly<RequestContext> contextAfterSetContentPolicyType = internalRequest->Context();
|
|
internalRequest->SetContext(aIn.context());
|
|
MOZ_ASSERT(contextAfterSetContentPolicyType.value == internalRequest->Context(),
|
|
"The RequestContext and nsContentPolicyType values should not get out of sync");
|
|
internalRequest->SetCacheMode(aIn.requestCache());
|
|
|
|
nsRefPtr<InternalHeaders> internalHeaders =
|
|
ToInternalHeaders(aIn.headers(), aIn.headersGuard());
|
|
ErrorResult result;
|
|
internalRequest->Headers()->SetGuard(aIn.headersGuard(), result);
|
|
MOZ_ASSERT(!result.Failed());
|
|
internalRequest->Headers()->Fill(*internalHeaders, 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)
|
|
{
|
|
nsRefPtr<InternalRequest> internalRequest = ToInternalRequest(aIn);
|
|
nsRefPtr<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()));
|
|
}
|
|
|
|
nsRefPtr<InternalHeaders> ref = new InternalHeaders(Move(entryList), aGuard);
|
|
return ref.forget();
|
|
}
|
|
|
|
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());
|
|
|
|
nsRefPtr<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.
|
|
nsRefPtr<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
|