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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 return; | 324 return; |
325 } | 325 } |
326 | 326 |
327 if (!isPortAllowedForScheme(m_url)) { | 327 if (!isPortAllowedForScheme(m_url)) { |
328 m_state = kClosed; | 328 m_state = kClosed; |
329 exceptionState.throwSecurityError( | 329 exceptionState.throwSecurityError( |
330 "The port " + String::number(m_url.port()) + " is not allowed."); | 330 "The port " + String::number(m_url.port()) + " is not allowed."); |
331 return; | 331 return; |
332 } | 332 } |
333 | 333 |
334 // FIXME: Convert this to check the isolated world's Content Security Policy o
nce webkit.org/b/104520 is solved. | 334 // FIXME: Convert this to check the isolated world's Content Security Policy |
| 335 // once webkit.org/b/104520 is solved. |
335 if (!ContentSecurityPolicy::shouldBypassMainWorld(getExecutionContext()) && | 336 if (!ContentSecurityPolicy::shouldBypassMainWorld(getExecutionContext()) && |
336 !getExecutionContext()->contentSecurityPolicy()->allowConnectToSource( | 337 !getExecutionContext()->contentSecurityPolicy()->allowConnectToSource( |
337 m_url)) { | 338 m_url)) { |
338 m_state = kClosed; | 339 m_state = kClosed; |
339 // The URL is safe to expose to JavaScript, as this check happens synchronou
sly before redirection. | 340 // The URL is safe to expose to JavaScript, as this check happens |
| 341 // synchronously before redirection. |
340 exceptionState.throwSecurityError( | 342 exceptionState.throwSecurityError( |
341 "Refused to connect to '" + m_url.elidedString() + | 343 "Refused to connect to '" + m_url.elidedString() + |
342 "' because it violates the document's Content Security Policy."); | 344 "' because it violates the document's Content Security Policy."); |
343 return; | 345 return; |
344 } | 346 } |
345 | 347 |
346 // Fail if not all elements in |protocols| are valid. | 348 // Fail if not all elements in |protocols| are valid. |
347 for (size_t i = 0; i < protocols.size(); ++i) { | 349 for (size_t i = 0; i < protocols.size(); ++i) { |
348 if (!isValidSubprotocolString(protocols[i])) { | 350 if (!isValidSubprotocolString(protocols[i])) { |
349 m_state = kClosed; | 351 m_state = kClosed; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 | 430 |
429 void DOMWebSocket::send(const String& message, ExceptionState& exceptionState) { | 431 void DOMWebSocket::send(const String& message, ExceptionState& exceptionState) { |
430 CString encodedMessage = message.utf8(); | 432 CString encodedMessage = message.utf8(); |
431 | 433 |
432 NETWORK_DVLOG(1) << "WebSocket " << this << " send() Sending String " | 434 NETWORK_DVLOG(1) << "WebSocket " << this << " send() Sending String " |
433 << message; | 435 << message; |
434 if (m_state == kConnecting) { | 436 if (m_state == kConnecting) { |
435 setInvalidStateErrorForSendMethod(exceptionState); | 437 setInvalidStateErrorForSendMethod(exceptionState); |
436 return; | 438 return; |
437 } | 439 } |
438 // No exception is raised if the connection was once established but has subse
quently been closed. | 440 // No exception is raised if the connection was once established but has |
| 441 // subsequently been closed. |
439 if (m_state == kClosing || m_state == kClosed) { | 442 if (m_state == kClosing || m_state == kClosed) { |
440 updateBufferedAmountAfterClose(encodedMessage.length()); | 443 updateBufferedAmountAfterClose(encodedMessage.length()); |
441 return; | 444 return; |
442 } | 445 } |
443 | 446 |
444 recordSendTypeHistogram(WebSocketSendTypeString); | 447 recordSendTypeHistogram(WebSocketSendTypeString); |
445 | 448 |
446 DCHECK(m_channel); | 449 DCHECK(m_channel); |
447 m_bufferedAmount += encodedMessage.length(); | 450 m_bufferedAmount += encodedMessage.length(); |
448 m_channel->send(encodedMessage); | 451 m_channel->send(encodedMessage); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 << " reason=" << reason; | 552 << " reason=" << reason; |
550 if (!(code == WebSocketChannel::CloseEventCodeNormalClosure || | 553 if (!(code == WebSocketChannel::CloseEventCodeNormalClosure || |
551 (WebSocketChannel::CloseEventCodeMinimumUserDefined <= code && | 554 (WebSocketChannel::CloseEventCodeMinimumUserDefined <= code && |
552 code <= WebSocketChannel::CloseEventCodeMaximumUserDefined))) { | 555 code <= WebSocketChannel::CloseEventCodeMaximumUserDefined))) { |
553 exceptionState.throwDOMException( | 556 exceptionState.throwDOMException( |
554 InvalidAccessError, | 557 InvalidAccessError, |
555 "The code must be either 1000, or between 3000 and 4999. " + | 558 "The code must be either 1000, or between 3000 and 4999. " + |
556 String::number(code) + " is neither."); | 559 String::number(code) + " is neither."); |
557 return; | 560 return; |
558 } | 561 } |
559 // Bindings specify USVString, so unpaired surrogates are already replaced w
ith U+FFFD. | 562 // Bindings specify USVString, so unpaired surrogates are already replaced |
| 563 // with U+FFFD. |
560 CString utf8 = reason.utf8(); | 564 CString utf8 = reason.utf8(); |
561 if (utf8.length() > maxReasonSizeInBytes) { | 565 if (utf8.length() > maxReasonSizeInBytes) { |
562 exceptionState.throwDOMException( | 566 exceptionState.throwDOMException( |
563 SyntaxError, "The message must not be greater than " + | 567 SyntaxError, "The message must not be greater than " + |
564 String::number(maxReasonSizeInBytes) + " bytes."); | 568 String::number(maxReasonSizeInBytes) + " bytes."); |
565 return; | 569 return; |
566 } | 570 } |
567 if (!reason.isEmpty() && !reason.is8Bit()) { | 571 if (!reason.isEmpty() && !reason.is8Bit()) { |
568 DCHECK_GT(utf8.length(), 0u); | 572 DCHECK_GT(utf8.length(), 0u); |
569 // reason might contain unpaired surrogates. Reconstruct it from | 573 // reason might contain unpaired surrogates. Reconstruct it from |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
862 | 866 |
863 DEFINE_TRACE(DOMWebSocket) { | 867 DEFINE_TRACE(DOMWebSocket) { |
864 visitor->trace(m_channel); | 868 visitor->trace(m_channel); |
865 visitor->trace(m_eventQueue); | 869 visitor->trace(m_eventQueue); |
866 WebSocketChannelClient::trace(visitor); | 870 WebSocketChannelClient::trace(visitor); |
867 EventTargetWithInlineData::trace(visitor); | 871 EventTargetWithInlineData::trace(visitor); |
868 ActiveDOMObject::trace(visitor); | 872 ActiveDOMObject::trace(visitor); |
869 } | 873 } |
870 | 874 |
871 } // namespace blink | 875 } // namespace blink |
OLD | NEW |