|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set sw=2 ts=8 et tw=80 : */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef nsDOMDataChannel_h |
|
8 #define nsDOMDataChannel_h |
|
9 |
|
10 #include "mozilla/Attributes.h" |
|
11 #include "mozilla/DOMEventTargetHelper.h" |
|
12 #include "mozilla/dom/DataChannelBinding.h" |
|
13 #include "mozilla/dom/TypedArray.h" |
|
14 #include "mozilla/net/DataChannelListener.h" |
|
15 #include "nsIDOMDataChannel.h" |
|
16 #include "nsIInputStream.h" |
|
17 |
|
18 |
|
19 namespace mozilla { |
|
20 class DataChannel; |
|
21 }; |
|
22 |
|
23 class nsDOMDataChannel : public mozilla::DOMEventTargetHelper, |
|
24 public nsIDOMDataChannel, |
|
25 public mozilla::DataChannelListener |
|
26 { |
|
27 public: |
|
28 nsDOMDataChannel(already_AddRefed<mozilla::DataChannel>& aDataChannel, |
|
29 nsPIDOMWindow* aWindow); |
|
30 ~nsDOMDataChannel(); |
|
31 |
|
32 nsresult Init(nsPIDOMWindow* aDOMWindow); |
|
33 |
|
34 NS_DECL_ISUPPORTS_INHERITED |
|
35 NS_DECL_NSIDOMDATACHANNEL |
|
36 |
|
37 NS_REALLY_FORWARD_NSIDOMEVENTTARGET(mozilla::DOMEventTargetHelper) |
|
38 |
|
39 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsDOMDataChannel, |
|
40 mozilla::DOMEventTargetHelper) |
|
41 |
|
42 virtual JSObject* WrapObject(JSContext* aCx) |
|
43 MOZ_OVERRIDE; |
|
44 nsPIDOMWindow* GetParentObject() const |
|
45 { |
|
46 return GetOwner(); |
|
47 } |
|
48 |
|
49 // WebIDL |
|
50 // Uses XPIDL GetLabel. |
|
51 bool Reliable() const; |
|
52 mozilla::dom::RTCDataChannelState ReadyState() const; |
|
53 uint32_t BufferedAmount() const; |
|
54 IMPL_EVENT_HANDLER(open) |
|
55 IMPL_EVENT_HANDLER(error) |
|
56 IMPL_EVENT_HANDLER(close) |
|
57 // Uses XPIDL Close. |
|
58 IMPL_EVENT_HANDLER(message) |
|
59 mozilla::dom::RTCDataChannelType BinaryType() const |
|
60 { |
|
61 return static_cast<mozilla::dom::RTCDataChannelType>( |
|
62 static_cast<int>(mBinaryType)); |
|
63 } |
|
64 void SetBinaryType(mozilla::dom::RTCDataChannelType aType) |
|
65 { |
|
66 mBinaryType = static_cast<DataChannelBinaryType>( |
|
67 static_cast<int>(aType)); |
|
68 } |
|
69 void Send(const nsAString& aData, mozilla::ErrorResult& aRv); |
|
70 void Send(nsIDOMBlob* aData, mozilla::ErrorResult& aRv); |
|
71 void Send(const mozilla::dom::ArrayBuffer& aData, mozilla::ErrorResult& aRv); |
|
72 void Send(const mozilla::dom::ArrayBufferView& aData, |
|
73 mozilla::ErrorResult& aRv); |
|
74 |
|
75 // Uses XPIDL GetProtocol. |
|
76 bool Ordered() const; |
|
77 uint16_t Id() const; |
|
78 uint16_t Stream() const; // deprecated |
|
79 |
|
80 nsresult |
|
81 DoOnMessageAvailable(const nsACString& aMessage, bool aBinary); |
|
82 |
|
83 virtual nsresult |
|
84 OnMessageAvailable(nsISupports* aContext, const nsACString& aMessage) MOZ_OVERRIDE; |
|
85 |
|
86 virtual nsresult |
|
87 OnBinaryMessageAvailable(nsISupports* aContext, const nsACString& aMessage) MOZ_OVERRIDE; |
|
88 |
|
89 virtual nsresult OnSimpleEvent(nsISupports* aContext, const nsAString& aName); |
|
90 |
|
91 virtual nsresult |
|
92 OnChannelConnected(nsISupports* aContext) MOZ_OVERRIDE; |
|
93 |
|
94 virtual nsresult |
|
95 OnChannelClosed(nsISupports* aContext) MOZ_OVERRIDE; |
|
96 |
|
97 virtual void |
|
98 AppReady(); |
|
99 |
|
100 private: |
|
101 void Send(nsIInputStream* aMsgStream, const nsACString& aMsgString, |
|
102 uint32_t aMsgLength, bool aIsBinary, mozilla::ErrorResult& aRv); |
|
103 |
|
104 // Owning reference |
|
105 nsRefPtr<mozilla::DataChannel> mDataChannel; |
|
106 nsString mOrigin; |
|
107 enum DataChannelBinaryType { |
|
108 DC_BINARY_TYPE_ARRAYBUFFER, |
|
109 DC_BINARY_TYPE_BLOB, |
|
110 }; |
|
111 DataChannelBinaryType mBinaryType; |
|
112 }; |
|
113 |
|
114 #endif // nsDOMDataChannel_h |