| 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/browser/websockets/websocket_impl.h" | 5 #include "content/browser/websockets/websocket_impl.h" |
| 6 | 6 |
| 7 #include <inttypes.h> | 7 #include <inttypes.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 ChannelState WebSocketImpl::WebSocketEventHandler::OnDataFrame( | 167 ChannelState WebSocketImpl::WebSocketEventHandler::OnDataFrame( |
| 168 bool fin, | 168 bool fin, |
| 169 net::WebSocketFrameHeader::OpCode type, | 169 net::WebSocketFrameHeader::OpCode type, |
| 170 const std::vector<char>& data) { | 170 const std::vector<char>& data) { |
| 171 DVLOG(3) << "WebSocketEventHandler::OnDataFrame @" | 171 DVLOG(3) << "WebSocketEventHandler::OnDataFrame @" |
| 172 << reinterpret_cast<void*>(this) | 172 << reinterpret_cast<void*>(this) |
| 173 << " fin=" << fin | 173 << " fin=" << fin |
| 174 << " type=" << type << " data is " << data.size() << " bytes"; | 174 << " type=" << type << " data is " << data.size() << " bytes"; |
| 175 | 175 |
| 176 // TODO(darin): Avoid this copy. | 176 // TODO(darin): Avoid this copy. |
| 177 mojo::Array<uint8_t> data_to_pass(data.size()); | 177 std::vector<uint8_t> data_to_pass(data.size()); |
| 178 std::copy(data.begin(), data.end(), data_to_pass.begin()); | 178 std::copy(data.begin(), data.end(), data_to_pass.begin()); |
| 179 | 179 |
| 180 impl_->client_->OnDataFrame(fin, OpCodeToMessageType(type), | 180 impl_->client_->OnDataFrame(fin, OpCodeToMessageType(type), data_to_pass); |
| 181 std::move(data_to_pass)); | |
| 182 | 181 |
| 183 return net::WebSocketEventInterface::CHANNEL_ALIVE; | 182 return net::WebSocketEventInterface::CHANNEL_ALIVE; |
| 184 } | 183 } |
| 185 | 184 |
| 186 ChannelState WebSocketImpl::WebSocketEventHandler::OnClosingHandshake() { | 185 ChannelState WebSocketImpl::WebSocketEventHandler::OnClosingHandshake() { |
| 187 DVLOG(3) << "WebSocketEventHandler::OnClosingHandshake @" | 186 DVLOG(3) << "WebSocketEventHandler::OnClosingHandshake @" |
| 188 << reinterpret_cast<void*>(this); | 187 << reinterpret_cast<void*>(this); |
| 189 | 188 |
| 190 impl_->client_->OnClosingHandshake(); | 189 impl_->client_->OnClosingHandshake(); |
| 191 | 190 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 366 |
| 368 WebSocketImpl::~WebSocketImpl() {} | 367 WebSocketImpl::~WebSocketImpl() {} |
| 369 | 368 |
| 370 void WebSocketImpl::GoAway() { | 369 void WebSocketImpl::GoAway() { |
| 371 StartClosingHandshake(static_cast<uint16_t>(net::kWebSocketErrorGoingAway), | 370 StartClosingHandshake(static_cast<uint16_t>(net::kWebSocketErrorGoingAway), |
| 372 ""); | 371 ""); |
| 373 } | 372 } |
| 374 | 373 |
| 375 void WebSocketImpl::AddChannelRequest( | 374 void WebSocketImpl::AddChannelRequest( |
| 376 const GURL& socket_url, | 375 const GURL& socket_url, |
| 377 mojo::Array<mojo::String> requested_protocols_mojo, | 376 const std::vector<std::string>& requested_protocols, |
| 378 const url::Origin& origin, | 377 const url::Origin& origin, |
| 379 const GURL& first_party_for_cookies, | 378 const GURL& first_party_for_cookies, |
| 380 const mojo::String& user_agent_override, | 379 const std::string& user_agent_override, |
| 381 mojom::WebSocketClientPtr client) { | 380 mojom::WebSocketClientPtr client) { |
| 382 // Convert to STL types. | |
| 383 std::vector<std::string> requested_protocols( | |
| 384 requested_protocols_mojo.begin(), | |
| 385 requested_protocols_mojo.end()); | |
| 386 | |
| 387 DVLOG(3) << "WebSocketImpl::AddChannelRequest @" | 381 DVLOG(3) << "WebSocketImpl::AddChannelRequest @" |
| 388 << reinterpret_cast<void*>(this) | 382 << reinterpret_cast<void*>(this) |
| 389 << " socket_url=\"" << socket_url << "\" requested_protocols=\"" | 383 << " socket_url=\"" << socket_url << "\" requested_protocols=\"" |
| 390 << base::JoinString(requested_protocols, ", ") | 384 << base::JoinString(requested_protocols, ", ") |
| 391 << "\" origin=\"" << origin | 385 << "\" origin=\"" << origin |
| 392 << "\" first_party_for_cookies=\"" << first_party_for_cookies | 386 << "\" first_party_for_cookies=\"" << first_party_for_cookies |
| 393 << "\" user_agent_override=\"" << user_agent_override | 387 << "\" user_agent_override=\"" << user_agent_override |
| 394 << "\""; | 388 << "\""; |
| 395 | 389 |
| 396 if (client_ || !client) { | 390 if (client_ || !client) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 413 origin, | 407 origin, |
| 414 first_party_for_cookies, | 408 first_party_for_cookies, |
| 415 user_agent_override), | 409 user_agent_override), |
| 416 delay_); | 410 delay_); |
| 417 } else { | 411 } else { |
| 418 AddChannel(socket_url, requested_protocols, origin, first_party_for_cookies, | 412 AddChannel(socket_url, requested_protocols, origin, first_party_for_cookies, |
| 419 user_agent_override); | 413 user_agent_override); |
| 420 } | 414 } |
| 421 } | 415 } |
| 422 | 416 |
| 423 void WebSocketImpl::SendFrame(bool fin, mojom::WebSocketMessageType type, | 417 void WebSocketImpl::SendFrame(bool fin, |
| 424 mojo::Array<uint8_t> data) { | 418 mojom::WebSocketMessageType type, |
| 419 const std::vector<uint8_t>& data) { |
| 425 DVLOG(3) << "WebSocketImpl::SendFrame @" | 420 DVLOG(3) << "WebSocketImpl::SendFrame @" |
| 426 << reinterpret_cast<void*>(this) << " fin=" << fin | 421 << reinterpret_cast<void*>(this) << " fin=" << fin |
| 427 << " type=" << type << " data is " << data.size() << " bytes"; | 422 << " type=" << type << " data is " << data.size() << " bytes"; |
| 428 | 423 |
| 429 if (!channel_) { | 424 if (!channel_) { |
| 430 // The client should not be sending us frames until after we've informed | 425 // The client should not be sending us frames until after we've informed |
| 431 // it that the channel has been opened (OnAddChannelResponse). | 426 // it that the channel has been opened (OnAddChannelResponse). |
| 432 if (handshake_succeeded_) { | 427 if (handshake_succeeded_) { |
| 433 DVLOG(1) << "Dropping frame sent to closed websocket"; | 428 DVLOG(1) << "Dropping frame sent to closed websocket"; |
| 434 } else { | 429 } else { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 455 // per-renderer WebSocket throttling. | 450 // per-renderer WebSocket throttling. |
| 456 // SendFlowControl() is called after WebSocketChannel is created. | 451 // SendFlowControl() is called after WebSocketChannel is created. |
| 457 pending_flow_control_quota_ += quota; | 452 pending_flow_control_quota_ += quota; |
| 458 return; | 453 return; |
| 459 } | 454 } |
| 460 | 455 |
| 461 ignore_result(channel_->SendFlowControl(quota)); | 456 ignore_result(channel_->SendFlowControl(quota)); |
| 462 } | 457 } |
| 463 | 458 |
| 464 void WebSocketImpl::StartClosingHandshake(uint16_t code, | 459 void WebSocketImpl::StartClosingHandshake(uint16_t code, |
| 465 const mojo::String& reason) { | 460 const std::string& reason) { |
| 466 DVLOG(3) << "WebSocketImpl::StartClosingHandshake @" | 461 DVLOG(3) << "WebSocketImpl::StartClosingHandshake @" |
| 467 << reinterpret_cast<void*>(this) | 462 << reinterpret_cast<void*>(this) |
| 468 << " code=" << code << " reason=\"" << reason << "\""; | 463 << " code=" << code << " reason=\"" << reason << "\""; |
| 469 | 464 |
| 470 if (!channel_) { | 465 if (!channel_) { |
| 471 // WebSocketChannel is not yet created due to the delay introduced by | 466 // WebSocketChannel is not yet created due to the delay introduced by |
| 472 // per-renderer WebSocket throttling. | 467 // per-renderer WebSocket throttling. |
| 473 if (client_) | 468 if (client_) |
| 474 client_->OnDropChannel(false, net::kWebSocketErrorAbnormalClosure, ""); | 469 client_->OnDropChannel(false, net::kWebSocketErrorAbnormalClosure, ""); |
| 475 return; | 470 return; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 net::HttpRequestHeaders::kUserAgent, | 522 net::HttpRequestHeaders::kUserAgent, |
| 528 user_agent_override.c_str()); | 523 user_agent_override.c_str()); |
| 529 } | 524 } |
| 530 channel_->SendAddChannelRequest(socket_url, requested_protocols, origin, | 525 channel_->SendAddChannelRequest(socket_url, requested_protocols, origin, |
| 531 first_party_for_cookies, additional_headers); | 526 first_party_for_cookies, additional_headers); |
| 532 if (quota > 0) | 527 if (quota > 0) |
| 533 SendFlowControl(quota); | 528 SendFlowControl(quota); |
| 534 } | 529 } |
| 535 | 530 |
| 536 } // namespace content | 531 } // namespace content |
| OLD | NEW |