зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1263991 part 3: Support incoming and outgoing requests/responses. r=baku f=bkelly
This commit is contained in:
Родитель
00ad3a0f9d
Коммит
64a8f66145
|
@ -9,13 +9,13 @@ include IPCStream;
|
|||
include ChannelInfo;
|
||||
include PBackgroundSharedTypes;
|
||||
|
||||
using HeadersGuardEnum from "mozilla/dom/cache/IPCUtils.h";
|
||||
using ReferrerPolicy from "mozilla/dom/cache/IPCUtils.h";
|
||||
using RequestCredentials from "mozilla/dom/cache/IPCUtils.h";
|
||||
using RequestMode from "mozilla/dom/cache/IPCUtils.h";
|
||||
using RequestCache from "mozilla/dom/cache/IPCUtils.h";
|
||||
using RequestRedirect from "mozilla/dom/cache/IPCUtils.h";
|
||||
using ResponseType from "mozilla/dom/cache/IPCUtils.h";
|
||||
using HeadersGuardEnum from "mozilla/dom/FetchIPCTypes.h";
|
||||
using ReferrerPolicy from "mozilla/dom/FetchIPCTypes.h";
|
||||
using RequestCredentials from "mozilla/dom/FetchIPCTypes.h";
|
||||
using RequestMode from "mozilla/dom/FetchIPCTypes.h";
|
||||
using RequestCache from "mozilla/dom/FetchIPCTypes.h";
|
||||
using RequestRedirect from "mozilla/dom/FetchIPCTypes.h";
|
||||
using ResponseType from "mozilla/dom/FetchIPCTypes.h";
|
||||
using mozilla::void_t from "ipc/IPCMessageUtils.h";
|
||||
using struct nsID from "nsID.h";
|
||||
|
||||
|
|
|
@ -9,51 +9,10 @@
|
|||
|
||||
#include "ipc/IPCMessageUtils.h"
|
||||
|
||||
// Fix X11 header brain damage that conflicts with HeadersGuardEnum::None
|
||||
#undef None
|
||||
|
||||
#include "mozilla/dom/HeadersBinding.h"
|
||||
#include "mozilla/dom/RequestBinding.h"
|
||||
#include "mozilla/dom/ResponseBinding.h"
|
||||
#include "mozilla/dom/cache/Types.h"
|
||||
|
||||
namespace IPC {
|
||||
template<>
|
||||
struct ParamTraits<mozilla::dom::HeadersGuardEnum> :
|
||||
public ContiguousEnumSerializer<mozilla::dom::HeadersGuardEnum,
|
||||
mozilla::dom::HeadersGuardEnum::None,
|
||||
mozilla::dom::HeadersGuardEnum::EndGuard_> {};
|
||||
template<>
|
||||
struct ParamTraits<mozilla::dom::ReferrerPolicy> :
|
||||
public ContiguousEnumSerializer<mozilla::dom::ReferrerPolicy,
|
||||
mozilla::dom::ReferrerPolicy::_empty,
|
||||
mozilla::dom::ReferrerPolicy::EndGuard_> {};
|
||||
template<>
|
||||
struct ParamTraits<mozilla::dom::RequestMode> :
|
||||
public ContiguousEnumSerializer<mozilla::dom::RequestMode,
|
||||
mozilla::dom::RequestMode::Same_origin,
|
||||
mozilla::dom::RequestMode::EndGuard_> {};
|
||||
template<>
|
||||
struct ParamTraits<mozilla::dom::RequestCredentials> :
|
||||
public ContiguousEnumSerializer<mozilla::dom::RequestCredentials,
|
||||
mozilla::dom::RequestCredentials::Omit,
|
||||
mozilla::dom::RequestCredentials::EndGuard_> {};
|
||||
template<>
|
||||
struct ParamTraits<mozilla::dom::RequestCache> :
|
||||
public ContiguousEnumSerializer<mozilla::dom::RequestCache,
|
||||
mozilla::dom::RequestCache::Default,
|
||||
mozilla::dom::RequestCache::EndGuard_> {};
|
||||
template<>
|
||||
struct ParamTraits<mozilla::dom::RequestRedirect> :
|
||||
public ContiguousEnumSerializer<mozilla::dom::RequestRedirect,
|
||||
mozilla::dom::RequestRedirect::Follow,
|
||||
mozilla::dom::RequestRedirect::EndGuard_> {};
|
||||
template<>
|
||||
struct ParamTraits<mozilla::dom::ResponseType> :
|
||||
public ContiguousEnumSerializer<mozilla::dom::ResponseType,
|
||||
mozilla::dom::ResponseType::Basic,
|
||||
mozilla::dom::ResponseType::EndGuard_> {};
|
||||
template<>
|
||||
struct ParamTraits<mozilla::dom::cache::Namespace> :
|
||||
public ContiguousEnumSerializer<mozilla::dom::cache::Namespace,
|
||||
mozilla::dom::cache::DEFAULT_NAMESPACE,
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/* -*- 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/. */
|
||||
|
||||
#ifndef mozilla_dom_fetch_IPCUtils_h
|
||||
#define mozilla_dom_fetch_IPCUtils_h
|
||||
|
||||
#include "ipc/IPCMessageUtils.h"
|
||||
|
||||
// Fix X11 header brain damage that conflicts with HeadersGuardEnum::None
|
||||
#undef None
|
||||
|
||||
#include "mozilla/dom/HeadersBinding.h"
|
||||
#include "mozilla/dom/RequestBinding.h"
|
||||
#include "mozilla/dom/ResponseBinding.h"
|
||||
|
||||
namespace IPC {
|
||||
template<>
|
||||
struct ParamTraits<mozilla::dom::HeadersGuardEnum> :
|
||||
public ContiguousEnumSerializer<mozilla::dom::HeadersGuardEnum,
|
||||
mozilla::dom::HeadersGuardEnum::None,
|
||||
mozilla::dom::HeadersGuardEnum::EndGuard_> {};
|
||||
template<>
|
||||
struct ParamTraits<mozilla::dom::ReferrerPolicy> :
|
||||
public ContiguousEnumSerializer<mozilla::dom::ReferrerPolicy,
|
||||
mozilla::dom::ReferrerPolicy::_empty,
|
||||
mozilla::dom::ReferrerPolicy::EndGuard_> {};
|
||||
template<>
|
||||
struct ParamTraits<mozilla::dom::RequestMode> :
|
||||
public ContiguousEnumSerializer<mozilla::dom::RequestMode,
|
||||
mozilla::dom::RequestMode::Same_origin,
|
||||
mozilla::dom::RequestMode::EndGuard_> {};
|
||||
template<>
|
||||
struct ParamTraits<mozilla::dom::RequestCredentials> :
|
||||
public ContiguousEnumSerializer<mozilla::dom::RequestCredentials,
|
||||
mozilla::dom::RequestCredentials::Omit,
|
||||
mozilla::dom::RequestCredentials::EndGuard_> {};
|
||||
template<>
|
||||
struct ParamTraits<mozilla::dom::RequestCache> :
|
||||
public ContiguousEnumSerializer<mozilla::dom::RequestCache,
|
||||
mozilla::dom::RequestCache::Default,
|
||||
mozilla::dom::RequestCache::EndGuard_> {};
|
||||
template<>
|
||||
struct ParamTraits<mozilla::dom::RequestRedirect> :
|
||||
public ContiguousEnumSerializer<mozilla::dom::RequestRedirect,
|
||||
mozilla::dom::RequestRedirect::Follow,
|
||||
mozilla::dom::RequestRedirect::EndGuard_> {};
|
||||
template<>
|
||||
struct ParamTraits<mozilla::dom::ResponseType> :
|
||||
public ContiguousEnumSerializer<mozilla::dom::ResponseType,
|
||||
mozilla::dom::ResponseType::Basic,
|
||||
mozilla::dom::ResponseType::EndGuard_> {};
|
||||
} // namespace IPC
|
||||
|
||||
#endif // mozilla_dom_fetch_IPCUtils_h
|
|
@ -0,0 +1,59 @@
|
|||
/* 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 IPCStream;
|
||||
include ChannelInfo;
|
||||
include PBackgroundSharedTypes;
|
||||
|
||||
using HeadersGuardEnum from "mozilla/dom/FetchIPCTypes.h";
|
||||
using ReferrerPolicy from "mozilla/dom/FetchIPCTypes.h";
|
||||
using RequestCredentials from "mozilla/dom/FetchIPCTypes.h";
|
||||
using RequestMode from "mozilla/dom/FetchIPCTypes.h";
|
||||
using ResponseType from "mozilla/dom/FetchIPCTypes.h";
|
||||
using RequestRedirect from "mozilla/dom/FetchIPCTypes.h";
|
||||
using RequestCache from "mozilla/dom/FetchIPCTypes.h";
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
struct HeadersEntry
|
||||
{
|
||||
nsCString name;
|
||||
nsCString value;
|
||||
};
|
||||
|
||||
// Note, this does not yet serialize *all* of InternalRequest
|
||||
// Make sure that it contains the fields that you care about
|
||||
struct IPCInternalRequest
|
||||
{
|
||||
nsCString[] urls;
|
||||
nsCString method;
|
||||
HeadersEntry[] headers;
|
||||
HeadersGuardEnum headersGuard;
|
||||
nsString referrer;
|
||||
ReferrerPolicy referrerPolicy;
|
||||
RequestMode mode;
|
||||
RequestCredentials credentials;
|
||||
uint32_t contentPolicyType;
|
||||
RequestCache requestCache;
|
||||
RequestRedirect requestRedirect;
|
||||
};
|
||||
|
||||
// Note, this does not yet serialize *all* of InternalResponse
|
||||
// Make sure that it contains the fields that you care about
|
||||
struct IPCInternalResponse
|
||||
{
|
||||
ResponseType type;
|
||||
nsCString[] urlList;
|
||||
uint32_t status;
|
||||
nsCString statusText;
|
||||
HeadersEntry[] headers;
|
||||
HeadersGuardEnum headersGuard;
|
||||
IPCChannelInfo channelInfo;
|
||||
OptionalPrincipalInfo principalInfo;
|
||||
};
|
||||
|
||||
|
||||
} // namespace ipc
|
||||
} // namespace mozilla
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "mozilla/dom/InternalHeaders.h"
|
||||
|
||||
#include "mozilla/dom/FetchTypes.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
|
||||
#include "nsCharSeparatedTokenizer.h"
|
||||
|
@ -23,6 +24,27 @@ InternalHeaders::InternalHeaders(const nsTArray<Entry>&& aHeaders,
|
|||
{
|
||||
}
|
||||
|
||||
InternalHeaders::InternalHeaders(const nsTArray<HeadersEntry>& aHeadersEntryList,
|
||||
HeadersGuardEnum aGuard)
|
||||
: mGuard(aGuard)
|
||||
{
|
||||
for (const HeadersEntry& headersEntry : aHeadersEntryList) {
|
||||
mList.AppendElement(Entry(headersEntry.name(), headersEntry.value()));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
InternalHeaders::ToIPC(nsTArray<HeadersEntry>& aIPCHeaders,
|
||||
HeadersGuardEnum& aGuard)
|
||||
{
|
||||
aGuard = mGuard;
|
||||
|
||||
aIPCHeaders.Clear();
|
||||
for (Entry& entry : mList) {
|
||||
aIPCHeaders.AppendElement(HeadersEntry(entry.mName, entry.mValue));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
InternalHeaders::Append(const nsACString& aName, const nsACString& aValue,
|
||||
ErrorResult& aRv)
|
||||
|
|
|
@ -21,6 +21,7 @@ class ErrorResult;
|
|||
namespace dom {
|
||||
|
||||
template<typename T> class MozMap;
|
||||
class HeadersEntry;
|
||||
|
||||
class InternalHeaders final
|
||||
{
|
||||
|
@ -64,6 +65,12 @@ public:
|
|||
explicit InternalHeaders(const nsTArray<Entry>&& aHeaders,
|
||||
HeadersGuardEnum aGuard = HeadersGuardEnum::None);
|
||||
|
||||
InternalHeaders(const nsTArray<HeadersEntry>& aHeadersEntryList,
|
||||
HeadersGuardEnum aGuard);
|
||||
|
||||
void ToIPC(nsTArray<HeadersEntry>& aIPCHeaders,
|
||||
HeadersGuardEnum& aGuard);
|
||||
|
||||
void Append(const nsACString& aName, const nsACString& aValue,
|
||||
ErrorResult& aRv);
|
||||
void Delete(const nsACString& aName, ErrorResult& aRv);
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "nsStreamUtils.h"
|
||||
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/dom/FetchTypes.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "mozilla/dom/workers/Workers.h"
|
||||
|
||||
|
@ -102,10 +103,45 @@ InternalRequest::InternalRequest(const InternalRequest& aOther)
|
|||
// NOTE: does not copy body stream... use the fallible Clone() for that
|
||||
}
|
||||
|
||||
InternalRequest::InternalRequest(const IPCInternalRequest& aIPCRequest)
|
||||
: mMethod(aIPCRequest.method())
|
||||
, mURLList(aIPCRequest.urls())
|
||||
, mHeaders(new InternalHeaders(aIPCRequest.headers(),
|
||||
aIPCRequest.headersGuard()))
|
||||
, mContentPolicyType(aIPCRequest.contentPolicyType())
|
||||
, mReferrer(aIPCRequest.referrer())
|
||||
, mReferrerPolicy(aIPCRequest.referrerPolicy())
|
||||
, mMode(aIPCRequest.mode())
|
||||
, mCredentialsMode(aIPCRequest.credentials())
|
||||
, mCacheMode(aIPCRequest.requestCache())
|
||||
, mRedirectMode(aIPCRequest.requestRedirect())
|
||||
{
|
||||
MOZ_ASSERT(!mURLList.IsEmpty());
|
||||
}
|
||||
|
||||
InternalRequest::~InternalRequest()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
InternalRequest::ToIPC(IPCInternalRequest* aIPCRequest)
|
||||
{
|
||||
MOZ_ASSERT(aIPCRequest);
|
||||
MOZ_ASSERT(!mURLList.IsEmpty());
|
||||
aIPCRequest->urls() = mURLList;
|
||||
aIPCRequest->method() = mMethod;
|
||||
|
||||
mHeaders->ToIPC(aIPCRequest->headers(), aIPCRequest->headersGuard());
|
||||
|
||||
aIPCRequest->referrer() = mReferrer;
|
||||
aIPCRequest->referrerPolicy() = mReferrerPolicy;
|
||||
aIPCRequest->mode() = mMode;
|
||||
aIPCRequest->credentials() = mCredentialsMode;
|
||||
aIPCRequest->contentPolicyType() = mContentPolicyType;
|
||||
aIPCRequest->requestCache() = mCacheMode;
|
||||
aIPCRequest->requestRedirect() = mRedirectMode;
|
||||
}
|
||||
|
||||
void
|
||||
InternalRequest::SetContentPolicyType(nsContentPolicyType aContentPolicyType)
|
||||
{
|
||||
|
|
|
@ -78,6 +78,7 @@ namespace dom {
|
|||
*/
|
||||
|
||||
class Request;
|
||||
class IPCInternalRequest;
|
||||
|
||||
#define kFETCH_CLIENT_REFERRER_STR "about:client"
|
||||
|
||||
|
@ -150,6 +151,10 @@ public:
|
|||
AddURL(aURL);
|
||||
}
|
||||
|
||||
explicit InternalRequest(const IPCInternalRequest& aIPCRequest);
|
||||
|
||||
void ToIPC(IPCInternalRequest* aIPCRequest);
|
||||
|
||||
already_AddRefed<InternalRequest> Clone();
|
||||
|
||||
void
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "mozilla/ipc/PBackgroundSharedTypes.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsStreamUtils.h"
|
||||
#include "mozilla/dom/FetchTypes.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -25,10 +26,78 @@ InternalResponse::InternalResponse(uint16_t aStatus, const nsACString& aStatusTe
|
|||
{
|
||||
}
|
||||
|
||||
already_AddRefed<InternalResponse>
|
||||
InternalResponse::FromIPC(const IPCInternalResponse& aIPCResponse)
|
||||
{
|
||||
MOZ_ASSERT(!aIPCResponse.urlList().IsEmpty());
|
||||
|
||||
if (aIPCResponse.type() == ResponseType::Error) {
|
||||
return InternalResponse::NetworkError();
|
||||
}
|
||||
|
||||
RefPtr<InternalResponse> response =
|
||||
new InternalResponse(aIPCResponse.status(),
|
||||
aIPCResponse.statusText());
|
||||
|
||||
response->SetURLList(aIPCResponse.urlList());
|
||||
|
||||
response->mHeaders = new InternalHeaders(aIPCResponse.headers(),
|
||||
aIPCResponse.headersGuard());
|
||||
|
||||
response->InitChannelInfo(aIPCResponse.channelInfo());
|
||||
if (aIPCResponse.principalInfo().type() == mozilla::ipc::OptionalPrincipalInfo::TPrincipalInfo) {
|
||||
UniquePtr<mozilla::ipc::PrincipalInfo> info(new mozilla::ipc::PrincipalInfo(aIPCResponse.principalInfo().get_PrincipalInfo()));
|
||||
response->SetPrincipalInfo(Move(info));
|
||||
}
|
||||
|
||||
switch (aIPCResponse.type())
|
||||
{
|
||||
case ResponseType::Basic:
|
||||
response = response->BasicResponse();
|
||||
break;
|
||||
case ResponseType::Cors:
|
||||
response = response->CORSResponse();
|
||||
break;
|
||||
case ResponseType::Default:
|
||||
break;
|
||||
case ResponseType::Opaque:
|
||||
response = response->OpaqueResponse();
|
||||
break;
|
||||
case ResponseType::Opaqueredirect:
|
||||
response = response->OpaqueRedirectResponse();
|
||||
break;
|
||||
default:
|
||||
MOZ_CRASH("Unexpected ResponseType!");
|
||||
}
|
||||
MOZ_ASSERT(response);
|
||||
|
||||
return response.forget();
|
||||
}
|
||||
|
||||
InternalResponse::~InternalResponse()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
InternalResponse::ToIPC(IPCInternalResponse* aIPCResponse)
|
||||
{
|
||||
MOZ_ASSERT(aIPCResponse);
|
||||
MOZ_ASSERT(!mURLList.IsEmpty());
|
||||
aIPCResponse->type() = mType;
|
||||
aIPCResponse->urlList() = mURLList;
|
||||
aIPCResponse->status() = GetUnfilteredStatus();
|
||||
aIPCResponse->statusText() = GetUnfilteredStatusText();
|
||||
|
||||
mHeaders->ToIPC(aIPCResponse->headers(), aIPCResponse->headersGuard());
|
||||
|
||||
aIPCResponse->channelInfo() = mChannelInfo.AsIPCChannelInfo();
|
||||
if (mPrincipalInfo) {
|
||||
aIPCResponse->principalInfo() = *mPrincipalInfo;
|
||||
} else {
|
||||
aIPCResponse->principalInfo() = void_t();
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<InternalResponse>
|
||||
InternalResponse::Clone()
|
||||
{
|
||||
|
|
|
@ -22,6 +22,7 @@ class PrincipalInfo;
|
|||
namespace dom {
|
||||
|
||||
class InternalHeaders;
|
||||
class IPCInternalResponse;
|
||||
|
||||
class InternalResponse final
|
||||
{
|
||||
|
@ -32,6 +33,11 @@ public:
|
|||
|
||||
InternalResponse(uint16_t aStatus, const nsACString& aStatusText);
|
||||
|
||||
static already_AddRefed<InternalResponse>
|
||||
FromIPC(const IPCInternalResponse& aIPCResponse);
|
||||
|
||||
void ToIPC(IPCInternalResponse* aIPCResponse);
|
||||
|
||||
already_AddRefed<InternalResponse> Clone();
|
||||
|
||||
static already_AddRefed<InternalResponse>
|
||||
|
|
|
@ -8,6 +8,7 @@ EXPORTS.mozilla.dom += [
|
|||
'ChannelInfo.h',
|
||||
'Fetch.h',
|
||||
'FetchDriver.h',
|
||||
'FetchIPCTypes.h',
|
||||
'FetchUtil.h',
|
||||
'Headers.h',
|
||||
'InternalHeaders.h',
|
||||
|
@ -32,6 +33,7 @@ UNIFIED_SOURCES += [
|
|||
|
||||
IPDL_SOURCES += [
|
||||
'ChannelInfo.ipdlh',
|
||||
'FetchTypes.ipdlh',
|
||||
]
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
#include "mozilla/dom/Request.h"
|
||||
#include "mozilla/dom/FlyWebServerEvents.h"
|
||||
#include "mozilla/dom/ContentChild.h"
|
||||
#include "mozilla/dom/ContentParent.h"
|
||||
#include "mozilla/dom/InternalResponse.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/unused.h"
|
||||
|
@ -262,6 +264,19 @@ FlyWebPublishedServerChild::RecvServerClose()
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
FlyWebPublishedServerChild::RecvFetchRequest(const IPCInternalRequest& aRequest,
|
||||
const uint64_t& aRequestId)
|
||||
{
|
||||
LOG_I("FlyWebPublishedServerChild::RecvFetchRequest(%p)", this);
|
||||
|
||||
RefPtr<InternalRequest> request = new InternalRequest(aRequest);
|
||||
mPendingRequests.Put(request, aRequestId);
|
||||
FireFetchEvent(request);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebPublishedServerChild::ActorDestroy(ActorDestroyReason aWhy)
|
||||
{
|
||||
|
@ -274,7 +289,20 @@ void
|
|||
FlyWebPublishedServerChild::OnFetchResponse(InternalRequest* aRequest,
|
||||
InternalResponse* aResponse)
|
||||
{
|
||||
// Send ipdl message to parent
|
||||
LOG_I("FlyWebPublishedServerChild::OnFetchResponse(%p)", this);
|
||||
|
||||
if (mActorDestroyed) {
|
||||
LOG_I("FlyWebPublishedServerChild::OnFetchResponse(%p) - No actor!", this);
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t id = mPendingRequests.Get(aRequest);
|
||||
MOZ_ASSERT(id);
|
||||
mPendingRequests.Remove(aRequest);
|
||||
|
||||
IPCInternalResponse ipcResp;
|
||||
aResponse->ToIPC(&ipcResp);
|
||||
Unused << SendFetchResponse(ipcResp, id);
|
||||
}
|
||||
|
||||
already_AddRefed<WebSocket>
|
||||
|
@ -309,9 +337,12 @@ FlyWebPublishedServerChild::Close()
|
|||
|
||||
/******** FlyWebPublishedServerParent ********/
|
||||
|
||||
NS_IMPL_ISUPPORTS(FlyWebPublishedServerParent, nsIDOMEventListener)
|
||||
|
||||
FlyWebPublishedServerParent::FlyWebPublishedServerParent(const nsAString& aName,
|
||||
const FlyWebPublishOptions& aOptions)
|
||||
: mActorDestroyed(false)
|
||||
, mNextRequestId(1)
|
||||
{
|
||||
LOG_I("FlyWebPublishedServerParent::FlyWebPublishedServerParent(%p)", this);
|
||||
|
||||
|
@ -330,21 +361,79 @@ FlyWebPublishedServerParent::FlyWebPublishedServerParent(const nsAString& aName,
|
|||
|
||||
RefPtr<FlyWebPublishedServerParent> self = this;
|
||||
|
||||
mozPromise->Then(AbstractThread::MainThread(),
|
||||
mozPromise->Then(
|
||||
AbstractThread::MainThread(),
|
||||
__func__,
|
||||
[this, self] (FlyWebPublishedServer* aServer) {
|
||||
mPublishedServer = static_cast<FlyWebPublishedServerImpl*>(aServer);
|
||||
if (!mActorDestroyed) {
|
||||
Unused << SendServerReady(NS_OK);
|
||||
if (mActorDestroyed) {
|
||||
mPublishedServer->Close();
|
||||
return;
|
||||
}
|
||||
|
||||
mPublishedServer->AddEventListener(NS_LITERAL_STRING("fetch"),
|
||||
this, false, false, 2);
|
||||
mPublishedServer->AddEventListener(NS_LITERAL_STRING("close"),
|
||||
this, false, false, 2);
|
||||
Unused << SendServerReady(NS_OK);
|
||||
},
|
||||
[this, self] (nsresult aStatus) {
|
||||
MOZ_ASSERT(NS_FAILED(aStatus));
|
||||
if (!mActorDestroyed) {
|
||||
Unused << SendServerReady(aStatus);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
FlyWebPublishedServerParent::HandleEvent(nsIDOMEvent* aEvent)
|
||||
{
|
||||
if (mActorDestroyed) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsAutoString type;
|
||||
aEvent->GetType(type);
|
||||
if (type.EqualsLiteral("close")) {
|
||||
Unused << SendServerClose();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (type.EqualsLiteral("fetch")) {
|
||||
RefPtr<InternalRequest> request =
|
||||
static_cast<FlyWebFetchEvent*>(aEvent)->Request()->GetInternalRequest();
|
||||
uint64_t id = mNextRequestId++;
|
||||
mPendingRequests.Put(id, request);
|
||||
|
||||
IPCInternalRequest ipcReq;
|
||||
request->ToIPC(&ipcReq);
|
||||
Unused << SendFetchRequest(ipcReq, id);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
MOZ_CRASH("Unknown event type");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
FlyWebPublishedServerParent::RecvFetchResponse(const IPCInternalResponse& aResponse,
|
||||
const uint64_t& aRequestId)
|
||||
{
|
||||
RefPtr<InternalRequest> request = mPendingRequests.GetWeak(aRequestId);
|
||||
mPendingRequests.Remove(aRequestId);
|
||||
if (!request) {
|
||||
static_cast<ContentParent*>(Manager())->KillHard("unknown request id");
|
||||
return false;
|
||||
}
|
||||
|
||||
RefPtr<InternalResponse> response = InternalResponse::FromIPC(aResponse);
|
||||
|
||||
mPublishedServer->OnFetchResponse(request, response);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebPublishedServerParent::ActorDestroy(ActorDestroyReason aWhy)
|
||||
{
|
||||
|
@ -359,6 +448,10 @@ FlyWebPublishedServerParent::Recv__delete__()
|
|||
LOG_I("FlyWebPublishedServerParent::Recv__delete__(%p)", this);
|
||||
|
||||
if (mPublishedServer) {
|
||||
mPublishedServer->RemoveEventListener(NS_LITERAL_STRING("fetch"),
|
||||
this, false);
|
||||
mPublishedServer->RemoveEventListener(NS_LITERAL_STRING("close"),
|
||||
this, false);
|
||||
mPublishedServer->Close();
|
||||
mPublishedServer = nullptr;
|
||||
}
|
||||
|
|
|
@ -12,8 +12,9 @@
|
|||
#include "mozilla/dom/PFlyWebPublishedServerParent.h"
|
||||
#include "mozilla/dom/PFlyWebPublishedServerChild.h"
|
||||
#include "mozilla/MozPromise.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "nsICancelable.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
|
||||
class nsPIDOMWindowInner;
|
||||
|
||||
|
@ -94,6 +95,8 @@ public:
|
|||
|
||||
virtual bool RecvServerReady(const nsresult& aStatus) override;
|
||||
virtual bool RecvServerClose() override;
|
||||
virtual bool RecvFetchRequest(const IPCInternalRequest& aRequest,
|
||||
const uint64_t& aRequestId) override;
|
||||
|
||||
virtual void OnFetchResponse(InternalRequest* aRequest,
|
||||
InternalResponse* aResponse) override;
|
||||
|
@ -111,16 +114,19 @@ public:
|
|||
private:
|
||||
~FlyWebPublishedServerChild() {}
|
||||
|
||||
nsDataHashtable<nsRefPtrHashKey<InternalRequest>, uint64_t> mPendingRequests;
|
||||
bool mActorDestroyed;
|
||||
};
|
||||
|
||||
class FlyWebPublishedServerParent final : public PFlyWebPublishedServerParent
|
||||
, public nsIDOMEventListener
|
||||
{
|
||||
public:
|
||||
FlyWebPublishedServerParent(const nsAString& aName,
|
||||
const FlyWebPublishOptions& aOptions);
|
||||
|
||||
NS_INLINE_DECL_REFCOUNTING(FlyWebPublishedServerParent)
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOMEVENTLISTENER
|
||||
|
||||
private:
|
||||
virtual void
|
||||
|
@ -128,10 +134,15 @@ private:
|
|||
|
||||
virtual bool
|
||||
Recv__delete__() override;
|
||||
virtual bool
|
||||
RecvFetchResponse(const IPCInternalResponse& aResponse,
|
||||
const uint64_t& aRequestId) override;
|
||||
|
||||
~FlyWebPublishedServerParent() {}
|
||||
|
||||
bool mActorDestroyed;
|
||||
uint64_t mNextRequestId;
|
||||
nsRefPtrHashtable<nsUint64HashKey, InternalRequest> mPendingRequests;
|
||||
RefPtr<FlyWebPublishedServerImpl> mPublishedServer;
|
||||
};
|
||||
|
||||
|
|
|
@ -912,7 +912,7 @@ HttpServer::Connection::QueueResponse(InternalResponse* aResponse)
|
|||
aResponse->GetStatusText() +
|
||||
NS_LITERAL_CSTRING("\r\n"));
|
||||
|
||||
nsTArray<InternalHeaders::Entry> entries;
|
||||
AutoTArray<InternalHeaders::Entry, 16> entries;
|
||||
headers->GetEntries(entries);
|
||||
|
||||
for (auto header : entries) {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
include protocol PContent;
|
||||
include FetchTypes;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
@ -15,10 +16,13 @@ async protocol PFlyWebPublishedServer
|
|||
|
||||
child:
|
||||
async ServerReady(nsresult aStatus);
|
||||
async FetchRequest(IPCInternalRequest aRequest, uint64_t aRequestId);
|
||||
async ServerClose();
|
||||
|
||||
parent:
|
||||
async __delete__();
|
||||
|
||||
async FetchResponse(IPCInternalResponse aResponse, uint64_t aRequestId);
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
|
Загрузка…
Ссылка в новой задаче