| 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/renderer_host/websocket_host.h" | 5 #include "content/browser/renderer_host/websocket_host.h" |
| 6 | 6 |
| 7 #include <inttypes.h> | 7 #include <inttypes.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 IPC_MESSAGE_HANDLER(WebSocketHostMsg_SendBlob, OnSendBlob) | 389 IPC_MESSAGE_HANDLER(WebSocketHostMsg_SendBlob, OnSendBlob) |
| 390 IPC_MESSAGE_HANDLER(WebSocketMsg_SendFrame, OnSendFrame) | 390 IPC_MESSAGE_HANDLER(WebSocketMsg_SendFrame, OnSendFrame) |
| 391 IPC_MESSAGE_HANDLER(WebSocketMsg_FlowControl, OnFlowControl) | 391 IPC_MESSAGE_HANDLER(WebSocketMsg_FlowControl, OnFlowControl) |
| 392 IPC_MESSAGE_HANDLER(WebSocketMsg_DropChannel, OnDropChannel) | 392 IPC_MESSAGE_HANDLER(WebSocketMsg_DropChannel, OnDropChannel) |
| 393 IPC_MESSAGE_UNHANDLED(handled = false) | 393 IPC_MESSAGE_UNHANDLED(handled = false) |
| 394 IPC_END_MESSAGE_MAP() | 394 IPC_END_MESSAGE_MAP() |
| 395 return handled; | 395 return handled; |
| 396 } | 396 } |
| 397 | 397 |
| 398 void WebSocketHost::OnAddChannelRequest( | 398 void WebSocketHost::OnAddChannelRequest( |
| 399 const GURL& socket_url, | 399 const WebSocketHostMsg_AddChannelRequest_Params& params) { |
| 400 const std::vector<std::string>& requested_protocols, | |
| 401 const url::Origin& origin, | |
| 402 const std::string& user_agent_override, | |
| 403 int render_frame_id) { | |
| 404 DVLOG(3) << "WebSocketHost::OnAddChannelRequest" | 400 DVLOG(3) << "WebSocketHost::OnAddChannelRequest" |
| 405 << " routing_id=" << routing_id_ << " socket_url=\"" << socket_url | 401 << " routing_id=" << routing_id_ << " socket_url=\"" |
| 406 << "\" requested_protocols=\"" | 402 << params.socket_url << "\" requested_protocols=\"" |
| 407 << base::JoinString(requested_protocols, ", ") << "\" origin=\"" | 403 << base::JoinString(params.requested_protocols, ", ") |
| 408 << origin << "\" user_agent_override=\"" << user_agent_override | 404 << "\" origin=\"" << params.origin |
| 405 << "\" first_party_for_cookies=\"" |
| 406 << params.first_party_for_cookies << "\" user_agent_override=\"" |
| 407 << params.user_agent_override |
| 409 << "\""; | 408 << "\""; |
| 410 | 409 |
| 411 DCHECK(!channel_); | 410 DCHECK(!channel_); |
| 412 if (delay_ > base::TimeDelta()) { | 411 if (delay_ > base::TimeDelta()) { |
| 413 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 412 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 414 FROM_HERE, | 413 FROM_HERE, |
| 415 base::Bind(&WebSocketHost::AddChannel, weak_ptr_factory_.GetWeakPtr(), | 414 base::Bind(&WebSocketHost::AddChannel, weak_ptr_factory_.GetWeakPtr(), |
| 416 socket_url, requested_protocols, origin, | 415 params.socket_url, params.requested_protocols, |
| 417 user_agent_override, render_frame_id), | 416 params.origin, params.first_party_for_cookies, |
| 417 params.user_agent_override, params.render_frame_id), |
| 418 delay_); | 418 delay_); |
| 419 } else { | 419 } else { |
| 420 AddChannel(socket_url, requested_protocols, origin, | 420 AddChannel( |
| 421 user_agent_override, render_frame_id); | 421 params.socket_url, params.requested_protocols, params.origin, |
| 422 params.first_party_for_cookies, params.user_agent_override, |
| 423 params.render_frame_id); |
| 422 } | 424 } |
| 423 // |this| may have been deleted here. | 425 // |this| may have been deleted here. |
| 424 } | 426 } |
| 425 | 427 |
| 426 void WebSocketHost::AddChannel( | 428 void WebSocketHost::AddChannel( |
| 427 const GURL& socket_url, | 429 const GURL& socket_url, |
| 428 const std::vector<std::string>& requested_protocols, | 430 const std::vector<std::string>& requested_protocols, |
| 429 const url::Origin& origin, | 431 const url::Origin& origin, |
| 432 const GURL& first_party_for_cookies, |
| 430 const std::string& user_agent_override, | 433 const std::string& user_agent_override, |
| 431 int render_frame_id) { | 434 int render_frame_id) { |
| 432 DVLOG(3) << "WebSocketHost::AddChannel" | 435 DVLOG(3) << "WebSocketHost::AddChannel" |
| 433 << " routing_id=" << routing_id_ << " socket_url=\"" << socket_url | 436 << " routing_id=" << routing_id_ << " socket_url=\"" << socket_url |
| 434 << "\" requested_protocols=\"" | 437 << "\" requested_protocols=\"" |
| 435 << base::JoinString(requested_protocols, ", ") << "\" origin=\"" | 438 << base::JoinString(requested_protocols, ", ") << "\" origin=\"" |
| 436 << origin << "\" user_agent_override=\"" | 439 << origin << "\" first_party_for_cookies=\"" |
| 440 << first_party_for_cookies << "\" user_agent_override=\"" |
| 437 << user_agent_override << "\""; | 441 << user_agent_override << "\""; |
| 438 | 442 |
| 439 DCHECK(!channel_); | 443 DCHECK(!channel_); |
| 440 | 444 |
| 441 std::unique_ptr<net::WebSocketEventInterface> event_interface( | 445 std::unique_ptr<net::WebSocketEventInterface> event_interface( |
| 442 new WebSocketEventHandler(dispatcher_, this, routing_id_, | 446 new WebSocketEventHandler(dispatcher_, this, routing_id_, |
| 443 render_frame_id)); | 447 render_frame_id)); |
| 444 channel_.reset(new net::WebSocketChannel(std::move(event_interface), | 448 channel_.reset(new net::WebSocketChannel(std::move(event_interface), |
| 445 url_request_context_)); | 449 url_request_context_)); |
| 446 | 450 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 462 if (!net::HttpUtil::IsValidHeaderValue(user_agent_override)) { | 466 if (!net::HttpUtil::IsValidHeaderValue(user_agent_override)) { |
| 463 bad_message::ReceivedBadMessage( | 467 bad_message::ReceivedBadMessage( |
| 464 dispatcher_, bad_message::WSH_INVALID_HEADER_VALUE); | 468 dispatcher_, bad_message::WSH_INVALID_HEADER_VALUE); |
| 465 return; | 469 return; |
| 466 } | 470 } |
| 467 additional_headers = base::StringPrintf("%s:%s", | 471 additional_headers = base::StringPrintf("%s:%s", |
| 468 net::HttpRequestHeaders::kUserAgent, | 472 net::HttpRequestHeaders::kUserAgent, |
| 469 user_agent_override.c_str()); | 473 user_agent_override.c_str()); |
| 470 } | 474 } |
| 471 channel_->SendAddChannelRequest( | 475 channel_->SendAddChannelRequest( |
| 472 socket_url, requested_protocols, origin, | 476 socket_url, requested_protocols, origin, first_party_for_cookies, |
| 473 additional_headers); | 477 additional_headers); |
| 474 // |this| may have been deleted here. | 478 // |this| may have been deleted here. |
| 475 } | 479 } |
| 476 | 480 |
| 477 void WebSocketHost::OnSendBlob(const std::string& uuid, | 481 void WebSocketHost::OnSendBlob(const std::string& uuid, |
| 478 uint64_t expected_size) { | 482 uint64_t expected_size) { |
| 479 DVLOG(3) << "WebSocketHost::OnSendBlob" | 483 DVLOG(3) << "WebSocketHost::OnSendBlob" |
| 480 << " routing_id=" << routing_id_ << " uuid=" << uuid | 484 << " routing_id=" << routing_id_ << " uuid=" << uuid |
| 481 << " expected_size=" << expected_size; | 485 << " expected_size=" << expected_size; |
| 482 | 486 |
| 483 DCHECK(channel_); | 487 DCHECK(channel_); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 default: | 597 default: |
| 594 ignore_result(dispatcher_->NotifyFailure( | 598 ignore_result(dispatcher_->NotifyFailure( |
| 595 routing_id_, | 599 routing_id_, |
| 596 "Failed to load Blob: error code = " + net::ErrorToString(result))); | 600 "Failed to load Blob: error code = " + net::ErrorToString(result))); |
| 597 // |this| is destroyed here. | 601 // |this| is destroyed here. |
| 598 return; | 602 return; |
| 599 } | 603 } |
| 600 } | 604 } |
| 601 | 605 |
| 602 } // namespace content | 606 } // namespace content |
| OLD | NEW |