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 didReceiveTextMessage(const String& payload) override
36 m_impl->didReceiveTextMessage(payload);
38 virtual void didReceiveBinaryMessage(PassOwnPtr<Vector<char> > payload) override
40 m_impl->didReceiveBinaryMessage(payload);
42 virtual void didError() override
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