2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef ThreadableWebSocketChannelClientWrapper_h
32 #define ThreadableWebSocketChannelClientWrapper_h
34 #if ENABLE(WEB_SOCKETS)
36 #include "PlatformString.h"
37 #include "ScriptExecutionContext.h"
38 #include "WebSocketChannelClient.h"
39 #include <wtf/Forward.h>
40 #include <wtf/OwnPtr.h>
41 #include <wtf/PassOwnPtr.h>
42 #include <wtf/Threading.h>
43 #include <wtf/Vector.h>
47 class WebSocketChannelClient;
49 class ThreadableWebSocketChannelClientWrapper : public ThreadSafeRefCounted<ThreadableWebSocketChannelClientWrapper> {
51 static PassRefPtr<ThreadableWebSocketChannelClientWrapper> create(WebSocketChannelClient*);
53 void clearSyncMethodDone();
54 void setSyncMethodDone();
55 bool syncMethodDone() const;
57 // The value of useHixie76Protocol flag is cachable; this value is saved after WebSocketChannel (on the main
58 // thread) is constructed.
59 bool useHixie76Protocol() const;
60 void setUseHixie76Protocol(bool);
62 // Subprotocol is cached too. Will be available when didConnect() callback is invoked.
63 String subprotocol() const;
64 void setSubprotocol(const String&);
66 bool sendRequestResult() const;
67 void setSendRequestResult(bool);
69 unsigned long bufferedAmount() const;
70 void setBufferedAmount(unsigned long);
75 void didReceiveMessage(const String& message);
76 void didReceiveBinaryData(PassOwnPtr<Vector<char> >);
77 void didUpdateBufferedAmount(unsigned long bufferedAmount);
78 void didStartClosingHandshake();
79 void didClose(unsigned long unhandledBufferedAmount, WebSocketChannelClient::ClosingHandshakeCompletionStatus, unsigned short code, const String& reason);
85 ThreadableWebSocketChannelClientWrapper(WebSocketChannelClient*);
87 void processPendingTasks();
88 static void didConnectCallback(ScriptExecutionContext*, ThreadableWebSocketChannelClientWrapper*);
89 static void didReceiveMessageCallback(ScriptExecutionContext*, ThreadableWebSocketChannelClientWrapper*, const String& message);
90 static void didReceiveBinaryDataCallback(ScriptExecutionContext*, ThreadableWebSocketChannelClientWrapper*, PassOwnPtr<Vector<char> >);
91 static void didUpdateBufferedAmountCallback(ScriptExecutionContext*, ThreadableWebSocketChannelClientWrapper*, unsigned long bufferedAmount);
92 static void didStartClosingHandshakeCallback(ScriptExecutionContext*, ThreadableWebSocketChannelClientWrapper*);
93 static void didCloseCallback(ScriptExecutionContext*, ThreadableWebSocketChannelClientWrapper*, unsigned long unhandledBufferedAmount, WebSocketChannelClient::ClosingHandshakeCompletionStatus, unsigned short code, const String& reason);
95 WebSocketChannelClient* m_client;
96 bool m_syncMethodDone;
97 bool m_useHixie76Protocol;
98 Vector<UChar> m_subprotocol; // ThreadSafeRefCounted must not have a String member variable.
99 bool m_sendRequestResult;
100 unsigned long m_bufferedAmount;
102 Vector<OwnPtr<ScriptExecutionContext::Task> > m_pendingTasks;
105 } // namespace WebCore
107 #endif // ENABLE(WEB_SOCKETS)
109 #endif // ThreadableWebSocketChannelClientWrapper_h