| 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 "net/websockets/websocket_stream.h" | 5 #include "net/websockets/websocket_stream.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "net/http/http_request_headers.h" | 9 #include "net/http/http_request_headers.h" |
| 10 #include "net/http/http_status_code.h" | 10 #include "net/http/http_status_code.h" |
| 11 #include "net/url_request/url_request.h" | 11 #include "net/url_request/url_request.h" |
| 12 #include "net/url_request/url_request_context.h" | 12 #include "net/url_request/url_request_context.h" |
| 13 #include "net/websockets/websocket_errors.h" | 13 #include "net/websockets/websocket_errors.h" |
| 14 #include "net/websockets/websocket_handshake_constants.h" | 14 #include "net/websockets/websocket_handshake_constants.h" |
| 15 #include "net/websockets/websocket_handshake_stream_base.h" | 15 #include "net/websockets/websocket_handshake_stream_base.h" |
| 16 #include "net/websockets/websocket_handshake_stream_create_helper.h" | 16 #include "net/websockets/websocket_handshake_stream_create_helper.h" |
| 17 #include "net/websockets/websocket_test_util.h" | 17 #include "net/websockets/websocket_test_util.h" |
| 18 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 19 #include "url/serialized_origin.h" |
| 19 | 20 |
| 20 namespace net { | 21 namespace net { |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 class StreamRequestImpl; | 24 class StreamRequestImpl; |
| 24 | 25 |
| 25 class Delegate : public URLRequest::Delegate { | 26 class Delegate : public URLRequest::Delegate { |
| 26 public: | 27 public: |
| 27 explicit Delegate(StreamRequestImpl* owner) : owner_(owner) {} | 28 explicit Delegate(StreamRequestImpl* owner) : owner_(owner) {} |
| 28 virtual ~Delegate() {} | 29 virtual ~Delegate() {} |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 | 140 |
| 140 void Delegate::OnReadCompleted(URLRequest* request, int bytes_read) { | 141 void Delegate::OnReadCompleted(URLRequest* request, int bytes_read) { |
| 141 NOTREACHED(); | 142 NOTREACHED(); |
| 142 } | 143 } |
| 143 | 144 |
| 144 // Internal implementation of CreateAndConnectStream and | 145 // Internal implementation of CreateAndConnectStream and |
| 145 // CreateAndConnectStreamForTesting. | 146 // CreateAndConnectStreamForTesting. |
| 146 scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamWithCreateHelper( | 147 scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamWithCreateHelper( |
| 147 const GURL& socket_url, | 148 const GURL& socket_url, |
| 148 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper, | 149 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper, |
| 149 const GURL& origin, | 150 const SerializedOrigin& origin, |
| 150 URLRequestContext* url_request_context, | 151 URLRequestContext* url_request_context, |
| 151 const BoundNetLog& net_log, | 152 const BoundNetLog& net_log, |
| 152 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { | 153 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { |
| 153 scoped_ptr<StreamRequestImpl> request( | 154 scoped_ptr<StreamRequestImpl> request( |
| 154 new StreamRequestImpl(socket_url, | 155 new StreamRequestImpl(socket_url, |
| 155 url_request_context, | 156 url_request_context, |
| 156 connect_delegate.Pass(), | 157 connect_delegate.Pass(), |
| 157 create_helper.get())); | 158 create_helper.get())); |
| 158 HttpRequestHeaders headers; | 159 HttpRequestHeaders headers; |
| 159 headers.SetHeader(websockets::kUpgrade, websockets::kWebSocketLowercase); | 160 headers.SetHeader(websockets::kUpgrade, websockets::kWebSocketLowercase); |
| 160 headers.SetHeader(HttpRequestHeaders::kConnection, websockets::kUpgrade); | 161 headers.SetHeader(HttpRequestHeaders::kConnection, websockets::kUpgrade); |
| 161 headers.SetHeader(HttpRequestHeaders::kOrigin, origin.spec()); | 162 headers.SetHeader(HttpRequestHeaders::kOrigin, origin.string()); |
| 162 // TODO(ricea): Move the version number to websocket_handshake_constants.h | 163 // TODO(ricea): Move the version number to websocket_handshake_constants.h |
| 163 headers.SetHeader(websockets::kSecWebSocketVersion, | 164 headers.SetHeader(websockets::kSecWebSocketVersion, |
| 164 websockets::kSupportedVersion); | 165 websockets::kSupportedVersion); |
| 165 request->url_request()->SetExtraRequestHeaders(headers); | 166 request->url_request()->SetExtraRequestHeaders(headers); |
| 166 request->url_request()->SetUserData( | 167 request->url_request()->SetUserData( |
| 167 WebSocketHandshakeStreamBase::CreateHelper::DataKey(), | 168 WebSocketHandshakeStreamBase::CreateHelper::DataKey(), |
| 168 create_helper.release()); | 169 create_helper.release()); |
| 169 request->url_request()->SetLoadFlags(LOAD_DISABLE_CACHE | | 170 request->url_request()->SetLoadFlags(LOAD_DISABLE_CACHE | |
| 170 LOAD_BYPASS_CACHE | | 171 LOAD_BYPASS_CACHE | |
| 171 LOAD_DO_NOT_PROMPT_FOR_LOGIN); | 172 LOAD_DO_NOT_PROMPT_FOR_LOGIN); |
| 172 request->url_request()->Start(); | 173 request->url_request()->Start(); |
| 173 return request.PassAs<WebSocketStreamRequest>(); | 174 return request.PassAs<WebSocketStreamRequest>(); |
| 174 } | 175 } |
| 175 | 176 |
| 176 } // namespace | 177 } // namespace |
| 177 | 178 |
| 178 WebSocketStreamRequest::~WebSocketStreamRequest() {} | 179 WebSocketStreamRequest::~WebSocketStreamRequest() {} |
| 179 | 180 |
| 180 WebSocketStream::WebSocketStream() {} | 181 WebSocketStream::WebSocketStream() {} |
| 181 WebSocketStream::~WebSocketStream() {} | 182 WebSocketStream::~WebSocketStream() {} |
| 182 | 183 |
| 183 WebSocketStream::ConnectDelegate::~ConnectDelegate() {} | 184 WebSocketStream::ConnectDelegate::~ConnectDelegate() {} |
| 184 | 185 |
| 185 scoped_ptr<WebSocketStreamRequest> WebSocketStream::CreateAndConnectStream( | 186 scoped_ptr<WebSocketStreamRequest> WebSocketStream::CreateAndConnectStream( |
| 186 const GURL& socket_url, | 187 const GURL& socket_url, |
| 187 const std::vector<std::string>& requested_subprotocols, | 188 const std::vector<std::string>& requested_subprotocols, |
| 188 const GURL& origin, | 189 const SerializedOrigin& origin, |
| 189 URLRequestContext* url_request_context, | 190 URLRequestContext* url_request_context, |
| 190 const BoundNetLog& net_log, | 191 const BoundNetLog& net_log, |
| 191 scoped_ptr<ConnectDelegate> connect_delegate) { | 192 scoped_ptr<ConnectDelegate> connect_delegate) { |
| 192 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper( | 193 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper( |
| 193 new WebSocketHandshakeStreamCreateHelper(connect_delegate.get(), | 194 new WebSocketHandshakeStreamCreateHelper(connect_delegate.get(), |
| 194 requested_subprotocols)); | 195 requested_subprotocols)); |
| 195 return CreateAndConnectStreamWithCreateHelper(socket_url, | 196 return CreateAndConnectStreamWithCreateHelper(socket_url, |
| 196 create_helper.Pass(), | 197 create_helper.Pass(), |
| 197 origin, | 198 origin, |
| 198 url_request_context, | 199 url_request_context, |
| 199 net_log, | 200 net_log, |
| 200 connect_delegate.Pass()); | 201 connect_delegate.Pass()); |
| 201 } | 202 } |
| 202 | 203 |
| 203 // This is declared in websocket_test_util.h. | 204 // This is declared in websocket_test_util.h. |
| 204 scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamForTesting( | 205 scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamForTesting( |
| 205 const GURL& socket_url, | 206 const GURL& socket_url, |
| 206 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper, | 207 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper, |
| 207 const GURL& origin, | 208 const SerializedOrigin& origin, |
| 208 URLRequestContext* url_request_context, | 209 URLRequestContext* url_request_context, |
| 209 const BoundNetLog& net_log, | 210 const BoundNetLog& net_log, |
| 210 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { | 211 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { |
| 211 return CreateAndConnectStreamWithCreateHelper(socket_url, | 212 return CreateAndConnectStreamWithCreateHelper(socket_url, |
| 212 create_helper.Pass(), | 213 create_helper.Pass(), |
| 213 origin, | 214 origin, |
| 214 url_request_context, | 215 url_request_context, |
| 215 net_log, | 216 net_log, |
| 216 connect_delegate.Pass()); | 217 connect_delegate.Pass()); |
| 217 } | 218 } |
| 218 | 219 |
| 219 } // namespace net | 220 } // namespace net |
| OLD | NEW |