OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 */ | 23 */ |
24 | 24 |
25 #include "config.h" | 25 #include "config.h" |
| 26 |
26 #include "modules/mediastream/RTCDataChannel.h" | 27 #include "modules/mediastream/RTCDataChannel.h" |
27 | 28 |
28 #include "bindings/v8/ExceptionState.h" | |
29 #include "core/dom/Event.h" | 29 #include "core/dom/Event.h" |
30 #include "core/dom/ExceptionCode.h" | 30 #include "core/dom/ExceptionCode.h" |
31 #include "core/dom/MessageEvent.h" | 31 #include "core/dom/MessageEvent.h" |
32 #include "core/dom/ScriptExecutionContext.h" | 32 #include "core/dom/ScriptExecutionContext.h" |
33 #include "core/fileapi/Blob.h" | 33 #include "core/fileapi/Blob.h" |
34 #include "core/platform/mediastream/RTCDataChannelHandler.h" | 34 #include "core/platform/mediastream/RTCDataChannelHandler.h" |
35 #include "core/platform/mediastream/RTCPeerConnectionHandler.h" | 35 #include "core/platform/mediastream/RTCPeerConnectionHandler.h" |
36 #include "wtf/ArrayBuffer.h" | 36 #include "wtf/ArrayBuffer.h" |
37 #include "wtf/ArrayBufferView.h" | 37 #include "wtf/ArrayBufferView.h" |
38 | 38 |
39 namespace WebCore { | 39 namespace WebCore { |
40 | 40 |
41 PassRefPtr<RTCDataChannel> RTCDataChannel::create(ScriptExecutionContext* contex
t, PassOwnPtr<RTCDataChannelHandler> handler) | 41 PassRefPtr<RTCDataChannel> RTCDataChannel::create(ScriptExecutionContext* contex
t, PassOwnPtr<RTCDataChannelHandler> handler) |
42 { | 42 { |
43 ASSERT(handler); | 43 ASSERT(handler); |
44 return adoptRef(new RTCDataChannel(context, handler)); | 44 return adoptRef(new RTCDataChannel(context, handler)); |
45 } | 45 } |
46 | 46 |
47 PassRefPtr<RTCDataChannel> RTCDataChannel::create(ScriptExecutionContext* contex
t, RTCPeerConnectionHandler* peerConnectionHandler, const String& label, const W
ebKit::WebRTCDataChannelInit& init, ExceptionState& es) | 47 PassRefPtr<RTCDataChannel> RTCDataChannel::create(ScriptExecutionContext* contex
t, RTCPeerConnectionHandler* peerConnectionHandler, const String& label, const W
ebKit::WebRTCDataChannelInit& init, ExceptionCode& ec) |
48 { | 48 { |
49 OwnPtr<RTCDataChannelHandler> handler = peerConnectionHandler->createDataCha
nnel(label, init); | 49 OwnPtr<RTCDataChannelHandler> handler = peerConnectionHandler->createDataCha
nnel(label, init); |
50 if (!handler) { | 50 if (!handler) { |
51 es.throwDOMException(NotSupportedError); | 51 ec = NotSupportedError; |
52 return 0; | 52 return 0; |
53 } | 53 } |
54 return adoptRef(new RTCDataChannel(context, handler.release())); | 54 return adoptRef(new RTCDataChannel(context, handler.release())); |
55 } | 55 } |
56 | 56 |
57 RTCDataChannel::RTCDataChannel(ScriptExecutionContext* context, PassOwnPtr<RTCDa
taChannelHandler> handler) | 57 RTCDataChannel::RTCDataChannel(ScriptExecutionContext* context, PassOwnPtr<RTCDa
taChannelHandler> handler) |
58 : m_scriptExecutionContext(context) | 58 : m_scriptExecutionContext(context) |
59 , m_handler(handler) | 59 , m_handler(handler) |
60 , m_stopped(false) | 60 , m_stopped(false) |
61 , m_readyState(ReadyStateConnecting) | 61 , m_readyState(ReadyStateConnecting) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 switch (m_binaryType) { | 107 switch (m_binaryType) { |
108 case BinaryTypeBlob: | 108 case BinaryTypeBlob: |
109 return ASCIILiteral("blob"); | 109 return ASCIILiteral("blob"); |
110 case BinaryTypeArrayBuffer: | 110 case BinaryTypeArrayBuffer: |
111 return ASCIILiteral("arraybuffer"); | 111 return ASCIILiteral("arraybuffer"); |
112 } | 112 } |
113 ASSERT_NOT_REACHED(); | 113 ASSERT_NOT_REACHED(); |
114 return String(); | 114 return String(); |
115 } | 115 } |
116 | 116 |
117 void RTCDataChannel::setBinaryType(const String& binaryType, ExceptionState& es) | 117 void RTCDataChannel::setBinaryType(const String& binaryType, ExceptionCode& ec) |
118 { | 118 { |
119 if (binaryType == "blob") | 119 if (binaryType == "blob") |
120 es.throwDOMException(NotSupportedError); | 120 ec = NotSupportedError; |
121 else if (binaryType == "arraybuffer") | 121 else if (binaryType == "arraybuffer") |
122 m_binaryType = BinaryTypeArrayBuffer; | 122 m_binaryType = BinaryTypeArrayBuffer; |
123 else | 123 else |
124 es.throwDOMException(TypeMismatchError); | 124 ec = TypeMismatchError; |
125 } | 125 } |
126 | 126 |
127 void RTCDataChannel::send(const String& data, ExceptionState& es) | 127 void RTCDataChannel::send(const String& data, ExceptionCode& ec) |
128 { | 128 { |
129 if (m_readyState != ReadyStateOpen) { | 129 if (m_readyState != ReadyStateOpen) { |
130 es.throwDOMException(InvalidStateError); | 130 ec = InvalidStateError; |
131 return; | 131 return; |
132 } | 132 } |
133 if (!m_handler->sendStringData(data)) { | 133 if (!m_handler->sendStringData(data)) { |
134 // FIXME: Decide what the right exception here is. | 134 // FIXME: Decide what the right exception here is. |
135 es.throwDOMException(SyntaxError); | 135 ec = SyntaxError; |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 void RTCDataChannel::send(PassRefPtr<ArrayBuffer> prpData, ExceptionState& es) | 139 void RTCDataChannel::send(PassRefPtr<ArrayBuffer> prpData, ExceptionCode& ec) |
140 { | 140 { |
141 if (m_readyState != ReadyStateOpen) { | 141 if (m_readyState != ReadyStateOpen) { |
142 es.throwDOMException(InvalidStateError); | 142 ec = InvalidStateError; |
143 return; | 143 return; |
144 } | 144 } |
145 | 145 |
146 RefPtr<ArrayBuffer> data = prpData; | 146 RefPtr<ArrayBuffer> data = prpData; |
147 | 147 |
148 size_t dataLength = data->byteLength(); | 148 size_t dataLength = data->byteLength(); |
149 if (!dataLength) | 149 if (!dataLength) |
150 return; | 150 return; |
151 | 151 |
152 const char* dataPointer = static_cast<const char*>(data->data()); | 152 const char* dataPointer = static_cast<const char*>(data->data()); |
153 | 153 |
154 if (!m_handler->sendRawData(dataPointer, dataLength)) { | 154 if (!m_handler->sendRawData(dataPointer, dataLength)) { |
155 // FIXME: Decide what the right exception here is. | 155 // FIXME: Decide what the right exception here is. |
156 es.throwDOMException(SyntaxError); | 156 ec = SyntaxError; |
157 } | 157 } |
158 } | 158 } |
159 | 159 |
160 void RTCDataChannel::send(PassRefPtr<ArrayBufferView> data, ExceptionState& es) | 160 void RTCDataChannel::send(PassRefPtr<ArrayBufferView> data, ExceptionCode& ec) |
161 { | 161 { |
162 RefPtr<ArrayBuffer> arrayBuffer(data->buffer()); | 162 RefPtr<ArrayBuffer> arrayBuffer(data->buffer()); |
163 send(arrayBuffer.release(), es); | 163 send(arrayBuffer.release(), ec); |
164 } | 164 } |
165 | 165 |
166 void RTCDataChannel::send(PassRefPtr<Blob> data, ExceptionState& es) | 166 void RTCDataChannel::send(PassRefPtr<Blob> data, ExceptionCode& ec) |
167 { | 167 { |
168 // FIXME: implement | 168 // FIXME: implement |
169 es.throwDOMException(NotSupportedError); | 169 ec = NotSupportedError; |
170 } | 170 } |
171 | 171 |
172 void RTCDataChannel::close() | 172 void RTCDataChannel::close() |
173 { | 173 { |
174 if (m_stopped) | 174 if (m_stopped) |
175 return; | 175 return; |
176 | 176 |
177 m_handler->close(); | 177 m_handler->close(); |
178 } | 178 } |
179 | 179 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 events.swap(m_scheduledEvents); | 274 events.swap(m_scheduledEvents); |
275 | 275 |
276 Vector<RefPtr<Event> >::iterator it = events.begin(); | 276 Vector<RefPtr<Event> >::iterator it = events.begin(); |
277 for (; it != events.end(); ++it) | 277 for (; it != events.end(); ++it) |
278 dispatchEvent((*it).release()); | 278 dispatchEvent((*it).release()); |
279 | 279 |
280 events.clear(); | 280 events.clear(); |
281 } | 281 } |
282 | 282 |
283 } // namespace WebCore | 283 } // namespace WebCore |
OLD | NEW |