Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 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 24 matching lines...) Expand all Loading... | |
| 35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
| 36 #include "core/frame/ConsoleTypes.h" | 36 #include "core/frame/ConsoleTypes.h" |
| 37 #include "modules/websockets/MainThreadWebSocketChannel.h" | 37 #include "modules/websockets/MainThreadWebSocketChannel.h" |
| 38 #include "modules/websockets/NewWebSocketChannelImpl.h" | 38 #include "modules/websockets/NewWebSocketChannelImpl.h" |
| 39 #include "modules/websockets/WebSocketChannel.h" | 39 #include "modules/websockets/WebSocketChannel.h" |
| 40 #include "public/platform/WebArrayBuffer.h" | 40 #include "public/platform/WebArrayBuffer.h" |
| 41 #include "public/platform/WebString.h" | 41 #include "public/platform/WebString.h" |
| 42 #include "public/platform/WebURL.h" | 42 #include "public/platform/WebURL.h" |
| 43 #include "public/web/WebDocument.h" | 43 #include "public/web/WebDocument.h" |
| 44 #include "wtf/ArrayBuffer.h" | 44 #include "wtf/ArrayBuffer.h" |
| 45 #include "wtf/text/CString.h" | |
| 45 #include "wtf/text/WTFString.h" | 46 #include "wtf/text/WTFString.h" |
| 46 | 47 |
| 47 using namespace WebCore; | 48 using namespace WebCore; |
| 48 | 49 |
| 49 namespace blink { | 50 namespace blink { |
| 50 | 51 |
| 51 WebSocketImpl::WebSocketImpl(const WebDocument& document, WebSocketClient* clien t) | 52 WebSocketImpl::WebSocketImpl(const WebDocument& document, WebSocketClient* clien t) |
| 52 : m_client(client) | 53 : m_client(client) |
| 53 , m_binaryType(BinaryTypeBlob) | 54 , m_binaryType(BinaryTypeBlob) |
| 55 , m_isClosingOrClosed(false) | |
| 56 , m_bufferedAmount(0) | |
| 57 , m_bufferedAmountAfterClose(0) | |
| 54 { | 58 { |
| 55 RefPtrWillBeRawPtr<Document> coreDocument = PassRefPtrWillBeRawPtr<Document> (document); | 59 RefPtrWillBeRawPtr<Document> coreDocument = PassRefPtrWillBeRawPtr<Document> (document); |
| 56 if (RuntimeEnabledFeatures::experimentalWebSocketEnabled()) { | 60 if (RuntimeEnabledFeatures::experimentalWebSocketEnabled()) { |
| 57 m_private = NewWebSocketChannelImpl::create(coreDocument.get(), this); | 61 m_private = NewWebSocketChannelImpl::create(coreDocument.get(), this); |
| 58 } else { | 62 } else { |
| 59 m_private = MainThreadWebSocketChannel::create(coreDocument.get(), this) ; | 63 m_private = MainThreadWebSocketChannel::create(coreDocument.get(), this) ; |
| 60 } | 64 } |
| 61 } | 65 } |
| 62 | 66 |
| 63 WebSocketImpl::~WebSocketImpl() | 67 WebSocketImpl::~WebSocketImpl() |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 88 return m_subprotocol; | 92 return m_subprotocol; |
| 89 } | 93 } |
| 90 | 94 |
| 91 WebString WebSocketImpl::extensions() | 95 WebString WebSocketImpl::extensions() |
| 92 { | 96 { |
| 93 return m_extensions; | 97 return m_extensions; |
| 94 } | 98 } |
| 95 | 99 |
| 96 bool WebSocketImpl::sendText(const WebString& message) | 100 bool WebSocketImpl::sendText(const WebString& message) |
| 97 { | 101 { |
| 102 size_t size = message.utf8().length(); | |
| 103 m_bufferedAmount += size; | |
| 104 if (m_isClosingOrClosed) | |
| 105 m_bufferedAmountAfterClose += size; | |
| 106 | |
| 107 // FIXME: Deprecate this call. | |
| 108 m_client->didUpdateBufferedAmount(m_bufferedAmount); | |
| 109 | |
| 110 if (m_isClosingOrClosed) | |
|
yhirano
2014/06/19 07:49:43
I added return here in order not to send messages
| |
| 111 return true; | |
| 112 | |
| 98 return m_private->send(message) == WebSocketChannel::SendSuccess; | 113 return m_private->send(message) == WebSocketChannel::SendSuccess; |
| 99 } | 114 } |
| 100 | 115 |
| 101 bool WebSocketImpl::sendArrayBuffer(const WebArrayBuffer& webArrayBuffer) | 116 bool WebSocketImpl::sendArrayBuffer(const WebArrayBuffer& webArrayBuffer) |
| 102 { | 117 { |
| 118 size_t size = webArrayBuffer.byteLength(); | |
| 119 m_bufferedAmount += size; | |
| 120 if (m_isClosingOrClosed) | |
| 121 m_bufferedAmountAfterClose += size; | |
| 122 | |
| 123 // FIXME: Deprecate this call. | |
| 124 m_client->didUpdateBufferedAmount(m_bufferedAmount); | |
| 125 | |
| 126 if (m_isClosingOrClosed) | |
| 127 return true; | |
| 128 | |
| 103 return m_private->send(*PassRefPtr<ArrayBuffer>(webArrayBuffer), 0, webArray Buffer.byteLength()) == WebSocketChannel::SendSuccess; | 129 return m_private->send(*PassRefPtr<ArrayBuffer>(webArrayBuffer), 0, webArray Buffer.byteLength()) == WebSocketChannel::SendSuccess; |
| 104 } | 130 } |
| 105 | 131 |
| 106 unsigned long WebSocketImpl::bufferedAmount() const | 132 unsigned long WebSocketImpl::bufferedAmount() const |
| 107 { | 133 { |
| 108 return m_private->bufferedAmount(); | 134 return m_bufferedAmount; |
| 109 } | 135 } |
| 110 | 136 |
| 111 void WebSocketImpl::close(int code, const WebString& reason) | 137 void WebSocketImpl::close(int code, const WebString& reason) |
| 112 { | 138 { |
| 139 m_isClosingOrClosed = true; | |
| 113 m_private->close(code, reason); | 140 m_private->close(code, reason); |
| 114 } | 141 } |
| 115 | 142 |
| 116 void WebSocketImpl::fail(const WebString& reason) | 143 void WebSocketImpl::fail(const WebString& reason) |
| 117 { | 144 { |
| 118 m_private->fail(reason, ErrorMessageLevel, String(), 0); | 145 m_private->fail(reason, ErrorMessageLevel, String(), 0); |
| 119 } | 146 } |
| 120 | 147 |
| 121 void WebSocketImpl::disconnect() | 148 void WebSocketImpl::disconnect() |
| 122 { | 149 { |
| 123 m_private->disconnect(); | 150 m_private->disconnect(); |
| 124 m_client = 0; | 151 m_client = 0; |
| 125 } | 152 } |
| 126 | 153 |
| 127 void WebSocketImpl::didConnect(const String& subprotocol, const String& extensio ns) | 154 void WebSocketImpl::didConnect(const String& subprotocol, const String& extensio ns) |
| 128 { | 155 { |
| 156 m_client->didConnect(subprotocol, extensions); | |
| 157 | |
| 158 // FIXME: Deprecate these statements. | |
| 129 m_subprotocol = subprotocol; | 159 m_subprotocol = subprotocol; |
| 130 m_extensions = extensions; | 160 m_extensions = extensions; |
| 131 m_client->didConnect(); | 161 m_client->didConnect(); |
| 132 } | 162 } |
| 133 | 163 |
| 134 void WebSocketImpl::didReceiveMessage(const String& message) | 164 void WebSocketImpl::didReceiveMessage(const String& message) |
| 135 { | 165 { |
| 136 m_client->didReceiveMessage(WebString(message)); | 166 m_client->didReceiveMessage(WebString(message)); |
| 137 } | 167 } |
| 138 | 168 |
| 139 void WebSocketImpl::didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData) | 169 void WebSocketImpl::didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData) |
| 140 { | 170 { |
| 141 switch (m_binaryType) { | 171 switch (m_binaryType) { |
| 142 case BinaryTypeBlob: | 172 case BinaryTypeBlob: |
| 143 // FIXME: Handle Blob after supporting WebBlob. | 173 // FIXME: Handle Blob after supporting WebBlob. |
| 144 break; | 174 break; |
| 145 case BinaryTypeArrayBuffer: | 175 case BinaryTypeArrayBuffer: |
| 146 m_client->didReceiveArrayBuffer(WebArrayBuffer(ArrayBuffer::create(binar yData->data(), binaryData->size()))); | 176 m_client->didReceiveArrayBuffer(WebArrayBuffer(ArrayBuffer::create(binar yData->data(), binaryData->size()))); |
| 147 break; | 177 break; |
| 148 } | 178 } |
| 149 } | 179 } |
| 150 | 180 |
| 151 void WebSocketImpl::didReceiveMessageError() | 181 void WebSocketImpl::didReceiveMessageError() |
| 152 { | 182 { |
| 153 m_client->didReceiveMessageError(); | 183 m_client->didReceiveMessageError(); |
| 154 } | 184 } |
| 155 | 185 |
| 156 void WebSocketImpl::didUpdateBufferedAmount(unsigned long bufferedAmount) | 186 void WebSocketImpl::didConsumeBufferedAmount(unsigned long consumed) |
| 157 { | 187 { |
| 158 m_client->didUpdateBufferedAmount(bufferedAmount); | 188 m_client->didConsumeBufferedAmount(consumed); |
| 189 | |
| 190 // FIXME: Deprecate the following statements. | |
| 191 m_bufferedAmount -= consumed; | |
| 192 m_client->didUpdateBufferedAmount(m_bufferedAmount); | |
| 159 } | 193 } |
| 160 | 194 |
| 161 void WebSocketImpl::didStartClosingHandshake() | 195 void WebSocketImpl::didStartClosingHandshake() |
| 162 { | 196 { |
| 163 m_client->didStartClosingHandshake(); | 197 m_client->didStartClosingHandshake(); |
| 164 } | 198 } |
| 165 | 199 |
| 166 void WebSocketImpl::didClose(unsigned long bufferedAmount, ClosingHandshakeCompl etionStatus status, unsigned short code, const String& reason) | 200 void WebSocketImpl::didClose(ClosingHandshakeCompletionStatus status, unsigned s hort code, const String& reason) |
| 167 { | 201 { |
| 168 m_client->didClose(bufferedAmount, static_cast<WebSocketClient::ClosingHands hakeCompletionStatus>(status), code, WebString(reason)); | 202 m_isClosingOrClosed = true; |
| 203 m_client->didClose(static_cast<WebSocketClient::ClosingHandshakeCompletionSt atus>(status), code, WebString(reason)); | |
| 204 | |
| 205 // FIXME: Deprecate this call. | |
| 206 m_client->didClose(m_bufferedAmount - m_bufferedAmountAfterClose, static_cas t<WebSocketClient::ClosingHandshakeCompletionStatus>(status), code, WebString(re ason)); | |
| 169 } | 207 } |
| 170 | 208 |
| 171 } // namespace blink | 209 } // namespace blink |
| OLD | NEW |