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

Side by Side Diff: Source/WebCore/Modules/websockets/WebSocket.cpp

Issue 13643002: Rename LOG() to LOG_INFO() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: rebase Created 7 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) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 204
205 void WebSocket::connect(const String& url, const String& protocol, ExceptionCode & ec) 205 void WebSocket::connect(const String& url, const String& protocol, ExceptionCode & ec)
206 { 206 {
207 Vector<String> protocols; 207 Vector<String> protocols;
208 protocols.append(protocol); 208 protocols.append(protocol);
209 connect(url, protocols, ec); 209 connect(url, protocols, ec);
210 } 210 }
211 211
212 void WebSocket::connect(const String& url, const Vector<String>& protocols, Exce ptionCode& ec) 212 void WebSocket::connect(const String& url, const Vector<String>& protocols, Exce ptionCode& ec)
213 { 213 {
214 LOG(Network, "WebSocket %p connect to %s", this, url.utf8().data()); 214 LOG_INFO(Network, "WebSocket %p connect to %s", this, url.utf8().data());
215 m_url = KURL(KURL(), url); 215 m_url = KURL(KURL(), url);
216 216
217 if (!m_url.isValid()) { 217 if (!m_url.isValid()) {
218 scriptExecutionContext()->addConsoleMessage(JSMessageSource, ErrorMessag eLevel, "Invalid url for WebSocket " + m_url.elidedString()); 218 scriptExecutionContext()->addConsoleMessage(JSMessageSource, ErrorMessag eLevel, "Invalid url for WebSocket " + m_url.elidedString());
219 m_state = CLOSED; 219 m_state = CLOSED;
220 ec = SYNTAX_ERR; 220 ec = SYNTAX_ERR;
221 return; 221 return;
222 } 222 }
223 223
224 if (!m_url.protocolIs("ws") && !m_url.protocolIs("wss")) { 224 if (!m_url.protocolIs("ws") && !m_url.protocolIs("wss")) {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 String protocolString; 285 String protocolString;
286 if (!protocols.isEmpty()) 286 if (!protocols.isEmpty())
287 protocolString = joinStrings(protocols, subProtocolSeperator()); 287 protocolString = joinStrings(protocols, subProtocolSeperator());
288 288
289 m_channel->connect(m_url, protocolString); 289 m_channel->connect(m_url, protocolString);
290 ActiveDOMObject::setPendingActivity(this); 290 ActiveDOMObject::setPendingActivity(this);
291 } 291 }
292 292
293 bool WebSocket::send(const String& message, ExceptionCode& ec) 293 bool WebSocket::send(const String& message, ExceptionCode& ec)
294 { 294 {
295 LOG(Network, "WebSocket %p send %s", this, message.utf8().data()); 295 LOG_INFO(Network, "WebSocket %p send %s", this, message.utf8().data());
296 if (m_state == CONNECTING) { 296 if (m_state == CONNECTING) {
297 ec = INVALID_STATE_ERR; 297 ec = INVALID_STATE_ERR;
298 return false; 298 return false;
299 } 299 }
300 // No exception is raised if the connection was once established but has sub sequently been closed. 300 // No exception is raised if the connection was once established but has sub sequently been closed.
301 if (m_state == CLOSING || m_state == CLOSED) { 301 if (m_state == CLOSING || m_state == CLOSED) {
302 size_t payloadSize = message.utf8().length(); 302 size_t payloadSize = message.utf8().length();
303 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, pay loadSize); 303 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, pay loadSize);
304 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, get FramingOverhead(payloadSize)); 304 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, get FramingOverhead(payloadSize));
305 return false; 305 return false;
306 } 306 }
307 ASSERT(m_channel); 307 ASSERT(m_channel);
308 ThreadableWebSocketChannel::SendResult result = m_channel->send(message); 308 ThreadableWebSocketChannel::SendResult result = m_channel->send(message);
309 if (result == ThreadableWebSocketChannel::InvalidMessage) { 309 if (result == ThreadableWebSocketChannel::InvalidMessage) {
310 scriptExecutionContext()->addConsoleMessage(JSMessageSource, ErrorMessag eLevel, "Websocket message contains invalid character(s)."); 310 scriptExecutionContext()->addConsoleMessage(JSMessageSource, ErrorMessag eLevel, "Websocket message contains invalid character(s).");
311 ec = SYNTAX_ERR; 311 ec = SYNTAX_ERR;
312 return false; 312 return false;
313 } 313 }
314 return result == ThreadableWebSocketChannel::SendSuccess; 314 return result == ThreadableWebSocketChannel::SendSuccess;
315 } 315 }
316 316
317 bool WebSocket::send(ArrayBuffer* binaryData, ExceptionCode& ec) 317 bool WebSocket::send(ArrayBuffer* binaryData, ExceptionCode& ec)
318 { 318 {
319 LOG(Network, "WebSocket %p send arraybuffer %p", this, binaryData); 319 LOG_INFO(Network, "WebSocket %p send arraybuffer %p", this, binaryData);
320 ASSERT(binaryData); 320 ASSERT(binaryData);
321 if (m_state == CONNECTING) { 321 if (m_state == CONNECTING) {
322 ec = INVALID_STATE_ERR; 322 ec = INVALID_STATE_ERR;
323 return false; 323 return false;
324 } 324 }
325 if (m_state == CLOSING || m_state == CLOSED) { 325 if (m_state == CLOSING || m_state == CLOSED) {
326 unsigned payloadSize = binaryData->byteLength(); 326 unsigned payloadSize = binaryData->byteLength();
327 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, pay loadSize); 327 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, pay loadSize);
328 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, get FramingOverhead(payloadSize)); 328 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, get FramingOverhead(payloadSize));
329 return false; 329 return false;
330 } 330 }
331 ASSERT(m_channel); 331 ASSERT(m_channel);
332 return m_channel->send(*binaryData, 0, binaryData->byteLength()) == Threadab leWebSocketChannel::SendSuccess; 332 return m_channel->send(*binaryData, 0, binaryData->byteLength()) == Threadab leWebSocketChannel::SendSuccess;
333 } 333 }
334 334
335 bool WebSocket::send(ArrayBufferView* arrayBufferView, ExceptionCode& ec) 335 bool WebSocket::send(ArrayBufferView* arrayBufferView, ExceptionCode& ec)
336 { 336 {
337 LOG(Network, "WebSocket %p send arraybufferview %p", this, arrayBufferView); 337 LOG_INFO(Network, "WebSocket %p send arraybufferview %p", this, arrayBufferV iew);
338 ASSERT(arrayBufferView); 338 ASSERT(arrayBufferView);
339 if (m_state == CONNECTING) { 339 if (m_state == CONNECTING) {
340 ec = INVALID_STATE_ERR; 340 ec = INVALID_STATE_ERR;
341 return false; 341 return false;
342 } 342 }
343 if (m_state == CLOSING || m_state == CLOSED) { 343 if (m_state == CLOSING || m_state == CLOSED) {
344 unsigned payloadSize = arrayBufferView->byteLength(); 344 unsigned payloadSize = arrayBufferView->byteLength();
345 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, pay loadSize); 345 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, pay loadSize);
346 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, get FramingOverhead(payloadSize)); 346 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, get FramingOverhead(payloadSize));
347 return false; 347 return false;
348 } 348 }
349 ASSERT(m_channel); 349 ASSERT(m_channel);
350 RefPtr<ArrayBuffer> arrayBuffer(arrayBufferView->buffer()); 350 RefPtr<ArrayBuffer> arrayBuffer(arrayBufferView->buffer());
351 return m_channel->send(*arrayBuffer, arrayBufferView->byteOffset(), arrayBuf ferView->byteLength()) == ThreadableWebSocketChannel::SendSuccess; 351 return m_channel->send(*arrayBuffer, arrayBufferView->byteOffset(), arrayBuf ferView->byteLength()) == ThreadableWebSocketChannel::SendSuccess;
352 } 352 }
353 353
354 bool WebSocket::send(Blob* binaryData, ExceptionCode& ec) 354 bool WebSocket::send(Blob* binaryData, ExceptionCode& ec)
355 { 355 {
356 LOG(Network, "WebSocket %p send blob %s", this, binaryData->url().elidedStri ng().utf8().data()); 356 LOG_INFO(Network, "WebSocket %p send blob %s", this, binaryData->url().elide dString().utf8().data());
357 ASSERT(binaryData); 357 ASSERT(binaryData);
358 if (m_state == CONNECTING) { 358 if (m_state == CONNECTING) {
359 ec = INVALID_STATE_ERR; 359 ec = INVALID_STATE_ERR;
360 return false; 360 return false;
361 } 361 }
362 if (m_state == CLOSING || m_state == CLOSED) { 362 if (m_state == CLOSING || m_state == CLOSED) {
363 unsigned long payloadSize = static_cast<unsigned long>(binaryData->size( )); 363 unsigned long payloadSize = static_cast<unsigned long>(binaryData->size( ));
364 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, pay loadSize); 364 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, pay loadSize);
365 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, get FramingOverhead(payloadSize)); 365 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, get FramingOverhead(payloadSize));
366 return false; 366 return false;
367 } 367 }
368 ASSERT(m_channel); 368 ASSERT(m_channel);
369 return m_channel->send(*binaryData) == ThreadableWebSocketChannel::SendSucce ss; 369 return m_channel->send(*binaryData) == ThreadableWebSocketChannel::SendSucce ss;
370 } 370 }
371 371
372 void WebSocket::close(int code, const String& reason, ExceptionCode& ec) 372 void WebSocket::close(int code, const String& reason, ExceptionCode& ec)
373 { 373 {
374 if (code == WebSocketChannel::CloseEventCodeNotSpecified) 374 if (code == WebSocketChannel::CloseEventCodeNotSpecified)
375 LOG(Network, "WebSocket %p close without code and reason", this); 375 LOG_INFO(Network, "WebSocket %p close without code and reason", this);
376 else { 376 else {
377 LOG(Network, "WebSocket %p close with code = %d, reason = %s", this, cod e, reason.utf8().data()); 377 LOG_INFO(Network, "WebSocket %p close with code = %d, reason = %s", this , code, reason.utf8().data());
378 if (!(code == WebSocketChannel::CloseEventCodeNormalClosure || (WebSocke tChannel::CloseEventCodeMinimumUserDefined <= code && code <= WebSocketChannel:: CloseEventCodeMaximumUserDefined))) { 378 if (!(code == WebSocketChannel::CloseEventCodeNormalClosure || (WebSocke tChannel::CloseEventCodeMinimumUserDefined <= code && code <= WebSocketChannel:: CloseEventCodeMaximumUserDefined))) {
379 ec = INVALID_ACCESS_ERR; 379 ec = INVALID_ACCESS_ERR;
380 return; 380 return;
381 } 381 }
382 CString utf8 = reason.utf8(String::StrictConversionReplacingUnpairedSurr ogatesWithFFFD); 382 CString utf8 = reason.utf8(String::StrictConversionReplacingUnpairedSurr ogatesWithFFFD);
383 if (utf8.length() > maxReasonSizeInBytes) { 383 if (utf8.length() > maxReasonSizeInBytes) {
384 scriptExecutionContext()->addConsoleMessage(JSMessageSource, ErrorMe ssageLevel, "WebSocket close message is too long."); 384 scriptExecutionContext()->addConsoleMessage(JSMessageSource, ErrorMe ssageLevel, "WebSocket close message is too long.");
385 ec = SYNTAX_ERR; 385 ec = SYNTAX_ERR;
386 return; 386 return;
387 } 387 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 return eventNames().interfaceForWebSocket; 454 return eventNames().interfaceForWebSocket;
455 } 455 }
456 456
457 ScriptExecutionContext* WebSocket::scriptExecutionContext() const 457 ScriptExecutionContext* WebSocket::scriptExecutionContext() const
458 { 458 {
459 return ActiveDOMObject::scriptExecutionContext(); 459 return ActiveDOMObject::scriptExecutionContext();
460 } 460 }
461 461
462 void WebSocket::contextDestroyed() 462 void WebSocket::contextDestroyed()
463 { 463 {
464 LOG(Network, "WebSocket %p scriptExecutionContext destroyed", this); 464 LOG_INFO(Network, "WebSocket %p scriptExecutionContext destroyed", this);
465 ASSERT(!m_channel); 465 ASSERT(!m_channel);
466 ASSERT(m_state == CLOSED); 466 ASSERT(m_state == CLOSED);
467 ActiveDOMObject::contextDestroyed(); 467 ActiveDOMObject::contextDestroyed();
468 } 468 }
469 469
470 bool WebSocket::canSuspend() const 470 bool WebSocket::canSuspend() const
471 { 471 {
472 return !m_channel; 472 return !m_channel;
473 } 473 }
474 474
(...skipping 16 matching lines...) Expand all
491 m_channel->disconnect(); 491 m_channel->disconnect();
492 m_channel = 0; 492 m_channel = 0;
493 m_state = CLOSED; 493 m_state = CLOSED;
494 ActiveDOMObject::stop(); 494 ActiveDOMObject::stop();
495 if (pending) 495 if (pending)
496 ActiveDOMObject::unsetPendingActivity(this); 496 ActiveDOMObject::unsetPendingActivity(this);
497 } 497 }
498 498
499 void WebSocket::didConnect() 499 void WebSocket::didConnect()
500 { 500 {
501 LOG(Network, "WebSocket %p didConnect", this); 501 LOG_INFO(Network, "WebSocket %p didConnect", this);
502 if (m_state != CONNECTING) { 502 if (m_state != CONNECTING) {
503 didClose(0, ClosingHandshakeIncomplete, WebSocketChannel::CloseEventCode AbnormalClosure, ""); 503 didClose(0, ClosingHandshakeIncomplete, WebSocketChannel::CloseEventCode AbnormalClosure, "");
504 return; 504 return;
505 } 505 }
506 ASSERT(scriptExecutionContext()); 506 ASSERT(scriptExecutionContext());
507 m_state = OPEN; 507 m_state = OPEN;
508 m_subprotocol = m_channel->subprotocol(); 508 m_subprotocol = m_channel->subprotocol();
509 m_extensions = m_channel->extensions(); 509 m_extensions = m_channel->extensions();
510 dispatchEvent(Event::create(eventNames().openEvent, false, false)); 510 dispatchEvent(Event::create(eventNames().openEvent, false, false));
511 } 511 }
512 512
513 void WebSocket::didReceiveMessage(const String& msg) 513 void WebSocket::didReceiveMessage(const String& msg)
514 { 514 {
515 LOG(Network, "WebSocket %p didReceiveMessage %s", this, msg.utf8().data()); 515 LOG_INFO(Network, "WebSocket %p didReceiveMessage %s", this, msg.utf8().data ());
516 if (m_state != OPEN && m_state != CLOSING) 516 if (m_state != OPEN && m_state != CLOSING)
517 return; 517 return;
518 ASSERT(scriptExecutionContext()); 518 ASSERT(scriptExecutionContext());
519 dispatchEvent(MessageEvent::create(msg, SecurityOrigin::create(m_url)->toStr ing())); 519 dispatchEvent(MessageEvent::create(msg, SecurityOrigin::create(m_url)->toStr ing()));
520 } 520 }
521 521
522 void WebSocket::didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData) 522 void WebSocket::didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData)
523 { 523 {
524 switch (m_binaryType) { 524 switch (m_binaryType) {
525 case BinaryTypeBlob: { 525 case BinaryTypeBlob: {
526 size_t size = binaryData->size(); 526 size_t size = binaryData->size();
527 RefPtr<RawData> rawData = RawData::create(); 527 RefPtr<RawData> rawData = RawData::create();
528 binaryData->swap(*rawData->mutableData()); 528 binaryData->swap(*rawData->mutableData());
529 OwnPtr<BlobData> blobData = BlobData::create(); 529 OwnPtr<BlobData> blobData = BlobData::create();
530 blobData->appendData(rawData.release(), 0, BlobDataItem::toEndOfFile); 530 blobData->appendData(rawData.release(), 0, BlobDataItem::toEndOfFile);
531 RefPtr<Blob> blob = Blob::create(blobData.release(), size); 531 RefPtr<Blob> blob = Blob::create(blobData.release(), size);
532 dispatchEvent(MessageEvent::create(blob.release(), SecurityOrigin::creat e(m_url)->toString())); 532 dispatchEvent(MessageEvent::create(blob.release(), SecurityOrigin::creat e(m_url)->toString()));
533 break; 533 break;
534 } 534 }
535 535
536 case BinaryTypeArrayBuffer: 536 case BinaryTypeArrayBuffer:
537 dispatchEvent(MessageEvent::create(ArrayBuffer::create(binaryData->data( ), binaryData->size()), SecurityOrigin::create(m_url)->toString())); 537 dispatchEvent(MessageEvent::create(ArrayBuffer::create(binaryData->data( ), binaryData->size()), SecurityOrigin::create(m_url)->toString()));
538 break; 538 break;
539 } 539 }
540 } 540 }
541 541
542 void WebSocket::didReceiveMessageError() 542 void WebSocket::didReceiveMessageError()
543 { 543 {
544 LOG(Network, "WebSocket %p didReceiveErrorMessage", this); 544 LOG_INFO(Network, "WebSocket %p didReceiveErrorMessage", this);
545 ASSERT(scriptExecutionContext()); 545 ASSERT(scriptExecutionContext());
546 dispatchEvent(Event::create(eventNames().errorEvent, false, false)); 546 dispatchEvent(Event::create(eventNames().errorEvent, false, false));
547 } 547 }
548 548
549 void WebSocket::didUpdateBufferedAmount(unsigned long bufferedAmount) 549 void WebSocket::didUpdateBufferedAmount(unsigned long bufferedAmount)
550 { 550 {
551 LOG(Network, "WebSocket %p didUpdateBufferedAmount %lu", this, bufferedAmoun t); 551 LOG_INFO(Network, "WebSocket %p didUpdateBufferedAmount %lu", this, buffered Amount);
552 if (m_state == CLOSED) 552 if (m_state == CLOSED)
553 return; 553 return;
554 m_bufferedAmount = bufferedAmount; 554 m_bufferedAmount = bufferedAmount;
555 } 555 }
556 556
557 void WebSocket::didStartClosingHandshake() 557 void WebSocket::didStartClosingHandshake()
558 { 558 {
559 LOG(Network, "WebSocket %p didStartClosingHandshake", this); 559 LOG_INFO(Network, "WebSocket %p didStartClosingHandshake", this);
560 m_state = CLOSING; 560 m_state = CLOSING;
561 } 561 }
562 562
563 void WebSocket::didClose(unsigned long unhandledBufferedAmount, ClosingHandshake CompletionStatus closingHandshakeCompletion, unsigned short code, const String& reason) 563 void WebSocket::didClose(unsigned long unhandledBufferedAmount, ClosingHandshake CompletionStatus closingHandshakeCompletion, unsigned short code, const String& reason)
564 { 564 {
565 LOG(Network, "WebSocket %p didClose", this); 565 LOG_INFO(Network, "WebSocket %p didClose", this);
566 if (!m_channel) 566 if (!m_channel)
567 return; 567 return;
568 bool wasClean = m_state == CLOSING && !unhandledBufferedAmount && closingHan dshakeCompletion == ClosingHandshakeComplete && code != WebSocketChannel::CloseE ventCodeAbnormalClosure; 568 bool wasClean = m_state == CLOSING && !unhandledBufferedAmount && closingHan dshakeCompletion == ClosingHandshakeComplete && code != WebSocketChannel::CloseE ventCodeAbnormalClosure;
569 m_state = CLOSED; 569 m_state = CLOSED;
570 m_bufferedAmount = unhandledBufferedAmount; 570 m_bufferedAmount = unhandledBufferedAmount;
571 ASSERT(scriptExecutionContext()); 571 ASSERT(scriptExecutionContext());
572 RefPtr<CloseEvent> event = CloseEvent::create(wasClean, code, reason); 572 RefPtr<CloseEvent> event = CloseEvent::create(wasClean, code, reason);
573 dispatchEvent(event); 573 dispatchEvent(event);
574 if (m_channel) { 574 if (m_channel) {
575 m_channel->disconnect(); 575 m_channel->disconnect();
(...skipping 23 matching lines...) Expand all
599 if (payloadSize >= minimumPayloadSizeWithEightByteExtendedPayloadLength) 599 if (payloadSize >= minimumPayloadSizeWithEightByteExtendedPayloadLength)
600 overhead += 8; 600 overhead += 8;
601 else if (payloadSize >= minimumPayloadSizeWithTwoByteExtendedPayloadLength) 601 else if (payloadSize >= minimumPayloadSizeWithTwoByteExtendedPayloadLength)
602 overhead += 2; 602 overhead += 2;
603 return overhead; 603 return overhead;
604 } 604 }
605 605
606 } // namespace WebCore 606 } // namespace WebCore
607 607
608 #endif 608 #endif
OLDNEW
« no previous file with comments | « Source/WebCore/Modules/webdatabase/SQLTransactionBackend.cpp ('k') | Source/WebCore/Modules/websockets/WebSocketChannel.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698