Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 { | 198 { |
| 199 StringBuilder builder; | 199 StringBuilder builder; |
| 200 for (size_t i = 0; i < strings.size(); ++i) { | 200 for (size_t i = 0; i < strings.size(); ++i) { |
| 201 if (i) | 201 if (i) |
| 202 builder.append(separator); | 202 builder.append(separator); |
| 203 builder.append(strings[i]); | 203 builder.append(strings[i]); |
| 204 } | 204 } |
| 205 return builder.toString(); | 205 return builder.toString(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 static unsigned long saturateAdd(unsigned long a, unsigned long b) | 208 static unsigned saturateAdd(unsigned a, unsigned b) |
|
tyoshino (SeeGerritForStatus)
2014/11/17 14:15:32
please leave the second argument type "unsigned lo
Paritosh Kumar
2014/11/18 09:38:44
Thanks
Done.
| |
| 209 { | 209 { |
| 210 if (std::numeric_limits<unsigned long>::max() - a < b) | 210 if (std::numeric_limits<unsigned>::max() - a < b) |
| 211 return std::numeric_limits<unsigned long>::max(); | 211 return std::numeric_limits<unsigned>::max(); |
| 212 return a + b; | 212 return a + b; |
| 213 } | 213 } |
| 214 | 214 |
| 215 static void setInvalidStateErrorForSendMethod(ExceptionState& exceptionState) | 215 static void setInvalidStateErrorForSendMethod(ExceptionState& exceptionState) |
| 216 { | 216 { |
| 217 exceptionState.throwDOMException(InvalidStateError, "Still in CONNECTING sta te."); | 217 exceptionState.throwDOMException(InvalidStateError, "Still in CONNECTING sta te."); |
| 218 } | 218 } |
| 219 | 219 |
| 220 const char* DOMWebSocket::subprotocolSeperator() | 220 const char* DOMWebSocket::subprotocolSeperator() |
| 221 { | 221 { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 m_channel = createChannel(executionContext(), this); | 342 m_channel = createChannel(executionContext(), this); |
| 343 | 343 |
| 344 if (!m_channel->connect(m_url, protocolString)) { | 344 if (!m_channel->connect(m_url, protocolString)) { |
| 345 m_state = CLOSED; | 345 m_state = CLOSED; |
| 346 exceptionState.throwSecurityError("An insecure WebSocket connection may not be initiated from a page loaded over HTTPS."); | 346 exceptionState.throwSecurityError("An insecure WebSocket connection may not be initiated from a page loaded over HTTPS."); |
| 347 releaseChannel(); | 347 releaseChannel(); |
| 348 return; | 348 return; |
| 349 } | 349 } |
| 350 } | 350 } |
| 351 | 351 |
| 352 void DOMWebSocket::updateBufferedAmountAfterClose(unsigned long payloadSize) | 352 void DOMWebSocket::updateBufferedAmountAfterClose(unsigned payloadSize) |
|
tyoshino (SeeGerritForStatus)
2014/11/17 14:15:32
please leave this unchanged
Paritosh Kumar
2014/11/18 09:38:44
Done.
| |
| 353 { | 353 { |
| 354 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, payload Size); | 354 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, payload Size); |
| 355 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, getFram ingOverhead(payloadSize)); | 355 m_bufferedAmountAfterClose = saturateAdd(m_bufferedAmountAfterClose, getFram ingOverhead(payloadSize)); |
| 356 | 356 |
| 357 logError("WebSocket is already in CLOSING or CLOSED state."); | 357 logError("WebSocket is already in CLOSING or CLOSED state."); |
| 358 } | 358 } |
| 359 | 359 |
| 360 void DOMWebSocket::reflectBufferedAmountConsumption(Timer<DOMWebSocket>*) | 360 void DOMWebSocket::reflectBufferedAmountConsumption(Timer<DOMWebSocket>*) |
| 361 { | 361 { |
| 362 ASSERT(m_bufferedAmount >= m_consumedBufferedAmount); | 362 ASSERT(m_bufferedAmount >= m_consumedBufferedAmount); |
| 363 WTF_LOG(Network, "WebSocket %p reflectBufferedAmountConsumption() %lu => %lu ", this, m_bufferedAmount, m_bufferedAmount - m_consumedBufferedAmount); | 363 WTF_LOG(Network, "WebSocket %p reflectBufferedAmountConsumption() %lu => %lu ", this, m_bufferedAmount, m_bufferedAmount - m_consumedBufferedAmount); |
|
eroman
2014/11/18 03:02:10
This should be %u now
Paritosh Kumar
2014/11/18 09:38:44
Done.
| |
| 364 | 364 |
| 365 m_bufferedAmount -= m_consumedBufferedAmount; | 365 m_bufferedAmount -= m_consumedBufferedAmount; |
| 366 m_consumedBufferedAmount = 0; | 366 m_consumedBufferedAmount = 0; |
| 367 } | 367 } |
| 368 | 368 |
| 369 void DOMWebSocket::releaseChannel() | 369 void DOMWebSocket::releaseChannel() |
| 370 { | 370 { |
| 371 ASSERT(m_channel); | 371 ASSERT(m_channel); |
| 372 m_channel->disconnect(); | 372 m_channel->disconnect(); |
| 373 m_channel = nullptr; | 373 m_channel = nullptr; |
| 374 } | 374 } |
| 375 | 375 |
| 376 void DOMWebSocket::send(const String& message, ExceptionState& exceptionState) | 376 void DOMWebSocket::send(const String& message, ExceptionState& exceptionState) |
| 377 { | 377 { |
| 378 WTF_LOG(Network, "WebSocket %p send() Sending String '%s'", this, message.ut f8().data()); | 378 WTF_LOG(Network, "WebSocket %p send() Sending String '%s'", this, message.ut f8().data()); |
| 379 if (m_state == CONNECTING) { | 379 if (m_state == CONNECTING) { |
| 380 setInvalidStateErrorForSendMethod(exceptionState); | 380 setInvalidStateErrorForSendMethod(exceptionState); |
| 381 return; | 381 return; |
| 382 } | 382 } |
| 383 // No exception is raised if the connection was once established but has sub sequently been closed. | 383 // No exception is raised if the connection was once established but has sub sequently been closed. |
| 384 if (m_state == CLOSING || m_state == CLOSED) { | 384 if (m_state == CLOSING || m_state == CLOSED) { |
| 385 updateBufferedAmountAfterClose(message.utf8().length()); | 385 updateBufferedAmountAfterClose(message.utf8().length()); |
|
eroman
2014/11/18 03:02:10
This (and other callsites) are potentially an inte
tyoshino (SeeGerritForStatus)
2014/11/18 03:38:03
Yes. They should be fixed. It's ok to either take
Paritosh Kumar
2014/11/18 09:38:44
Thanks, I'm leaving this one now.
| |
| 386 return; | 386 return; |
| 387 } | 387 } |
| 388 Platform::current()->histogramEnumeration("WebCore.WebSocket.SendType", WebS ocketSendTypeString, WebSocketSendTypeMax); | 388 Platform::current()->histogramEnumeration("WebCore.WebSocket.SendType", WebS ocketSendTypeString, WebSocketSendTypeMax); |
| 389 ASSERT(m_channel); | 389 ASSERT(m_channel); |
| 390 m_bufferedAmount += message.utf8().length(); | 390 m_bufferedAmount += message.utf8().length(); |
| 391 m_channel->send(message); | 391 m_channel->send(message); |
| 392 } | 392 } |
| 393 | 393 |
| 394 void DOMWebSocket::send(DOMArrayBuffer* binaryData, ExceptionState& exceptionSta te) | 394 void DOMWebSocket::send(DOMArrayBuffer* binaryData, ExceptionState& exceptionSta te) |
| 395 { | 395 { |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 493 const KURL& DOMWebSocket::url() const | 493 const KURL& DOMWebSocket::url() const |
| 494 { | 494 { |
| 495 return m_url; | 495 return m_url; |
| 496 } | 496 } |
| 497 | 497 |
| 498 DOMWebSocket::State DOMWebSocket::readyState() const | 498 DOMWebSocket::State DOMWebSocket::readyState() const |
| 499 { | 499 { |
| 500 return m_state; | 500 return m_state; |
| 501 } | 501 } |
| 502 | 502 |
| 503 unsigned long DOMWebSocket::bufferedAmount() const | 503 unsigned DOMWebSocket::bufferedAmount() const |
| 504 { | 504 { |
| 505 return saturateAdd(m_bufferedAmount, m_bufferedAmountAfterClose); | 505 return saturateAdd(m_bufferedAmount, m_bufferedAmountAfterClose); |
| 506 } | 506 } |
| 507 | 507 |
| 508 String DOMWebSocket::protocol() const | 508 String DOMWebSocket::protocol() const |
| 509 { | 509 { |
| 510 return m_subprotocol; | 510 return m_subprotocol; |
| 511 } | 511 } |
| 512 | 512 |
| 513 String DOMWebSocket::extensions() const | 513 String DOMWebSocket::extensions() const |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 634 } | 634 } |
| 635 } | 635 } |
| 636 | 636 |
| 637 void DOMWebSocket::didError() | 637 void DOMWebSocket::didError() |
| 638 { | 638 { |
| 639 WTF_LOG(Network, "WebSocket %p didError()", this); | 639 WTF_LOG(Network, "WebSocket %p didError()", this); |
| 640 m_state = CLOSED; | 640 m_state = CLOSED; |
| 641 m_eventQueue->dispatch(Event::create(EventTypeNames::error)); | 641 m_eventQueue->dispatch(Event::create(EventTypeNames::error)); |
| 642 } | 642 } |
| 643 | 643 |
| 644 void DOMWebSocket::didConsumeBufferedAmount(unsigned long consumed) | 644 void DOMWebSocket::didConsumeBufferedAmount(unsigned long consumed) |
|
eroman
2014/11/18 03:02:10
Should this be changed to an unsigned too?
Paritosh Kumar
2014/11/18 09:38:44
Thanks
I think this should be changed to unsigned,
| |
| 645 { | 645 { |
| 646 ASSERT(m_bufferedAmount >= consumed); | 646 ASSERT(m_bufferedAmount >= consumed); |
| 647 WTF_LOG(Network, "WebSocket %p didConsumeBufferedAmount(%lu)", this, consume d); | 647 WTF_LOG(Network, "WebSocket %p didConsumeBufferedAmount(%lu)", this, consume d); |
| 648 if (m_state == CLOSED) | 648 if (m_state == CLOSED) |
| 649 return; | 649 return; |
| 650 m_consumedBufferedAmount += consumed; | 650 m_consumedBufferedAmount += consumed; |
| 651 if (!m_bufferedAmountConsumeTimer.isActive()) | 651 if (!m_bufferedAmountConsumeTimer.isActive()) |
| 652 m_bufferedAmountConsumeTimer.startOneShot(0, FROM_HERE); | 652 m_bufferedAmountConsumeTimer.startOneShot(0, FROM_HERE); |
| 653 } | 653 } |
| 654 | 654 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 687 | 687 |
| 688 void DOMWebSocket::trace(Visitor* visitor) | 688 void DOMWebSocket::trace(Visitor* visitor) |
| 689 { | 689 { |
| 690 visitor->trace(m_channel); | 690 visitor->trace(m_channel); |
| 691 visitor->trace(m_eventQueue); | 691 visitor->trace(m_eventQueue); |
| 692 WebSocketChannelClient::trace(visitor); | 692 WebSocketChannelClient::trace(visitor); |
| 693 EventTargetWithInlineData::trace(visitor); | 693 EventTargetWithInlineData::trace(visitor); |
| 694 } | 694 } |
| 695 | 695 |
| 696 } // namespace blink | 696 } // namespace blink |
| OLD | NEW |