OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <algorithm> | 5 #include <algorithm> |
6 #include <limits> | 6 #include <limits> |
7 | 7 |
8 #include "net/websockets/websocket.h" | 8 #include "net/websockets/websocket.h" |
9 | 9 |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "net/websockets/websocket_handshake.h" | 11 #include "net/websockets/websocket_handshake.h" |
| 12 #include "net/websockets/websocket_handshake_draft75.h" |
12 | 13 |
13 namespace net { | 14 namespace net { |
14 | 15 |
15 WebSocket::WebSocket(Request* request, WebSocketDelegate* delegate) | 16 WebSocket::WebSocket(Request* request, WebSocketDelegate* delegate) |
16 : ready_state_(INITIALIZED), | 17 : ready_state_(INITIALIZED), |
17 request_(request), | 18 request_(request), |
18 handshake_(NULL), | 19 handshake_(NULL), |
19 delegate_(delegate), | 20 delegate_(delegate), |
20 origin_loop_(MessageLoop::current()), | 21 origin_loop_(MessageLoop::current()), |
21 socket_stream_(NULL), | 22 socket_stream_(NULL), |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 DCHECK(socket_stream == socket_stream_); | 95 DCHECK(socket_stream == socket_stream_); |
95 max_pending_send_allowed_ = max_pending_send_allowed; | 96 max_pending_send_allowed_ = max_pending_send_allowed; |
96 | 97 |
97 // Use |max_pending_send_allowed| as hint for initial size of read buffer. | 98 // Use |max_pending_send_allowed| as hint for initial size of read buffer. |
98 current_read_buf_ = new GrowableIOBuffer(); | 99 current_read_buf_ = new GrowableIOBuffer(); |
99 current_read_buf_->SetCapacity(max_pending_send_allowed_); | 100 current_read_buf_->SetCapacity(max_pending_send_allowed_); |
100 read_consumed_len_ = 0; | 101 read_consumed_len_ = 0; |
101 | 102 |
102 DCHECK(!current_write_buf_); | 103 DCHECK(!current_write_buf_); |
103 DCHECK(!handshake_.get()); | 104 DCHECK(!handshake_.get()); |
104 handshake_.reset(new WebSocketHandshake( | 105 switch (request_->version()) { |
105 request_->url(), request_->origin(), request_->location(), | 106 case DEFAULT_VERSION: |
106 request_->protocol())); | 107 handshake_.reset(new WebSocketHandshake( |
| 108 request_->url(), request_->origin(), request_->location(), |
| 109 request_->protocol())); |
| 110 break; |
| 111 case DRAFT75: |
| 112 handshake_.reset(new WebSocketHandshakeDraft75( |
| 113 request_->url(), request_->origin(), request_->location(), |
| 114 request_->protocol())); |
| 115 break; |
| 116 default: |
| 117 NOTREACHED() << "Unexpected protocol version:" << request_->version(); |
| 118 } |
107 | 119 |
108 const std::string msg = handshake_->CreateClientHandshakeMessage(); | 120 const std::string msg = handshake_->CreateClientHandshakeMessage(); |
109 IOBufferWithSize* buf = new IOBufferWithSize(msg.size()); | 121 IOBufferWithSize* buf = new IOBufferWithSize(msg.size()); |
110 memcpy(buf->data(), msg.data(), msg.size()); | 122 memcpy(buf->data(), msg.data(), msg.size()); |
111 pending_write_bufs_.push_back(buf); | 123 pending_write_bufs_.push_back(buf); |
112 origin_loop_->PostTask(FROM_HERE, | 124 origin_loop_->PostTask(FROM_HERE, |
113 NewRunnableMethod(this, &WebSocket::SendPending)); | 125 NewRunnableMethod(this, &WebSocket::SendPending)); |
114 } | 126 } |
115 | 127 |
116 void WebSocket::OnSentData(SocketStream* socket_stream, int amount_sent) { | 128 void WebSocket::OnSentData(SocketStream* socket_stream, int amount_sent) { |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 Release(); | 315 Release(); |
304 } | 316 } |
305 | 317 |
306 void WebSocket::DoError(int error) { | 318 void WebSocket::DoError(int error) { |
307 DCHECK(MessageLoop::current() == origin_loop_); | 319 DCHECK(MessageLoop::current() == origin_loop_); |
308 if (delegate_) | 320 if (delegate_) |
309 delegate_->OnError(this, error); | 321 delegate_->OnError(this, error); |
310 } | 322 } |
311 | 323 |
312 } // namespace net | 324 } // namespace net |
OLD | NEW |