Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / web / WebSocketChannelClientProxy.h
blobfe17744936f2837216e7c1d489a2a02f40635e51
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"
14 #include <stdint.h>
16 namespace blink {
18 // Ideally we want to simply make WebSocketImpl inherit from
19 // WebSocketChannelClient, but we cannot do that because WebSocketChannelClient
20 // needs to be on Oilpan's heap whereas WebSocketImpl cannot be on Oilpan's
21 // heap. Thus we need to introduce a proxy class to decouple WebSocketImpl
22 // from WebSocketChannelClient.
23 class WebSocketChannelClientProxy final : public GarbageCollectedFinalized<WebSocketChannelClientProxy>, public WebSocketChannelClient {
24 USING_GARBAGE_COLLECTED_MIXIN(WebSocketChannelClientProxy)
25 public:
26 static WebSocketChannelClientProxy* create(WebSocketImpl* impl)
28 return new WebSocketChannelClientProxy(impl);
31 void didConnect(const String& subprotocol, const String& extensions) override
33 m_impl->didConnect(subprotocol, extensions);
35 void didReceiveTextMessage(const String& payload) override
37 m_impl->didReceiveTextMessage(payload);
39 void didReceiveBinaryMessage(PassOwnPtr<Vector<char>> payload) override
41 m_impl->didReceiveBinaryMessage(payload);
43 void didError() override
45 m_impl->didError();
47 void didConsumeBufferedAmount(uint64_t consumed) override
49 m_impl->didConsumeBufferedAmount(consumed);
51 void didStartClosingHandshake() override
53 m_impl->didStartClosingHandshake();
55 void didClose(ClosingHandshakeCompletionStatus status, unsigned short code, const String& reason) override
57 WebSocketImpl* impl = m_impl;
58 m_impl = nullptr;
59 impl->didClose(status, code, reason);
62 DEFINE_INLINE_VIRTUAL_TRACE()
64 WebSocketChannelClient::trace(visitor);
67 private:
68 explicit WebSocketChannelClientProxy(WebSocketImpl* impl)
69 : m_impl(impl)
73 WebSocketImpl* m_impl;
76 } // namespace blink
78 #endif // WebSocketChannelClientProxy_h