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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
21 #include "content/browser/bad_message.h" | 21 #include "content/browser/bad_message.h" |
22 #include "content/browser/renderer_host/websocket_blob_sender.h" | 22 #include "content/browser/renderer_host/websocket_blob_sender.h" |
23 #include "content/browser/renderer_host/websocket_dispatcher_host.h" | 23 #include "content/browser/renderer_host/websocket_dispatcher_host.h" |
24 #include "content/browser/ssl/ssl_error_handler.h" | 24 #include "content/browser/ssl/ssl_error_handler.h" |
25 #include "content/browser/ssl/ssl_manager.h" | 25 #include "content/browser/ssl/ssl_manager.h" |
26 #include "content/common/websocket_messages.h" | 26 #include "content/common/websocket_messages.h" |
27 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
28 #include "content/public/browser/devtools_agent_host.h" | |
28 #include "content/public/browser/render_frame_host.h" | 29 #include "content/public/browser/render_frame_host.h" |
29 #include "content/public/browser/storage_partition.h" | 30 #include "content/public/browser/storage_partition.h" |
31 #include "content/public/browser/web_contents.h" | |
30 #include "ipc/ipc_message_macros.h" | 32 #include "ipc/ipc_message_macros.h" |
31 #include "net/base/net_errors.h" | 33 #include "net/base/net_errors.h" |
32 #include "net/http/http_request_headers.h" | 34 #include "net/http/http_request_headers.h" |
33 #include "net/http/http_response_headers.h" | 35 #include "net/http/http_response_headers.h" |
34 #include "net/http/http_util.h" | 36 #include "net/http/http_util.h" |
35 #include "net/ssl/ssl_info.h" | 37 #include "net/ssl/ssl_info.h" |
36 #include "net/websockets/websocket_channel.h" | 38 #include "net/websockets/websocket_channel.h" |
37 #include "net/websockets/websocket_errors.h" | 39 #include "net/websockets/websocket_errors.h" |
38 #include "net/websockets/websocket_event_interface.h" | 40 #include "net/websockets/websocket_event_interface.h" |
39 #include "net/websockets/websocket_frame.h" // for WebSocketFrameHeader::OpCode | 41 #include "net/websockets/websocket_frame.h" // for WebSocketFrameHeader::OpCode |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 AddChannel(socket_url, requested_protocols, origin, render_frame_id); | 419 AddChannel(socket_url, requested_protocols, origin, render_frame_id); |
418 } | 420 } |
419 // |this| may have been deleted here. | 421 // |this| may have been deleted here. |
420 } | 422 } |
421 | 423 |
422 void WebSocketHost::AddChannel( | 424 void WebSocketHost::AddChannel( |
423 const GURL& socket_url, | 425 const GURL& socket_url, |
424 const std::vector<std::string>& requested_protocols, | 426 const std::vector<std::string>& requested_protocols, |
425 const url::Origin& origin, | 427 const url::Origin& origin, |
426 int render_frame_id) { | 428 int render_frame_id) { |
429 | |
430 DCHECK(!channel_); | |
431 | |
432 net::HttpRequestHeaders additional_headers; | |
433 RenderFrameHost* frame_host = RenderFrameHost::FromID( | |
434 dispatcher_->render_process_id(), render_frame_id); | |
435 if (frame_host) { | |
436 WebContents* tab = WebContents::FromRenderFrameHost(frame_host); | |
437 DCHECK(tab); | |
438 | |
439 if (DevToolsAgentHost::HasFor(tab)) { | |
440 scoped_refptr<DevToolsAgentHost> agent = | |
441 DevToolsAgentHost::GetOrCreateFor(tab); | |
442 DCHECK(agent); | |
443 | |
444 std::string user_agent = agent->GetUserAgentOverride(); | |
dgozman
2016/05/24 19:02:30
I'd reverse this dependency, reaching from Network
| |
445 if (user_agent.length()) | |
446 additional_headers.SetHeader( | |
447 net::HttpRequestHeaders::kUserAgent, user_agent.c_str()); | |
448 } | |
449 } | |
450 | |
427 DVLOG(3) << "WebSocketHost::AddChannel" | 451 DVLOG(3) << "WebSocketHost::AddChannel" |
428 << " routing_id=" << routing_id_ << " socket_url=\"" << socket_url | 452 << " routing_id=" << routing_id_ << " socket_url=\"" << socket_url |
429 << "\" requested_protocols=\"" | 453 << "\" requested_protocols=\"" |
430 << base::JoinString(requested_protocols, ", ") << "\" origin=\"" | 454 << base::JoinString(requested_protocols, ", ") << "\" origin=\"" |
431 << origin << "\""; | 455 << origin << "\" additional_headers=\"" |
432 | 456 << additional_headers.ToString() << "\""; |
433 DCHECK(!channel_); | |
434 | 457 |
435 std::unique_ptr<net::WebSocketEventInterface> event_interface( | 458 std::unique_ptr<net::WebSocketEventInterface> event_interface( |
436 new WebSocketEventHandler(dispatcher_, this, routing_id_, | 459 new WebSocketEventHandler(dispatcher_, this, routing_id_, |
437 render_frame_id)); | 460 render_frame_id)); |
438 channel_.reset(new net::WebSocketChannel(std::move(event_interface), | 461 channel_.reset(new net::WebSocketChannel(std::move(event_interface), |
439 url_request_context_)); | 462 url_request_context_)); |
440 | 463 |
441 if (pending_flow_control_quota_ > 0) { | 464 if (pending_flow_control_quota_ > 0) { |
442 // channel_->SendFlowControl(pending_flow_control_quota_) must be called | 465 // channel_->SendFlowControl(pending_flow_control_quota_) must be called |
443 // after channel_->SendAddChannelRequest() below. | 466 // after channel_->SendAddChannelRequest() below. |
444 // We post OnFlowControl() here using |weak_ptr_factory_| instead of | 467 // We post OnFlowControl() here using |weak_ptr_factory_| instead of |
445 // calling SendFlowControl directly, because |this| may have been deleted | 468 // calling SendFlowControl directly, because |this| may have been deleted |
446 // after channel_->SendAddChannelRequest(). | 469 // after channel_->SendAddChannelRequest(). |
447 base::ThreadTaskRunnerHandle::Get()->PostTask( | 470 base::ThreadTaskRunnerHandle::Get()->PostTask( |
448 FROM_HERE, base::Bind(&WebSocketHost::OnFlowControl, | 471 FROM_HERE, base::Bind(&WebSocketHost::OnFlowControl, |
449 weak_ptr_factory_.GetWeakPtr(), | 472 weak_ptr_factory_.GetWeakPtr(), |
450 pending_flow_control_quota_)); | 473 pending_flow_control_quota_)); |
451 pending_flow_control_quota_ = 0; | 474 pending_flow_control_quota_ = 0; |
452 } | 475 } |
453 | 476 channel_->SendAddChannelRequest( |
454 channel_->SendAddChannelRequest(socket_url, requested_protocols, origin); | 477 socket_url, requested_protocols, origin, |
478 additional_headers.ToString()); | |
455 // |this| may have been deleted here. | 479 // |this| may have been deleted here. |
456 } | 480 } |
457 | 481 |
458 void WebSocketHost::OnSendBlob(const std::string& uuid, | 482 void WebSocketHost::OnSendBlob(const std::string& uuid, |
459 uint64_t expected_size) { | 483 uint64_t expected_size) { |
460 DVLOG(3) << "WebSocketHost::OnSendBlob" | 484 DVLOG(3) << "WebSocketHost::OnSendBlob" |
461 << " routing_id=" << routing_id_ << " uuid=" << uuid | 485 << " routing_id=" << routing_id_ << " uuid=" << uuid |
462 << " expected_size=" << expected_size; | 486 << " expected_size=" << expected_size; |
463 | 487 |
464 DCHECK(channel_); | 488 DCHECK(channel_); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
574 default: | 598 default: |
575 ignore_result(dispatcher_->NotifyFailure( | 599 ignore_result(dispatcher_->NotifyFailure( |
576 routing_id_, | 600 routing_id_, |
577 "Failed to load Blob: error code = " + net::ErrorToString(result))); | 601 "Failed to load Blob: error code = " + net::ErrorToString(result))); |
578 // |this| is destroyed here. | 602 // |this| is destroyed here. |
579 return; | 603 return; |
580 } | 604 } |
581 } | 605 } |
582 | 606 |
583 } // namespace content | 607 } // namespace content |
OLD | NEW |