OLD | NEW |
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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 m_bridge->suspend(); | 220 m_bridge->suspend(); |
221 } | 221 } |
222 | 222 |
223 void WorkerThreadableWebSocketChannel::resume() | 223 void WorkerThreadableWebSocketChannel::resume() |
224 { | 224 { |
225 m_workerClientWrapper->resume(); | 225 m_workerClientWrapper->resume(); |
226 if (m_bridge) | 226 if (m_bridge) |
227 m_bridge->resume(); | 227 m_bridge->resume(); |
228 } | 228 } |
229 | 229 |
230 WorkerThreadableWebSocketChannel::Peer::Peer(PassRefPtr<WeakReference<Peer> > re
ference, PassRefPtr<ThreadableWebSocketChannelClientWrapper> clientWrapper, Work
erLoaderProxy& loaderProxy, ExecutionContext* context, const String& sourceURL,
unsigned lineNumber, PassOwnPtr<ThreadableWebSocketChannelSyncHelper> syncHelper
) | 230 void WorkerThreadableWebSocketChannel::trace(Visitor* visitor) |
| 231 { |
| 232 visitor->trace(m_workerClientWrapper); |
| 233 } |
| 234 |
| 235 WorkerThreadableWebSocketChannel::Peer::Peer(PassRefPtr<WeakReference<Peer> > re
ference, PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper> clientW
rapper, WorkerLoaderProxy& loaderProxy, ExecutionContext* context, const String&
sourceURL, unsigned lineNumber, PassOwnPtr<ThreadableWebSocketChannelSyncHelper
> syncHelper) |
231 : m_workerClientWrapper(clientWrapper) | 236 : m_workerClientWrapper(clientWrapper) |
232 , m_loaderProxy(loaderProxy) | 237 , m_loaderProxy(loaderProxy) |
233 , m_mainWebSocketChannel(nullptr) | 238 , m_mainWebSocketChannel(nullptr) |
234 , m_syncHelper(syncHelper) | 239 , m_syncHelper(syncHelper) |
235 , m_weakFactory(reference, this) | 240 , m_weakFactory(reference, this) |
236 { | 241 { |
237 ASSERT(isMainThread()); | 242 ASSERT(isMainThread()); |
238 ASSERT(m_workerClientWrapper.get()); | 243 ASSERT(m_workerClientWrapper.get()); |
239 | 244 |
240 Document* document = toDocument(context); | 245 Document* document = toDocument(context); |
241 if (RuntimeEnabledFeatures::experimentalWebSocketEnabled()) { | 246 if (RuntimeEnabledFeatures::experimentalWebSocketEnabled()) { |
242 m_mainWebSocketChannel = NewWebSocketChannelImpl::create(document, this,
sourceURL, lineNumber); | 247 m_mainWebSocketChannel = NewWebSocketChannelImpl::create(document, this,
sourceURL, lineNumber); |
243 } else { | 248 } else { |
244 m_mainWebSocketChannel = MainThreadWebSocketChannel::create(document, th
is, sourceURL, lineNumber); | 249 m_mainWebSocketChannel = MainThreadWebSocketChannel::create(document, th
is, sourceURL, lineNumber); |
245 } | 250 } |
246 | 251 |
247 m_syncHelper->signalWorkerThread(); | 252 m_syncHelper->signalWorkerThread(); |
248 } | 253 } |
249 | 254 |
250 WorkerThreadableWebSocketChannel::Peer::~Peer() | 255 WorkerThreadableWebSocketChannel::Peer::~Peer() |
251 { | 256 { |
252 ASSERT(isMainThread()); | 257 ASSERT(isMainThread()); |
253 if (m_mainWebSocketChannel) | 258 if (m_mainWebSocketChannel) |
254 m_mainWebSocketChannel->disconnect(); | 259 m_mainWebSocketChannel->disconnect(); |
255 } | 260 } |
256 | 261 |
257 void WorkerThreadableWebSocketChannel::Peer::initialize(ExecutionContext* contex
t, PassRefPtr<WeakReference<Peer> > reference, WorkerLoaderProxy* loaderProxy, P
assRefPtr<ThreadableWebSocketChannelClientWrapper> clientWrapper, const String&
sourceURLAtConnection, unsigned lineNumberAtConnection, PassOwnPtr<ThreadableWeb
SocketChannelSyncHelper> syncHelper) | 262 void WorkerThreadableWebSocketChannel::Peer::initialize(ExecutionContext* contex
t, PassRefPtr<WeakReference<Peer> > reference, WorkerLoaderProxy* loaderProxy, P
assRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper> clientWrapper, co
nst String& sourceURLAtConnection, unsigned lineNumberAtConnection, PassOwnPtr<T
hreadableWebSocketChannelSyncHelper> syncHelper) |
258 { | 263 { |
259 // The caller must call destroy() to free the peer. | 264 // The caller must call destroy() to free the peer. |
260 new Peer(reference, clientWrapper, *loaderProxy, context, sourceURLAtConnect
ion, lineNumberAtConnection, syncHelper); | 265 new Peer(reference, clientWrapper, *loaderProxy, context, sourceURLAtConnect
ion, lineNumberAtConnection, syncHelper); |
261 } | 266 } |
262 | 267 |
263 void WorkerThreadableWebSocketChannel::Peer::destroy() | 268 void WorkerThreadableWebSocketChannel::Peer::destroy() |
264 { | 269 { |
265 ASSERT(isMainThread()); | 270 ASSERT(isMainThread()); |
266 delete this; | 271 delete this; |
267 } | 272 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 } | 366 } |
362 | 367 |
363 void WorkerThreadableWebSocketChannel::Peer::resume() | 368 void WorkerThreadableWebSocketChannel::Peer::resume() |
364 { | 369 { |
365 ASSERT(isMainThread()); | 370 ASSERT(isMainThread()); |
366 if (!m_mainWebSocketChannel) | 371 if (!m_mainWebSocketChannel) |
367 return; | 372 return; |
368 m_mainWebSocketChannel->resume(); | 373 m_mainWebSocketChannel->resume(); |
369 } | 374 } |
370 | 375 |
371 static void workerGlobalScopeDidConnect(ExecutionContext* context, PassRefPtr<Th
readableWebSocketChannelClientWrapper> workerClientWrapper, const String& subpro
tocol, const String& extensions) | 376 static void workerGlobalScopeDidConnect(ExecutionContext* context, PassRefPtrWil
lBeRawPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, const St
ring& subprotocol, const String& extensions) |
372 { | 377 { |
373 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 378 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
374 workerClientWrapper->setSubprotocol(subprotocol); | 379 workerClientWrapper->setSubprotocol(subprotocol); |
375 workerClientWrapper->setExtensions(extensions); | 380 workerClientWrapper->setExtensions(extensions); |
376 workerClientWrapper->didConnect(); | 381 workerClientWrapper->didConnect(); |
377 } | 382 } |
378 | 383 |
379 void WorkerThreadableWebSocketChannel::Peer::didConnect() | 384 void WorkerThreadableWebSocketChannel::Peer::didConnect() |
380 { | 385 { |
381 ASSERT(isMainThread()); | 386 ASSERT(isMainThread()); |
382 m_loaderProxy.postTaskToWorkerGlobalScope(createCallbackTask(&workerGlobalSc
opeDidConnect, m_workerClientWrapper, m_mainWebSocketChannel->subprotocol(), m_m
ainWebSocketChannel->extensions())); | 387 m_loaderProxy.postTaskToWorkerGlobalScope(createCallbackTask(&workerGlobalSc
opeDidConnect, m_workerClientWrapper, m_mainWebSocketChannel->subprotocol(), m_m
ainWebSocketChannel->extensions())); |
383 } | 388 } |
384 | 389 |
385 static void workerGlobalScopeDidReceiveMessage(ExecutionContext* context, PassRe
fPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, const String&
message) | 390 static void workerGlobalScopeDidReceiveMessage(ExecutionContext* context, PassRe
fPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, c
onst String& message) |
386 { | 391 { |
387 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 392 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
388 workerClientWrapper->didReceiveMessage(message); | 393 workerClientWrapper->didReceiveMessage(message); |
389 } | 394 } |
390 | 395 |
391 void WorkerThreadableWebSocketChannel::Peer::didReceiveMessage(const String& mes
sage) | 396 void WorkerThreadableWebSocketChannel::Peer::didReceiveMessage(const String& mes
sage) |
392 { | 397 { |
393 ASSERT(isMainThread()); | 398 ASSERT(isMainThread()); |
394 m_loaderProxy.postTaskToWorkerGlobalScope(createCallbackTask(&workerGlobalSc
opeDidReceiveMessage, m_workerClientWrapper, message)); | 399 m_loaderProxy.postTaskToWorkerGlobalScope(createCallbackTask(&workerGlobalSc
opeDidReceiveMessage, m_workerClientWrapper, message)); |
395 } | 400 } |
396 | 401 |
397 static void workerGlobalScopeDidReceiveBinaryData(ExecutionContext* context, Pas
sRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, PassOwnPtr
<Vector<char> > binaryData) | 402 static void workerGlobalScopeDidReceiveBinaryData(ExecutionContext* context, Pas
sRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper
, PassOwnPtr<Vector<char> > binaryData) |
398 { | 403 { |
399 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 404 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
400 workerClientWrapper->didReceiveBinaryData(binaryData); | 405 workerClientWrapper->didReceiveBinaryData(binaryData); |
401 } | 406 } |
402 | 407 |
403 void WorkerThreadableWebSocketChannel::Peer::didReceiveBinaryData(PassOwnPtr<Vec
tor<char> > binaryData) | 408 void WorkerThreadableWebSocketChannel::Peer::didReceiveBinaryData(PassOwnPtr<Vec
tor<char> > binaryData) |
404 { | 409 { |
405 ASSERT(isMainThread()); | 410 ASSERT(isMainThread()); |
406 m_loaderProxy.postTaskToWorkerGlobalScope(createCallbackTask(&workerGlobalSc
opeDidReceiveBinaryData, m_workerClientWrapper, binaryData)); | 411 m_loaderProxy.postTaskToWorkerGlobalScope(createCallbackTask(&workerGlobalSc
opeDidReceiveBinaryData, m_workerClientWrapper, binaryData)); |
407 } | 412 } |
408 | 413 |
409 static void workerGlobalScopeDidUpdateBufferedAmount(ExecutionContext* context,
PassRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, unsigne
d long bufferedAmount) | 414 static void workerGlobalScopeDidUpdateBufferedAmount(ExecutionContext* context,
PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrap
per, unsigned long bufferedAmount) |
410 { | 415 { |
411 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 416 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
412 workerClientWrapper->didUpdateBufferedAmount(bufferedAmount); | 417 workerClientWrapper->didUpdateBufferedAmount(bufferedAmount); |
413 } | 418 } |
414 | 419 |
415 void WorkerThreadableWebSocketChannel::Peer::didUpdateBufferedAmount(unsigned lo
ng bufferedAmount) | 420 void WorkerThreadableWebSocketChannel::Peer::didUpdateBufferedAmount(unsigned lo
ng bufferedAmount) |
416 { | 421 { |
417 ASSERT(isMainThread()); | 422 ASSERT(isMainThread()); |
418 m_loaderProxy.postTaskToWorkerGlobalScope(createCallbackTask(&workerGlobalSc
opeDidUpdateBufferedAmount, m_workerClientWrapper, bufferedAmount)); | 423 m_loaderProxy.postTaskToWorkerGlobalScope(createCallbackTask(&workerGlobalSc
opeDidUpdateBufferedAmount, m_workerClientWrapper, bufferedAmount)); |
419 } | 424 } |
420 | 425 |
421 static void workerGlobalScopeDidStartClosingHandshake(ExecutionContext* context,
PassRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper) | 426 static void workerGlobalScopeDidStartClosingHandshake(ExecutionContext* context,
PassRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper> workerClientWra
pper) |
422 { | 427 { |
423 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 428 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
424 workerClientWrapper->didStartClosingHandshake(); | 429 workerClientWrapper->didStartClosingHandshake(); |
425 } | 430 } |
426 | 431 |
427 void WorkerThreadableWebSocketChannel::Peer::didStartClosingHandshake() | 432 void WorkerThreadableWebSocketChannel::Peer::didStartClosingHandshake() |
428 { | 433 { |
429 ASSERT(isMainThread()); | 434 ASSERT(isMainThread()); |
430 m_loaderProxy.postTaskToWorkerGlobalScope(createCallbackTask(&workerGlobalSc
opeDidStartClosingHandshake, m_workerClientWrapper)); | 435 m_loaderProxy.postTaskToWorkerGlobalScope(createCallbackTask(&workerGlobalSc
opeDidStartClosingHandshake, m_workerClientWrapper)); |
431 } | 436 } |
432 | 437 |
433 static void workerGlobalScopeDidClose(ExecutionContext* context, PassRefPtr<Thre
adableWebSocketChannelClientWrapper> workerClientWrapper, unsigned long unhandle
dBufferedAmount, WebSocketChannelClient::ClosingHandshakeCompletionStatus closin
gHandshakeCompletion, unsigned short code, const String& reason) | 438 static void workerGlobalScopeDidClose(ExecutionContext* context, PassRefPtrWillB
eRawPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper, unsigned l
ong unhandledBufferedAmount, WebSocketChannelClient::ClosingHandshakeCompletionS
tatus closingHandshakeCompletion, unsigned short code, const String& reason) |
434 { | 439 { |
435 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 440 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
436 workerClientWrapper->didClose(unhandledBufferedAmount, closingHandshakeCompl
etion, code, reason); | 441 workerClientWrapper->didClose(unhandledBufferedAmount, closingHandshakeCompl
etion, code, reason); |
437 } | 442 } |
438 | 443 |
439 void WorkerThreadableWebSocketChannel::Peer::didClose(unsigned long unhandledBuf
feredAmount, ClosingHandshakeCompletionStatus closingHandshakeCompletion, unsign
ed short code, const String& reason) | 444 void WorkerThreadableWebSocketChannel::Peer::didClose(unsigned long unhandledBuf
feredAmount, ClosingHandshakeCompletionStatus closingHandshakeCompletion, unsign
ed short code, const String& reason) |
440 { | 445 { |
441 ASSERT(isMainThread()); | 446 ASSERT(isMainThread()); |
442 m_mainWebSocketChannel = nullptr; | 447 m_mainWebSocketChannel = nullptr; |
443 m_loaderProxy.postTaskToWorkerGlobalScope(createCallbackTask(&workerGlobalSc
opeDidClose, m_workerClientWrapper, unhandledBufferedAmount, closingHandshakeCom
pletion, code, reason)); | 448 m_loaderProxy.postTaskToWorkerGlobalScope(createCallbackTask(&workerGlobalSc
opeDidClose, m_workerClientWrapper, unhandledBufferedAmount, closingHandshakeCom
pletion, code, reason)); |
444 } | 449 } |
445 | 450 |
446 static void workerGlobalScopeDidReceiveMessageError(ExecutionContext* context, P
assRefPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapper) | 451 static void workerGlobalScopeDidReceiveMessageError(ExecutionContext* context, P
assRefPtrWillBeRawPtr<ThreadableWebSocketChannelClientWrapper> workerClientWrapp
er) |
447 { | 452 { |
448 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); | 453 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); |
449 workerClientWrapper->didReceiveMessageError(); | 454 workerClientWrapper->didReceiveMessageError(); |
450 } | 455 } |
451 | 456 |
452 void WorkerThreadableWebSocketChannel::Peer::didReceiveMessageError() | 457 void WorkerThreadableWebSocketChannel::Peer::didReceiveMessageError() |
453 { | 458 { |
454 ASSERT(isMainThread()); | 459 ASSERT(isMainThread()); |
455 m_loaderProxy.postTaskToWorkerGlobalScope(createCallbackTask(&workerGlobalSc
opeDidReceiveMessageError, m_workerClientWrapper)); | 460 m_loaderProxy.postTaskToWorkerGlobalScope(createCallbackTask(&workerGlobalSc
opeDidReceiveMessageError, m_workerClientWrapper)); |
456 } | 461 } |
457 | 462 |
458 WorkerThreadableWebSocketChannel::Bridge::Bridge(PassRefPtr<ThreadableWebSocketC
hannelClientWrapper> workerClientWrapper, WorkerGlobalScope& workerGlobalScope) | 463 WorkerThreadableWebSocketChannel::Bridge::Bridge(PassRefPtrWillBeRawPtr<Threadab
leWebSocketChannelClientWrapper> workerClientWrapper, WorkerGlobalScope& workerG
lobalScope) |
459 : m_workerClientWrapper(workerClientWrapper) | 464 : m_workerClientWrapper(workerClientWrapper) |
460 , m_workerGlobalScope(workerGlobalScope) | 465 , m_workerGlobalScope(workerGlobalScope) |
461 , m_loaderProxy(m_workerGlobalScope->thread()->workerLoaderProxy()) | 466 , m_loaderProxy(m_workerGlobalScope->thread()->workerLoaderProxy()) |
462 , m_syncHelper(0) | 467 , m_syncHelper(0) |
463 { | 468 { |
464 ASSERT(m_workerClientWrapper.get()); | 469 ASSERT(m_workerClientWrapper.get()); |
465 } | 470 } |
466 | 471 |
467 WorkerThreadableWebSocketChannel::Bridge::~Bridge() | 472 WorkerThreadableWebSocketChannel::Bridge::~Bridge() |
468 { | 473 { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 m_loaderProxy.postTaskToLoader(CallClosureTask::create(bind(&Peer::destroy,
m_peer))); | 622 m_loaderProxy.postTaskToLoader(CallClosureTask::create(bind(&Peer::destroy,
m_peer))); |
618 // Peer::destroy() deletes m_peer and then m_syncHelper will be released. | 623 // Peer::destroy() deletes m_peer and then m_syncHelper will be released. |
619 // We must not touch m_syncHelper any more. | 624 // We must not touch m_syncHelper any more. |
620 m_syncHelper = 0; | 625 m_syncHelper = 0; |
621 | 626 |
622 // We won't use this any more. | 627 // We won't use this any more. |
623 m_workerGlobalScope = nullptr; | 628 m_workerGlobalScope = nullptr; |
624 } | 629 } |
625 | 630 |
626 } // namespace WebCore | 631 } // namespace WebCore |
OLD | NEW |