[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 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 | ||||
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_BASE_H_ | ||||
6 | #define NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_BASE_H_ | ||||
7 | |||||
8 | // This file is included from net/http files. | ||||
9 | // Since net/http can be built without linking net/websockets code, | ||||
10 | // this file must not introduce any link-time dependencies on websockets. | ||||
11 | |||||
danakj | 9c5cab5 | 2016-04-16 00:54:33 | [diff] [blame] | 12 | #include <memory> |
[email protected] | 9686820 | 2014-01-09 10:38:04 | [diff] [blame] | 13 | #include <string> |
14 | |||||
tfarina | ea94afc23 | 2015-10-20 04:23:36 | [diff] [blame] | 15 | #include "base/macros.h" |
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 16 | #include "base/memory/weak_ptr.h" |
[email protected] | f4533ba | 2013-11-28 09:35:41 | [diff] [blame] | 17 | #include "base/supports_user_data.h" |
bnc | 81c46c1f | 2016-10-04 16:25:59 | [diff] [blame] | 18 | #include "net/base/net_export.h" |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 19 | #include "net/http/http_stream.h" |
[email protected] | f4533ba | 2013-11-28 09:35:41 | [diff] [blame] | 20 | #include "net/url_request/websocket_handshake_userdata_key.h" |
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 21 | #include "net/websockets/websocket_stream.h" |
22 | |||||
23 | namespace net { | ||||
24 | |||||
25 | class ClientSocketHandle; | ||||
Bence Béky | 46bfbc1 | 2018-02-22 19:28:20 | [diff] [blame^] | 26 | class SpdySession; |
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 27 | |
28 | // WebSocketHandshakeStreamBase is the base class of | ||||
29 | // WebSocketBasicHandshakeStream. net/http code uses this interface to handle | ||||
30 | // WebSocketBasicHandshakeStream when it needs to be treated differently from | ||||
31 | // HttpStreamBase. | ||||
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 32 | class NET_EXPORT WebSocketHandshakeStreamBase : public HttpStream { |
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 33 | public: |
[email protected] | efa9e73 | 2013-11-29 02:55:05 | [diff] [blame] | 34 | // An object that stores data needed for the creation of a |
35 | // WebSocketBasicHandshakeStream object. A new CreateHelper is used for each | ||||
36 | // WebSocket connection. | ||||
37 | class NET_EXPORT_PRIVATE CreateHelper : public base::SupportsUserData::Data { | ||||
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 38 | public: |
[email protected] | f4533ba | 2013-11-28 09:35:41 | [diff] [blame] | 39 | // Returns a key to use to lookup this object in a URLRequest object. It is |
40 | // different from any other key that is supplied to | ||||
41 | // URLRequest::SetUserData(). | ||||
42 | static const void* DataKey() { return kWebSocketHandshakeUserDataKey; } | ||||
43 | |||||
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 44 | ~CreateHelper() override {} |
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 45 | |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 46 | // Create a WebSocketBasicHandshakeStream. This is called after the |
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 47 | // underlying connection has been established but before any handshake data |
[email protected] | efa9e73 | 2013-11-29 02:55:05 | [diff] [blame] | 48 | // has been transferred. This can be called more than once in the case that |
49 | // HTTP authentication is needed. | ||||
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 50 | virtual std::unique_ptr<WebSocketHandshakeStreamBase> CreateBasicStream( |
danakj | 9c5cab5 | 2016-04-16 00:54:33 | [diff] [blame] | 51 | std::unique_ptr<ClientSocketHandle> connection, |
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 52 | bool using_proxy) = 0; |
Bence Béky | 46bfbc1 | 2018-02-22 19:28:20 | [diff] [blame^] | 53 | |
54 | // Create a WebSocketHttp2HandshakeStream. This is called after the | ||||
55 | // underlying HTTP/2 connection has been established but before the stream | ||||
56 | // has been opened. This cannot be called more than once. | ||||
57 | virtual std::unique_ptr<WebSocketHandshakeStreamBase> CreateHttp2Stream( | ||||
58 | base::WeakPtr<SpdySession> session) = 0; | ||||
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 59 | }; |
60 | |||||
[email protected] | f4533ba | 2013-11-28 09:35:41 | [diff] [blame] | 61 | // This has to have an inline implementation so that the net/url_request/ |
62 | // tests do not fail on iOS. | ||||
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 63 | ~WebSocketHandshakeStreamBase() override {} |
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 64 | |
65 | // After the handshake has completed, this method creates a WebSocketStream | ||||
66 | // (of the appropriate type) from the WebSocketHandshakeStreamBase object. | ||||
67 | // The WebSocketHandshakeStreamBase object is unusable after Upgrade() has | ||||
68 | // been called. | ||||
danakj | 9c5cab5 | 2016-04-16 00:54:33 | [diff] [blame] | 69 | virtual std::unique_ptr<WebSocketStream> Upgrade() = 0; |
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 70 | |
Andrey Kosyakov | 83a6eee | 2017-08-14 19:20:04 | [diff] [blame] | 71 | void SetRequestHeadersCallback(RequestHeadersCallback callback) override {} |
72 | |||||
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 73 | protected: |
[email protected] | f4533ba | 2013-11-28 09:35:41 | [diff] [blame] | 74 | // As with the destructor, this must be inline. |
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 75 | WebSocketHandshakeStreamBase() {} |
76 | |||||
77 | private: | ||||
78 | DISALLOW_COPY_AND_ASSIGN(WebSocketHandshakeStreamBase); | ||||
79 | }; | ||||
80 | |||||
81 | } // namespace net | ||||
82 | |||||
83 | #endif // NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_BASE_H_ |