| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 m_channel->didFinishLoadingBlob(m_loader.arrayBufferResult()); | 102 m_channel->didFinishLoadingBlob(m_loader.arrayBufferResult()); |
| 103 // |this| is deleted here. | 103 // |this| is deleted here. |
| 104 } | 104 } |
| 105 | 105 |
| 106 void NewWebSocketChannelImpl::BlobLoader::didFail(FileError::ErrorCode errorCode
) | 106 void NewWebSocketChannelImpl::BlobLoader::didFail(FileError::ErrorCode errorCode
) |
| 107 { | 107 { |
| 108 m_channel->didFailLoadingBlob(errorCode); | 108 m_channel->didFailLoadingBlob(errorCode); |
| 109 // |this| is deleted here. | 109 // |this| is deleted here. |
| 110 } | 110 } |
| 111 | 111 |
| 112 NewWebSocketChannelImpl::NewWebSocketChannelImpl(ExecutionContext* context, WebS
ocketChannelClient* client, const String& sourceURL, unsigned lineNumber, blink:
:WebSocketHandle *handle) | 112 NewWebSocketChannelImpl::NewWebSocketChannelImpl(ExecutionContext* context, WebS
ocketChannelClient* client, const String& sourceURL, unsigned lineNumber, WebSoc
ketHandle *handle) |
| 113 : ContextLifecycleObserver(context) | 113 : ContextLifecycleObserver(context) |
| 114 , m_handle(adoptPtr(handle ? handle : blink::Platform::current()->createWebS
ocketHandle())) | 114 , m_handle(adoptPtr(handle ? handle : Platform::current()->createWebSocketHa
ndle())) |
| 115 , m_client(client) | 115 , m_client(client) |
| 116 , m_identifier(0) | 116 , m_identifier(0) |
| 117 , m_sendingQuota(0) | 117 , m_sendingQuota(0) |
| 118 , m_receivedDataSizeForFlowControl(receivedDataSizeForFlowControlHighWaterMa
rk * 2) // initial quota | 118 , m_receivedDataSizeForFlowControl(receivedDataSizeForFlowControlHighWaterMa
rk * 2) // initial quota |
| 119 , m_sentSizeOfTopMessage(0) | 119 , m_sentSizeOfTopMessage(0) |
| 120 , m_sourceURLAtConstruction(sourceURL) | 120 , m_sourceURLAtConstruction(sourceURL) |
| 121 , m_lineNumberAtConstruction(lineNumber) | 121 , m_lineNumberAtConstruction(lineNumber) |
| 122 { | 122 { |
| 123 if (context->isDocument() && toDocument(context)->page()) | 123 if (context->isDocument() && toDocument(context)->page()) |
| 124 m_identifier = createUniqueIdentifier(); | 124 m_identifier = createUniqueIdentifier(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 146 | 146 |
| 147 m_url = url; | 147 m_url = url; |
| 148 Vector<String> protocols; | 148 Vector<String> protocols; |
| 149 // Avoid placing an empty token in the Vector when the protocol string is | 149 // Avoid placing an empty token in the Vector when the protocol string is |
| 150 // empty. | 150 // empty. |
| 151 if (!protocol.isEmpty()) { | 151 if (!protocol.isEmpty()) { |
| 152 // Since protocol is already verified and escaped, we can simply split | 152 // Since protocol is already verified and escaped, we can simply split |
| 153 // it. | 153 // it. |
| 154 protocol.split(", ", true, protocols); | 154 protocol.split(", ", true, protocols); |
| 155 } | 155 } |
| 156 blink::WebVector<blink::WebString> webProtocols(protocols.size()); | 156 WebVector<WebString> webProtocols(protocols.size()); |
| 157 for (size_t i = 0; i < protocols.size(); ++i) { | 157 for (size_t i = 0; i < protocols.size(); ++i) { |
| 158 webProtocols[i] = protocols[i]; | 158 webProtocols[i] = protocols[i]; |
| 159 } | 159 } |
| 160 | 160 |
| 161 if (executionContext()->isDocument() && document()->frame()) | 161 if (executionContext()->isDocument() && document()->frame()) |
| 162 document()->frame()->loader().client()->dispatchWillOpenWebSocket(m_hand
le.get()); | 162 document()->frame()->loader().client()->dispatchWillOpenWebSocket(m_hand
le.get()); |
| 163 m_handle->connect(url, webProtocols, *executionContext()->securityOrigin(),
this); | 163 m_handle->connect(url, webProtocols, *executionContext()->securityOrigin(),
this); |
| 164 | 164 |
| 165 flowControlIfNecessary(); | 165 flowControlIfNecessary(); |
| 166 if (m_identifier) { | 166 if (m_identifier) { |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 } | 397 } |
| 398 | 398 |
| 399 Document* NewWebSocketChannelImpl::document() | 399 Document* NewWebSocketChannelImpl::document() |
| 400 { | 400 { |
| 401 ASSERT(m_identifier); | 401 ASSERT(m_identifier); |
| 402 ExecutionContext* context = executionContext(); | 402 ExecutionContext* context = executionContext(); |
| 403 ASSERT(context->isDocument()); | 403 ASSERT(context->isDocument()); |
| 404 return toDocument(context); | 404 return toDocument(context); |
| 405 } | 405 } |
| 406 | 406 |
| 407 void NewWebSocketChannelImpl::didConnect(WebSocketHandle* handle, bool fail, con
st blink::WebString& selectedProtocol, const blink::WebString& extensions) | 407 void NewWebSocketChannelImpl::didConnect(WebSocketHandle* handle, bool fail, con
st WebString& selectedProtocol, const WebString& extensions) |
| 408 { | 408 { |
| 409 WTF_LOG(Network, "NewWebSocketChannelImpl %p didConnect(%p, %d, %s, %s)", th
is, handle, fail, selectedProtocol.utf8().data(), extensions.utf8().data()); | 409 WTF_LOG(Network, "NewWebSocketChannelImpl %p didConnect(%p, %d, %s, %s)", th
is, handle, fail, selectedProtocol.utf8().data(), extensions.utf8().data()); |
| 410 ASSERT(m_handle); | 410 ASSERT(m_handle); |
| 411 ASSERT(handle == m_handle); | 411 ASSERT(handle == m_handle); |
| 412 ASSERT(m_client); | 412 ASSERT(m_client); |
| 413 if (fail) { | 413 if (fail) { |
| 414 failAsError("Cannot connect to " + m_url.string() + "."); | 414 failAsError("Cannot connect to " + m_url.string() + "."); |
| 415 // failAsError may delete this object. | 415 // failAsError may delete this object. |
| 416 return; | 416 return; |
| 417 } | 417 } |
| 418 m_client->didConnect(selectedProtocol, extensions); | 418 m_client->didConnect(selectedProtocol, extensions); |
| 419 } | 419 } |
| 420 | 420 |
| 421 void NewWebSocketChannelImpl::didStartOpeningHandshake(WebSocketHandle* handle,
const blink::WebSocketHandshakeRequestInfo& request) | 421 void NewWebSocketChannelImpl::didStartOpeningHandshake(WebSocketHandle* handle,
const WebSocketHandshakeRequestInfo& request) |
| 422 { | 422 { |
| 423 WTF_LOG(Network, "NewWebSocketChannelImpl %p didStartOpeningHandshake(%p)",
this, handle); | 423 WTF_LOG(Network, "NewWebSocketChannelImpl %p didStartOpeningHandshake(%p)",
this, handle); |
| 424 if (m_identifier) { | 424 if (m_identifier) { |
| 425 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "We
bSocketSendHandshakeRequest", "data", InspectorWebSocketEvent::data(document(),
m_identifier)); | 425 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "We
bSocketSendHandshakeRequest", "data", InspectorWebSocketEvent::data(document(),
m_identifier)); |
| 426 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"
), "CallStack", "stack", InspectorCallStackEvent::currentCallStack()); | 426 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"
), "CallStack", "stack", InspectorCallStackEvent::currentCallStack()); |
| 427 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Ti
meline migrates to tracing. | 427 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Ti
meline migrates to tracing. |
| 428 InspectorInstrumentation::willSendWebSocketHandshakeRequest(document(),
m_identifier, &request.toCoreRequest()); | 428 InspectorInstrumentation::willSendWebSocketHandshakeRequest(document(),
m_identifier, &request.toCoreRequest()); |
| 429 m_handshakeRequest = WebSocketHandshakeRequest::create(request.toCoreReq
uest()); | 429 m_handshakeRequest = WebSocketHandshakeRequest::create(request.toCoreReq
uest()); |
| 430 } | 430 } |
| 431 } | 431 } |
| 432 | 432 |
| 433 void NewWebSocketChannelImpl::didFinishOpeningHandshake(WebSocketHandle* handle,
const blink::WebSocketHandshakeResponseInfo& response) | 433 void NewWebSocketChannelImpl::didFinishOpeningHandshake(WebSocketHandle* handle,
const WebSocketHandshakeResponseInfo& response) |
| 434 { | 434 { |
| 435 WTF_LOG(Network, "NewWebSocketChannelImpl %p didFinishOpeningHandshake(%p)",
this, handle); | 435 WTF_LOG(Network, "NewWebSocketChannelImpl %p didFinishOpeningHandshake(%p)",
this, handle); |
| 436 if (m_identifier) { | 436 if (m_identifier) { |
| 437 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "We
bSocketReceiveHandshakeResponse", "data", InspectorWebSocketEvent::data(document
(), m_identifier)); | 437 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "We
bSocketReceiveHandshakeResponse", "data", InspectorWebSocketEvent::data(document
(), m_identifier)); |
| 438 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Ti
meline migrates to tracing. | 438 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Ti
meline migrates to tracing. |
| 439 InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(document(
), m_identifier, m_handshakeRequest.get(), &response.toCoreResponse()); | 439 InspectorInstrumentation::didReceiveWebSocketHandshakeResponse(document(
), m_identifier, m_handshakeRequest.get(), &response.toCoreResponse()); |
| 440 } | 440 } |
| 441 m_handshakeRequest.clear(); | 441 m_handshakeRequest.clear(); |
| 442 } | 442 } |
| 443 | 443 |
| 444 void NewWebSocketChannelImpl::didFail(WebSocketHandle* handle, const blink::WebS
tring& message) | 444 void NewWebSocketChannelImpl::didFail(WebSocketHandle* handle, const WebString&
message) |
| 445 { | 445 { |
| 446 WTF_LOG(Network, "NewWebSocketChannelImpl %p didFail(%p, %s)", this, handle,
message.utf8().data()); | 446 WTF_LOG(Network, "NewWebSocketChannelImpl %p didFail(%p, %s)", this, handle,
message.utf8().data()); |
| 447 // This function is called when the browser is required to fail the | 447 // This function is called when the browser is required to fail the |
| 448 // WebSocketConnection. Hence we fail this channel by calling | 448 // WebSocketConnection. Hence we fail this channel by calling |
| 449 // |this->failAsError| function. | 449 // |this->failAsError| function. |
| 450 failAsError(message); | 450 failAsError(message); |
| 451 // |this| may be deleted. | 451 // |this| may be deleted. |
| 452 } | 452 } |
| 453 | 453 |
| 454 void NewWebSocketChannelImpl::didReceiveData(WebSocketHandle* handle, bool fin,
WebSocketHandle::MessageType type, const char* data, size_t size) | 454 void NewWebSocketChannelImpl::didReceiveData(WebSocketHandle* handle, bool fin,
WebSocketHandle::MessageType type, const char* data, size_t size) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 } else { | 495 } else { |
| 496 m_client->didReceiveMessage(message); | 496 m_client->didReceiveMessage(message); |
| 497 } | 497 } |
| 498 } else { | 498 } else { |
| 499 OwnPtr<Vector<char> > binaryData = adoptPtr(new Vector<char>); | 499 OwnPtr<Vector<char> > binaryData = adoptPtr(new Vector<char>); |
| 500 binaryData->swap(m_receivingMessageData); | 500 binaryData->swap(m_receivingMessageData); |
| 501 m_client->didReceiveBinaryData(binaryData.release()); | 501 m_client->didReceiveBinaryData(binaryData.release()); |
| 502 } | 502 } |
| 503 } | 503 } |
| 504 | 504 |
| 505 void NewWebSocketChannelImpl::didClose(WebSocketHandle* handle, bool wasClean, u
nsigned short code, const blink::WebString& reason) | 505 void NewWebSocketChannelImpl::didClose(WebSocketHandle* handle, bool wasClean, u
nsigned short code, const WebString& reason) |
| 506 { | 506 { |
| 507 WTF_LOG(Network, "NewWebSocketChannelImpl %p didClose(%p, %d, %u, %s)", this
, handle, wasClean, code, String(reason).utf8().data()); | 507 WTF_LOG(Network, "NewWebSocketChannelImpl %p didClose(%p, %d, %u, %s)", this
, handle, wasClean, code, String(reason).utf8().data()); |
| 508 ASSERT(m_handle); | 508 ASSERT(m_handle); |
| 509 m_handle.clear(); | 509 m_handle.clear(); |
| 510 if (m_identifier) { | 510 if (m_identifier) { |
| 511 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "We
bSocketDestroy", "data", InspectorWebSocketEvent::data(document(), m_identifier)
); | 511 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "We
bSocketDestroy", "data", InspectorWebSocketEvent::data(document(), m_identifier)
); |
| 512 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"
), "CallStack", "stack", InspectorCallStackEvent::currentCallStack()); | 512 TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline.stack"
), "CallStack", "stack", InspectorCallStackEvent::currentCallStack()); |
| 513 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Ti
meline migrates to tracing. | 513 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Ti
meline migrates to tracing. |
| 514 InspectorInstrumentation::didCloseWebSocket(document(), m_identifier); | 514 InspectorInstrumentation::didCloseWebSocket(document(), m_identifier); |
| 515 m_identifier = 0; | 515 m_identifier = 0; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 } | 558 } |
| 559 | 559 |
| 560 void NewWebSocketChannelImpl::trace(Visitor* visitor) | 560 void NewWebSocketChannelImpl::trace(Visitor* visitor) |
| 561 { | 561 { |
| 562 visitor->trace(m_blobLoader); | 562 visitor->trace(m_blobLoader); |
| 563 visitor->trace(m_client); | 563 visitor->trace(m_client); |
| 564 WebSocketChannel::trace(visitor); | 564 WebSocketChannel::trace(visitor); |
| 565 } | 565 } |
| 566 | 566 |
| 567 } // namespace blink | 567 } // namespace blink |
| OLD | NEW |