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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE; | 78 virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE; |
79 virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteO
ffset, unsigned byteLength) OVERRIDE; | 79 virtual WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteO
ffset, unsigned byteLength) OVERRIDE; |
80 virtual WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>) OVERRI
DE; | 80 virtual WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>) OVERRI
DE; |
81 virtual unsigned long bufferedAmount() const OVERRIDE; | 81 virtual unsigned long bufferedAmount() const OVERRIDE; |
82 virtual void close(int code, const String& reason) OVERRIDE; | 82 virtual void close(int code, const String& reason) OVERRIDE; |
83 virtual void fail(const String& reason, MessageLevel, const String&, unsigne
d) OVERRIDE; | 83 virtual void fail(const String& reason, MessageLevel, const String&, unsigne
d) OVERRIDE; |
84 virtual void disconnect() OVERRIDE; // Will suppress didClose(). | 84 virtual void disconnect() OVERRIDE; // Will suppress didClose(). |
85 virtual void suspend() OVERRIDE; | 85 virtual void suspend() OVERRIDE; |
86 virtual void resume() OVERRIDE; | 86 virtual void resume() OVERRIDE; |
87 | 87 |
| 88 virtual void trace(Visitor*) OVERRIDE; |
| 89 |
88 // Generated by the bridge. The Peer is destructed by an async call from | 90 // Generated by the bridge. The Peer is destructed by an async call from |
89 // Bridge, and may outlive the bridge. All methods of this class must | 91 // Bridge, and may outlive the bridge. All methods of this class must |
90 // be called on the main thread. | 92 // be called on the main thread. |
91 class Peer FINAL : public WebSocketChannelClient { | 93 class Peer FINAL : public WebSocketChannelClient { |
92 WTF_MAKE_NONCOPYABLE(Peer); WTF_MAKE_FAST_ALLOCATED; | 94 WTF_MAKE_NONCOPYABLE(Peer); WTF_MAKE_FAST_ALLOCATED; |
93 public: | 95 public: |
94 virtual ~Peer(); | 96 virtual ~Peer(); |
95 | 97 |
96 // sourceURLAtConnection and lineNumberAtConnection parameters may | 98 // sourceURLAtConnection and lineNumberAtConnection parameters may |
97 // be shown when the connection fails. | 99 // be shown when the connection fails. |
98 static void initialize(ExecutionContext*, PassRefPtr<WeakReference<Peer>
>, WorkerLoaderProxy*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>, con
st String& sourceURLAtConnection, unsigned lineNumberAtConnection, PassOwnPtr<Th
readableWebSocketChannelSyncHelper>); | 100 static void initialize(ExecutionContext*, PassRefPtr<WeakReference<Peer>
>, WorkerLoaderProxy*, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientW
rapper>, const String& sourceURLAtConnection, unsigned lineNumberAtConnection, P
assOwnPtr<ThreadableWebSocketChannelSyncHelper>); |
99 void destroy(); | 101 void destroy(); |
100 | 102 |
101 void connect(const KURL&, const String& protocol); | 103 void connect(const KURL&, const String& protocol); |
102 void send(const String& message); | 104 void send(const String& message); |
103 void sendArrayBuffer(PassOwnPtr<Vector<char> >); | 105 void sendArrayBuffer(PassOwnPtr<Vector<char> >); |
104 void sendBlob(PassRefPtr<BlobDataHandle>); | 106 void sendBlob(PassRefPtr<BlobDataHandle>); |
105 void bufferedAmount(); | 107 void bufferedAmount(); |
106 void close(int code, const String& reason); | 108 void close(int code, const String& reason); |
107 void fail(const String& reason, MessageLevel, const String& sourceURL, u
nsigned lineNumber); | 109 void fail(const String& reason, MessageLevel, const String& sourceURL, u
nsigned lineNumber); |
108 void disconnect(); | 110 void disconnect(); |
109 void suspend(); | 111 void suspend(); |
110 void resume(); | 112 void resume(); |
111 | 113 |
112 // WebSocketChannelClient functions. | 114 // WebSocketChannelClient functions. |
113 virtual void didConnect() OVERRIDE; | 115 virtual void didConnect() OVERRIDE; |
114 virtual void didReceiveMessage(const String& message) OVERRIDE; | 116 virtual void didReceiveMessage(const String& message) OVERRIDE; |
115 virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> >) OVERRIDE; | 117 virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> >) OVERRIDE; |
116 virtual void didUpdateBufferedAmount(unsigned long bufferedAmount) OVERR
IDE; | 118 virtual void didUpdateBufferedAmount(unsigned long bufferedAmount) OVERR
IDE; |
117 virtual void didStartClosingHandshake() OVERRIDE; | 119 virtual void didStartClosingHandshake() OVERRIDE; |
118 virtual void didClose(unsigned long unhandledBufferedAmount, ClosingHand
shakeCompletionStatus, unsigned short code, const String& reason) OVERRIDE; | 120 virtual void didClose(unsigned long unhandledBufferedAmount, ClosingHand
shakeCompletionStatus, unsigned short code, const String& reason) OVERRIDE; |
119 virtual void didReceiveMessageError() OVERRIDE; | 121 virtual void didReceiveMessageError() OVERRIDE; |
120 | 122 |
121 private: | 123 private: |
122 Peer(PassRefPtr<WeakReference<Peer> >, PassRefPtr<ThreadableWebSocketCha
nnelClientWrapper>, WorkerLoaderProxy&, ExecutionContext*, const String& sourceU
RL, unsigned lineNumber, PassOwnPtr<ThreadableWebSocketChannelSyncHelper>); | 124 Peer(PassRefPtr<WeakReference<Peer> >, PassRefPtrWillBeRawPtr<Threadable
WebSocketChannelClientWrapper>, WorkerLoaderProxy&, ExecutionContext*, const Str
ing& sourceURL, unsigned lineNumber, PassOwnPtr<ThreadableWebSocketChannelSyncHe
lper>); |
123 | 125 |
124 const RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrap
per; | 126 const RefPtrWillBePersistent<ThreadableWebSocketChannelClientWrapper> m_
workerClientWrapper; |
125 WorkerLoaderProxy& m_loaderProxy; | 127 WorkerLoaderProxy& m_loaderProxy; |
126 RefPtrWillBePersistent<WebSocketChannel> m_mainWebSocketChannel; | 128 RefPtrWillBePersistent<WebSocketChannel> m_mainWebSocketChannel; |
127 OwnPtr<ThreadableWebSocketChannelSyncHelper> m_syncHelper; | 129 OwnPtr<ThreadableWebSocketChannelSyncHelper> m_syncHelper; |
128 WeakPtrFactory<Peer> m_weakFactory; | 130 WeakPtrFactory<Peer> m_weakFactory; |
129 }; | 131 }; |
130 | 132 |
131 private: | 133 private: |
132 // Bridge for Peer. Running on the worker thread. | 134 // Bridge for Peer. Running on the worker thread. |
133 class Bridge : public RefCounted<Bridge> { | 135 class Bridge : public RefCounted<Bridge> { |
134 public: | 136 public: |
135 static PassRefPtr<Bridge> create(PassRefPtr<ThreadableWebSocketChannelCl
ientWrapper> workerClientWrapper, WorkerGlobalScope& workerGlobalScope) | 137 static PassRefPtr<Bridge> create(PassRefPtrWillBeRawPtr<ThreadableWebSoc
ketChannelClientWrapper> workerClientWrapper, WorkerGlobalScope& workerGlobalSco
pe) |
136 { | 138 { |
137 return adoptRef(new Bridge(workerClientWrapper, workerGlobalScope)); | 139 return adoptRef(new Bridge(workerClientWrapper, workerGlobalScope)); |
138 } | 140 } |
139 ~Bridge(); | 141 ~Bridge(); |
140 // sourceURLAtConnection and lineNumberAtConnection parameters may | 142 // sourceURLAtConnection and lineNumberAtConnection parameters may |
141 // be shown when the connection fails. | 143 // be shown when the connection fails. |
142 void initialize(const String& sourceURLAtConnection, unsigned lineNumber
AtConnection); | 144 void initialize(const String& sourceURLAtConnection, unsigned lineNumber
AtConnection); |
143 bool connect(const KURL&, const String& protocol); | 145 bool connect(const KURL&, const String& protocol); |
144 WebSocketChannel::SendResult send(const String& message); | 146 WebSocketChannel::SendResult send(const String& message); |
145 WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffse
t, unsigned byteLength); | 147 WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffse
t, unsigned byteLength); |
146 WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>); | 148 WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>); |
147 unsigned long bufferedAmount(); | 149 unsigned long bufferedAmount(); |
148 void close(int code, const String& reason); | 150 void close(int code, const String& reason); |
149 void fail(const String& reason, MessageLevel, const String& sourceURL, u
nsigned lineNumber); | 151 void fail(const String& reason, MessageLevel, const String& sourceURL, u
nsigned lineNumber); |
150 void disconnect(); | 152 void disconnect(); |
151 void suspend(); | 153 void suspend(); |
152 void resume(); | 154 void resume(); |
153 | 155 |
154 private: | 156 private: |
155 Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, WorkerGlobal
Scope&); | 157 Bridge(PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper>,
WorkerGlobalScope&); |
156 | 158 |
157 static void setWebSocketChannel(ExecutionContext*, Bridge* thisPtr, Peer
*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>); | 159 static void setWebSocketChannel(ExecutionContext*, Bridge* thisPtr, Peer
*, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper>); |
158 | 160 |
159 // Executed on the worker context's thread. | 161 // Executed on the worker context's thread. |
160 void clearClientWrapper(); | 162 void clearClientWrapper(); |
161 | 163 |
162 // Returns false if shutdown event is received before method completion. | 164 // Returns false if shutdown event is received before method completion. |
163 bool waitForMethodCompletion(PassOwnPtr<ExecutionContextTask>); | 165 bool waitForMethodCompletion(PassOwnPtr<ExecutionContextTask>); |
164 | 166 |
165 void terminatePeer(); | 167 void terminatePeer(); |
166 | 168 |
167 bool hasTerminatedPeer() { return !m_syncHelper; } | 169 bool hasTerminatedPeer() { return !m_syncHelper; } |
168 | 170 |
169 const RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrap
per; | 171 const RefPtrWillBePersistent<ThreadableWebSocketChannelClientWrapper> m_
workerClientWrapper; |
170 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; | 172 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; |
171 WorkerLoaderProxy& m_loaderProxy; | 173 WorkerLoaderProxy& m_loaderProxy; |
172 ThreadableWebSocketChannelSyncHelper* m_syncHelper; | 174 ThreadableWebSocketChannelSyncHelper* m_syncHelper; |
173 WeakPtr<Peer> m_peer; | 175 WeakPtr<Peer> m_peer; |
174 }; | 176 }; |
175 | 177 |
176 WorkerThreadableWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient*
, const String& sourceURL, unsigned lineNumber); | 178 WorkerThreadableWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient*
, const String& sourceURL, unsigned lineNumber); |
177 | 179 |
178 const RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; | 180 const RefPtrWillBeMember<ThreadableWebSocketChannelClientWrapper> m_workerCl
ientWrapper; |
179 RefPtr<Bridge> m_bridge; | 181 RefPtr<Bridge> m_bridge; |
180 String m_sourceURLAtConnection; | 182 String m_sourceURLAtConnection; |
181 unsigned m_lineNumberAtConnection; | 183 unsigned m_lineNumberAtConnection; |
182 }; | 184 }; |
183 | 185 |
184 } // namespace WebCore | 186 } // namespace WebCore |
185 | 187 |
186 #endif // WorkerThreadableWebSocketChannel_h | 188 #endif // WorkerThreadableWebSocketChannel_h |
OLD | NEW |