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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 GURL& socket_url, |
400 const std::vector<std::string>& requested_protocols, | 400 const std::vector<std::string>& requested_protocols, |
401 const url::Origin& origin, | 401 const url::Origin& origin, |
| 402 const std::string& user_agent_override, |
402 int render_frame_id) { | 403 int render_frame_id) { |
403 DVLOG(3) << "WebSocketHost::OnAddChannelRequest" | 404 DVLOG(3) << "WebSocketHost::OnAddChannelRequest" |
404 << " routing_id=" << routing_id_ << " socket_url=\"" << socket_url | 405 << " routing_id=" << routing_id_ << " socket_url=\"" << socket_url |
405 << "\" requested_protocols=\"" | 406 << "\" requested_protocols=\"" |
406 << base::JoinString(requested_protocols, ", ") << "\" origin=\"" | 407 << base::JoinString(requested_protocols, ", ") << "\" origin=\"" |
407 << origin << "\""; | 408 << origin << "\" user_agent_override=\"" << user_agent_override |
| 409 << "\""; |
408 | 410 |
409 DCHECK(!channel_); | 411 DCHECK(!channel_); |
410 if (delay_ > base::TimeDelta()) { | 412 if (delay_ > base::TimeDelta()) { |
411 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 413 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
412 FROM_HERE, | 414 FROM_HERE, |
413 base::Bind(&WebSocketHost::AddChannel, weak_ptr_factory_.GetWeakPtr(), | 415 base::Bind(&WebSocketHost::AddChannel, weak_ptr_factory_.GetWeakPtr(), |
414 socket_url, requested_protocols, origin, render_frame_id), | 416 socket_url, requested_protocols, origin, |
| 417 user_agent_override, render_frame_id), |
415 delay_); | 418 delay_); |
416 } else { | 419 } else { |
417 AddChannel(socket_url, requested_protocols, origin, render_frame_id); | 420 AddChannel(socket_url, requested_protocols, origin, |
| 421 user_agent_override, render_frame_id); |
418 } | 422 } |
419 // |this| may have been deleted here. | 423 // |this| may have been deleted here. |
420 } | 424 } |
421 | 425 |
422 void WebSocketHost::AddChannel( | 426 void WebSocketHost::AddChannel( |
423 const GURL& socket_url, | 427 const GURL& socket_url, |
424 const std::vector<std::string>& requested_protocols, | 428 const std::vector<std::string>& requested_protocols, |
425 const url::Origin& origin, | 429 const url::Origin& origin, |
| 430 const std::string& user_agent_override, |
426 int render_frame_id) { | 431 int render_frame_id) { |
427 DVLOG(3) << "WebSocketHost::AddChannel" | 432 DVLOG(3) << "WebSocketHost::AddChannel" |
428 << " routing_id=" << routing_id_ << " socket_url=\"" << socket_url | 433 << " routing_id=" << routing_id_ << " socket_url=\"" << socket_url |
429 << "\" requested_protocols=\"" | 434 << "\" requested_protocols=\"" |
430 << base::JoinString(requested_protocols, ", ") << "\" origin=\"" | 435 << base::JoinString(requested_protocols, ", ") << "\" origin=\"" |
431 << origin << "\""; | 436 << origin << "\" user_agent_override=\"" |
| 437 << user_agent_override << "\""; |
432 | 438 |
433 DCHECK(!channel_); | 439 DCHECK(!channel_); |
434 | 440 |
435 std::unique_ptr<net::WebSocketEventInterface> event_interface( | 441 std::unique_ptr<net::WebSocketEventInterface> event_interface( |
436 new WebSocketEventHandler(dispatcher_, this, routing_id_, | 442 new WebSocketEventHandler(dispatcher_, this, routing_id_, |
437 render_frame_id)); | 443 render_frame_id)); |
438 channel_.reset(new net::WebSocketChannel(std::move(event_interface), | 444 channel_.reset(new net::WebSocketChannel(std::move(event_interface), |
439 url_request_context_)); | 445 url_request_context_)); |
440 | 446 |
441 if (pending_flow_control_quota_ > 0) { | 447 if (pending_flow_control_quota_ > 0) { |
442 // channel_->SendFlowControl(pending_flow_control_quota_) must be called | 448 // channel_->SendFlowControl(pending_flow_control_quota_) must be called |
443 // after channel_->SendAddChannelRequest() below. | 449 // after channel_->SendAddChannelRequest() below. |
444 // We post OnFlowControl() here using |weak_ptr_factory_| instead of | 450 // We post OnFlowControl() here using |weak_ptr_factory_| instead of |
445 // calling SendFlowControl directly, because |this| may have been deleted | 451 // calling SendFlowControl directly, because |this| may have been deleted |
446 // after channel_->SendAddChannelRequest(). | 452 // after channel_->SendAddChannelRequest(). |
447 base::ThreadTaskRunnerHandle::Get()->PostTask( | 453 base::ThreadTaskRunnerHandle::Get()->PostTask( |
448 FROM_HERE, base::Bind(&WebSocketHost::OnFlowControl, | 454 FROM_HERE, base::Bind(&WebSocketHost::OnFlowControl, |
449 weak_ptr_factory_.GetWeakPtr(), | 455 weak_ptr_factory_.GetWeakPtr(), |
450 pending_flow_control_quota_)); | 456 pending_flow_control_quota_)); |
451 pending_flow_control_quota_ = 0; | 457 pending_flow_control_quota_ = 0; |
452 } | 458 } |
453 | 459 |
454 channel_->SendAddChannelRequest(socket_url, requested_protocols, origin); | 460 std::string additional_headers; |
| 461 if (user_agent_override != "") { |
| 462 if (!net::HttpUtil::IsValidHeaderValue(user_agent_override)) { |
| 463 bad_message::ReceivedBadMessage( |
| 464 dispatcher_, bad_message::WSH_INVALID_HEADER_VALUE); |
| 465 return; |
| 466 } |
| 467 additional_headers = base::StringPrintf("%s:%s", |
| 468 net::HttpRequestHeaders::kUserAgent, |
| 469 user_agent_override.c_str()); |
| 470 } |
| 471 channel_->SendAddChannelRequest( |
| 472 socket_url, requested_protocols, origin, |
| 473 additional_headers); |
455 // |this| may have been deleted here. | 474 // |this| may have been deleted here. |
456 } | 475 } |
457 | 476 |
458 void WebSocketHost::OnSendBlob(const std::string& uuid, | 477 void WebSocketHost::OnSendBlob(const std::string& uuid, |
459 uint64_t expected_size) { | 478 uint64_t expected_size) { |
460 DVLOG(3) << "WebSocketHost::OnSendBlob" | 479 DVLOG(3) << "WebSocketHost::OnSendBlob" |
461 << " routing_id=" << routing_id_ << " uuid=" << uuid | 480 << " routing_id=" << routing_id_ << " uuid=" << uuid |
462 << " expected_size=" << expected_size; | 481 << " expected_size=" << expected_size; |
463 | 482 |
464 DCHECK(channel_); | 483 DCHECK(channel_); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 default: | 593 default: |
575 ignore_result(dispatcher_->NotifyFailure( | 594 ignore_result(dispatcher_->NotifyFailure( |
576 routing_id_, | 595 routing_id_, |
577 "Failed to load Blob: error code = " + net::ErrorToString(result))); | 596 "Failed to load Blob: error code = " + net::ErrorToString(result))); |
578 // |this| is destroyed here. | 597 // |this| is destroyed here. |
579 return; | 598 return; |
580 } | 599 } |
581 } | 600 } |
582 | 601 |
583 } // namespace content | 602 } // namespace content |
OLD | NEW |