michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set sw=2 ts=8 et tw=80 : */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsDOMDataChannel_h michael@0: #define nsDOMDataChannel_h michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/DOMEventTargetHelper.h" michael@0: #include "mozilla/dom/DataChannelBinding.h" michael@0: #include "mozilla/dom/TypedArray.h" michael@0: #include "mozilla/net/DataChannelListener.h" michael@0: #include "nsIDOMDataChannel.h" michael@0: #include "nsIInputStream.h" michael@0: michael@0: michael@0: namespace mozilla { michael@0: class DataChannel; michael@0: }; michael@0: michael@0: class nsDOMDataChannel : public mozilla::DOMEventTargetHelper, michael@0: public nsIDOMDataChannel, michael@0: public mozilla::DataChannelListener michael@0: { michael@0: public: michael@0: nsDOMDataChannel(already_AddRefed& aDataChannel, michael@0: nsPIDOMWindow* aWindow); michael@0: ~nsDOMDataChannel(); michael@0: michael@0: nsresult Init(nsPIDOMWindow* aDOMWindow); michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_NSIDOMDATACHANNEL michael@0: michael@0: NS_REALLY_FORWARD_NSIDOMEVENTTARGET(mozilla::DOMEventTargetHelper) michael@0: michael@0: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMDataChannel, michael@0: mozilla::DOMEventTargetHelper) michael@0: michael@0: virtual JSObject* WrapObject(JSContext* aCx) michael@0: MOZ_OVERRIDE; michael@0: nsPIDOMWindow* GetParentObject() const michael@0: { michael@0: return GetOwner(); michael@0: } michael@0: michael@0: // WebIDL michael@0: // Uses XPIDL GetLabel. michael@0: bool Reliable() const; michael@0: mozilla::dom::RTCDataChannelState ReadyState() const; michael@0: uint32_t BufferedAmount() const; michael@0: IMPL_EVENT_HANDLER(open) michael@0: IMPL_EVENT_HANDLER(error) michael@0: IMPL_EVENT_HANDLER(close) michael@0: // Uses XPIDL Close. michael@0: IMPL_EVENT_HANDLER(message) michael@0: mozilla::dom::RTCDataChannelType BinaryType() const michael@0: { michael@0: return static_cast( michael@0: static_cast(mBinaryType)); michael@0: } michael@0: void SetBinaryType(mozilla::dom::RTCDataChannelType aType) michael@0: { michael@0: mBinaryType = static_cast( michael@0: static_cast(aType)); michael@0: } michael@0: void Send(const nsAString& aData, mozilla::ErrorResult& aRv); michael@0: void Send(nsIDOMBlob* aData, mozilla::ErrorResult& aRv); michael@0: void Send(const mozilla::dom::ArrayBuffer& aData, mozilla::ErrorResult& aRv); michael@0: void Send(const mozilla::dom::ArrayBufferView& aData, michael@0: mozilla::ErrorResult& aRv); michael@0: michael@0: // Uses XPIDL GetProtocol. michael@0: bool Ordered() const; michael@0: uint16_t Id() const; michael@0: uint16_t Stream() const; // deprecated michael@0: michael@0: nsresult michael@0: DoOnMessageAvailable(const nsACString& aMessage, bool aBinary); michael@0: michael@0: virtual nsresult michael@0: OnMessageAvailable(nsISupports* aContext, const nsACString& aMessage) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult michael@0: OnBinaryMessageAvailable(nsISupports* aContext, const nsACString& aMessage) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult OnSimpleEvent(nsISupports* aContext, const nsAString& aName); michael@0: michael@0: virtual nsresult michael@0: OnChannelConnected(nsISupports* aContext) MOZ_OVERRIDE; michael@0: michael@0: virtual nsresult michael@0: OnChannelClosed(nsISupports* aContext) MOZ_OVERRIDE; michael@0: michael@0: virtual void michael@0: AppReady(); michael@0: michael@0: private: michael@0: void Send(nsIInputStream* aMsgStream, const nsACString& aMsgString, michael@0: uint32_t aMsgLength, bool aIsBinary, mozilla::ErrorResult& aRv); michael@0: michael@0: // Owning reference michael@0: nsRefPtr mDataChannel; michael@0: nsString mOrigin; michael@0: enum DataChannelBinaryType { michael@0: DC_BINARY_TYPE_ARRAYBUFFER, michael@0: DC_BINARY_TYPE_BLOB, michael@0: }; michael@0: DataChannelBinaryType mBinaryType; michael@0: }; michael@0: michael@0: #endif // nsDOMDataChannel_h