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

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: Address a blink-side review comment Created 7 years, 1 month 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 false,
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)
60 IPC_MESSAGE_HANDLER(WebSocketMsg_NotifyFailure, DidFail)
45 IPC_MESSAGE_HANDLER(WebSocketMsg_SendFrame, DidReceiveData) 61 IPC_MESSAGE_HANDLER(WebSocketMsg_SendFrame, DidReceiveData)
46 IPC_MESSAGE_HANDLER(WebSocketMsg_FlowControl, DidReceiveFlowControl) 62 IPC_MESSAGE_HANDLER(WebSocketMsg_FlowControl, DidReceiveFlowControl)
47 IPC_MESSAGE_HANDLER(WebSocketMsg_DropChannel, DidClose) 63 IPC_MESSAGE_HANDLER(WebSocketMsg_DropChannel, DidClose)
48 IPC_MESSAGE_UNHANDLED(handled = false) 64 IPC_MESSAGE_UNHANDLED(handled = false)
49 IPC_END_MESSAGE_MAP() 65 IPC_END_MESSAGE_MAP()
50 return handled; 66 return handled;
51 } 67 }
52 68
53 void WebSocketBridge::DidConnect(bool fail, 69 void WebSocketBridge::DidConnect(bool fail,
54 const std::string& selected_protocol, 70 const std::string& selected_protocol,
55 const std::string& extensions) { 71 const std::string& extensions) {
56 WebSocketHandleClient* client = client_; 72 WebSocketHandleClient* client = client_;
57 DVLOG(1) << "WebSocketBridge::DidConnect(" 73 DVLOG(1) << "WebSocketBridge::DidConnect("
58 << fail << ", " 74 << fail << ", "
59 << selected_protocol << ", " 75 << selected_protocol << ", "
60 << extensions << ")"; 76 << extensions << ")";
61 if (fail) 77 if (fail)
62 Disconnect(); 78 Disconnect();
63 if (!client) 79 if (!client)
64 return; 80 return;
65 81
66 WebString protocol_to_pass = WebString::fromUTF8(selected_protocol); 82 WebString protocol_to_pass = WebString::fromUTF8(selected_protocol);
67 WebString extensions_to_pass = WebString::fromUTF8(extensions); 83 WebString extensions_to_pass = WebString::fromUTF8(extensions);
68 client->didConnect(this, fail, protocol_to_pass, extensions_to_pass); 84 client->didConnect(this, fail, protocol_to_pass, extensions_to_pass);
69 // |this| can be deleted here. 85 // |this| can be deleted here.
70 } 86 }
71 87
88 void WebSocketBridge::DidFail(const std::string& message) {
89 DVLOG(1) << "WebSocketBridge::DidFail(" << message << ")";
90 WebSocketHandleClient* client = client_;
91 Disconnect();
92 if (!client)
93 return;
94
95 WebString message_to_pass = WebString::fromUTF8(message);
96 client->didFail(this, message_to_pass);
97 // |this| can be deleted here.
98 }
99
72 void WebSocketBridge::DidReceiveData(bool fin, 100 void WebSocketBridge::DidReceiveData(bool fin,
73 WebSocketMessageType type, 101 WebSocketMessageType type,
74 const std::vector<char>& data) { 102 const std::vector<char>& data) {
75 DVLOG(1) << "WebSocketBridge::DidReceiveData(" 103 DVLOG(1) << "WebSocketBridge::DidReceiveData("
76 << fin << ", " 104 << fin << ", "
77 << type << ", " 105 << type << ", "
78 << "(data size = " << data.size() << "))"; 106 << "(data size = " << data.size() << "))";
79 if (!client_) 107 if (!client_)
80 return; 108 return;
81 109
(...skipping 17 matching lines...) Expand all
99 127
100 void WebSocketBridge::DidReceiveFlowControl(int64_t quota) { 128 void WebSocketBridge::DidReceiveFlowControl(int64_t quota) {
101 DVLOG(1) << "WebSocketBridge::DidReceiveFlowControl(" << quota << ")"; 129 DVLOG(1) << "WebSocketBridge::DidReceiveFlowControl(" << quota << ")";
102 if (!client_) 130 if (!client_)
103 return; 131 return;
104 132
105 client_->didReceiveFlowControl(this, quota); 133 client_->didReceiveFlowControl(this, quota);
106 // |this| can be deleted here. 134 // |this| can be deleted here.
107 } 135 }
108 136
109 void WebSocketBridge::DidClose(unsigned short code, 137 void WebSocketBridge::DidClose(bool was_clean,
138 unsigned short code,
110 const std::string& reason) { 139 const std::string& reason) {
111 DVLOG(1) << "WebSocketBridge::DidClose(" 140 DVLOG(1) << "WebSocketBridge::DidClose("
141 << was_clean << ", "
112 << code << ", " 142 << code << ", "
113 << reason << ")"; 143 << reason << ")";
114 WebSocketHandleClient* client = client_; 144 WebSocketHandleClient* client = client_;
115 Disconnect(); 145 Disconnect();
116 if (!client) 146 if (!client)
117 return; 147 return;
118 148
119 WebString reason_to_pass = WebString::fromUTF8(reason); 149 WebString reason_to_pass = WebString::fromUTF8(reason);
120 client->didClose(this, code, reason_to_pass); 150 client->didClose(this, was_clean, code, reason_to_pass);
121 // |this| can be deleted here. 151 // |this| can be deleted here.
122 } 152 }
123 153
124 void WebSocketBridge::connect( 154 void WebSocketBridge::connect(
125 const WebURL& url, 155 const WebURL& url,
126 const WebVector<WebString>& protocols, 156 const WebVector<WebString>& protocols,
127 const WebString& origin, 157 const WebString& origin,
128 WebSocketHandleClient* client) { 158 WebSocketHandleClient* client) {
129 DCHECK_EQ(kInvalidChannelId, channel_id_); 159 DCHECK_EQ(kInvalidChannelId, channel_id_);
130 WebSocketDispatcher* dispatcher = 160 WebSocketDispatcher* dispatcher =
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 220 }
191 221
192 void WebSocketBridge::close(unsigned short code, 222 void WebSocketBridge::close(unsigned short code,
193 const WebString& reason) { 223 const WebString& reason) {
194 if (channel_id_ == kInvalidChannelId) 224 if (channel_id_ == kInvalidChannelId)
195 return; 225 return;
196 226
197 std::string reason_to_pass = reason.utf8(); 227 std::string reason_to_pass = reason.utf8();
198 DVLOG(1) << "Bridge #" << channel_id_ << " Close(" 228 DVLOG(1) << "Bridge #" << channel_id_ << " Close("
199 << code << ", " << reason_to_pass << ")"; 229 << code << ", " << reason_to_pass << ")";
230 // This method is for closing handshake and hence |was_clean| shall be true.
200 ChildThread::current()->Send( 231 ChildThread::current()->Send(
201 new WebSocketMsg_DropChannel(channel_id_, code, reason_to_pass)); 232 new WebSocketMsg_DropChannel(channel_id_, true, code, reason_to_pass));
202 } 233 }
203 234
204 void WebSocketBridge::Disconnect() { 235 void WebSocketBridge::Disconnect() {
205 if (channel_id_ == kInvalidChannelId) 236 if (channel_id_ == kInvalidChannelId)
206 return; 237 return;
207 WebSocketDispatcher* dispatcher = 238 WebSocketDispatcher* dispatcher =
208 ChildThread::current()->websocket_dispatcher(); 239 ChildThread::current()->websocket_dispatcher();
209 dispatcher->RemoveBridge(channel_id_); 240 dispatcher->RemoveBridge(channel_id_);
210 241
211 channel_id_ = kInvalidChannelId; 242 channel_id_ = kInvalidChannelId;
212 client_ = NULL; 243 client_ = NULL;
213 } 244 }
214 245
215 } // namespace content 246 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698