Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1887)

Side by Side Diff: content/browser/renderer_host/websocket_host.cc

Issue 1459473003: Add a WebContents getter callback in ResourceRequestInfo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/single_thread_task_runner.h" 10 #include "base/single_thread_task_runner.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/thread_task_runner_handle.h" 12 #include "base/thread_task_runner_handle.h"
13 #include "content/browser/renderer_host/websocket_dispatcher_host.h" 13 #include "content/browser/renderer_host/websocket_dispatcher_host.h"
14 #include "content/browser/ssl/ssl_error_handler.h" 14 #include "content/browser/ssl/ssl_error_handler.h"
15 #include "content/browser/ssl/ssl_manager.h" 15 #include "content/browser/ssl/ssl_manager.h"
16 #include "content/common/websocket_messages.h" 16 #include "content/common/websocket_messages.h"
17 #include "content/public/browser/render_frame_host.h"
17 #include "ipc/ipc_message_macros.h" 18 #include "ipc/ipc_message_macros.h"
18 #include "net/http/http_request_headers.h" 19 #include "net/http/http_request_headers.h"
19 #include "net/http/http_response_headers.h" 20 #include "net/http/http_response_headers.h"
20 #include "net/http/http_util.h" 21 #include "net/http/http_util.h"
21 #include "net/ssl/ssl_info.h" 22 #include "net/ssl/ssl_info.h"
22 #include "net/websockets/websocket_channel.h" 23 #include "net/websockets/websocket_channel.h"
23 #include "net/websockets/websocket_errors.h" 24 #include "net/websockets/websocket_errors.h"
24 #include "net/websockets/websocket_event_interface.h" 25 #include "net/websockets/websocket_event_interface.h"
25 #include "net/websockets/websocket_frame.h" // for WebSocketFrameHeader::OpCode 26 #include "net/websockets/websocket_frame.h" // for WebSocketFrameHeader::OpCode
26 #include "net/websockets/websocket_handshake_request_info.h" 27 #include "net/websockets/websocket_handshake_request_info.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 // for the conversion. 77 // for the conversion.
77 static_assert(static_cast<ChannelState>(WEBSOCKET_HOST_ALIVE) == 78 static_assert(static_cast<ChannelState>(WEBSOCKET_HOST_ALIVE) ==
78 net::WebSocketEventInterface::CHANNEL_ALIVE, 79 net::WebSocketEventInterface::CHANNEL_ALIVE,
79 "enum values must match for state_alive"); 80 "enum values must match for state_alive");
80 static_assert(static_cast<ChannelState>(WEBSOCKET_HOST_DELETED) == 81 static_assert(static_cast<ChannelState>(WEBSOCKET_HOST_DELETED) ==
81 net::WebSocketEventInterface::CHANNEL_DELETED, 82 net::WebSocketEventInterface::CHANNEL_DELETED,
82 "enum values must match for state_deleted"); 83 "enum values must match for state_deleted");
83 return static_cast<ChannelState>(host_state); 84 return static_cast<ChannelState>(host_state);
84 } 85 }
85 86
87 WebContents* GetWebContentsFromRFHID(int render_process_id,
88 int render_frame_id) {
89 DCHECK_CURRENTLY_ON(BrowserThread::UI);
90 RenderFrameHost* render_frame_host =
91 RenderFrameHost::FromID(render_process_id, render_frame_id);
92 if (!render_frame_host)
93 return nullptr;
94
95 return WebContents::FromRenderFrameHost(render_frame_host);
96 }
97
86 // Implementation of net::WebSocketEventInterface. Receives events from our 98 // Implementation of net::WebSocketEventInterface. Receives events from our
87 // WebSocketChannel object. Each event is translated to an IPC and sent to the 99 // WebSocketChannel object. Each event is translated to an IPC and sent to the
88 // renderer or child process via WebSocketDispatcherHost. 100 // renderer or child process via WebSocketDispatcherHost.
89 class WebSocketEventHandler : public net::WebSocketEventInterface { 101 class WebSocketEventHandler : public net::WebSocketEventInterface {
90 public: 102 public:
91 WebSocketEventHandler(WebSocketDispatcherHost* dispatcher, 103 WebSocketEventHandler(WebSocketDispatcherHost* dispatcher,
92 int routing_id, 104 int routing_id,
93 int render_frame_id); 105 int render_frame_id);
94 ~WebSocketEventHandler() override; 106 ~WebSocketEventHandler() override;
95 107
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 ChannelState WebSocketEventHandler::OnSSLCertificateError( 279 ChannelState WebSocketEventHandler::OnSSLCertificateError(
268 scoped_ptr<net::WebSocketEventInterface::SSLErrorCallbacks> callbacks, 280 scoped_ptr<net::WebSocketEventInterface::SSLErrorCallbacks> callbacks,
269 const GURL& url, 281 const GURL& url,
270 const net::SSLInfo& ssl_info, 282 const net::SSLInfo& ssl_info,
271 bool fatal) { 283 bool fatal) {
272 DVLOG(3) << "WebSocketEventHandler::OnSSLCertificateError" 284 DVLOG(3) << "WebSocketEventHandler::OnSSLCertificateError"
273 << " routing_id=" << routing_id_ << " url=" << url.spec() 285 << " routing_id=" << routing_id_ << " url=" << url.spec()
274 << " cert_status=" << ssl_info.cert_status << " fatal=" << fatal; 286 << " cert_status=" << ssl_info.cert_status << " fatal=" << fatal;
275 ssl_error_handler_delegate_.reset( 287 ssl_error_handler_delegate_.reset(
276 new SSLErrorHandlerDelegate(callbacks.Pass())); 288 new SSLErrorHandlerDelegate(callbacks.Pass()));
277 SSLManager::OnSSLCertificateError(ssl_error_handler_delegate_->GetWeakPtr(), 289 SSLManager::OnSSLCertificateError(
278 RESOURCE_TYPE_SUB_RESOURCE, 290 ssl_error_handler_delegate_->GetWeakPtr(), RESOURCE_TYPE_SUB_RESOURCE,
279 url, 291 url, base::Bind(&GetWebContentsFromRFHID,
280 dispatcher_->render_process_id(), 292 dispatcher_->render_process_id(), render_frame_id_),
281 render_frame_id_, 293 ssl_info, fatal);
282 ssl_info,
283 fatal);
284 // The above method is always asynchronous. 294 // The above method is always asynchronous.
285 return WebSocketEventInterface::CHANNEL_ALIVE; 295 return WebSocketEventInterface::CHANNEL_ALIVE;
286 } 296 }
287 297
288 WebSocketEventHandler::SSLErrorHandlerDelegate::SSLErrorHandlerDelegate( 298 WebSocketEventHandler::SSLErrorHandlerDelegate::SSLErrorHandlerDelegate(
289 scoped_ptr<net::WebSocketEventInterface::SSLErrorCallbacks> callbacks) 299 scoped_ptr<net::WebSocketEventInterface::SSLErrorCallbacks> callbacks)
290 : callbacks_(callbacks.Pass()), weak_ptr_factory_(this) {} 300 : callbacks_(callbacks.Pass()), weak_ptr_factory_(this) {}
291 301
292 WebSocketEventHandler::SSLErrorHandlerDelegate::~SSLErrorHandlerDelegate() {} 302 WebSocketEventHandler::SSLErrorHandlerDelegate::~SSLErrorHandlerDelegate() {}
293 303
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 ""); 457 "");
448 DCHECK_EQ(WebSocketDispatcherHost::WEBSOCKET_HOST_DELETED, result); 458 DCHECK_EQ(WebSocketDispatcherHost::WEBSOCKET_HOST_DELETED, result);
449 return; 459 return;
450 } 460 }
451 461
452 // TODO(yhirano): Handle |was_clean| appropriately. 462 // TODO(yhirano): Handle |was_clean| appropriately.
453 channel_->StartClosingHandshake(code, reason); 463 channel_->StartClosingHandshake(code, reason);
454 } 464 }
455 465
456 } // namespace content 466 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698