1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/*
* Copyright (C) 2009 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBSOCKETS_WEBSOCKET_CHANNEL_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBSOCKETS_WEBSOCKET_CHANNEL_H_
#include <memory>
#include "base/callback_forward.h"
#include "base/macros.h"
#include "third_party/blink/public/mojom/devtools/console_message.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/source_location.h"
#include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
namespace blink {
class BlobDataHandle;
class DOMArrayBuffer;
class KURL;
class MODULES_EXPORT WebSocketChannel
: public GarbageCollected<WebSocketChannel> {
public:
enum class SendResult { SENT_SYNCHRONOUSLY, CALLBACK_WILL_BE_CALLED };
WebSocketChannel() = default;
virtual ~WebSocketChannel() = default;
enum CloseEventCode {
kCloseEventCodeNotSpecified = -1,
kCloseEventCodeNormalClosure = 1000,
kCloseEventCodeGoingAway = 1001,
kCloseEventCodeProtocolError = 1002,
kCloseEventCodeUnsupportedData = 1003,
kCloseEventCodeFrameTooLarge = 1004,
kCloseEventCodeNoStatusRcvd = 1005,
kCloseEventCodeAbnormalClosure = 1006,
kCloseEventCodeInvalidFramePayloadData = 1007,
kCloseEventCodePolicyViolation = 1008,
kCloseEventCodeMessageTooBig = 1009,
kCloseEventCodeMandatoryExt = 1010,
kCloseEventCodeInternalError = 1011,
kCloseEventCodeTLSHandshake = 1015,
kCloseEventCodeMinimumUserDefined = 3000,
kCloseEventCodeMaximumUserDefined = 4999
};
virtual bool Connect(const KURL&, const String& protocol) = 0;
virtual SendResult Send(const std::string&,
base::OnceClosure completion_callback) = 0;
virtual SendResult Send(const DOMArrayBuffer&,
size_t byte_offset,
size_t byte_length,
base::OnceClosure completion_callback) = 0;
// Blobs are always sent asynchronously. No callers currently need completion
// callbacks for Blobs, so they are not implemented.
virtual void Send(scoped_refptr<BlobDataHandle>) = 0;
// Do not call |Send| after calling this method.
virtual void Close(int code, const String& reason) = 0;
// Log the reason text and close the connection. Will call DidClose().
// The mojom::ConsoleMessageLevel parameter will be used for the level
// of the message shown at the devtools console. SourceLocation parameter may
// be shown with the reason text at the devtools console. Even if location is
// specified, it may be ignored and the "current" location in the sense of
// JavaScript execution may be shown if this method is called in a JS
// execution context. Location should not be null.
virtual void Fail(const String& reason,
mojom::ConsoleMessageLevel,
std::unique_ptr<SourceLocation>) = 0;
// Do not call any methods after calling this method.
virtual void Disconnect() = 0; // Will suppress didClose().
// Cancel the WebSocket handshake. Does nothing if the connection is already
// established. Do not call any other methods after this one.
virtual void CancelHandshake() = 0;
// Clients can call ApplyBackpressure() to indicate that they want to stop
// receiving new messages. WebSocketChannelClient::DidReceive*Message() may
// still be called after this, until existing flow control quota is used up.
virtual void ApplyBackpressure() = 0;
// Clients should call RemoveBackpressure() after calling ApplyBackpressure()
// to indicate that they are ready to receive new messages.
virtual void RemoveBackpressure() = 0;
virtual void Trace(Visitor* visitor) {}
private:
DISALLOW_COPY_AND_ASSIGN(WebSocketChannel);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_WEBSOCKETS_WEBSOCKET_CHANNEL_H_
|