OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 10 matching lines...) Expand all Loading... | |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #ifndef WebSocketImpl_h | 31 #ifndef WebSocketChannelClientProxy_h |
32 #define WebSocketImpl_h | 32 #define WebSocketChannelClientProxy_h |
33 | 33 |
34 #include "modules/websockets/WebSocketChannelClient.h" | 34 #include "modules/websockets/WebSocketChannelClient.h" |
35 #include "platform/heap/Handle.h" | 35 #include "platform/heap/Handle.h" |
36 #include "public/platform/WebCommon.h" | |
37 #include "public/platform/WebString.h" | |
38 #include "public/web/WebSocket.h" | |
39 #include "public/web/WebSocketClient.h" | 36 #include "public/web/WebSocketClient.h" |
yhirano
2014/08/04 01:05:53
No need to include WebSocketClient.h
haraken
2014/08/04 01:21:57
We need to include WebSocketClient.h for ClosingHa
yhirano
2014/08/04 01:48:28
ClosingHandshakeCompletionStatus used in this head
haraken
2014/08/04 02:34:17
You're right. Removed WebSocketClient.h from inclu
| |
37 #include "web/WebSocketImpl.h" | |
40 #include "wtf/OwnPtr.h" | 38 #include "wtf/OwnPtr.h" |
yhirano
2014/08/04 01:05:53
PassOwnPtr.h instead of OwnPtr.h
haraken
2014/08/04 01:21:57
Done.
| |
41 #include "wtf/RefPtr.h" | 39 #include "wtf/RefPtr.h" |
yhirano
2014/08/04 01:05:52
No need to include RefPtr.h
haraken
2014/08/04 01:21:57
Done.
| |
40 #include "wtf/Vector.h" | |
41 #include "wtf/text/WTFString.h" | |
42 | 42 |
43 namespace blink { class WebSocketChannel; } | 43 namespace blink { class WebSocketChannel; } |
44 | 44 |
45 namespace blink { | 45 namespace blink { |
46 | 46 |
47 class WebDocument; | 47 // Ideally we want to simply make WebSocketImpl inherit from WebSocketChannelCli ent, |
yhirano
2014/08/04 01:05:52
Please wrap comments in 80 columns.
haraken
2014/08/04 01:21:57
Done.
| |
48 class WebURL; | 48 // but we cannot do that because WebSocketChannelClient needs to be on Oilpan's heap |
49 // whereas WebSocketImpl cannot be on Oilpan's heap. Thus we need to introduce a proxy | |
50 // class to decouple WebSocketImpl from WebSocketChannelClient. | |
51 class WebSocketChannelClientProxy FINAL : public NoBaseWillBeGarbageCollectedFin alized<WebSocketChannelClientProxy>, public blink::WebSocketChannelClient { | |
52 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(WebSocketChannelClientProxy) | |
53 public: | |
54 static PassOwnPtrWillBeRawPtr<WebSocketChannelClientProxy> create(WebSocketI mpl* impl) | |
55 { | |
56 return adoptPtrWillBeNoop(new WebSocketChannelClientProxy(impl)); | |
57 } | |
49 | 58 |
50 class WebSocketImpl FINAL : public NoBaseWillBeGarbageCollectedFinalized<WebSock etImpl>, public WebSocket, public blink::WebSocketChannelClient { | 59 virtual void didConnect(const String& subprotocol, const String& extensions) OVERRIDE |
51 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(WebSocketImpl) | 60 { |
52 public: | 61 m_impl->didConnect(subprotocol, extensions); |
53 WebSocketImpl(const WebDocument&, WebSocketClient*); | 62 } |
54 virtual ~WebSocketImpl(); | 63 virtual void didReceiveMessage(const String& message) OVERRIDE |
55 | 64 { |
56 bool isNull() const { return !m_private; } | 65 m_impl->didReceiveMessage(message); |
57 | 66 } |
58 virtual BinaryType binaryType() const OVERRIDE; | 67 virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData) OVER RIDE |
59 virtual bool setBinaryType(BinaryType) OVERRIDE; | 68 { |
60 virtual void connect(const WebURL&, const WebString& protocol) OVERRIDE; | 69 m_impl->didReceiveBinaryData(binaryData); |
61 virtual WebString subprotocol() OVERRIDE; | 70 } |
62 virtual WebString extensions() OVERRIDE; | 71 virtual void didReceiveMessageError() OVERRIDE |
63 virtual bool sendText(const WebString&) OVERRIDE; | 72 { |
64 virtual bool sendArrayBuffer(const WebArrayBuffer&) OVERRIDE; | 73 m_impl->didReceiveMessageError(); |
65 virtual unsigned long bufferedAmount() const OVERRIDE; | 74 } |
66 virtual void close(int code, const WebString& reason) OVERRIDE; | 75 virtual void didConsumeBufferedAmount(unsigned long consumed) OVERRIDE |
67 virtual void fail(const WebString& reason) OVERRIDE; | 76 { |
68 virtual void disconnect() OVERRIDE; | 77 m_impl->didConsumeBufferedAmount(consumed); |
69 | 78 } |
70 // WebSocketChannelClient | 79 virtual void didStartClosingHandshake() OVERRIDE |
71 virtual void didConnect(const String& subprotocol, const String& extensions) OVERRIDE; | 80 { |
72 virtual void didReceiveMessage(const String& message) OVERRIDE; | 81 m_impl->didStartClosingHandshake(); |
73 virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData) OVER RIDE; | 82 } |
74 virtual void didReceiveMessageError() OVERRIDE; | 83 virtual void didClose(ClosingHandshakeCompletionStatus status, unsigned shor t code, const String& reason) OVERRIDE |
75 virtual void didConsumeBufferedAmount(unsigned long consumed) OVERRIDE; | 84 { |
76 virtual void didStartClosingHandshake() OVERRIDE; | 85 m_impl->didClose(status, code, reason); |
yhirano
2014/08/04 01:05:52
Clearing m_impl would be good.
WebSocketImpl* imp
haraken
2014/08/04 01:21:57
Done.
| |
77 virtual void didClose(ClosingHandshakeCompletionStatus, unsigned short code, const String& reason) OVERRIDE; | 86 } |
78 | |
79 virtual void trace(blink::Visitor*) OVERRIDE; | |
80 | 87 |
81 private: | 88 private: |
82 RefPtrWillBeMember<blink::WebSocketChannel> m_private; | 89 explicit WebSocketChannelClientProxy(WebSocketImpl* impl) |
83 WebSocketClient* m_client; | 90 : m_impl(impl) |
84 BinaryType m_binaryType; | 91 { |
85 WebString m_subprotocol; | 92 } |
86 WebString m_extensions; | 93 |
87 bool m_isClosingOrClosed; | 94 WebSocketImpl* m_impl; |
88 // m_bufferedAmount includes m_bufferedAmountAfterClose. | |
89 unsigned long m_bufferedAmount; | |
90 unsigned long m_bufferedAmountAfterClose; | |
91 }; | 95 }; |
92 | 96 |
93 } // namespace blink | 97 } // namespace blink |
94 | 98 |
95 #endif // WebWebSocketChannelImpl_h | 99 #endif // WebSocketChannelClientProxy_h |
OLD | NEW |