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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 static void throwCouldNotSendDataException(ExceptionState& exceptionState) | 44 static void throwCouldNotSendDataException(ExceptionState& exceptionState) |
45 { | 45 { |
46 exceptionState.throwDOMException(NetworkError, "Could not send data"); | 46 exceptionState.throwDOMException(NetworkError, "Could not send data"); |
47 } | 47 } |
48 | 48 |
49 static void throwNoBlobSupportException(ExceptionState& exceptionState) | 49 static void throwNoBlobSupportException(ExceptionState& exceptionState) |
50 { | 50 { |
51 exceptionState.throwDOMException(NotSupportedError, "Blob support not implem
ented yet"); | 51 exceptionState.throwDOMException(NotSupportedError, "Blob support not implem
ented yet"); |
52 } | 52 } |
53 | 53 |
54 RTCDataChannel* RTCDataChannel::create(ExecutionContext* context, PassOwnPtr<Web
RTCDataChannelHandler> handler) | 54 RTCDataChannel* RTCDataChannel::create(ExecutionContext* context, RTCPeerConnect
ion* connection, PassOwnPtr<WebRTCDataChannelHandler> handler) |
55 { | 55 { |
56 ASSERT(handler); | 56 ASSERT(handler); |
57 return new RTCDataChannel(context, handler); | 57 return new RTCDataChannel(context, connection, handler); |
58 } | 58 } |
59 | 59 |
60 RTCDataChannel* RTCDataChannel::create(ExecutionContext* context, WebRTCPeerConn
ectionHandler* peerConnectionHandler, const String& label, const WebRTCDataChann
elInit& init, ExceptionState& exceptionState) | 60 RTCDataChannel* RTCDataChannel::create(ExecutionContext* context, RTCPeerConnect
ion* connection, WebRTCPeerConnectionHandler* peerConnectionHandler, const Strin
g& label, const WebRTCDataChannelInit& init, ExceptionState& exceptionState) |
61 { | 61 { |
62 OwnPtr<WebRTCDataChannelHandler> handler = adoptPtr(peerConnectionHandler->c
reateDataChannel(label, init)); | 62 OwnPtr<WebRTCDataChannelHandler> handler = adoptPtr(peerConnectionHandler->c
reateDataChannel(label, init)); |
63 if (!handler) { | 63 if (!handler) { |
64 exceptionState.throwDOMException(NotSupportedError, "RTCDataChannel is n
ot supported"); | 64 exceptionState.throwDOMException(NotSupportedError, "RTCDataChannel is n
ot supported"); |
65 return nullptr; | 65 return nullptr; |
66 } | 66 } |
67 return new RTCDataChannel(context, handler.release()); | 67 return new RTCDataChannel(context, connection, handler.release()); |
68 } | 68 } |
69 | 69 |
70 RTCDataChannel::RTCDataChannel(ExecutionContext* context, PassOwnPtr<WebRTCDataC
hannelHandler> handler) | 70 RTCDataChannel::RTCDataChannel(ExecutionContext* context, RTCPeerConnection* con
nection, PassOwnPtr<WebRTCDataChannelHandler> handler) |
71 : m_executionContext(context) | 71 : m_executionContext(context) |
72 , m_handler(handler) | 72 , m_handler(handler) |
| 73 , m_stopped(false) |
73 , m_readyState(ReadyStateConnecting) | 74 , m_readyState(ReadyStateConnecting) |
74 , m_binaryType(BinaryTypeArrayBuffer) | 75 , m_binaryType(BinaryTypeArrayBuffer) |
75 , m_scheduledEventTimer(this, &RTCDataChannel::scheduledEventTimerFired) | 76 , m_scheduledEventTimer(this, &RTCDataChannel::scheduledEventTimerFired) |
| 77 , m_connection(connection) |
76 , m_bufferedAmountLowThreshold(0U) | 78 , m_bufferedAmountLowThreshold(0U) |
77 { | 79 { |
78 m_handler->setClient(this); | 80 m_handler->setClient(this); |
79 } | 81 } |
80 | 82 |
81 RTCDataChannel::~RTCDataChannel() | 83 RTCDataChannel::~RTCDataChannel() |
82 { | 84 { |
83 // Notify the client that the channel is gone. | 85 // If the peer connection and the data channel die in the same |
84 m_handler->setClient(0); | 86 // GC cycle stop has not been called and we need to notify the |
| 87 // client that the channel is gone. |
| 88 if (!m_stopped) |
| 89 m_handler->setClient(0); |
85 } | 90 } |
86 | 91 |
87 RTCDataChannel::ReadyState RTCDataChannel::getHandlerState() const | 92 RTCDataChannel::ReadyState RTCDataChannel::getHandlerState() const |
88 { | 93 { |
89 return m_handler->state(); | 94 return m_handler->state(); |
90 } | 95 } |
91 | 96 |
92 String RTCDataChannel::label() const | 97 String RTCDataChannel::label() const |
93 { | 98 { |
94 return m_handler->label(); | 99 return m_handler->label(); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 } | 228 } |
224 | 229 |
225 void RTCDataChannel::send(Blob* data, ExceptionState& exceptionState) | 230 void RTCDataChannel::send(Blob* data, ExceptionState& exceptionState) |
226 { | 231 { |
227 // FIXME: implement | 232 // FIXME: implement |
228 throwNoBlobSupportException(exceptionState); | 233 throwNoBlobSupportException(exceptionState); |
229 } | 234 } |
230 | 235 |
231 void RTCDataChannel::close() | 236 void RTCDataChannel::close() |
232 { | 237 { |
| 238 if (m_stopped) |
| 239 return; |
| 240 |
233 m_handler->close(); | 241 m_handler->close(); |
234 } | 242 } |
235 | 243 |
236 void RTCDataChannel::didChangeReadyState(WebRTCDataChannelHandlerClient::ReadySt
ate newState) | 244 void RTCDataChannel::didChangeReadyState(WebRTCDataChannelHandlerClient::ReadySt
ate newState) |
237 { | 245 { |
238 if (m_readyState == ReadyStateClosed) | 246 if (m_stopped || m_readyState == ReadyStateClosed) |
239 return; | 247 return; |
240 | 248 |
241 m_readyState = newState; | 249 m_readyState = newState; |
242 | 250 |
243 switch (m_readyState) { | 251 switch (m_readyState) { |
244 case ReadyStateOpen: | 252 case ReadyStateOpen: |
245 scheduleDispatchEvent(Event::create(EventTypeNames::open)); | 253 scheduleDispatchEvent(Event::create(EventTypeNames::open)); |
246 break; | 254 break; |
247 case ReadyStateClosed: | 255 case ReadyStateClosed: |
248 scheduleDispatchEvent(Event::create(EventTypeNames::close)); | 256 scheduleDispatchEvent(Event::create(EventTypeNames::close)); |
249 break; | 257 break; |
250 default: | 258 default: |
251 break; | 259 break; |
252 } | 260 } |
253 } | 261 } |
254 | 262 |
255 void RTCDataChannel::didDecreaseBufferedAmount(unsigned previousAmount) | 263 void RTCDataChannel::didDecreaseBufferedAmount(unsigned previousAmount) |
256 { | 264 { |
257 if (previousAmount > m_bufferedAmountLowThreshold | 265 if (previousAmount > m_bufferedAmountLowThreshold |
258 && bufferedAmount() <= m_bufferedAmountLowThreshold) { | 266 && bufferedAmount() <= m_bufferedAmountLowThreshold) { |
259 scheduleDispatchEvent(Event::create(EventTypeNames::bufferedamountlow)); | 267 scheduleDispatchEvent(Event::create(EventTypeNames::bufferedamountlow)); |
260 } | 268 } |
261 } | 269 } |
262 | 270 |
263 void RTCDataChannel::didReceiveStringData(const WebString& text) | 271 void RTCDataChannel::didReceiveStringData(const WebString& text) |
264 { | 272 { |
| 273 if (m_stopped) |
| 274 return; |
| 275 |
265 scheduleDispatchEvent(MessageEvent::create(text)); | 276 scheduleDispatchEvent(MessageEvent::create(text)); |
266 } | 277 } |
267 | 278 |
268 void RTCDataChannel::didReceiveRawData(const char* data, size_t dataLength) | 279 void RTCDataChannel::didReceiveRawData(const char* data, size_t dataLength) |
269 { | 280 { |
| 281 if (m_stopped) |
| 282 return; |
| 283 |
270 if (m_binaryType == BinaryTypeBlob) { | 284 if (m_binaryType == BinaryTypeBlob) { |
271 // FIXME: Implement. | 285 // FIXME: Implement. |
272 return; | 286 return; |
273 } | 287 } |
274 if (m_binaryType == BinaryTypeArrayBuffer) { | 288 if (m_binaryType == BinaryTypeArrayBuffer) { |
275 RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::create(data, dataLength)
; | 289 RefPtr<DOMArrayBuffer> buffer = DOMArrayBuffer::create(data, dataLength)
; |
276 scheduleDispatchEvent(MessageEvent::create(buffer.release())); | 290 scheduleDispatchEvent(MessageEvent::create(buffer.release())); |
277 return; | 291 return; |
278 } | 292 } |
279 ASSERT_NOT_REACHED(); | 293 ASSERT_NOT_REACHED(); |
280 } | 294 } |
281 | 295 |
282 void RTCDataChannel::didDetectError() | 296 void RTCDataChannel::didDetectError() |
283 { | 297 { |
| 298 if (m_stopped) |
| 299 return; |
| 300 |
284 scheduleDispatchEvent(Event::create(EventTypeNames::error)); | 301 scheduleDispatchEvent(Event::create(EventTypeNames::error)); |
285 } | 302 } |
286 | 303 |
287 const AtomicString& RTCDataChannel::interfaceName() const | 304 const AtomicString& RTCDataChannel::interfaceName() const |
288 { | 305 { |
289 return EventTargetNames::RTCDataChannel; | 306 return EventTargetNames::RTCDataChannel; |
290 } | 307 } |
291 | 308 |
292 ExecutionContext* RTCDataChannel::executionContext() const | 309 ExecutionContext* RTCDataChannel::executionContext() const |
293 { | 310 { |
294 return m_executionContext; | 311 return m_executionContext; |
295 } | 312 } |
296 | 313 |
| 314 void RTCDataChannel::stop() |
| 315 { |
| 316 m_stopped = true; |
| 317 m_readyState = ReadyStateClosed; |
| 318 m_handler->setClient(0); |
| 319 m_executionContext = 0; |
| 320 } |
| 321 |
297 void RTCDataChannel::scheduleDispatchEvent(PassRefPtrWillBeRawPtr<Event> event) | 322 void RTCDataChannel::scheduleDispatchEvent(PassRefPtrWillBeRawPtr<Event> event) |
298 { | 323 { |
299 m_scheduledEvents.append(event); | 324 m_scheduledEvents.append(event); |
300 | 325 |
301 if (!m_scheduledEventTimer.isActive()) | 326 if (!m_scheduledEventTimer.isActive()) |
302 m_scheduledEventTimer.startOneShot(0, BLINK_FROM_HERE); | 327 m_scheduledEventTimer.startOneShot(0, BLINK_FROM_HERE); |
303 } | 328 } |
304 | 329 |
305 void RTCDataChannel::scheduledEventTimerFired(Timer<RTCDataChannel>*) | 330 void RTCDataChannel::scheduledEventTimerFired(Timer<RTCDataChannel>*) |
306 { | 331 { |
| 332 if (m_stopped) |
| 333 return; |
| 334 |
307 WillBeHeapVector<RefPtrWillBeMember<Event>> events; | 335 WillBeHeapVector<RefPtrWillBeMember<Event>> events; |
308 events.swap(m_scheduledEvents); | 336 events.swap(m_scheduledEvents); |
309 | 337 |
310 WillBeHeapVector<RefPtrWillBeMember<Event>>::iterator it = events.begin(); | 338 WillBeHeapVector<RefPtrWillBeMember<Event>>::iterator it = events.begin(); |
311 for (; it != events.end(); ++it) | 339 for (; it != events.end(); ++it) |
312 dispatchEvent((*it).release()); | 340 dispatchEvent((*it).release()); |
313 | 341 |
314 events.clear(); | 342 events.clear(); |
315 } | 343 } |
316 | 344 |
| 345 void RTCDataChannel::clearWeakMembers(Visitor* visitor) |
| 346 { |
| 347 if (Heap::isHeapObjectAlive(m_connection)) |
| 348 return; |
| 349 stop(); |
| 350 m_connection = nullptr; |
| 351 } |
| 352 |
317 DEFINE_TRACE(RTCDataChannel) | 353 DEFINE_TRACE(RTCDataChannel) |
318 { | 354 { |
319 visitor->trace(m_executionContext); | 355 visitor->trace(m_executionContext); |
320 visitor->trace(m_scheduledEvents); | 356 visitor->trace(m_scheduledEvents); |
| 357 visitor->template registerWeakMembers<RTCDataChannel, &RTCDataChannel::clear
WeakMembers>(this); |
321 RefCountedGarbageCollectedEventTargetWithInlineData<RTCDataChannel>::trace(v
isitor); | 358 RefCountedGarbageCollectedEventTargetWithInlineData<RTCDataChannel>::trace(v
isitor); |
322 } | 359 } |
323 | 360 |
324 } // namespace blink | 361 } // namespace blink |
OLD | NEW |