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 18 matching lines...) Expand all Loading... |
29 */ | 29 */ |
30 | 30 |
31 #ifndef WorkerThreadableWebSocketChannel_h | 31 #ifndef WorkerThreadableWebSocketChannel_h |
32 #define WorkerThreadableWebSocketChannel_h | 32 #define WorkerThreadableWebSocketChannel_h |
33 | 33 |
34 #if ENABLE(WEB_SOCKETS) && ENABLE(WORKERS) | 34 #if ENABLE(WEB_SOCKETS) && ENABLE(WORKERS) |
35 | 35 |
36 #include "PlatformString.h" | 36 #include "PlatformString.h" |
37 #include "ThreadableWebSocketChannel.h" | 37 #include "ThreadableWebSocketChannel.h" |
38 #include "WebSocketChannelClient.h" | 38 #include "WebSocketChannelClient.h" |
| 39 #include "WorkerContext.h" |
39 | 40 |
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 | 45 |
45 namespace WebCore { | 46 namespace WebCore { |
46 | 47 |
47 class KURL; | 48 class KURL; |
48 class ScriptExecutionContext; | 49 class ScriptExecutionContext; |
(...skipping 19 matching lines...) Expand all Loading... |
68 virtual ThreadableWebSocketChannel::SendResult send(const String& message) O
VERRIDE; | 69 virtual ThreadableWebSocketChannel::SendResult send(const String& message) O
VERRIDE; |
69 virtual ThreadableWebSocketChannel::SendResult send(const ArrayBuffer&) OVER
RIDE; | 70 virtual ThreadableWebSocketChannel::SendResult send(const ArrayBuffer&) OVER
RIDE; |
70 virtual ThreadableWebSocketChannel::SendResult send(const Blob&) OVERRIDE; | 71 virtual ThreadableWebSocketChannel::SendResult send(const Blob&) OVERRIDE; |
71 virtual unsigned long bufferedAmount() const OVERRIDE; | 72 virtual unsigned long bufferedAmount() const OVERRIDE; |
72 virtual void close(int code, const String& reason) OVERRIDE; | 73 virtual void close(int code, const String& reason) OVERRIDE; |
73 virtual void fail(const String& reason) OVERRIDE; | 74 virtual void fail(const String& reason) OVERRIDE; |
74 virtual void disconnect() OVERRIDE; // Will suppress didClose(). | 75 virtual void disconnect() OVERRIDE; // Will suppress didClose(). |
75 virtual void suspend() OVERRIDE; | 76 virtual void suspend() OVERRIDE; |
76 virtual void resume() OVERRIDE; | 77 virtual void resume() OVERRIDE; |
77 | 78 |
78 using RefCounted<WorkerThreadableWebSocketChannel>::ref; | |
79 using RefCounted<WorkerThreadableWebSocketChannel>::deref; | |
80 | |
81 protected: | |
82 virtual void refThreadableWebSocketChannel() { ref(); } | |
83 virtual void derefThreadableWebSocketChannel() { deref(); } | |
84 | |
85 private: | |
86 // Generated by the bridge. The Peer and its bridge should have identical | 79 // Generated by the bridge. The Peer and its bridge should have identical |
87 // lifetimes. | 80 // lifetimes. |
88 class Peer : public WebSocketChannelClient { | 81 class Peer : public WebSocketChannelClient { |
89 WTF_MAKE_NONCOPYABLE(Peer); WTF_MAKE_FAST_ALLOCATED; | 82 WTF_MAKE_NONCOPYABLE(Peer); WTF_MAKE_FAST_ALLOCATED; |
90 public: | 83 public: |
91 static Peer* create(PassRefPtr<ThreadableWebSocketChannelClientWrapper>
clientWrapper, WorkerLoaderProxy& loaderProxy, ScriptExecutionContext* context,
const String& taskMode) | 84 static Peer* create(PassRefPtr<ThreadableWebSocketChannelClientWrapper>
clientWrapper, WorkerLoaderProxy& loaderProxy, ScriptExecutionContext* context,
const String& taskMode) |
92 { | 85 { |
93 return new Peer(clientWrapper, loaderProxy, context, taskMode); | 86 return new Peer(clientWrapper, loaderProxy, context, taskMode); |
94 } | 87 } |
95 ~Peer(); | 88 ~Peer(); |
(...skipping 20 matching lines...) Expand all Loading... |
116 | 109 |
117 private: | 110 private: |
118 Peer(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, WorkerLoaderPr
oxy&, ScriptExecutionContext*, const String& taskMode); | 111 Peer(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, WorkerLoaderPr
oxy&, ScriptExecutionContext*, const String& taskMode); |
119 | 112 |
120 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; | 113 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; |
121 WorkerLoaderProxy& m_loaderProxy; | 114 WorkerLoaderProxy& m_loaderProxy; |
122 RefPtr<ThreadableWebSocketChannel> m_mainWebSocketChannel; | 115 RefPtr<ThreadableWebSocketChannel> m_mainWebSocketChannel; |
123 String m_taskMode; | 116 String m_taskMode; |
124 }; | 117 }; |
125 | 118 |
| 119 using RefCounted<WorkerThreadableWebSocketChannel>::ref; |
| 120 using RefCounted<WorkerThreadableWebSocketChannel>::deref; |
| 121 |
| 122 protected: |
| 123 virtual void refThreadableWebSocketChannel() { ref(); } |
| 124 virtual void derefThreadableWebSocketChannel() { deref(); } |
| 125 |
| 126 private: |
126 // Bridge for Peer. Running on the worker thread. | 127 // Bridge for Peer. Running on the worker thread. |
127 class Bridge : public RefCounted<Bridge> { | 128 class Bridge : public RefCounted<Bridge> { |
128 public: | 129 public: |
129 static PassRefPtr<Bridge> create(PassRefPtr<ThreadableWebSocketChannelCl
ientWrapper> workerClientWrapper, PassRefPtr<WorkerContext> workerContext, const
String& taskMode) | 130 static PassRefPtr<Bridge> create(PassRefPtr<ThreadableWebSocketChannelCl
ientWrapper> workerClientWrapper, PassRefPtr<WorkerContext> workerContext, const
String& taskMode) |
130 { | 131 { |
131 return adoptRef(new Bridge(workerClientWrapper, workerContext, taskM
ode)); | 132 return adoptRef(new Bridge(workerClientWrapper, workerContext, taskM
ode)); |
132 } | 133 } |
133 ~Bridge(); | 134 ~Bridge(); |
| 135 void initialize(); |
134 void connect(const KURL&, const String& protocol); | 136 void connect(const KURL&, const String& protocol); |
135 ThreadableWebSocketChannel::SendResult send(const String& message); | 137 ThreadableWebSocketChannel::SendResult send(const String& message); |
136 ThreadableWebSocketChannel::SendResult send(const ArrayBuffer&); | 138 ThreadableWebSocketChannel::SendResult send(const ArrayBuffer&); |
137 ThreadableWebSocketChannel::SendResult send(const Blob&); | 139 ThreadableWebSocketChannel::SendResult send(const Blob&); |
138 unsigned long bufferedAmount(); | 140 unsigned long bufferedAmount(); |
139 void close(int code, const String& reason); | 141 void close(int code, const String& reason); |
140 void fail(const String& reason); | 142 void fail(const String& reason); |
141 void disconnect(); | 143 void disconnect(); |
142 void suspend(); | 144 void suspend(); |
143 void resume(); | 145 void resume(); |
144 | 146 |
145 using RefCounted<Bridge>::ref; | 147 using RefCounted<Bridge>::ref; |
146 using RefCounted<Bridge>::deref; | 148 using RefCounted<Bridge>::deref; |
147 | 149 |
148 private: | 150 private: |
149 Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, PassRefPtr<W
orkerContext>, const String& taskMode); | 151 Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, PassRefPtr<W
orkerContext>, const String& taskMode); |
150 | 152 |
151 static void setWebSocketChannel(ScriptExecutionContext*, Bridge* thisPtr
, Peer*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>, bool useHixie76Pro
tocol); | 153 static void setWebSocketChannel(ScriptExecutionContext*, Bridge* thisPtr
, Peer*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>, bool useHixie76Pro
tocol); |
152 | 154 |
153 // Executed on the main thread to create a Peer for this bridge. | 155 // Executed on the main thread to create a Peer for this bridge. |
154 static void mainThreadCreateWebSocketChannel(ScriptExecutionContext*, Br
idge* thisPtr, PassRefPtr<ThreadableWebSocketChannelClientWrapper>, const String
& taskMode); | 156 static void mainThreadInitialize(ScriptExecutionContext*, WorkerLoaderPr
oxy*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>, const String& taskMod
e); |
155 | 157 |
156 // Executed on the worker context's thread. | 158 // Executed on the worker context's thread. |
157 void clearClientWrapper(); | 159 void clearClientWrapper(); |
158 | 160 |
159 void setMethodNotCompleted(); | 161 void setMethodNotCompleted(); |
160 void waitForMethodCompletion(); | 162 void waitForMethodCompletion(); |
161 | 163 |
162 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; | 164 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; |
163 RefPtr<WorkerContext> m_workerContext; | 165 RefPtr<WorkerContext> m_workerContext; |
164 WorkerLoaderProxy& m_loaderProxy; | 166 WorkerLoaderProxy& m_loaderProxy; |
(...skipping 17 matching lines...) Expand all Loading... |
182 RefPtr<WorkerContext> m_workerContext; | 184 RefPtr<WorkerContext> m_workerContext; |
183 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; | 185 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; |
184 RefPtr<Bridge> m_bridge; | 186 RefPtr<Bridge> m_bridge; |
185 }; | 187 }; |
186 | 188 |
187 } // namespace WebCore | 189 } // namespace WebCore |
188 | 190 |
189 #endif // ENABLE(WEB_SOCKETS) | 191 #endif // ENABLE(WEB_SOCKETS) |
190 | 192 |
191 #endif // WorkerThreadableWebSocketChannel_h | 193 #endif // WorkerThreadableWebSocketChannel_h |
OLD | NEW |