diff --git a/dom/flyweb/FlyWebPublishedServer.cpp b/dom/flyweb/FlyWebPublishedServer.cpp index ae358f95d8bfc..87eb2e2e5cb8c 100644 --- a/dom/flyweb/FlyWebPublishedServer.cpp +++ b/dom/flyweb/FlyWebPublishedServer.cpp @@ -17,6 +17,7 @@ #include "mozilla/Preferences.h" #include "mozilla/unused.h" #include "nsGlobalWindow.h" +#include "WebSocketChannel.h" namespace mozilla { namespace dom { @@ -111,6 +112,51 @@ FlyWebPublishedServer::PublishedServerStarted(nsresult aStatus) } } +already_AddRefed +FlyWebPublishedServer::OnWebSocketAccept(InternalRequest* aConnectRequest, + const Optional& aProtocol, + ErrorResult& aRv) +{ + MOZ_ASSERT(aConnectRequest); + + LOG_I("FlyWebPublishedServer::OnWebSocketAccept(%p)", this); + + nsCOMPtr provider = + OnWebSocketAcceptInternal(aConnectRequest, + aProtocol, + aRv); + if (aRv.Failed()) { + return nullptr; + } + MOZ_ASSERT(provider); + + nsCOMPtr window = do_QueryInterface(GetOwner()); + AutoJSContext cx; + GlobalObject global(cx, nsGlobalWindow::Cast(window)->FastGetGlobalJSObject()); + + nsAutoCString extensions, negotiatedExtensions; + aConnectRequest->Headers()-> + Get(NS_LITERAL_CSTRING("Sec-WebSocket-Extensions"), extensions, aRv); + mozilla::net::ProcessServerWebSocketExtensions(extensions, + negotiatedExtensions); + + nsCString url; + aConnectRequest->GetURL(url); + Sequence 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) @@ -166,52 +212,6 @@ FlyWebPublishedServerImpl::OnFetchResponse(InternalRequest* aRequest, } } -already_AddRefed -FlyWebPublishedServerImpl::OnWebSocketAccept(InternalRequest* aConnectRequest, - const Optional& aProtocol, - ErrorResult& aRv) -{ - MOZ_ASSERT(aConnectRequest); - - LOG_I("FlyWebPublishedMDNSServer::OnWebSocketAccept(%p)", this); - - if (!mHttpServer) { - aRv.Throw(NS_ERROR_UNEXPECTED); - return nullptr; - } - - nsAutoCString negotiatedExtensions; - nsCOMPtr provider = - mHttpServer->AcceptWebSocket(aConnectRequest, - aProtocol, - negotiatedExtensions, - aRv); - if (aRv.Failed()) { - return nullptr; - } - MOZ_ASSERT(provider); - - nsCOMPtr window = do_QueryInterface(GetOwner()); - AutoJSContext cx; - GlobalObject global(cx, nsGlobalWindow::Cast(window)->FastGetGlobalJSObject()); - - nsCString url; - aConnectRequest->GetURL(url); - Sequence 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); -} - void FlyWebPublishedServerImpl::OnWebSocketResponse(InternalRequest* aConnectRequest, InternalResponse* aResponse) @@ -226,6 +226,23 @@ FlyWebPublishedServerImpl::OnWebSocketResponse(InternalRequest* aConnectRequest, } } +already_AddRefed +FlyWebPublishedServerImpl::OnWebSocketAcceptInternal(InternalRequest* aConnectRequest, + const Optional& 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, @@ -310,12 +327,14 @@ FlyWebPublishedServerChild::OnFetchResponse(InternalRequest* aRequest, } } -already_AddRefed -FlyWebPublishedServerChild::OnWebSocketAccept(InternalRequest* aConnectRequest, - const Optional& aProtocol, - ErrorResult& aRv) +already_AddRefed +FlyWebPublishedServerChild::OnWebSocketAcceptInternal(InternalRequest* aConnectRequest, + const Optional& aProtocol, + ErrorResult& aRv) { - // Send ipdl message to parent + LOG_I("FlyWebPublishedServerChild::OnWebSocketAcceptInternal(%p)", this); + + aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); return nullptr; } diff --git a/dom/flyweb/FlyWebPublishedServer.h b/dom/flyweb/FlyWebPublishedServer.h index fa917c7cfd512..f360beed9ba61 100644 --- a/dom/flyweb/FlyWebPublishedServer.h +++ b/dom/flyweb/FlyWebPublishedServer.h @@ -11,6 +11,7 @@ #include "mozilla/MozPromise.h" class nsPIDOMWindowInner; +class nsITransportProvider; namespace mozilla { @@ -58,12 +59,16 @@ class FlyWebPublishedServer : public mozilla::DOMEventTargetHelper virtual void OnFetchResponse(InternalRequest* aRequest, InternalResponse* aResponse) = 0; - virtual already_AddRefed + already_AddRefed OnWebSocketAccept(InternalRequest* aConnectRequest, const Optional& aProtocol, - ErrorResult& aRv) = 0; + ErrorResult& aRv); virtual void OnWebSocketResponse(InternalRequest* aConnectRequest, InternalResponse* aResponse) = 0; + virtual already_AddRefed + OnWebSocketAcceptInternal(InternalRequest* aConnectRequest, + const Optional& aProtocol, + ErrorResult& aRv) = 0; virtual void Close(); @@ -82,7 +87,6 @@ class FlyWebPublishedServer : public mozilla::DOMEventTargetHelper } protected: - virtual ~FlyWebPublishedServer() { MOZ_ASSERT(!mIsRegistered, "Subclass dtor forgot to call Close()"); diff --git a/dom/flyweb/FlyWebPublishedServerIPC.h b/dom/flyweb/FlyWebPublishedServerIPC.h index 23d3b6c152ec4..9bc57b93ef6b4 100644 --- a/dom/flyweb/FlyWebPublishedServerIPC.h +++ b/dom/flyweb/FlyWebPublishedServerIPC.h @@ -47,12 +47,12 @@ class FlyWebPublishedServerImpl final : public FlyWebPublishedServer virtual void OnFetchResponse(InternalRequest* aRequest, InternalResponse* aResponse) override; - virtual already_AddRefed - OnWebSocketAccept(InternalRequest* aConnectRequest, - const Optional& aProtocol, - ErrorResult& aRv) override; virtual void OnWebSocketResponse(InternalRequest* aConnectRequest, InternalResponse* aResponse) override; + virtual already_AddRefed + OnWebSocketAcceptInternal(InternalRequest* aConnectRequest, + const Optional& aProtocol, + ErrorResult& aRv) override; void SetCancelRegister(nsICancelable* aCancelRegister) { @@ -100,12 +100,12 @@ class FlyWebPublishedServerChild final : public FlyWebPublishedServer virtual void OnFetchResponse(InternalRequest* aRequest, InternalResponse* aResponse) override; - virtual already_AddRefed - OnWebSocketAccept(InternalRequest* aConnectRequest, - const Optional& aProtocol, - ErrorResult& aRv) override; virtual void OnWebSocketResponse(InternalRequest* aConnectRequest, InternalResponse* aResponse) override; + virtual already_AddRefed + OnWebSocketAcceptInternal(InternalRequest* aConnectRequest, + const Optional& aProtocol, + ErrorResult& aRv) override; virtual void Close() override; diff --git a/dom/flyweb/HttpServer.cpp b/dom/flyweb/HttpServer.cpp index f85e573c77ad4..2b2d6800090dc 100644 --- a/dom/flyweb/HttpServer.cpp +++ b/dom/flyweb/HttpServer.cpp @@ -175,7 +175,6 @@ HttpServer::SendResponse(InternalRequest* aRequest, InternalResponse* aResponse) already_AddRefed HttpServer::AcceptWebSocket(InternalRequest* aConnectRequest, const Optional& aProtocol, - nsACString& aNegotiatedExtensions, ErrorResult& aRv) { for (Connection* conn : mConnections) { @@ -183,7 +182,7 @@ HttpServer::AcceptWebSocket(InternalRequest* aConnectRequest, continue; } nsCOMPtr provider = - conn->HandleAcceptWebSocket(aProtocol, aNegotiatedExtensions, aRv); + conn->HandleAcceptWebSocket(aProtocol, aRv); if (aRv.Failed()) { conn->Close(); } @@ -790,7 +789,6 @@ HttpServer::Connection::TryHandleResponse(InternalRequest* aRequest, already_AddRefed HttpServer::Connection::HandleAcceptWebSocket(const Optional& aProtocol, - nsACString& aNegotiatedExtensions, ErrorResult& aRv) { MOZ_ASSERT(mPendingWebSocketRequest); @@ -830,14 +828,14 @@ HttpServer::Connection::HandleAcceptWebSocket(const Optional& aProtoc } headers->Set(NS_LITERAL_CSTRING("Sec-WebSocket-Accept"), hash, aRv); - nsAutoCString extensions; + nsAutoCString extensions, negotiatedExtensions; mPendingWebSocketRequest->Headers()-> Get(NS_LITERAL_CSTRING("Sec-WebSocket-Extensions"), extensions, aRv); mozilla::net::ProcessServerWebSocketExtensions(extensions, - aNegotiatedExtensions); - if (!aNegotiatedExtensions.IsEmpty()) { + negotiatedExtensions); + if (!negotiatedExtensions.IsEmpty()) { headers->Set(NS_LITERAL_CSTRING("Sec-WebSocket-Extensions"), - aNegotiatedExtensions, aRv); + negotiatedExtensions, aRv); } RefPtr result = new TransportProvider(); diff --git a/dom/flyweb/HttpServer.h b/dom/flyweb/HttpServer.h index 747ea7f3975df..5eb93f612fe06 100644 --- a/dom/flyweb/HttpServer.h +++ b/dom/flyweb/HttpServer.h @@ -55,7 +55,6 @@ class HttpServer final : public nsIServerSocketListener, already_AddRefed AcceptWebSocket(InternalRequest* aConnectRequest, const Optional& aProtocol, - nsACString& aNegotiatedExtensions, ErrorResult& aRv); void SendWebSocketResponse(InternalRequest* aConnectRequest, InternalResponse* aResponse); @@ -113,7 +112,6 @@ class HttpServer final : public nsIServerSocketListener, InternalResponse* aResponse); already_AddRefed HandleAcceptWebSocket(const Optional& aProtocol, - nsACString& aNegotiatedExtensions, ErrorResult& aRv); void HandleWebSocketResponse(InternalResponse* aResponse); bool HasPendingWebSocketRequest(InternalRequest* aRequest)