| 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/dom/ExecutionContextTask.h" |
| 34 #include "core/frame/ConsoleTypes.h" | 35 #include "core/frame/ConsoleTypes.h" |
| 35 #include "core/workers/WorkerGlobalScope.h" | 36 #include "core/workers/WorkerGlobalScope.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 #include "platform/heap/Handle.h" | 39 #include "platform/heap/Handle.h" |
| 39 | 40 |
| 40 #include "wtf/PassOwnPtr.h" | 41 #include "wtf/PassOwnPtr.h" |
| 41 #include "wtf/PassRefPtr.h" | 42 #include "wtf/PassRefPtr.h" |
| 42 #include "wtf/RefCounted.h" | 43 #include "wtf/RefCounted.h" |
| 43 #include "wtf/RefPtr.h" | 44 #include "wtf/RefPtr.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE; | 78 virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE; |
| 78 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; |
| 79 virtual WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>) OVERRI
DE; | 80 virtual WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>) OVERRI
DE; |
| 80 virtual unsigned long bufferedAmount() const OVERRIDE; | 81 virtual unsigned long bufferedAmount() const OVERRIDE; |
| 81 virtual void close(int code, const String& reason) OVERRIDE; | 82 virtual void close(int code, const String& reason) OVERRIDE; |
| 82 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; |
| 83 virtual void disconnect() OVERRIDE; // Will suppress didClose(). | 84 virtual void disconnect() OVERRIDE; // Will suppress didClose(). |
| 84 virtual void suspend() OVERRIDE; | 85 virtual void suspend() OVERRIDE; |
| 85 virtual void resume() OVERRIDE; | 86 virtual void resume() OVERRIDE; |
| 86 | 87 |
| 87 virtual void trace(Visitor*) OVERRIDE; | |
| 88 | |
| 89 // Generated by the bridge. The Peer is destructed by an async call from | 88 // Generated by the bridge. The Peer is destructed by an async call from |
| 90 // Bridge, and may outlive the bridge. All methods of this class must | 89 // Bridge, and may outlive the bridge. All methods of this class must |
| 91 // be called on the main thread. | 90 // be called on the main thread. |
| 92 class Peer FINAL : public WebSocketChannelClient { | 91 class Peer FINAL : public WebSocketChannelClient { |
| 93 WTF_MAKE_NONCOPYABLE(Peer); WTF_MAKE_FAST_ALLOCATED; | 92 WTF_MAKE_NONCOPYABLE(Peer); WTF_MAKE_FAST_ALLOCATED; |
| 94 public: | 93 public: |
| 95 virtual ~Peer(); | 94 virtual ~Peer(); |
| 96 | 95 |
| 97 // sourceURLAtConnection and lineNumberAtConnection parameters may | 96 // sourceURLAtConnection and lineNumberAtConnection parameters may |
| 98 // be shown when the connection fails. | 97 // be shown when the connection fails. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 126 WorkerLoaderProxy& m_loaderProxy; | 125 WorkerLoaderProxy& m_loaderProxy; |
| 127 RefPtrWillBePersistent<WebSocketChannel> m_mainWebSocketChannel; | 126 RefPtrWillBePersistent<WebSocketChannel> m_mainWebSocketChannel; |
| 128 OwnPtr<ThreadableWebSocketChannelSyncHelper> m_syncHelper; | 127 OwnPtr<ThreadableWebSocketChannelSyncHelper> m_syncHelper; |
| 129 WeakPtrFactory<Peer> m_weakFactory; | 128 WeakPtrFactory<Peer> m_weakFactory; |
| 130 }; | 129 }; |
| 131 | 130 |
| 132 private: | 131 private: |
| 133 // Bridge for Peer. Running on the worker thread. | 132 // Bridge for Peer. Running on the worker thread. |
| 134 class Bridge : public RefCounted<Bridge> { | 133 class Bridge : public RefCounted<Bridge> { |
| 135 public: | 134 public: |
| 136 static PassRefPtr<Bridge> create(PassRefPtr<ThreadableWebSocketChannelCl
ientWrapper> workerClientWrapper, PassRefPtrWillBeRawPtr<WorkerGlobalScope> work
erGlobalScope) | 135 static PassRefPtr<Bridge> create(PassRefPtr<ThreadableWebSocketChannelCl
ientWrapper> workerClientWrapper, WorkerGlobalScope& workerGlobalScope) |
| 137 { | 136 { |
| 138 return adoptRef(new Bridge(workerClientWrapper, workerGlobalScope)); | 137 return adoptRef(new Bridge(workerClientWrapper, workerGlobalScope)); |
| 139 } | 138 } |
| 140 ~Bridge(); | 139 ~Bridge(); |
| 141 // sourceURLAtConnection and lineNumberAtConnection parameters may | 140 // sourceURLAtConnection and lineNumberAtConnection parameters may |
| 142 // be shown when the connection fails. | 141 // be shown when the connection fails. |
| 143 void initialize(const String& sourceURLAtConnection, unsigned lineNumber
AtConnection); | 142 void initialize(const String& sourceURLAtConnection, unsigned lineNumber
AtConnection); |
| 144 bool connect(const KURL&, const String& protocol); | 143 bool connect(const KURL&, const String& protocol); |
| 145 WebSocketChannel::SendResult send(const String& message); | 144 WebSocketChannel::SendResult send(const String& message); |
| 146 WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffse
t, unsigned byteLength); | 145 WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffse
t, unsigned byteLength); |
| 147 WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>); | 146 WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>); |
| 148 unsigned long bufferedAmount(); | 147 unsigned long bufferedAmount(); |
| 149 void close(int code, const String& reason); | 148 void close(int code, const String& reason); |
| 150 void fail(const String& reason, MessageLevel, const String& sourceURL, u
nsigned lineNumber); | 149 void fail(const String& reason, MessageLevel, const String& sourceURL, u
nsigned lineNumber); |
| 151 void disconnect(); | 150 void disconnect(); |
| 152 void suspend(); | 151 void suspend(); |
| 153 void resume(); | 152 void resume(); |
| 154 | 153 |
| 155 private: | 154 private: |
| 156 Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, PassRefPtrWi
llBeRawPtr<WorkerGlobalScope>); | 155 Bridge(PassRefPtr<ThreadableWebSocketChannelClientWrapper>, WorkerGlobal
Scope&); |
| 157 | 156 |
| 158 static void setWebSocketChannel(ExecutionContext*, Bridge* thisPtr, Peer
*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>); | 157 static void setWebSocketChannel(ExecutionContext*, Bridge* thisPtr, Peer
*, PassRefPtr<ThreadableWebSocketChannelClientWrapper>); |
| 159 | 158 |
| 160 // Executed on the worker context's thread. | 159 // Executed on the worker context's thread. |
| 161 void clearClientWrapper(); | 160 void clearClientWrapper(); |
| 162 | 161 |
| 163 // Returns false if shutdown event is received before method completion. | 162 // Returns false if shutdown event is received before method completion. |
| 164 bool waitForMethodCompletion(); | 163 bool waitForMethodCompletion(PassOwnPtr<ExecutionContextTask>); |
| 165 | 164 |
| 166 void terminatePeer(); | 165 void terminatePeer(); |
| 167 | 166 |
| 167 bool hasTerminatedPeer() { return !m_syncHelper; } |
| 168 |
| 168 const RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrap
per; | 169 const RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrap
per; |
| 169 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; | 170 RefPtrWillBePersistent<WorkerGlobalScope> m_workerGlobalScope; |
| 170 WorkerLoaderProxy& m_loaderProxy; | 171 WorkerLoaderProxy& m_loaderProxy; |
| 171 ThreadableWebSocketChannelSyncHelper* m_syncHelper; | 172 ThreadableWebSocketChannelSyncHelper* m_syncHelper; |
| 172 WeakPtr<Peer> m_peer; | 173 WeakPtr<Peer> m_peer; |
| 173 }; | 174 }; |
| 174 | 175 |
| 175 WorkerThreadableWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient*
, const String& sourceURL, unsigned lineNumber); | 176 WorkerThreadableWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient*
, const String& sourceURL, unsigned lineNumber); |
| 176 | 177 |
| 177 RefPtrWillBeMember<WorkerGlobalScope> m_workerGlobalScope; | |
| 178 const RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; | 178 const RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; |
| 179 RefPtr<Bridge> m_bridge; | 179 RefPtr<Bridge> m_bridge; |
| 180 String m_sourceURLAtConnection; | 180 String m_sourceURLAtConnection; |
| 181 unsigned m_lineNumberAtConnection; | 181 unsigned m_lineNumberAtConnection; |
| 182 }; | 182 }; |
| 183 | 183 |
| 184 } // namespace WebCore | 184 } // namespace WebCore |
| 185 | 185 |
| 186 #endif // WorkerThreadableWebSocketChannel_h | 186 #endif // WorkerThreadableWebSocketChannel_h |
| OLD | NEW |