| 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 WorkerWebSocketChannel_h | 31 #ifndef WorkerWebSocketChannel_h |
| 32 #define WorkerWebSocketChannel_h | 32 #define WorkerWebSocketChannel_h |
| 33 | 33 |
| 34 #include "bindings/core/v8/SourceLocation.h" |
| 34 #include "modules/websockets/WebSocketChannel.h" | 35 #include "modules/websockets/WebSocketChannel.h" |
| 35 #include "modules/websockets/WebSocketChannelClient.h" | 36 #include "modules/websockets/WebSocketChannelClient.h" |
| 36 #include "platform/heap/Handle.h" | 37 #include "platform/heap/Handle.h" |
| 37 #include "platform/v8_inspector/public/ConsoleTypes.h" | 38 #include "platform/v8_inspector/public/ConsoleTypes.h" |
| 38 #include "wtf/Assertions.h" | 39 #include "wtf/Assertions.h" |
| 39 #include "wtf/Forward.h" | 40 #include "wtf/Forward.h" |
| 40 #include "wtf/OwnPtr.h" | 41 #include "wtf/OwnPtr.h" |
| 41 #include "wtf/RefPtr.h" | 42 #include "wtf/RefPtr.h" |
| 42 #include "wtf/Vector.h" | 43 #include "wtf/Vector.h" |
| 43 #include "wtf/text/WTFString.h" | 44 #include "wtf/text/WTFString.h" |
| 44 #include <stdint.h> | 45 #include <stdint.h> |
| 45 | 46 |
| 46 namespace blink { | 47 namespace blink { |
| 47 | 48 |
| 48 class BlobDataHandle; | 49 class BlobDataHandle; |
| 49 class KURL; | 50 class KURL; |
| 50 class ExecutionContext; | 51 class ExecutionContext; |
| 51 class ExecutionContextTask; | 52 class ExecutionContextTask; |
| 52 class WebSocketChannelSyncHelper; | 53 class WebSocketChannelSyncHelper; |
| 53 class WorkerGlobalScope; | 54 class WorkerGlobalScope; |
| 54 class WorkerLoaderProxy; | 55 class WorkerLoaderProxy; |
| 55 | 56 |
| 56 class WorkerWebSocketChannel final : public WebSocketChannel { | 57 class WorkerWebSocketChannel final : public WebSocketChannel { |
| 57 WTF_MAKE_NONCOPYABLE(WorkerWebSocketChannel); | 58 WTF_MAKE_NONCOPYABLE(WorkerWebSocketChannel); |
| 58 public: | 59 public: |
| 59 static WebSocketChannel* create(WorkerGlobalScope& workerGlobalScope, WebSoc
ketChannelClient* client, const String& sourceURL, unsigned lineNumber) | 60 static WebSocketChannel* create(WorkerGlobalScope& workerGlobalScope, WebSoc
ketChannelClient* client, PassOwnPtr<SourceLocation> location) |
| 60 { | 61 { |
| 61 return new WorkerWebSocketChannel(workerGlobalScope, client, sourceURL,
lineNumber); | 62 return new WorkerWebSocketChannel(workerGlobalScope, client, std::move(l
ocation)); |
| 62 } | 63 } |
| 63 ~WorkerWebSocketChannel() override; | 64 ~WorkerWebSocketChannel() override; |
| 64 | 65 |
| 65 // WebSocketChannel functions. | 66 // WebSocketChannel functions. |
| 66 bool connect(const KURL&, const String& protocol) override; | 67 bool connect(const KURL&, const String& protocol) override; |
| 67 void send(const CString&) override; | 68 void send(const CString&) override; |
| 68 void send(const DOMArrayBuffer&, unsigned byteOffset, unsigned byteLength) o
verride; | 69 void send(const DOMArrayBuffer&, unsigned byteOffset, unsigned byteLength) o
verride; |
| 69 void send(PassRefPtr<BlobDataHandle>) override; | 70 void send(PassRefPtr<BlobDataHandle>) override; |
| 70 void sendTextAsCharVector(PassOwnPtr<Vector<char>>) override | 71 void sendTextAsCharVector(PassOwnPtr<Vector<char>>) override |
| 71 { | 72 { |
| 72 ASSERT_NOT_REACHED(); | 73 ASSERT_NOT_REACHED(); |
| 73 } | 74 } |
| 74 void sendBinaryAsCharVector(PassOwnPtr<Vector<char>>) override | 75 void sendBinaryAsCharVector(PassOwnPtr<Vector<char>>) override |
| 75 { | 76 { |
| 76 ASSERT_NOT_REACHED(); | 77 ASSERT_NOT_REACHED(); |
| 77 } | 78 } |
| 78 void close(int code, const String& reason) override; | 79 void close(int code, const String& reason) override; |
| 79 void fail(const String& reason, MessageLevel, const String&, unsigned) overr
ide; | 80 void fail(const String& reason, MessageLevel, PassOwnPtr<SourceLocation>) ov
erride; |
| 80 void disconnect() override; // Will suppress didClose(). | 81 void disconnect() override; // Will suppress didClose(). |
| 81 | 82 |
| 82 DECLARE_VIRTUAL_TRACE(); | 83 DECLARE_VIRTUAL_TRACE(); |
| 83 | 84 |
| 84 class Bridge; | 85 class Bridge; |
| 85 // Allocated in the worker thread, but used in the main thread. | 86 // Allocated in the worker thread, but used in the main thread. |
| 86 class Peer final : public GarbageCollectedFinalized<Peer>, public WebSocketC
hannelClient { | 87 class Peer final : public GarbageCollectedFinalized<Peer>, public WebSocketC
hannelClient { |
| 87 USING_GARBAGE_COLLECTED_MIXIN(Peer); | 88 USING_GARBAGE_COLLECTED_MIXIN(Peer); |
| 88 WTF_MAKE_NONCOPYABLE(Peer); | 89 WTF_MAKE_NONCOPYABLE(Peer); |
| 89 public: | 90 public: |
| 90 Peer(Bridge*, PassRefPtr<WorkerLoaderProxy>, WebSocketChannelSyncHelper*
); | 91 Peer(Bridge*, PassRefPtr<WorkerLoaderProxy>, WebSocketChannelSyncHelper*
); |
| 91 ~Peer() override; | 92 ~Peer() override; |
| 92 | 93 |
| 93 // sourceURLAtConnection and lineNumberAtConnection parameters may | 94 // SourceLocation parameter may be shown when the connection fails. |
| 94 // be shown when the connection fails. | 95 void initialize(PassOwnPtr<SourceLocation>, ExecutionContext*); |
| 95 void initialize(const String& sourceURLAtConnection, unsigned lineNumber
AtConnection, ExecutionContext*); | |
| 96 | 96 |
| 97 void connect(const KURL&, const String& protocol); | 97 void connect(const KURL&, const String& protocol); |
| 98 void sendTextAsCharVector(PassOwnPtr<Vector<char>>); | 98 void sendTextAsCharVector(PassOwnPtr<Vector<char>>); |
| 99 void sendBinaryAsCharVector(PassOwnPtr<Vector<char>>); | 99 void sendBinaryAsCharVector(PassOwnPtr<Vector<char>>); |
| 100 void sendBlob(PassRefPtr<BlobDataHandle>); | 100 void sendBlob(PassRefPtr<BlobDataHandle>); |
| 101 void close(int code, const String& reason); | 101 void close(int code, const String& reason); |
| 102 void fail(const String& reason, MessageLevel, const String& sourceURL, u
nsigned lineNumber); | 102 void fail(const String& reason, MessageLevel, PassOwnPtr<SourceLocation>
); |
| 103 void disconnect(); | 103 void disconnect(); |
| 104 | 104 |
| 105 DECLARE_VIRTUAL_TRACE(); | 105 DECLARE_VIRTUAL_TRACE(); |
| 106 | 106 |
| 107 // WebSocketChannelClient functions. | 107 // WebSocketChannelClient functions. |
| 108 void didConnect(const String& subprotocol, const String& extensions) ove
rride; | 108 void didConnect(const String& subprotocol, const String& extensions) ove
rride; |
| 109 void didReceiveTextMessage(const String& payload) override; | 109 void didReceiveTextMessage(const String& payload) override; |
| 110 void didReceiveBinaryMessage(PassOwnPtr<Vector<char>>) override; | 110 void didReceiveBinaryMessage(PassOwnPtr<Vector<char>>) override; |
| 111 void didConsumeBufferedAmount(uint64_t) override; | 111 void didConsumeBufferedAmount(uint64_t) override; |
| 112 void didStartClosingHandshake() override; | 112 void didStartClosingHandshake() override; |
| 113 void didClose(ClosingHandshakeCompletionStatus, unsigned short code, con
st String& reason) override; | 113 void didClose(ClosingHandshakeCompletionStatus, unsigned short code, con
st String& reason) override; |
| 114 void didError() override; | 114 void didError() override; |
| 115 | 115 |
| 116 private: | 116 private: |
| 117 Member<Bridge> m_bridge; | 117 Member<Bridge> m_bridge; |
| 118 RefPtr<WorkerLoaderProxy> m_loaderProxy; | 118 RefPtr<WorkerLoaderProxy> m_loaderProxy; |
| 119 Member<WebSocketChannel> m_mainWebSocketChannel; | 119 Member<WebSocketChannel> m_mainWebSocketChannel; |
| 120 Member<WebSocketChannelSyncHelper> m_syncHelper; | 120 Member<WebSocketChannelSyncHelper> m_syncHelper; |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 // Bridge for Peer. Running on the worker thread. | 123 // Bridge for Peer. Running on the worker thread. |
| 124 class Bridge final : public GarbageCollectedFinalized<Bridge> { | 124 class Bridge final : public GarbageCollectedFinalized<Bridge> { |
| 125 WTF_MAKE_NONCOPYABLE(Bridge); | 125 WTF_MAKE_NONCOPYABLE(Bridge); |
| 126 public: | 126 public: |
| 127 Bridge(WebSocketChannelClient*, WorkerGlobalScope&); | 127 Bridge(WebSocketChannelClient*, WorkerGlobalScope&); |
| 128 ~Bridge(); | 128 ~Bridge(); |
| 129 // sourceURLAtConnection and lineNumberAtConnection parameters may | 129 // SourceLocation parameter may be shown when the connection fails. |
| 130 // be shown when the connection fails. | 130 void initialize(PassOwnPtr<SourceLocation>); |
| 131 void initialize(const String& sourceURLAtConnection, unsigned lineNumber
AtConnection); | |
| 132 bool connect(const KURL&, const String& protocol); | 131 bool connect(const KURL&, const String& protocol); |
| 133 void send(const CString& message); | 132 void send(const CString& message); |
| 134 void send(const DOMArrayBuffer&, unsigned byteOffset, unsigned byteLengt
h); | 133 void send(const DOMArrayBuffer&, unsigned byteOffset, unsigned byteLengt
h); |
| 135 void send(PassRefPtr<BlobDataHandle>); | 134 void send(PassRefPtr<BlobDataHandle>); |
| 136 void close(int code, const String& reason); | 135 void close(int code, const String& reason); |
| 137 void fail(const String& reason, MessageLevel, const String& sourceURL, u
nsigned lineNumber); | 136 void fail(const String& reason, MessageLevel, PassOwnPtr<SourceLocation>
); |
| 138 void disconnect(); | 137 void disconnect(); |
| 139 | 138 |
| 140 // Returns null when |disconnect| has already been called. | 139 // Returns null when |disconnect| has already been called. |
| 141 WebSocketChannelClient* client() { return m_client; } | 140 WebSocketChannelClient* client() { return m_client; } |
| 142 | 141 |
| 143 DECLARE_TRACE(); | 142 DECLARE_TRACE(); |
| 144 | 143 |
| 145 private: | 144 private: |
| 146 // Returns false if shutdown event is received before method completion. | 145 // Returns false if shutdown event is received before method completion. |
| 147 bool waitForMethodCompletion(std::unique_ptr<ExecutionContextTask>); | 146 bool waitForMethodCompletion(std::unique_ptr<ExecutionContextTask>); |
| 148 | 147 |
| 149 Member<WebSocketChannelClient> m_client; | 148 Member<WebSocketChannelClient> m_client; |
| 150 Member<WorkerGlobalScope> m_workerGlobalScope; | 149 Member<WorkerGlobalScope> m_workerGlobalScope; |
| 151 RefPtr<WorkerLoaderProxy> m_loaderProxy; | 150 RefPtr<WorkerLoaderProxy> m_loaderProxy; |
| 152 Member<WebSocketChannelSyncHelper> m_syncHelper; | 151 Member<WebSocketChannelSyncHelper> m_syncHelper; |
| 153 Member<Peer> m_peer; | 152 Member<Peer> m_peer; |
| 154 }; | 153 }; |
| 155 | 154 |
| 156 private: | 155 private: |
| 157 WorkerWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient*, const St
ring& sourceURL, unsigned lineNumber); | 156 WorkerWebSocketChannel(WorkerGlobalScope&, WebSocketChannelClient*, PassOwnP
tr<SourceLocation>); |
| 158 | 157 |
| 159 Member<Bridge> m_bridge; | 158 Member<Bridge> m_bridge; |
| 160 String m_sourceURLAtConnection; | 159 OwnPtr<SourceLocation> m_locationAtConnection; |
| 161 unsigned m_lineNumberAtConnection; | |
| 162 }; | 160 }; |
| 163 | 161 |
| 164 } // namespace blink | 162 } // namespace blink |
| 165 | 163 |
| 166 #endif // WorkerWebSocketChannel_h | 164 #endif // WorkerWebSocketChannel_h |
| OLD | NEW |