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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 DOMWebSocket::~DOMWebSocket() | 241 DOMWebSocket::~DOMWebSocket() |
242 { | 242 { |
243 ASSERT(!m_channel); | 243 ASSERT(!m_channel); |
244 } | 244 } |
245 | 245 |
246 void DOMWebSocket::logError(const String& message) | 246 void DOMWebSocket::logError(const String& message) |
247 { | 247 { |
248 executionContext()->addConsoleMessage(ConsoleMessage::create(JSMessageSource
, ErrorMessageLevel, message)); | 248 executionContext()->addConsoleMessage(ConsoleMessage::create(JSMessageSource
, ErrorMessageLevel, message)); |
249 } | 249 } |
250 | 250 |
251 DOMWebSocket* DOMWebSocket::create(ExecutionContext* context, const String& url,
ExceptionState& exceptionState) | |
252 { | |
253 Vector<String> protocols; | |
254 return create(context, url, protocols, exceptionState); | |
255 } | |
256 | |
257 DOMWebSocket* DOMWebSocket::create(ExecutionContext* context, const String& url,
const Vector<String>& protocols, ExceptionState& exceptionState) | 251 DOMWebSocket* DOMWebSocket::create(ExecutionContext* context, const String& url,
const Vector<String>& protocols, ExceptionState& exceptionState) |
258 { | 252 { |
259 if (url.isNull()) { | 253 if (url.isNull()) { |
260 exceptionState.throwDOMException(SyntaxError, "Failed to create a WebSoc
ket: the provided URL is invalid."); | 254 exceptionState.throwDOMException(SyntaxError, "Failed to create a WebSoc
ket: the provided URL is invalid."); |
261 return nullptr; | 255 return nullptr; |
262 } | 256 } |
263 | 257 |
264 DOMWebSocket* webSocket(adoptRefCountedGarbageCollectedWillBeNoop(new DOMWeb
Socket(context))); | 258 DOMWebSocket* webSocket(adoptRefCountedGarbageCollectedWillBeNoop(new DOMWeb
Socket(context))); |
265 webSocket->suspendIfNeeded(); | 259 webSocket->suspendIfNeeded(); |
266 | 260 |
267 webSocket->connect(url, protocols, exceptionState); | 261 webSocket->connect(url, protocols, exceptionState); |
268 if (exceptionState.hadException()) | 262 if (exceptionState.hadException()) |
269 return nullptr; | 263 return nullptr; |
270 | 264 |
271 return webSocket; | 265 return webSocket; |
272 } | 266 } |
273 | 267 |
274 DOMWebSocket* DOMWebSocket::create(ExecutionContext* context, const String& url,
const String& protocol, ExceptionState& exceptionState) | 268 DOMWebSocket* DOMWebSocket::create(ExecutionContext* context, const String& url,
const String& protocol, ExceptionState& exceptionState) |
275 { | 269 { |
276 Vector<String> protocols; | 270 Vector<String> protocols; |
277 protocols.append(protocol); | 271 if (!protocol.isNull()) |
| 272 protocols.append(protocol); |
278 return create(context, url, protocols, exceptionState); | 273 return create(context, url, protocols, exceptionState); |
279 } | 274 } |
280 | 275 |
281 void DOMWebSocket::connect(const String& url, const Vector<String>& protocols, E
xceptionState& exceptionState) | 276 void DOMWebSocket::connect(const String& url, const Vector<String>& protocols, E
xceptionState& exceptionState) |
282 { | 277 { |
283 WTF_LOG(Network, "WebSocket %p connect() url='%s'", this, url.utf8().data())
; | 278 WTF_LOG(Network, "WebSocket %p connect() url='%s'", this, url.utf8().data())
; |
284 m_url = KURL(KURL(), url); | 279 m_url = KURL(KURL(), url); |
285 | 280 |
286 if (!m_url.isValid()) { | 281 if (!m_url.isValid()) { |
287 m_state = CLOSED; | 282 m_state = CLOSED; |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 if (m_state == CLOSING || m_state == CLOSED) { | 435 if (m_state == CLOSING || m_state == CLOSED) { |
441 updateBufferedAmountAfterClose(static_cast<unsigned long>(binaryData->si
ze())); | 436 updateBufferedAmountAfterClose(static_cast<unsigned long>(binaryData->si
ze())); |
442 return; | 437 return; |
443 } | 438 } |
444 Platform::current()->histogramEnumeration("WebCore.WebSocket.SendType", WebS
ocketSendTypeBlob, WebSocketSendTypeMax); | 439 Platform::current()->histogramEnumeration("WebCore.WebSocket.SendType", WebS
ocketSendTypeBlob, WebSocketSendTypeMax); |
445 m_bufferedAmount += binaryData->size(); | 440 m_bufferedAmount += binaryData->size(); |
446 ASSERT(m_channel); | 441 ASSERT(m_channel); |
447 m_channel->send(binaryData->blobDataHandle()); | 442 m_channel->send(binaryData->blobDataHandle()); |
448 } | 443 } |
449 | 444 |
450 void DOMWebSocket::close(unsigned short code, const String& reason, ExceptionSta
te& exceptionState) | 445 void DOMWebSocket::close(Optional<unsigned short> optionalCode, const String& re
ason, ExceptionState& exceptionState) |
451 { | 446 { |
452 closeInternal(code, reason, exceptionState); | 447 closeInternal(optionalCode.isMissing() ? WebSocketChannel::CloseEventCodeNot
Specified : optionalCode.get(), reason, exceptionState); |
453 } | |
454 | |
455 void DOMWebSocket::close(ExceptionState& exceptionState) | |
456 { | |
457 closeInternal(WebSocketChannel::CloseEventCodeNotSpecified, String(), except
ionState); | |
458 } | |
459 | |
460 void DOMWebSocket::close(unsigned short code, ExceptionState& exceptionState) | |
461 { | |
462 closeInternal(code, String(), exceptionState); | |
463 } | 448 } |
464 | 449 |
465 void DOMWebSocket::closeInternal(int code, const String& reason, ExceptionState&
exceptionState) | 450 void DOMWebSocket::closeInternal(int code, const String& reason, ExceptionState&
exceptionState) |
466 { | 451 { |
467 if (code == WebSocketChannel::CloseEventCodeNotSpecified) { | 452 if (code == WebSocketChannel::CloseEventCodeNotSpecified) { |
468 WTF_LOG(Network, "WebSocket %p close() without code and reason", this); | 453 WTF_LOG(Network, "WebSocket %p close() without code and reason", this); |
469 } else { | 454 } else { |
470 WTF_LOG(Network, "WebSocket %p close() code=%d reason='%s'", this, code,
reason.utf8().data()); | 455 WTF_LOG(Network, "WebSocket %p close() code=%d reason='%s'", this, code,
reason.utf8().data()); |
471 if (!(code == WebSocketChannel::CloseEventCodeNormalClosure || (WebSocke
tChannel::CloseEventCodeMinimumUserDefined <= code && code <= WebSocketChannel::
CloseEventCodeMaximumUserDefined))) { | 456 if (!(code == WebSocketChannel::CloseEventCodeNormalClosure || (WebSocke
tChannel::CloseEventCodeMinimumUserDefined <= code && code <= WebSocketChannel::
CloseEventCodeMaximumUserDefined))) { |
472 exceptionState.throwDOMException(InvalidAccessError, "The code must
be either 1000, or between 3000 and 4999. " + String::number(code) + " is neithe
r."); | 457 exceptionState.throwDOMException(InvalidAccessError, "The code must
be either 1000, or between 3000 and 4999. " + String::number(code) + " is neithe
r."); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 | 673 |
689 void DOMWebSocket::trace(Visitor* visitor) | 674 void DOMWebSocket::trace(Visitor* visitor) |
690 { | 675 { |
691 visitor->trace(m_channel); | 676 visitor->trace(m_channel); |
692 visitor->trace(m_eventQueue); | 677 visitor->trace(m_eventQueue); |
693 WebSocketChannelClient::trace(visitor); | 678 WebSocketChannelClient::trace(visitor); |
694 EventTargetWithInlineData::trace(visitor); | 679 EventTargetWithInlineData::trace(visitor); |
695 } | 680 } |
696 | 681 |
697 } // namespace blink | 682 } // namespace blink |
OLD | NEW |