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

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

Issue 1878463002: Move DOMArrayBuffer, DOMArrayBufferViews and DataView to the heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tidy Created 4 years, 8 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 DEFINE_INLINE_TRACE() 76 DEFINE_INLINE_TRACE()
77 { 77 {
78 visitor->trace(m_channel); 78 visitor->trace(m_channel);
79 } 79 }
80 80
81 private: 81 private:
82 Member<DocumentWebSocketChannel> m_channel; 82 Member<DocumentWebSocketChannel> m_channel;
83 FileReaderLoader m_loader; 83 FileReaderLoader m_loader;
84 }; 84 };
85 85
86 class DocumentWebSocketChannel::Message : public GarbageCollectedFinalized<Docum entWebSocketChannel::Message> {
87 public:
88 explicit Message(const CString&);
89 explicit Message(PassRefPtr<BlobDataHandle>);
90 explicit Message(DOMArrayBuffer*);
91 // For WorkerWebSocketChannel
92 explicit Message(PassOwnPtr<Vector<char>>, MessageType);
93 // Close message
94 Message(unsigned short code, const String& reason);
95
96 DEFINE_INLINE_TRACE()
97 {
98 visitor->trace(arrayBuffer);
99 }
100
101 MessageType type;
102
103 CString text;
104 RefPtr<BlobDataHandle> blobDataHandle;
105 Member<DOMArrayBuffer> arrayBuffer;
106 OwnPtr<Vector<char>> vectorData;
107 unsigned short code;
108 String reason;
109 };
110
86 DocumentWebSocketChannel::BlobLoader::BlobLoader(PassRefPtr<BlobDataHandle> blob DataHandle, DocumentWebSocketChannel* channel) 111 DocumentWebSocketChannel::BlobLoader::BlobLoader(PassRefPtr<BlobDataHandle> blob DataHandle, DocumentWebSocketChannel* channel)
87 : m_channel(channel) 112 : m_channel(channel)
88 , m_loader(FileReaderLoader::ReadAsArrayBuffer, this) 113 , m_loader(FileReaderLoader::ReadAsArrayBuffer, this)
89 { 114 {
90 m_loader.start(channel->getExecutionContext(), blobDataHandle); 115 m_loader.start(channel->getExecutionContext(), blobDataHandle);
91 } 116 }
92 117
93 void DocumentWebSocketChannel::BlobLoader::cancel() 118 void DocumentWebSocketChannel::BlobLoader::cancel()
94 { 119 {
95 m_loader.cancel(); 120 m_loader.cancel();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 InspectorInstrumentation::didCreateWebSocket(document(), m_identifier, url, protocol); 190 InspectorInstrumentation::didCreateWebSocket(document(), m_identifier, url, protocol);
166 return true; 191 return true;
167 } 192 }
168 193
169 void DocumentWebSocketChannel::send(const CString& message) 194 void DocumentWebSocketChannel::send(const CString& message)
170 { 195 {
171 WTF_LOG(Network, "DocumentWebSocketChannel %p sendText(%s)", this, message.d ata()); 196 WTF_LOG(Network, "DocumentWebSocketChannel %p sendText(%s)", this, message.d ata());
172 // FIXME: Change the inspector API to show the entire message instead 197 // FIXME: Change the inspector API to show the entire message instead
173 // of individual frames. 198 // of individual frames.
174 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier, We bSocketFrame::OpCodeText, true, message.data(), message.length()); 199 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier, We bSocketFrame::OpCodeText, true, message.data(), message.length());
175 m_messages.append(adoptPtr(new Message(message))); 200 m_messages.append(new Message(message));
176 processSendQueue(); 201 processSendQueue();
177 } 202 }
178 203
179 void DocumentWebSocketChannel::send(PassRefPtr<BlobDataHandle> blobDataHandle) 204 void DocumentWebSocketChannel::send(PassRefPtr<BlobDataHandle> blobDataHandle)
180 { 205 {
181 WTF_LOG(Network, "DocumentWebSocketChannel %p sendBlob(%s, %s, %llu)", this, blobDataHandle->uuid().utf8().data(), blobDataHandle->type().utf8().data(), blo bDataHandle->size()); 206 WTF_LOG(Network, "DocumentWebSocketChannel %p sendBlob(%s, %s, %llu)", this, blobDataHandle->uuid().utf8().data(), blobDataHandle->type().utf8().data(), blo bDataHandle->size());
182 // FIXME: Change the inspector API to show the entire message instead 207 // FIXME: Change the inspector API to show the entire message instead
183 // of individual frames. 208 // of individual frames.
184 // FIXME: We can't access the data here. 209 // FIXME: We can't access the data here.
185 // Since Binary data are not displayed in Inspector, this does not 210 // Since Binary data are not displayed in Inspector, this does not
186 // affect actual behavior. 211 // affect actual behavior.
187 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier, We bSocketFrame::OpCodeBinary, true, "", 0); 212 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier, We bSocketFrame::OpCodeBinary, true, "", 0);
188 m_messages.append(adoptPtr(new Message(blobDataHandle))); 213 m_messages.append(new Message(blobDataHandle));
189 processSendQueue(); 214 processSendQueue();
190 } 215 }
191 216
192 void DocumentWebSocketChannel::send(const DOMArrayBuffer& buffer, unsigned byteO ffset, unsigned byteLength) 217 void DocumentWebSocketChannel::send(const DOMArrayBuffer& buffer, unsigned byteO ffset, unsigned byteLength)
193 { 218 {
194 WTF_LOG(Network, "DocumentWebSocketChannel %p sendArrayBuffer(%p, %u, %u)", this, buffer.data(), byteOffset, byteLength); 219 WTF_LOG(Network, "DocumentWebSocketChannel %p sendArrayBuffer(%p, %u, %u)", this, buffer.data(), byteOffset, byteLength);
195 // FIXME: Change the inspector API to show the entire message instead 220 // FIXME: Change the inspector API to show the entire message instead
196 // of individual frames. 221 // of individual frames.
197 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier, We bSocketFrame::OpCodeBinary, true, static_cast<const char*>(buffer.data()) + byte Offset, byteLength); 222 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier, We bSocketFrame::OpCodeBinary, true, static_cast<const char*>(buffer.data()) + byte Offset, byteLength);
198 // buffer.slice copies its contents. 223 // buffer.slice copies its contents.
199 // FIXME: Reduce copy by sending the data immediately when we don't need to 224 // FIXME: Reduce copy by sending the data immediately when we don't need to
200 // queue the data. 225 // queue the data.
201 m_messages.append(adoptPtr(new Message(buffer.slice(byteOffset, byteOffset + byteLength)))); 226 m_messages.append(new Message(buffer.slice(byteOffset, byteOffset + byteLeng th)));
202 processSendQueue(); 227 processSendQueue();
203 } 228 }
204 229
205 void DocumentWebSocketChannel::sendTextAsCharVector(PassOwnPtr<Vector<char>> dat a) 230 void DocumentWebSocketChannel::sendTextAsCharVector(PassOwnPtr<Vector<char>> dat a)
206 { 231 {
207 WTF_LOG(Network, "DocumentWebSocketChannel %p sendTextAsCharVector(%p, %llu) ", this, data.get(), static_cast<unsigned long long>(data->size())); 232 WTF_LOG(Network, "DocumentWebSocketChannel %p sendTextAsCharVector(%p, %llu) ", this, data.get(), static_cast<unsigned long long>(data->size()));
208 // FIXME: Change the inspector API to show the entire message instead 233 // FIXME: Change the inspector API to show the entire message instead
209 // of individual frames. 234 // of individual frames.
210 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier, We bSocketFrame::OpCodeText, true, data->data(), data->size()); 235 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier, We bSocketFrame::OpCodeText, true, data->data(), data->size());
211 m_messages.append(adoptPtr(new Message(data, MessageTypeTextAsCharVector))); 236 m_messages.append(new Message(data, MessageTypeTextAsCharVector));
212 processSendQueue(); 237 processSendQueue();
213 } 238 }
214 239
215 void DocumentWebSocketChannel::sendBinaryAsCharVector(PassOwnPtr<Vector<char>> d ata) 240 void DocumentWebSocketChannel::sendBinaryAsCharVector(PassOwnPtr<Vector<char>> d ata)
216 { 241 {
217 WTF_LOG(Network, "DocumentWebSocketChannel %p sendBinaryAsCharVector(%p, %ll u)", this, data.get(), static_cast<unsigned long long>(data->size())); 242 WTF_LOG(Network, "DocumentWebSocketChannel %p sendBinaryAsCharVector(%p, %ll u)", this, data.get(), static_cast<unsigned long long>(data->size()));
218 // FIXME: Change the inspector API to show the entire message instead 243 // FIXME: Change the inspector API to show the entire message instead
219 // of individual frames. 244 // of individual frames.
220 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier, We bSocketFrame::OpCodeBinary, true, data->data(), data->size()); 245 InspectorInstrumentation::didSendWebSocketFrame(document(), m_identifier, We bSocketFrame::OpCodeBinary, true, data->data(), data->size());
221 m_messages.append(adoptPtr(new Message(data, MessageTypeBinaryAsCharVector)) ); 246 m_messages.append(new Message(data, MessageTypeBinaryAsCharVector));
222 processSendQueue(); 247 processSendQueue();
223 } 248 }
224 249
225 void DocumentWebSocketChannel::close(int code, const String& reason) 250 void DocumentWebSocketChannel::close(int code, const String& reason)
226 { 251 {
227 WTF_LOG(Network, "DocumentWebSocketChannel %p close(%d, %s)", this, code, re ason.utf8().data()); 252 WTF_LOG(Network, "DocumentWebSocketChannel %p close(%d, %s)", this, code, re ason.utf8().data());
228 ASSERT(m_handle); 253 ASSERT(m_handle);
229 unsigned short codeToSend = static_cast<unsigned short>(code == CloseEventCo deNotSpecified ? CloseEventCodeNoStatusRcvd : code); 254 unsigned short codeToSend = static_cast<unsigned short>(code == CloseEventCo deNotSpecified ? CloseEventCodeNoStatusRcvd : code);
230 m_messages.append(adoptPtr(new Message(codeToSend, reason))); 255 m_messages.append(new Message(codeToSend, reason));
231 processSendQueue(); 256 processSendQueue();
232 } 257 }
233 258
234 void DocumentWebSocketChannel::fail(const String& reason, MessageLevel level, co nst String& sourceURL, unsigned lineNumber) 259 void DocumentWebSocketChannel::fail(const String& reason, MessageLevel level, co nst String& sourceURL, unsigned lineNumber)
235 { 260 {
236 WTF_LOG(Network, "DocumentWebSocketChannel %p fail(%s)", this, reason.utf8() .data()); 261 WTF_LOG(Network, "DocumentWebSocketChannel %p fail(%s)", this, reason.utf8() .data());
237 // m_handle and m_client can be null here. 262 // m_handle and m_client can be null here.
238 263
239 InspectorInstrumentation::didReceiveWebSocketFrameError(document(), m_identi fier, reason); 264 InspectorInstrumentation::didReceiveWebSocketFrameError(document(), m_identi fier, reason);
240 const String message = "WebSocket connection to '" + m_url.elidedString() + "' failed: " + reason; 265 const String message = "WebSocket connection to '" + m_url.elidedString() + "' failed: " + reason;
(...skipping 21 matching lines...) Expand all
262 } 287 }
263 288
264 DocumentWebSocketChannel::Message::Message(const CString& text) 289 DocumentWebSocketChannel::Message::Message(const CString& text)
265 : type(MessageTypeText) 290 : type(MessageTypeText)
266 , text(text) { } 291 , text(text) { }
267 292
268 DocumentWebSocketChannel::Message::Message(PassRefPtr<BlobDataHandle> blobDataHa ndle) 293 DocumentWebSocketChannel::Message::Message(PassRefPtr<BlobDataHandle> blobDataHa ndle)
269 : type(MessageTypeBlob) 294 : type(MessageTypeBlob)
270 , blobDataHandle(blobDataHandle) { } 295 , blobDataHandle(blobDataHandle) { }
271 296
272 DocumentWebSocketChannel::Message::Message(PassRefPtr<DOMArrayBuffer> arrayBuffe r) 297 DocumentWebSocketChannel::Message::Message(DOMArrayBuffer* arrayBuffer)
273 : type(MessageTypeArrayBuffer) 298 : type(MessageTypeArrayBuffer)
274 , arrayBuffer(arrayBuffer) { } 299 , arrayBuffer(arrayBuffer) { }
275 300
276 DocumentWebSocketChannel::Message::Message(PassOwnPtr<Vector<char>> vectorData, MessageType type) 301 DocumentWebSocketChannel::Message::Message(PassOwnPtr<Vector<char>> vectorData, MessageType type)
277 : type(type) 302 : type(type)
278 , vectorData(vectorData) 303 , vectorData(vectorData)
279 { 304 {
280 ASSERT(type == MessageTypeTextAsCharVector || type == MessageTypeBinaryAsCha rVector); 305 ASSERT(type == MessageTypeTextAsCharVector || type == MessageTypeBinaryAsCha rVector);
281 } 306 }
282 307
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 { 547 {
523 WTF_LOG(Network, "DocumentWebSocketChannel %p didStartClosingHandshake(%p)", this, handle); 548 WTF_LOG(Network, "DocumentWebSocketChannel %p didStartClosingHandshake(%p)", this, handle);
524 549
525 ASSERT(m_handle); 550 ASSERT(m_handle);
526 ASSERT(handle == m_handle); 551 ASSERT(handle == m_handle);
527 552
528 if (m_client) 553 if (m_client)
529 m_client->didStartClosingHandshake(); 554 m_client->didStartClosingHandshake();
530 } 555 }
531 556
532 void DocumentWebSocketChannel::didFinishLoadingBlob(PassRefPtr<DOMArrayBuffer> b uffer) 557 void DocumentWebSocketChannel::didFinishLoadingBlob(DOMArrayBuffer* buffer)
533 { 558 {
534 m_blobLoader.clear(); 559 m_blobLoader.clear();
535 ASSERT(m_handle); 560 ASSERT(m_handle);
536 // The loaded blob is always placed on m_messages[0]. 561 // The loaded blob is always placed on m_messages[0].
537 ASSERT(m_messages.size() > 0 && m_messages.first()->type == MessageTypeBlob) ; 562 ASSERT(m_messages.size() > 0 && m_messages.first()->type == MessageTypeBlob) ;
538 // We replace it with the loaded blob. 563 // We replace it with the loaded blob.
539 m_messages.first() = adoptPtr(new Message(buffer)); 564 m_messages.first() = new Message(buffer);
540 processSendQueue(); 565 processSendQueue();
541 } 566 }
542 567
543 void DocumentWebSocketChannel::didFailLoadingBlob(FileError::ErrorCode errorCode ) 568 void DocumentWebSocketChannel::didFailLoadingBlob(FileError::ErrorCode errorCode )
544 { 569 {
545 m_blobLoader.clear(); 570 m_blobLoader.clear();
546 if (errorCode == FileError::ABORT_ERR) { 571 if (errorCode == FileError::ABORT_ERR) {
547 // The error is caused by cancel(). 572 // The error is caused by cancel().
548 return; 573 return;
549 } 574 }
550 // FIXME: Generate human-friendly reason message. 575 // FIXME: Generate human-friendly reason message.
551 failAsError("Failed to load Blob: error code = " + String::number(errorCode) ); 576 failAsError("Failed to load Blob: error code = " + String::number(errorCode) );
552 // |this| can be deleted here. 577 // |this| can be deleted here.
553 } 578 }
554 579
555 DEFINE_TRACE(DocumentWebSocketChannel) 580 DEFINE_TRACE(DocumentWebSocketChannel)
556 { 581 {
557 visitor->trace(m_blobLoader); 582 visitor->trace(m_blobLoader);
583 visitor->trace(m_messages);
558 visitor->trace(m_client); 584 visitor->trace(m_client);
559 WebSocketChannel::trace(visitor); 585 WebSocketChannel::trace(visitor);
560 ContextLifecycleObserver::trace(visitor); 586 ContextLifecycleObserver::trace(visitor);
561 } 587 }
562 588
563 } // namespace blink 589 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698