mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Bug 562681, websockets (protocol v76), r=smaug
--HG-- extra : rebase_source : 3fd1b153d688eba6fa6ffb499bc704dd9ca2a3c2
This commit is contained in:
parent
62f3ce4818
commit
2e35f8b75b
@ -51,7 +51,7 @@ interface nsPIDOMWindow;
|
||||
* http://dev.w3.org/html5/websockets/
|
||||
*
|
||||
*/
|
||||
[scriptable, uuid(14b32727-d501-4a3b-b0f9-5d9109a0d5f0)]
|
||||
[scriptable, uuid(af0d293a-d18c-43e6-84ed-d1de5e85b885)]
|
||||
interface nsIWebSocket : nsISupports
|
||||
{
|
||||
readonly attribute DOMString URL;
|
||||
@ -59,13 +59,16 @@ interface nsIWebSocket : nsISupports
|
||||
//ready state
|
||||
const unsigned short CONNECTING = 0;
|
||||
const unsigned short OPEN = 1;
|
||||
const unsigned short CLOSED = 2;
|
||||
readonly attribute long readyState;
|
||||
const unsigned short CLOSING = 2;
|
||||
const unsigned short CLOSED = 3;
|
||||
readonly attribute unsigned short readyState;
|
||||
|
||||
readonly attribute unsigned long bufferedAmount;
|
||||
|
||||
// event handler attributes
|
||||
attribute nsIDOMEventListener onopen;
|
||||
attribute nsIDOMEventListener onmessage;
|
||||
attribute nsIDOMEventListener onerror;
|
||||
attribute nsIDOMEventListener onclose;
|
||||
|
||||
/**
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -62,15 +62,17 @@
|
||||
|
||||
#define NS_WEBSOCKET_CONTRACTID "@mozilla.org/websocket;1"
|
||||
|
||||
class nsNetAddressComparator;
|
||||
class nsWSNetAddressComparator;
|
||||
class nsWebSocketEstablishedConnection;
|
||||
class nsWSCloseEvent;
|
||||
|
||||
class nsWebSocket: public nsDOMEventTargetWrapperCache,
|
||||
public nsIWebSocket,
|
||||
public nsIJSNativeInitializer
|
||||
{
|
||||
friend class nsNetAddressComparator;
|
||||
friend class nsWSNetAddressComparator;
|
||||
friend class nsWebSocketEstablishedConnection;
|
||||
friend class nsWSCloseEvent;
|
||||
|
||||
public:
|
||||
nsWebSocket();
|
||||
@ -81,8 +83,8 @@ public:
|
||||
NS_DECL_NSIWEBSOCKET
|
||||
|
||||
// nsIJSNativeInitializer
|
||||
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* cx, JSObject* obj,
|
||||
PRUint32 argc, jsval* argv);
|
||||
NS_IMETHOD Initialize(nsISupports* aOwner, JSContext* aContext,
|
||||
JSObject* aObject, PRUint32 aArgc, jsval* aArgv);
|
||||
|
||||
static void ReleaseGlobals();
|
||||
|
||||
@ -90,9 +92,16 @@ protected:
|
||||
nsresult ParseURL(const nsString& aURL);
|
||||
nsresult SetProtocol(const nsString& aProtocol);
|
||||
nsresult EstablishConnection();
|
||||
nsresult SetReadyState(PRInt32 aNewReadyState);
|
||||
|
||||
nsresult CreateAndDispatchSimpleEvent(const nsString& aName);
|
||||
nsresult CreateAndDispatchMessageEvent(nsCString *aData);
|
||||
nsresult CreateAndDispatchCloseEvent(PRBool aWasClean);
|
||||
|
||||
// called from mConnection accordingly to the situation
|
||||
void SetReadyState(PRUint16 aNewReadyState);
|
||||
|
||||
nsRefPtr<nsDOMEventListenerWrapper> mOnOpenListener;
|
||||
nsRefPtr<nsDOMEventListenerWrapper> mOnErrorListener;
|
||||
nsRefPtr<nsDOMEventListenerWrapper> mOnMessageListener;
|
||||
nsRefPtr<nsDOMEventListenerWrapper> mOnCloseListener;
|
||||
|
||||
@ -107,7 +116,7 @@ protected:
|
||||
nsCOMPtr<nsIURI> mURI;
|
||||
nsCString mProtocol;
|
||||
|
||||
PRInt32 mReadyState;
|
||||
PRUint16 mReadyState;
|
||||
|
||||
nsCOMPtr<nsIPrincipal> mPrincipal;
|
||||
|
||||
|
@ -117,4 +117,6 @@ nsresult
|
||||
NS_NewDOMScrollAreaEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, class nsScrollAreaEvent* aEvent);
|
||||
nsresult
|
||||
NS_NewDOMTransitionEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, class nsTransitionEvent* aEvent);
|
||||
nsresult
|
||||
NS_NewDOMCloseEvent(nsIDOMEvent** aInstancePtrResult, nsPresContext* aPresContext, class nsEvent* aEvent);
|
||||
#endif // nsIPrivateDOMEvent_h__
|
||||
|
@ -83,6 +83,7 @@ CPPSRCS = \
|
||||
nsDOMScrollAreaEvent.cpp \
|
||||
nsDOMTransitionEvent.cpp \
|
||||
nsDOMPopStateEvent.cpp \
|
||||
nsDOMCloseEvent.cpp \
|
||||
$(NULL)
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a static lib.
|
||||
|
84
content/events/src/nsDOMCloseEvent.cpp
Normal file
84
content/events/src/nsDOMCloseEvent.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Wellington Fernando de Macedo.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Wellington Fernando de Macedo <wfernandom2004@gmail.com> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsDOMCloseEvent.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsDOMCloseEvent, nsDOMEvent)
|
||||
NS_IMPL_RELEASE_INHERITED(nsDOMCloseEvent, nsDOMEvent)
|
||||
|
||||
DOMCI_DATA(CloseEvent, nsDOMCloseEvent)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsDOMCloseEvent)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMCloseEvent)
|
||||
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CloseEvent)
|
||||
NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMCloseEvent::GetWasClean(PRBool *aWasClean)
|
||||
{
|
||||
*aWasClean = mWasClean;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMCloseEvent::InitCloseEvent(const nsAString& aType,
|
||||
PRBool aCanBubble,
|
||||
PRBool aCancelable,
|
||||
PRBool aWasClean)
|
||||
{
|
||||
nsresult rv = nsDOMEvent::InitEvent(aType, aCanBubble, aCancelable);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
mWasClean = aWasClean;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
NS_NewDOMCloseEvent(nsIDOMEvent** aInstancePtrResult,
|
||||
nsPresContext* aPresContext,
|
||||
nsEvent* aEvent)
|
||||
{
|
||||
nsDOMCloseEvent* it = new nsDOMCloseEvent(aPresContext, aEvent);
|
||||
if (nsnull == it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return CallQueryInterface(it, aInstancePtrResult);
|
||||
}
|
71
content/events/src/nsDOMCloseEvent.h
Normal file
71
content/events/src/nsDOMCloseEvent.h
Normal file
@ -0,0 +1,71 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Wellington Fernando de Macedo.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Wellington Fernando de Macedo <wfernandom2004@gmail.com> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsDOMCloseEvent_h__
|
||||
#define nsDOMCloseEvent_h__
|
||||
|
||||
#include "nsIDOMCloseEvent.h"
|
||||
#include "nsDOMEvent.h"
|
||||
|
||||
/**
|
||||
* Implements the CloseEvent event, used for notifying that a WebSocket
|
||||
* connection has been closed.
|
||||
*
|
||||
* See http://dev.w3.org/html5/websockets/#closeevent for further details.
|
||||
*/
|
||||
class nsDOMCloseEvent : public nsDOMEvent,
|
||||
public nsIDOMCloseEvent
|
||||
{
|
||||
public:
|
||||
nsDOMCloseEvent(nsPresContext* aPresContext, nsEvent* aEvent)
|
||||
: nsDOMEvent(aPresContext, aEvent), mWasClean(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// Forward to base class
|
||||
NS_FORWARD_TO_NSDOMEVENT
|
||||
|
||||
NS_DECL_NSIDOMCLOSEEVENT
|
||||
|
||||
private:
|
||||
PRBool mWasClean;
|
||||
};
|
||||
|
||||
#endif // nsDOMCloseEvent_h__
|
@ -826,6 +826,8 @@ nsEventDispatcher::CreateEvent(nsPresContext* aPresContext,
|
||||
return NS_NewDOMTransitionEvent(aDOMEvent, aPresContext, nsnull);
|
||||
if (aEventType.LowerCaseEqualsLiteral("popstateevent"))
|
||||
return NS_NewDOMPopStateEvent(aDOMEvent, aPresContext, nsnull);
|
||||
if (aEventType.LowerCaseEqualsLiteral("closeevent"))
|
||||
return NS_NewDOMCloseEvent(aDOMEvent, aPresContext, nsnull);
|
||||
|
||||
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
|
||||
}
|
||||
|
@ -204,6 +204,7 @@
|
||||
#include "nsIDOMSerializer.h"
|
||||
#include "nsXMLHttpRequest.h"
|
||||
#include "nsWebSocket.h"
|
||||
#include "nsIDOMCloseEvent.h"
|
||||
|
||||
// includes needed for the prototype chain interfaces
|
||||
#include "nsIDOMNavigator.h"
|
||||
@ -1400,6 +1401,9 @@ static nsDOMClassInfoData sClassInfoData[] = {
|
||||
|
||||
NS_DEFINE_CLASSINFO_DATA(WebSocket, nsEventTargetSH,
|
||||
EVENTTARGET_SCRIPTABLE_FLAGS)
|
||||
|
||||
NS_DEFINE_CLASSINFO_DATA(CloseEvent, nsDOMGenericSH,
|
||||
DOM_DEFAULT_SCRIPTABLE_FLAGS)
|
||||
};
|
||||
|
||||
// Objects that should be constructable through |new Name();|
|
||||
@ -3870,6 +3874,11 @@ nsDOMClassInfo::Init()
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMNSEventTarget)
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
DOM_CLASSINFO_MAP_BEGIN(CloseEvent, nsIDOMCloseEvent)
|
||||
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCloseEvent)
|
||||
DOM_CLASSINFO_EVENT_MAP_ENTRIES
|
||||
DOM_CLASSINFO_MAP_END
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
{
|
||||
PRUint32 i = NS_ARRAY_LENGTH(sClassInfoData);
|
||||
|
@ -475,4 +475,6 @@ DOMCI_CLASS(ContentFrameMessageManager)
|
||||
|
||||
DOMCI_CLASS(FormData)
|
||||
|
||||
// WebSocket
|
||||
DOMCI_CLASS(WebSocket)
|
||||
DOMCI_CLASS(CloseEvent)
|
||||
|
@ -84,6 +84,7 @@ XPIDLSRCS = \
|
||||
nsIDOMScrollAreaEvent.idl \
|
||||
nsIDOMTransitionEvent.idl \
|
||||
nsIDOMPopStateEvent.idl \
|
||||
nsIDOMCloseEvent.idl \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
57
dom/interfaces/events/nsIDOMCloseEvent.idl
Normal file
57
dom/interfaces/events/nsIDOMCloseEvent.idl
Normal file
@ -0,0 +1,57 @@
|
||||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Wellington Fernando de Macedo.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2010
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Wellington Fernando de Macedo <wfernandom2004@gmail.com> (original author)
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
||||
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIDOMEvent.idl"
|
||||
|
||||
/**
|
||||
* The nsIDOMCloseEvent interface is the interface to the event
|
||||
* close on a WebSocket object.
|
||||
*
|
||||
* For more information on this interface, please see
|
||||
* http://dev.w3.org/html5/websockets/#closeevent
|
||||
*/
|
||||
[scriptable, uuid(a94d4379-eba2-45f4-be3a-6cc2fa1453a8)]
|
||||
interface nsIDOMCloseEvent : nsIDOMEvent
|
||||
{
|
||||
readonly attribute boolean wasClean;
|
||||
|
||||
void initCloseEvent(in DOMString aType,
|
||||
in boolean aCanBubble,
|
||||
in boolean aCancelable,
|
||||
in boolean aWasClean);
|
||||
};
|
Loading…
Reference in New Issue
Block a user