Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Side by Side Diff: Source/modules/websockets/DOMWebSocket.cpp

Issue 954933003: Sync the WebSocket interface with the spec (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add TypeChecking=Interface Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 { 466 {
462 String cleansedReason = reason; 467 String cleansedReason = reason;
463 if (code == WebSocketChannel::CloseEventCodeNotSpecified) { 468 if (code == WebSocketChannel::CloseEventCodeNotSpecified) {
464 WTF_LOG(Network, "WebSocket %p close() without code and reason", this); 469 WTF_LOG(Network, "WebSocket %p close() without code and reason", this);
465 } else { 470 } else {
466 WTF_LOG(Network, "WebSocket %p close() code=%d reason='%s'", this, code, reason.utf8().data()); 471 WTF_LOG(Network, "WebSocket %p close() code=%d reason='%s'", this, code, reason.utf8().data());
467 if (!(code == WebSocketChannel::CloseEventCodeNormalClosure || (WebSocke tChannel::CloseEventCodeMinimumUserDefined <= code && code <= WebSocketChannel:: CloseEventCodeMaximumUserDefined))) { 472 if (!(code == WebSocketChannel::CloseEventCodeNormalClosure || (WebSocke tChannel::CloseEventCodeMinimumUserDefined <= code && code <= WebSocketChannel:: CloseEventCodeMaximumUserDefined))) {
468 exceptionState.throwDOMException(InvalidAccessError, "The code must be either 1000, or between 3000 and 4999. " + String::number(code) + " is neithe r."); 473 exceptionState.throwDOMException(InvalidAccessError, "The code must be either 1000, or between 3000 and 4999. " + String::number(code) + " is neithe r.");
469 return; 474 return;
470 } 475 }
471 CString utf8 = reason.utf8(StrictUTF8ConversionReplacingUnpairedSurrogat esWithFFFD); 476 // Bindings specify USVString, so unpaired surrogates are already replac ed with U+FFFD.
477 CString utf8 = reason.utf8();
472 if (utf8.length() > maxReasonSizeInBytes) { 478 if (utf8.length() > maxReasonSizeInBytes) {
473 exceptionState.throwDOMException(SyntaxError, "The message must not be greater than " + String::number(maxReasonSizeInBytes) + " bytes."); 479 exceptionState.throwDOMException(SyntaxError, "The message must not be greater than " + String::number(maxReasonSizeInBytes) + " bytes.");
474 return; 480 return;
475 } 481 }
476 if (!reason.isEmpty() && !reason.is8Bit()) { 482 if (!reason.isEmpty() && !reason.is8Bit()) {
477 ASSERT(utf8.length() > 0); 483 ASSERT(utf8.length() > 0);
478 // reason might contain unpaired surrogates. Reconstruct it from 484 // reason might contain unpaired surrogates. Reconstruct it from
479 // utf8. 485 // utf8.
480 cleansedReason = String::fromUTF8(utf8.data(), utf8.length()); 486 cleansedReason = String::fromUTF8(utf8.data(), utf8.length());
481 } 487 }
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 DEFINE_TRACE(DOMWebSocket) 679 DEFINE_TRACE(DOMWebSocket)
674 { 680 {
675 visitor->trace(m_channel); 681 visitor->trace(m_channel);
676 visitor->trace(m_eventQueue); 682 visitor->trace(m_eventQueue);
677 WebSocketChannelClient::trace(visitor); 683 WebSocketChannelClient::trace(visitor);
678 RefCountedGarbageCollectedEventTargetWithInlineData<DOMWebSocket>::trace(vis itor); 684 RefCountedGarbageCollectedEventTargetWithInlineData<DOMWebSocket>::trace(vis itor);
679 ActiveDOMObject::trace(visitor); 685 ActiveDOMObject::trace(visitor);
680 } 686 }
681 687
682 } // namespace blink 688 } // namespace blink
OLDNEW
« no previous file with comments | « Source/modules/websockets/DOMWebSocket.h ('k') | Source/modules/websockets/DocumentWebSocketChannel.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698