1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef WebSocketChannelClientProxy_h
6 #define WebSocketChannelClientProxy_h
8 #include "modules/websockets/WebSocketChannelClient.h"
9 #include "platform/heap/Handle.h"
10 #include "web/WebSocketImpl.h"
11 #include "wtf/PassOwnPtr.h"
12 #include "wtf/Vector.h"
13 #include "wtf/text/WTFString.h"
17 // Ideally we want to simply make WebSocketImpl inherit from
18 // WebSocketChannelClient, but we cannot do that because WebSocketChannelClient
19 // needs to be on Oilpan's heap whereas WebSocketImpl cannot be on Oilpan's
20 // heap. Thus we need to introduce a proxy class to decouple WebSocketImpl
21 // from WebSocketChannelClient.
22 class WebSocketChannelClientProxy FINAL : public GarbageCollectedFinalized<WebSocketChannelClientProxy>, public WebSocketChannelClient {
23 USING_GARBAGE_COLLECTED_MIXIN(WebSocketChannelClientProxy)
25 static WebSocketChannelClientProxy* create(WebSocketImpl* impl)
27 return new WebSocketChannelClientProxy(impl);
30 virtual void didConnect(const String& subprotocol, const String& extensions) OVERRIDE
32 m_impl->didConnect(subprotocol, extensions);
34 virtual void didReceiveMessage(const String& message) OVERRIDE
36 m_impl->didReceiveMessage(message);
38 virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData) OVERRIDE
40 m_impl->didReceiveBinaryData(binaryData);
42 virtual void didReceiveMessageError() OVERRIDE
44 m_impl->didReceiveMessageError();
46 virtual void didConsumeBufferedAmount(unsigned long consumed) OVERRIDE
48 m_impl->didConsumeBufferedAmount(consumed);
50 virtual void didStartClosingHandshake() OVERRIDE
52 m_impl->didStartClosingHandshake();
54 virtual void didClose(ClosingHandshakeCompletionStatus status, unsigned short code, const String& reason) OVERRIDE
56 WebSocketImpl* impl = m_impl;
58 impl->didClose(status, code, reason);
62 explicit WebSocketChannelClientProxy(WebSocketImpl* impl)
67 WebSocketImpl* m_impl;
72 #endif // WebSocketChannelClientProxy_h