| 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 28 matching lines...) Expand all Loading... |
| 39 #include "wtf/PassOwnPtr.h" | 39 #include "wtf/PassOwnPtr.h" |
| 40 #include "wtf/PassRefPtr.h" | 40 #include "wtf/PassRefPtr.h" |
| 41 #include "wtf/RefCounted.h" | 41 #include "wtf/RefCounted.h" |
| 42 #include "wtf/RefPtr.h" | 42 #include "wtf/RefPtr.h" |
| 43 #include "wtf/Threading.h" | 43 #include "wtf/Threading.h" |
| 44 #include "wtf/Vector.h" | 44 #include "wtf/Vector.h" |
| 45 #include "wtf/text/WTFString.h" | 45 #include "wtf/text/WTFString.h" |
| 46 | 46 |
| 47 namespace WebCore { | 47 namespace WebCore { |
| 48 | 48 |
| 49 class BlobDataHandle; |
| 49 class KURL; | 50 class KURL; |
| 50 class ScriptExecutionContext; | 51 class ScriptExecutionContext; |
| 51 class ThreadableWebSocketChannelClientWrapper; | 52 class ThreadableWebSocketChannelClientWrapper; |
| 52 class WorkerGlobalScope; | 53 class WorkerGlobalScope; |
| 53 class WorkerLoaderProxy; | 54 class WorkerLoaderProxy; |
| 54 class WorkerRunLoop; | 55 class WorkerRunLoop; |
| 55 | 56 |
| 56 class WorkerThreadableWebSocketChannel : public RefCounted<WorkerThreadableWebSo
cketChannel>, public WebSocketChannel { | 57 class WorkerThreadableWebSocketChannel : public RefCounted<WorkerThreadableWebSo
cketChannel>, public WebSocketChannel { |
| 57 WTF_MAKE_FAST_ALLOCATED; | 58 WTF_MAKE_FAST_ALLOCATED; |
| 58 public: | 59 public: |
| 59 static PassRefPtr<WebSocketChannel> create(WorkerGlobalScope* workerGlobalSc
ope, WebSocketChannelClient* client, const String& taskMode) | 60 static PassRefPtr<WebSocketChannel> create(WorkerGlobalScope* workerGlobalSc
ope, WebSocketChannelClient* client, const String& taskMode) |
| 60 { | 61 { |
| 61 return adoptRef(new WorkerThreadableWebSocketChannel(workerGlobalScope,
client, taskMode)); | 62 return adoptRef(new WorkerThreadableWebSocketChannel(workerGlobalScope,
client, taskMode)); |
| 62 } | 63 } |
| 63 virtual ~WorkerThreadableWebSocketChannel(); | 64 virtual ~WorkerThreadableWebSocketChannel(); |
| 64 | 65 |
| 65 // WebSocketChannel functions. | 66 // WebSocketChannel functions. |
| 66 virtual void connect(const KURL&, const String& protocol) OVERRIDE; | 67 virtual void connect(const KURL&, const String& protocol) OVERRIDE; |
| 67 virtual String subprotocol() OVERRIDE; | 68 virtual String subprotocol() OVERRIDE; |
| 68 virtual String extensions() OVERRIDE; | 69 virtual String extensions() OVERRIDE; |
| 69 virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE; | 70 virtual WebSocketChannel::SendResult send(const String& message) OVERRIDE; |
| 70 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; |
| 71 virtual WebSocketChannel::SendResult send(const Blob&) OVERRIDE; | 72 virtual WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>) OVERRI
DE; |
| 72 virtual unsigned long bufferedAmount() const OVERRIDE; | 73 virtual unsigned long bufferedAmount() const OVERRIDE; |
| 73 virtual void close(int code, const String& reason) OVERRIDE; | 74 virtual void close(int code, const String& reason) OVERRIDE; |
| 74 virtual void fail(const String& reason, MessageLevel, const String&, unsigne
d) OVERRIDE; | 75 virtual void fail(const String& reason, MessageLevel, const String&, unsigne
d) OVERRIDE; |
| 75 virtual void disconnect() OVERRIDE; // Will suppress didClose(). | 76 virtual void disconnect() OVERRIDE; // Will suppress didClose(). |
| 76 virtual void suspend() OVERRIDE; | 77 virtual void suspend() OVERRIDE; |
| 77 virtual void resume() OVERRIDE; | 78 virtual void resume() OVERRIDE; |
| 78 | 79 |
| 79 // Generated by the bridge. The Peer and its bridge should have identical | 80 // Generated by the bridge. The Peer and its bridge should have identical |
| 80 // lifetimes. | 81 // lifetimes. |
| 81 class Peer : public WebSocketChannelClient { | 82 class Peer : public WebSocketChannelClient { |
| 82 WTF_MAKE_NONCOPYABLE(Peer); WTF_MAKE_FAST_ALLOCATED; | 83 WTF_MAKE_NONCOPYABLE(Peer); WTF_MAKE_FAST_ALLOCATED; |
| 83 public: | 84 public: |
| 84 // sourceURLAtConnection and lineNumberAtConnection parameters may | 85 // sourceURLAtConnection and lineNumberAtConnection parameters may |
| 85 // be shown when the connection fails. | 86 // be shown when the connection fails. |
| 86 static Peer* create(PassRefPtr<ThreadableWebSocketChannelClientWrapper>
clientWrapper, WorkerLoaderProxy& loaderProxy, ScriptExecutionContext* context,
const String& taskMode, const String& sourceURLAtConnection, unsigned lineNumber
AtConnection) | 87 static Peer* create(PassRefPtr<ThreadableWebSocketChannelClientWrapper>
clientWrapper, WorkerLoaderProxy& loaderProxy, ScriptExecutionContext* context,
const String& taskMode, const String& sourceURLAtConnection, unsigned lineNumber
AtConnection) |
| 87 { | 88 { |
| 88 return new Peer(clientWrapper, loaderProxy, context, taskMode, sourc
eURLAtConnection, lineNumberAtConnection); | 89 return new Peer(clientWrapper, loaderProxy, context, taskMode, sourc
eURLAtConnection, lineNumberAtConnection); |
| 89 } | 90 } |
| 90 ~Peer(); | 91 ~Peer(); |
| 91 | 92 |
| 92 void connect(const KURL&, const String& protocol); | 93 void connect(const KURL&, const String& protocol); |
| 93 void send(const String& message); | 94 void send(const String& message); |
| 94 void send(const ArrayBuffer&); | 95 void send(const ArrayBuffer&); |
| 95 void send(const Blob&); | 96 void send(PassRefPtr<BlobDataHandle>); |
| 96 void bufferedAmount(); | 97 void bufferedAmount(); |
| 97 void close(int code, const String& reason); | 98 void close(int code, const String& reason); |
| 98 void fail(const String& reason, MessageLevel, const String& sourceURL, u
nsigned lineNumber); | 99 void fail(const String& reason, MessageLevel, const String& sourceURL, u
nsigned lineNumber); |
| 99 void disconnect(); | 100 void disconnect(); |
| 100 void suspend(); | 101 void suspend(); |
| 101 void resume(); | 102 void resume(); |
| 102 | 103 |
| 103 // WebSocketChannelClient functions. | 104 // WebSocketChannelClient functions. |
| 104 virtual void didConnect() OVERRIDE; | 105 virtual void didConnect() OVERRIDE; |
| 105 virtual void didReceiveMessage(const String& message) OVERRIDE; | 106 virtual void didReceiveMessage(const String& message) OVERRIDE; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 134 { | 135 { |
| 135 return adoptRef(new Bridge(workerClientWrapper, workerGlobalScope, t
askMode)); | 136 return adoptRef(new Bridge(workerClientWrapper, workerGlobalScope, t
askMode)); |
| 136 } | 137 } |
| 137 ~Bridge(); | 138 ~Bridge(); |
| 138 // sourceURLAtConnection and lineNumberAtConnection parameters may | 139 // sourceURLAtConnection and lineNumberAtConnection parameters may |
| 139 // be shown when the connection fails. | 140 // be shown when the connection fails. |
| 140 void initialize(const String& sourceURLAtConnection, unsigned lineNumber
AtConnection); | 141 void initialize(const String& sourceURLAtConnection, unsigned lineNumber
AtConnection); |
| 141 void connect(const KURL&, const String& protocol); | 142 void connect(const KURL&, const String& protocol); |
| 142 WebSocketChannel::SendResult send(const String& message); | 143 WebSocketChannel::SendResult send(const String& message); |
| 143 WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffse
t, unsigned byteLength); | 144 WebSocketChannel::SendResult send(const ArrayBuffer&, unsigned byteOffse
t, unsigned byteLength); |
| 144 WebSocketChannel::SendResult send(const Blob&); | 145 WebSocketChannel::SendResult send(PassRefPtr<BlobDataHandle>); |
| 145 unsigned long bufferedAmount(); | 146 unsigned long bufferedAmount(); |
| 146 void close(int code, const String& reason); | 147 void close(int code, const String& reason); |
| 147 void fail(const String& reason, MessageLevel, const String& sourceURL, u
nsigned lineNumber); | 148 void fail(const String& reason, MessageLevel, const String& sourceURL, u
nsigned lineNumber); |
| 148 void disconnect(); | 149 void disconnect(); |
| 149 void suspend(); | 150 void suspend(); |
| 150 void resume(); | 151 void resume(); |
| 151 | 152 |
| 152 using RefCounted<Bridge>::ref; | 153 using RefCounted<Bridge>::ref; |
| 153 using RefCounted<Bridge>::deref; | 154 using RefCounted<Bridge>::deref; |
| 154 | 155 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 174 WorkerLoaderProxy& m_loaderProxy; | 175 WorkerLoaderProxy& m_loaderProxy; |
| 175 String m_taskMode; | 176 String m_taskMode; |
| 176 Peer* m_peer; | 177 Peer* m_peer; |
| 177 }; | 178 }; |
| 178 | 179 |
| 179 WorkerThreadableWebSocketChannel(WorkerGlobalScope*, WebSocketChannelClient*
, const String& taskMode); | 180 WorkerThreadableWebSocketChannel(WorkerGlobalScope*, WebSocketChannelClient*
, const String& taskMode); |
| 180 | 181 |
| 181 static void mainThreadConnect(ScriptExecutionContext*, Peer*, const KURL&, c
onst String& protocol); | 182 static void mainThreadConnect(ScriptExecutionContext*, Peer*, const KURL&, c
onst String& protocol); |
| 182 static void mainThreadSend(ScriptExecutionContext*, Peer*, const String& mes
sage); | 183 static void mainThreadSend(ScriptExecutionContext*, Peer*, const String& mes
sage); |
| 183 static void mainThreadSendArrayBuffer(ScriptExecutionContext*, Peer*, PassOw
nPtr<Vector<char> >); | 184 static void mainThreadSendArrayBuffer(ScriptExecutionContext*, Peer*, PassOw
nPtr<Vector<char> >); |
| 184 static void mainThreadSendBlob(ScriptExecutionContext*, Peer*, const KURL&,
const String& type, long long size); | 185 static void mainThreadSendBlob(ScriptExecutionContext*, Peer*, PassRefPtr<Bl
obDataHandle>); |
| 185 static void mainThreadBufferedAmount(ScriptExecutionContext*, Peer*); | 186 static void mainThreadBufferedAmount(ScriptExecutionContext*, Peer*); |
| 186 static void mainThreadClose(ScriptExecutionContext*, Peer*, int code, const
String& reason); | 187 static void mainThreadClose(ScriptExecutionContext*, Peer*, int code, const
String& reason); |
| 187 static void mainThreadFail(ScriptExecutionContext*, Peer*, const String& rea
son, MessageLevel, const String& sourceURL, unsigned lineNumber); | 188 static void mainThreadFail(ScriptExecutionContext*, Peer*, const String& rea
son, MessageLevel, const String& sourceURL, unsigned lineNumber); |
| 188 static void mainThreadDestroy(ScriptExecutionContext*, PassOwnPtr<Peer>); | 189 static void mainThreadDestroy(ScriptExecutionContext*, PassOwnPtr<Peer>); |
| 189 static void mainThreadSuspend(ScriptExecutionContext*, Peer*); | 190 static void mainThreadSuspend(ScriptExecutionContext*, Peer*); |
| 190 static void mainThreadResume(ScriptExecutionContext*, Peer*); | 191 static void mainThreadResume(ScriptExecutionContext*, Peer*); |
| 191 | 192 |
| 192 class WorkerGlobalScopeDidInitializeTask; | 193 class WorkerGlobalScopeDidInitializeTask; |
| 193 | 194 |
| 194 RefPtr<WorkerGlobalScope> m_workerGlobalScope; | 195 RefPtr<WorkerGlobalScope> m_workerGlobalScope; |
| 195 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; | 196 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; |
| 196 RefPtr<Bridge> m_bridge; | 197 RefPtr<Bridge> m_bridge; |
| 197 String m_sourceURLAtConnection; | 198 String m_sourceURLAtConnection; |
| 198 unsigned m_lineNumberAtConnection; | 199 unsigned m_lineNumberAtConnection; |
| 199 }; | 200 }; |
| 200 | 201 |
| 201 } // namespace WebCore | 202 } // namespace WebCore |
| 202 | 203 |
| 203 #endif // WorkerThreadableWebSocketChannel_h | 204 #endif // WorkerThreadableWebSocketChannel_h |
| OLD | NEW |