| 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 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "core/dom/ExecutionContext.h" | 32 #include "core/dom/ExecutionContext.h" |
| 33 #include "core/events/MessageEvent.h" | 33 #include "core/events/MessageEvent.h" |
| 34 #include "core/fileapi/Blob.h" | 34 #include "core/fileapi/Blob.h" |
| 35 #include "core/platform/mediastream/RTCDataChannelHandler.h" | 35 #include "core/platform/mediastream/RTCDataChannelHandler.h" |
| 36 #include "core/platform/mediastream/RTCPeerConnectionHandler.h" | 36 #include "core/platform/mediastream/RTCPeerConnectionHandler.h" |
| 37 #include "wtf/ArrayBuffer.h" | 37 #include "wtf/ArrayBuffer.h" |
| 38 #include "wtf/ArrayBufferView.h" | 38 #include "wtf/ArrayBufferView.h" |
| 39 | 39 |
| 40 namespace WebCore { | 40 namespace WebCore { |
| 41 | 41 |
| 42 static void throwNotOpenException(ExceptionState& es) | 42 static void throwNotOpenException(ExceptionState& exceptionState) |
| 43 { | 43 { |
| 44 es.throwDOMException(InvalidStateError, "RTCDataChannel.readyState is not 'o
pen'"); | 44 exceptionState.throwDOMException(InvalidStateError, "RTCDataChannel.readySta
te is not 'open'"); |
| 45 } | 45 } |
| 46 | 46 |
| 47 static void throwCouldNotSendDataException(ExceptionState& es) | 47 static void throwCouldNotSendDataException(ExceptionState& exceptionState) |
| 48 { | 48 { |
| 49 es.throwDOMException(NetworkError, "Could not send data"); | 49 exceptionState.throwDOMException(NetworkError, "Could not send data"); |
| 50 } | 50 } |
| 51 | 51 |
| 52 static void throwNoBlobSupportException(ExceptionState& es) | 52 static void throwNoBlobSupportException(ExceptionState& exceptionState) |
| 53 { | 53 { |
| 54 es.throwDOMException(NotSupportedError, ExceptionMessages::failedToExecute("
send", "RTCDataChannel", "Blob support not implemented yet")); | 54 exceptionState.throwDOMException(NotSupportedError, ExceptionMessages::faile
dToExecute("send", "RTCDataChannel", "Blob support not implemented yet")); |
| 55 } | 55 } |
| 56 | 56 |
| 57 PassRefPtr<RTCDataChannel> RTCDataChannel::create(ExecutionContext* context, Pas
sOwnPtr<RTCDataChannelHandler> handler) | 57 PassRefPtr<RTCDataChannel> RTCDataChannel::create(ExecutionContext* context, Pas
sOwnPtr<RTCDataChannelHandler> handler) |
| 58 { | 58 { |
| 59 ASSERT(handler); | 59 ASSERT(handler); |
| 60 return adoptRef(new RTCDataChannel(context, handler)); | 60 return adoptRef(new RTCDataChannel(context, handler)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 PassRefPtr<RTCDataChannel> RTCDataChannel::create(ExecutionContext* context, RTC
PeerConnectionHandler* peerConnectionHandler, const String& label, const blink::
WebRTCDataChannelInit& init, ExceptionState& es) | 63 PassRefPtr<RTCDataChannel> RTCDataChannel::create(ExecutionContext* context, RTC
PeerConnectionHandler* peerConnectionHandler, const String& label, const blink::
WebRTCDataChannelInit& init, ExceptionState& exceptionState) |
| 64 { | 64 { |
| 65 OwnPtr<RTCDataChannelHandler> handler = peerConnectionHandler->createDataCha
nnel(label, init); | 65 OwnPtr<RTCDataChannelHandler> handler = peerConnectionHandler->createDataCha
nnel(label, init); |
| 66 if (!handler) { | 66 if (!handler) { |
| 67 es.throwDOMException(NotSupportedError, "RTCDataChannel is not supported
"); | 67 exceptionState.throwDOMException(NotSupportedError, "RTCDataChannel is n
ot supported"); |
| 68 return 0; | 68 return 0; |
| 69 } | 69 } |
| 70 return adoptRef(new RTCDataChannel(context, handler.release())); | 70 return adoptRef(new RTCDataChannel(context, handler.release())); |
| 71 } | 71 } |
| 72 | 72 |
| 73 RTCDataChannel::RTCDataChannel(ExecutionContext* context, PassOwnPtr<RTCDataChan
nelHandler> handler) | 73 RTCDataChannel::RTCDataChannel(ExecutionContext* context, PassOwnPtr<RTCDataChan
nelHandler> handler) |
| 74 : m_executionContext(context) | 74 : m_executionContext(context) |
| 75 , m_handler(handler) | 75 , m_handler(handler) |
| 76 , m_stopped(false) | 76 , m_stopped(false) |
| 77 , m_readyState(ReadyStateConnecting) | 77 , m_readyState(ReadyStateConnecting) |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 switch (m_binaryType) { | 153 switch (m_binaryType) { |
| 154 case BinaryTypeBlob: | 154 case BinaryTypeBlob: |
| 155 return "blob"; | 155 return "blob"; |
| 156 case BinaryTypeArrayBuffer: | 156 case BinaryTypeArrayBuffer: |
| 157 return "arraybuffer"; | 157 return "arraybuffer"; |
| 158 } | 158 } |
| 159 ASSERT_NOT_REACHED(); | 159 ASSERT_NOT_REACHED(); |
| 160 return String(); | 160 return String(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void RTCDataChannel::setBinaryType(const String& binaryType, ExceptionState& es) | 163 void RTCDataChannel::setBinaryType(const String& binaryType, ExceptionState& exc
eptionState) |
| 164 { | 164 { |
| 165 if (binaryType == "blob") | 165 if (binaryType == "blob") |
| 166 throwNoBlobSupportException(es); | 166 throwNoBlobSupportException(exceptionState); |
| 167 else if (binaryType == "arraybuffer") | 167 else if (binaryType == "arraybuffer") |
| 168 m_binaryType = BinaryTypeArrayBuffer; | 168 m_binaryType = BinaryTypeArrayBuffer; |
| 169 else | 169 else |
| 170 es.throwDOMException(TypeMismatchError, "Unknown binary type : " + binar
yType); | 170 exceptionState.throwDOMException(TypeMismatchError, "Unknown binary type
: " + binaryType); |
| 171 } | 171 } |
| 172 | 172 |
| 173 void RTCDataChannel::send(const String& data, ExceptionState& es) | 173 void RTCDataChannel::send(const String& data, ExceptionState& exceptionState) |
| 174 { | 174 { |
| 175 if (m_readyState != ReadyStateOpen) { | 175 if (m_readyState != ReadyStateOpen) { |
| 176 throwNotOpenException(es); | 176 throwNotOpenException(exceptionState); |
| 177 return; | 177 return; |
| 178 } | 178 } |
| 179 if (!m_handler->sendStringData(data)) { | 179 if (!m_handler->sendStringData(data)) { |
| 180 // FIXME: This should not throw an exception but instead forcefully clos
e the data channel. | 180 // FIXME: This should not throw an exception but instead forcefully clos
e the data channel. |
| 181 throwCouldNotSendDataException(es); | 181 throwCouldNotSendDataException(exceptionState); |
| 182 } | 182 } |
| 183 } | 183 } |
| 184 | 184 |
| 185 void RTCDataChannel::send(PassRefPtr<ArrayBuffer> prpData, ExceptionState& es) | 185 void RTCDataChannel::send(PassRefPtr<ArrayBuffer> prpData, ExceptionState& excep
tionState) |
| 186 { | 186 { |
| 187 if (m_readyState != ReadyStateOpen) { | 187 if (m_readyState != ReadyStateOpen) { |
| 188 throwNotOpenException(es); | 188 throwNotOpenException(exceptionState); |
| 189 return; | 189 return; |
| 190 } | 190 } |
| 191 | 191 |
| 192 RefPtr<ArrayBuffer> data = prpData; | 192 RefPtr<ArrayBuffer> data = prpData; |
| 193 | 193 |
| 194 size_t dataLength = data->byteLength(); | 194 size_t dataLength = data->byteLength(); |
| 195 if (!dataLength) | 195 if (!dataLength) |
| 196 return; | 196 return; |
| 197 | 197 |
| 198 const char* dataPointer = static_cast<const char*>(data->data()); | 198 const char* dataPointer = static_cast<const char*>(data->data()); |
| 199 | 199 |
| 200 if (!m_handler->sendRawData(dataPointer, dataLength)) { | 200 if (!m_handler->sendRawData(dataPointer, dataLength)) { |
| 201 // FIXME: This should not throw an exception but instead forcefully clos
e the data channel. | 201 // FIXME: This should not throw an exception but instead forcefully clos
e the data channel. |
| 202 throwCouldNotSendDataException(es); | 202 throwCouldNotSendDataException(exceptionState); |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 | 205 |
| 206 void RTCDataChannel::send(PassRefPtr<ArrayBufferView> data, ExceptionState& es) | 206 void RTCDataChannel::send(PassRefPtr<ArrayBufferView> data, ExceptionState& exce
ptionState) |
| 207 { | 207 { |
| 208 RefPtr<ArrayBuffer> arrayBuffer(data->buffer()); | 208 RefPtr<ArrayBuffer> arrayBuffer(data->buffer()); |
| 209 send(arrayBuffer.release(), es); | 209 send(arrayBuffer.release(), exceptionState); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void RTCDataChannel::send(PassRefPtr<Blob> data, ExceptionState& es) | 212 void RTCDataChannel::send(PassRefPtr<Blob> data, ExceptionState& exceptionState) |
| 213 { | 213 { |
| 214 // FIXME: implement | 214 // FIXME: implement |
| 215 throwNoBlobSupportException(es); | 215 throwNoBlobSupportException(exceptionState); |
| 216 } | 216 } |
| 217 | 217 |
| 218 void RTCDataChannel::close() | 218 void RTCDataChannel::close() |
| 219 { | 219 { |
| 220 if (m_stopped) | 220 if (m_stopped) |
| 221 return; | 221 return; |
| 222 | 222 |
| 223 m_handler->close(); | 223 m_handler->close(); |
| 224 } | 224 } |
| 225 | 225 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 events.swap(m_scheduledEvents); | 310 events.swap(m_scheduledEvents); |
| 311 | 311 |
| 312 Vector<RefPtr<Event> >::iterator it = events.begin(); | 312 Vector<RefPtr<Event> >::iterator it = events.begin(); |
| 313 for (; it != events.end(); ++it) | 313 for (; it != events.end(); ++it) |
| 314 dispatchEvent((*it).release()); | 314 dispatchEvent((*it).release()); |
| 315 | 315 |
| 316 events.clear(); | 316 events.clear(); |
| 317 } | 317 } |
| 318 | 318 |
| 319 } // namespace WebCore | 319 } // namespace WebCore |
| OLD | NEW |