| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/websockets/WebSocketHandleImpl.h" | 5 #include "modules/websockets/WebSocketHandleImpl.h" |
| 6 | 6 |
| 7 #include "modules/websockets/WebSocketHandleClient.h" | 7 #include "modules/websockets/WebSocketHandleClient.h" |
| 8 #include "platform/network/NetworkLog.h" | 8 #include "platform/network/NetworkLog.h" |
| 9 #include "platform/network/WebSocketHandshakeRequest.h" | 9 #include "platform/network/WebSocketHandshakeRequest.h" |
| 10 #include "platform/network/WebSocketHandshakeResponse.h" | 10 #include "platform/network/WebSocketHandshakeResponse.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 m_websocket->StartClosingHandshake(kAbnormalShutdownOpCode, emptyString(
)); | 38 m_websocket->StartClosingHandshake(kAbnormalShutdownOpCode, emptyString(
)); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void WebSocketHandleImpl::initialize(InterfaceProvider* interfaceProvider) | 41 void WebSocketHandleImpl::initialize(InterfaceProvider* interfaceProvider) |
| 42 { | 42 { |
| 43 NETWORK_DVLOG(1) << this << " initialize(...)"; | 43 NETWORK_DVLOG(1) << this << " initialize(...)"; |
| 44 | 44 |
| 45 DCHECK(!m_websocket); | 45 DCHECK(!m_websocket); |
| 46 interfaceProvider->getInterface(mojo::GetProxy(&m_websocket)); | 46 interfaceProvider->getInterface(mojo::GetProxy(&m_websocket)); |
| 47 | 47 |
| 48 m_websocket.set_connection_error_handler( | 48 m_websocket.set_connection_error_with_reason_handler( |
| 49 convertToBaseCallback(bind(&WebSocketHandleImpl::onConnectionError, unre
tained(this)))); | 49 convertToBaseCallback(WTF::bind(&WebSocketHandleImpl::onConnectionError,
unretained(this)))); |
| 50 } | 50 } |
| 51 | 51 |
| 52 void WebSocketHandleImpl::connect(const KURL& url, const Vector<String>& protoco
ls, SecurityOrigin* origin, const KURL& firstPartyForCookies, const String& user
AgentOverride, WebSocketHandleClient* client) | 52 void WebSocketHandleImpl::connect(const KURL& url, const Vector<String>& protoco
ls, SecurityOrigin* origin, const KURL& firstPartyForCookies, const String& user
AgentOverride, WebSocketHandleClient* client) |
| 53 { | 53 { |
| 54 DCHECK(m_websocket); | 54 DCHECK(m_websocket); |
| 55 | 55 |
| 56 NETWORK_DVLOG(1) << this << " connect(" << url.getString() << ", " << origin
->toString() << ")"; | 56 NETWORK_DVLOG(1) << this << " connect(" << url.getString() << ", " << origin
->toString() << ")"; |
| 57 | 57 |
| 58 DCHECK(!m_client); | 58 DCHECK(!m_client); |
| 59 DCHECK(client); | 59 DCHECK(client); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 115 |
| 116 m_websocket->StartClosingHandshake(code, reason.isNull() ? emptyString() : r
eason); | 116 m_websocket->StartClosingHandshake(code, reason.isNull() ? emptyString() : r
eason); |
| 117 } | 117 } |
| 118 | 118 |
| 119 void WebSocketHandleImpl::disconnect() | 119 void WebSocketHandleImpl::disconnect() |
| 120 { | 120 { |
| 121 m_websocket.reset(); | 121 m_websocket.reset(); |
| 122 m_client = nullptr; | 122 m_client = nullptr; |
| 123 } | 123 } |
| 124 | 124 |
| 125 void WebSocketHandleImpl::onConnectionError() | 125 void WebSocketHandleImpl::onConnectionError(uint32_t customReason, const std::st
ring& description) |
| 126 { | 126 { |
| 127 if (!blink::Platform::current()) { | 127 if (!blink::Platform::current()) { |
| 128 // In the renderrer shutdown sequence, mojo channels are destructed and
this | 128 // In the renderrer shutdown sequence, mojo channels are destructed and
this |
| 129 // function is called. On the other hand, blink objects became invalid | 129 // function is called. On the other hand, blink objects became invalid |
| 130 // *silently*, which means we must not touch |*client_| any more. | 130 // *silently*, which means we must not touch |*client_| any more. |
| 131 // TODO(yhirano): Remove this code once the shutdown sequence is fixed. | 131 // TODO(yhirano): Remove this code once the shutdown sequence is fixed. |
| 132 disconnect(); | 132 disconnect(); |
| 133 return; | 133 return; |
| 134 } | 134 } |
| 135 | 135 |
| 136 // Our connection to the WebSocket was dropped. This could be due to | 136 // Our connection to the WebSocket was dropped. This could be due to |
| 137 // exceeding the maximum number of concurrent websockets from this process. | 137 // exceeding the maximum number of concurrent websockets from this process. |
| 138 | 138 String failureMessage; |
| 139 // TODO(darin): Communicate a more specific error here (see crbug/634502). | 139 if (customReason == mojom::blink::WebSocket::kInsufficientResources) { |
| 140 OnFailChannel( | 140 failureMessage = description.empty() ? "Insufficient resources" : String
::fromUTF8(description.c_str(), description.size()); |
| 141 "Error in connection establishment: net:" | 141 } else { |
| 142 ":ERR_INSUFFICIENT_RESOURCES"); | 142 DCHECK(description.empty()); |
| 143 failureMessage = "Unspecified reason"; |
| 144 } |
| 145 OnFailChannel(failureMessage); |
| 143 } | 146 } |
| 144 | 147 |
| 145 void WebSocketHandleImpl::OnFailChannel(const String& message) | 148 void WebSocketHandleImpl::OnFailChannel(const String& message) |
| 146 { | 149 { |
| 147 NETWORK_DVLOG(1) << this << " OnFailChannel(" << message << ")"; | 150 NETWORK_DVLOG(1) << this << " OnFailChannel(" << message << ")"; |
| 148 | 151 |
| 149 WebSocketHandleClient* client = m_client; | 152 WebSocketHandleClient* client = m_client; |
| 150 disconnect(); | 153 disconnect(); |
| 151 if (!client) | 154 if (!client) |
| 152 return; | 155 return; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 { | 247 { |
| 245 NETWORK_DVLOG(1) << this << " OnClosingHandshake()"; | 248 NETWORK_DVLOG(1) << this << " OnClosingHandshake()"; |
| 246 if (!m_client) | 249 if (!m_client) |
| 247 return; | 250 return; |
| 248 | 251 |
| 249 m_client->didStartClosingHandshake(this); | 252 m_client->didStartClosingHandshake(this); |
| 250 // |this| can be deleted here. | 253 // |this| can be deleted here. |
| 251 } | 254 } |
| 252 | 255 |
| 253 } // namespace blink | 256 } // namespace blink |
| OLD | NEW |