2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef WebSocketChannel_h
32 #define WebSocketChannel_h
34 #include "core/frame/ConsoleTypes.h"
35 #include "platform/heap/Handle.h"
36 #include "wtf/Forward.h"
37 #include "wtf/Noncopyable.h"
38 #include "wtf/PassRefPtr.h"
39 #include "wtf/RefCounted.h"
40 #include "wtf/text/WTFString.h"
46 class ExecutionContext;
47 class WebSocketChannelClient;
49 // FIXME: WebSocketChannel needs to be RefCountedGarbageCollected to support manual ref/deref
50 // in MainThreadWebSocketChannelImpl. We should change it to GarbageCollectedFinalized once
51 // we remove MainThreadWebSocketChannelImpl.
52 class WebSocketChannel : public RefCountedWillBeRefCountedGarbageCollected<WebSocketChannel> {
53 WTF_MAKE_NONCOPYABLE(WebSocketChannel);
55 WebSocketChannel() { }
56 static PassRefPtrWillBeRawPtr<WebSocketChannel> create(ExecutionContext*, WebSocketChannelClient*);
65 CloseEventCodeNotSpecified = -1,
66 CloseEventCodeNormalClosure = 1000,
67 CloseEventCodeGoingAway = 1001,
68 CloseEventCodeProtocolError = 1002,
69 CloseEventCodeUnsupportedData = 1003,
70 CloseEventCodeFrameTooLarge = 1004,
71 CloseEventCodeNoStatusRcvd = 1005,
72 CloseEventCodeAbnormalClosure = 1006,
73 CloseEventCodeInvalidFramePayloadData = 1007,
74 CloseEventCodePolicyViolation = 1008,
75 CloseEventCodeMessageTooBig = 1009,
76 CloseEventCodeMandatoryExt = 1010,
77 CloseEventCodeInternalError = 1011,
78 CloseEventCodeTLSHandshake = 1015,
79 CloseEventCodeMinimumUserDefined = 3000,
80 CloseEventCodeMaximumUserDefined = 4999
83 virtual bool connect(const KURL&, const String& protocol) = 0;
84 virtual String subprotocol() = 0; // Will be available after didConnect() callback is invoked.
85 virtual String extensions() = 0; // Will be available after didConnect() callback is invoked.
86 virtual SendResult send(const String& message) = 0;
87 virtual SendResult send(const ArrayBuffer&, unsigned byteOffset, unsigned byteLength) = 0;
88 virtual SendResult send(PassRefPtr<BlobDataHandle>) = 0;
89 virtual unsigned long bufferedAmount() const = 0;
90 virtual void close(int code, const String& reason) = 0;
92 // Log the reason text and close the connection. Will call didClose().
93 // The MessageLevel parameter will be used for the level of the message
94 // shown at the devtool console.
95 // sourceURL and lineNumber parameters may be shown with the reason text
96 // at the devtool console.
97 // Even if sourceURL and lineNumber are specified, they may be ignored
98 // and the "current" url and the line number in the sense of
99 // JavaScript execution may be shown if this method is called in
100 // a JS execution context.
101 // You can specify String() and 0 for sourceURL and lineNumber
102 // respectively, if you can't / needn't provide the information.
103 virtual void fail(const String& reason, MessageLevel, const String& sourceURL, unsigned lineNumber) = 0;
104 void fail(const String& reason, MessageLevel level) { fail(reason, level, String(), 0); }
106 virtual void disconnect() = 0; // Will suppress didClose().
108 virtual void suspend() = 0;
109 virtual void resume() = 0;
111 virtual ~WebSocketChannel() { }
113 virtual void trace(Visitor*) { }
116 } // namespace WebCore
118 #endif // WebSocketChannel_h