| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "wtf/Forward.h" | 44 #include "wtf/Forward.h" |
| 45 #include "wtf/OwnPtr.h" | 45 #include "wtf/OwnPtr.h" |
| 46 #include "wtf/RefCounted.h" | 46 #include "wtf/RefCounted.h" |
| 47 #include "wtf/text/AtomicStringHash.h" | 47 #include "wtf/text/AtomicStringHash.h" |
| 48 | 48 |
| 49 namespace WebCore { | 49 namespace WebCore { |
| 50 | 50 |
| 51 class Blob; | 51 class Blob; |
| 52 class ExceptionState; | 52 class ExceptionState; |
| 53 | 53 |
| 54 class WebSocket FINAL : public RefCountedWillBeRefCountedGarbageCollected<WebSoc
ket>, public ScriptWrappable, public EventTargetWithInlineData, public ActiveDOM
Object, public WebSocketChannelClient { | 54 class WebSocket : public RefCountedWillBeRefCountedGarbageCollected<WebSocket>,
public ScriptWrappable, public EventTargetWithInlineData, public ActiveDOMObject
, public WebSocketChannelClient { |
| 55 REFCOUNTED_EVENT_TARGET(WebSocket); | 55 REFCOUNTED_EVENT_TARGET(WebSocket); |
| 56 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(WebSocket); | 56 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(WebSocket); |
| 57 public: | 57 public: |
| 58 static const char* subProtocolSeperator(); | 58 static const char* subprotocolSeperator(); |
| 59 // WebSocket instances must be used with a wrapper since this class's | 59 // WebSocket instances must be used with a wrapper since this class's |
| 60 // lifetime management is designed assuming the V8 holds a ref on it while | 60 // lifetime management is designed assuming the V8 holds a ref on it while |
| 61 // hasPendingActivity() returns true. | 61 // hasPendingActivity() returns true. |
| 62 static PassRefPtrWillBeRawPtr<WebSocket> create(ExecutionContext*, const Str
ing& url, ExceptionState&); | 62 static PassRefPtrWillBeRawPtr<WebSocket> create(ExecutionContext*, const Str
ing& url, ExceptionState&); |
| 63 static PassRefPtrWillBeRawPtr<WebSocket> create(ExecutionContext*, const Str
ing& url, const String& protocol, ExceptionState&); | 63 static PassRefPtrWillBeRawPtr<WebSocket> create(ExecutionContext*, const Str
ing& url, const String& protocol, ExceptionState&); |
| 64 static PassRefPtrWillBeRawPtr<WebSocket> create(ExecutionContext*, const Str
ing& url, const Vector<String>& protocols, ExceptionState&); | 64 static PassRefPtrWillBeRawPtr<WebSocket> create(ExecutionContext*, const Str
ing& url, const Vector<String>& protocols, ExceptionState&); |
| 65 virtual ~WebSocket(); | 65 virtual ~WebSocket(); |
| 66 | 66 |
| 67 enum State { | 67 enum State { |
| 68 CONNECTING = 0, | 68 CONNECTING = 0, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 virtual void didConnect() OVERRIDE; | 119 virtual void didConnect() OVERRIDE; |
| 120 virtual void didReceiveMessage(const String& message) OVERRIDE; | 120 virtual void didReceiveMessage(const String& message) OVERRIDE; |
| 121 virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> >) OVERRIDE; | 121 virtual void didReceiveBinaryData(PassOwnPtr<Vector<char> >) OVERRIDE; |
| 122 virtual void didReceiveMessageError() OVERRIDE; | 122 virtual void didReceiveMessageError() OVERRIDE; |
| 123 virtual void didUpdateBufferedAmount(unsigned long bufferedAmount) OVERRIDE; | 123 virtual void didUpdateBufferedAmount(unsigned long bufferedAmount) OVERRIDE; |
| 124 virtual void didStartClosingHandshake() OVERRIDE; | 124 virtual void didStartClosingHandshake() OVERRIDE; |
| 125 virtual void didClose(unsigned long unhandledBufferedAmount, ClosingHandshak
eCompletionStatus, unsigned short code, const String& reason) OVERRIDE; | 125 virtual void didClose(unsigned long unhandledBufferedAmount, ClosingHandshak
eCompletionStatus, unsigned short code, const String& reason) OVERRIDE; |
| 126 | 126 |
| 127 virtual void trace(Visitor*) OVERRIDE; | 127 virtual void trace(Visitor*) OVERRIDE; |
| 128 | 128 |
| 129 static bool isValidSubprotocolString(const String&); |
| 130 |
| 131 protected: |
| 132 explicit WebSocket(ExecutionContext*); |
| 133 |
| 129 private: | 134 private: |
| 130 // FIXME: This should inherit WebCore::EventQueue. | 135 // FIXME: This should inherit WebCore::EventQueue. |
| 131 class EventQueue FINAL : public RefCountedWillBeGarbageCollectedFinalized<Ev
entQueue> { | 136 class EventQueue FINAL : public RefCountedWillBeGarbageCollectedFinalized<Ev
entQueue> { |
| 132 public: | 137 public: |
| 133 static PassRefPtrWillBeRawPtr<EventQueue> create(EventTarget* target) | 138 static PassRefPtrWillBeRawPtr<EventQueue> create(EventTarget* target) |
| 134 { | 139 { |
| 135 return adoptRefWillBeNoop(new EventQueue(target)); | 140 return adoptRefWillBeNoop(new EventQueue(target)); |
| 136 } | 141 } |
| 137 ~EventQueue(); | 142 ~EventQueue(); |
| 138 | 143 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 }; | 175 }; |
| 171 | 176 |
| 172 enum WebSocketSendType { | 177 enum WebSocketSendType { |
| 173 WebSocketSendTypeString, | 178 WebSocketSendTypeString, |
| 174 WebSocketSendTypeArrayBuffer, | 179 WebSocketSendTypeArrayBuffer, |
| 175 WebSocketSendTypeArrayBufferView, | 180 WebSocketSendTypeArrayBufferView, |
| 176 WebSocketSendTypeBlob, | 181 WebSocketSendTypeBlob, |
| 177 WebSocketSendTypeMax, | 182 WebSocketSendTypeMax, |
| 178 }; | 183 }; |
| 179 | 184 |
| 180 explicit WebSocket(ExecutionContext*); | 185 // This function is virtual for unittests. |
| 186 // FIXME: Move WebSocketChannel::create here. |
| 187 virtual PassRefPtrWillBeRawPtr<WebSocketChannel> createChannel(ExecutionCont
ext* context, WebSocketChannelClient* client) |
| 188 { |
| 189 return WebSocketChannel::create(context, client); |
| 190 } |
| 181 | 191 |
| 182 // Adds a console message with JSMessageSource and ErrorMessageLevel. | 192 // Adds a console message with JSMessageSource and ErrorMessageLevel. |
| 183 void logError(const String& message); | 193 void logError(const String& message); |
| 184 | 194 |
| 185 // Handle the JavaScript close method call. close() methods on this class | 195 // Handle the JavaScript close method call. close() methods on this class |
| 186 // are just for determining if the optional code argument is supplied or | 196 // are just for determining if the optional code argument is supplied or |
| 187 // not. | 197 // not. |
| 188 void closeInternal(int, const String&, ExceptionState&); | 198 void closeInternal(int, const String&, ExceptionState&); |
| 189 | 199 |
| 190 size_t getFramingOverhead(size_t payloadSize); | 200 size_t getFramingOverhead(size_t payloadSize); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 216 // The subprotocol the server selected. | 226 // The subprotocol the server selected. |
| 217 String m_subprotocol; | 227 String m_subprotocol; |
| 218 String m_extensions; | 228 String m_extensions; |
| 219 | 229 |
| 220 RefPtrWillBeMember<EventQueue> m_eventQueue; | 230 RefPtrWillBeMember<EventQueue> m_eventQueue; |
| 221 }; | 231 }; |
| 222 | 232 |
| 223 } // namespace WebCore | 233 } // namespace WebCore |
| 224 | 234 |
| 225 #endif // WebSocket_h | 235 #endif // WebSocket_h |
| OLD | NEW |