Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Side by Side Diff: content/child/websocket_bridge.cc

Issue 34753008: Notify WebSocket connection failure, chromium side (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/websocket_bridge.h" 5 #include "content/child/websocket_bridge.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 13 matching lines...) Expand all
24 #include "third_party/WebKit/public/platform/WebVector.h" 24 #include "third_party/WebKit/public/platform/WebVector.h"
25 25
26 using WebKit::WebSocketHandle; 26 using WebKit::WebSocketHandle;
27 using WebKit::WebSocketHandleClient; 27 using WebKit::WebSocketHandleClient;
28 using WebKit::WebString; 28 using WebKit::WebString;
29 using WebKit::WebURL; 29 using WebKit::WebURL;
30 using WebKit::WebVector; 30 using WebKit::WebVector;
31 31
32 namespace content { 32 namespace content {
33 33
34 namespace {
35
36 const unsigned short kAbnormalShutdownOpCode = 1006;
37
38 } // namespace
39
34 WebSocketBridge::WebSocketBridge() 40 WebSocketBridge::WebSocketBridge()
35 : channel_id_(kInvalidChannelId), client_(NULL) {} 41 : channel_id_(kInvalidChannelId), client_(NULL) {}
36 42
37 WebSocketBridge::~WebSocketBridge() { 43 WebSocketBridge::~WebSocketBridge() {
44 if (channel_id_ != kInvalidChannelId) {
45 // The connection is abruptly disconnected by the renderer without
46 // closing handshake.
47 ChildThread::current()->Send(
48 new WebSocketMsg_DropChannel(channel_id_,
49 true,
50 kAbnormalShutdownOpCode,
51 std::string()));
52 }
38 Disconnect(); 53 Disconnect();
39 } 54 }
40 55
41 bool WebSocketBridge::OnMessageReceived(const IPC::Message& msg) { 56 bool WebSocketBridge::OnMessageReceived(const IPC::Message& msg) {
42 bool handled = true; 57 bool handled = true;
43 IPC_BEGIN_MESSAGE_MAP(WebSocketBridge, msg) 58 IPC_BEGIN_MESSAGE_MAP(WebSocketBridge, msg)
44 IPC_MESSAGE_HANDLER(WebSocketMsg_AddChannelResponse, DidConnect) 59 IPC_MESSAGE_HANDLER(WebSocketMsg_AddChannelResponse, DidConnect)
45 IPC_MESSAGE_HANDLER(WebSocketMsg_SendFrame, DidReceiveData) 60 IPC_MESSAGE_HANDLER(WebSocketMsg_SendFrame, DidReceiveData)
46 IPC_MESSAGE_HANDLER(WebSocketMsg_FlowControl, DidReceiveFlowControl) 61 IPC_MESSAGE_HANDLER(WebSocketMsg_FlowControl, DidReceiveFlowControl)
47 IPC_MESSAGE_HANDLER(WebSocketMsg_DropChannel, DidClose) 62 IPC_MESSAGE_HANDLER(WebSocketMsg_DropChannel, DidClose)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 114
100 void WebSocketBridge::DidReceiveFlowControl(int64_t quota) { 115 void WebSocketBridge::DidReceiveFlowControl(int64_t quota) {
101 DVLOG(1) << "WebSocketBridge::DidReceiveFlowControl(" << quota << ")"; 116 DVLOG(1) << "WebSocketBridge::DidReceiveFlowControl(" << quota << ")";
102 if (!client_) 117 if (!client_)
103 return; 118 return;
104 119
105 client_->didReceiveFlowControl(this, quota); 120 client_->didReceiveFlowControl(this, quota);
106 // |this| can be deleted here. 121 // |this| can be deleted here.
107 } 122 }
108 123
109 void WebSocketBridge::DidClose(unsigned short code, 124 void WebSocketBridge::DidClose(bool fail,
125 unsigned short code,
110 const std::string& reason) { 126 const std::string& reason) {
111 DVLOG(1) << "WebSocketBridge::DidClose(" 127 DVLOG(1) << "WebSocketBridge::DidClose("
128 << fail << ", "
112 << code << ", " 129 << code << ", "
113 << reason << ")"; 130 << reason << ")";
114 WebSocketHandleClient* client = client_; 131 WebSocketHandleClient* client = client_;
115 Disconnect(); 132 Disconnect();
116 if (!client) 133 if (!client)
117 return; 134 return;
118 135
119 WebString reason_to_pass = WebString::fromUTF8(reason); 136 WebString reason_to_pass = WebString::fromUTF8(reason);
120 client->didClose(this, code, reason_to_pass); 137 client->didClose(this, fail, code, reason_to_pass);
121 // |this| can be deleted here. 138 // |this| can be deleted here.
122 } 139 }
123 140
124 void WebSocketBridge::connect( 141 void WebSocketBridge::connect(
125 const WebURL& url, 142 const WebURL& url,
126 const WebVector<WebString>& protocols, 143 const WebVector<WebString>& protocols,
127 const WebString& origin, 144 const WebString& origin,
128 WebSocketHandleClient* client) { 145 WebSocketHandleClient* client) {
129 DCHECK_EQ(kInvalidChannelId, channel_id_); 146 DCHECK_EQ(kInvalidChannelId, channel_id_);
130 WebSocketDispatcher* dispatcher = 147 WebSocketDispatcher* dispatcher =
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 207 }
191 208
192 void WebSocketBridge::close(unsigned short code, 209 void WebSocketBridge::close(unsigned short code,
193 const WebString& reason) { 210 const WebString& reason) {
194 if (channel_id_ == kInvalidChannelId) 211 if (channel_id_ == kInvalidChannelId)
195 return; 212 return;
196 213
197 std::string reason_to_pass = reason.utf8(); 214 std::string reason_to_pass = reason.utf8();
198 DVLOG(1) << "Bridge #" << channel_id_ << " Close(" 215 DVLOG(1) << "Bridge #" << channel_id_ << " Close("
199 << code << ", " << reason_to_pass << ")"; 216 << code << ", " << reason_to_pass << ")";
217 // This method is for closing handshake and hence |fail| shall be false.
200 ChildThread::current()->Send( 218 ChildThread::current()->Send(
201 new WebSocketMsg_DropChannel(channel_id_, code, reason_to_pass)); 219 new WebSocketMsg_DropChannel(channel_id_, false, code, reason_to_pass));
202 } 220 }
203 221
204 void WebSocketBridge::Disconnect() { 222 void WebSocketBridge::Disconnect() {
205 if (channel_id_ == kInvalidChannelId) 223 if (channel_id_ == kInvalidChannelId)
206 return; 224 return;
207 WebSocketDispatcher* dispatcher = 225 WebSocketDispatcher* dispatcher =
208 ChildThread::current()->websocket_dispatcher(); 226 ChildThread::current()->websocket_dispatcher();
209 dispatcher->RemoveBridge(channel_id_); 227 dispatcher->RemoveBridge(channel_id_);
210 228
211 channel_id_ = kInvalidChannelId; 229 channel_id_ = kInvalidChannelId;
212 client_ = NULL; 230 client_ = NULL;
213 } 231 }
214 232
215 } // namespace content 233 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698