mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 20:35:50 +00:00
bug 674905 - implement ws extensions attribute r=biesi r=sicking sr=bz
This commit is contained in:
parent
30171152e1
commit
2f338d19b9
@ -58,10 +58,11 @@ class nsString;
|
||||
* http://dev.w3.org/html5/websockets/
|
||||
*
|
||||
*/
|
||||
[scriptable, uuid(8fa080c7-934a-4040-90cb-31055798b35d)]
|
||||
[scriptable, uuid(5b124f54-7d46-4bc0-8507-e58ed22c19b9)]
|
||||
interface nsIMozWebSocket : nsISupports
|
||||
{
|
||||
readonly attribute DOMString url;
|
||||
readonly attribute DOMString extensions;
|
||||
readonly attribute DOMString protocol;
|
||||
|
||||
//ready state
|
||||
|
@ -513,6 +513,8 @@ nsWebSocketEstablishedConnection::OnStart(nsISupports *aContext)
|
||||
if (!mOwner->mRequestedProtocolList.IsEmpty())
|
||||
mWebSocketChannel->GetProtocol(mOwner->mEstablishedProtocol);
|
||||
|
||||
mWebSocketChannel->GetExtensions(mOwner->mEstablishedExtensions);
|
||||
|
||||
mStatus = CONN_CONNECTED_AND_READY;
|
||||
mOwner->SetReadyState(nsIMozWebSocket::OPEN);
|
||||
return NS_OK;
|
||||
@ -1233,6 +1235,13 @@ nsWebSocket::GetUrl(nsAString& aURL)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWebSocket::GetExtensions(nsAString& aExtensions)
|
||||
{
|
||||
CopyUTF8toUTF16(mEstablishedExtensions, aExtensions);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsWebSocket::GetProtocol(nsAString& aProtocol)
|
||||
{
|
||||
|
@ -150,6 +150,7 @@ protected:
|
||||
nsCOMPtr<nsIURI> mURI;
|
||||
nsCString mRequestedProtocolList;
|
||||
nsCString mEstablishedProtocol;
|
||||
nsCString mEstablishedExtensions;
|
||||
|
||||
PRUint16 mReadyState;
|
||||
|
||||
|
@ -60,7 +60,7 @@
|
||||
* 35. test for sending custom close code and reason
|
||||
* 36. negative test for sending out of range close code
|
||||
* 37. negative test for too long of a close reason
|
||||
* 38. reserved for extension test
|
||||
* 38. ensure extensions attribute is defined
|
||||
* 39. a basic wss:// connectivity test
|
||||
* 40. negative test for wss:// with no cert
|
||||
*/
|
||||
@ -1061,9 +1061,22 @@ function test37()
|
||||
|
||||
function test38()
|
||||
{
|
||||
ok(true, "test 38 reserved for extension test.");
|
||||
current_test++;
|
||||
doTest(39);
|
||||
var prots=["test-38"];
|
||||
|
||||
var ws = CreateTestWS("ws://mochi.test:8888/tests/content/base/test/file_websocket", prots);
|
||||
ws.onopen = function(e)
|
||||
{
|
||||
ok(true, "test 38 open");
|
||||
ok(ws.extensions != undefined, "extensions attribute defined");
|
||||
ok(ws.extensions == "deflate-stream", "extensions attribute deflate-stream");
|
||||
ws.close();
|
||||
};
|
||||
|
||||
ws.onclose = function(e)
|
||||
{
|
||||
ok(true, "test 38 close");
|
||||
doTest(39);
|
||||
};
|
||||
}
|
||||
|
||||
function test39()
|
||||
|
@ -124,6 +124,14 @@ BaseWebSocketChannel::SetLoadGroup(nsILoadGroup *aLoadGroup)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BaseWebSocketChannel::GetExtensions(nsACString &aExtensions)
|
||||
{
|
||||
LOG(("BaseWebSocketChannel::GetExtensions() %p\n", this));
|
||||
aExtensions = mNegotiatedExtensions;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BaseWebSocketChannel::GetProtocol(nsACString &aProtocol)
|
||||
{
|
||||
|
@ -72,6 +72,7 @@ class BaseWebSocketChannel : public nsIWebSocketChannel,
|
||||
NS_IMETHOD SetNotificationCallbacks(nsIInterfaceRequestor *aNotificationCallbacks);
|
||||
NS_IMETHOD GetLoadGroup(nsILoadGroup **aLoadGroup);
|
||||
NS_IMETHOD SetLoadGroup(nsILoadGroup *aLoadGroup);
|
||||
NS_IMETHOD GetExtensions(nsACString &aExtensions);
|
||||
NS_IMETHOD GetProtocol(nsACString &aProtocol);
|
||||
NS_IMETHOD SetProtocol(const nsACString &aProtocol);
|
||||
|
||||
@ -87,6 +88,7 @@ class BaseWebSocketChannel : public nsIWebSocketChannel,
|
||||
nsCString mOrigin;
|
||||
|
||||
PRBool mEncrypted;
|
||||
nsCString mNegotiatedExtensions;
|
||||
};
|
||||
|
||||
} // namespace net
|
||||
|
@ -63,7 +63,7 @@ parent:
|
||||
|
||||
child:
|
||||
// Forwarded notifications corresponding to the nsIWebSocketListener interface
|
||||
OnStart(nsCString aProtocol);
|
||||
OnStart(nsCString aProtocol, nsCString aExtensions);
|
||||
OnStop(nsresult aStatusCode);
|
||||
OnMessageAvailable(nsCString aMsg);
|
||||
OnBinaryMessageAvailable(nsCString aMsg);
|
||||
|
@ -1516,6 +1516,7 @@ WebSocketChannel::HandleExtensions()
|
||||
AbortSession(NS_ERROR_UNEXPECTED);
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
mNegotiatedExtensions = extensions;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,36 +107,43 @@ class StartEvent : public ChannelEvent
|
||||
{
|
||||
public:
|
||||
StartEvent(WebSocketChannelChild* aChild,
|
||||
const nsCString& aProtocol)
|
||||
const nsCString& aProtocol,
|
||||
const nsCString& aExtensions)
|
||||
: mChild(aChild)
|
||||
, mProtocol(aProtocol)
|
||||
, mExtensions(aExtensions)
|
||||
{}
|
||||
|
||||
void Run()
|
||||
{
|
||||
mChild->OnStart(mProtocol);
|
||||
mChild->OnStart(mProtocol, mExtensions);
|
||||
}
|
||||
private:
|
||||
WebSocketChannelChild* mChild;
|
||||
nsCString mProtocol;
|
||||
nsCString mExtensions;
|
||||
};
|
||||
|
||||
bool
|
||||
WebSocketChannelChild::RecvOnStart(const nsCString& aProtocol)
|
||||
WebSocketChannelChild::RecvOnStart(const nsCString& aProtocol,
|
||||
const nsCString& aExtensions)
|
||||
{
|
||||
if (mEventQ.ShouldEnqueue()) {
|
||||
mEventQ.Enqueue(new StartEvent(this, aProtocol));
|
||||
mEventQ.Enqueue(new StartEvent(this, aProtocol, aExtensions));
|
||||
} else {
|
||||
OnStart(aProtocol);
|
||||
OnStart(aProtocol, aExtensions);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
WebSocketChannelChild::OnStart(const nsCString& aProtocol)
|
||||
WebSocketChannelChild::OnStart(const nsCString& aProtocol,
|
||||
const nsCString& aExtensions)
|
||||
{
|
||||
LOG(("WebSocketChannelChild::RecvOnStart() %p\n", this));
|
||||
SetProtocol(aProtocol);
|
||||
mNegotiatedExtensions = aExtensions;
|
||||
|
||||
if (mListener) {
|
||||
AutoEventEnqueuer ensureSerialDispatch(mEventQ);;
|
||||
mListener->OnStart(mContext);
|
||||
|
@ -73,7 +73,7 @@ class WebSocketChannelChild : public BaseWebSocketChannel,
|
||||
void ReleaseIPDLReference();
|
||||
|
||||
private:
|
||||
bool RecvOnStart(const nsCString& aProtocol);
|
||||
bool RecvOnStart(const nsCString& aProtocol, const nsCString& aExtensions);
|
||||
bool RecvOnStop(const nsresult& aStatusCode);
|
||||
bool RecvOnMessageAvailable(const nsCString& aMsg);
|
||||
bool RecvOnBinaryMessageAvailable(const nsCString& aMsg);
|
||||
@ -81,7 +81,7 @@ class WebSocketChannelChild : public BaseWebSocketChannel,
|
||||
bool RecvOnServerClose(const PRUint16& aCode, const nsCString &aReason);
|
||||
bool RecvAsyncOpenFailed();
|
||||
|
||||
void OnStart(const nsCString& aProtocol);
|
||||
void OnStart(const nsCString& aProtocol, const nsCString& aExtensions);
|
||||
void OnStop(const nsresult& aStatusCode);
|
||||
void OnMessageAvailable(const nsCString& aMsg);
|
||||
void OnBinaryMessageAvailable(const nsCString& aMsg);
|
||||
|
@ -152,11 +152,12 @@ NS_IMETHODIMP
|
||||
WebSocketChannelParent::OnStart(nsISupports *aContext)
|
||||
{
|
||||
LOG(("WebSocketChannelParent::OnStart() %p\n", this));
|
||||
nsCAutoString protocol;
|
||||
nsCAutoString protocol, extensions;
|
||||
if (mChannel) {
|
||||
mChannel->GetProtocol(protocol);
|
||||
mChannel->GetExtensions(extensions);
|
||||
}
|
||||
if (!mIPCOpen || !SendOnStart(protocol)) {
|
||||
if (!mIPCOpen || !SendOnStart(protocol, extensions)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return NS_OK;
|
||||
|
@ -44,7 +44,7 @@ interface nsIWebSocketListener;
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(783029cf-75b5-439e-8e47-86b390202b4c)]
|
||||
[scriptable, uuid(e8ae0371-c28f-4d61-b257-514e014a4686)]
|
||||
interface nsIWebSocketChannel : nsISupports
|
||||
{
|
||||
/**
|
||||
@ -81,6 +81,11 @@ interface nsIWebSocketChannel : nsISupports
|
||||
*/
|
||||
attribute ACString protocol;
|
||||
|
||||
/**
|
||||
* Sec-Websocket-Extensions response header value
|
||||
*/
|
||||
readonly attribute ACString extensions;
|
||||
|
||||
/**
|
||||
* Asynchronously open the websocket connection. Received messages are fed
|
||||
* to the socket listener as they arrive. The socket listener's methods
|
||||
|
Loading…
Reference in New Issue
Block a user