Chromium Code Reviews| 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 |
| 139 // TODO(darin): Communicate a more specific error here (see crbug/634502). | 139 OnFailChannel(String::fromUTF8(description.c_str(), description.size())); |
|
dcheng
2016/09/14 16:18:33
It kind of feels like we should be using customRea
yzshen1
2016/09/14 16:26:03
IIUC, this description is displayed in inspector.
darin (slow to review)
2016/09/19 17:36:13
I guess in some cases this message could be empty.
yzshen1
2016/09/19 18:26:48
Done. Thanks!
| |
| 140 OnFailChannel( | |
| 141 "Error in connection establishment: net:" | |
| 142 ":ERR_INSUFFICIENT_RESOURCES"); | |
| 143 } | 140 } |
| 144 | 141 |
| 145 void WebSocketHandleImpl::OnFailChannel(const String& message) | 142 void WebSocketHandleImpl::OnFailChannel(const String& message) |
| 146 { | 143 { |
| 147 NETWORK_DVLOG(1) << this << " OnFailChannel(" << message << ")"; | 144 NETWORK_DVLOG(1) << this << " OnFailChannel(" << message << ")"; |
| 148 | 145 |
| 149 WebSocketHandleClient* client = m_client; | 146 WebSocketHandleClient* client = m_client; |
| 150 disconnect(); | 147 disconnect(); |
| 151 if (!client) | 148 if (!client) |
| 152 return; | 149 return; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 { | 241 { |
| 245 NETWORK_DVLOG(1) << this << " OnClosingHandshake()"; | 242 NETWORK_DVLOG(1) << this << " OnClosingHandshake()"; |
| 246 if (!m_client) | 243 if (!m_client) |
| 247 return; | 244 return; |
| 248 | 245 |
| 249 m_client->didStartClosingHandshake(this); | 246 m_client->didStartClosingHandshake(this); |
| 250 // |this| can be deleted here. | 247 // |this| can be deleted here. |
| 251 } | 248 } |
| 252 | 249 |
| 253 } // namespace blink | 250 } // namespace blink |
| OLD | NEW |