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 15 matching lines...) Expand all Loading... | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "modules/websockets/DOMWebSocket.h" | 32 #include "modules/websockets/DOMWebSocket.h" |
33 | 33 |
34 #include "bindings/core/v8/ExceptionState.h" | 34 #include "bindings/core/v8/ExceptionState.h" |
35 #include "bindings/core/v8/ScriptController.h" | 35 #include "bindings/core/v8/ScriptController.h" |
36 #include "bindings/modules/v8/UnionTypesModules.h" | |
36 #include "core/dom/DOMArrayBuffer.h" | 37 #include "core/dom/DOMArrayBuffer.h" |
37 #include "core/dom/DOMArrayBufferView.h" | 38 #include "core/dom/DOMArrayBufferView.h" |
38 #include "core/dom/Document.h" | 39 #include "core/dom/Document.h" |
39 #include "core/dom/ExceptionCode.h" | 40 #include "core/dom/ExceptionCode.h" |
40 #include "core/dom/ExecutionContext.h" | 41 #include "core/dom/ExecutionContext.h" |
41 #include "core/dom/SecurityContext.h" | 42 #include "core/dom/SecurityContext.h" |
42 #include "core/events/MessageEvent.h" | 43 #include "core/events/MessageEvent.h" |
43 #include "core/fileapi/Blob.h" | 44 #include "core/fileapi/Blob.h" |
44 #include "core/frame/ConsoleTypes.h" | 45 #include "core/frame/ConsoleTypes.h" |
45 #include "core/frame/LocalDOMWindow.h" | 46 #include "core/frame/LocalDOMWindow.h" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 ASSERT(!m_channel); | 236 ASSERT(!m_channel); |
236 } | 237 } |
237 | 238 |
238 void DOMWebSocket::logError(const String& message) | 239 void DOMWebSocket::logError(const String& message) |
239 { | 240 { |
240 executionContext()->addConsoleMessage(ConsoleMessage::create(JSMessageSource , ErrorMessageLevel, message)); | 241 executionContext()->addConsoleMessage(ConsoleMessage::create(JSMessageSource , ErrorMessageLevel, message)); |
241 } | 242 } |
242 | 243 |
243 DOMWebSocket* DOMWebSocket::create(ExecutionContext* context, const String& url, ExceptionState& exceptionState) | 244 DOMWebSocket* DOMWebSocket::create(ExecutionContext* context, const String& url, ExceptionState& exceptionState) |
244 { | 245 { |
245 Vector<String> protocols; | 246 StringOrStringSequence protocols; |
246 return create(context, url, protocols, exceptionState); | 247 return create(context, url, protocols, exceptionState); |
247 } | 248 } |
248 | 249 |
249 DOMWebSocket* DOMWebSocket::create(ExecutionContext* context, const String& url, const Vector<String>& protocols, ExceptionState& exceptionState) | 250 DOMWebSocket* DOMWebSocket::create(ExecutionContext* context, const String& url, const StringOrStringSequence& protocols, ExceptionState& exceptionState) |
250 { | 251 { |
251 if (url.isNull()) { | 252 if (url.isNull()) { |
252 exceptionState.throwDOMException(SyntaxError, "Failed to create a WebSoc ket: the provided URL is invalid."); | 253 exceptionState.throwDOMException(SyntaxError, "Failed to create a WebSoc ket: the provided URL is invalid."); |
253 return nullptr; | 254 return nullptr; |
254 } | 255 } |
255 | 256 |
256 DOMWebSocket* webSocket = new DOMWebSocket(context); | 257 DOMWebSocket* webSocket = new DOMWebSocket(context); |
257 webSocket->suspendIfNeeded(); | 258 webSocket->suspendIfNeeded(); |
258 | 259 |
259 webSocket->connect(url, protocols, exceptionState); | 260 if (protocols.isNull()) { |
261 Vector<String> protocolsVector; | |
262 webSocket->connect(url, protocolsVector, exceptionState); | |
263 } else if (protocols.isString()) { | |
264 Vector<String> protocolsVector; | |
265 protocolsVector.append(protocols.getAsString()); | |
266 webSocket->connect(url, protocolsVector, exceptionState); | |
267 } else { | |
268 ASSERT(protocols.isStringSequence()); | |
269 webSocket->connect(url, protocols.getAsStringSequence(), exceptionState) ; | |
270 } | |
271 | |
260 if (exceptionState.hadException()) | 272 if (exceptionState.hadException()) |
261 return nullptr; | 273 return nullptr; |
262 | 274 |
263 return webSocket; | 275 return webSocket; |
264 } | 276 } |
265 | 277 |
266 DOMWebSocket* DOMWebSocket::create(ExecutionContext* context, const String& url, const String& protocol, ExceptionState& exceptionState) | |
267 { | |
268 Vector<String> protocols; | |
269 protocols.append(protocol); | |
270 return create(context, url, protocols, exceptionState); | |
271 } | |
272 | |
273 void DOMWebSocket::connect(const String& url, const Vector<String>& protocols, E xceptionState& exceptionState) | 278 void DOMWebSocket::connect(const String& url, const Vector<String>& protocols, E xceptionState& exceptionState) |
274 { | 279 { |
275 | 280 |
276 WTF_LOG(Network, "WebSocket %p connect() url='%s'", this, url.utf8().data()) ; | 281 WTF_LOG(Network, "WebSocket %p connect() url='%s'", this, url.utf8().data()) ; |
277 m_url = KURL(KURL(), url); | 282 m_url = KURL(KURL(), url); |
278 | 283 |
279 if (executionContext()->securityContext().insecureContentPolicy() == Securit yContext::InsecureContentUpgrade && m_url.protocol() == "ws") { | 284 if (executionContext()->securityContext().insecureContentPolicy() == Securit yContext::InsecureContentUpgrade && m_url.protocol() == "ws") { |
280 m_url.setProtocol("wss"); | 285 m_url.setProtocol("wss"); |
281 if (m_url.port() == 80) | 286 if (m_url.port() == 80) |
282 m_url.setPort(443); | 287 m_url.setPort(443); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
460 void DOMWebSocket::closeInternal(int code, const String& reason, ExceptionState& exceptionState) | 465 void DOMWebSocket::closeInternal(int code, const String& reason, ExceptionState& exceptionState) |
461 { | 466 { |
462 if (code == WebSocketChannel::CloseEventCodeNotSpecified) { | 467 if (code == WebSocketChannel::CloseEventCodeNotSpecified) { |
463 WTF_LOG(Network, "WebSocket %p close() without code and reason", this); | 468 WTF_LOG(Network, "WebSocket %p close() without code and reason", this); |
464 } else { | 469 } else { |
465 WTF_LOG(Network, "WebSocket %p close() code=%d reason='%s'", this, code, reason.utf8().data()); | 470 WTF_LOG(Network, "WebSocket %p close() code=%d reason='%s'", this, code, reason.utf8().data()); |
466 if (!(code == WebSocketChannel::CloseEventCodeNormalClosure || (WebSocke tChannel::CloseEventCodeMinimumUserDefined <= code && code <= WebSocketChannel:: CloseEventCodeMaximumUserDefined))) { | 471 if (!(code == WebSocketChannel::CloseEventCodeNormalClosure || (WebSocke tChannel::CloseEventCodeMinimumUserDefined <= code && code <= WebSocketChannel:: CloseEventCodeMaximumUserDefined))) { |
467 exceptionState.throwDOMException(InvalidAccessError, "The code must be either 1000, or between 3000 and 4999. " + String::number(code) + " is neithe r."); | 472 exceptionState.throwDOMException(InvalidAccessError, "The code must be either 1000, or between 3000 and 4999. " + String::number(code) + " is neithe r."); |
468 return; | 473 return; |
469 } | 474 } |
470 CString utf8 = reason.utf8(StrictUTF8ConversionReplacingUnpairedSurrogat esWithFFFD); | 475 // Bindings specify USVString, so unpaired surrogates are already replac ed with U+FFFD. |
jsbell
2015/02/25 18:51:11
Is this comment helpful here, or just let the bind
philipj_slow
2015/02/26 03:02:53
Someone very familiar with bindings and the distin
jsbell
2015/02/26 05:45:18
That'd be me (I implemented our USVString handling
| |
476 CString utf8 = reason.utf8(); | |
471 if (utf8.length() > maxReasonSizeInBytes) { | 477 if (utf8.length() > maxReasonSizeInBytes) { |
472 exceptionState.throwDOMException(SyntaxError, "The message must not be greater than " + String::number(maxReasonSizeInBytes) + " bytes."); | 478 exceptionState.throwDOMException(SyntaxError, "The message must not be greater than " + String::number(maxReasonSizeInBytes) + " bytes."); |
473 return; | 479 return; |
474 } | 480 } |
475 } | 481 } |
476 | 482 |
477 if (m_state == CLOSING || m_state == CLOSED) | 483 if (m_state == CLOSING || m_state == CLOSED) |
478 return; | 484 return; |
479 if (m_state == CONNECTING) { | 485 if (m_state == CONNECTING) { |
480 m_state = CLOSING; | 486 m_state = CLOSING; |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
666 DEFINE_TRACE(DOMWebSocket) | 672 DEFINE_TRACE(DOMWebSocket) |
667 { | 673 { |
668 visitor->trace(m_channel); | 674 visitor->trace(m_channel); |
669 visitor->trace(m_eventQueue); | 675 visitor->trace(m_eventQueue); |
670 WebSocketChannelClient::trace(visitor); | 676 WebSocketChannelClient::trace(visitor); |
671 RefCountedGarbageCollectedEventTargetWithInlineData<DOMWebSocket>::trace(vis itor); | 677 RefCountedGarbageCollectedEventTargetWithInlineData<DOMWebSocket>::trace(vis itor); |
672 ActiveDOMObject::trace(visitor); | 678 ActiveDOMObject::trace(visitor); |
673 } | 679 } |
674 | 680 |
675 } // namespace blink | 681 } // namespace blink |
OLD | NEW |