Index: mojo/services/html_viewer/websockethandle_impl.cc |
diff --git a/mojo/services/html_viewer/websockethandle_impl.cc b/mojo/services/html_viewer/websockethandle_impl.cc |
index e5d291a51ba381b6154e410adfc83e23a4103129..a4d9d5eabd77977865123bae1487b173d5c01429 100644 |
--- a/mojo/services/html_viewer/websockethandle_impl.cc |
+++ b/mojo/services/html_viewer/websockethandle_impl.cc |
@@ -6,6 +6,7 @@ |
#include <vector> |
+#include "mojo/services/html_viewer/blink_basic_type_converters.h" |
#include "mojo/services/public/interfaces/network/network_service.mojom.h" |
#include "third_party/WebKit/public/platform/WebSerializedOrigin.h" |
#include "third_party/WebKit/public/platform/WebSocketHandleClient.h" |
@@ -23,29 +24,6 @@ using blink::WebVector; |
namespace mojo { |
template<> |
-struct TypeConverter<String, WebString> { |
- static String Convert(const WebString& str) { |
- return String(str.utf8()); |
- } |
-}; |
-template<> |
-struct TypeConverter<WebString, String> { |
- static WebString Convert(const String& str) { |
- return WebString::fromUTF8(str.get()); |
- } |
-}; |
- |
-template<typename T, typename U> |
-struct TypeConverter<Array<T>, WebVector<U> > { |
- static Array<T> Convert(const WebVector<U>& vector) { |
- Array<T> array(vector.size()); |
- for (size_t i = 0; i < vector.size(); ++i) |
- array[i] = TypeConverter<T, U>::Convert(vector[i]); |
- return array.Pass(); |
- } |
-}; |
- |
-template<> |
struct TypeConverter<WebSocket::MessageType, WebSocketHandle::MessageType> { |
static WebSocket::MessageType Convert(WebSocketHandle::MessageType type) { |
DCHECK(type == WebSocketHandle::MessageTypeContinuation || |
@@ -93,11 +71,17 @@ class WebSocketClientImpl : public InterfaceImpl<WebSocketClient> { |
bool fail, |
const String& selected_subprotocol, |
const String& extensions) OVERRIDE { |
- client_->didConnect(handle_, |
- fail, |
- selected_subprotocol.To<WebString>(), |
- extensions.To<WebString>()); |
+ blink::WebSocketHandleClient* client = client_; |
+ WebSocketHandleImpl* handle = handle_; |
+ if (fail) |
+ handle->Disconnect(); // deletes |this| |
+ client->didConnect(handle, |
+ fail, |
+ selected_subprotocol.To<WebString>(), |
+ extensions.To<WebString>()); |
+ // |handle_| can be deleted here. |
} |
+ |
virtual void DidReceiveData(bool fin, |
WebSocket::MessageType type, |
ScopedDataPipeConsumerHandle data_pipe) OVERRIDE { |
@@ -112,6 +96,7 @@ class WebSocketClientImpl : public InterfaceImpl<WebSocketClient> { |
ConvertTo<WebSocketHandle::MessageType>(type), |
data_ptr, |
data.size()); |
+ // |handle_| can be deleted here. |
} |
virtual void DidReceiveFlowControl(int64_t quota) OVERRIDE { |
@@ -119,6 +104,24 @@ class WebSocketClientImpl : public InterfaceImpl<WebSocketClient> { |
// |handle_| can be deleted here. |
} |
+ virtual void DidFail(const String& message) OVERRIDE { |
+ blink::WebSocketHandleClient* client = client_; |
+ WebSocketHandleImpl* handle = handle_; |
+ handle->Disconnect(); // deletes |this| |
+ client->didFail(handle, message.To<WebString>()); |
+ // |handle_| can be deleted here. |
+ } |
+ |
+ virtual void DidClose(bool was_clean, |
+ uint16_t code, |
+ const String& reason) OVERRIDE { |
+ blink::WebSocketHandleClient* client = client_; |
+ WebSocketHandleImpl* handle = handle_; |
+ handle->Disconnect(); // deletes |this| |
+ client->didClose(handle, was_clean, code, reason.To<WebString>()); |
+ // |handle_| can be deleted here. |
darin (slow to review)
2014/09/05 18:54:15
hmm, this comment is a bit fishy since |this| is a
Matt Perry
2014/09/05 19:49:07
Done.
|
+ } |
+ |
WebSocketHandleImpl* handle_; |
blink::WebSocketHandleClient* client_; |
@@ -186,8 +189,12 @@ void WebSocketHandleImpl::flowControl(int64_t quota) { |
} |
void WebSocketHandleImpl::close(unsigned short code, const WebString& reason) { |
- did_close_ = true; |
web_socket_->Close(code, reason.utf8()); |
} |
+void WebSocketHandleImpl::Disconnect() { |
+ did_close_ = true; |
+ client_.reset(); |
+} |
+ |
} // namespace mojo |