blob: 0edf249082a112ca94fea9a5b8675bce6e89f87d [file] [log] [blame]
[email protected]999bcaa2013-07-17 13:42:541// 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_EVENT_INTERFACE_H_
6#define NET_WEBSOCKETS_WEBSOCKET_EVENT_INTERFACE_H_
7
tfarina8a2c66c22015-10-13 19:14:498#include <stdint.h>
Avi Drissman13fc8932015-12-20 04:40:469
danakj9c5cab52016-04-16 00:54:3310#include <memory>
[email protected]999bcaa2013-07-17 13:42:5411#include <string>
12#include <vector>
13
Yutaka Hirano70fa25912018-06-06 05:26:5414#include "base/callback_forward.h"
[email protected]f485985e2013-10-24 13:47:4415#include "base/compiler_specific.h" // for WARN_UNUSED_RESULT
tfarinaea94afc232015-10-20 04:23:3616#include "base/macros.h"
Bence Béky65623972018-03-05 15:31:5617#include "base/memory/scoped_refptr.h"
Yutaka Hirano70fa25912018-06-06 05:26:5418#include "base/optional.h"
[email protected]999bcaa2013-07-17 13:42:5419#include "net/base/net_export.h"
20
[email protected]a62449522014-06-05 11:11:1521class GURL;
22
[email protected]999bcaa2013-07-17 13:42:5423namespace net {
24
Yutaka Hirano70fa25912018-06-06 05:26:5425class AuthChallengeInfo;
26class AuthCredentials;
Tsuyoshi Horo01faed62019-02-20 22:11:3727class IPEndPoint;
Yutaka Hirano70fa25912018-06-06 05:26:5428class HttpResponseHeaders;
darin0da77e922016-10-04 17:31:2329class IOBuffer;
[email protected]a62449522014-06-05 11:11:1530class SSLInfo;
yhirano4a593832016-10-24 18:58:2231class URLRequest;
[email protected]cd48ed12014-01-22 14:34:2232struct WebSocketHandshakeRequestInfo;
33struct WebSocketHandshakeResponseInfo;
34
[email protected]999bcaa2013-07-17 13:42:5435// Interface for events sent from the network layer to the content layer. These
36// events will generally be sent as-is to the renderer process.
37class NET_EXPORT WebSocketEventInterface {
38 public:
39 typedef int WebSocketMessageType;
[email protected]f485985e2013-10-24 13:47:4440
[email protected]999bcaa2013-07-17 13:42:5441 virtual ~WebSocketEventInterface() {}
[email protected]6c5d9f62014-01-27 15:05:2142
yhirano4a593832016-10-24 18:58:2243 // Called when a URLRequest is created for handshaking.
44 virtual void OnCreateURLRequest(URLRequest* request) = 0;
45
tyoshinoc06da562015-03-06 06:02:4246 // Called in response to an AddChannelRequest. This means that a response has
47 // been received from the remote server.
Yutaka Hirano4165de92018-04-10 11:46:4948 virtual void OnAddChannelResponse(const std::string& selected_subprotocol,
49 const std::string& extensions) = 0;
[email protected]999bcaa2013-07-17 13:42:5450
51 // Called when a data frame has been received from the remote host and needs
[email protected]f485985e2013-10-24 13:47:4452 // to be forwarded to the renderer process.
Yutaka Hirano4165de92018-04-10 11:46:4953 virtual void OnDataFrame(bool fin,
54 WebSocketMessageType type,
55 scoped_refptr<IOBuffer> buffer,
56 size_t buffer_size) = 0;
[email protected]999bcaa2013-07-17 13:42:5457
58 // Called to provide more send quota for this channel to the renderer
59 // process. Currently the quota units are always bytes of message body
[email protected]f485985e2013-10-24 13:47:4460 // data. In future it might depend on the type of multiplexing in use.
Yutaka Hirano4165de92018-04-10 11:46:4961 virtual void OnFlowControl(int64_t quota) = 0;
[email protected]999bcaa2013-07-17 13:42:5462
63 // Called when the remote server has Started the WebSocket Closing
64 // Handshake. The client should not attempt to send any more messages after
65 // receiving this message. It will be followed by OnDropChannel() when the
[email protected]f485985e2013-10-24 13:47:4466 // closing handshake is complete.
Yutaka Hirano4165de92018-04-10 11:46:4967 virtual void OnClosingHandshake() = 0;
[email protected]999bcaa2013-07-17 13:42:5468
69 // Called when the channel has been dropped, either due to a network close, a
70 // network error, or a protocol error. This may or may not be preceeded by a
71 // call to OnClosingHandshake().
72 //
73 // Warning: Both the |code| and |reason| are passed through to Javascript, so
74 // callers must take care not to provide details that could be useful to
75 // attackers attempting to use WebSockets to probe networks.
76 //
[email protected]86ec55502014-02-10 13:16:1677 // |was_clean| should be true if the closing handshake completed successfully.
78 //
[email protected]999bcaa2013-07-17 13:42:5479 // The channel should not be used again after OnDropChannel() has been
80 // called.
81 //
Yutaka Hirano4165de92018-04-10 11:46:4982 // This function deletes the Channel.
83 virtual void OnDropChannel(bool was_clean,
84 uint16_t code,
85 const std::string& reason) = 0;
[email protected]999bcaa2013-07-17 13:42:5486
[email protected]96868202014-01-09 10:38:0487 // Called when the browser fails the channel, as specified in the spec.
88 //
89 // The channel should not be used again after OnFailChannel() has been
90 // called.
91 //
Yutaka Hirano4165de92018-04-10 11:46:4992 // This function deletes the Channel.
93 virtual void OnFailChannel(const std::string& message) = 0;
[email protected]96868202014-01-09 10:38:0494
[email protected]cd48ed12014-01-22 14:34:2295 // Called when the browser starts the WebSocket Opening Handshake.
Yutaka Hirano4165de92018-04-10 11:46:4996 virtual void OnStartOpeningHandshake(
97 std::unique_ptr<WebSocketHandshakeRequestInfo> request) = 0;
[email protected]cd48ed12014-01-22 14:34:2298
99 // Called when the browser finishes the WebSocket Opening Handshake.
Yutaka Hirano4165de92018-04-10 11:46:49100 virtual void OnFinishOpeningHandshake(
101 std::unique_ptr<WebSocketHandshakeResponseInfo> response) = 0;
[email protected]cd48ed12014-01-22 14:34:22102
[email protected]a62449522014-06-05 11:11:15103 // Callbacks to be used in response to a call to OnSSLCertificateError. Very
104 // similar to content::SSLErrorHandler::Delegate (which we can't use directly
105 // due to layering constraints).
106 class NET_EXPORT SSLErrorCallbacks {
107 public:
108 virtual ~SSLErrorCallbacks() {}
109
110 // Cancels the SSL response in response to the error.
111 virtual void CancelSSLRequest(int error, const SSLInfo* ssl_info) = 0;
112
113 // Continue with the SSL connection despite the error.
114 virtual void ContinueSSLRequest() = 0;
115 };
116
117 // Called on SSL Certificate Error during the SSL handshake. Should result in
118 // a call to either ssl_error_callbacks->ContinueSSLRequest() or
119 // ssl_error_callbacks->CancelSSLRequest(). Normally the implementation of
120 // this method will delegate to content::SSLManager::OnSSLCertificateError to
121 // make the actual decision. The callbacks must not be called after the
122 // WebSocketChannel has been destroyed.
Yutaka Hirano4165de92018-04-10 11:46:49123 virtual void OnSSLCertificateError(
danakj9c5cab52016-04-16 00:54:33124 std::unique_ptr<SSLErrorCallbacks> ssl_error_callbacks,
[email protected]a62449522014-06-05 11:11:15125 const GURL& url,
Emily Starkd9df3d32019-04-29 17:54:57126 int net_error,
[email protected]a62449522014-06-05 11:11:15127 const SSLInfo& ssl_info,
Yutaka Hirano4165de92018-04-10 11:46:49128 bool fatal) = 0;
[email protected]a62449522014-06-05 11:11:15129
Yutaka Hirano70fa25912018-06-06 05:26:54130 // Called when authentication is required. Returns a net error. The opening
131 // handshake is blocked when this function returns ERR_IO_PENDING.
132 // In that case calling |callback| resumes the handshake. |callback| can be
133 // called during the opening handshake. An implementation can rewrite
134 // |*credentials| (in the sync case) or provide new credentials (in the
135 // async case).
136 // Providing null credentials (nullopt in the sync case and nullptr in the
137 // async case) cancels authentication. Otherwise the new credentials are set
138 // and the opening handshake will be retried with the credentials.
139 virtual int OnAuthRequired(
Emily Starkf2c9bbd2019-04-09 17:08:58140 const AuthChallengeInfo& auth_info,
Yutaka Hirano70fa25912018-06-06 05:26:54141 scoped_refptr<HttpResponseHeaders> response_headers,
Tsuyoshi Horo01faed62019-02-20 22:11:37142 const IPEndPoint& socket_address,
Yutaka Hirano70fa25912018-06-06 05:26:54143 base::OnceCallback<void(const AuthCredentials*)> callback,
144 base::Optional<AuthCredentials>* credentials) = 0;
145
[email protected]999bcaa2013-07-17 13:42:54146 protected:
147 WebSocketEventInterface() {}
148
149 private:
150 DISALLOW_COPY_AND_ASSIGN(WebSocketEventInterface);
151};
152
153} // namespace net
154
155#endif // NET_WEBSOCKETS_WEBSOCKET_EVENT_INTERFACE_H_