| 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 if (!m_url.isValid()) { | 294 if (!m_url.isValid()) { |
| 295 m_state = CLOSED; | 295 m_state = CLOSED; |
| 296 exceptionState.throwDOMException(SyntaxError, "The URL '" + url + "' is
invalid."); | 296 exceptionState.throwDOMException(SyntaxError, "The URL '" + url + "' is
invalid."); |
| 297 return; | 297 return; |
| 298 } | 298 } |
| 299 if (!m_url.protocolIs("ws") && !m_url.protocolIs("wss")) { | 299 if (!m_url.protocolIs("ws") && !m_url.protocolIs("wss")) { |
| 300 m_state = CLOSED; | 300 m_state = CLOSED; |
| 301 exceptionState.throwDOMException(SyntaxError, "The URL's scheme must be
either 'ws' or 'wss'. '" + m_url.protocol() + "' is not allowed."); | 301 exceptionState.throwDOMException(SyntaxError, "The URL's scheme must be
either 'ws' or 'wss'. '" + m_url.protocol() + "' is not allowed."); |
| 302 return; | 302 return; |
| 303 } | 303 } |
| 304 if (MixedContentChecker::isMixedContent(executionContext()->securityOrigin()
, m_url)) { | 304 |
| 305 // FIXME: Throw an exception and close the connection. | |
| 306 String message = "Connecting to a non-secure WebSocket server from a sec
ure origin is deprecated."; | |
| 307 executionContext()->addConsoleMessage(JSMessageSource, WarningMessageLev
el, message); | |
| 308 } | |
| 309 if (m_url.hasFragmentIdentifier()) { | 305 if (m_url.hasFragmentIdentifier()) { |
| 310 m_state = CLOSED; | 306 m_state = CLOSED; |
| 311 exceptionState.throwDOMException(SyntaxError, "The URL contains a fragme
nt identifier ('" + m_url.fragmentIdentifier() + "'). Fragment identifiers are n
ot allowed in WebSocket URLs."); | 307 exceptionState.throwDOMException(SyntaxError, "The URL contains a fragme
nt identifier ('" + m_url.fragmentIdentifier() + "'). Fragment identifiers are n
ot allowed in WebSocket URLs."); |
| 312 return; | 308 return; |
| 313 } | 309 } |
| 314 if (!portAllowed(m_url)) { | 310 if (!portAllowed(m_url)) { |
| 315 m_state = CLOSED; | 311 m_state = CLOSED; |
| 316 exceptionState.throwSecurityError("The port " + String::number(m_url.por
t()) + " is not allowed."); | 312 exceptionState.throwSecurityError("The port " + String::number(m_url.por
t()) + " is not allowed."); |
| 317 return; | 313 return; |
| 318 } | 314 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 347 exceptionState.throwDOMException(SyntaxError, "The subprotocol '" +
encodeSubprotocolString(protocols[i]) + "' is duplicated."); | 343 exceptionState.throwDOMException(SyntaxError, "The subprotocol '" +
encodeSubprotocolString(protocols[i]) + "' is duplicated."); |
| 348 releaseChannel(); | 344 releaseChannel(); |
| 349 return; | 345 return; |
| 350 } | 346 } |
| 351 } | 347 } |
| 352 | 348 |
| 353 String protocolString; | 349 String protocolString; |
| 354 if (!protocols.isEmpty()) | 350 if (!protocols.isEmpty()) |
| 355 protocolString = joinStrings(protocols, subProtocolSeperator()); | 351 protocolString = joinStrings(protocols, subProtocolSeperator()); |
| 356 | 352 |
| 357 m_channel->connect(m_url, protocolString); | 353 if (!m_channel->connect(m_url, protocolString)) { |
| 354 m_state = CLOSED; |
| 355 exceptionState.throwSecurityError("An insecure WebSocket connection may
not be initiated from a page loaded over HTTPS."); |
| 356 releaseChannel(); |
| 357 return; |
| 358 } |
| 358 } | 359 } |
| 359 | 360 |
| 360 void WebSocket::handleSendResult(WebSocketChannel::SendResult result, ExceptionS
tate& exceptionState, WebSocketSendType dataType) | 361 void WebSocket::handleSendResult(WebSocketChannel::SendResult result, ExceptionS
tate& exceptionState, WebSocketSendType dataType) |
| 361 { | 362 { |
| 362 switch (result) { | 363 switch (result) { |
| 363 case WebSocketChannel::InvalidMessage: | 364 case WebSocketChannel::InvalidMessage: |
| 364 exceptionState.throwDOMException(SyntaxError, "The message contains inva
lid characters."); | 365 exceptionState.throwDOMException(SyntaxError, "The message contains inva
lid characters."); |
| 365 return; | 366 return; |
| 366 case WebSocketChannel::SendFail: | 367 case WebSocketChannel::SendFail: |
| 367 logError("WebSocket send() failed."); | 368 logError("WebSocket send() failed."); |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 static const size_t minimumPayloadSizeWithEightByteExtendedPayloadLength = 0
x10000; | 677 static const size_t minimumPayloadSizeWithEightByteExtendedPayloadLength = 0
x10000; |
| 677 size_t overhead = hybiBaseFramingOverhead + hybiMaskingKeyLength; | 678 size_t overhead = hybiBaseFramingOverhead + hybiMaskingKeyLength; |
| 678 if (payloadSize >= minimumPayloadSizeWithEightByteExtendedPayloadLength) | 679 if (payloadSize >= minimumPayloadSizeWithEightByteExtendedPayloadLength) |
| 679 overhead += 8; | 680 overhead += 8; |
| 680 else if (payloadSize >= minimumPayloadSizeWithTwoByteExtendedPayloadLength) | 681 else if (payloadSize >= minimumPayloadSizeWithTwoByteExtendedPayloadLength) |
| 681 overhead += 2; | 682 overhead += 2; |
| 682 return overhead; | 683 return overhead; |
| 683 } | 684 } |
| 684 | 685 |
| 685 } // namespace WebCore | 686 } // namespace WebCore |
| OLD | NEW |