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