blob: dda9f3d10b2cc07c29cc14dee17fb2807855384b [file] [log] [blame]
[email protected]a9cf2b92013-10-30 12:08:491// 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]96868202014-01-09 10:38:0412#include <string>
13
tfarinaea94afc232015-10-20 04:23:3614#include "base/macros.h"
[email protected]7e841a52013-11-22 09:04:2115#include "base/memory/scoped_ptr.h"
[email protected]a9cf2b92013-10-30 12:08:4916#include "base/memory/weak_ptr.h"
[email protected]f4533ba2013-11-28 09:35:4117#include "base/supports_user_data.h"
yhiranoa7e05bb2014-11-06 05:40:3918#include "net/http/http_stream.h"
[email protected]f4533ba2013-11-28 09:35:4119#include "net/url_request/websocket_handshake_userdata_key.h"
[email protected]a9cf2b92013-10-30 12:08:4920#include "net/websockets/websocket_stream.h"
21
22namespace net {
23
24class ClientSocketHandle;
25class 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.
yhiranoa7e05bb2014-11-06 05:40:3931class NET_EXPORT WebSocketHandshakeStreamBase : public HttpStream {
[email protected]a9cf2b92013-10-30 12:08:4932 public:
[email protected]efa9e732013-11-29 02:55:0533 // 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]a9cf2b92013-10-30 12:08:4937 public:
[email protected]f4533ba2013-11-28 09:35:4138 // 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
dchengb03027d2014-10-21 12:00:2043 ~CreateHelper() override {}
[email protected]a9cf2b92013-10-30 12:08:4944
[email protected]7e841a52013-11-22 09:04:2145 // Create a WebSocketBasicHandshakeStream. This is called after the
[email protected]a9cf2b92013-10-30 12:08:4946 // underlying connection has been established but before any handshake data
[email protected]efa9e732013-11-29 02:55:0547 // has been transferred. This can be called more than once in the case that
48 // HTTP authentication is needed.
[email protected]a9cf2b92013-10-30 12:08:4949 virtual WebSocketHandshakeStreamBase* CreateBasicStream(
[email protected]7e841a52013-11-22 09:04:2150 scoped_ptr<ClientSocketHandle> connection,
[email protected]a9cf2b92013-10-30 12:08:4951 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]f4533ba2013-11-28 09:35:4159 // This has to have an inline implementation so that the net/url_request/
60 // tests do not fail on iOS.
dchengb03027d2014-10-21 12:00:2061 ~WebSocketHandshakeStreamBase() override {}
[email protected]a9cf2b92013-10-30 12:08:4962
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]f4533ba2013-11-28 09:35:4170 // As with the destructor, this must be inline.
[email protected]a9cf2b92013-10-30 12:08:4971 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_