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