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