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/text/WTFString.h"
44 class ExecutionContext;
45 class WebSocketChannelClient;
47 // FIXME: WebSocketChannel needs to be RefCountedGarbageCollected to support manual ref/deref
48 // in MainThreadWebSocketChannelImpl. We should change it to GarbageCollectedFinalized once
49 // we remove MainThreadWebSocketChannelImpl.
50 class WebSocketChannel : public RefCountedGarbageCollected<WebSocketChannel> {
51 WTF_MAKE_NONCOPYABLE(WebSocketChannel);
53 WebSocketChannel() { }
54 static WebSocketChannel* create(ExecutionContext*, WebSocketChannelClient*);
57 CloseEventCodeNotSpecified = -1,
58 CloseEventCodeNormalClosure = 1000,
59 CloseEventCodeGoingAway = 1001,
60 CloseEventCodeProtocolError = 1002,
61 CloseEventCodeUnsupportedData = 1003,
62 CloseEventCodeFrameTooLarge = 1004,
63 CloseEventCodeNoStatusRcvd = 1005,
64 CloseEventCodeAbnormalClosure = 1006,
65 CloseEventCodeInvalidFramePayloadData = 1007,
66 CloseEventCodePolicyViolation = 1008,
67 CloseEventCodeMessageTooBig = 1009,
68 CloseEventCodeMandatoryExt = 1010,
69 CloseEventCodeInternalError = 1011,
70 CloseEventCodeTLSHandshake = 1015,
71 CloseEventCodeMinimumUserDefined = 3000,
72 CloseEventCodeMaximumUserDefined = 4999
75 virtual bool connect(const KURL&, const String& protocol) = 0;
76 virtual void send(const String& message) = 0;
77 virtual void send(const ArrayBuffer&, unsigned byteOffset, unsigned byteLength) = 0;
78 virtual void send(PassRefPtr<BlobDataHandle>) = 0;
80 // For WorkerThreadableWebSocketChannel.
81 virtual void send(PassOwnPtr<Vector<char> >) = 0;
83 // Do not call |send| after calling this method.
84 virtual void close(int code, const String& reason) = 0;
86 // Log the reason text and close the connection. Will call didClose().
87 // The MessageLevel parameter will be used for the level of the message
88 // shown at the devtool console.
89 // sourceURL and lineNumber parameters may be shown with the reason text
90 // at the devtool console.
91 // Even if sourceURL and lineNumber are specified, they may be ignored
92 // and the "current" url and the line number in the sense of
93 // JavaScript execution may be shown if this method is called in
94 // a JS execution context.
95 // You can specify String() and 0 for sourceURL and lineNumber
96 // respectively, if you can't / needn't provide the information.
97 virtual void fail(const String& reason, MessageLevel, const String& sourceURL, unsigned lineNumber) = 0;
99 // Do not call any methods after calling this method.
100 virtual void disconnect() = 0; // Will suppress didClose().
102 virtual void suspend() = 0;
103 virtual void resume() = 0;
105 virtual ~WebSocketChannel() { }
107 virtual void trace(Visitor*) { }
112 #endif // WebSocketChannel_h