backport 659324 664692 - prefix websocket as mozwebsocket, based on nossralf. r=sicking

This commit is contained in:
Patrick McManus 2011-07-26 09:30:14 -04:00
Родитель e5c794686e
Коммит 7b1ae9070c
11 изменённых файлов: 71 добавлений и 62 удалений

Просмотреть файл

@ -121,7 +121,7 @@ XPIDLSRCS = \
nsIXMLHttpRequest.idl \
nsIContentSecurityPolicy.idl \
nsIFrameMessageManager.idl \
nsIWebSocket.idl \
nsIMozWebSocket.idl \
nsIEventSource.idl \
$(NULL)

Просмотреть файл

@ -45,14 +45,14 @@ interface nsIScriptContext;
interface nsPIDOMWindow;
/**
* The nsIWebSocket interface enables Web applications to maintain
* The nsIMozWebSocket interface enables Web applications to maintain
* bidirectional communications with server-side processes as described in:
*
* http://dev.w3.org/html5/websockets/
*
*/
[scriptable, uuid(431aea4c-568a-470e-b876-c57a29ff0fc6)]
interface nsIWebSocket : nsISupports
[scriptable, uuid(eae76132-e4a4-4765-8494-5e136521c846)]
interface nsIMozWebSocket : nsISupports
{
readonly attribute DOMString url;
readonly attribute DOMString protocol;

Просмотреть файл

@ -374,17 +374,17 @@ nsWebSocketEstablishedConnection::Close()
// reference until the end of the method
nsRefPtr<nsWebSocketEstablishedConnection> kungfuDeathGrip = this;
if (mOwner->mReadyState == nsIWebSocket::CONNECTING) {
mOwner->SetReadyState(nsIWebSocket::CLOSING);
mOwner->SetReadyState(nsIWebSocket::CLOSED);
if (mOwner->mReadyState == nsIMozWebSocket::CONNECTING) {
mOwner->SetReadyState(nsIMozWebSocket::CLOSING);
mOwner->SetReadyState(nsIMozWebSocket::CLOSED);
Disconnect();
return NS_OK;
}
mOwner->SetReadyState(nsIWebSocket::CLOSING);
mOwner->SetReadyState(nsIMozWebSocket::CLOSING);
if (mStatus == CONN_CLOSED) {
mOwner->SetReadyState(nsIWebSocket::CLOSED);
mOwner->SetReadyState(nsIMozWebSocket::CLOSED);
Disconnect();
return NS_OK;
}
@ -508,7 +508,7 @@ nsWebSocketEstablishedConnection::OnStart(nsISupports *aContext)
mWebSocketChannel->GetProtocol(mOwner->mProtocol);
mStatus = CONN_CONNECTED_AND_READY;
mOwner->SetReadyState(nsIWebSocket::OPEN);
mOwner->SetReadyState(nsIMozWebSocket::OPEN);
return NS_OK;
}
@ -523,14 +523,14 @@ nsWebSocketEstablishedConnection::OnStop(nsISupports *aContext,
mClosedCleanly = NS_SUCCEEDED(aStatusCode);
if (aStatusCode == NS_BASE_STREAM_CLOSED &&
mOwner->mReadyState >= nsIWebSocket::CLOSING) {
mOwner->mReadyState >= nsIMozWebSocket::CLOSING) {
// don't generate an error event just because of an unclean close
aStatusCode = NS_OK;
}
if (NS_FAILED(aStatusCode)) {
ConsoleError();
if (mOwner && mOwner->mReadyState != nsIWebSocket::CONNECTING) {
if (mOwner && mOwner->mReadyState != nsIMozWebSocket::CONNECTING) {
nsresult rv =
mOwner->CreateAndDispatchSimpleEvent(NS_LITERAL_STRING("error"));
if (NS_FAILED(rv))
@ -540,7 +540,7 @@ nsWebSocketEstablishedConnection::OnStop(nsISupports *aContext,
mStatus = CONN_CLOSED;
if (mOwner) {
mOwner->SetReadyState(nsIWebSocket::CLOSED);
mOwner->SetReadyState(nsIMozWebSocket::CLOSED);
Disconnect();
}
return NS_OK;
@ -610,7 +610,7 @@ nsWebSocketEstablishedConnection::GetInterface(const nsIID &aIID,
nsWebSocket::nsWebSocket() : mKeepingAlive(PR_FALSE),
mCheckMustKeepAlive(PR_TRUE),
mTriggeredCloseEvent(PR_FALSE),
mReadyState(nsIWebSocket::CONNECTING),
mReadyState(nsIMozWebSocket::CONNECTING),
mOutgoingBufferedAmount(0),
mScriptLine(0),
mWindowID(0)
@ -659,12 +659,12 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsWebSocket,
NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mURI)
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
DOMCI_DATA(WebSocket, nsWebSocket)
DOMCI_DATA(MozWebSocket, nsWebSocket)
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(nsWebSocket)
NS_INTERFACE_MAP_ENTRY(nsIWebSocket)
NS_INTERFACE_MAP_ENTRY(nsIMozWebSocket)
NS_INTERFACE_MAP_ENTRY(nsIJSNativeInitializer)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(WebSocket)
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozWebSocket)
NS_INTERFACE_MAP_END_INHERITING(nsDOMEventTargetWrapperCache)
NS_IMPL_ADDREF_INHERITED(nsWebSocket, nsDOMEventTargetWrapperCache)
@ -925,13 +925,13 @@ nsWebSocket::SetReadyState(PRUint16 aNewReadyState)
return;
}
NS_ABORT_IF_FALSE((aNewReadyState == nsIWebSocket::OPEN) ||
(aNewReadyState == nsIWebSocket::CLOSING) ||
(aNewReadyState == nsIWebSocket::CLOSED),
NS_ABORT_IF_FALSE((aNewReadyState == nsIMozWebSocket::OPEN) ||
(aNewReadyState == nsIMozWebSocket::CLOSING) ||
(aNewReadyState == nsIMozWebSocket::CLOSED),
"unexpected readyState");
if (aNewReadyState == nsIWebSocket::OPEN) {
NS_ABORT_IF_FALSE(mReadyState == nsIWebSocket::CONNECTING,
if (aNewReadyState == nsIMozWebSocket::OPEN) {
NS_ABORT_IF_FALSE(mReadyState == nsIMozWebSocket::CONNECTING,
"unexpected readyState transition");
mReadyState = aNewReadyState;
@ -943,15 +943,15 @@ nsWebSocket::SetReadyState(PRUint16 aNewReadyState)
return;
}
if (aNewReadyState == nsIWebSocket::CLOSING) {
NS_ABORT_IF_FALSE((mReadyState == nsIWebSocket::CONNECTING) ||
(mReadyState == nsIWebSocket::OPEN),
if (aNewReadyState == nsIMozWebSocket::CLOSING) {
NS_ABORT_IF_FALSE((mReadyState == nsIMozWebSocket::CONNECTING) ||
(mReadyState == nsIMozWebSocket::OPEN),
"unexpected readyState transition");
mReadyState = aNewReadyState;
return;
}
if (aNewReadyState == nsIWebSocket::CLOSED) {
if (aNewReadyState == nsIMozWebSocket::CLOSED) {
mReadyState = aNewReadyState;
if (mConnection) {
@ -1096,7 +1096,7 @@ nsWebSocket::UpdateMustKeepAlive()
if (mListenerManager) {
switch (mReadyState)
{
case nsIWebSocket::CONNECTING:
case nsIMozWebSocket::CONNECTING:
{
if (mListenerManager->HasListenersFor(NS_LITERAL_STRING("open")) ||
mListenerManager->HasListenersFor(NS_LITERAL_STRING("message")) ||
@ -1106,8 +1106,8 @@ nsWebSocket::UpdateMustKeepAlive()
}
break;
case nsIWebSocket::OPEN:
case nsIWebSocket::CLOSING:
case nsIMozWebSocket::OPEN:
case nsIMozWebSocket::CLOSING:
{
if (mListenerManager->HasListenersFor(NS_LITERAL_STRING("message")) ||
mListenerManager->HasListenersFor(NS_LITERAL_STRING("close")) ||
@ -1117,7 +1117,7 @@ nsWebSocket::UpdateMustKeepAlive()
}
break;
case nsIWebSocket::CLOSED:
case nsIMozWebSocket::CLOSED:
{
shouldKeepAlive =
(!mTriggeredCloseEvent &&
@ -1181,7 +1181,7 @@ nsWebSocket::AddEventListener(const nsAString& aType,
}
//-----------------------------------------------------------------------------
// nsWebSocket::nsIWebSocket methods:
// nsWebSocket::nsIMozWebSocket methods:
//-----------------------------------------------------------------------------
NS_IMETHODIMP
@ -1241,7 +1241,7 @@ nsWebSocket::Send(const nsAString& aData, PRBool *aRet)
NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread");
*aRet = PR_FALSE;
if (mReadyState == nsIWebSocket::CONNECTING) {
if (mReadyState == nsIMozWebSocket::CONNECTING) {
return NS_ERROR_DOM_INVALID_STATE_ERR;
}
@ -1260,8 +1260,8 @@ nsWebSocket::Send(const nsAString& aData, PRBool *aRet)
}
}
if (mReadyState == nsIWebSocket::CLOSING ||
mReadyState == nsIWebSocket::CLOSED) {
if (mReadyState == nsIMozWebSocket::CLOSING ||
mReadyState == nsIMozWebSocket::CLOSED) {
mOutgoingBufferedAmount += NS_ConvertUTF16toUTF8(aData).Length();
return NS_OK;
}
@ -1276,12 +1276,12 @@ NS_IMETHODIMP
nsWebSocket::Close()
{
NS_ABORT_IF_FALSE(NS_IsMainThread(), "Not running on main thread");
if (mReadyState == nsIWebSocket::CLOSING ||
mReadyState == nsIWebSocket::CLOSED) {
if (mReadyState == nsIMozWebSocket::CLOSING ||
mReadyState == nsIMozWebSocket::CLOSED) {
return NS_OK;
}
if (mReadyState == nsIWebSocket::CONNECTING) {
if (mReadyState == nsIMozWebSocket::CONNECTING) {
// FailConnection() can release the object, so we keep a reference
// before calling it
nsRefPtr<nsWebSocket> kungfuDeathGrip = this;
@ -1292,7 +1292,7 @@ nsWebSocket::Close()
return NS_OK;
}
// mReadyState == nsIWebSocket::OPEN
// mReadyState == nsIMozWebSocket::OPEN
mConnection->Close();
return NS_OK;

Просмотреть файл

@ -41,7 +41,7 @@
#define nsWebSocket_h__
#include "nsISupportsUtils.h"
#include "nsIWebSocket.h"
#include "nsIMozWebSocket.h"
#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsIJSNativeInitializer.h"
@ -66,7 +66,7 @@ class nsWebSocketEstablishedConnection;
class nsWSCloseEvent;
class nsWebSocket: public nsDOMEventTargetWrapperCache,
public nsIWebSocket,
public nsIMozWebSocket,
public nsIJSNativeInitializer
{
friend class nsWSNetAddressComparator;
@ -79,7 +79,7 @@ public:
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsWebSocket,
nsDOMEventTargetWrapperCache)
NS_DECL_NSIWEBSOCKET
NS_DECL_NSIMOZWEBSOCKET
// nsIJSNativeInitializer
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aContext,

Просмотреть файл

@ -43,10 +43,12 @@
* 21. see bug 572975 - same as test 17, but delete strong event listeners when
* receiving the message event;
* 22. server takes too long to establish the ws connection;
* 23. see bug 664692 - feature detection should detect MozWebSocket but not
* WebSocket on window object;
*/
var first_test = 1;
var last_test = 22;
var last_test = 23;
var current_test = first_test;
@ -97,9 +99,9 @@ function CreateTestWS(ws_location, ws_protocol)
try {
if (ws_protocol == undefined) {
ws = new WebSocket(ws_location);
ws = new MozWebSocket(ws_location);
} else {
ws = new WebSocket(ws_location, ws_protocol);
ws = new MozWebSocket(ws_location, ws_protocol);
}
@ -473,7 +475,7 @@ var status_test17 = "not started";
window._test17 = function()
{
var local_ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test-17");
var local_ws = new MozWebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test-17");
local_ws._testNumber = "local17";
local_ws._testNumber = current_test++;
@ -546,7 +548,7 @@ function test19()
window._test20 = function()
{
var local_ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test-20");
var local_ws = new MozWebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test-20");
local_ws._testNumber = "local20";
local_ws._testNumber = current_test++;
@ -575,7 +577,7 @@ var timeoutTest21;
window._test21 = function()
{
var local_ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test-21");
var local_ws = new MozWebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket", "test-21");
local_ws._testNumber = current_test++;
local_ws.onopen = function(e)
@ -631,6 +633,13 @@ function test22()
};
}
function test23()
{
is(false, "WebSocket" in window, "WebSocket shouldn't be available on window object");
is(true, "MozWebSocket" in window, "MozWebSocket should be available on window object");
doTest(24);
}
function finishWSTest()
{
for (i = 0; i < all_ws.length; ++i) {

Просмотреть файл

@ -32,7 +32,7 @@ function finishWSTest() {
function testWebSocket () {
var url = "ws://mochi.test:8888/tests/content/base/test/file_websocket_basic";
ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket_basic", "test");
ws = new MozWebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket_basic", "test");
is(ws.url, url, "Wrong Websocket.url!");
ws.onopen = function(e) {
for (var i = 0; i < params.length; ++i) {
@ -57,7 +57,7 @@ function testWebSocket () {
}
function testWebSocket2() {
ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket_basic", "test");
ws = new MozWebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket_basic", "test");
var testCount = 1000; // Send lots of messages
var messageCount = 0;
var testMessage = "test message";
@ -87,7 +87,7 @@ function testWebSocket2() {
}
function testWebSocket3() {
ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket_basic", "test");
ws = new MozWebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket_basic", "test");
var testCount = 100; // Send lots of messages
var messageCount = 0;
var testMessage = "test message";
@ -119,7 +119,7 @@ function testWebSocket3() {
}
function testWebSocket4() {
ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket_basic", "test");
ws = new MozWebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket_basic", "test");
// String length = (10,000 - 1) * 23 = 229,977 = almost 225 KiB.
var longString = new Array(10000).join("-huge websocket message");
ws.onopen = function(e) {
@ -146,7 +146,7 @@ function testWebSocket4() {
}
function testWebSocket5() {
ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket_basic", "test");
ws = new MozWebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket_basic", "test");
ws.onopen = function(e) {
this.close();
}

Просмотреть файл

@ -19,7 +19,7 @@
var ws;
function testWebSocket () {
ws = new WebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket_hello");
ws = new MozWebSocket("ws://mochi.test:8888/tests/content/base/test/file_websocket_hello");
ws.onopen = function(e) {
ws.send("data");
}

Просмотреть файл

@ -1474,7 +1474,7 @@ static nsDOMClassInfoData sClassInfoData[] = {
NS_DEFINE_CLASSINFO_DATA(DesktopNotificationCenter, nsDOMGenericSH,
DOM_DEFAULT_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(WebSocket, nsEventTargetSH,
NS_DEFINE_CLASSINFO_DATA(MozWebSocket, nsEventTargetSH,
EVENTTARGET_SCRIPTABLE_FLAGS)
NS_DEFINE_CLASSINFO_DATA(CloseEvent, nsDOMGenericSH,
@ -1543,7 +1543,7 @@ static const nsContractIDMapData kConstructorMap[] =
NS_DEFINE_CONSTRUCTOR_DATA(FormData, NS_FORMDATA_CONTRACTID)
NS_DEFINE_CONSTRUCTOR_DATA(XMLSerializer, NS_XMLSERIALIZER_CONTRACTID)
NS_DEFINE_CONSTRUCTOR_DATA(XMLHttpRequest, NS_XMLHTTPREQUEST_CONTRACTID)
NS_DEFINE_CONSTRUCTOR_DATA(WebSocket, NS_WEBSOCKET_CONTRACTID)
NS_DEFINE_CONSTRUCTOR_DATA(MozWebSocket, NS_WEBSOCKET_CONTRACTID)
NS_DEFINE_CONSTRUCTOR_DATA(XPathEvaluator, NS_XPATH_EVALUATOR_CONTRACTID)
NS_DEFINE_CONSTRUCTOR_DATA(XSLTProcessor,
"@mozilla.org/document-transformer;1?type=xslt")
@ -4212,8 +4212,8 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_ENTRY(nsIDOMDesktopNotificationCenter)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(WebSocket, nsIWebSocket)
DOM_CLASSINFO_MAP_ENTRY(nsIWebSocket)
DOM_CLASSINFO_MAP_BEGIN(MozWebSocket, nsIMozWebSocket)
DOM_CLASSINFO_MAP_ENTRY(nsIMozWebSocket)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMEventTarget)
DOM_CLASSINFO_MAP_END
@ -6502,7 +6502,7 @@ nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
}
// For now don't expose web sockets unless user has explicitly enabled them
if (name_struct->mDOMClassInfoID == eDOMClassInfo_WebSocket_id) {
if (name_struct->mDOMClassInfoID == eDOMClassInfo_MozWebSocket_id) {
if (!nsWebSocket::PrefEnabled()) {
return NS_OK;
}

Просмотреть файл

@ -493,7 +493,7 @@ DOMCI_CLASS(DesktopNotification)
DOMCI_CLASS(DesktopNotificationCenter)
// WebSocket
DOMCI_CLASS(WebSocket)
DOMCI_CLASS(MozWebSocket)
DOMCI_CLASS(CloseEvent)
DOMCI_CLASS(IDBFactory)

Просмотреть файл

@ -421,7 +421,7 @@ members = [
'-nsIXMLHttpRequest.upload',
# WebSocket
'nsIWebSocket.*',
'nsIMozWebSocket.*',
# webgl
'nsIDOMWebGLRenderingContext.*',

Просмотреть файл

@ -4,13 +4,13 @@
*/
window.addEventListener("load", function () {
var ws1 = new WebSocket("ws://0.0.0.0:81");
var ws1 = new MozWebSocket("ws://0.0.0.0:81");
ws1.onopen = function() {
ws1.send("test 1");
ws1.close();
};
var ws2 = new window.frames[0].WebSocket("ws://0.0.0.0:82");
var ws2 = new window.frames[0].MozWebSocket("ws://0.0.0.0:82");
ws2.onopen = function() {
ws2.send("test 2");
ws2.close();