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

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

Issue 242323003: Crash the renderer when WebSocket fails to allocate an ArrayBuffer to set to a MessageEvent. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 6 years, 7 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 | « Source/modules/websockets/WebSocket.cpp ('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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "core/inspector/ScriptCallStack.h" 43 #include "core/inspector/ScriptCallStack.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/NewWebSocketChannelImpl.h" 48 #include "modules/websockets/NewWebSocketChannelImpl.h"
49 #include "modules/websockets/ThreadableWebSocketChannelClientWrapper.h" 49 #include "modules/websockets/ThreadableWebSocketChannelClientWrapper.h"
50 #include "public/platform/Platform.h" 50 #include "public/platform/Platform.h"
51 #include "public/platform/WebWaitableEvent.h" 51 #include "public/platform/WebWaitableEvent.h"
52 #include "wtf/ArrayBuffer.h" 52 #include "wtf/ArrayBuffer.h"
53 #include "wtf/Assertions.h"
53 #include "wtf/Functional.h" 54 #include "wtf/Functional.h"
54 #include "wtf/MainThread.h" 55 #include "wtf/MainThread.h"
55 56
56 namespace WebCore { 57 namespace WebCore {
57 58
58 // Created and destroyed on the worker thread. All setters of this class are 59 // Created and destroyed on the worker thread. All setters of this class are
59 // called on the main thread, while all getters are called on the worker 60 // called on the main thread, while all getters are called on the worker
60 // thread. signalWorkerThread() must be called before any getters are called. 61 // thread. signalWorkerThread() must be called before any getters are called.
61 class ThreadableWebSocketChannelSyncHelper { 62 class ThreadableWebSocketChannelSyncHelper {
62 public: 63 public:
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 m_syncHelper->signalWorkerThread(); 299 m_syncHelper->signalWorkerThread();
299 } 300 }
300 301
301 void WorkerThreadableWebSocketChannel::Peer::sendArrayBuffer(PassOwnPtr<Vector<c har> > data) 302 void WorkerThreadableWebSocketChannel::Peer::sendArrayBuffer(PassOwnPtr<Vector<c har> > data)
302 { 303 {
303 ASSERT(isMainThread()); 304 ASSERT(isMainThread());
304 if (!m_mainWebSocketChannel) { 305 if (!m_mainWebSocketChannel) {
305 m_syncHelper->setSendRequestResult(WebSocketChannel::SendFail); 306 m_syncHelper->setSendRequestResult(WebSocketChannel::SendFail);
306 } else { 307 } else {
307 RefPtr<ArrayBuffer> binaryData = ArrayBuffer::create(data->data(), data- >size()); 308 RefPtr<ArrayBuffer> binaryData = ArrayBuffer::create(data->data(), data- >size());
309 if (!binaryData) {
310 // Failed to allocate an ArrayBuffer. We need to crash the renderer
311 // since there's no way defined in the spec to tell this to the
312 // user.
313 CRASH();
314 }
308 WebSocketChannel::SendResult sendRequestResult = m_mainWebSocketChannel- >send(*binaryData, 0, binaryData->byteLength()); 315 WebSocketChannel::SendResult sendRequestResult = m_mainWebSocketChannel- >send(*binaryData, 0, binaryData->byteLength());
309 m_syncHelper->setSendRequestResult(sendRequestResult); 316 m_syncHelper->setSendRequestResult(sendRequestResult);
310 } 317 }
311 m_syncHelper->signalWorkerThread(); 318 m_syncHelper->signalWorkerThread();
312 } 319 }
313 320
314 void WorkerThreadableWebSocketChannel::Peer::sendBlob(PassRefPtr<BlobDataHandle> blobData) 321 void WorkerThreadableWebSocketChannel::Peer::sendBlob(PassRefPtr<BlobDataHandle> blobData)
315 { 322 {
316 ASSERT(isMainThread()); 323 ASSERT(isMainThread());
317 if (!m_mainWebSocketChannel) { 324 if (!m_mainWebSocketChannel) {
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 } 610 }
604 611
605 void WorkerThreadableWebSocketChannel::Bridge::terminatePeer() 612 void WorkerThreadableWebSocketChannel::Bridge::terminatePeer()
606 { 613 {
607 m_loaderProxy.postTaskToLoader(CallClosureTask::create(bind(&Peer::destroy, m_peer))); 614 m_loaderProxy.postTaskToLoader(CallClosureTask::create(bind(&Peer::destroy, m_peer)));
608 m_workerGlobalScope = nullptr; 615 m_workerGlobalScope = nullptr;
609 m_syncHelper = 0; 616 m_syncHelper = 0;
610 } 617 }
611 618
612 } // namespace WebCore 619 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/modules/websockets/WebSocket.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698