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_bufferedAmount(0) | |
| 54 { | 56 { |
| 55 RefPtrWillBeRawPtr<Document> coreDocument = PassRefPtrWillBeRawPtr<Document> (document); | 57 RefPtrWillBeRawPtr<Document> coreDocument = PassRefPtrWillBeRawPtr<Document> (document); |
| 56 if (RuntimeEnabledFeatures::experimentalWebSocketEnabled()) { | 58 if (RuntimeEnabledFeatures::experimentalWebSocketEnabled()) { |
| 57 m_private = NewWebSocketChannelImpl::create(coreDocument.get(), this); | 59 m_private = NewWebSocketChannelImpl::create(coreDocument.get(), this); |
| 58 } else { | 60 } else { |
| 59 m_private = MainThreadWebSocketChannel::create(coreDocument.get(), this) ; | 61 m_private = MainThreadWebSocketChannel::create(coreDocument.get(), this) ; |
| 60 } | 62 } |
| 61 } | 63 } |
| 62 | 64 |
| 63 WebSocketImpl::~WebSocketImpl() | 65 WebSocketImpl::~WebSocketImpl() |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 88 return m_private->subprotocol(); | 90 return m_private->subprotocol(); |
| 89 } | 91 } |
| 90 | 92 |
| 91 WebString WebSocketImpl::extensions() | 93 WebString WebSocketImpl::extensions() |
| 92 { | 94 { |
| 93 return m_private->extensions(); | 95 return m_private->extensions(); |
| 94 } | 96 } |
| 95 | 97 |
| 96 bool WebSocketImpl::sendText(const WebString& message) | 98 bool WebSocketImpl::sendText(const WebString& message) |
| 97 { | 99 { |
| 100 m_bufferedAmount += ((String)message).utf8().length(); | |
|
tyoshino (SeeGerritForStatus)
2014/06/16 07:31:42
WebString also has utf8()?
yhirano
2014/06/16 10:19:45
Done.
| |
| 98 return m_private->send(message) == WebSocketChannel::SendSuccess; | 101 return m_private->send(message) == WebSocketChannel::SendSuccess; |
| 99 } | 102 } |
| 100 | 103 |
| 101 bool WebSocketImpl::sendArrayBuffer(const WebArrayBuffer& webArrayBuffer) | 104 bool WebSocketImpl::sendArrayBuffer(const WebArrayBuffer& webArrayBuffer) |
| 102 { | 105 { |
| 106 m_bufferedAmount += webArrayBuffer.byteLength(); | |
| 103 return m_private->send(*PassRefPtr<ArrayBuffer>(webArrayBuffer), 0, webArray Buffer.byteLength()) == WebSocketChannel::SendSuccess; | 107 return m_private->send(*PassRefPtr<ArrayBuffer>(webArrayBuffer), 0, webArray Buffer.byteLength()) == WebSocketChannel::SendSuccess; |
| 104 } | 108 } |
| 105 | 109 |
| 106 unsigned long WebSocketImpl::bufferedAmount() const | 110 unsigned long WebSocketImpl::bufferedAmount() const |
| 107 { | 111 { |
| 108 return m_private->bufferedAmount(); | 112 return m_bufferedAmount; |
| 109 } | 113 } |
| 110 | 114 |
| 111 void WebSocketImpl::close(int code, const WebString& reason) | 115 void WebSocketImpl::close(int code, const WebString& reason) |
| 112 { | 116 { |
| 113 m_private->close(code, reason); | 117 m_private->close(code, reason); |
| 114 } | 118 } |
| 115 | 119 |
| 116 void WebSocketImpl::fail(const WebString& reason) | 120 void WebSocketImpl::fail(const WebString& reason) |
| 117 { | 121 { |
| 118 m_private->fail(reason, ErrorMessageLevel, String(), 0); | 122 m_private->fail(reason, ErrorMessageLevel, String(), 0); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 144 m_client->didReceiveArrayBuffer(WebArrayBuffer(ArrayBuffer::create(binar yData->data(), binaryData->size()))); | 148 m_client->didReceiveArrayBuffer(WebArrayBuffer(ArrayBuffer::create(binar yData->data(), binaryData->size()))); |
| 145 break; | 149 break; |
| 146 } | 150 } |
| 147 } | 151 } |
| 148 | 152 |
| 149 void WebSocketImpl::didReceiveMessageError() | 153 void WebSocketImpl::didReceiveMessageError() |
| 150 { | 154 { |
| 151 m_client->didReceiveMessageError(); | 155 m_client->didReceiveMessageError(); |
| 152 } | 156 } |
| 153 | 157 |
| 154 void WebSocketImpl::didUpdateBufferedAmount(unsigned long bufferedAmount) | 158 void WebSocketImpl::didConsumeBufferedAmount(unsigned long consumed) |
| 155 { | 159 { |
| 156 m_client->didUpdateBufferedAmount(bufferedAmount); | 160 m_bufferedAmount -= consumed; |
| 157 } | 161 } |
| 158 | 162 |
| 159 void WebSocketImpl::didStartClosingHandshake() | 163 void WebSocketImpl::didStartClosingHandshake() |
| 160 { | 164 { |
| 161 m_client->didStartClosingHandshake(); | 165 m_client->didStartClosingHandshake(); |
| 162 } | 166 } |
| 163 | 167 |
| 164 void WebSocketImpl::didClose(unsigned long bufferedAmount, ClosingHandshakeCompl etionStatus status, unsigned short code, const String& reason) | 168 void WebSocketImpl::didClose(ClosingHandshakeCompletionStatus status, unsigned s hort code, const String& reason) |
| 165 { | 169 { |
| 166 m_client->didClose(bufferedAmount, static_cast<WebSocketClient::ClosingHands hakeCompletionStatus>(status), code, WebString(reason)); | 170 m_client->didClose(m_bufferedAmount, static_cast<WebSocketClient::ClosingHan dshakeCompletionStatus>(status), code, WebString(reason)); |
| 167 } | 171 } |
| 168 | 172 |
| 169 } // namespace blink | 173 } // namespace blink |
| OLD | NEW |