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 15 matching lines...) Expand all Loading... |
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 WorkerThreadableWebSocketChannel_h |
32 #define WorkerThreadableWebSocketChannel_h | 32 #define WorkerThreadableWebSocketChannel_h |
33 | 33 |
34 #include "core/frame/ConsoleTypes.h" | 34 #include "core/frame/ConsoleTypes.h" |
35 #include "core/workers/WorkerGlobalScope.h" | 35 #include "core/workers/WorkerGlobalScope.h" |
| 36 #include "heap/Handle.h" |
36 #include "modules/websockets/WebSocketChannel.h" | 37 #include "modules/websockets/WebSocketChannel.h" |
37 #include "modules/websockets/WebSocketChannelClient.h" | 38 #include "modules/websockets/WebSocketChannelClient.h" |
38 | 39 |
39 #include "wtf/PassOwnPtr.h" | 40 #include "wtf/PassOwnPtr.h" |
40 #include "wtf/PassRefPtr.h" | 41 #include "wtf/PassRefPtr.h" |
41 #include "wtf/RefCounted.h" | 42 #include "wtf/RefCounted.h" |
42 #include "wtf/RefPtr.h" | 43 #include "wtf/RefPtr.h" |
43 #include "wtf/Threading.h" | 44 #include "wtf/Threading.h" |
44 #include "wtf/Vector.h" | 45 #include "wtf/Vector.h" |
45 #include "wtf/WeakPtr.h" | 46 #include "wtf/WeakPtr.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 | 132 |
132 protected: | 133 protected: |
133 // WebSocketChannel functions. | 134 // WebSocketChannel functions. |
134 virtual void refWebSocketChannel() OVERRIDE { ref(); } | 135 virtual void refWebSocketChannel() OVERRIDE { ref(); } |
135 virtual void derefWebSocketChannel() OVERRIDE { deref(); } | 136 virtual void derefWebSocketChannel() OVERRIDE { deref(); } |
136 | 137 |
137 private: | 138 private: |
138 // Bridge for Peer. Running on the worker thread. | 139 // Bridge for Peer. Running on the worker thread. |
139 class Bridge : public RefCounted<Bridge> { | 140 class Bridge : public RefCounted<Bridge> { |
140 public: | 141 public: |
141 static PassRefPtr<Bridge> create(PassRefPtr<ThreadableWebSocketChannelCl
ientWrapper> workerClientWrapper, PassRefPtr<WorkerGlobalScope> workerGlobalScop
e) | 142 static PassRefPtr<Bridge> create(PassRefPtr<ThreadableWebSocketChannelCl
ientWrapper> workerClientWrapper, PassRefPtrWillBeRawPtr<WorkerGlobalScope> work
erGlobalScope) |
142 { | 143 { |
143 return adoptRef(new Bridge(workerClientWrapper, workerGlobalScope)); | 144 return adoptRef(new Bridge(workerClientWrapper, workerGlobalScope)); |
144 } | 145 } |
145 ~Bridge(); | 146 ~Bridge(); |
146 // sourceURLAtConnection and lineNumberAtConnection parameters may | 147 // sourceURLAtConnection and lineNumberAtConnection parameters may |
147 // be shown when the connection fails. | 148 // be shown when the connection fails. |
148 void initialize(const String& sourceURLAtConnection, unsigned lineNumber
AtConnection); | 149 void initialize(const String& sourceURLAtConnection, unsigned lineNumber
AtConnection); |
149 void connect(const KURL&, const String& protocol); | 150 void connect(const KURL&, const String& protocol); |
150 WebSocketChannel::SendResult send(const String& message); | 151 WebSocketChannel::SendResult send(const String& message); |
151 WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffse
t, unsigned byteLength); | 152 WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffse
t, unsigned byteLength); |
152 WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>); | 153 WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>); |
153 unsigned long bufferedAmount(); | 154 unsigned long bufferedAmount(); |
154 void close(int code, const String& reason); | 155 void close(int code, const String& reason); |
155 void fail(const String& reason, MessageLevel, const String& sourceURL, u
nsigned lineNumber); | 156 void fail(const String& reason, MessageLevel, const String& sourceURL, u
nsigned lineNumber); |
156 void disconnect(); | 157 void disconnect(); |
157 void suspend(); | 158 void suspend(); |
158 void resume(); | 159 void resume(); |
159 | 160 |
160 using RefCounted<Bridge>::ref; | 161 using RefCounted<Bridge>::ref; |
161 using RefCounted<Bridge>::deref; | 162 using RefCounted<Bridge>::deref; |
162 | 163 |
163 private: | 164 private: |
164 Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, PassRefPtr<W
orkerGlobalScope>); | 165 Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, PassRefPtrWi
llBeRawPtr<WorkerGlobalScope>); |
165 | 166 |
166 static void setWebSocketChannel(ExecutionContext*, Bridge* thisPtr, Peer
*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>); | 167 static void setWebSocketChannel(ExecutionContext*, Bridge* thisPtr, Peer
*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>); |
167 | 168 |
168 // Executed on the worker context's thread. | 169 // Executed on the worker context's thread. |
169 void clearClientWrapper(); | 170 void clearClientWrapper(); |
170 | 171 |
171 // Returns false if shutdown event is received before method completion. | 172 // Returns false if shutdown event is received before method completion. |
172 bool waitForMethodCompletion(); | 173 bool waitForMethodCompletion(); |
173 | 174 |
174 void terminatePeer(); | 175 void terminatePeer(); |
175 | 176 |
176 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; | 177 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; |
177 RefPtr<WorkerGlobalScope> m_workerGlobalScope; | 178 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; |
178 WorkerLoaderProxy& m_loaderProxy; | 179 WorkerLoaderProxy& m_loaderProxy; |
179 ThreadableWebSocketChannelSyncHelper* m_syncHelper; | 180 ThreadableWebSocketChannelSyncHelper* m_syncHelper; |
180 WeakPtr<Peer> m_peer; | 181 WeakPtr<Peer> m_peer; |
181 }; | 182 }; |
182 | 183 |
183 WorkerThreadableWebSocketChannel(WorkerGlobalScope*, WebSocketChannelClient*
, const String& sourceURL, unsigned lineNumber); | 184 WorkerThreadableWebSocketChannel(WorkerGlobalScope*, WebSocketChannelClient*
, const String& sourceURL, unsigned lineNumber); |
184 | 185 |
185 RefPtr<WorkerGlobalScope> m_workerGlobalScope; | 186 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; |
186 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; | 187 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; |
187 RefPtr<Bridge> m_bridge; | 188 RefPtr<Bridge> m_bridge; |
188 String m_sourceURLAtConnection; | 189 String m_sourceURLAtConnection; |
189 unsigned m_lineNumberAtConnection; | 190 unsigned m_lineNumberAtConnection; |
190 }; | 191 }; |
191 | 192 |
192 } // namespace WebCore | 193 } // namespace WebCore |
193 | 194 |
194 #endif // WorkerThreadableWebSocketChannel_h | 195 #endif // WorkerThreadableWebSocketChannel_h |
OLD | NEW |