Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Side by Side Diff: Source/modules/websockets/WorkerThreadableWebSocketChannel.h

Issue 14657008: Make websocket error messages look better at the devtools console. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: cleanup Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 static Peer* create(PassRefPtr<ThreadableWebSocketChannelClientWrapper> clientWrapper, WorkerLoaderProxy& loaderProxy, ScriptExecutionContext* context, const String& taskMode, const ScriptCallFrame& frame)
82 { 87 {
83 return new Peer(clientWrapper, loaderProxy, context, taskMode); 88 return new Peer(clientWrapper, loaderProxy, context, taskMode, frame );
84 } 89 }
85 ~Peer(); 90 ~Peer();
86 91
87 void connect(const KURL&, const String& protocol); 92 void connect(const KURL&, const String& protocol);
88 void send(const String& message); 93 void send(const String& message);
89 void send(const ArrayBuffer&); 94 void send(const ArrayBuffer&);
90 void send(const Blob&); 95 void send(const Blob&);
91 void bufferedAmount(); 96 void bufferedAmount();
92 void close(int code, const String& reason); 97 void close(int code, const String& reason);
93 void fail(const String& reason); 98 void fail(const String& reason, MessageLevel, PassOwnPtr<CallStackWrappe r>);
94 void disconnect(); 99 void disconnect();
95 void suspend(); 100 void suspend();
96 void resume(); 101 void resume();
97 102
98 // WebSocketChannelClient functions. 103 // WebSocketChannelClient functions.
99 virtual void didConnect() OVERRIDE; 104 virtual void didConnect() OVERRIDE;
100 virtual void didReceiveMessage(const String& message) OVERRIDE; 105 virtual void didReceiveMessage(const String& message) OVERRIDE;
101 virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> >) OVERRIDE; 106 virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> >) OVERRIDE;
102 virtual void didUpdateBufferedAmount(unsigned long bufferedAmount) OVERR IDE; 107 virtual void didUpdateBufferedAmount(unsigned long bufferedAmount) OVERR IDE;
103 virtual void didStartClosingHandshake() OVERRIDE; 108 virtual void didStartClosingHandshake() OVERRIDE;
104 virtual void didClose(unsigned long unhandledBufferedAmount, ClosingHand shakeCompletionStatus, unsigned short code, const String& reason) OVERRIDE; 109 virtual void didClose(unsigned long unhandledBufferedAmount, ClosingHand shakeCompletionStatus, unsigned short code, const String& reason) OVERRIDE;
105 virtual void didReceiveMessageError() OVERRIDE; 110 virtual void didReceiveMessageError() OVERRIDE;
106 111
107 private: 112 private:
108 Peer(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, WorkerLoaderPr oxy&, ScriptExecutionContext*, const String& taskMode); 113 Peer(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, WorkerLoaderPr oxy&, ScriptExecutionContext*, const String& taskMode, const ScriptCallFrame&);
109 114
110 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; 115 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper;
111 WorkerLoaderProxy& m_loaderProxy; 116 WorkerLoaderProxy& m_loaderProxy;
112 RefPtr<WebSocketChannel> m_mainWebSocketChannel; 117 RefPtr<WebSocketChannel> m_mainWebSocketChannel;
113 String m_taskMode; 118 String m_taskMode;
114 }; 119 };
115 120
116 using RefCounted<WorkerThreadableWebSocketChannel>::ref; 121 using RefCounted<WorkerThreadableWebSocketChannel>::ref;
117 using RefCounted<WorkerThreadableWebSocketChannel>::deref; 122 using RefCounted<WorkerThreadableWebSocketChannel>::deref;
118 123
119 protected: 124 protected:
120 // WebSocketChannel functions. 125 // WebSocketChannel functions.
121 virtual void refWebSocketChannel() OVERRIDE { ref(); } 126 virtual void refWebSocketChannel() OVERRIDE { ref(); }
122 virtual void derefWebSocketChannel() OVERRIDE { deref(); } 127 virtual void derefWebSocketChannel() OVERRIDE { deref(); }
123 128
124 private: 129 private:
125 // Bridge for Peer. Running on the worker thread. 130 // Bridge for Peer. Running on the worker thread.
126 class Bridge : public RefCounted<Bridge> { 131 class Bridge : public RefCounted<Bridge> {
127 public: 132 public:
128 static PassRefPtr<Bridge> create(PassRefPtr<ThreadableWebSocketChannelCl ientWrapper> workerClientWrapper, PassRefPtr<WorkerContext> workerContext, const String& taskMode) 133 static PassRefPtr<Bridge> create(PassRefPtr<ThreadableWebSocketChannelCl ientWrapper> workerClientWrapper, PassRefPtr<WorkerContext> workerContext, const String& taskMode)
129 { 134 {
130 return adoptRef(new Bridge(workerClientWrapper, workerContext, taskM ode)); 135 return adoptRef(new Bridge(workerClientWrapper, workerContext, taskM ode));
131 } 136 }
132 ~Bridge(); 137 ~Bridge();
tyoshino (SeeGerritForStatus) 2013/05/01 08:03:23 Explain what the ScriptCallFrame argument is expec
yhirano 2013/05/01 09:31:44 Done.
133 void initialize(); 138 void initialize(const ScriptCallFrame&);
134 void connect(const KURL&, const String& protocol); 139 void connect(const KURL&, const String& protocol);
135 WebSocketChannel::SendResult send(const String& message); 140 WebSocketChannel::SendResult send(const String& message);
136 WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffse t, unsigned byteLength); 141 WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffse t, unsigned byteLength);
137 WebSocketChannel::SendResult send(const Blob&); 142 WebSocketChannel::SendResult send(const Blob&);
138 unsigned long bufferedAmount(); 143 unsigned long bufferedAmount();
139 void close(int code, const String& reason); 144 void close(int code, const String& reason);
140 void fail(const String& reason); 145 void fail(const String& reason, MessageLevel, PassOwnPtr<CallStackWrappe r>);
141 void disconnect(); 146 void disconnect();
142 void suspend(); 147 void suspend();
143 void resume(); 148 void resume();
144 149
145 using RefCounted<Bridge>::ref; 150 using RefCounted<Bridge>::ref;
146 using RefCounted<Bridge>::deref; 151 using RefCounted<Bridge>::deref;
147 152
148 private: 153 private:
149 Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, PassRefPtr<W orkerContext>, const String& taskMode); 154 Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, PassRefPtr<W orkerContext>, const String& taskMode);
150 155
151 static void setWebSocketChannel(ScriptExecutionContext*, Bridge* thisPtr , Peer*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>); 156 static void setWebSocketChannel(ScriptExecutionContext*, Bridge* thisPtr , Peer*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>);
152 157
153 // Executed on the main thread to create a Peer for this bridge. 158 // Executed on the main thread to create a Peer for this bridge.
tyoshino (SeeGerritForStatus) 2013/05/01 08:03:23 Explain how sourceURL and lineNumber will be used
yhirano 2013/05/01 09:31:44 Done.
154 static void mainThreadInitialize(ScriptExecutionContext*, WorkerLoaderPr oxy*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>, const String& taskMod e); 159 static void mainThreadInitialize(ScriptExecutionContext*, WorkerLoaderPr oxy*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>, const String& taskMod e, const String& sourceURL, unsigned lineNumber);
155 160
156 // Executed on the worker context's thread. 161 // Executed on the worker context's thread.
157 void clearClientWrapper(); 162 void clearClientWrapper();
158 163
159 void setMethodNotCompleted(); 164 void setMethodNotCompleted();
160 void waitForMethodCompletion(); 165 void waitForMethodCompletion();
161 166
162 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; 167 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper;
163 RefPtr<WorkerContext> m_workerContext; 168 RefPtr<WorkerContext> m_workerContext;
164 WorkerLoaderProxy& m_loaderProxy; 169 WorkerLoaderProxy& m_loaderProxy;
165 String m_taskMode; 170 String m_taskMode;
166 Peer* m_peer; 171 Peer* m_peer;
167 }; 172 };
168 173
169 WorkerThreadableWebSocketChannel(WorkerContext*, WebSocketChannelClient*, co nst String& taskMode); 174 WorkerThreadableWebSocketChannel(WorkerContext*, WebSocketChannelClient*, co nst String& taskMode);
170 175
171 static void mainThreadConnect(ScriptExecutionContext*, Peer*, const KURL&, c onst String& protocol); 176 static void mainThreadConnect(ScriptExecutionContext*, Peer*, const KURL&, c onst String& protocol);
172 static void mainThreadSend(ScriptExecutionContext*, Peer*, const String& mes sage); 177 static void mainThreadSend(ScriptExecutionContext*, Peer*, const String& mes sage);
173 static void mainThreadSendArrayBuffer(ScriptExecutionContext*, Peer*, PassOw nPtr<Vector<char> >); 178 static void mainThreadSendArrayBuffer(ScriptExecutionContext*, Peer*, PassOw nPtr<Vector<char> >);
174 static void mainThreadSendBlob(ScriptExecutionContext*, Peer*, const KURL&, const String& type, long long size); 179 static void mainThreadSendBlob(ScriptExecutionContext*, Peer*, const KURL&, const String& type, long long size);
175 static void mainThreadBufferedAmount(ScriptExecutionContext*, Peer*); 180 static void mainThreadBufferedAmount(ScriptExecutionContext*, Peer*);
176 static void mainThreadClose(ScriptExecutionContext*, Peer*, int code, const String& reason); 181 static void mainThreadClose(ScriptExecutionContext*, Peer*, int code, const String& reason);
177 static void mainThreadFail(ScriptExecutionContext*, Peer*, const String& rea son); 182 static void mainThreadFail(ScriptExecutionContext*, Peer*, const String& rea son, MessageLevel, PassOwnPtr<CallStackWrapper>);
178 static void mainThreadDestroy(ScriptExecutionContext*, PassOwnPtr<Peer>); 183 static void mainThreadDestroy(ScriptExecutionContext*, PassOwnPtr<Peer>);
179 static void mainThreadSuspend(ScriptExecutionContext*, Peer*); 184 static void mainThreadSuspend(ScriptExecutionContext*, Peer*);
180 static void mainThreadResume(ScriptExecutionContext*, Peer*); 185 static void mainThreadResume(ScriptExecutionContext*, Peer*);
181 186
182 class WorkerContextDidInitializeTask; 187 class WorkerContextDidInitializeTask;
183 188
184 RefPtr<WorkerContext> m_workerContext; 189 RefPtr<WorkerContext> m_workerContext;
185 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; 190 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper;
186 RefPtr<Bridge> m_bridge; 191 RefPtr<Bridge> m_bridge;
192 ScriptCallFrame m_callFrameAtConnection;
187 }; 193 };
188 194
189 } // namespace WebCore 195 } // namespace WebCore
190 196
191 #endif // WorkerThreadableWebSocketChannel_h 197 #endif // WorkerThreadableWebSocketChannel_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698