[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 | |||||
[email protected] | 9686820 | 2014-01-09 10:38:04 | [diff] [blame] | 12 | #include <string> |
13 | |||||
tfarina | ea94afc23 | 2015-10-20 04:23:36 | [diff] [blame] | 14 | #include "base/macros.h" |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 15 | #include "base/memory/scoped_ptr.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" |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 18 | #include "net/http/http_stream.h" |
[email protected] | f4533ba | 2013-11-28 09:35:41 | [diff] [blame] | 19 | #include "net/url_request/websocket_handshake_userdata_key.h" |
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 20 | #include "net/websockets/websocket_stream.h" |
21 | |||||
22 | namespace net { | ||||
23 | |||||
24 | class ClientSocketHandle; | ||||
25 | class SpdySession; | ||||
26 | |||||
27 | // WebSocketHandshakeStreamBase is the base class of | ||||
28 | // WebSocketBasicHandshakeStream. net/http code uses this interface to handle | ||||
29 | // WebSocketBasicHandshakeStream when it needs to be treated differently from | ||||
30 | // HttpStreamBase. | ||||
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 31 | class NET_EXPORT WebSocketHandshakeStreamBase : public HttpStream { |
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 32 | public: |
[email protected] | efa9e73 | 2013-11-29 02:55:05 | [diff] [blame] | 33 | // An object that stores data needed for the creation of a |
34 | // WebSocketBasicHandshakeStream object. A new CreateHelper is used for each | ||||
35 | // WebSocket connection. | ||||
36 | class NET_EXPORT_PRIVATE CreateHelper : public base::SupportsUserData::Data { | ||||
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 37 | public: |
[email protected] | f4533ba | 2013-11-28 09:35:41 | [diff] [blame] | 38 | // Returns a key to use to lookup this object in a URLRequest object. It is |
39 | // different from any other key that is supplied to | ||||
40 | // URLRequest::SetUserData(). | ||||
41 | static const void* DataKey() { return kWebSocketHandshakeUserDataKey; } | ||||
42 | |||||
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 43 | ~CreateHelper() override {} |
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 44 | |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 45 | // Create a WebSocketBasicHandshakeStream. This is called after the |
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 46 | // underlying connection has been established but before any handshake data |
[email protected] | efa9e73 | 2013-11-29 02:55:05 | [diff] [blame] | 47 | // has been transferred. This can be called more than once in the case that |
48 | // HTTP authentication is needed. | ||||
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 49 | virtual WebSocketHandshakeStreamBase* CreateBasicStream( |
[email protected] | 7e841a5 | 2013-11-22 09:04:21 | [diff] [blame] | 50 | scoped_ptr<ClientSocketHandle> connection, |
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 51 | bool using_proxy) = 0; |
52 | |||||
53 | // Create a WebSocketSpdyHandshakeStream (unimplemented as of October 2013) | ||||
54 | virtual WebSocketHandshakeStreamBase* CreateSpdyStream( | ||||
55 | const base::WeakPtr<SpdySession>& session, | ||||
56 | bool use_relative_url) = 0; | ||||
57 | }; | ||||
58 | |||||
[email protected] | f4533ba | 2013-11-28 09:35:41 | [diff] [blame] | 59 | // This has to have an inline implementation so that the net/url_request/ |
60 | // tests do not fail on iOS. | ||||
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 61 | ~WebSocketHandshakeStreamBase() override {} |
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 62 | |
63 | // After the handshake has completed, this method creates a WebSocketStream | ||||
64 | // (of the appropriate type) from the WebSocketHandshakeStreamBase object. | ||||
65 | // The WebSocketHandshakeStreamBase object is unusable after Upgrade() has | ||||
66 | // been called. | ||||
67 | virtual scoped_ptr<WebSocketStream> Upgrade() = 0; | ||||
68 | |||||
69 | protected: | ||||
[email protected] | f4533ba | 2013-11-28 09:35:41 | [diff] [blame] | 70 | // As with the destructor, this must be inline. |
[email protected] | a9cf2b9 | 2013-10-30 12:08:49 | [diff] [blame] | 71 | WebSocketHandshakeStreamBase() {} |
72 | |||||
73 | private: | ||||
74 | DISALLOW_COPY_AND_ASSIGN(WebSocketHandshakeStreamBase); | ||||
75 | }; | ||||
76 | |||||
77 | } // namespace net | ||||
78 | |||||
79 | #endif // NET_WEBSOCKETS_WEBSOCKET_HANDSHAKE_STREAM_BASE_H_ |