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

Side by Side Diff: third_party/WebKit/Source/modules/websockets/WorkerWebSocketChannel.cpp

Issue 2123703002: Fix worker WebSocket crash caused by dereferencing weak pointer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix Created 4 years, 5 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
« no previous file with comments | « no previous file | 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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 if (m_mainWebSocketChannel) { 263 if (m_mainWebSocketChannel) {
264 m_mainWebSocketChannel->disconnect(); 264 m_mainWebSocketChannel->disconnect();
265 m_mainWebSocketChannel = nullptr; 265 m_mainWebSocketChannel = nullptr;
266 } 266 }
267 m_syncHelper->signalWorkerThread(); 267 m_syncHelper->signalWorkerThread();
268 } 268 }
269 269
270 static void workerGlobalScopeDidConnect(Bridge* bridge, const String& subprotoco l, const String& extensions, ExecutionContext* context) 270 static void workerGlobalScopeDidConnect(Bridge* bridge, const String& subprotoco l, const String& extensions, ExecutionContext* context)
271 { 271 {
272 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); 272 ASSERT_UNUSED(context, context->isWorkerGlobalScope());
273 if (bridge->client()) 273 if (bridge && bridge->client())
274 bridge->client()->didConnect(subprotocol, extensions); 274 bridge->client()->didConnect(subprotocol, extensions);
275 } 275 }
276 276
277 void Peer::didConnect(const String& subprotocol, const String& extensions) 277 void Peer::didConnect(const String& subprotocol, const String& extensions)
278 { 278 {
279 ASSERT(isMainThread()); 279 ASSERT(isMainThread());
280 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob alScopeDidConnect, m_bridge, subprotocol, extensions)); 280 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob alScopeDidConnect, m_bridge, subprotocol, extensions));
281 } 281 }
282 282
283 static void workerGlobalScopeDidReceiveTextMessage(Bridge* bridge, const String& payload, ExecutionContext* context) 283 static void workerGlobalScopeDidReceiveTextMessage(Bridge* bridge, const String& payload, ExecutionContext* context)
284 { 284 {
285 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); 285 ASSERT_UNUSED(context, context->isWorkerGlobalScope());
286 if (bridge->client()) 286 if (bridge && bridge->client())
287 bridge->client()->didReceiveTextMessage(payload); 287 bridge->client()->didReceiveTextMessage(payload);
288 } 288 }
289 289
290 void Peer::didReceiveTextMessage(const String& payload) 290 void Peer::didReceiveTextMessage(const String& payload)
291 { 291 {
292 ASSERT(isMainThread()); 292 ASSERT(isMainThread());
293 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob alScopeDidReceiveTextMessage, m_bridge, payload)); 293 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob alScopeDidReceiveTextMessage, m_bridge, payload));
294 } 294 }
295 295
296 static void workerGlobalScopeDidReceiveBinaryMessage(Bridge* bridge, std::unique _ptr<Vector<char>> payload, ExecutionContext* context) 296 static void workerGlobalScopeDidReceiveBinaryMessage(Bridge* bridge, std::unique _ptr<Vector<char>> payload, ExecutionContext* context)
297 { 297 {
298 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); 298 ASSERT_UNUSED(context, context->isWorkerGlobalScope());
299 if (bridge->client()) 299 if (bridge && bridge->client())
300 bridge->client()->didReceiveBinaryMessage(std::move(payload)); 300 bridge->client()->didReceiveBinaryMessage(std::move(payload));
301 } 301 }
302 302
303 void Peer::didReceiveBinaryMessage(std::unique_ptr<Vector<char>> payload) 303 void Peer::didReceiveBinaryMessage(std::unique_ptr<Vector<char>> payload)
304 { 304 {
305 ASSERT(isMainThread()); 305 ASSERT(isMainThread());
306 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob alScopeDidReceiveBinaryMessage, m_bridge, passed(std::move(payload)))); 306 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob alScopeDidReceiveBinaryMessage, m_bridge, passed(std::move(payload))));
307 } 307 }
308 308
309 static void workerGlobalScopeDidConsumeBufferedAmount(Bridge* bridge, uint64_t c onsumed, ExecutionContext* context) 309 static void workerGlobalScopeDidConsumeBufferedAmount(Bridge* bridge, uint64_t c onsumed, ExecutionContext* context)
310 { 310 {
311 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); 311 ASSERT_UNUSED(context, context->isWorkerGlobalScope());
312 if (bridge->client()) 312 if (bridge && bridge->client())
313 bridge->client()->didConsumeBufferedAmount(consumed); 313 bridge->client()->didConsumeBufferedAmount(consumed);
314 } 314 }
315 315
316 void Peer::didConsumeBufferedAmount(uint64_t consumed) 316 void Peer::didConsumeBufferedAmount(uint64_t consumed)
317 { 317 {
318 ASSERT(isMainThread()); 318 ASSERT(isMainThread());
319 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob alScopeDidConsumeBufferedAmount, m_bridge, consumed)); 319 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob alScopeDidConsumeBufferedAmount, m_bridge, consumed));
320 } 320 }
321 321
322 static void workerGlobalScopeDidStartClosingHandshake(Bridge* bridge, ExecutionC ontext* context) 322 static void workerGlobalScopeDidStartClosingHandshake(Bridge* bridge, ExecutionC ontext* context)
323 { 323 {
324 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); 324 ASSERT_UNUSED(context, context->isWorkerGlobalScope());
325 if (bridge->client()) 325 if (bridge && bridge->client())
326 bridge->client()->didStartClosingHandshake(); 326 bridge->client()->didStartClosingHandshake();
327 } 327 }
328 328
329 void Peer::didStartClosingHandshake() 329 void Peer::didStartClosingHandshake()
330 { 330 {
331 ASSERT(isMainThread()); 331 ASSERT(isMainThread());
332 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob alScopeDidStartClosingHandshake, m_bridge)); 332 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob alScopeDidStartClosingHandshake, m_bridge));
333 } 333 }
334 334
335 static void workerGlobalScopeDidClose(Bridge* bridge, WebSocketChannelClient::Cl osingHandshakeCompletionStatus closingHandshakeCompletion, unsigned short code, const String& reason, ExecutionContext* context) 335 static void workerGlobalScopeDidClose(Bridge* bridge, WebSocketChannelClient::Cl osingHandshakeCompletionStatus closingHandshakeCompletion, unsigned short code, const String& reason, ExecutionContext* context)
336 { 336 {
337 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); 337 ASSERT_UNUSED(context, context->isWorkerGlobalScope());
338 if (bridge->client()) 338 if (bridge && bridge->client())
339 bridge->client()->didClose(closingHandshakeCompletion, code, reason); 339 bridge->client()->didClose(closingHandshakeCompletion, code, reason);
340 } 340 }
341 341
342 void Peer::didClose(ClosingHandshakeCompletionStatus closingHandshakeCompletion, unsigned short code, const String& reason) 342 void Peer::didClose(ClosingHandshakeCompletionStatus closingHandshakeCompletion, unsigned short code, const String& reason)
343 { 343 {
344 ASSERT(isMainThread()); 344 ASSERT(isMainThread());
345 if (m_mainWebSocketChannel) { 345 if (m_mainWebSocketChannel) {
346 m_mainWebSocketChannel->disconnect(); 346 m_mainWebSocketChannel->disconnect();
347 m_mainWebSocketChannel = nullptr; 347 m_mainWebSocketChannel = nullptr;
348 } 348 }
349 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob alScopeDidClose, m_bridge, closingHandshakeCompletion, code, reason)); 349 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob alScopeDidClose, m_bridge, closingHandshakeCompletion, code, reason));
350 } 350 }
351 351
352 static void workerGlobalScopeDidError(Bridge* bridge, ExecutionContext* context) 352 static void workerGlobalScopeDidError(Bridge* bridge, ExecutionContext* context)
353 { 353 {
354 ASSERT_UNUSED(context, context->isWorkerGlobalScope()); 354 ASSERT_UNUSED(context, context->isWorkerGlobalScope());
355 if (bridge->client()) 355 if (bridge && bridge->client())
356 bridge->client()->didError(); 356 bridge->client()->didError();
357 } 357 }
358 358
359 void Peer::didError() 359 void Peer::didError()
360 { 360 {
361 ASSERT(isMainThread()); 361 ASSERT(isMainThread());
362 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob alScopeDidError, m_bridge)); 362 m_loaderProxy->postTaskToWorkerGlobalScope(createCrossThreadTask(&workerGlob alScopeDidError, m_bridge));
363 } 363 }
364 364
365 void Peer::contextDestroyed() 365 void Peer::contextDestroyed()
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 } 499 }
500 500
501 DEFINE_TRACE(Bridge) 501 DEFINE_TRACE(Bridge)
502 { 502 {
503 visitor->trace(m_client); 503 visitor->trace(m_client);
504 visitor->trace(m_workerGlobalScope); 504 visitor->trace(m_workerGlobalScope);
505 visitor->trace(m_syncHelper); 505 visitor->trace(m_syncHelper);
506 } 506 }
507 507
508 } // namespace blink 508 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698