| OLD | NEW |
| 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/renderer/websockethandle_impl.h" | 5 #include "content/renderer/websockethandle_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // websocket_ to null. | 76 // websocket_ to null. |
| 77 if (!did_initialize_) | 77 if (!did_initialize_) |
| 78 Initialize(blink::Platform::current()->interfaceProvider()); | 78 Initialize(blink::Platform::current()->interfaceProvider()); |
| 79 | 79 |
| 80 DCHECK(websocket_); | 80 DCHECK(websocket_); |
| 81 | 81 |
| 82 DCHECK(!client_); | 82 DCHECK(!client_); |
| 83 DCHECK(client); | 83 DCHECK(client); |
| 84 client_ = client; | 84 client_ = client; |
| 85 | 85 |
| 86 mojo::Array<mojo::String> protocols_to_pass(protocols.size()); | 86 std::vector<std::string> protocols_to_pass(protocols.size()); |
| 87 for (size_t i = 0; i < protocols.size(); ++i) | 87 for (size_t i = 0; i < protocols.size(); ++i) |
| 88 protocols_to_pass[i] = protocols[i].utf8(); | 88 protocols_to_pass[i] = protocols[i].utf8(); |
| 89 | 89 |
| 90 websocket_->AddChannelRequest( | 90 websocket_->AddChannelRequest( |
| 91 url, | 91 url, protocols_to_pass, origin, first_party_for_cookies, |
| 92 std::move(protocols_to_pass), | |
| 93 origin, | |
| 94 first_party_for_cookies, | |
| 95 user_agent_override.latin1(), | 92 user_agent_override.latin1(), |
| 96 client_binding_.CreateInterfacePtrAndBind(task_runner_)); | 93 client_binding_.CreateInterfacePtrAndBind(task_runner_)); |
| 97 } | 94 } |
| 98 | 95 |
| 99 void WebSocketHandleImpl::send(bool fin, | 96 void WebSocketHandleImpl::send(bool fin, |
| 100 WebSocketHandle::MessageType type, | 97 WebSocketHandle::MessageType type, |
| 101 const char* data, | 98 const char* data, |
| 102 size_t size) { | 99 size_t size) { |
| 103 DCHECK(websocket_); | 100 DCHECK(websocket_); |
| 104 | 101 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 115 break; | 112 break; |
| 116 default: | 113 default: |
| 117 NOTREACHED(); | 114 NOTREACHED(); |
| 118 return; | 115 return; |
| 119 } | 116 } |
| 120 | 117 |
| 121 DVLOG(1) << "WebSocketHandleImpl @" << reinterpret_cast<void*>(this) | 118 DVLOG(1) << "WebSocketHandleImpl @" << reinterpret_cast<void*>(this) |
| 122 << " Send(" << fin << ", " << type_to_pass << ", " | 119 << " Send(" << fin << ", " << type_to_pass << ", " |
| 123 << "(data size = " << size << "))"; | 120 << "(data size = " << size << "))"; |
| 124 | 121 |
| 125 mojo::Array<uint8_t> data_to_pass(size); | 122 std::vector<uint8_t> data_to_pass(size); |
| 126 std::copy(data, data + size, data_to_pass.begin()); | 123 std::copy(data, data + size, data_to_pass.begin()); |
| 127 | 124 |
| 128 websocket_->SendFrame(fin, type_to_pass, std::move(data_to_pass)); | 125 websocket_->SendFrame(fin, type_to_pass, data_to_pass); |
| 129 } | 126 } |
| 130 | 127 |
| 131 void WebSocketHandleImpl::flowControl(int64_t quota) { | 128 void WebSocketHandleImpl::flowControl(int64_t quota) { |
| 132 DCHECK(websocket_); | 129 DCHECK(websocket_); |
| 133 | 130 |
| 134 DVLOG(1) << "WebSocketHandleImpl @" << reinterpret_cast<void*>(this) | 131 DVLOG(1) << "WebSocketHandleImpl @" << reinterpret_cast<void*>(this) |
| 135 << " FlowControl(" << quota << ")"; | 132 << " FlowControl(" << quota << ")"; |
| 136 | 133 |
| 137 websocket_->SendFlowControl(quota); | 134 websocket_->SendFlowControl(quota); |
| 138 } | 135 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 165 // Our connection to the WebSocket was dropped. This could be due to | 162 // Our connection to the WebSocket was dropped. This could be due to |
| 166 // exceeding the maximum number of concurrent websockets from this process. | 163 // exceeding the maximum number of concurrent websockets from this process. |
| 167 | 164 |
| 168 // TODO(darin): This error message is overly specific. We don't know for sure | 165 // TODO(darin): This error message is overly specific. We don't know for sure |
| 169 // that this is the only reason we'd get here. This should be more generic or | 166 // that this is the only reason we'd get here. This should be more generic or |
| 170 // we should figure out how to make it more specific. | 167 // we should figure out how to make it more specific. |
| 171 OnFailChannel("Error in connection establishment: " | 168 OnFailChannel("Error in connection establishment: " |
| 172 "net::ERR_INSUFFICIENT_RESOURCES"); | 169 "net::ERR_INSUFFICIENT_RESOURCES"); |
| 173 } | 170 } |
| 174 | 171 |
| 175 void WebSocketHandleImpl::OnFailChannel(const mojo::String& message) { | 172 void WebSocketHandleImpl::OnFailChannel(const std::string& message) { |
| 176 DVLOG(1) << "WebSocketHandleImpl @" << reinterpret_cast<void*>(this) | 173 DVLOG(1) << "WebSocketHandleImpl @" << reinterpret_cast<void*>(this) |
| 177 << " OnFailChannel(" << message << ")"; | 174 << " OnFailChannel(" << message << ")"; |
| 178 | 175 |
| 179 WebSocketHandleClient* client = client_; | 176 WebSocketHandleClient* client = client_; |
| 180 Disconnect(); | 177 Disconnect(); |
| 181 if (!client) | 178 if (!client) |
| 182 return; | 179 return; |
| 183 | 180 |
| 184 client->didFail(this, WebString::fromUTF8(message)); | 181 client->didFail(this, WebString::fromUTF8(message)); |
| 185 // |this| can be deleted here. | 182 // |this| can be deleted here. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 213 for (size_t i = 0; i < response->headers.size(); ++i) { | 210 for (size_t i = 0; i < response->headers.size(); ++i) { |
| 214 const mojom::HttpHeaderPtr& header = response->headers[i]; | 211 const mojom::HttpHeaderPtr& header = response->headers[i]; |
| 215 response_to_pass.addHeaderField(WebString::fromLatin1(header->name), | 212 response_to_pass.addHeaderField(WebString::fromLatin1(header->name), |
| 216 WebString::fromLatin1(header->value)); | 213 WebString::fromLatin1(header->value)); |
| 217 } | 214 } |
| 218 response_to_pass.setHeadersText( | 215 response_to_pass.setHeadersText( |
| 219 WebString::fromLatin1(response->headers_text)); | 216 WebString::fromLatin1(response->headers_text)); |
| 220 client_->didFinishOpeningHandshake(this, response_to_pass); | 217 client_->didFinishOpeningHandshake(this, response_to_pass); |
| 221 } | 218 } |
| 222 | 219 |
| 223 void WebSocketHandleImpl::OnAddChannelResponse( | 220 void WebSocketHandleImpl::OnAddChannelResponse(const std::string& protocol, |
| 224 const mojo::String& protocol, | 221 const std::string& extensions) { |
| 225 const mojo::String& extensions) { | |
| 226 DVLOG(1) << "WebSocketHandleImpl @" << reinterpret_cast<void*>(this) | 222 DVLOG(1) << "WebSocketHandleImpl @" << reinterpret_cast<void*>(this) |
| 227 << " OnAddChannelResponse(" | 223 << " OnAddChannelResponse(" |
| 228 << protocol << ", " << extensions << ")"; | 224 << protocol << ", " << extensions << ")"; |
| 229 | 225 |
| 230 if (!client_) | 226 if (!client_) |
| 231 return; | 227 return; |
| 232 | 228 |
| 233 client_->didConnect(this, | 229 client_->didConnect(this, |
| 234 WebString::fromUTF8(protocol), | 230 WebString::fromUTF8(protocol), |
| 235 WebString::fromUTF8(extensions)); | 231 WebString::fromUTF8(extensions)); |
| 236 // |this| can be deleted here. | 232 // |this| can be deleted here. |
| 237 } | 233 } |
| 238 | 234 |
| 239 void WebSocketHandleImpl::OnDataFrame( | 235 void WebSocketHandleImpl::OnDataFrame(bool fin, |
| 240 bool fin, mojom::WebSocketMessageType type, | 236 mojom::WebSocketMessageType type, |
| 241 mojo::Array<uint8_t> data) { | 237 const std::vector<uint8_t>& data) { |
| 242 DVLOG(1) << "WebSocketHandleImpl @" << reinterpret_cast<void*>(this) | 238 DVLOG(1) << "WebSocketHandleImpl @" << reinterpret_cast<void*>(this) |
| 243 << " OnDataFrame(" << fin << ", " << type << ", " | 239 << " OnDataFrame(" << fin << ", " << type << ", " |
| 244 << "(data size = " << data.size() << "))"; | 240 << "(data size = " << data.size() << "))"; |
| 245 if (!client_) | 241 if (!client_) |
| 246 return; | 242 return; |
| 247 | 243 |
| 248 WebSocketHandle::MessageType type_to_pass = | 244 WebSocketHandle::MessageType type_to_pass = |
| 249 WebSocketHandle::MessageTypeContinuation; | 245 WebSocketHandle::MessageTypeContinuation; |
| 250 switch (type) { | 246 switch (type) { |
| 251 case mojom::WebSocketMessageType::CONTINUATION: | 247 case mojom::WebSocketMessageType::CONTINUATION: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 267 void WebSocketHandleImpl::OnFlowControl(int64_t quota) { | 263 void WebSocketHandleImpl::OnFlowControl(int64_t quota) { |
| 268 DVLOG(1) << "WebSocketHandleImpl @" << reinterpret_cast<void*>(this) | 264 DVLOG(1) << "WebSocketHandleImpl @" << reinterpret_cast<void*>(this) |
| 269 << " OnFlowControl(" << quota << ")"; | 265 << " OnFlowControl(" << quota << ")"; |
| 270 if (!client_) | 266 if (!client_) |
| 271 return; | 267 return; |
| 272 | 268 |
| 273 client_->didReceiveFlowControl(this, quota); | 269 client_->didReceiveFlowControl(this, quota); |
| 274 // |this| can be deleted here. | 270 // |this| can be deleted here. |
| 275 } | 271 } |
| 276 | 272 |
| 277 void WebSocketHandleImpl::OnDropChannel(bool was_clean, uint16_t code, | 273 void WebSocketHandleImpl::OnDropChannel(bool was_clean, |
| 278 const mojo::String& reason) { | 274 uint16_t code, |
| 275 const std::string& reason) { |
| 279 DVLOG(1) << "WebSocketHandleImpl @" << reinterpret_cast<void*>(this) | 276 DVLOG(1) << "WebSocketHandleImpl @" << reinterpret_cast<void*>(this) |
| 280 << " OnDropChannel(" << was_clean << ", " << code << ", " | 277 << " OnDropChannel(" << was_clean << ", " << code << ", " |
| 281 << reason << ")"; | 278 << reason << ")"; |
| 282 | 279 |
| 283 WebSocketHandleClient* client = client_; | 280 WebSocketHandleClient* client = client_; |
| 284 Disconnect(); | 281 Disconnect(); |
| 285 if (!client) | 282 if (!client) |
| 286 return; | 283 return; |
| 287 | 284 |
| 288 client->didClose(this, was_clean, code, WebString::fromUTF8(reason)); | 285 client->didClose(this, was_clean, code, WebString::fromUTF8(reason)); |
| 289 // |this| can be deleted here. | 286 // |this| can be deleted here. |
| 290 } | 287 } |
| 291 | 288 |
| 292 void WebSocketHandleImpl::OnClosingHandshake() { | 289 void WebSocketHandleImpl::OnClosingHandshake() { |
| 293 DVLOG(1) << "WebSocketHandleImpl @" << reinterpret_cast<void*>(this) | 290 DVLOG(1) << "WebSocketHandleImpl @" << reinterpret_cast<void*>(this) |
| 294 << " OnClosingHandshake()"; | 291 << " OnClosingHandshake()"; |
| 295 if (!client_) | 292 if (!client_) |
| 296 return; | 293 return; |
| 297 | 294 |
| 298 client_->didStartClosingHandshake(this); | 295 client_->didStartClosingHandshake(this); |
| 299 // |this| can be deleted here. | 296 // |this| can be deleted here. |
| 300 } | 297 } |
| 301 | 298 |
| 302 } // namespace content | 299 } // namespace content |
| OLD | NEW |