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 // Deprecate this call. | |
|
tyoshino (SeeGerritForStatus)
2014/06/19 07:38:54
FIXME
yhirano
2014/06/19 07:49:43
Done.
| |
| 108 m_client->didUpdateBufferedAmount(m_bufferedAmount); | |
| 109 | |
| 98 return m_private->send(message) == WebSocketChannel::SendSuccess; | 110 return m_private->send(message) == WebSocketChannel::SendSuccess; |
| 99 } | 111 } |
| 100 | 112 |
| 101 bool WebSocketImpl::sendArrayBuffer(const WebArrayBuffer& webArrayBuffer) | 113 bool WebSocketImpl::sendArrayBuffer(const WebArrayBuffer& webArrayBuffer) |
| 102 { | 114 { |
| 115 size_t size = webArrayBuffer.byteLength(); | |
| 116 m_bufferedAmount += size; | |
| 117 if (m_isClosingOrClosed) | |
| 118 m_bufferedAmountAfterClose += size; | |
| 119 | |
| 120 // Deprecate this call. | |
|
tyoshino (SeeGerritForStatus)
2014/06/19 07:38:54
FIXME
yhirano
2014/06/19 07:49:43
Done.
| |
| 121 m_client->didUpdateBufferedAmount(m_bufferedAmount); | |
| 122 | |
| 103 return m_private->send(*PassRefPtr<ArrayBuffer>(webArrayBuffer), 0, webArray Buffer.byteLength()) == WebSocketChannel::SendSuccess; | 123 return m_private->send(*PassRefPtr<ArrayBuffer>(webArrayBuffer), 0, webArray Buffer.byteLength()) == WebSocketChannel::SendSuccess; |
| 104 } | 124 } |
| 105 | 125 |
| 106 unsigned long WebSocketImpl::bufferedAmount() const | 126 unsigned long WebSocketImpl::bufferedAmount() const |
| 107 { | 127 { |
| 108 return m_private->bufferedAmount(); | 128 return m_bufferedAmount; |
| 109 } | 129 } |
| 110 | 130 |
| 111 void WebSocketImpl::close(int code, const WebString& reason) | 131 void WebSocketImpl::close(int code, const WebString& reason) |
| 112 { | 132 { |
| 133 m_isClosingOrClosed = true; | |
| 113 m_private->close(code, reason); | 134 m_private->close(code, reason); |
| 114 } | 135 } |
| 115 | 136 |
| 116 void WebSocketImpl::fail(const WebString& reason) | 137 void WebSocketImpl::fail(const WebString& reason) |
| 117 { | 138 { |
| 118 m_private->fail(reason, ErrorMessageLevel, String(), 0); | 139 m_private->fail(reason, ErrorMessageLevel, String(), 0); |
| 119 } | 140 } |
| 120 | 141 |
| 121 void WebSocketImpl::disconnect() | 142 void WebSocketImpl::disconnect() |
| 122 { | 143 { |
| 123 m_private->disconnect(); | 144 m_private->disconnect(); |
| 124 m_client = 0; | 145 m_client = 0; |
| 125 } | 146 } |
| 126 | 147 |
| 127 void WebSocketImpl::didConnect(const String& subprotocol, const String& extensio ns) | 148 void WebSocketImpl::didConnect(const String& subprotocol, const String& extensio ns) |
| 128 { | 149 { |
| 150 m_client->didConnect(subprotocol, extensions); | |
| 151 | |
| 152 // FIXME: Deprecate these statements. | |
| 129 m_subprotocol = subprotocol; | 153 m_subprotocol = subprotocol; |
| 130 m_extensions = extensions; | 154 m_extensions = extensions; |
| 131 m_client->didConnect(); | 155 m_client->didConnect(); |
| 132 } | 156 } |
| 133 | 157 |
| 134 void WebSocketImpl::didReceiveMessage(const String& message) | 158 void WebSocketImpl::didReceiveMessage(const String& message) |
| 135 { | 159 { |
| 136 m_client->didReceiveMessage(WebString(message)); | 160 m_client->didReceiveMessage(WebString(message)); |
| 137 } | 161 } |
| 138 | 162 |
| 139 void WebSocketImpl::didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData) | 163 void WebSocketImpl::didReceiveBinaryData(PassOwnPtr<Vector<char> > binaryData) |
| 140 { | 164 { |
| 141 switch (m_binaryType) { | 165 switch (m_binaryType) { |
| 142 case BinaryTypeBlob: | 166 case BinaryTypeBlob: |
| 143 // FIXME: Handle Blob after supporting WebBlob. | 167 // FIXME: Handle Blob after supporting WebBlob. |
| 144 break; | 168 break; |
| 145 case BinaryTypeArrayBuffer: | 169 case BinaryTypeArrayBuffer: |
| 146 m_client->didReceiveArrayBuffer(WebArrayBuffer(ArrayBuffer::create(binar yData->data(), binaryData->size()))); | 170 m_client->didReceiveArrayBuffer(WebArrayBuffer(ArrayBuffer::create(binar yData->data(), binaryData->size()))); |
| 147 break; | 171 break; |
| 148 } | 172 } |
| 149 } | 173 } |
| 150 | 174 |
| 151 void WebSocketImpl::didReceiveMessageError() | 175 void WebSocketImpl::didReceiveMessageError() |
| 152 { | 176 { |
| 153 m_client->didReceiveMessageError(); | 177 m_client->didReceiveMessageError(); |
| 154 } | 178 } |
| 155 | 179 |
| 156 void WebSocketImpl::didUpdateBufferedAmount(unsigned long bufferedAmount) | 180 void WebSocketImpl::didConsumeBufferedAmount(unsigned long consumed) |
| 157 { | 181 { |
| 158 m_client->didUpdateBufferedAmount(bufferedAmount); | 182 m_client->didConsumeBufferedAmount(consumed); |
| 183 | |
| 184 // FIXME: Deprecate the following statements. | |
| 185 m_bufferedAmount -= consumed; | |
| 186 m_client->didUpdateBufferedAmount(m_bufferedAmount); | |
| 159 } | 187 } |
| 160 | 188 |
| 161 void WebSocketImpl::didStartClosingHandshake() | 189 void WebSocketImpl::didStartClosingHandshake() |
| 162 { | 190 { |
| 163 m_client->didStartClosingHandshake(); | 191 m_client->didStartClosingHandshake(); |
| 164 } | 192 } |
| 165 | 193 |
| 166 void WebSocketImpl::didClose(unsigned long bufferedAmount, ClosingHandshakeCompl etionStatus status, unsigned short code, const String& reason) | 194 void WebSocketImpl::didClose(ClosingHandshakeCompletionStatus status, unsigned s hort code, const String& reason) |
| 167 { | 195 { |
| 168 m_client->didClose(bufferedAmount, static_cast<WebSocketClient::ClosingHands hakeCompletionStatus>(status), code, WebString(reason)); | 196 m_isClosingOrClosed = true; |
| 197 m_client->didClose(static_cast<WebSocketClient::ClosingHandshakeCompletionSt atus>(status), code, WebString(reason)); | |
| 198 | |
| 199 // Deprecate this call. | |
| 200 m_client->didClose(m_bufferedAmount - m_bufferedAmountAfterClose, static_cas t<WebSocketClient::ClosingHandshakeCompletionStatus>(status), code, WebString(re ason)); | |
| 169 } | 201 } |
| 170 | 202 |
| 171 } // namespace blink | 203 } // namespace blink |
| OLD | NEW |