| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/test/chromedriver/net/websocket.h" | 5 #include "chrome/test/chromedriver/net/websocket.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 | 10 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } else { | 81 } else { |
| 82 if (!ResolveHost(url_.HostNoBrackets(), port, &addresses)) { | 82 if (!ResolveHost(url_.HostNoBrackets(), port, &addresses)) { |
| 83 callback.Run(net::ERR_ADDRESS_UNREACHABLE); | 83 callback.Run(net::ERR_ADDRESS_UNREACHABLE); |
| 84 return; | 84 return; |
| 85 } | 85 } |
| 86 base::ListValue endpoints; | 86 base::ListValue endpoints; |
| 87 for (auto endpoint : addresses) | 87 for (auto endpoint : addresses) |
| 88 endpoints.AppendString(endpoint.ToStringWithoutPort()); | 88 endpoints.AppendString(endpoint.ToStringWithoutPort()); |
| 89 std::string json; | 89 std::string json; |
| 90 CHECK(base::JSONWriter::Write(endpoints, &json)); | 90 CHECK(base::JSONWriter::Write(endpoints, &json)); |
| 91 VLOG(0) << "resolved " << url_.HostNoBrackets() << " to " << json; | 91 VLOG(0) << "resolved " << url_.HostNoBracketsPiece() << " to " << json; |
| 92 } | 92 } |
| 93 | 93 |
| 94 net::NetLogSource source; | 94 net::NetLogSource source; |
| 95 socket_.reset(new net::TCPClientSocket(addresses, NULL, NULL, source)); | 95 socket_.reset(new net::TCPClientSocket(addresses, NULL, NULL, source)); |
| 96 | 96 |
| 97 state_ = CONNECTING; | 97 state_ = CONNECTING; |
| 98 connect_callback_ = callback; | 98 connect_callback_ = callback; |
| 99 int code = socket_->Connect(base::Bind( | 99 int code = socket_->Connect(base::Bind( |
| 100 &WebSocket::OnSocketConnect, base::Unretained(this))); | 100 &WebSocket::OnSocketConnect, base::Unretained(this))); |
| 101 if (code != net::ERR_IO_PENDING) | 101 if (code != net::ERR_IO_PENDING) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 120 | 120 |
| 121 std::string masked_message = message; | 121 std::string masked_message = message; |
| 122 net::MaskWebSocketFramePayload( | 122 net::MaskWebSocketFramePayload( |
| 123 masking_key, 0, &masked_message[0], masked_message.length()); | 123 masking_key, 0, &masked_message[0], masked_message.length()); |
| 124 Write(header_str + masked_message); | 124 Write(header_str + masked_message); |
| 125 return true; | 125 return true; |
| 126 } | 126 } |
| 127 | 127 |
| 128 void WebSocket::OnSocketConnect(int code) { | 128 void WebSocket::OnSocketConnect(int code) { |
| 129 if (code != net::OK) { | 129 if (code != net::OK) { |
| 130 VLOG(1) << "failed to connect to " << url_.HostNoBrackets() << " (error " | 130 VLOG(1) << "failed to connect to " << url_.HostNoBracketsPiece() |
| 131 << code << ")"; | 131 << " (error " << code << ")"; |
| 132 Close(code); | 132 Close(code); |
| 133 return; | 133 return; |
| 134 } | 134 } |
| 135 | 135 |
| 136 base::Base64Encode(base::RandBytesAsString(16), &sec_key_); | 136 base::Base64Encode(base::RandBytesAsString(16), &sec_key_); |
| 137 std::string handshake = base::StringPrintf( | 137 std::string handshake = base::StringPrintf( |
| 138 "GET %s HTTP/1.1\r\n" | 138 "GET %s HTTP/1.1\r\n" |
| 139 "Host: %s\r\n" | 139 "Host: %s\r\n" |
| 140 "Upgrade: websocket\r\n" | 140 "Upgrade: websocket\r\n" |
| 141 "Connection: Upgrade\r\n" | 141 "Connection: Upgrade\r\n" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 | 267 |
| 268 void WebSocket::Close(int code) { | 268 void WebSocket::Close(int code) { |
| 269 socket_->Disconnect(); | 269 socket_->Disconnect(); |
| 270 if (!connect_callback_.is_null()) | 270 if (!connect_callback_.is_null()) |
| 271 InvokeConnectCallback(code); | 271 InvokeConnectCallback(code); |
| 272 if (state_ == OPEN) | 272 if (state_ == OPEN) |
| 273 listener_->OnClose(); | 273 listener_->OnClose(); |
| 274 | 274 |
| 275 state_ = CLOSED; | 275 state_ = CLOSED; |
| 276 } | 276 } |
| OLD | NEW |