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

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

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

Powered by Google App Engine
This is Rietveld 408576698