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 13 matching lines...) Expand all Loading... |
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 WorkerThreadableWebSocketChannel_h |
32 #define WorkerThreadableWebSocketChannel_h | 32 #define WorkerThreadableWebSocketChannel_h |
33 | 33 |
| 34 #include "core/inspector/ScriptCallFrame.h" |
| 35 #include "core/page/ConsoleTypes.h" |
34 #include "core/workers/WorkerContext.h" | 36 #include "core/workers/WorkerContext.h" |
35 #include "modules/websockets/WebSocketChannel.h" | 37 #include "modules/websockets/WebSocketChannel.h" |
36 #include "modules/websockets/WebSocketChannelClient.h" | 38 #include "modules/websockets/WebSocketChannelClient.h" |
37 | 39 |
| 40 #include "wtf/PassOwnPtr.h" |
38 #include "wtf/PassRefPtr.h" | 41 #include "wtf/PassRefPtr.h" |
39 #include "wtf/RefCounted.h" | 42 #include "wtf/RefCounted.h" |
40 #include "wtf/RefPtr.h" | 43 #include "wtf/RefPtr.h" |
41 #include "wtf/Threading.h" | 44 #include "wtf/Threading.h" |
| 45 #include "wtf/Vector.h" |
42 #include "wtf/text/WTFString.h" | 46 #include "wtf/text/WTFString.h" |
43 | 47 |
44 namespace WebCore { | 48 namespace WebCore { |
45 | 49 |
46 class KURL; | 50 class KURL; |
47 class ScriptExecutionContext; | 51 class ScriptExecutionContext; |
48 class ThreadableWebSocketChannelClientWrapper; | 52 class ThreadableWebSocketChannelClientWrapper; |
49 class WorkerContext; | 53 class WorkerContext; |
50 class WorkerLoaderProxy; | 54 class WorkerLoaderProxy; |
51 class WorkerRunLoop; | 55 class WorkerRunLoop; |
52 | 56 |
53 class WorkerThreadableWebSocketChannel : public RefCounted<WorkerThreadableWebSo
cketChannel>, public WebSocketChannel { | 57 class WorkerThreadableWebSocketChannel : public RefCounted<WorkerThreadableWebSo
cketChannel>, public WebSocketChannel { |
54 WTF_MAKE_FAST_ALLOCATED; | 58 WTF_MAKE_FAST_ALLOCATED; |
55 public: | 59 public: |
56 static PassRefPtr<WebSocketChannel> create(WorkerContext* workerContext, Web
SocketChannelClient* client, const String& taskMode) | 60 static PassRefPtr<WebSocketChannel> create(WorkerContext* workerContext, Web
SocketChannelClient* client, const String& taskMode) |
57 { | 61 { |
58 return adoptRef(new WorkerThreadableWebSocketChannel(workerContext, clie
nt, taskMode)); | 62 return adoptRef(new WorkerThreadableWebSocketChannel(workerContext, clie
nt, taskMode)); |
59 } | 63 } |
60 virtual ~WorkerThreadableWebSocketChannel(); | 64 virtual ~WorkerThreadableWebSocketChannel(); |
61 | 65 |
62 // WebSocketChannel functions. | 66 // WebSocketChannel functions. |
63 virtual void connect(const KURL&, const String& protocol) OVERRIDE; | 67 virtual void connect(const KURL&, const String& protocol) OVERRIDE; |
64 virtual String subprotocol() OVERRIDE; | 68 virtual String subprotocol() OVERRIDE; |
65 virtual String extensions() OVERRIDE; | 69 virtual String extensions() OVERRIDE; |
66 virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE; | 70 virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE; |
67 virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteO
ffset, unsigned byteLength) OVERRIDE; | 71 virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteO
ffset, unsigned byteLength) OVERRIDE; |
68 virtual WebSocketChannel::SendResult send(const Blob&) OVERRIDE; | 72 virtual WebSocketChannel::SendResult send(const Blob&) OVERRIDE; |
69 virtual unsigned long bufferedAmount() const OVERRIDE; | 73 virtual unsigned long bufferedAmount() const OVERRIDE; |
70 virtual void close(int code, const String& reason) OVERRIDE; | 74 virtual void close(int code, const String& reason) OVERRIDE; |
71 virtual void fail(const String& reason) OVERRIDE; | 75 virtual void fail(const String& reason, MessageLevel) OVERRIDE; |
| 76 virtual void fail(const String& reason, MessageLevel, PassOwnPtr<CallStackWr
apper>) OVERRIDE; |
72 virtual void disconnect() OVERRIDE; // Will suppress didClose(). | 77 virtual void disconnect() OVERRIDE; // Will suppress didClose(). |
73 virtual void suspend() OVERRIDE; | 78 virtual void suspend() OVERRIDE; |
74 virtual void resume() OVERRIDE; | 79 virtual void resume() OVERRIDE; |
75 | 80 |
76 // Generated by the bridge. The Peer and its bridge should have identical | 81 // Generated by the bridge. The Peer and its bridge should have identical |
77 // lifetimes. | 82 // lifetimes. |
78 class Peer : public WebSocketChannelClient { | 83 class Peer : public WebSocketChannelClient { |
79 WTF_MAKE_NONCOPYABLE(Peer); WTF_MAKE_FAST_ALLOCATED; | 84 WTF_MAKE_NONCOPYABLE(Peer); WTF_MAKE_FAST_ALLOCATED; |
80 public: | 85 public: |
81 static Peer* create(PassRefPtr<ThreadableWebSocketChannelClientWrapper>
clientWrapper, WorkerLoaderProxy& loaderProxy, ScriptExecutionContext* context,
const String& taskMode) | 86 // The ScriptCallFrame parameter provides the source filename and |
| 87 // the line number information at the connection initiation, which may |
| 88 // be shown when the connection fails. |
| 89 static Peer* create(PassRefPtr<ThreadableWebSocketChannelClientWrapper>
clientWrapper, WorkerLoaderProxy& loaderProxy, ScriptExecutionContext* context,
const String& taskMode, const ScriptCallFrame& frame) |
82 { | 90 { |
83 return new Peer(clientWrapper, loaderProxy, context, taskMode); | 91 return new Peer(clientWrapper, loaderProxy, context, taskMode, frame
); |
84 } | 92 } |
85 ~Peer(); | 93 ~Peer(); |
86 | 94 |
87 void connect(const KURL&, const String& protocol); | 95 void connect(const KURL&, const String& protocol); |
88 void send(const String& message); | 96 void send(const String& message); |
89 void send(const ArrayBuffer&); | 97 void send(const ArrayBuffer&); |
90 void send(const Blob&); | 98 void send(const Blob&); |
91 void bufferedAmount(); | 99 void bufferedAmount(); |
92 void close(int code, const String& reason); | 100 void close(int code, const String& reason); |
93 void fail(const String& reason); | 101 void fail(const String& reason, MessageLevel, PassOwnPtr<CallStackWrappe
r>); |
94 void disconnect(); | 102 void disconnect(); |
95 void suspend(); | 103 void suspend(); |
96 void resume(); | 104 void resume(); |
97 | 105 |
98 // WebSocketChannelClient functions. | 106 // WebSocketChannelClient functions. |
99 virtual void didConnect() OVERRIDE; | 107 virtual void didConnect() OVERRIDE; |
100 virtual void didReceiveMessage(const String& message) OVERRIDE; | 108 virtual void didReceiveMessage(const String& message) OVERRIDE; |
101 virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> >) OVERRIDE; | 109 virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> >) OVERRIDE; |
102 virtual void didUpdateBufferedAmount(unsigned long bufferedAmount) OVERR
IDE; | 110 virtual void didUpdateBufferedAmount(unsigned long bufferedAmount) OVERR
IDE; |
103 virtual void didStartClosingHandshake() OVERRIDE; | 111 virtual void didStartClosingHandshake() OVERRIDE; |
104 virtual void didClose(unsigned long unhandledBufferedAmount, ClosingHand
shakeCompletionStatus, unsigned short code, const String& reason) OVERRIDE; | 112 virtual void didClose(unsigned long unhandledBufferedAmount, ClosingHand
shakeCompletionStatus, unsigned short code, const String& reason) OVERRIDE; |
105 virtual void didReceiveMessageError() OVERRIDE; | 113 virtual void didReceiveMessageError() OVERRIDE; |
106 | 114 |
107 private: | 115 private: |
108 Peer(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, WorkerLoaderPr
oxy&, ScriptExecutionContext*, const String& taskMode); | 116 Peer(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, WorkerLoaderPr
oxy&, ScriptExecutionContext*, const String& taskMode, const ScriptCallFrame&); |
109 | 117 |
110 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; | 118 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; |
111 WorkerLoaderProxy& m_loaderProxy; | 119 WorkerLoaderProxy& m_loaderProxy; |
112 RefPtr<WebSocketChannel> m_mainWebSocketChannel; | 120 RefPtr<WebSocketChannel> m_mainWebSocketChannel; |
113 String m_taskMode; | 121 String m_taskMode; |
114 }; | 122 }; |
115 | 123 |
116 using RefCounted<WorkerThreadableWebSocketChannel>::ref; | 124 using RefCounted<WorkerThreadableWebSocketChannel>::ref; |
117 using RefCounted<WorkerThreadableWebSocketChannel>::deref; | 125 using RefCounted<WorkerThreadableWebSocketChannel>::deref; |
118 | 126 |
119 protected: | 127 protected: |
120 // WebSocketChannel functions. | 128 // WebSocketChannel functions. |
121 virtual void refWebSocketChannel() OVERRIDE { ref(); } | 129 virtual void refWebSocketChannel() OVERRIDE { ref(); } |
122 virtual void derefWebSocketChannel() OVERRIDE { deref(); } | 130 virtual void derefWebSocketChannel() OVERRIDE { deref(); } |
123 | 131 |
124 private: | 132 private: |
125 // Bridge for Peer. Running on the worker thread. | 133 // Bridge for Peer. Running on the worker thread. |
126 class Bridge : public RefCounted<Bridge> { | 134 class Bridge : public RefCounted<Bridge> { |
127 public: | 135 public: |
128 static PassRefPtr<Bridge> create(PassRefPtr<ThreadableWebSocketChannelCl
ientWrapper> workerClientWrapper, PassRefPtr<WorkerContext> workerContext, const
String& taskMode) | 136 static PassRefPtr<Bridge> create(PassRefPtr<ThreadableWebSocketChannelCl
ientWrapper> workerClientWrapper, PassRefPtr<WorkerContext> workerContext, const
String& taskMode) |
129 { | 137 { |
130 return adoptRef(new Bridge(workerClientWrapper, workerContext, taskM
ode)); | 138 return adoptRef(new Bridge(workerClientWrapper, workerContext, taskM
ode)); |
131 } | 139 } |
132 ~Bridge(); | 140 ~Bridge(); |
133 void initialize(); | 141 // The ScriptCallFrame parameter provides the source filename and |
| 142 // the line number information at the connection initiation, which may |
| 143 // be shown when the connection fails. |
| 144 void initialize(const ScriptCallFrame&); |
134 void connect(const KURL&, const String& protocol); | 145 void connect(const KURL&, const String& protocol); |
135 WebSocketChannel::SendResult send(const String& message); | 146 WebSocketChannel::SendResult send(const String& message); |
136 WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffse
t, unsigned byteLength); | 147 WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffse
t, unsigned byteLength); |
137 WebSocketChannel::SendResult send(const Blob&); | 148 WebSocketChannel::SendResult send(const Blob&); |
138 unsigned long bufferedAmount(); | 149 unsigned long bufferedAmount(); |
139 void close(int code, const String& reason); | 150 void close(int code, const String& reason); |
140 void fail(const String& reason); | 151 void fail(const String& reason, MessageLevel, PassOwnPtr<CallStackWrappe
r>); |
141 void disconnect(); | 152 void disconnect(); |
142 void suspend(); | 153 void suspend(); |
143 void resume(); | 154 void resume(); |
144 | 155 |
145 using RefCounted<Bridge>::ref; | 156 using RefCounted<Bridge>::ref; |
146 using RefCounted<Bridge>::deref; | 157 using RefCounted<Bridge>::deref; |
147 | 158 |
148 private: | 159 private: |
149 Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, PassRefPtr<W
orkerContext>, const String& taskMode); | 160 Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, PassRefPtr<W
orkerContext>, const String& taskMode); |
150 | 161 |
151 static void setWebSocketChannel(ScriptExecutionContext*, Bridge* thisPtr
, Peer*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>); | 162 static void setWebSocketChannel(ScriptExecutionContext*, Bridge* thisPtr
, Peer*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>); |
152 | 163 |
153 // Executed on the main thread to create a Peer for this bridge. | 164 // Executed on the main thread to create a Peer for this bridge. |
154 static void mainThreadInitialize(ScriptExecutionContext*, WorkerLoaderPr
oxy*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>, const String& taskMod
e); | 165 // sourceURL and lineNumber provides the source filename and |
| 166 // the line number information at the connection initiation |
| 167 // respectively. They may be shown when the connection fails. |
| 168 static void mainThreadInitialize(ScriptExecutionContext*, WorkerLoaderPr
oxy*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>, const String& taskMod
e, const String& sourceURL, unsigned lineNumber); |
155 | 169 |
156 // Executed on the worker context's thread. | 170 // Executed on the worker context's thread. |
157 void clearClientWrapper(); | 171 void clearClientWrapper(); |
158 | 172 |
159 void setMethodNotCompleted(); | 173 void setMethodNotCompleted(); |
160 void waitForMethodCompletion(); | 174 void waitForMethodCompletion(); |
161 | 175 |
162 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; | 176 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; |
163 RefPtr<WorkerContext> m_workerContext; | 177 RefPtr<WorkerContext> m_workerContext; |
164 WorkerLoaderProxy& m_loaderProxy; | 178 WorkerLoaderProxy& m_loaderProxy; |
165 String m_taskMode; | 179 String m_taskMode; |
166 Peer* m_peer; | 180 Peer* m_peer; |
167 }; | 181 }; |
168 | 182 |
169 WorkerThreadableWebSocketChannel(WorkerContext*, WebSocketChannelClient*, co
nst String& taskMode); | 183 WorkerThreadableWebSocketChannel(WorkerContext*, WebSocketChannelClient*, co
nst String& taskMode); |
170 | 184 |
171 static void mainThreadConnect(ScriptExecutionContext*, Peer*, const KURL&, c
onst String& protocol); | 185 static void mainThreadConnect(ScriptExecutionContext*, Peer*, const KURL&, c
onst String& protocol); |
172 static void mainThreadSend(ScriptExecutionContext*, Peer*, const String& mes
sage); | 186 static void mainThreadSend(ScriptExecutionContext*, Peer*, const String& mes
sage); |
173 static void mainThreadSendArrayBuffer(ScriptExecutionContext*, Peer*, PassOw
nPtr<Vector<char> >); | 187 static void mainThreadSendArrayBuffer(ScriptExecutionContext*, Peer*, PassOw
nPtr<Vector<char> >); |
174 static void mainThreadSendBlob(ScriptExecutionContext*, Peer*, const KURL&,
const String& type, long long size); | 188 static void mainThreadSendBlob(ScriptExecutionContext*, Peer*, const KURL&,
const String& type, long long size); |
175 static void mainThreadBufferedAmount(ScriptExecutionContext*, Peer*); | 189 static void mainThreadBufferedAmount(ScriptExecutionContext*, Peer*); |
176 static void mainThreadClose(ScriptExecutionContext*, Peer*, int code, const
String& reason); | 190 static void mainThreadClose(ScriptExecutionContext*, Peer*, int code, const
String& reason); |
177 static void mainThreadFail(ScriptExecutionContext*, Peer*, const String& rea
son); | 191 static void mainThreadFail(ScriptExecutionContext*, Peer*, const String& rea
son, MessageLevel, PassOwnPtr<CallStackWrapper>); |
178 static void mainThreadDestroy(ScriptExecutionContext*, PassOwnPtr<Peer>); | 192 static void mainThreadDestroy(ScriptExecutionContext*, PassOwnPtr<Peer>); |
179 static void mainThreadSuspend(ScriptExecutionContext*, Peer*); | 193 static void mainThreadSuspend(ScriptExecutionContext*, Peer*); |
180 static void mainThreadResume(ScriptExecutionContext*, Peer*); | 194 static void mainThreadResume(ScriptExecutionContext*, Peer*); |
181 | 195 |
182 class WorkerContextDidInitializeTask; | 196 class WorkerContextDidInitializeTask; |
183 | 197 |
184 RefPtr<WorkerContext> m_workerContext; | 198 RefPtr<WorkerContext> m_workerContext; |
185 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; | 199 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; |
186 RefPtr<Bridge> m_bridge; | 200 RefPtr<Bridge> m_bridge; |
| 201 ScriptCallFrame m_callFrameAtConnection; |
187 }; | 202 }; |
188 | 203 |
189 } // namespace WebCore | 204 } // namespace WebCore |
190 | 205 |
191 #endif // WorkerThreadableWebSocketChannel_h | 206 #endif // WorkerThreadableWebSocketChannel_h |
OLD | NEW |