mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-06 15:58:39 +09:00
Issue #1395 - Part 2: Remove the /rest/ of FlyWeb
This commit is contained in:
parent
146d0aa2d2
commit
2c6ab7ccd9
14 changed files with 0 additions and 4420 deletions
|
|
@ -1,126 +0,0 @@
|
|||
/* -*- 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 "nsString.h"
|
||||
#include "nsTHashtable.h"
|
||||
#include "nsClassHashtable.h"
|
||||
#include "nsIUUIDGenerator.h"
|
||||
#include "jsapi.h"
|
||||
#include "mozilla/StaticPtr.h"
|
||||
#include "mozilla/Logging.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
#include "mozilla/dom/FlyWebDiscoveryManager.h"
|
||||
#include "mozilla/dom/FlyWebDiscoveryManagerBinding.h"
|
||||
#include "mozilla/dom/Element.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
static LazyLogModule gFlyWebDiscoveryManagerLog("FlyWebDiscoveryManager");
|
||||
#undef LOG_I
|
||||
#define LOG_I(...) MOZ_LOG(mozilla::dom::gFlyWebDiscoveryManagerLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
|
||||
#undef LOG_E
|
||||
#define LOG_E(...) MOZ_LOG(mozilla::dom::gFlyWebDiscoveryManagerLog, mozilla::LogLevel::Error, (__VA_ARGS__))
|
||||
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(FlyWebDiscoveryManager)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTING_ADDREF(FlyWebDiscoveryManager)
|
||||
NS_IMPL_CYCLE_COLLECTING_RELEASE(FlyWebDiscoveryManager)
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(FlyWebDiscoveryManager)
|
||||
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
||||
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
FlyWebDiscoveryManager::FlyWebDiscoveryManager(nsISupports* aParent,
|
||||
FlyWebService* aService)
|
||||
: mParent(aParent)
|
||||
, mService(aService)
|
||||
, mNextId(0)
|
||||
{
|
||||
}
|
||||
|
||||
FlyWebDiscoveryManager::~FlyWebDiscoveryManager()
|
||||
{
|
||||
mService->UnregisterDiscoveryManager(this);
|
||||
}
|
||||
|
||||
JSObject*
|
||||
FlyWebDiscoveryManager::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return FlyWebDiscoveryManagerBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
nsISupports*
|
||||
FlyWebDiscoveryManager::GetParentObject() const
|
||||
{
|
||||
return mParent;
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<FlyWebDiscoveryManager>
|
||||
FlyWebDiscoveryManager::Constructor(const GlobalObject& aGlobal, ErrorResult& rv)
|
||||
{
|
||||
RefPtr<FlyWebService> service = FlyWebService::GetOrCreate();
|
||||
if (!service) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
RefPtr<FlyWebDiscoveryManager> result = new FlyWebDiscoveryManager(
|
||||
aGlobal.GetAsSupports(), service);
|
||||
return result.forget();
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebDiscoveryManager::ListServices(nsTArray<FlyWebDiscoveredService>& aServices)
|
||||
{
|
||||
return mService->ListDiscoveredServices(aServices);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
FlyWebDiscoveryManager::StartDiscovery(FlyWebDiscoveryCallback& aCallback)
|
||||
{
|
||||
uint32_t id = GenerateId();
|
||||
mCallbackMap.Put(id, &aCallback);
|
||||
mService->RegisterDiscoveryManager(this);
|
||||
return id;
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebDiscoveryManager::StopDiscovery(uint32_t aId)
|
||||
{
|
||||
mCallbackMap.Remove(aId);
|
||||
if (mCallbackMap.Count() == 0) {
|
||||
mService->UnregisterDiscoveryManager(this);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebDiscoveryManager::PairWithService(const nsAString& aServiceId,
|
||||
FlyWebPairingCallback& aCallback)
|
||||
{
|
||||
mService->PairWithService(aServiceId, aCallback);
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebDiscoveryManager::NotifyDiscoveredServicesChanged()
|
||||
{
|
||||
nsTArray<FlyWebDiscoveredService> services;
|
||||
ListServices(services);
|
||||
Sequence<FlyWebDiscoveredService> servicesSeq;
|
||||
servicesSeq.SwapElements(services);
|
||||
for (auto iter = mCallbackMap.Iter(); !iter.Done(); iter.Next()) {
|
||||
FlyWebDiscoveryCallback *callback = iter.UserData();
|
||||
ErrorResult err;
|
||||
callback->OnDiscoveredServicesChanged(servicesSeq, err);
|
||||
ENSURE_SUCCESS_VOID(err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
/* -*- 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_FlyWebDiscoveryManager_h
|
||||
#define mozilla_dom_FlyWebDiscoveryManager_h
|
||||
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "nsRefPtrHashtable.h"
|
||||
#include "nsWrapperCache.h"
|
||||
#include "FlyWebDiscoveryManagerBinding.h"
|
||||
#include "FlyWebService.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class FlyWebDiscoveryManager final : public nsISupports
|
||||
, public nsWrapperCache
|
||||
{
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(FlyWebDiscoveryManager)
|
||||
|
||||
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
nsISupports* GetParentObject() const;
|
||||
|
||||
static already_AddRefed<FlyWebDiscoveryManager> Constructor(const GlobalObject& aGlobal,
|
||||
ErrorResult& rv);
|
||||
|
||||
void ListServices(nsTArray<FlyWebDiscoveredService>& aServices);
|
||||
uint32_t StartDiscovery(FlyWebDiscoveryCallback& aCallback);
|
||||
void StopDiscovery(uint32_t aId);
|
||||
|
||||
void PairWithService(const nsAString& aServiceId,
|
||||
FlyWebPairingCallback& callback);
|
||||
|
||||
void NotifyDiscoveredServicesChanged();
|
||||
|
||||
private:
|
||||
FlyWebDiscoveryManager(nsISupports* mParent, FlyWebService* aService);
|
||||
~FlyWebDiscoveryManager();
|
||||
|
||||
uint32_t GenerateId() {
|
||||
return ++mNextId;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsISupports> mParent;
|
||||
RefPtr<FlyWebService> mService;
|
||||
|
||||
uint32_t mNextId;
|
||||
|
||||
nsRefPtrHashtable<nsUint32HashKey, FlyWebDiscoveryCallback> mCallbackMap;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_FlyWebDiscoveryManager_h
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
/* -*- 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_FlyWebPublishOptionsIPCSerialiser_h
|
||||
#define mozilla_dom_FlyWebPublishOptionsIPCSerialiser_h
|
||||
|
||||
#include "mozilla/dom/FlyWebPublishBinding.h"
|
||||
|
||||
namespace IPC {
|
||||
|
||||
template <>
|
||||
struct ParamTraits<mozilla::dom::FlyWebPublishOptions>
|
||||
{
|
||||
typedef mozilla::dom::FlyWebPublishOptions paramType;
|
||||
|
||||
// Function to serialize a FlyWebPublishOptions
|
||||
static void Write(Message *aMsg, const paramType& aParam)
|
||||
{
|
||||
WriteParam(aMsg, aParam.mUiUrl);
|
||||
}
|
||||
// Function to de-serialize a FlyWebPublishOptions
|
||||
static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
|
||||
{
|
||||
return ReadParam(aMsg, aIter, &(aResult->mUiUrl));
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // mozilla_dom_FlyWebPublishOptionsIPCSerialiser_h
|
||||
|
|
@ -1,675 +0,0 @@
|
|||
/* -*- 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/FlyWebPublishedServerIPC.h"
|
||||
#include "mozilla/dom/FlyWebPublishBinding.h"
|
||||
#include "mozilla/dom/FlyWebService.h"
|
||||
#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/ipc/IPCStreamUtils.h"
|
||||
#include "mozilla/net/NeckoParent.h"
|
||||
#include "mozilla/net/IPCTransportProvider.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "nsCharSeparatedTokenizer.h"
|
||||
#include "nsGlobalWindow.h"
|
||||
#include "WebSocketChannel.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
static LazyLogModule gFlyWebPublishedServerLog("FlyWebPublishedServer");
|
||||
#undef LOG_I
|
||||
#define LOG_I(...) MOZ_LOG(mozilla::dom::gFlyWebPublishedServerLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
|
||||
#undef LOG_E
|
||||
#define LOG_E(...) MOZ_LOG(mozilla::dom::gFlyWebPublishedServerLog, mozilla::LogLevel::Error, (__VA_ARGS__))
|
||||
|
||||
/******** FlyWebPublishedServer ********/
|
||||
|
||||
FlyWebPublishedServer::FlyWebPublishedServer(nsPIDOMWindowInner* aOwner,
|
||||
const nsAString& aName,
|
||||
const FlyWebPublishOptions& aOptions)
|
||||
: mozilla::DOMEventTargetHelper(aOwner)
|
||||
, mOwnerWindowID(aOwner ? aOwner->WindowID() : 0)
|
||||
, mName(aName)
|
||||
, mUiUrl(aOptions.mUiUrl)
|
||||
, mIsRegistered(true) // Registered by the FlyWebService
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebPublishedServer::LastRelease()
|
||||
{
|
||||
// Make sure to unregister to avoid dangling pointers. Use the LastRelease
|
||||
// hook rather than dtor since calling virtual functions during dtor
|
||||
// wouldn't do what we want. Also, LastRelease is called earlier than dtor
|
||||
// for CC objects.
|
||||
Close();
|
||||
}
|
||||
|
||||
JSObject*
|
||||
FlyWebPublishedServer::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return FlyWebPublishedServerBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebPublishedServer::Close()
|
||||
{
|
||||
LOG_I("FlyWebPublishedServer::Close(%p)", this);
|
||||
|
||||
// Unregister from server.
|
||||
if (mIsRegistered) {
|
||||
MOZ_ASSERT(FlyWebService::GetExisting());
|
||||
FlyWebService::GetExisting()->UnregisterServer(this);
|
||||
mIsRegistered = false;
|
||||
|
||||
DispatchTrustedEvent(NS_LITERAL_STRING("close"));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebPublishedServer::FireFetchEvent(InternalRequest* aRequest)
|
||||
{
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
||||
RefPtr<FlyWebFetchEvent> e = new FlyWebFetchEvent(this,
|
||||
new Request(global, aRequest),
|
||||
aRequest);
|
||||
e->Init(this);
|
||||
e->InitEvent(NS_LITERAL_STRING("fetch"), false, false);
|
||||
|
||||
DispatchTrustedEvent(e);
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebPublishedServer::FireWebsocketEvent(InternalRequest* aConnectRequest)
|
||||
{
|
||||
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
|
||||
RefPtr<FlyWebFetchEvent> e = new FlyWebWebSocketEvent(this,
|
||||
new Request(global, aConnectRequest),
|
||||
aConnectRequest);
|
||||
e->Init(this);
|
||||
e->InitEvent(NS_LITERAL_STRING("websocket"), false, false);
|
||||
|
||||
DispatchTrustedEvent(e);
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebPublishedServer::PublishedServerStarted(nsresult aStatus)
|
||||
{
|
||||
LOG_I("FlyWebPublishedServer::PublishedServerStarted(%p)", this);
|
||||
|
||||
RefPtr<FlyWebPublishPromise> promise = mPublishPromise.Ensure(__func__);
|
||||
if (NS_SUCCEEDED(aStatus)) {
|
||||
mPublishPromise.Resolve(this, __func__);
|
||||
} else {
|
||||
Close();
|
||||
mPublishPromise.Reject(aStatus, __func__);
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<WebSocket>
|
||||
FlyWebPublishedServer::OnWebSocketAccept(InternalRequest* aConnectRequest,
|
||||
const Optional<nsAString>& aProtocol,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(aConnectRequest);
|
||||
|
||||
LOG_I("FlyWebPublishedServer::OnWebSocketAccept(%p)", this);
|
||||
|
||||
nsCOMPtr<nsITransportProvider> provider =
|
||||
OnWebSocketAcceptInternal(aConnectRequest,
|
||||
aProtocol,
|
||||
aRv);
|
||||
if (aRv.Failed()) {
|
||||
return nullptr;
|
||||
}
|
||||
MOZ_ASSERT(provider);
|
||||
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(GetOwner());
|
||||
AutoJSContext cx;
|
||||
GlobalObject global(cx, nsGlobalWindow::Cast(window)->FastGetGlobalJSObject());
|
||||
|
||||
nsAutoCString extensions, negotiatedExtensions;
|
||||
aConnectRequest->Headers()->
|
||||
GetFirst(NS_LITERAL_CSTRING("Sec-WebSocket-Extensions"), extensions, aRv);
|
||||
mozilla::net::ProcessServerWebSocketExtensions(extensions,
|
||||
negotiatedExtensions);
|
||||
|
||||
nsCString url;
|
||||
aConnectRequest->GetURL(url);
|
||||
Sequence<nsString> protocols;
|
||||
if (aProtocol.WasPassed() &&
|
||||
!protocols.AppendElement(aProtocol.Value(), fallible)) {
|
||||
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return WebSocket::ConstructorCommon(global,
|
||||
NS_ConvertUTF8toUTF16(url),
|
||||
protocols,
|
||||
provider,
|
||||
negotiatedExtensions,
|
||||
aRv);
|
||||
}
|
||||
|
||||
/******** FlyWebPublishedServerImpl ********/
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED0(FlyWebPublishedServerImpl, mozilla::DOMEventTargetHelper)
|
||||
|
||||
FlyWebPublishedServerImpl::FlyWebPublishedServerImpl(nsPIDOMWindowInner* aOwner,
|
||||
const nsAString& aName,
|
||||
const FlyWebPublishOptions& aOptions)
|
||||
: FlyWebPublishedServer(aOwner, aName, aOptions)
|
||||
, mHttpServer(new HttpServer())
|
||||
{
|
||||
LOG_I("FlyWebPublishedServerImpl::FlyWebPublishedServerImpl(%p)", this);
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebPublishedServerImpl::PermissionGranted(bool aGranted)
|
||||
{
|
||||
LOG_I("FlyWebPublishedServerImpl::PermissionGranted(%b)", aGranted);
|
||||
if (!aGranted) {
|
||||
PublishedServerStarted(NS_ERROR_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
mHttpServer->Init(-1, Preferences::GetBool("flyweb.use-tls", false), this);
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebPublishedServerImpl::Close()
|
||||
{
|
||||
FlyWebPublishedServer::Close();
|
||||
|
||||
if (mMDNSCancelRegister) {
|
||||
mMDNSCancelRegister->Cancel(NS_BINDING_ABORTED);
|
||||
mMDNSCancelRegister = nullptr;
|
||||
}
|
||||
|
||||
if (mHttpServer) {
|
||||
RefPtr<HttpServer> server = mHttpServer.forget();
|
||||
server->Close();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebPublishedServerImpl::OnServerStarted(nsresult aStatus)
|
||||
{
|
||||
if (NS_SUCCEEDED(aStatus)) {
|
||||
FlyWebService::GetOrCreate()->StartDiscoveryOf(this);
|
||||
} else {
|
||||
PublishedServerStarted(aStatus);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebPublishedServerImpl::OnFetchResponse(InternalRequest* aRequest,
|
||||
InternalResponse* aResponse)
|
||||
{
|
||||
MOZ_ASSERT(aRequest);
|
||||
MOZ_ASSERT(aResponse);
|
||||
|
||||
LOG_I("FlyWebPublishedServerImpl::OnFetchResponse(%p)", this);
|
||||
|
||||
if (mHttpServer) {
|
||||
mHttpServer->SendResponse(aRequest, aResponse);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebPublishedServerImpl::OnWebSocketResponse(InternalRequest* aConnectRequest,
|
||||
InternalResponse* aResponse)
|
||||
{
|
||||
MOZ_ASSERT(aConnectRequest);
|
||||
MOZ_ASSERT(aResponse);
|
||||
|
||||
LOG_I("FlyWebPublishedMDNSServer::OnWebSocketResponse(%p)", this);
|
||||
|
||||
if (mHttpServer) {
|
||||
mHttpServer->SendWebSocketResponse(aConnectRequest, aResponse);
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<nsITransportProvider>
|
||||
FlyWebPublishedServerImpl::OnWebSocketAcceptInternal(InternalRequest* aConnectRequest,
|
||||
const Optional<nsAString>& aProtocol,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
LOG_I("FlyWebPublishedServerImpl::OnWebSocketAcceptInternal(%p)", this);
|
||||
|
||||
if (!mHttpServer) {
|
||||
aRv.Throw(NS_ERROR_UNEXPECTED);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return mHttpServer->AcceptWebSocket(aConnectRequest,
|
||||
aProtocol,
|
||||
aRv);
|
||||
}
|
||||
|
||||
/******** FlyWebPublishedServerChild ********/
|
||||
|
||||
FlyWebPublishedServerChild::FlyWebPublishedServerChild(nsPIDOMWindowInner* aOwner,
|
||||
const nsAString& aName,
|
||||
const FlyWebPublishOptions& aOptions)
|
||||
: FlyWebPublishedServer(aOwner, aName, aOptions)
|
||||
, mActorExists(false)
|
||||
{
|
||||
LOG_I("FlyWebPublishedServerChild::FlyWebPublishedServerChild(%p)", this);
|
||||
|
||||
// The matching release happens when the actor is destroyed, in
|
||||
// ContentChild::DeallocPFlyWebPublishedServerChild
|
||||
NS_ADDREF_THIS();
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebPublishedServerChild::PermissionGranted(bool aGranted)
|
||||
{
|
||||
if (!aGranted) {
|
||||
PublishedServerStarted(NS_ERROR_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
mActorExists = true;
|
||||
FlyWebPublishOptions options;
|
||||
options.mUiUrl = mUiUrl;
|
||||
|
||||
// Proceed with initialization.
|
||||
ContentChild::GetSingleton()->
|
||||
SendPFlyWebPublishedServerConstructor(this, mName, options);
|
||||
}
|
||||
|
||||
bool
|
||||
FlyWebPublishedServerChild::RecvServerReady(const nsresult& aStatus)
|
||||
{
|
||||
LOG_I("FlyWebPublishedServerChild::RecvServerReady(%p)", this);
|
||||
MOZ_ASSERT(mActorExists);
|
||||
|
||||
PublishedServerStarted(aStatus);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
FlyWebPublishedServerChild::RecvServerClose()
|
||||
{
|
||||
LOG_I("FlyWebPublishedServerChild::RecvServerClose(%p)", this);
|
||||
MOZ_ASSERT(mActorExists);
|
||||
|
||||
Close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
FlyWebPublishedServerChild::RecvFetchRequest(const IPCInternalRequest& aRequest,
|
||||
const uint64_t& aRequestId)
|
||||
{
|
||||
LOG_I("FlyWebPublishedServerChild::RecvFetchRequest(%p)", this);
|
||||
MOZ_ASSERT(mActorExists);
|
||||
|
||||
RefPtr<InternalRequest> request = new InternalRequest(aRequest);
|
||||
mPendingRequests.Put(request, aRequestId);
|
||||
FireFetchEvent(request);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
FlyWebPublishedServerChild::RecvWebSocketRequest(const IPCInternalRequest& aRequest,
|
||||
const uint64_t& aRequestId,
|
||||
PTransportProviderChild* aProvider)
|
||||
{
|
||||
LOG_I("FlyWebPublishedServerChild::RecvWebSocketRequest(%p)", this);
|
||||
MOZ_ASSERT(mActorExists);
|
||||
|
||||
RefPtr<InternalRequest> request = new InternalRequest(aRequest);
|
||||
mPendingRequests.Put(request, aRequestId);
|
||||
|
||||
// Not addreffing here. The addref was already done when the
|
||||
// PTransportProvider child constructor original ran.
|
||||
mPendingTransportProviders.Put(aRequestId,
|
||||
dont_AddRef(static_cast<TransportProviderChild*>(aProvider)));
|
||||
|
||||
FireWebsocketEvent(request);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebPublishedServerChild::ActorDestroy(ActorDestroyReason aWhy)
|
||||
{
|
||||
LOG_I("FlyWebPublishedServerChild::ActorDestroy(%p)", this);
|
||||
|
||||
mActorExists = false;
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebPublishedServerChild::OnFetchResponse(InternalRequest* aRequest,
|
||||
InternalResponse* aResponse)
|
||||
{
|
||||
LOG_I("FlyWebPublishedServerChild::OnFetchResponse(%p)", this);
|
||||
|
||||
if (!mActorExists) {
|
||||
LOG_I("FlyWebPublishedServerChild::OnFetchResponse(%p) - No actor!", this);
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t id = mPendingRequests.Get(aRequest);
|
||||
MOZ_ASSERT(id);
|
||||
mPendingRequests.Remove(aRequest);
|
||||
|
||||
IPCInternalResponse ipcResp;
|
||||
UniquePtr<mozilla::ipc::AutoIPCStream> autoStream;
|
||||
nsIContentChild* cc = static_cast<ContentChild*>(Manager());
|
||||
aResponse->ToIPC(&ipcResp, cc, autoStream);
|
||||
Unused << SendFetchResponse(ipcResp, id);
|
||||
if (autoStream) {
|
||||
autoStream->TakeOptionalValue();
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<nsITransportProvider>
|
||||
FlyWebPublishedServerChild::OnWebSocketAcceptInternal(InternalRequest* aRequest,
|
||||
const Optional<nsAString>& aProtocol,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
LOG_I("FlyWebPublishedServerChild::OnWebSocketAcceptInternal(%p)", this);
|
||||
|
||||
if (!mActorExists) {
|
||||
LOG_I("FlyWebPublishedServerChild::OnWebSocketAcceptInternal(%p) - No actor!", this);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint64_t id = mPendingRequests.Get(aRequest);
|
||||
MOZ_ASSERT(id);
|
||||
mPendingRequests.Remove(aRequest);
|
||||
|
||||
RefPtr<TransportProviderChild> provider;
|
||||
mPendingTransportProviders.Remove(id, getter_AddRefs(provider));
|
||||
|
||||
nsString protocol;
|
||||
if (aProtocol.WasPassed()) {
|
||||
protocol = aProtocol.Value();
|
||||
|
||||
nsAutoCString reqProtocols;
|
||||
aRequest->Headers()->
|
||||
GetFirst(NS_LITERAL_CSTRING("Sec-WebSocket-Protocol"), reqProtocols, aRv);
|
||||
if (!ContainsToken(reqProtocols, NS_ConvertUTF16toUTF8(protocol))) {
|
||||
// Should throw a better error here
|
||||
aRv.Throw(NS_ERROR_FAILURE);
|
||||
return nullptr;
|
||||
}
|
||||
} else {
|
||||
protocol.SetIsVoid(true);
|
||||
}
|
||||
|
||||
Unused << SendWebSocketAccept(protocol, id);
|
||||
|
||||
return provider.forget();
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebPublishedServerChild::OnWebSocketResponse(InternalRequest* aRequest,
|
||||
InternalResponse* aResponse)
|
||||
{
|
||||
LOG_I("FlyWebPublishedServerChild::OnFetchResponse(%p)", this);
|
||||
|
||||
if (!mActorExists) {
|
||||
LOG_I("FlyWebPublishedServerChild::OnFetchResponse(%p) - No actor!", this);
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t id = mPendingRequests.Get(aRequest);
|
||||
MOZ_ASSERT(id);
|
||||
mPendingRequests.Remove(aRequest);
|
||||
|
||||
mPendingTransportProviders.Remove(id);
|
||||
|
||||
IPCInternalResponse ipcResp;
|
||||
UniquePtr<mozilla::ipc::AutoIPCStream> autoStream;
|
||||
nsIContentChild* cc = static_cast<ContentChild*>(Manager());
|
||||
aResponse->ToIPC(&ipcResp, cc, autoStream);
|
||||
|
||||
Unused << SendWebSocketResponse(ipcResp, id);
|
||||
if (autoStream) {
|
||||
autoStream->TakeOptionalValue();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebPublishedServerChild::Close()
|
||||
{
|
||||
LOG_I("FlyWebPublishedServerChild::Close(%p)", this);
|
||||
|
||||
FlyWebPublishedServer::Close();
|
||||
|
||||
if (mActorExists) {
|
||||
LOG_I("FlyWebPublishedServerChild::Close - sending __delete__ (%p)", this);
|
||||
|
||||
Send__delete__(this);
|
||||
}
|
||||
}
|
||||
|
||||
/******** FlyWebPublishedServerParent ********/
|
||||
|
||||
NS_IMPL_ISUPPORTS(FlyWebPublishedServerParent, nsIDOMEventListener)
|
||||
|
||||
FlyWebPublishedServerParent::FlyWebPublishedServerParent(const nsAString& aName,
|
||||
const FlyWebPublishOptions& aOptions)
|
||||
: mActorDestroyed(false)
|
||||
, mNextRequestId(1)
|
||||
{
|
||||
LOG_I("FlyWebPublishedServerParent::FlyWebPublishedServerParent(%p)", this);
|
||||
|
||||
RefPtr<FlyWebService> service = FlyWebService::GetOrCreate();
|
||||
if (!service) {
|
||||
Unused << SendServerReady(NS_ERROR_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<FlyWebPublishPromise> mozPromise =
|
||||
service->PublishServer(aName, aOptions, nullptr);
|
||||
if (!mozPromise) {
|
||||
Unused << SendServerReady(NS_ERROR_FAILURE);
|
||||
return;
|
||||
}
|
||||
|
||||
RefPtr<FlyWebPublishedServerParent> self = this;
|
||||
|
||||
mozPromise->Then(
|
||||
AbstractThread::MainThread(),
|
||||
__func__,
|
||||
[this, self] (FlyWebPublishedServer* aServer) {
|
||||
mPublishedServer = static_cast<FlyWebPublishedServerImpl*>(aServer);
|
||||
if (mActorDestroyed) {
|
||||
mPublishedServer->Close();
|
||||
return;
|
||||
}
|
||||
|
||||
mPublishedServer->AddEventListener(NS_LITERAL_STRING("fetch"),
|
||||
this, false, false, 2);
|
||||
mPublishedServer->AddEventListener(NS_LITERAL_STRING("websocket"),
|
||||
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;
|
||||
}
|
||||
|
||||
if (type.EqualsLiteral("websocket")) {
|
||||
RefPtr<InternalRequest> request =
|
||||
static_cast<FlyWebWebSocketEvent*>(aEvent)->Request()->GetInternalRequest();
|
||||
uint64_t id = mNextRequestId++;
|
||||
mPendingRequests.Put(id, request);
|
||||
|
||||
nsTArray<PNeckoParent*> neckoParents;
|
||||
Manager()->ManagedPNeckoParent(neckoParents);
|
||||
if (neckoParents.Length() != 1) {
|
||||
MOZ_CRASH("Expected exactly 1 PNeckoParent instance per PNeckoChild");
|
||||
}
|
||||
|
||||
RefPtr<TransportProviderParent> provider =
|
||||
static_cast<TransportProviderParent*>(
|
||||
neckoParents[0]->SendPTransportProviderConstructor());
|
||||
|
||||
IPCInternalRequest ipcReq;
|
||||
request->ToIPC(&ipcReq);
|
||||
Unused << SendWebSocketRequest(ipcReq, id, provider);
|
||||
|
||||
mPendingTransportProviders.Put(id, provider.forget());
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
MOZ_CRASH("Unknown event type");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
FlyWebPublishedServerParent::RecvFetchResponse(const IPCInternalResponse& aResponse,
|
||||
const uint64_t& aRequestId)
|
||||
{
|
||||
MOZ_ASSERT(!mActorDestroyed);
|
||||
|
||||
RefPtr<InternalRequest> request;
|
||||
mPendingRequests.Remove(aRequestId, getter_AddRefs(request));
|
||||
if (!request) {
|
||||
static_cast<ContentParent*>(Manager())->KillHard("unknown request id");
|
||||
return false;
|
||||
}
|
||||
|
||||
RefPtr<InternalResponse> response = InternalResponse::FromIPC(aResponse);
|
||||
|
||||
mPublishedServer->OnFetchResponse(request, response);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
FlyWebPublishedServerParent::RecvWebSocketResponse(const IPCInternalResponse& aResponse,
|
||||
const uint64_t& aRequestId)
|
||||
{
|
||||
MOZ_ASSERT(!mActorDestroyed);
|
||||
|
||||
mPendingTransportProviders.Remove(aRequestId);
|
||||
|
||||
RefPtr<InternalRequest> request;
|
||||
mPendingRequests.Remove(aRequestId, getter_AddRefs(request));
|
||||
if (!request) {
|
||||
static_cast<ContentParent*>(Manager())->KillHard("unknown websocket request id");
|
||||
return false;
|
||||
}
|
||||
|
||||
RefPtr<InternalResponse> response = InternalResponse::FromIPC(aResponse);
|
||||
|
||||
mPublishedServer->OnWebSocketResponse(request, response);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
FlyWebPublishedServerParent::RecvWebSocketAccept(const nsString& aProtocol,
|
||||
const uint64_t& aRequestId)
|
||||
{
|
||||
MOZ_ASSERT(!mActorDestroyed);
|
||||
|
||||
RefPtr<TransportProviderParent> providerIPC;
|
||||
mPendingTransportProviders.Remove(aRequestId, getter_AddRefs(providerIPC));
|
||||
|
||||
RefPtr<InternalRequest> request;
|
||||
mPendingRequests.Remove(aRequestId, getter_AddRefs(request));
|
||||
|
||||
if (!request || !providerIPC) {
|
||||
static_cast<ContentParent*>(Manager())->KillHard("unknown websocket request id");
|
||||
return false;
|
||||
}
|
||||
|
||||
Optional<nsAString> protocol;
|
||||
if (!aProtocol.IsVoid()) {
|
||||
protocol = &aProtocol;
|
||||
}
|
||||
|
||||
ErrorResult result;
|
||||
nsCOMPtr<nsITransportProvider> providerServer =
|
||||
mPublishedServer->OnWebSocketAcceptInternal(request, protocol, result);
|
||||
if (result.Failed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
providerServer->SetListener(providerIPC);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebPublishedServerParent::ActorDestroy(ActorDestroyReason aWhy)
|
||||
{
|
||||
LOG_I("FlyWebPublishedServerParent::ActorDestroy(%p)", this);
|
||||
|
||||
mActorDestroyed = true;
|
||||
}
|
||||
|
||||
bool
|
||||
FlyWebPublishedServerParent::Recv__delete__()
|
||||
{
|
||||
LOG_I("FlyWebPublishedServerParent::Recv__delete__(%p)", this);
|
||||
MOZ_ASSERT(!mActorDestroyed);
|
||||
|
||||
if (mPublishedServer) {
|
||||
mPublishedServer->RemoveEventListener(NS_LITERAL_STRING("fetch"),
|
||||
this, false);
|
||||
mPublishedServer->RemoveEventListener(NS_LITERAL_STRING("websocket"),
|
||||
this, false);
|
||||
mPublishedServer->RemoveEventListener(NS_LITERAL_STRING("close"),
|
||||
this, false);
|
||||
mPublishedServer->Close();
|
||||
mPublishedServer = nullptr;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
|
||||
|
|
@ -1,109 +0,0 @@
|
|||
/* -*- 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_FlyWebPublishedServer_h
|
||||
#define mozilla_dom_FlyWebPublishedServer_h
|
||||
|
||||
#include "mozilla/DOMEventTargetHelper.h"
|
||||
#include "mozilla/MozPromise.h"
|
||||
|
||||
class nsPIDOMWindowInner;
|
||||
class nsITransportProvider;
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
class ErrorResult;
|
||||
|
||||
namespace dom {
|
||||
|
||||
class InternalResponse;
|
||||
class InternalRequest;
|
||||
class WebSocket;
|
||||
struct FlyWebPublishOptions;
|
||||
class FlyWebPublishedServer;
|
||||
|
||||
typedef MozPromise<RefPtr<FlyWebPublishedServer>, nsresult, false>
|
||||
FlyWebPublishPromise;
|
||||
|
||||
class FlyWebPublishedServer : public mozilla::DOMEventTargetHelper
|
||||
{
|
||||
public:
|
||||
FlyWebPublishedServer(nsPIDOMWindowInner* aOwner,
|
||||
const nsAString& aName,
|
||||
const FlyWebPublishOptions& aOptions);
|
||||
|
||||
virtual void LastRelease() override;
|
||||
|
||||
virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
uint64_t OwnerWindowID() const {
|
||||
return mOwnerWindowID;
|
||||
}
|
||||
|
||||
void GetName(nsAString& aName)
|
||||
{
|
||||
aName = mName;
|
||||
}
|
||||
nsAString& Name()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
void GetUiUrl(nsAString& aUiUrl)
|
||||
{
|
||||
aUiUrl = mUiUrl;
|
||||
}
|
||||
|
||||
virtual void PermissionGranted(bool aGranted) = 0;
|
||||
|
||||
virtual void OnFetchResponse(InternalRequest* aRequest,
|
||||
InternalResponse* aResponse) = 0;
|
||||
already_AddRefed<WebSocket>
|
||||
OnWebSocketAccept(InternalRequest* aConnectRequest,
|
||||
const Optional<nsAString>& aProtocol,
|
||||
ErrorResult& aRv);
|
||||
virtual void OnWebSocketResponse(InternalRequest* aConnectRequest,
|
||||
InternalResponse* aResponse) = 0;
|
||||
virtual already_AddRefed<nsITransportProvider>
|
||||
OnWebSocketAcceptInternal(InternalRequest* aConnectRequest,
|
||||
const Optional<nsAString>& aProtocol,
|
||||
ErrorResult& aRv) = 0;
|
||||
|
||||
virtual void Close();
|
||||
|
||||
void FireFetchEvent(InternalRequest* aRequest);
|
||||
void FireWebsocketEvent(InternalRequest* aConnectRequest);
|
||||
void PublishedServerStarted(nsresult aStatus);
|
||||
|
||||
IMPL_EVENT_HANDLER(fetch)
|
||||
IMPL_EVENT_HANDLER(websocket)
|
||||
IMPL_EVENT_HANDLER(close)
|
||||
|
||||
already_AddRefed<FlyWebPublishPromise>
|
||||
GetPublishPromise()
|
||||
{
|
||||
return mPublishPromise.Ensure(__func__);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ~FlyWebPublishedServer()
|
||||
{
|
||||
MOZ_ASSERT(!mIsRegistered, "Subclass dtor forgot to call Close()");
|
||||
}
|
||||
|
||||
uint64_t mOwnerWindowID;
|
||||
MozPromiseHolder<FlyWebPublishPromise> mPublishPromise;
|
||||
|
||||
nsString mName;
|
||||
nsString mUiUrl;
|
||||
|
||||
bool mIsRegistered;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_FlyWebPublishedServer_h
|
||||
|
|
@ -1,172 +0,0 @@
|
|||
/* -*- 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_FlyWebPublishedServerIPC_h
|
||||
#define mozilla_dom_FlyWebPublishedServerIPC_h
|
||||
|
||||
#include "HttpServer.h"
|
||||
#include "mozilla/dom/FlyWebPublishedServer.h"
|
||||
#include "mozilla/dom/PFlyWebPublishedServerParent.h"
|
||||
#include "mozilla/dom/PFlyWebPublishedServerChild.h"
|
||||
#include "mozilla/MozPromise.h"
|
||||
#include "nsICancelable.h"
|
||||
#include "nsIDOMEventListener.h"
|
||||
#include "nsISupportsImpl.h"
|
||||
|
||||
class nsPIDOMWindowInner;
|
||||
|
||||
namespace mozilla {
|
||||
namespace net {
|
||||
class TransportProviderParent;
|
||||
class TransportProviderChild;
|
||||
}
|
||||
|
||||
namespace dom {
|
||||
|
||||
class FlyWebPublishedServerParent;
|
||||
|
||||
class FlyWebPublishedServerImpl final : public FlyWebPublishedServer
|
||||
, public HttpServerListener
|
||||
{
|
||||
public:
|
||||
FlyWebPublishedServerImpl(nsPIDOMWindowInner* aOwner,
|
||||
const nsAString& aName,
|
||||
const FlyWebPublishOptions& aOptions);
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
int32_t Port()
|
||||
{
|
||||
return mHttpServer ? mHttpServer->GetPort() : 0;
|
||||
}
|
||||
void GetCertKey(nsACString& aKey) {
|
||||
if (mHttpServer) {
|
||||
mHttpServer->GetCertKey(aKey);
|
||||
} else {
|
||||
aKey.Truncate();
|
||||
}
|
||||
}
|
||||
|
||||
virtual void PermissionGranted(bool aGranted) override;
|
||||
virtual void OnFetchResponse(InternalRequest* aRequest,
|
||||
InternalResponse* aResponse) override;
|
||||
virtual void OnWebSocketResponse(InternalRequest* aConnectRequest,
|
||||
InternalResponse* aResponse) override;
|
||||
virtual already_AddRefed<nsITransportProvider>
|
||||
OnWebSocketAcceptInternal(InternalRequest* aConnectRequest,
|
||||
const Optional<nsAString>& aProtocol,
|
||||
ErrorResult& aRv) override;
|
||||
|
||||
void SetCancelRegister(nsICancelable* aCancelRegister)
|
||||
{
|
||||
mMDNSCancelRegister = aCancelRegister;
|
||||
}
|
||||
|
||||
virtual void Close() override;
|
||||
|
||||
// HttpServerListener
|
||||
virtual void OnServerStarted(nsresult aStatus) override;
|
||||
virtual void OnRequest(InternalRequest* aRequest) override
|
||||
{
|
||||
FireFetchEvent(aRequest);
|
||||
}
|
||||
virtual void OnWebSocket(InternalRequest* aConnectRequest) override
|
||||
{
|
||||
FireWebsocketEvent(aConnectRequest);
|
||||
}
|
||||
virtual void OnServerClose() override
|
||||
{
|
||||
mHttpServer = nullptr;
|
||||
Close();
|
||||
}
|
||||
|
||||
private:
|
||||
~FlyWebPublishedServerImpl() {}
|
||||
|
||||
RefPtr<HttpServer> mHttpServer;
|
||||
nsCOMPtr<nsICancelable> mMDNSCancelRegister;
|
||||
RefPtr<FlyWebPublishedServerParent> mServerParent;
|
||||
};
|
||||
|
||||
class FlyWebPublishedServerChild final : public FlyWebPublishedServer
|
||||
, public PFlyWebPublishedServerChild
|
||||
{
|
||||
public:
|
||||
FlyWebPublishedServerChild(nsPIDOMWindowInner* aOwner,
|
||||
const nsAString& aName,
|
||||
const FlyWebPublishOptions& aOptions);
|
||||
|
||||
virtual void PermissionGranted(bool aGranted) override;
|
||||
virtual bool RecvServerReady(const nsresult& aStatus) override;
|
||||
virtual bool RecvServerClose() override;
|
||||
virtual bool RecvFetchRequest(const IPCInternalRequest& aRequest,
|
||||
const uint64_t& aRequestId) override;
|
||||
virtual bool RecvWebSocketRequest(const IPCInternalRequest& aRequest,
|
||||
const uint64_t& aRequestId,
|
||||
PTransportProviderChild* aProvider) override;
|
||||
|
||||
virtual void OnFetchResponse(InternalRequest* aRequest,
|
||||
InternalResponse* aResponse) override;
|
||||
virtual void OnWebSocketResponse(InternalRequest* aConnectRequest,
|
||||
InternalResponse* aResponse) override;
|
||||
virtual already_AddRefed<nsITransportProvider>
|
||||
OnWebSocketAcceptInternal(InternalRequest* aConnectRequest,
|
||||
const Optional<nsAString>& aProtocol,
|
||||
ErrorResult& aRv) override;
|
||||
|
||||
virtual void Close() override;
|
||||
|
||||
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
|
||||
|
||||
private:
|
||||
~FlyWebPublishedServerChild() {}
|
||||
|
||||
nsDataHashtable<nsRefPtrHashKey<InternalRequest>, uint64_t> mPendingRequests;
|
||||
nsRefPtrHashtable<nsUint64HashKey, TransportProviderChild>
|
||||
mPendingTransportProviders;
|
||||
bool mActorExists;
|
||||
};
|
||||
|
||||
class FlyWebPublishedServerParent final : public PFlyWebPublishedServerParent
|
||||
, public nsIDOMEventListener
|
||||
{
|
||||
public:
|
||||
FlyWebPublishedServerParent(const nsAString& aName,
|
||||
const FlyWebPublishOptions& aOptions);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIDOMEVENTLISTENER
|
||||
|
||||
private:
|
||||
virtual void
|
||||
ActorDestroy(ActorDestroyReason aWhy) override;
|
||||
|
||||
virtual bool
|
||||
Recv__delete__() override;
|
||||
virtual bool
|
||||
RecvFetchResponse(const IPCInternalResponse& aResponse,
|
||||
const uint64_t& aRequestId) override;
|
||||
virtual bool
|
||||
RecvWebSocketResponse(const IPCInternalResponse& aResponse,
|
||||
const uint64_t& aRequestId) override;
|
||||
virtual bool
|
||||
RecvWebSocketAccept(const nsString& aProtocol,
|
||||
const uint64_t& aRequestId) override;
|
||||
|
||||
~FlyWebPublishedServerParent() {}
|
||||
|
||||
bool mActorDestroyed;
|
||||
uint64_t mNextRequestId;
|
||||
nsRefPtrHashtable<nsUint64HashKey, InternalRequest> mPendingRequests;
|
||||
nsRefPtrHashtable<nsUint64HashKey, TransportProviderParent>
|
||||
mPendingTransportProviders;
|
||||
RefPtr<FlyWebPublishedServerImpl> mPublishedServer;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_FlyWebPublishedServerIPC_h
|
||||
|
|
@ -1,141 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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/EventBinding.h"
|
||||
#include "mozilla/dom/FlyWebFetchEventBinding.h"
|
||||
#include "mozilla/dom/FlyWebPublishedServer.h"
|
||||
#include "mozilla/dom/FlyWebServerEvents.h"
|
||||
#include "mozilla/dom/FlyWebWebSocketEventBinding.h"
|
||||
#include "mozilla/dom/Nullable.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/Response.h"
|
||||
|
||||
#include "js/GCAPI.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(FlyWebFetchEvent)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(FlyWebFetchEvent, Event)
|
||||
NS_IMPL_RELEASE_INHERITED(FlyWebFetchEvent, Event)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(FlyWebFetchEvent, Event)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRequest)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN_INHERITED(FlyWebFetchEvent, Event)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(FlyWebFetchEvent, Event)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRequest)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(FlyWebFetchEvent)
|
||||
NS_INTERFACE_MAP_END_INHERITING(Event)
|
||||
|
||||
FlyWebFetchEvent::FlyWebFetchEvent(FlyWebPublishedServer* aServer,
|
||||
class Request* aRequest,
|
||||
InternalRequest* aInternalRequest)
|
||||
: Event(aServer, nullptr, nullptr)
|
||||
, mRequest(aRequest)
|
||||
, mInternalRequest(aInternalRequest)
|
||||
, mServer(aServer)
|
||||
, mResponded(false)
|
||||
{
|
||||
MOZ_ASSERT(aServer);
|
||||
MOZ_ASSERT(aRequest);
|
||||
MOZ_ASSERT(aInternalRequest);
|
||||
}
|
||||
|
||||
FlyWebFetchEvent::~FlyWebFetchEvent()
|
||||
{
|
||||
}
|
||||
|
||||
JSObject*
|
||||
FlyWebFetchEvent::WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return FlyWebFetchEventBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebFetchEvent::RespondWith(Promise& aArg, ErrorResult& aRv)
|
||||
{
|
||||
if (mResponded) {
|
||||
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return;
|
||||
}
|
||||
|
||||
mResponded = true;
|
||||
|
||||
aArg.AppendNativeHandler(this);
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebFetchEvent::ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue)
|
||||
{
|
||||
RefPtr<Response> response;
|
||||
if (aValue.isObject()) {
|
||||
UNWRAP_OBJECT(Response, &aValue.toObject(), response);
|
||||
}
|
||||
|
||||
RefPtr<InternalResponse> intResponse;
|
||||
if (response && response->Type() != ResponseType::Opaque) {
|
||||
intResponse = response->GetInternalResponse();
|
||||
}
|
||||
|
||||
if (!intResponse) {
|
||||
intResponse = InternalResponse::NetworkError();
|
||||
}
|
||||
|
||||
NotifyServer(intResponse);
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebFetchEvent::NotifyServer(InternalResponse* aResponse)
|
||||
{
|
||||
mServer->OnFetchResponse(mInternalRequest, aResponse);
|
||||
}
|
||||
|
||||
void
|
||||
FlyWebFetchEvent::RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue)
|
||||
{
|
||||
RefPtr<InternalResponse> err = InternalResponse::NetworkError();
|
||||
|
||||
NotifyServer(err);
|
||||
}
|
||||
|
||||
JSObject*
|
||||
FlyWebWebSocketEvent::WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return FlyWebWebSocketEventBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
already_AddRefed<WebSocket>
|
||||
FlyWebWebSocketEvent::Accept(const Optional<nsAString>& aProtocol,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
if (mResponded) {
|
||||
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
mResponded = true;
|
||||
|
||||
return mServer->OnWebSocketAccept(mInternalRequest, aProtocol, aRv);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
FlyWebWebSocketEvent::NotifyServer(InternalResponse* aResponse)
|
||||
{
|
||||
mServer->OnWebSocketResponse(mInternalRequest, aResponse);
|
||||
}
|
||||
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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_FlyWebFetchEvent_h
|
||||
#define mozilla_dom_FlyWebFetchEvent_h
|
||||
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "mozilla/dom/BindingUtils.h"
|
||||
#include "mozilla/dom/Event.h"
|
||||
#include "mozilla/dom/FlyWebFetchEventBinding.h"
|
||||
#include "mozilla/dom/PromiseNativeHandler.h"
|
||||
#include "mozilla/dom/WebSocket.h"
|
||||
|
||||
struct JSContext;
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class Request;
|
||||
class Response;
|
||||
class FlyWebPublishedServer;
|
||||
class InternalRequest;
|
||||
class InternalResponse;
|
||||
|
||||
class FlyWebFetchEvent : public Event
|
||||
, public PromiseNativeHandler
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(FlyWebFetchEvent, Event)
|
||||
|
||||
virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
virtual void
|
||||
ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override;
|
||||
virtual void
|
||||
RejectedCallback(JSContext* aCx, JS::Handle<JS::Value> aValue) override;
|
||||
|
||||
class Request* Request() const
|
||||
{
|
||||
return mRequest;
|
||||
}
|
||||
|
||||
void RespondWith(Promise& aArg, ErrorResult& aRv);
|
||||
|
||||
FlyWebFetchEvent(FlyWebPublishedServer* aServer,
|
||||
class Request* aRequest,
|
||||
InternalRequest* aInternalRequest);
|
||||
|
||||
protected:
|
||||
virtual ~FlyWebFetchEvent();
|
||||
|
||||
virtual void NotifyServer(InternalResponse* aResponse);
|
||||
|
||||
RefPtr<class Request> mRequest;
|
||||
RefPtr<InternalRequest> mInternalRequest;
|
||||
RefPtr<FlyWebPublishedServer> mServer;
|
||||
|
||||
bool mResponded;
|
||||
};
|
||||
|
||||
class FlyWebWebSocketEvent final : public FlyWebFetchEvent
|
||||
{
|
||||
public:
|
||||
FlyWebWebSocketEvent(FlyWebPublishedServer* aServer,
|
||||
class Request* aRequest,
|
||||
InternalRequest* aInternalRequest)
|
||||
: FlyWebFetchEvent(aServer, aRequest, aInternalRequest)
|
||||
{}
|
||||
|
||||
virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
already_AddRefed<WebSocket> Accept(const Optional<nsAString>& aProtocol,
|
||||
ErrorResult& aRv);
|
||||
|
||||
private:
|
||||
~FlyWebWebSocketEvent() {};
|
||||
|
||||
virtual void NotifyServer(InternalResponse* aResponse) override;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_FlyWebFetchEvent_h
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,113 +0,0 @@
|
|||
/* -*- 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_FlyWebService_h
|
||||
#define mozilla_dom_FlyWebService_h
|
||||
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "nsIProtocolHandler.h"
|
||||
#include "nsDataHashtable.h"
|
||||
#include "nsClassHashtable.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "mozilla/MozPromise.h"
|
||||
#include "mozilla/ReentrantMonitor.h"
|
||||
#include "mozilla/dom/FlyWebDiscoveryManagerBinding.h"
|
||||
#include "nsITimer.h"
|
||||
#include "nsICancelable.h"
|
||||
#include "nsIDNSServiceDiscovery.h"
|
||||
|
||||
class nsPIDOMWindowInner;
|
||||
class nsIProxyInfo;
|
||||
class nsISocketTransport;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
struct FlyWebPublishOptions;
|
||||
struct FlyWebFilter;
|
||||
class FlyWebPublishedServer;
|
||||
class FlyWebPublishedServerImpl;
|
||||
class FlyWebPairingCallback;
|
||||
class FlyWebDiscoveryManager;
|
||||
class FlyWebMDNSService;
|
||||
|
||||
typedef MozPromise<RefPtr<FlyWebPublishedServer>, nsresult, false>
|
||||
FlyWebPublishPromise;
|
||||
|
||||
class FlyWebService final : public nsIObserver
|
||||
{
|
||||
friend class FlyWebMDNSService;
|
||||
public:
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
static FlyWebService* GetExisting();
|
||||
static FlyWebService* GetOrCreate();
|
||||
static already_AddRefed<FlyWebService> GetOrCreateAddRefed()
|
||||
{
|
||||
return do_AddRef(GetOrCreate());
|
||||
}
|
||||
|
||||
already_AddRefed<FlyWebPublishPromise>
|
||||
PublishServer(const nsAString& aName,
|
||||
const FlyWebPublishOptions& aOptions,
|
||||
nsPIDOMWindowInner* aWindow);
|
||||
|
||||
void UnregisterServer(FlyWebPublishedServer* aServer);
|
||||
|
||||
bool HasConnectionOrServer(uint64_t aWindowID);
|
||||
|
||||
void ListDiscoveredServices(nsTArray<FlyWebDiscoveredService>& aServices);
|
||||
void PairWithService(const nsAString& aServiceId, FlyWebPairingCallback& aCallback);
|
||||
nsresult CreateTransportForHost(const char **types,
|
||||
uint32_t typeCount,
|
||||
const nsACString &host,
|
||||
int32_t port,
|
||||
const nsACString &hostRoute,
|
||||
int32_t portRoute,
|
||||
nsIProxyInfo *proxyInfo,
|
||||
nsISocketTransport **result);
|
||||
|
||||
already_AddRefed<FlyWebPublishedServer> FindPublishedServerByName(
|
||||
const nsAString& aName);
|
||||
|
||||
void RegisterDiscoveryManager(FlyWebDiscoveryManager* aDiscoveryManager);
|
||||
void UnregisterDiscoveryManager(FlyWebDiscoveryManager* aDiscoveryManager);
|
||||
|
||||
// Should only be called by FlyWebPublishedServerImpl
|
||||
void StartDiscoveryOf(FlyWebPublishedServerImpl* aServer);
|
||||
|
||||
private:
|
||||
FlyWebService();
|
||||
~FlyWebService();
|
||||
|
||||
ErrorResult Init();
|
||||
|
||||
void NotifyDiscoveredServicesChanged();
|
||||
|
||||
// Might want to make these hashes for perf
|
||||
nsTArray<FlyWebPublishedServer*> mServers;
|
||||
|
||||
RefPtr<FlyWebMDNSService> mMDNSHttpService;
|
||||
RefPtr<FlyWebMDNSService> mMDNSFlywebService;
|
||||
|
||||
struct PairedInfo
|
||||
{
|
||||
FlyWebPairedService mService;
|
||||
nsCOMPtr<nsIDNSServiceInfo> mDNSServiceInfo;
|
||||
};
|
||||
nsClassHashtable<nsCStringHashKey, PairedInfo>
|
||||
mPairedServiceTable;
|
||||
ReentrantMonitor mMonitor; // Protecting mPairedServiceTable
|
||||
|
||||
nsTHashtable<nsPtrHashKey<FlyWebDiscoveryManager>> mDiscoveryManagerTable;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_FlyWebService_h
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,193 +0,0 @@
|
|||
/* -*- 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_HttpServer_h
|
||||
#define mozilla_dom_HttpServer_h
|
||||
|
||||
#include "nsISupportsImpl.h"
|
||||
#include "mozilla/DOMEventTargetHelper.h"
|
||||
#include "nsITLSServerSocket.h"
|
||||
#include "nsIAsyncInputStream.h"
|
||||
#include "nsIAsyncOutputStream.h"
|
||||
#include "mozilla/Variant.h"
|
||||
#include "nsIRequestObserver.h"
|
||||
#include "mozilla/MozPromise.h"
|
||||
#include "nsITransportProvider.h"
|
||||
#include "nsILocalCertService.h"
|
||||
|
||||
class nsIX509Cert;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
extern bool
|
||||
ContainsToken(const nsCString& aList, const nsCString& aToken);
|
||||
|
||||
class InternalRequest;
|
||||
class InternalResponse;
|
||||
|
||||
class HttpServerListener
|
||||
{
|
||||
public:
|
||||
// switch to NS_INLINE_DECL_PURE_VIRTUAL_REFCOUNTING when that lands
|
||||
NS_IMETHOD_(MozExternalRefCountType) AddRef(void) = 0;
|
||||
NS_IMETHOD_(MozExternalRefCountType) Release(void) = 0;
|
||||
|
||||
virtual void OnServerStarted(nsresult aStatus) = 0;
|
||||
virtual void OnRequest(InternalRequest* aRequest) = 0;
|
||||
virtual void OnWebSocket(InternalRequest* aConnectRequest) = 0;
|
||||
virtual void OnServerClose() = 0;
|
||||
};
|
||||
|
||||
class HttpServer final : public nsIServerSocketListener,
|
||||
public nsILocalCertGetCallback
|
||||
{
|
||||
public:
|
||||
HttpServer();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISERVERSOCKETLISTENER
|
||||
NS_DECL_NSILOCALCERTGETCALLBACK
|
||||
|
||||
void Init(int32_t aPort, bool aHttps, HttpServerListener* aListener);
|
||||
|
||||
void SendResponse(InternalRequest* aRequest, InternalResponse* aResponse);
|
||||
already_AddRefed<nsITransportProvider>
|
||||
AcceptWebSocket(InternalRequest* aConnectRequest,
|
||||
const Optional<nsAString>& aProtocol,
|
||||
ErrorResult& aRv);
|
||||
void SendWebSocketResponse(InternalRequest* aConnectRequest,
|
||||
InternalResponse* aResponse);
|
||||
|
||||
void Close();
|
||||
|
||||
void GetCertKey(nsACString& aKey);
|
||||
|
||||
int32_t GetPort()
|
||||
{
|
||||
return mPort;
|
||||
}
|
||||
|
||||
private:
|
||||
~HttpServer();
|
||||
|
||||
nsresult StartServerSocket(nsIX509Cert* aCert);
|
||||
void NotifyStarted(nsresult aStatus);
|
||||
|
||||
class TransportProvider final : public nsITransportProvider
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSITRANSPORTPROVIDER
|
||||
|
||||
void SetTransport(nsISocketTransport* aTransport,
|
||||
nsIAsyncInputStream* aInput,
|
||||
nsIAsyncOutputStream* aOutput);
|
||||
|
||||
private:
|
||||
virtual ~TransportProvider();
|
||||
void MaybeNotify();
|
||||
|
||||
nsCOMPtr<nsIHttpUpgradeListener> mListener;
|
||||
nsCOMPtr<nsISocketTransport> mTransport;
|
||||
nsCOMPtr<nsIAsyncInputStream> mInput;
|
||||
nsCOMPtr<nsIAsyncOutputStream> mOutput;
|
||||
};
|
||||
|
||||
class Connection final : public nsIInputStreamCallback
|
||||
, public nsIOutputStreamCallback
|
||||
, public nsITLSServerSecurityObserver
|
||||
{
|
||||
public:
|
||||
Connection(nsISocketTransport* aTransport,
|
||||
HttpServer* aServer,
|
||||
nsresult& rv);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIINPUTSTREAMCALLBACK
|
||||
NS_DECL_NSIOUTPUTSTREAMCALLBACK
|
||||
NS_DECL_NSITLSSERVERSECURITYOBSERVER
|
||||
|
||||
bool TryHandleResponse(InternalRequest* aRequest,
|
||||
InternalResponse* aResponse);
|
||||
already_AddRefed<nsITransportProvider>
|
||||
HandleAcceptWebSocket(const Optional<nsAString>& aProtocol,
|
||||
ErrorResult& aRv);
|
||||
void HandleWebSocketResponse(InternalResponse* aResponse);
|
||||
bool HasPendingWebSocketRequest(InternalRequest* aRequest)
|
||||
{
|
||||
return aRequest == mPendingWebSocketRequest;
|
||||
}
|
||||
|
||||
void Close();
|
||||
|
||||
private:
|
||||
~Connection();
|
||||
|
||||
void SetSecurityObserver(bool aListen);
|
||||
|
||||
static nsresult ReadSegmentsFunc(nsIInputStream* aIn,
|
||||
void* aClosure,
|
||||
const char* aBuffer,
|
||||
uint32_t aToOffset,
|
||||
uint32_t aCount,
|
||||
uint32_t* aWriteCount);
|
||||
nsresult ConsumeInput(const char*& aBuffer,
|
||||
const char* aEnd);
|
||||
nsresult ConsumeLine(const char* aBuffer,
|
||||
size_t aLength);
|
||||
void MaybeAddPendingHeader();
|
||||
|
||||
void QueueResponse(InternalResponse* aResponse);
|
||||
|
||||
RefPtr<HttpServer> mServer;
|
||||
nsCOMPtr<nsISocketTransport> mTransport;
|
||||
nsCOMPtr<nsIAsyncInputStream> mInput;
|
||||
nsCOMPtr<nsIAsyncOutputStream> mOutput;
|
||||
|
||||
enum { eRequestLine, eHeaders, eBody, ePause } mState;
|
||||
RefPtr<InternalRequest> mPendingReq;
|
||||
uint32_t mPendingReqVersion;
|
||||
nsCString mInputBuffer;
|
||||
nsCString mPendingHeaderName;
|
||||
nsCString mPendingHeaderValue;
|
||||
uint32_t mRemainingBodySize;
|
||||
nsCOMPtr<nsIAsyncOutputStream> mCurrentRequestBody;
|
||||
bool mCloseAfterRequest;
|
||||
|
||||
typedef Pair<RefPtr<InternalRequest>,
|
||||
RefPtr<InternalResponse>> PendingRequest;
|
||||
nsTArray<PendingRequest> mPendingRequests;
|
||||
RefPtr<MozPromise<nsresult, bool, false>> mOutputCopy;
|
||||
|
||||
RefPtr<InternalRequest> mPendingWebSocketRequest;
|
||||
RefPtr<TransportProvider> mWebSocketTransportProvider;
|
||||
|
||||
struct OutputBuffer {
|
||||
nsCString mString;
|
||||
nsCOMPtr<nsIInputStream> mStream;
|
||||
bool mChunked;
|
||||
};
|
||||
|
||||
nsTArray<OutputBuffer> mOutputBuffers;
|
||||
};
|
||||
|
||||
friend class Connection;
|
||||
|
||||
RefPtr<HttpServerListener> mListener;
|
||||
nsCOMPtr<nsIServerSocket> mServerSocket;
|
||||
nsCOMPtr<nsIX509Cert> mCert;
|
||||
|
||||
nsTArray<RefPtr<Connection>> mConnections;
|
||||
|
||||
int32_t mPort;
|
||||
bool mHttps;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_HttpServer_h
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set sw=2 ts=8 et ft=cpp : */
|
||||
/* 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 protocol PContent;
|
||||
include protocol PSendStream;
|
||||
include protocol PFileDescriptorSet;
|
||||
include protocol PTransportProvider;
|
||||
include FetchTypes;
|
||||
include ChannelInfo;
|
||||
include PBackgroundSharedTypes;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
async protocol PFlyWebPublishedServer
|
||||
{
|
||||
manager PContent;
|
||||
|
||||
child:
|
||||
async ServerReady(nsresult aStatus);
|
||||
async FetchRequest(IPCInternalRequest aRequest, uint64_t aRequestId);
|
||||
async WebSocketRequest(IPCInternalRequest aRequest, uint64_t aRequestId,
|
||||
PTransportProvider aProvider);
|
||||
async ServerClose();
|
||||
|
||||
parent:
|
||||
async __delete__();
|
||||
|
||||
async FetchResponse(IPCInternalResponse aResponse, uint64_t aRequestId);
|
||||
async WebSocketResponse(IPCInternalResponse aResponse, uint64_t aRequestId);
|
||||
async WebSocketAccept(nsString aProtocol, uint64_t aRequestId);
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# 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/.
|
||||
|
||||
EXPORTS.mozilla.dom += [
|
||||
'FlyWebDiscoveryManager.h',
|
||||
'FlyWebPublishedServer.h',
|
||||
'FlyWebPublishedServerIPC.h',
|
||||
'FlyWebPublishOptionsIPCSerializer.h',
|
||||
'FlyWebServerEvents.h',
|
||||
'FlyWebService.h',
|
||||
'HttpServer.h',
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'FlyWebDiscoveryManager.cpp',
|
||||
'FlyWebPublishedServer.cpp',
|
||||
'FlyWebServerEvents.cpp',
|
||||
'FlyWebService.cpp',
|
||||
'HttpServer.cpp'
|
||||
]
|
||||
|
||||
IPDL_SOURCES += [
|
||||
'PFlyWebPublishedServer.ipdl',
|
||||
]
|
||||
|
||||
FINAL_LIBRARY = 'xul'
|
||||
|
||||
LOCAL_INCLUDES += [
|
||||
'/dom/base',
|
||||
'/netwerk/base',
|
||||
'/netwerk/dns',
|
||||
'/netwerk/protocol/websocket',
|
||||
'/xpcom/io'
|
||||
]
|
||||
|
||||
include('/ipc/chromium/chromium-config.mozbuild')
|
||||
|
||||
if CONFIG['GNU_CXX']:
|
||||
CXXFLAGS += ['-Wshadow']
|
||||
Loading…
Add table
Add a link
Reference in a new issue