Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: Source/modules/websockets/WorkerThreadableWebSocketChannel.cpp

Issue 17648006: Rename WorkerContext to WorkerGlobalScope (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/modules/websockets/WorkerThreadableWebSocketChannel.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 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 22 matching lines...) Expand all
33 #include "modules/websockets/WorkerThreadableWebSocketChannel.h" 33 #include "modules/websockets/WorkerThreadableWebSocketChannel.h"
34 34
35 #include "bindings/v8/ScriptCallStackFactory.h" 35 #include "bindings/v8/ScriptCallStackFactory.h"
36 #include "core/dom/CrossThreadTask.h" 36 #include "core/dom/CrossThreadTask.h"
37 #include "core/dom/Document.h" 37 #include "core/dom/Document.h"
38 #include "core/dom/ScriptExecutionContext.h" 38 #include "core/dom/ScriptExecutionContext.h"
39 #include "core/fileapi/Blob.h" 39 #include "core/fileapi/Blob.h"
40 #include "core/inspector/ScriptCallFrame.h" 40 #include "core/inspector/ScriptCallFrame.h"
41 #include "core/inspector/ScriptCallStack.h" 41 #include "core/inspector/ScriptCallStack.h"
42 #include "core/page/Settings.h" 42 #include "core/page/Settings.h"
43 #include "core/workers/WorkerContext.h" 43 #include "core/workers/WorkerGlobalScope.h"
44 #include "core/workers/WorkerLoaderProxy.h" 44 #include "core/workers/WorkerLoaderProxy.h"
45 #include "core/workers/WorkerRunLoop.h" 45 #include "core/workers/WorkerRunLoop.h"
46 #include "core/workers/WorkerThread.h" 46 #include "core/workers/WorkerThread.h"
47 #include "modules/websockets/MainThreadWebSocketChannel.h" 47 #include "modules/websockets/MainThreadWebSocketChannel.h"
48 #include "modules/websockets/ThreadableWebSocketChannelClientWrapper.h" 48 #include "modules/websockets/ThreadableWebSocketChannelClientWrapper.h"
49 #include "modules/websockets/WebSocketChannel.h" 49 #include "modules/websockets/WebSocketChannel.h"
50 #include "modules/websockets/WebSocketChannelClient.h" 50 #include "modules/websockets/WebSocketChannelClient.h"
51 #include "wtf/ArrayBuffer.h" 51 #include "wtf/ArrayBuffer.h"
52 #include "wtf/MainThread.h" 52 #include "wtf/MainThread.h"
53 #include "wtf/PassRefPtr.h" 53 #include "wtf/PassRefPtr.h"
54 #include "wtf/text/WTFString.h" 54 #include "wtf/text/WTFString.h"
55 55
56 namespace WebCore { 56 namespace WebCore {
57 57
58 WorkerThreadableWebSocketChannel::WorkerThreadableWebSocketChannel(WorkerContext * context, WebSocketChannelClient* client, const String& taskMode) 58 WorkerThreadableWebSocketChannel::WorkerThreadableWebSocketChannel(WorkerGlobalS cope* context, WebSocketChannelClient* client, const String& taskMode)
59 : m_workerContext(context) 59 : m_workerGlobalScope(context)
60 , m_workerClientWrapper(ThreadableWebSocketChannelClientWrapper::create(cont ext, client)) 60 , m_workerClientWrapper(ThreadableWebSocketChannelClientWrapper::create(cont ext, client))
61 , m_bridge(Bridge::create(m_workerClientWrapper, m_workerContext, taskMode)) 61 , m_bridge(Bridge::create(m_workerClientWrapper, m_workerGlobalScope, taskMo de))
62 , m_lineNumberAtConnection(0) 62 , m_lineNumberAtConnection(0)
63 { 63 {
64 // We assume that we can take the JS callstack at WebSocket connection here. 64 // We assume that we can take the JS callstack at WebSocket connection here.
65 RefPtr<ScriptCallStack> callStack = createScriptCallStack(1, true); 65 RefPtr<ScriptCallStack> callStack = createScriptCallStack(1, true);
66 String sourceURL; 66 String sourceURL;
67 unsigned lineNumber = 0; 67 unsigned lineNumber = 0;
68 if (callStack && callStack->size()) { 68 if (callStack && callStack->size()) {
69 sourceURL = callStack->at(0).sourceURL(); 69 sourceURL = callStack->at(0).sourceURL();
70 lineNumber = callStack->at(0).lineNumber(); 70 lineNumber = callStack->at(0).lineNumber();
71 } 71 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 } 200 }
201 201
202 void WorkerThreadableWebSocketChannel::Peer::connect(const KURL& url, const Stri ng& protocol) 202 void WorkerThreadableWebSocketChannel::Peer::connect(const KURL& url, const Stri ng& protocol)
203 { 203 {
204 ASSERT(isMainThread()); 204 ASSERT(isMainThread());
205 if (!m_mainWebSocketChannel) 205 if (!m_mainWebSocketChannel)
206 return; 206 return;
207 m_mainWebSocketChannel->connect(url, protocol); 207 m_mainWebSocketChannel->connect(url, protocol);
208 } 208 }
209 209
210 static void workerContextDidSend(ScriptExecutionContext* context, PassRefPtr<Thr eadableWebSocketChannelClientWrapper> workerClientWrapper, WebSocketChannel::Sen dResult sendRequestResult) 210 static void workerGlobalScopeDidSend(ScriptExecutionContext* context, PassRefPtr <ThreadableWebSocketChannelClientWrapper> workerClientWrapper, WebSocketChannel: :SendResult sendRequestResult)
211 { 211 {
212 ASSERT_UNUSED(context, context->isWorkerContext()); 212 ASSERT_UNUSED(context, context->isWorkerGlobalScope());
213 workerClientWrapper->setSendRequestResult(sendRequestResult); 213 workerClientWrapper->setSendRequestResult(sendRequestResult);
214 } 214 }
215 215
216 void WorkerThreadableWebSocketChannel::Peer::send(const String& message) 216 void WorkerThreadableWebSocketChannel::Peer::send(const String& message)
217 { 217 {
218 ASSERT(isMainThread()); 218 ASSERT(isMainThread());
219 if (!m_mainWebSocketChannel || !m_workerClientWrapper) 219 if (!m_mainWebSocketChannel || !m_workerClientWrapper)
220 return; 220 return;
221 WebSocketChannel::SendResult sendRequestResult = m_mainWebSocketChannel->sen d(message); 221 WebSocketChannel::SendResult sendRequestResult = m_mainWebSocketChannel->sen d(message);
222 m_loaderProxy.postTaskForModeToWorkerContext(createCallbackTask(&workerConte xtDidSend, m_workerClientWrapper, sendRequestResult), m_taskMode); 222 m_loaderProxy.postTaskForModeToWorkerGlobalScope(createCallbackTask(&workerG lobalScopeDidSend, m_workerClientWrapper, sendRequestResult), m_taskMode);
223 } 223 }
224 224
225 void WorkerThreadableWebSocketChannel::Peer::send(const ArrayBuffer& binaryData) 225 void WorkerThreadableWebSocketChannel::Peer::send(const ArrayBuffer& binaryData)
226 { 226 {
227 ASSERT(isMainThread()); 227 ASSERT(isMainThread());
228 if (!m_mainWebSocketChannel || !m_workerClientWrapper) 228 if (!m_mainWebSocketChannel || !m_workerClientWrapper)
229 return; 229 return;
230 WebSocketChannel::SendResult sendRequestResult = m_mainWebSocketChannel->sen d(binaryData, 0, binaryData.byteLength()); 230 WebSocketChannel::SendResult sendRequestResult = m_mainWebSocketChannel->sen d(binaryData, 0, binaryData.byteLength());
231 m_loaderProxy.postTaskForModeToWorkerContext(createCallbackTask(&workerConte xtDidSend, m_workerClientWrapper, sendRequestResult), m_taskMode); 231 m_loaderProxy.postTaskForModeToWorkerGlobalScope(createCallbackTask(&workerG lobalScopeDidSend, m_workerClientWrapper, sendRequestResult), m_taskMode);
232 } 232 }
233 233
234 void WorkerThreadableWebSocketChannel::Peer::send(const Blob& binaryData) 234 void WorkerThreadableWebSocketChannel::Peer::send(const Blob& binaryData)
235 { 235 {
236 ASSERT(isMainThread()); 236 ASSERT(isMainThread());
237 if (!m_mainWebSocketChannel || !m_workerClientWrapper) 237 if (!m_mainWebSocketChannel || !m_workerClientWrapper)
238 return; 238 return;
239 WebSocketChannel::SendResult sendRequestResult = m_mainWebSocketChannel->sen d(binaryData); 239 WebSocketChannel::SendResult sendRequestResult = m_mainWebSocketChannel->sen d(binaryData);
240 m_loaderProxy.postTaskForModeToWorkerContext(createCallbackTask(&workerConte xtDidSend, m_workerClientWrapper, sendRequestResult), m_taskMode); 240 m_loaderProxy.postTaskForModeToWorkerGlobalScope(createCallbackTask(&workerG lobalScopeDidSend, m_workerClientWrapper, sendRequestResult), m_taskMode);
241 } 241 }
242 242
243 static void workerContextDidGetBufferedAmount(ScriptExecutionContext* context, P assRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, unsigned long bufferedAmount) 243 static void workerGlobalScopeDidGetBufferedAmount(ScriptExecutionContext* contex t, PassRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, unsi gned long bufferedAmount)
244 { 244 {
245 ASSERT_UNUSED(context, context->isWorkerContext()); 245 ASSERT_UNUSED(context, context->isWorkerGlobalScope());
246 workerClientWrapper->setBufferedAmount(bufferedAmount); 246 workerClientWrapper->setBufferedAmount(bufferedAmount);
247 } 247 }
248 248
249 void WorkerThreadableWebSocketChannel::Peer::bufferedAmount() 249 void WorkerThreadableWebSocketChannel::Peer::bufferedAmount()
250 { 250 {
251 ASSERT(isMainThread()); 251 ASSERT(isMainThread());
252 if (!m_mainWebSocketChannel || !m_workerClientWrapper) 252 if (!m_mainWebSocketChannel || !m_workerClientWrapper)
253 return; 253 return;
254 unsigned long bufferedAmount = m_mainWebSocketChannel->bufferedAmount(); 254 unsigned long bufferedAmount = m_mainWebSocketChannel->bufferedAmount();
255 m_loaderProxy.postTaskForModeToWorkerContext(createCallbackTask(&workerConte xtDidGetBufferedAmount, m_workerClientWrapper, bufferedAmount), m_taskMode); 255 m_loaderProxy.postTaskForModeToWorkerGlobalScope(createCallbackTask(&workerG lobalScopeDidGetBufferedAmount, m_workerClientWrapper, bufferedAmount), m_taskMo de);
256 } 256 }
257 257
258 void WorkerThreadableWebSocketChannel::Peer::close(int code, const String& reaso n) 258 void WorkerThreadableWebSocketChannel::Peer::close(int code, const String& reaso n)
259 { 259 {
260 ASSERT(isMainThread()); 260 ASSERT(isMainThread());
261 if (!m_mainWebSocketChannel) 261 if (!m_mainWebSocketChannel)
262 return; 262 return;
263 m_mainWebSocketChannel->close(code, reason); 263 m_mainWebSocketChannel->close(code, reason);
264 } 264 }
265 265
(...skipping 23 matching lines...) Expand all
289 } 289 }
290 290
291 void WorkerThreadableWebSocketChannel::Peer::resume() 291 void WorkerThreadableWebSocketChannel::Peer::resume()
292 { 292 {
293 ASSERT(isMainThread()); 293 ASSERT(isMainThread());
294 if (!m_mainWebSocketChannel) 294 if (!m_mainWebSocketChannel)
295 return; 295 return;
296 m_mainWebSocketChannel->resume(); 296 m_mainWebSocketChannel->resume();
297 } 297 }
298 298
299 static void workerContextDidConnect(ScriptExecutionContext* context, PassRefPtr< ThreadableWebSocketChannelClientWrapper> workerClientWrapper, const String& subp rotocol, const String& extensions) 299 static void workerGlobalScopeDidConnect(ScriptExecutionContext* context, PassRef Ptr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, const String& subprotocol, const String& extensions)
300 { 300 {
301 ASSERT_UNUSED(context, context->isWorkerContext()); 301 ASSERT_UNUSED(context, context->isWorkerGlobalScope());
302 workerClientWrapper->setSubprotocol(subprotocol); 302 workerClientWrapper->setSubprotocol(subprotocol);
303 workerClientWrapper->setExtensions(extensions); 303 workerClientWrapper->setExtensions(extensions);
304 workerClientWrapper->didConnect(); 304 workerClientWrapper->didConnect();
305 } 305 }
306 306
307 void WorkerThreadableWebSocketChannel::Peer::didConnect() 307 void WorkerThreadableWebSocketChannel::Peer::didConnect()
308 { 308 {
309 ASSERT(isMainThread()); 309 ASSERT(isMainThread());
310 m_loaderProxy.postTaskForModeToWorkerContext(createCallbackTask(&workerConte xtDidConnect, m_workerClientWrapper, m_mainWebSocketChannel->subprotocol(), m_ma inWebSocketChannel->extensions()), m_taskMode); 310 m_loaderProxy.postTaskForModeToWorkerGlobalScope(createCallbackTask(&workerG lobalScopeDidConnect, m_workerClientWrapper, m_mainWebSocketChannel->subprotocol (), m_mainWebSocketChannel->extensions()), m_taskMode);
311 } 311 }
312 312
313 static void workerContextDidReceiveMessage(ScriptExecutionContext* context, Pass RefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, const Strin g& message) 313 static void workerGlobalScopeDidReceiveMessage(ScriptExecutionContext* context, PassRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, const S tring& message)
314 { 314 {
315 ASSERT_UNUSED(context, context->isWorkerContext()); 315 ASSERT_UNUSED(context, context->isWorkerGlobalScope());
316 workerClientWrapper->didReceiveMessage(message); 316 workerClientWrapper->didReceiveMessage(message);
317 } 317 }
318 318
319 void WorkerThreadableWebSocketChannel::Peer::didReceiveMessage(const String& mes sage) 319 void WorkerThreadableWebSocketChannel::Peer::didReceiveMessage(const String& mes sage)
320 { 320 {
321 ASSERT(isMainThread()); 321 ASSERT(isMainThread());
322 m_loaderProxy.postTaskForModeToWorkerContext(createCallbackTask(&workerConte xtDidReceiveMessage, m_workerClientWrapper, message), m_taskMode); 322 m_loaderProxy.postTaskForModeToWorkerGlobalScope(createCallbackTask(&workerG lobalScopeDidReceiveMessage, m_workerClientWrapper, message), m_taskMode);
323 } 323 }
324 324
325 static void workerContextDidReceiveBinaryData(ScriptExecutionContext* context, P assRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, PassOwnP tr<Vector<char> > binaryData) 325 static void workerGlobalScopeDidReceiveBinaryData(ScriptExecutionContext* contex t, PassRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, Pass OwnPtr<Vector<char> > binaryData)
326 { 326 {
327 ASSERT_UNUSED(context, context->isWorkerContext()); 327 ASSERT_UNUSED(context, context->isWorkerGlobalScope());
328 workerClientWrapper->didReceiveBinaryData(binaryData); 328 workerClientWrapper->didReceiveBinaryData(binaryData);
329 } 329 }
330 330
331 void WorkerThreadableWebSocketChannel::Peer::didReceiveBinaryData(PassOwnPtr<Vec tor<char> > binaryData) 331 void WorkerThreadableWebSocketChannel::Peer::didReceiveBinaryData(PassOwnPtr<Vec tor<char> > binaryData)
332 { 332 {
333 ASSERT(isMainThread()); 333 ASSERT(isMainThread());
334 m_loaderProxy.postTaskForModeToWorkerContext(createCallbackTask(&workerConte xtDidReceiveBinaryData, m_workerClientWrapper, binaryData), m_taskMode); 334 m_loaderProxy.postTaskForModeToWorkerGlobalScope(createCallbackTask(&workerG lobalScopeDidReceiveBinaryData, m_workerClientWrapper, binaryData), m_taskMode);
335 } 335 }
336 336
337 static void workerContextDidUpdateBufferedAmount(ScriptExecutionContext* context , PassRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, unsig ned long bufferedAmount) 337 static void workerGlobalScopeDidUpdateBufferedAmount(ScriptExecutionContext* con text, PassRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, u nsigned long bufferedAmount)
338 { 338 {
339 ASSERT_UNUSED(context, context->isWorkerContext()); 339 ASSERT_UNUSED(context, context->isWorkerGlobalScope());
340 workerClientWrapper->didUpdateBufferedAmount(bufferedAmount); 340 workerClientWrapper->didUpdateBufferedAmount(bufferedAmount);
341 } 341 }
342 342
343 void WorkerThreadableWebSocketChannel::Peer::didUpdateBufferedAmount(unsigned lo ng bufferedAmount) 343 void WorkerThreadableWebSocketChannel::Peer::didUpdateBufferedAmount(unsigned lo ng bufferedAmount)
344 { 344 {
345 ASSERT(isMainThread()); 345 ASSERT(isMainThread());
346 m_loaderProxy.postTaskForModeToWorkerContext(createCallbackTask(&workerConte xtDidUpdateBufferedAmount, m_workerClientWrapper, bufferedAmount), m_taskMode); 346 m_loaderProxy.postTaskForModeToWorkerGlobalScope(createCallbackTask(&workerG lobalScopeDidUpdateBufferedAmount, m_workerClientWrapper, bufferedAmount), m_tas kMode);
347 } 347 }
348 348
349 static void workerContextDidStartClosingHandshake(ScriptExecutionContext* contex t, PassRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper) 349 static void workerGlobalScopeDidStartClosingHandshake(ScriptExecutionContext* co ntext, PassRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper)
350 { 350 {
351 ASSERT_UNUSED(context, context->isWorkerContext()); 351 ASSERT_UNUSED(context, context->isWorkerGlobalScope());
352 workerClientWrapper->didStartClosingHandshake(); 352 workerClientWrapper->didStartClosingHandshake();
353 } 353 }
354 354
355 void WorkerThreadableWebSocketChannel::Peer::didStartClosingHandshake() 355 void WorkerThreadableWebSocketChannel::Peer::didStartClosingHandshake()
356 { 356 {
357 ASSERT(isMainThread()); 357 ASSERT(isMainThread());
358 m_loaderProxy.postTaskForModeToWorkerContext(createCallbackTask(&workerConte xtDidStartClosingHandshake, m_workerClientWrapper), m_taskMode); 358 m_loaderProxy.postTaskForModeToWorkerGlobalScope(createCallbackTask(&workerG lobalScopeDidStartClosingHandshake, m_workerClientWrapper), m_taskMode);
359 } 359 }
360 360
361 static void workerContextDidClose(ScriptExecutionContext* context, PassRefPtr<Th readableWebSocketChannelClientWrapper> workerClientWrapper, unsigned long unhand ledBufferedAmount, WebSocketChannelClient::ClosingHandshakeCompletionStatus clos ingHandshakeCompletion, unsigned short code, const String& reason) 361 static void workerGlobalScopeDidClose(ScriptExecutionContext* context, PassRefPt r<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, unsigned long un handledBufferedAmount, WebSocketChannelClient::ClosingHandshakeCompletionStatus closingHandshakeCompletion, unsigned short code, const String& reason)
362 { 362 {
363 ASSERT_UNUSED(context, context->isWorkerContext()); 363 ASSERT_UNUSED(context, context->isWorkerGlobalScope());
364 workerClientWrapper->didClose(unhandledBufferedAmount, closingHandshakeCompl etion, code, reason); 364 workerClientWrapper->didClose(unhandledBufferedAmount, closingHandshakeCompl etion, code, reason);
365 } 365 }
366 366
367 void WorkerThreadableWebSocketChannel::Peer::didClose(unsigned long unhandledBuf feredAmount, ClosingHandshakeCompletionStatus closingHandshakeCompletion, unsign ed short code, const String& reason) 367 void WorkerThreadableWebSocketChannel::Peer::didClose(unsigned long unhandledBuf feredAmount, ClosingHandshakeCompletionStatus closingHandshakeCompletion, unsign ed short code, const String& reason)
368 { 368 {
369 ASSERT(isMainThread()); 369 ASSERT(isMainThread());
370 m_mainWebSocketChannel = 0; 370 m_mainWebSocketChannel = 0;
371 m_loaderProxy.postTaskForModeToWorkerContext(createCallbackTask(&workerConte xtDidClose, m_workerClientWrapper, unhandledBufferedAmount, closingHandshakeComp letion, code, reason), m_taskMode); 371 m_loaderProxy.postTaskForModeToWorkerGlobalScope(createCallbackTask(&workerG lobalScopeDidClose, m_workerClientWrapper, unhandledBufferedAmount, closingHands hakeCompletion, code, reason), m_taskMode);
372 } 372 }
373 373
374 static void workerContextDidReceiveMessageError(ScriptExecutionContext* context, PassRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper) 374 static void workerGlobalScopeDidReceiveMessageError(ScriptExecutionContext* cont ext, PassRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper)
375 { 375 {
376 ASSERT_UNUSED(context, context->isWorkerContext()); 376 ASSERT_UNUSED(context, context->isWorkerGlobalScope());
377 workerClientWrapper->didReceiveMessageError(); 377 workerClientWrapper->didReceiveMessageError();
378 } 378 }
379 379
380 void WorkerThreadableWebSocketChannel::Peer::didReceiveMessageError() 380 void WorkerThreadableWebSocketChannel::Peer::didReceiveMessageError()
381 { 381 {
382 ASSERT(isMainThread()); 382 ASSERT(isMainThread());
383 m_loaderProxy.postTaskForModeToWorkerContext(createCallbackTask(&workerConte xtDidReceiveMessageError, m_workerClientWrapper), m_taskMode); 383 m_loaderProxy.postTaskForModeToWorkerGlobalScope(createCallbackTask(&workerG lobalScopeDidReceiveMessageError, m_workerClientWrapper), m_taskMode);
384 } 384 }
385 385
386 WorkerThreadableWebSocketChannel::Bridge::Bridge(PassRefPtr<ThreadableWebSocketC hannelClientWrapper> workerClientWrapper, PassRefPtr<WorkerContext> workerContex t, const String& taskMode) 386 WorkerThreadableWebSocketChannel::Bridge::Bridge(PassRefPtr<ThreadableWebSocketC hannelClientWrapper> workerClientWrapper, PassRefPtr<WorkerGlobalScope> workerGl obalScope, const String& taskMode)
387 : m_workerClientWrapper(workerClientWrapper) 387 : m_workerClientWrapper(workerClientWrapper)
388 , m_workerContext(workerContext) 388 , m_workerGlobalScope(workerGlobalScope)
389 , m_loaderProxy(m_workerContext->thread()->workerLoaderProxy()) 389 , m_loaderProxy(m_workerGlobalScope->thread()->workerLoaderProxy())
390 , m_taskMode(taskMode) 390 , m_taskMode(taskMode)
391 , m_peer(0) 391 , m_peer(0)
392 { 392 {
393 ASSERT(m_workerClientWrapper.get()); 393 ASSERT(m_workerClientWrapper.get());
394 } 394 }
395 395
396 WorkerThreadableWebSocketChannel::Bridge::~Bridge() 396 WorkerThreadableWebSocketChannel::Bridge::~Bridge()
397 { 397 {
398 disconnect(); 398 disconnect();
399 } 399 }
400 400
401 class WorkerThreadableWebSocketChannel::WorkerContextDidInitializeTask : public ScriptExecutionContext::Task { 401 class WorkerThreadableWebSocketChannel::WorkerGlobalScopeDidInitializeTask : pub lic ScriptExecutionContext::Task {
402 public: 402 public:
403 static PassOwnPtr<ScriptExecutionContext::Task> create(WorkerThreadableWebSo cketChannel::Peer* peer, WorkerLoaderProxy* loaderProxy, PassRefPtr<ThreadableWe bSocketChannelClientWrapper> workerClientWrapper) 403 static PassOwnPtr<ScriptExecutionContext::Task> create(WorkerThreadableWebSo cketChannel::Peer* peer, WorkerLoaderProxy* loaderProxy, PassRefPtr<ThreadableWe bSocketChannelClientWrapper> workerClientWrapper)
404 { 404 {
405 return adoptPtr(new WorkerContextDidInitializeTask(peer, loaderProxy, wo rkerClientWrapper)); 405 return adoptPtr(new WorkerGlobalScopeDidInitializeTask(peer, loaderProxy , workerClientWrapper));
406 } 406 }
407 407
408 virtual ~WorkerContextDidInitializeTask() { } 408 virtual ~WorkerGlobalScopeDidInitializeTask() { }
409 virtual void performTask(ScriptExecutionContext* context) OVERRIDE 409 virtual void performTask(ScriptExecutionContext* context) OVERRIDE
410 { 410 {
411 ASSERT_UNUSED(context, context->isWorkerContext()); 411 ASSERT_UNUSED(context, context->isWorkerGlobalScope());
412 if (m_workerClientWrapper->failedWebSocketChannelCreation()) { 412 if (m_workerClientWrapper->failedWebSocketChannelCreation()) {
413 // If Bridge::initialize() quitted earlier, we need to kick mainThre adDestroy() to delete the peer. 413 // If Bridge::initialize() quitted earlier, we need to kick mainThre adDestroy() to delete the peer.
414 OwnPtr<WorkerThreadableWebSocketChannel::Peer> peer = adoptPtr(m_pee r); 414 OwnPtr<WorkerThreadableWebSocketChannel::Peer> peer = adoptPtr(m_pee r);
415 m_peer = 0; 415 m_peer = 0;
416 m_loaderProxy->postTaskToLoader(createCallbackTask(&WorkerThreadable WebSocketChannel::mainThreadDestroy, peer.release())); 416 m_loaderProxy->postTaskToLoader(createCallbackTask(&WorkerThreadable WebSocketChannel::mainThreadDestroy, peer.release()));
417 } else 417 } else
418 m_workerClientWrapper->didCreateWebSocketChannel(m_peer); 418 m_workerClientWrapper->didCreateWebSocketChannel(m_peer);
419 } 419 }
420 virtual bool isCleanupTask() const OVERRIDE { return true; } 420 virtual bool isCleanupTask() const OVERRIDE { return true; }
421 421
422 private: 422 private:
423 WorkerContextDidInitializeTask(WorkerThreadableWebSocketChannel::Peer* peer, WorkerLoaderProxy* loaderProxy, PassRefPtr<ThreadableWebSocketChannelClientWrap per> workerClientWrapper) 423 WorkerGlobalScopeDidInitializeTask(WorkerThreadableWebSocketChannel::Peer* p eer, WorkerLoaderProxy* loaderProxy, PassRefPtr<ThreadableWebSocketChannelClient Wrapper> workerClientWrapper)
424 : m_peer(peer) 424 : m_peer(peer)
425 , m_loaderProxy(loaderProxy) 425 , m_loaderProxy(loaderProxy)
426 , m_workerClientWrapper(workerClientWrapper) 426 , m_workerClientWrapper(workerClientWrapper)
427 { 427 {
428 } 428 }
429 429
430 WorkerThreadableWebSocketChannel::Peer* m_peer; 430 WorkerThreadableWebSocketChannel::Peer* m_peer;
431 WorkerLoaderProxy* m_loaderProxy; 431 WorkerLoaderProxy* m_loaderProxy;
432 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper; 432 RefPtr<ThreadableWebSocketChannelClientWrapper> m_workerClientWrapper;
433 }; 433 };
434 434
435 void WorkerThreadableWebSocketChannel::Bridge::mainThreadInitialize(ScriptExecut ionContext* context, WorkerLoaderProxy* loaderProxy, PassRefPtr<ThreadableWebSoc ketChannelClientWrapper> prpClientWrapper, const String& taskMode, const String& sourceURL, unsigned lineNumber) 435 void WorkerThreadableWebSocketChannel::Bridge::mainThreadInitialize(ScriptExecut ionContext* context, WorkerLoaderProxy* loaderProxy, PassRefPtr<ThreadableWebSoc ketChannelClientWrapper> prpClientWrapper, const String& taskMode, const String& sourceURL, unsigned lineNumber)
436 { 436 {
437 ASSERT(isMainThread()); 437 ASSERT(isMainThread());
438 ASSERT_UNUSED(context, context->isDocument()); 438 ASSERT_UNUSED(context, context->isDocument());
439 439
440 RefPtr<ThreadableWebSocketChannelClientWrapper> clientWrapper = prpClientWra pper; 440 RefPtr<ThreadableWebSocketChannelClientWrapper> clientWrapper = prpClientWra pper;
441 441
442 Peer* peer = Peer::create(clientWrapper, *loaderProxy, context, taskMode, so urceURL, lineNumber); 442 Peer* peer = Peer::create(clientWrapper, *loaderProxy, context, taskMode, so urceURL, lineNumber);
443 bool sent = loaderProxy->postTaskForModeToWorkerContext( 443 bool sent = loaderProxy->postTaskForModeToWorkerGlobalScope(
444 WorkerThreadableWebSocketChannel::WorkerContextDidInitializeTask::create (peer, loaderProxy, clientWrapper), taskMode); 444 WorkerThreadableWebSocketChannel::WorkerGlobalScopeDidInitializeTask::cr eate(peer, loaderProxy, clientWrapper), taskMode);
445 if (!sent) { 445 if (!sent) {
446 clientWrapper->clearPeer(); 446 clientWrapper->clearPeer();
447 delete peer; 447 delete peer;
448 } 448 }
449 } 449 }
450 450
451 void WorkerThreadableWebSocketChannel::Bridge::initialize(const String& sourceUR L, unsigned lineNumber) 451 void WorkerThreadableWebSocketChannel::Bridge::initialize(const String& sourceUR L, unsigned lineNumber)
452 { 452 {
453 ASSERT(!m_peer); 453 ASSERT(!m_peer);
454 setMethodNotCompleted(); 454 setMethodNotCompleted();
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 } 620 }
621 621
622 void WorkerThreadableWebSocketChannel::Bridge::disconnect() 622 void WorkerThreadableWebSocketChannel::Bridge::disconnect()
623 { 623 {
624 clearClientWrapper(); 624 clearClientWrapper();
625 if (m_peer) { 625 if (m_peer) {
626 OwnPtr<Peer> peer = adoptPtr(m_peer); 626 OwnPtr<Peer> peer = adoptPtr(m_peer);
627 m_peer = 0; 627 m_peer = 0;
628 m_loaderProxy.postTaskToLoader(createCallbackTask(&WorkerThreadableWebSo cketChannel::mainThreadDestroy, peer.release())); 628 m_loaderProxy.postTaskToLoader(createCallbackTask(&WorkerThreadableWebSo cketChannel::mainThreadDestroy, peer.release()));
629 } 629 }
630 m_workerContext = 0; 630 m_workerGlobalScope = 0;
631 } 631 }
632 632
633 void WorkerThreadableWebSocketChannel::mainThreadSuspend(ScriptExecutionContext* context, Peer* peer) 633 void WorkerThreadableWebSocketChannel::mainThreadSuspend(ScriptExecutionContext* context, Peer* peer)
634 { 634 {
635 ASSERT(isMainThread()); 635 ASSERT(isMainThread());
636 ASSERT_UNUSED(context, context->isDocument()); 636 ASSERT_UNUSED(context, context->isDocument());
637 ASSERT(peer); 637 ASSERT(peer);
638 638
639 peer->suspend(); 639 peer->suspend();
640 } 640 }
(...skipping 29 matching lines...) Expand all
670 void WorkerThreadableWebSocketChannel::Bridge::setMethodNotCompleted() 670 void WorkerThreadableWebSocketChannel::Bridge::setMethodNotCompleted()
671 { 671 {
672 ASSERT(m_workerClientWrapper); 672 ASSERT(m_workerClientWrapper);
673 m_workerClientWrapper->clearSyncMethodDone(); 673 m_workerClientWrapper->clearSyncMethodDone();
674 } 674 }
675 675
676 // Caller of this function should hold a reference to the bridge, because this f unction may call WebSocket::didClose() in the end, 676 // Caller of this function should hold a reference to the bridge, because this f unction may call WebSocket::didClose() in the end,
677 // which causes the bridge to get disconnected from the WebSocket and deleted if there is no other reference. 677 // which causes the bridge to get disconnected from the WebSocket and deleted if there is no other reference.
678 void WorkerThreadableWebSocketChannel::Bridge::waitForMethodCompletion() 678 void WorkerThreadableWebSocketChannel::Bridge::waitForMethodCompletion()
679 { 679 {
680 if (!m_workerContext) 680 if (!m_workerGlobalScope)
681 return; 681 return;
682 WorkerRunLoop& runLoop = m_workerContext->thread()->runLoop(); 682 WorkerRunLoop& runLoop = m_workerGlobalScope->thread()->runLoop();
683 MessageQueueWaitResult result = MessageQueueMessageReceived; 683 MessageQueueWaitResult result = MessageQueueMessageReceived;
684 ThreadableWebSocketChannelClientWrapper* clientWrapper = m_workerClientWrapp er.get(); 684 ThreadableWebSocketChannelClientWrapper* clientWrapper = m_workerClientWrapp er.get();
685 while (m_workerContext && clientWrapper && !clientWrapper->syncMethodDone() && result != MessageQueueTerminated) { 685 while (m_workerGlobalScope && clientWrapper && !clientWrapper->syncMethodDon e() && result != MessageQueueTerminated) {
686 result = runLoop.runInMode(m_workerContext.get(), m_taskMode); // May ca use this bridge to get disconnected, which makes m_workerContext become null. 686 result = runLoop.runInMode(m_workerGlobalScope.get(), m_taskMode); // Ma y cause this bridge to get disconnected, which makes m_workerGlobalScope become null.
687 clientWrapper = m_workerClientWrapper.get(); 687 clientWrapper = m_workerClientWrapper.get();
688 } 688 }
689 } 689 }
690 690
691 } // namespace WebCore 691 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/websockets/WorkerThreadableWebSocketChannel.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698