Chromium Code Reviews| 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 |
| 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/child_process_security_policy_impl.h" | 22 #include "content/browser/child_process_security_policy_impl.h" |
| 23 #include "content/browser/loader/resource_request_info_impl.h" | |
|
tyoshino (SeeGerritForStatus)
2016/10/12 08:13:36
for what?
yhirano
2016/10/12 10:47:15
Sorry, it was used when I used ResourceRequestInfo
| |
| 23 #include "content/browser/ssl/ssl_error_handler.h" | 24 #include "content/browser/ssl/ssl_error_handler.h" |
| 24 #include "content/browser/ssl/ssl_manager.h" | 25 #include "content/browser/ssl/ssl_manager.h" |
| 26 #include "content/browser/websockets/websocket_handshake_request_info_impl.h" | |
| 25 #include "content/public/browser/storage_partition.h" | 27 #include "content/public/browser/storage_partition.h" |
| 28 #include "content/public/common/process_type.h" | |
|
tyoshino (SeeGerritForStatus)
2016/10/12 08:13:36
for what?
yhirano
2016/10/12 10:47:15
Ditto
| |
| 26 #include "ipc/ipc_message.h" | 29 #include "ipc/ipc_message.h" |
| 27 #include "net/base/io_buffer.h" | 30 #include "net/base/io_buffer.h" |
| 28 #include "net/base/net_errors.h" | 31 #include "net/base/net_errors.h" |
| 29 #include "net/http/http_request_headers.h" | 32 #include "net/http/http_request_headers.h" |
| 30 #include "net/http/http_response_headers.h" | 33 #include "net/http/http_response_headers.h" |
| 31 #include "net/http/http_util.h" | 34 #include "net/http/http_util.h" |
| 32 #include "net/ssl/ssl_info.h" | 35 #include "net/ssl/ssl_info.h" |
| 36 #include "net/url_request/url_request.h" | |
|
tyoshino (SeeGerritForStatus)
2016/10/12 08:13:36
where is this used?
yhirano
2016/10/12 10:47:15
Done.
| |
| 33 #include "net/url_request/url_request_context_getter.h" | 37 #include "net/url_request/url_request_context_getter.h" |
| 34 #include "net/websockets/websocket_channel.h" | 38 #include "net/websockets/websocket_channel.h" |
| 35 #include "net/websockets/websocket_errors.h" | 39 #include "net/websockets/websocket_errors.h" |
| 36 #include "net/websockets/websocket_event_interface.h" | 40 #include "net/websockets/websocket_event_interface.h" |
| 37 #include "net/websockets/websocket_frame.h" // for WebSocketFrameHeader::OpCode | 41 #include "net/websockets/websocket_frame.h" // for WebSocketFrameHeader::OpCode |
| 38 #include "net/websockets/websocket_handshake_request_info.h" | 42 #include "net/websockets/websocket_handshake_request_info.h" |
| 39 #include "net/websockets/websocket_handshake_response_info.h" | 43 #include "net/websockets/websocket_handshake_response_info.h" |
| 40 #include "url/origin.h" | 44 #include "url/origin.h" |
| 41 | 45 |
| 42 namespace content { | 46 namespace content { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 // Implementation of net::WebSocketEventInterface. Receives events from our | 87 // Implementation of net::WebSocketEventInterface. Receives events from our |
| 84 // WebSocketChannel object. | 88 // WebSocketChannel object. |
| 85 class WebSocketImpl::WebSocketEventHandler final | 89 class WebSocketImpl::WebSocketEventHandler final |
| 86 : public net::WebSocketEventInterface { | 90 : public net::WebSocketEventInterface { |
| 87 public: | 91 public: |
| 88 explicit WebSocketEventHandler(WebSocketImpl* impl); | 92 explicit WebSocketEventHandler(WebSocketImpl* impl); |
| 89 ~WebSocketEventHandler() override; | 93 ~WebSocketEventHandler() override; |
| 90 | 94 |
| 91 // net::WebSocketEventInterface implementation | 95 // net::WebSocketEventInterface implementation |
| 92 | 96 |
| 97 void OnCreateURLRequest(net::URLRequest* request) override; | |
| 93 ChannelState OnAddChannelResponse(const std::string& selected_subprotocol, | 98 ChannelState OnAddChannelResponse(const std::string& selected_subprotocol, |
| 94 const std::string& extensions) override; | 99 const std::string& extensions) override; |
| 95 ChannelState OnDataFrame(bool fin, | 100 ChannelState OnDataFrame(bool fin, |
| 96 WebSocketMessageType type, | 101 WebSocketMessageType type, |
| 97 scoped_refptr<net::IOBuffer> buffer, | 102 scoped_refptr<net::IOBuffer> buffer, |
| 98 size_t buffer_size) override; | 103 size_t buffer_size) override; |
| 99 ChannelState OnClosingHandshake() override; | 104 ChannelState OnClosingHandshake() override; |
| 100 ChannelState OnFlowControl(int64_t quota) override; | 105 ChannelState OnFlowControl(int64_t quota) override; |
| 101 ChannelState OnDropChannel(bool was_clean, | 106 ChannelState OnDropChannel(bool was_clean, |
| 102 uint16_t code, | 107 uint16_t code, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 : impl_(impl) { | 149 : impl_(impl) { |
| 145 DVLOG(1) << "WebSocketEventHandler created @" | 150 DVLOG(1) << "WebSocketEventHandler created @" |
| 146 << reinterpret_cast<void*>(this); | 151 << reinterpret_cast<void*>(this); |
| 147 } | 152 } |
| 148 | 153 |
| 149 WebSocketImpl::WebSocketEventHandler::~WebSocketEventHandler() { | 154 WebSocketImpl::WebSocketEventHandler::~WebSocketEventHandler() { |
| 150 DVLOG(1) << "WebSocketEventHandler destroyed @" | 155 DVLOG(1) << "WebSocketEventHandler destroyed @" |
| 151 << reinterpret_cast<void*>(this); | 156 << reinterpret_cast<void*>(this); |
| 152 } | 157 } |
| 153 | 158 |
| 159 void WebSocketImpl::WebSocketEventHandler::OnCreateURLRequest( | |
| 160 net::URLRequest* request) { | |
| 161 WebSocketHandshakeRequestInfoImpl::CreateInfoAndAssociateWithRequest( | |
| 162 impl_->child_id_, impl_->frame_id_, request); | |
| 163 } | |
| 164 | |
| 154 ChannelState WebSocketImpl::WebSocketEventHandler::OnAddChannelResponse( | 165 ChannelState WebSocketImpl::WebSocketEventHandler::OnAddChannelResponse( |
| 155 const std::string& selected_protocol, | 166 const std::string& selected_protocol, |
| 156 const std::string& extensions) { | 167 const std::string& extensions) { |
| 157 DVLOG(3) << "WebSocketEventHandler::OnAddChannelResponse @" | 168 DVLOG(3) << "WebSocketEventHandler::OnAddChannelResponse @" |
| 158 << reinterpret_cast<void*>(this) | 169 << reinterpret_cast<void*>(this) |
| 159 << " selected_protocol=\"" << selected_protocol << "\"" | 170 << " selected_protocol=\"" << selected_protocol << "\"" |
| 160 << " extensions=\"" << extensions << "\""; | 171 << " extensions=\"" << extensions << "\""; |
| 161 | 172 |
| 162 impl_->delegate_->OnReceivedResponseFromServer(impl_); | 173 impl_->delegate_->OnReceivedResponseFromServer(impl_); |
| 163 | 174 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 : static_cast<net::CertStatus>(-1)); | 358 : static_cast<net::CertStatus>(-1)); |
| 348 callbacks_->CancelSSLRequest(error, ssl_info); | 359 callbacks_->CancelSSLRequest(error, ssl_info); |
| 349 } | 360 } |
| 350 | 361 |
| 351 void WebSocketImpl::WebSocketEventHandler::SSLErrorHandlerDelegate:: | 362 void WebSocketImpl::WebSocketEventHandler::SSLErrorHandlerDelegate:: |
| 352 ContinueSSLRequest() { | 363 ContinueSSLRequest() { |
| 353 DVLOG(3) << "SSLErrorHandlerDelegate::ContinueSSLRequest"; | 364 DVLOG(3) << "SSLErrorHandlerDelegate::ContinueSSLRequest"; |
| 354 callbacks_->ContinueSSLRequest(); | 365 callbacks_->ContinueSSLRequest(); |
| 355 } | 366 } |
| 356 | 367 |
| 357 WebSocketImpl::WebSocketImpl( | 368 WebSocketImpl::WebSocketImpl(Delegate* delegate, |
| 358 Delegate* delegate, | 369 blink::mojom::WebSocketRequest request, |
| 359 blink::mojom::WebSocketRequest request, | 370 int child_id, |
| 360 int frame_id, | 371 int frame_id, |
| 361 base::TimeDelta delay) | 372 base::TimeDelta delay) |
| 362 : delegate_(delegate), | 373 : delegate_(delegate), |
| 363 binding_(this, std::move(request)), | 374 binding_(this, std::move(request)), |
| 364 delay_(delay), | 375 delay_(delay), |
| 365 pending_flow_control_quota_(0), | 376 pending_flow_control_quota_(0), |
| 377 child_id_(child_id), | |
| 366 frame_id_(frame_id), | 378 frame_id_(frame_id), |
| 367 handshake_succeeded_(false), | 379 handshake_succeeded_(false), |
| 368 weak_ptr_factory_(this) { | 380 weak_ptr_factory_(this) { |
| 369 binding_.set_connection_error_handler( | 381 binding_.set_connection_error_handler( |
| 370 base::Bind(&WebSocketImpl::OnConnectionError, base::Unretained(this))); | 382 base::Bind(&WebSocketImpl::OnConnectionError, base::Unretained(this))); |
| 371 } | 383 } |
| 372 | 384 |
| 373 WebSocketImpl::~WebSocketImpl() {} | 385 WebSocketImpl::~WebSocketImpl() {} |
| 374 | 386 |
| 375 void WebSocketImpl::GoAway() { | 387 void WebSocketImpl::GoAway() { |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 net::HttpRequestHeaders::kUserAgent, | 541 net::HttpRequestHeaders::kUserAgent, |
| 530 user_agent_override.c_str()); | 542 user_agent_override.c_str()); |
| 531 } | 543 } |
| 532 channel_->SendAddChannelRequest(socket_url, requested_protocols, origin, | 544 channel_->SendAddChannelRequest(socket_url, requested_protocols, origin, |
| 533 first_party_for_cookies, additional_headers); | 545 first_party_for_cookies, additional_headers); |
| 534 if (quota > 0) | 546 if (quota > 0) |
| 535 SendFlowControl(quota); | 547 SendFlowControl(quota); |
| 536 } | 548 } |
| 537 | 549 |
| 538 } // namespace content | 550 } // namespace content |
| OLD | NEW |