OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 14 matching lines...) Expand all Loading... |
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 WorkerWebSocketChannel_h | 31 #ifndef WorkerWebSocketChannel_h |
32 #define WorkerWebSocketChannel_h | 32 #define WorkerWebSocketChannel_h |
33 | 33 |
34 #include "bindings/core/v8/SourceLocation.h" | 34 #include "bindings/core/v8/SourceLocation.h" |
| 35 #include "core/workers/WorkerThreadLifecycleObserver.h" |
35 #include "modules/websockets/WebSocketChannel.h" | 36 #include "modules/websockets/WebSocketChannel.h" |
36 #include "modules/websockets/WebSocketChannelClient.h" | 37 #include "modules/websockets/WebSocketChannelClient.h" |
37 #include "platform/heap/Handle.h" | 38 #include "platform/heap/Handle.h" |
38 #include "platform/v8_inspector/public/ConsoleTypes.h" | 39 #include "platform/v8_inspector/public/ConsoleTypes.h" |
39 #include "wtf/Assertions.h" | 40 #include "wtf/Assertions.h" |
40 #include "wtf/Forward.h" | 41 #include "wtf/Forward.h" |
41 #include "wtf/OwnPtr.h" | 42 #include "wtf/OwnPtr.h" |
42 #include "wtf/RefPtr.h" | 43 #include "wtf/RefPtr.h" |
43 #include "wtf/Vector.h" | 44 #include "wtf/Vector.h" |
44 #include "wtf/text/WTFString.h" | 45 #include "wtf/text/WTFString.h" |
45 #include <stdint.h> | 46 #include <stdint.h> |
46 | 47 |
47 namespace blink { | 48 namespace blink { |
48 | 49 |
49 class BlobDataHandle; | 50 class BlobDataHandle; |
50 class KURL; | 51 class KURL; |
51 class ExecutionContext; | 52 class ExecutionContext; |
52 class ExecutionContextTask; | 53 class ExecutionContextTask; |
53 class WebSocketChannelSyncHelper; | 54 class WebSocketChannelSyncHelper; |
54 class WorkerGlobalScope; | 55 class WorkerGlobalScope; |
55 class WorkerLoaderProxy; | 56 class WorkerLoaderProxy; |
| 57 class WorkerThread; |
56 | 58 |
57 class WorkerWebSocketChannel final : public WebSocketChannel { | 59 class WorkerWebSocketChannel final : public WebSocketChannel { |
58 WTF_MAKE_NONCOPYABLE(WorkerWebSocketChannel); | 60 WTF_MAKE_NONCOPYABLE(WorkerWebSocketChannel); |
59 public: | 61 public: |
60 static WebSocketChannel* create(WorkerGlobalScope& workerGlobalScope, WebSoc
ketChannelClient* client, PassOwnPtr<SourceLocation> location) | 62 static WebSocketChannel* create(WorkerGlobalScope& workerGlobalScope, WebSoc
ketChannelClient* client, PassOwnPtr<SourceLocation> location) |
61 { | 63 { |
62 return new WorkerWebSocketChannel(workerGlobalScope, client, std::move(l
ocation)); | 64 return new WorkerWebSocketChannel(workerGlobalScope, client, std::move(l
ocation)); |
63 } | 65 } |
64 ~WorkerWebSocketChannel() override; | 66 ~WorkerWebSocketChannel() override; |
65 | 67 |
(...skipping 11 matching lines...) Expand all Loading... |
77 ASSERT_NOT_REACHED(); | 79 ASSERT_NOT_REACHED(); |
78 } | 80 } |
79 void close(int code, const String& reason) override; | 81 void close(int code, const String& reason) override; |
80 void fail(const String& reason, MessageLevel, PassOwnPtr<SourceLocation>) ov
erride; | 82 void fail(const String& reason, MessageLevel, PassOwnPtr<SourceLocation>) ov
erride; |
81 void disconnect() override; // Will suppress didClose(). | 83 void disconnect() override; // Will suppress didClose(). |
82 | 84 |
83 DECLARE_VIRTUAL_TRACE(); | 85 DECLARE_VIRTUAL_TRACE(); |
84 | 86 |
85 class Bridge; | 87 class Bridge; |
86 // Allocated in the worker thread, but used in the main thread. | 88 // Allocated in the worker thread, but used in the main thread. |
87 class Peer final : public GarbageCollectedFinalized<Peer>, public WebSocketC
hannelClient { | 89 class Peer final : public GarbageCollectedFinalized<Peer>, public WebSocketC
hannelClient, public WorkerThreadLifecycleObserver { |
88 USING_GARBAGE_COLLECTED_MIXIN(Peer); | 90 USING_GARBAGE_COLLECTED_MIXIN(Peer); |
89 WTF_MAKE_NONCOPYABLE(Peer); | 91 WTF_MAKE_NONCOPYABLE(Peer); |
90 public: | 92 public: |
91 Peer(Bridge*, PassRefPtr<WorkerLoaderProxy>, WebSocketChannelSyncHelper*
); | 93 Peer(Bridge*, PassRefPtr<WorkerLoaderProxy>, WebSocketChannelSyncHelper*
, WorkerThread*); |
92 ~Peer() override; | 94 ~Peer() override; |
93 | 95 |
94 // SourceLocation parameter may be shown when the connection fails. | 96 // SourceLocation parameter may be shown when the connection fails. |
95 void initialize(PassOwnPtr<SourceLocation>, ExecutionContext*); | 97 void initialize(PassOwnPtr<SourceLocation>, ExecutionContext*); |
96 | 98 |
97 void connect(const KURL&, const String& protocol); | 99 void connect(const KURL&, const String& protocol); |
98 void sendTextAsCharVector(PassOwnPtr<Vector<char>>); | 100 void sendTextAsCharVector(PassOwnPtr<Vector<char>>); |
99 void sendBinaryAsCharVector(PassOwnPtr<Vector<char>>); | 101 void sendBinaryAsCharVector(PassOwnPtr<Vector<char>>); |
100 void sendBlob(PassRefPtr<BlobDataHandle>); | 102 void sendBlob(PassRefPtr<BlobDataHandle>); |
101 void close(int code, const String& reason); | 103 void close(int code, const String& reason); |
102 void fail(const String& reason, MessageLevel, PassOwnPtr<SourceLocation>
); | 104 void fail(const String& reason, MessageLevel, PassOwnPtr<SourceLocation>
); |
103 void disconnect(); | 105 void disconnect(); |
104 | 106 |
105 DECLARE_VIRTUAL_TRACE(); | 107 DECLARE_VIRTUAL_TRACE(); |
106 | 108 |
107 // WebSocketChannelClient functions. | 109 // WebSocketChannelClient functions. |
108 void didConnect(const String& subprotocol, const String& extensions) ove
rride; | 110 void didConnect(const String& subprotocol, const String& extensions) ove
rride; |
109 void didReceiveTextMessage(const String& payload) override; | 111 void didReceiveTextMessage(const String& payload) override; |
110 void didReceiveBinaryMessage(PassOwnPtr<Vector<char>>) override; | 112 void didReceiveBinaryMessage(PassOwnPtr<Vector<char>>) override; |
111 void didConsumeBufferedAmount(uint64_t) override; | 113 void didConsumeBufferedAmount(uint64_t) override; |
112 void didStartClosingHandshake() override; | 114 void didStartClosingHandshake() override; |
113 void didClose(ClosingHandshakeCompletionStatus, unsigned short code, con
st String& reason) override; | 115 void didClose(ClosingHandshakeCompletionStatus, unsigned short code, con
st String& reason) override; |
114 void didError() override; | 116 void didError() override; |
115 | 117 |
| 118 // WorkerThreadLifecycleObserver function. |
| 119 void contextDestroyed() override; |
| 120 |
116 private: | 121 private: |
117 Member<Bridge> m_bridge; | 122 Member<Bridge> m_bridge; |
118 RefPtr<WorkerLoaderProxy> m_loaderProxy; | 123 RefPtr<WorkerLoaderProxy> m_loaderProxy; |
119 Member<WebSocketChannel> m_mainWebSocketChannel; | 124 Member<WebSocketChannel> m_mainWebSocketChannel; |
120 Member<WebSocketChannelSyncHelper> m_syncHelper; | 125 Member<WebSocketChannelSyncHelper> m_syncHelper; |
121 }; | 126 }; |
122 | 127 |
123 // Bridge for Peer. Running on the worker thread. | 128 // Bridge for Peer. Running on the worker thread. |
124 class Bridge final : public GarbageCollectedFinalized<Bridge> { | 129 class Bridge final : public GarbageCollectedFinalized<Bridge> { |
125 WTF_MAKE_NONCOPYABLE(Bridge); | 130 WTF_MAKE_NONCOPYABLE(Bridge); |
(...skipping 29 matching lines...) Expand all Loading... |
155 private: | 160 private: |
156 WorkerWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient*, PassOwnP
tr<SourceLocation>); | 161 WorkerWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient*, PassOwnP
tr<SourceLocation>); |
157 | 162 |
158 Member<Bridge> m_bridge; | 163 Member<Bridge> m_bridge; |
159 OwnPtr<SourceLocation> m_locationAtConnection; | 164 OwnPtr<SourceLocation> m_locationAtConnection; |
160 }; | 165 }; |
161 | 166 |
162 } // namespace blink | 167 } // namespace blink |
163 | 168 |
164 #endif // WorkerWebSocketChannel_h | 169 #endif // WorkerWebSocketChannel_h |
OLD | NEW |