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 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 WorkerThreadableWebSocketChannel_h | 31 #ifndef WorkerWebSocketChannel_h |
32 #define WorkerThreadableWebSocketChannel_h | 32 #define WorkerWebSocketChannel_h |
33 | 33 |
34 #include "core/frame/ConsoleTypes.h" | 34 #include "core/frame/ConsoleTypes.h" |
35 #include "modules/websockets/WebSocketChannel.h" | 35 #include "modules/websockets/WebSocketChannel.h" |
36 #include "modules/websockets/WebSocketChannelClient.h" | 36 #include "modules/websockets/WebSocketChannelClient.h" |
37 #include "platform/heap/Handle.h" | 37 #include "platform/heap/Handle.h" |
38 #include "wtf/Assertions.h" | 38 #include "wtf/Assertions.h" |
39 #include "wtf/Forward.h" | 39 #include "wtf/Forward.h" |
40 #include "wtf/OwnPtr.h" | 40 #include "wtf/OwnPtr.h" |
41 #include "wtf/RefPtr.h" | 41 #include "wtf/RefPtr.h" |
42 #include "wtf/Vector.h" | 42 #include "wtf/Vector.h" |
43 #include "wtf/text/WTFString.h" | 43 #include "wtf/text/WTFString.h" |
44 | 44 |
45 namespace blink { | 45 namespace blink { |
46 | 46 |
47 class BlobDataHandle; | 47 class BlobDataHandle; |
48 class KURL; | 48 class KURL; |
49 class ExecutionContext; | 49 class ExecutionContext; |
50 class ExecutionContextTask; | 50 class ExecutionContextTask; |
51 class ThreadableWebSocketChannelSyncHelper; | 51 class WebSocketChannelSyncHelper; |
52 class WorkerGlobalScope; | 52 class WorkerGlobalScope; |
53 class WorkerLoaderProxy; | 53 class WorkerLoaderProxy; |
54 | 54 |
55 class WorkerThreadableWebSocketChannel final : public WebSocketChannel { | 55 class WorkerWebSocketChannel final : public WebSocketChannel { |
56 WTF_MAKE_NONCOPYABLE(WorkerThreadableWebSocketChannel); | 56 WTF_MAKE_NONCOPYABLE(WorkerWebSocketChannel); |
57 public: | 57 public: |
58 static WebSocketChannel* create(WorkerGlobalScope& workerGlobalScope, WebSoc
ketChannelClient* client, const String& sourceURL, unsigned lineNumber) | 58 static WebSocketChannel* create(WorkerGlobalScope& workerGlobalScope, WebSoc
ketChannelClient* client, const String& sourceURL, unsigned lineNumber) |
59 { | 59 { |
60 return new WorkerThreadableWebSocketChannel(workerGlobalScope, client, s
ourceURL, lineNumber); | 60 return new WorkerWebSocketChannel(workerGlobalScope, client, sourceURL,
lineNumber); |
61 } | 61 } |
62 virtual ~WorkerThreadableWebSocketChannel(); | 62 virtual ~WorkerWebSocketChannel(); |
63 | 63 |
64 // WebSocketChannel functions. | 64 // WebSocketChannel functions. |
65 virtual bool connect(const KURL&, const String& protocol) override; | 65 virtual bool connect(const KURL&, const String& protocol) override; |
66 virtual void send(const String& message) override; | 66 virtual void send(const String& message) override; |
67 virtual void send(const ArrayBuffer&, unsigned byteOffset, unsigned byteLeng
th) override; | 67 virtual void send(const ArrayBuffer&, unsigned byteOffset, unsigned byteLeng
th) override; |
68 virtual void send(PassRefPtr<BlobDataHandle>) override; | 68 virtual void send(PassRefPtr<BlobDataHandle>) override; |
69 virtual void send(PassOwnPtr<Vector<char> >) override | 69 virtual void send(PassOwnPtr<Vector<char> >) override |
70 { | 70 { |
71 ASSERT_NOT_REACHED(); | 71 ASSERT_NOT_REACHED(); |
72 } | 72 } |
73 virtual void close(int code, const String& reason) override; | 73 virtual void close(int code, const String& reason) override; |
74 virtual void fail(const String& reason, MessageLevel, const String&, unsigne
d) override; | 74 virtual void fail(const String& reason, MessageLevel, const String&, unsigne
d) override; |
75 virtual void disconnect() override; // Will suppress didClose(). | 75 virtual void disconnect() override; // Will suppress didClose(). |
76 virtual void suspend() override { } | 76 virtual void suspend() override { } |
77 virtual void resume() override { } | 77 virtual void resume() override { } |
78 | 78 |
79 virtual void trace(Visitor*) override; | 79 virtual void trace(Visitor*) override; |
80 | 80 |
81 class Bridge; | 81 class Bridge; |
82 // Allocated in the worker thread, but used in the main thread. | 82 // Allocated in the worker thread, but used in the main thread. |
83 class Peer final : public GarbageCollectedFinalized<Peer>, public WebSocketC
hannelClient { | 83 class Peer final : public GarbageCollectedFinalized<Peer>, public WebSocketC
hannelClient { |
84 USING_GARBAGE_COLLECTED_MIXIN(Peer); | 84 USING_GARBAGE_COLLECTED_MIXIN(Peer); |
85 WTF_MAKE_NONCOPYABLE(Peer); | 85 WTF_MAKE_NONCOPYABLE(Peer); |
86 public: | 86 public: |
87 Peer(Bridge*, WorkerLoaderProxy&, ThreadableWebSocketChannelSyncHelper*)
; | 87 Peer(Bridge*, WorkerLoaderProxy&, WebSocketChannelSyncHelper*); |
88 virtual ~Peer(); | 88 virtual ~Peer(); |
89 | 89 |
90 // sourceURLAtConnection and lineNumberAtConnection parameters may | 90 // sourceURLAtConnection and lineNumberAtConnection parameters may |
91 // be shown when the connection fails. | 91 // be shown when the connection fails. |
92 static void initialize(ExecutionContext* executionContext, Peer* peer, c
onst String& sourceURLAtConnection, unsigned lineNumberAtConnection) | 92 static void initialize(ExecutionContext* executionContext, Peer* peer, c
onst String& sourceURLAtConnection, unsigned lineNumberAtConnection) |
93 { | 93 { |
94 peer->initializeInternal(executionContext, sourceURLAtConnection, li
neNumberAtConnection); | 94 peer->initializeInternal(executionContext, sourceURLAtConnection, li
neNumberAtConnection); |
95 } | 95 } |
96 | 96 |
97 void connect(const KURL&, const String& protocol); | 97 void connect(const KURL&, const String& protocol); |
(...skipping 15 matching lines...) Expand all Loading... |
113 virtual void didStartClosingHandshake() override; | 113 virtual void didStartClosingHandshake() override; |
114 virtual void didClose(ClosingHandshakeCompletionStatus, unsigned short c
ode, const String& reason) override; | 114 virtual void didClose(ClosingHandshakeCompletionStatus, unsigned short c
ode, const String& reason) override; |
115 virtual void didError() override; | 115 virtual void didError() override; |
116 | 116 |
117 private: | 117 private: |
118 void initializeInternal(ExecutionContext*, const String& sourceURLAtConn
ection, unsigned lineNumberAtConnection); | 118 void initializeInternal(ExecutionContext*, const String& sourceURLAtConn
ection, unsigned lineNumberAtConnection); |
119 | 119 |
120 Member<Bridge> m_bridge; | 120 Member<Bridge> m_bridge; |
121 WorkerLoaderProxy& m_loaderProxy; | 121 WorkerLoaderProxy& m_loaderProxy; |
122 Member<WebSocketChannel> m_mainWebSocketChannel; | 122 Member<WebSocketChannel> m_mainWebSocketChannel; |
123 Member<ThreadableWebSocketChannelSyncHelper> m_syncHelper; | 123 Member<WebSocketChannelSyncHelper> m_syncHelper; |
124 }; | 124 }; |
125 | 125 |
126 // Bridge for Peer. Running on the worker thread. | 126 // Bridge for Peer. Running on the worker thread. |
127 class Bridge final : public GarbageCollectedFinalized<Bridge> { | 127 class Bridge final : public GarbageCollectedFinalized<Bridge> { |
128 WTF_MAKE_NONCOPYABLE(Bridge); | 128 WTF_MAKE_NONCOPYABLE(Bridge); |
129 public: | 129 public: |
130 Bridge(WebSocketChannelClient*, WorkerGlobalScope&); | 130 Bridge(WebSocketChannelClient*, WorkerGlobalScope&); |
131 ~Bridge(); | 131 ~Bridge(); |
132 // sourceURLAtConnection and lineNumberAtConnection parameters may | 132 // sourceURLAtConnection and lineNumberAtConnection parameters may |
133 // be shown when the connection fails. | 133 // be shown when the connection fails. |
(...skipping 12 matching lines...) Expand all Loading... |
146 | 146 |
147 void trace(Visitor*); | 147 void trace(Visitor*); |
148 | 148 |
149 private: | 149 private: |
150 // Returns false if shutdown event is received before method completion. | 150 // Returns false if shutdown event is received before method completion. |
151 bool waitForMethodCompletion(PassOwnPtr<ExecutionContextTask>); | 151 bool waitForMethodCompletion(PassOwnPtr<ExecutionContextTask>); |
152 | 152 |
153 Member<WebSocketChannelClient> m_client; | 153 Member<WebSocketChannelClient> m_client; |
154 RefPtrWillBeMember<WorkerGlobalScope> m_workerGlobalScope; | 154 RefPtrWillBeMember<WorkerGlobalScope> m_workerGlobalScope; |
155 WorkerLoaderProxy& m_loaderProxy; | 155 WorkerLoaderProxy& m_loaderProxy; |
156 Member<ThreadableWebSocketChannelSyncHelper> m_syncHelper; | 156 Member<WebSocketChannelSyncHelper> m_syncHelper; |
157 Member<Peer> m_peer; | 157 Member<Peer> m_peer; |
158 }; | 158 }; |
159 | 159 |
160 private: | 160 private: |
161 WorkerThreadableWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient*
, const String& sourceURL, unsigned lineNumber); | 161 WorkerWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient*, const St
ring& sourceURL, unsigned lineNumber); |
162 | 162 |
163 Member<Bridge> m_bridge; | 163 Member<Bridge> m_bridge; |
164 String m_sourceURLAtConnection; | 164 String m_sourceURLAtConnection; |
165 unsigned m_lineNumberAtConnection; | 165 unsigned m_lineNumberAtConnection; |
166 }; | 166 }; |
167 | 167 |
168 } // namespace blink | 168 } // namespace blink |
169 | 169 |
170 #endif // WorkerThreadableWebSocketChannel_h | 170 #endif // WorkerWebSocketChannel_h |
OLD | NEW |