Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: net/websockets/websocket_stream.cc

Issue 170843007: Introduce url::Origin to represent Web Origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 void Delegate::OnReadCompleted(URLRequest* request, int bytes_read) { 140 void Delegate::OnReadCompleted(URLRequest* request, int bytes_read) {
141 NOTREACHED(); 141 NOTREACHED();
142 } 142 }
143 143
144 // Internal implementation of CreateAndConnectStream and 144 // Internal implementation of CreateAndConnectStream and
145 // CreateAndConnectStreamForTesting. 145 // CreateAndConnectStreamForTesting.
146 scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamWithCreateHelper( 146 scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamWithCreateHelper(
147 const GURL& socket_url, 147 const GURL& socket_url,
148 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper, 148 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper,
149 const GURL& origin, 149 const std::string& origin,
150 URLRequestContext* url_request_context, 150 URLRequestContext* url_request_context,
151 const BoundNetLog& net_log, 151 const BoundNetLog& net_log,
152 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { 152 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) {
153 scoped_ptr<StreamRequestImpl> request( 153 scoped_ptr<StreamRequestImpl> request(
154 new StreamRequestImpl(socket_url, 154 new StreamRequestImpl(socket_url,
155 url_request_context, 155 url_request_context,
156 connect_delegate.Pass(), 156 connect_delegate.Pass(),
157 create_helper.get())); 157 create_helper.get()));
158 HttpRequestHeaders headers; 158 HttpRequestHeaders headers;
159 headers.SetHeader(websockets::kUpgrade, websockets::kWebSocketLowercase); 159 headers.SetHeader(websockets::kUpgrade, websockets::kWebSocketLowercase);
160 headers.SetHeader(HttpRequestHeaders::kConnection, websockets::kUpgrade); 160 headers.SetHeader(HttpRequestHeaders::kConnection, websockets::kUpgrade);
161 headers.SetHeader(HttpRequestHeaders::kOrigin, origin.spec()); 161 headers.SetHeader(HttpRequestHeaders::kOrigin, origin);
162 // TODO(ricea): Move the version number to websocket_handshake_constants.h 162 // TODO(ricea): Move the version number to websocket_handshake_constants.h
163 headers.SetHeader(websockets::kSecWebSocketVersion, 163 headers.SetHeader(websockets::kSecWebSocketVersion,
164 websockets::kSupportedVersion); 164 websockets::kSupportedVersion);
165 request->url_request()->SetExtraRequestHeaders(headers); 165 request->url_request()->SetExtraRequestHeaders(headers);
166 request->url_request()->SetUserData( 166 request->url_request()->SetUserData(
167 WebSocketHandshakeStreamBase::CreateHelper::DataKey(), 167 WebSocketHandshakeStreamBase::CreateHelper::DataKey(),
168 create_helper.release()); 168 create_helper.release());
169 request->url_request()->SetLoadFlags(LOAD_DISABLE_CACHE | 169 request->url_request()->SetLoadFlags(LOAD_DISABLE_CACHE |
170 LOAD_BYPASS_CACHE | 170 LOAD_BYPASS_CACHE |
171 LOAD_DO_NOT_PROMPT_FOR_LOGIN); 171 LOAD_DO_NOT_PROMPT_FOR_LOGIN);
172 request->url_request()->Start(); 172 request->url_request()->Start();
173 return request.PassAs<WebSocketStreamRequest>(); 173 return request.PassAs<WebSocketStreamRequest>();
174 } 174 }
175 175
176 } // namespace 176 } // namespace
177 177
178 WebSocketStreamRequest::~WebSocketStreamRequest() {} 178 WebSocketStreamRequest::~WebSocketStreamRequest() {}
179 179
180 WebSocketStream::WebSocketStream() {} 180 WebSocketStream::WebSocketStream() {}
181 WebSocketStream::~WebSocketStream() {} 181 WebSocketStream::~WebSocketStream() {}
182 182
183 WebSocketStream::ConnectDelegate::~ConnectDelegate() {} 183 WebSocketStream::ConnectDelegate::~ConnectDelegate() {}
184 184
185 scoped_ptr<WebSocketStreamRequest> WebSocketStream::CreateAndConnectStream( 185 scoped_ptr<WebSocketStreamRequest> WebSocketStream::CreateAndConnectStream(
186 const GURL& socket_url, 186 const GURL& socket_url,
187 const std::vector<std::string>& requested_subprotocols, 187 const std::vector<std::string>& requested_subprotocols,
188 const GURL& origin, 188 const std::string& origin,
189 URLRequestContext* url_request_context, 189 URLRequestContext* url_request_context,
190 const BoundNetLog& net_log, 190 const BoundNetLog& net_log,
191 scoped_ptr<ConnectDelegate> connect_delegate) { 191 scoped_ptr<ConnectDelegate> connect_delegate) {
192 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper( 192 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper(
193 new WebSocketHandshakeStreamCreateHelper(connect_delegate.get(), 193 new WebSocketHandshakeStreamCreateHelper(connect_delegate.get(),
194 requested_subprotocols)); 194 requested_subprotocols));
195 return CreateAndConnectStreamWithCreateHelper(socket_url, 195 return CreateAndConnectStreamWithCreateHelper(socket_url,
196 create_helper.Pass(), 196 create_helper.Pass(),
197 origin, 197 origin,
198 url_request_context, 198 url_request_context,
199 net_log, 199 net_log,
200 connect_delegate.Pass()); 200 connect_delegate.Pass());
201 } 201 }
202 202
203 // This is declared in websocket_test_util.h. 203 // This is declared in websocket_test_util.h.
204 scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamForTesting( 204 scoped_ptr<WebSocketStreamRequest> CreateAndConnectStreamForTesting(
205 const GURL& socket_url, 205 const GURL& socket_url,
206 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper, 206 scoped_ptr<WebSocketHandshakeStreamCreateHelper> create_helper,
207 const GURL& origin, 207 const std::string& origin,
208 URLRequestContext* url_request_context, 208 URLRequestContext* url_request_context,
209 const BoundNetLog& net_log, 209 const BoundNetLog& net_log,
210 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) { 210 scoped_ptr<WebSocketStream::ConnectDelegate> connect_delegate) {
211 return CreateAndConnectStreamWithCreateHelper(socket_url, 211 return CreateAndConnectStreamWithCreateHelper(socket_url,
212 create_helper.Pass(), 212 create_helper.Pass(),
213 origin, 213 origin,
214 url_request_context, 214 url_request_context,
215 net_log, 215 net_log,
216 connect_delegate.Pass()); 216 connect_delegate.Pass());
217 } 217 }
218 218
219 } // namespace net 219 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698