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

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, 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
« no previous file with comments | « content/child/websocket_bridge.h ('k') | content/child/websocket_dispatcher.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 if (!client_)
91 return;
92
93 WebString message_to_pass = WebString::fromUTF8(message);
94 client_->didFail(this, message_to_pass);
95 // |this| can be deleted here.
96 }
97
72 void WebSocketBridge::DidReceiveData(bool fin, 98 void WebSocketBridge::DidReceiveData(bool fin,
73 WebSocketMessageType type, 99 WebSocketMessageType type,
74 const std::vector<char>& data) { 100 const std::vector<char>& data) {
75 DVLOG(1) << "WebSocketBridge::DidReceiveData(" 101 DVLOG(1) << "WebSocketBridge::DidReceiveData("
76 << fin << ", " 102 << fin << ", "
77 << type << ", " 103 << type << ", "
78 << "(data size = " << data.size() << "))"; 104 << "(data size = " << data.size() << "))";
79 if (!client_) 105 if (!client_)
80 return; 106 return;
81 107
(...skipping 17 matching lines...) Expand all
99 125
100 void WebSocketBridge::DidReceiveFlowControl(int64_t quota) { 126 void WebSocketBridge::DidReceiveFlowControl(int64_t quota) {
101 DVLOG(1) << "WebSocketBridge::DidReceiveFlowControl(" << quota << ")"; 127 DVLOG(1) << "WebSocketBridge::DidReceiveFlowControl(" << quota << ")";
102 if (!client_) 128 if (!client_)
103 return; 129 return;
104 130
105 client_->didReceiveFlowControl(this, quota); 131 client_->didReceiveFlowControl(this, quota);
106 // |this| can be deleted here. 132 // |this| can be deleted here.
107 } 133 }
108 134
109 void WebSocketBridge::DidClose(unsigned short code, 135 void WebSocketBridge::DidClose(bool was_clean,
136 unsigned short code,
110 const std::string& reason) { 137 const std::string& reason) {
111 DVLOG(1) << "WebSocketBridge::DidClose(" 138 DVLOG(1) << "WebSocketBridge::DidClose("
139 << was_clean << ", "
112 << code << ", " 140 << code << ", "
113 << reason << ")"; 141 << reason << ")";
114 WebSocketHandleClient* client = client_; 142 WebSocketHandleClient* client = client_;
115 Disconnect(); 143 Disconnect();
116 if (!client) 144 if (!client)
117 return; 145 return;
118 146
119 WebString reason_to_pass = WebString::fromUTF8(reason); 147 WebString reason_to_pass = WebString::fromUTF8(reason);
120 client->didClose(this, code, reason_to_pass); 148 client->didClose(this, was_clean, code, reason_to_pass);
121 // |this| can be deleted here. 149 // |this| can be deleted here.
122 } 150 }
123 151
124 void WebSocketBridge::connect( 152 void WebSocketBridge::connect(
125 const WebURL& url, 153 const WebURL& url,
126 const WebVector<WebString>& protocols, 154 const WebVector<WebString>& protocols,
127 const WebString& origin, 155 const WebString& origin,
128 WebSocketHandleClient* client) { 156 WebSocketHandleClient* client) {
129 DCHECK_EQ(kInvalidChannelId, channel_id_); 157 DCHECK_EQ(kInvalidChannelId, channel_id_);
130 WebSocketDispatcher* dispatcher = 158 WebSocketDispatcher* dispatcher =
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 } 218 }
191 219
192 void WebSocketBridge::close(unsigned short code, 220 void WebSocketBridge::close(unsigned short code,
193 const WebString& reason) { 221 const WebString& reason) {
194 if (channel_id_ == kInvalidChannelId) 222 if (channel_id_ == kInvalidChannelId)
195 return; 223 return;
196 224
197 std::string reason_to_pass = reason.utf8(); 225 std::string reason_to_pass = reason.utf8();
198 DVLOG(1) << "Bridge #" << channel_id_ << " Close(" 226 DVLOG(1) << "Bridge #" << channel_id_ << " Close("
199 << code << ", " << reason_to_pass << ")"; 227 << code << ", " << reason_to_pass << ")";
228 // This method is for closing handshake and hence |was_clean| shall be true.
tyoshino (SeeGerritForStatus) 2013/10/23 08:28:53 NewWebSocketChannelImpl::disconnect() also uses th
yhirano 2013/10/23 08:32:55 You are right, I will fix NewWebSocketChannelImpl
yhirano 2013/10/23 09:12:59 Done at the Blink-side change. https://codereview.
200 ChildThread::current()->Send( 229 ChildThread::current()->Send(
201 new WebSocketMsg_DropChannel(channel_id_, code, reason_to_pass)); 230 new WebSocketMsg_DropChannel(channel_id_, true, code, reason_to_pass));
202 } 231 }
203 232
204 void WebSocketBridge::Disconnect() { 233 void WebSocketBridge::Disconnect() {
205 if (channel_id_ == kInvalidChannelId) 234 if (channel_id_ == kInvalidChannelId)
206 return; 235 return;
207 WebSocketDispatcher* dispatcher = 236 WebSocketDispatcher* dispatcher =
208 ChildThread::current()->websocket_dispatcher(); 237 ChildThread::current()->websocket_dispatcher();
209 dispatcher->RemoveBridge(channel_id_); 238 dispatcher->RemoveBridge(channel_id_);
210 239
211 channel_id_ = kInvalidChannelId; 240 channel_id_ = kInvalidChannelId;
212 client_ = NULL; 241 client_ = NULL;
213 } 242 }
214 243
215 } // namespace content 244 } // namespace content
OLDNEW
« no previous file with comments | « content/child/websocket_bridge.h ('k') | content/child/websocket_dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698