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 "content/browser/renderer_host/websocket_host.h" | 5 #include "content/browser/renderer_host/websocket_host.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "content/browser/renderer_host/websocket_dispatcher_host.h" | 9 #include "content/browser/renderer_host/websocket_dispatcher_host.h" |
10 #include "content/common/websocket_messages.h" | 10 #include "content/common/websocket_messages.h" |
11 #include "ipc/ipc_message_macros.h" | 11 #include "ipc/ipc_message_macros.h" |
12 #include "net/http/http_request_headers.h" | 12 #include "net/http/http_request_headers.h" |
13 #include "net/http/http_response_headers.h" | 13 #include "net/http/http_response_headers.h" |
| 14 #include "net/http/http_util.h" |
14 #include "net/websockets/websocket_channel.h" | 15 #include "net/websockets/websocket_channel.h" |
15 #include "net/websockets/websocket_event_interface.h" | 16 #include "net/websockets/websocket_event_interface.h" |
16 #include "net/websockets/websocket_frame.h" // for WebSocketFrameHeader::OpCode | 17 #include "net/websockets/websocket_frame.h" // for WebSocketFrameHeader::OpCode |
17 #include "net/websockets/websocket_handshake_request_info.h" | 18 #include "net/websockets/websocket_handshake_request_info.h" |
18 #include "net/websockets/websocket_handshake_response_info.h" | 19 #include "net/websockets/websocket_handshake_response_info.h" |
19 | 20 |
20 namespace content { | 21 namespace content { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 | 169 |
169 ChannelState WebSocketEventHandler::OnStartOpeningHandshake( | 170 ChannelState WebSocketEventHandler::OnStartOpeningHandshake( |
170 scoped_ptr<net::WebSocketHandshakeRequestInfo> request) { | 171 scoped_ptr<net::WebSocketHandshakeRequestInfo> request) { |
171 // TODO(yhirano) Do nothing if the inspector is not attached. | 172 // TODO(yhirano) Do nothing if the inspector is not attached. |
172 DVLOG(3) << "WebSocketEventHandler::OnStartOpeningHandshake"; | 173 DVLOG(3) << "WebSocketEventHandler::OnStartOpeningHandshake"; |
173 WebSocketHandshakeRequest request_to_pass; | 174 WebSocketHandshakeRequest request_to_pass; |
174 request_to_pass.url.Swap(&request->url); | 175 request_to_pass.url.Swap(&request->url); |
175 net::HttpRequestHeaders::Iterator it(request->headers); | 176 net::HttpRequestHeaders::Iterator it(request->headers); |
176 while (it.GetNext()) | 177 while (it.GetNext()) |
177 request_to_pass.headers.push_back(std::make_pair(it.name(), it.value())); | 178 request_to_pass.headers.push_back(std::make_pair(it.name(), it.value())); |
| 179 request_to_pass.headers_text = |
| 180 base::StringPrintf("GET %s HTTP/1.1\r\n", |
| 181 request_to_pass.url.spec().c_str()) + |
| 182 request->headers.ToString(); |
| 183 |
178 request_to_pass.request_time = request->request_time; | 184 request_to_pass.request_time = request->request_time; |
179 return StateCast(dispatcher_->SendStartOpeningHandshake(routing_id_, | 185 return StateCast(dispatcher_->SendStartOpeningHandshake(routing_id_, |
180 request_to_pass)); | 186 request_to_pass)); |
181 } | 187 } |
182 | 188 |
183 ChannelState WebSocketEventHandler::OnFinishOpeningHandshake( | 189 ChannelState WebSocketEventHandler::OnFinishOpeningHandshake( |
184 scoped_ptr<net::WebSocketHandshakeResponseInfo> response) { | 190 scoped_ptr<net::WebSocketHandshakeResponseInfo> response) { |
185 // TODO(yhirano) Do nothing if the inspector is not attached. | 191 // TODO(yhirano) Do nothing if the inspector is not attached. |
186 DVLOG(3) << "WebSocketEventHandler::OnFinishOpeningHandshake"; | 192 DVLOG(3) << "WebSocketEventHandler::OnFinishOpeningHandshake"; |
187 WebSocketHandshakeResponse response_to_pass; | 193 WebSocketHandshakeResponse response_to_pass; |
188 response_to_pass.url.Swap(&response->url); | 194 response_to_pass.url.Swap(&response->url); |
189 response_to_pass.status_code = response->status_code; | 195 response_to_pass.status_code = response->status_code; |
190 response_to_pass.status_text.swap(response->status_text); | 196 response_to_pass.status_text.swap(response->status_text); |
191 void* iter = NULL; | 197 void* iter = NULL; |
192 std::string name, value; | 198 std::string name, value; |
193 while (response->headers->EnumerateHeaderLines(&iter, &name, &value)) | 199 while (response->headers->EnumerateHeaderLines(&iter, &name, &value)) |
194 response_to_pass.headers.push_back(std::make_pair(name, value)); | 200 response_to_pass.headers.push_back(std::make_pair(name, value)); |
| 201 response_to_pass.headers_text = |
| 202 net::HttpUtil::ConvertHeadersBackToHTTPResponse( |
| 203 response->headers->raw_headers()); |
195 response_to_pass.response_time = response->response_time; | 204 response_to_pass.response_time = response->response_time; |
196 return StateCast(dispatcher_->SendFinishOpeningHandshake(routing_id_, | 205 return StateCast(dispatcher_->SendFinishOpeningHandshake(routing_id_, |
197 response_to_pass)); | 206 response_to_pass)); |
198 } | 207 } |
199 | 208 |
200 } // namespace | 209 } // namespace |
201 | 210 |
202 WebSocketHost::WebSocketHost(int routing_id, | 211 WebSocketHost::WebSocketHost(int routing_id, |
203 WebSocketDispatcherHost* dispatcher, | 212 WebSocketDispatcherHost* dispatcher, |
204 net::URLRequestContext* url_request_context) | 213 net::URLRequestContext* url_request_context) |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 const std::string& reason) { | 269 const std::string& reason) { |
261 DVLOG(3) << "WebSocketHost::OnDropChannel" | 270 DVLOG(3) << "WebSocketHost::OnDropChannel" |
262 << " routing_id=" << routing_id_ << " was_clean=" << was_clean | 271 << " routing_id=" << routing_id_ << " was_clean=" << was_clean |
263 << " code=" << code << " reason=\"" << reason << "\""; | 272 << " code=" << code << " reason=\"" << reason << "\""; |
264 | 273 |
265 // TODO(yhirano): Handle |was_clean| appropriately. | 274 // TODO(yhirano): Handle |was_clean| appropriately. |
266 channel_->StartClosingHandshake(code, reason); | 275 channel_->StartClosingHandshake(code, reason); |
267 } | 276 } |
268 | 277 |
269 } // namespace content | 278 } // namespace content |
OLD | NEW |