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/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 url::Origin& 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 headers.SetHeader(websockets::kSecWebSocketVersion, | 163 headers.SetHeader(websockets::kSecWebSocketVersion, |
163 websockets::kSupportedVersion); | 164 websockets::kSupportedVersion); |
164 request->url_request()->SetExtraRequestHeaders(headers); | 165 request->url_request()->SetExtraRequestHeaders(headers); |
165 request->url_request()->SetUserData( | 166 request->url_request()->SetUserData( |
166 WebSocketHandshakeStreamBase::CreateHelper::DataKey(), | 167 WebSocketHandshakeStreamBase::CreateHelper::DataKey(), |
167 create_helper.release()); | 168 create_helper.release()); |
168 request->url_request()->SetLoadFlags(LOAD_DISABLE_CACHE | | 169 request->url_request()->SetLoadFlags(LOAD_DISABLE_CACHE | |
169 LOAD_BYPASS_CACHE | | 170 LOAD_BYPASS_CACHE | |
170 LOAD_DO_NOT_PROMPT_FOR_LOGIN); | 171 LOAD_DO_NOT_PROMPT_FOR_LOGIN); |
171 request->url_request()->Start(); | 172 request->url_request()->Start(); |
172 return request.PassAs<WebSocketStreamRequest>(); | 173 return request.PassAs<WebSocketStreamRequest>(); |
173 } | 174 } |
174 | 175 |
175 } // namespace | 176 } // namespace |
176 | 177 |
177 WebSocketStreamRequest::~WebSocketStreamRequest() {} | 178 WebSocketStreamRequest::~WebSocketStreamRequest() {} |
178 | 179 |
179 WebSocketStream::WebSocketStream() {} | 180 WebSocketStream::WebSocketStream() {} |
180 WebSocketStream::~WebSocketStream() {} | 181 WebSocketStream::~WebSocketStream() {} |
181 | 182 |
182 WebSocketStream::ConnectDelegate::~ConnectDelegate() {} | 183 WebSocketStream::ConnectDelegate::~ConnectDelegate() {} |
183 | 184 |
184 scoped_ptr<WebSocketStreamRequest> WebSocketStream::CreateAndConnectStream( | 185 scoped_ptr<WebSocketStreamRequest> WebSocketStream::CreateAndConnectStream( |
185 const GURL& socket_url, | 186 const GURL& socket_url, |
186 const std::vector<std::string>& requested_subprotocols, | 187 const std::vector<std::string>& requested_subprotocols, |
187 const GURL& origin, | 188 const url::Origin& origin, |
188 URLRequestContext* url_request_context, | 189 URLRequestContext* url_request_context, |
189 const BoundNetLog& net_log, | 190 const BoundNetLog& net_log, |
190 scoped_ptr<ConnectDelegate> connect_delegate) { | 191 scoped_ptr<ConnectDelegate> connect_delegate) { |
191 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper( | 192 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper( |
192 new WebSocketHandshakeStreamCreateHelper(connect_delegate.get(), | 193 new WebSocketHandshakeStreamCreateHelper(connect_delegate.get(), |
193 requested_subprotocols)); | 194 requested_subprotocols)); |
194 return CreateAndConnectStreamWithCreateHelper(socket_url, | 195 return CreateAndConnectStreamWithCreateHelper(socket_url, |
195 create_helper.Pass(), | 196 create_helper.Pass(), |
196 origin, | 197 origin, |
197 url_request_context, | 198 url_request_context, |
198 net_log, | 199 net_log, |
199 connect_delegate.Pass()); | 200 connect_delegate.Pass()); |
200 } | 201 } |
201 | 202 |
202 // This is declared in websocket_test_util.h. | 203 // This is declared in websocket_test_util.h. |
203 scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamForTesting( | 204 scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamForTesting( |
204 const GURL& socket_url, | 205 const GURL& socket_url, |
205 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper, | 206 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper, |
206 const GURL& origin, | 207 const url::Origin& origin, |
207 URLRequestContext* url_request_context, | 208 URLRequestContext* url_request_context, |
208 const BoundNetLog& net_log, | 209 const BoundNetLog& net_log, |
209 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { | 210 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { |
210 return CreateAndConnectStreamWithCreateHelper(socket_url, | 211 return CreateAndConnectStreamWithCreateHelper(socket_url, |
211 create_helper.Pass(), | 212 create_helper.Pass(), |
212 origin, | 213 origin, |
213 url_request_context, | 214 url_request_context, |
214 net_log, | 215 net_log, |
215 connect_delegate.Pass()); | 216 connect_delegate.Pass()); |
216 } | 217 } |
217 | 218 |
218 } // namespace net | 219 } // namespace net |
OLD | NEW |