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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 | 306 |
307 if (!m_url.isValid()) { | 307 if (!m_url.isValid()) { |
308 m_state = kClosed; | 308 m_state = kClosed; |
309 exceptionState.throwDOMException(SyntaxError, | 309 exceptionState.throwDOMException(SyntaxError, |
310 "The URL '" + url + "' is invalid."); | 310 "The URL '" + url + "' is invalid."); |
311 return; | 311 return; |
312 } | 312 } |
313 if (!m_url.protocolIs("ws") && !m_url.protocolIs("wss")) { | 313 if (!m_url.protocolIs("ws") && !m_url.protocolIs("wss")) { |
314 m_state = kClosed; | 314 m_state = kClosed; |
315 exceptionState.throwDOMException( | 315 exceptionState.throwDOMException( |
316 SyntaxError, "The URL's scheme must be either 'ws' or 'wss'. '" + | 316 SyntaxError, |
317 m_url.protocol() + "' is not allowed."); | 317 "The URL's scheme must be either 'ws' or 'wss'. '" + m_url.protocol() + |
| 318 "' is not allowed."); |
318 return; | 319 return; |
319 } | 320 } |
320 | 321 |
321 if (m_url.hasFragmentIdentifier()) { | 322 if (m_url.hasFragmentIdentifier()) { |
322 m_state = kClosed; | 323 m_state = kClosed; |
323 exceptionState.throwDOMException( | 324 exceptionState.throwDOMException( |
324 SyntaxError, | 325 SyntaxError, |
325 "The URL contains a fragment identifier ('" + | 326 "The URL contains a fragment identifier ('" + |
326 m_url.fragmentIdentifier() + | 327 m_url.fragmentIdentifier() + |
327 "'). Fragment identifiers are not allowed in WebSocket URLs."); | 328 "'). Fragment identifiers are not allowed in WebSocket URLs."); |
(...skipping 19 matching lines...) Expand all Loading... |
347 "Refused to connect to '" + m_url.elidedString() + | 348 "Refused to connect to '" + m_url.elidedString() + |
348 "' because it violates the document's Content Security Policy."); | 349 "' because it violates the document's Content Security Policy."); |
349 return; | 350 return; |
350 } | 351 } |
351 | 352 |
352 // Fail if not all elements in |protocols| are valid. | 353 // Fail if not all elements in |protocols| are valid. |
353 for (size_t i = 0; i < protocols.size(); ++i) { | 354 for (size_t i = 0; i < protocols.size(); ++i) { |
354 if (!isValidSubprotocolString(protocols[i])) { | 355 if (!isValidSubprotocolString(protocols[i])) { |
355 m_state = kClosed; | 356 m_state = kClosed; |
356 exceptionState.throwDOMException( | 357 exceptionState.throwDOMException( |
357 SyntaxError, "The subprotocol '" + | 358 SyntaxError, |
358 encodeSubprotocolString(protocols[i]) + | 359 "The subprotocol '" + encodeSubprotocolString(protocols[i]) + |
359 "' is invalid."); | 360 "' is invalid."); |
360 return; | 361 return; |
361 } | 362 } |
362 } | 363 } |
363 | 364 |
364 // Fail if there're duplicated elements in |protocols|. | 365 // Fail if there're duplicated elements in |protocols|. |
365 HashSet<String> visited; | 366 HashSet<String> visited; |
366 for (size_t i = 0; i < protocols.size(); ++i) { | 367 for (size_t i = 0; i < protocols.size(); ++i) { |
367 if (!visited.insert(protocols[i]).isNewEntry) { | 368 if (!visited.insert(protocols[i]).isNewEntry) { |
368 m_state = kClosed; | 369 m_state = kClosed; |
369 exceptionState.throwDOMException( | 370 exceptionState.throwDOMException( |
370 SyntaxError, "The subprotocol '" + | 371 SyntaxError, |
371 encodeSubprotocolString(protocols[i]) + | 372 "The subprotocol '" + encodeSubprotocolString(protocols[i]) + |
372 "' is duplicated."); | 373 "' is duplicated."); |
373 return; | 374 return; |
374 } | 375 } |
375 } | 376 } |
376 | 377 |
377 if (getExecutionContext()->getSecurityOrigin()->hasSuborigin()) { | 378 if (getExecutionContext()->getSecurityOrigin()->hasSuborigin()) { |
378 m_state = kClosed; | 379 m_state = kClosed; |
379 exceptionState.throwSecurityError( | 380 exceptionState.throwSecurityError( |
380 "Connecting to a WebSocket from a suborigin is not allowed."); | 381 "Connecting to a WebSocket from a suborigin is not allowed."); |
381 return; | 382 return; |
382 } | 383 } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 InvalidAccessError, | 562 InvalidAccessError, |
562 "The code must be either 1000, or between 3000 and 4999. " + | 563 "The code must be either 1000, or between 3000 and 4999. " + |
563 String::number(code) + " is neither."); | 564 String::number(code) + " is neither."); |
564 return; | 565 return; |
565 } | 566 } |
566 // Bindings specify USVString, so unpaired surrogates are already replaced | 567 // Bindings specify USVString, so unpaired surrogates are already replaced |
567 // with U+FFFD. | 568 // with U+FFFD. |
568 CString utf8 = reason.utf8(); | 569 CString utf8 = reason.utf8(); |
569 if (utf8.length() > maxReasonSizeInBytes) { | 570 if (utf8.length() > maxReasonSizeInBytes) { |
570 exceptionState.throwDOMException( | 571 exceptionState.throwDOMException( |
571 SyntaxError, "The message must not be greater than " + | 572 SyntaxError, |
572 String::number(maxReasonSizeInBytes) + " bytes."); | 573 "The message must not be greater than " + |
| 574 String::number(maxReasonSizeInBytes) + " bytes."); |
573 return; | 575 return; |
574 } | 576 } |
575 if (!reason.isEmpty() && !reason.is8Bit()) { | 577 if (!reason.isEmpty() && !reason.is8Bit()) { |
576 DCHECK_GT(utf8.length(), 0u); | 578 DCHECK_GT(utf8.length(), 0u); |
577 // reason might contain unpaired surrogates. Reconstruct it from | 579 // reason might contain unpaired surrogates. Reconstruct it from |
578 // utf8. | 580 // utf8. |
579 cleansedReason = String::fromUTF8(utf8.data(), utf8.length()); | 581 cleansedReason = String::fromUTF8(utf8.data(), utf8.length()); |
580 } | 582 } |
581 } | 583 } |
582 | 584 |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 | 866 |
865 DEFINE_TRACE(DOMWebSocket) { | 867 DEFINE_TRACE(DOMWebSocket) { |
866 visitor->trace(m_channel); | 868 visitor->trace(m_channel); |
867 visitor->trace(m_eventQueue); | 869 visitor->trace(m_eventQueue); |
868 WebSocketChannelClient::trace(visitor); | 870 WebSocketChannelClient::trace(visitor); |
869 EventTargetWithInlineData::trace(visitor); | 871 EventTargetWithInlineData::trace(visitor); |
870 SuspendableObject::trace(visitor); | 872 SuspendableObject::trace(visitor); |
871 } | 873 } |
872 | 874 |
873 } // namespace blink | 875 } // namespace blink |
OLD | NEW |