OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 29 matching lines...) Expand all Loading... |
40 #include "modules/websockets/WebSocketChannelClient.h" | 40 #include "modules/websockets/WebSocketChannelClient.h" |
41 #include "weborigin/KURL.h" | 41 #include "weborigin/KURL.h" |
42 #include "wtf/Forward.h" | 42 #include "wtf/Forward.h" |
43 #include "wtf/OwnPtr.h" | 43 #include "wtf/OwnPtr.h" |
44 #include "wtf/RefCounted.h" | 44 #include "wtf/RefCounted.h" |
45 #include "wtf/text/AtomicStringHash.h" | 45 #include "wtf/text/AtomicStringHash.h" |
46 | 46 |
47 namespace WebCore { | 47 namespace WebCore { |
48 | 48 |
49 class Blob; | 49 class Blob; |
50 class ExceptionState; | |
51 | 50 |
52 class WebSocket : public RefCounted<WebSocket>, public ScriptWrappable, public E
ventTarget, public ActiveDOMObject, public WebSocketChannelClient { | 51 class WebSocket : public RefCounted<WebSocket>, public ScriptWrappable, public E
ventTarget, public ActiveDOMObject, public WebSocketChannelClient { |
53 public: | 52 public: |
54 static const char* subProtocolSeperator(); | 53 static const char* subProtocolSeperator(); |
55 static PassRefPtr<WebSocket> create(ScriptExecutionContext*); | 54 static PassRefPtr<WebSocket> create(ScriptExecutionContext*); |
56 static PassRefPtr<WebSocket> create(ScriptExecutionContext*, const String& u
rl, ExceptionState&); | 55 static PassRefPtr<WebSocket> create(ScriptExecutionContext*, const String& u
rl, ExceptionCode&); |
57 static PassRefPtr<WebSocket> create(ScriptExecutionContext*, const String& u
rl, const String& protocol, ExceptionState&); | 56 static PassRefPtr<WebSocket> create(ScriptExecutionContext*, const String& u
rl, const String& protocol, ExceptionCode&); |
58 static PassRefPtr<WebSocket> create(ScriptExecutionContext*, const String& u
rl, const Vector<String>& protocols, ExceptionState&); | 57 static PassRefPtr<WebSocket> create(ScriptExecutionContext*, const String& u
rl, const Vector<String>& protocols, ExceptionCode&); |
59 virtual ~WebSocket(); | 58 virtual ~WebSocket(); |
60 | 59 |
61 enum State { | 60 enum State { |
62 CONNECTING = 0, | 61 CONNECTING = 0, |
63 OPEN = 1, | 62 OPEN = 1, |
64 CLOSING = 2, | 63 CLOSING = 2, |
65 CLOSED = 3 | 64 CLOSED = 3 |
66 }; | 65 }; |
67 | 66 |
68 void connect(const String& url, ExceptionState&); | 67 void connect(const String& url, ExceptionCode&); |
69 void connect(const String& url, const String& protocol, ExceptionState&); | 68 void connect(const String& url, const String& protocol, ExceptionCode&); |
70 void connect(const String& url, const Vector<String>& protocols, ExceptionSt
ate&); | 69 void connect(const String& url, const Vector<String>& protocols, ExceptionCo
de&); |
71 | 70 |
72 void send(const String& message, ExceptionState&); | 71 void send(const String& message, ExceptionCode&); |
73 void send(ArrayBuffer*, ExceptionState&); | 72 void send(ArrayBuffer*, ExceptionCode&); |
74 void send(ArrayBufferView*, ExceptionState&); | 73 void send(ArrayBufferView*, ExceptionCode&); |
75 void send(Blob*, ExceptionState&); | 74 void send(Blob*, ExceptionCode&); |
76 | 75 |
77 // To distinguish close method call with the code parameter from one | 76 // To distinguish close method call with the code parameter from one |
78 // without, we have these three signatures. Use of | 77 // without, we have these three signatures. Use of |
79 // Optional=DefaultIsUndefined in the IDL file doesn't help for now since | 78 // Optional=DefaultIsUndefined in the IDL file doesn't help for now since |
80 // it's bound to a value of 0 which is indistinguishable from the case 0 | 79 // it's bound to a value of 0 which is indistinguishable from the case 0 |
81 // is passed as code parameter. | 80 // is passed as code parameter. |
82 void close(unsigned short code, const String& reason, ExceptionState&); | 81 void close(unsigned short code, const String& reason, ExceptionCode&); |
83 void close(ExceptionState&); | 82 void close(ExceptionCode&); |
84 void close(unsigned short code, ExceptionState&); | 83 void close(unsigned short code, ExceptionCode&); |
85 | 84 |
86 const KURL& url() const; | 85 const KURL& url() const; |
87 State readyState() const; | 86 State readyState() const; |
88 unsigned long bufferedAmount() const; | 87 unsigned long bufferedAmount() const; |
89 | 88 |
90 String protocol() const; | 89 String protocol() const; |
91 String extensions() const; | 90 String extensions() const; |
92 | 91 |
93 String binaryType() const; | 92 String binaryType() const; |
94 void setBinaryType(const String&); | 93 void setBinaryType(const String&); |
(...skipping 25 matching lines...) Expand all Loading... |
120 virtual void didUpdateBufferedAmount(unsigned long bufferedAmount) OVERRIDE; | 119 virtual void didUpdateBufferedAmount(unsigned long bufferedAmount) OVERRIDE; |
121 virtual void didStartClosingHandshake() OVERRIDE; | 120 virtual void didStartClosingHandshake() OVERRIDE; |
122 virtual void didClose(unsigned long unhandledBufferedAmount, ClosingHandshak
eCompletionStatus, unsigned short code, const String& reason) OVERRIDE; | 121 virtual void didClose(unsigned long unhandledBufferedAmount, ClosingHandshak
eCompletionStatus, unsigned short code, const String& reason) OVERRIDE; |
123 | 122 |
124 private: | 123 private: |
125 explicit WebSocket(ScriptExecutionContext*); | 124 explicit WebSocket(ScriptExecutionContext*); |
126 | 125 |
127 // Handle the JavaScript close method call. close() methods on this class | 126 // Handle the JavaScript close method call. close() methods on this class |
128 // are just for determining if the optional code argument is supplied or | 127 // are just for determining if the optional code argument is supplied or |
129 // not. | 128 // not. |
130 void closeInternal(int, const String&, ExceptionState&); | 129 void closeInternal(int, const String&, ExceptionCode&); |
131 | 130 |
132 virtual void refEventTarget() { ref(); } | 131 virtual void refEventTarget() { ref(); } |
133 virtual void derefEventTarget() { deref(); } | 132 virtual void derefEventTarget() { deref(); } |
134 virtual EventTargetData* eventTargetData(); | 133 virtual EventTargetData* eventTargetData(); |
135 virtual EventTargetData* ensureEventTargetData(); | 134 virtual EventTargetData* ensureEventTargetData(); |
136 | 135 |
137 size_t getFramingOverhead(size_t payloadSize); | 136 size_t getFramingOverhead(size_t payloadSize); |
138 | 137 |
139 // Checks the result of WebSocketChannel::send() method, and shows console | 138 // Checks the result of WebSocketChannel::send() method, and shows console |
140 // message and sets ec appropriately. | 139 // message and sets ec appropriately. |
141 void handleSendResult(WebSocketChannel::SendResult, ExceptionState&); | 140 void handleSendResult(WebSocketChannel::SendResult, ExceptionCode&); |
142 | 141 |
143 // Updates m_bufferedAmountAfterClose given the amount of data passed to | 142 // Updates m_bufferedAmountAfterClose given the amount of data passed to |
144 // send() method after the state changed to CLOSING or CLOSED. | 143 // send() method after the state changed to CLOSING or CLOSED. |
145 void updateBufferedAmountAfterClose(unsigned long); | 144 void updateBufferedAmountAfterClose(unsigned long); |
146 | 145 |
147 enum BinaryType { | 146 enum BinaryType { |
148 BinaryTypeBlob, | 147 BinaryTypeBlob, |
149 BinaryTypeArrayBuffer | 148 BinaryTypeArrayBuffer |
150 }; | 149 }; |
151 | 150 |
152 RefPtr<WebSocketChannel> m_channel; | 151 RefPtr<WebSocketChannel> m_channel; |
153 | 152 |
154 State m_state; | 153 State m_state; |
155 KURL m_url; | 154 KURL m_url; |
156 EventTargetData m_eventTargetData; | 155 EventTargetData m_eventTargetData; |
157 unsigned long m_bufferedAmount; | 156 unsigned long m_bufferedAmount; |
158 unsigned long m_bufferedAmountAfterClose; | 157 unsigned long m_bufferedAmountAfterClose; |
159 BinaryType m_binaryType; | 158 BinaryType m_binaryType; |
160 String m_subprotocol; | 159 String m_subprotocol; |
161 String m_extensions; | 160 String m_extensions; |
162 }; | 161 }; |
163 | 162 |
164 } // namespace WebCore | 163 } // namespace WebCore |
165 | 164 |
166 #endif // WebSocket_h | 165 #endif // WebSocket_h |
OLD | NEW |