1 /* 2 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 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 ANY 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 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 ON 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 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 */ 24 25 #ifndef RTCDataChannel_h 26 #define RTCDataChannel_h 27 28 #include "bindings/v8/ScriptWrappable.h" 29 #include "modules/EventTargetModules.h" 30 #include "platform/Timer.h" 31 #include "platform/heap/Handle.h" 32 #include "public/platform/WebRTCDataChannelHandler.h" 33 #include "public/platform/WebRTCDataChannelHandlerClient.h" 34 #include "wtf/RefCounted.h" 35 36 namespace blink { 37 class WebRTCDataChannelHandler; 38 class WebRTCPeerConnectionHandler; 39 struct WebRTCDataChannelInit; 40 } 41 42 namespace WebCore { 43 44 class Blob; 45 class ExceptionState; 46 class RTCPeerConnection; 47 48 class RTCDataChannel FINAL : public RefCountedWillBeRefCountedGarbageCollected<RTCDataChannel>, public ScriptWrappable, public EventTargetWithInlineData, public blink::WebRTCDataChannelHandlerClient { 49 REFCOUNTED_EVENT_TARGET(RTCDataChannel); 50 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(RTCDataChannel); 51 public: 52 static PassRefPtrWillBeRawPtr<RTCDataChannel> create(ExecutionContext*, RTCPeerConnection*, PassOwnPtr<blink::WebRTCDataChannelHandler>); 53 static PassRefPtrWillBeRawPtr<RTCDataChannel> create(ExecutionContext*, RTCPeerConnection*, blink::WebRTCPeerConnectionHandler*, const String& label, const blink::WebRTCDataChannelInit&, ExceptionState&); 54 virtual ~RTCDataChannel(); 55 56 String label() const; 57 58 // DEPRECATED 59 bool reliable() const; 60 61 bool ordered() const; 62 unsigned short maxRetransmitTime() const; 63 unsigned short maxRetransmits() const; 64 String protocol() const; 65 bool negotiated() const; 66 unsigned short id() const; 67 String readyState() const; 68 unsigned long bufferedAmount() const; 69 70 String binaryType() const; 71 void setBinaryType(const String&, ExceptionState&); 72 73 void send(const String&, ExceptionState&); 74 void send(PassRefPtr<ArrayBuffer>, ExceptionState&); 75 void send(PassRefPtr<ArrayBufferView>, ExceptionState&); 76 void send(PassRefPtrWillBeRawPtr<Blob>, ExceptionState&); 77 78 void close(); 79 80 DEFINE_ATTRIBUTE_EVENT_LISTENER(open); 81 DEFINE_ATTRIBUTE_EVENT_LISTENER(error); 82 DEFINE_ATTRIBUTE_EVENT_LISTENER(close); 83 DEFINE_ATTRIBUTE_EVENT_LISTENER(message); 84 85 void stop(); 86 87 // EventTarget 88 virtual const AtomicString& interfaceName() const OVERRIDE; 89 virtual ExecutionContext* executionContext() const OVERRIDE; 90 91 #if ENABLE(OILPAN) 92 void clearWeakMembers(Visitor*); 93 #endif 94 95 virtual void trace(Visitor*) OVERRIDE; 96 97 private: 98 RTCDataChannel(ExecutionContext*, RTCPeerConnection*, PassOwnPtr<blink::WebRTCDataChannelHandler>); 99 100 void scheduleDispatchEvent(PassRefPtrWillBeRawPtr<Event>); 101 void scheduledEventTimerFired(Timer<RTCDataChannel>*); 102 103 ExecutionContext* m_executionContext; 104 105 // blink::WebRTCDataChannelHandlerClient 106 virtual void didChangeReadyState(blink::WebRTCDataChannelHandlerClient::ReadyState) OVERRIDE; 107 virtual void didReceiveStringData(const blink::WebString&) OVERRIDE; 108 virtual void didReceiveRawData(const char*, size_t) OVERRIDE; 109 virtual void didDetectError() OVERRIDE; 110 111 OwnPtr<blink::WebRTCDataChannelHandler> m_handler; 112 113 bool m_stopped; 114 115 blink::WebRTCDataChannelHandlerClient::ReadyState m_readyState; 116 117 enum BinaryType { 118 BinaryTypeBlob, 119 BinaryTypeArrayBuffer 120 }; 121 BinaryType m_binaryType; 122 123 Timer<RTCDataChannel> m_scheduledEventTimer; 124 WillBeHeapVector<RefPtrWillBeMember<Event> > m_scheduledEvents; 125 126 #if ENABLE(OILPAN) 127 WeakMember<RTCPeerConnection> m_connection; 128 #endif 129 }; 130 131 } // namespace WebCore 132 133 #endif // RTCDataChannel_h 134