Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/renderer_host/media/dtls_identity_service_host.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "content/common/media/dtls_identity_messages.h" | |
| 9 #include "content/public/browser/render_process_host.h" | |
| 10 #include "net/base/net_errors.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 DTLSIdentityServiceHost::DTLSIdentityServiceHost( | |
| 15 DTLSIdentityStore* dtls_identity_store) | |
| 16 : dtls_identity_store_(dtls_identity_store) {} | |
| 17 | |
| 18 DTLSIdentityServiceHost::~DTLSIdentityServiceHost() { | |
| 19 RequestCancelCallbackMap::iterator it; | |
| 20 for (it = pending_request_cancel_callback_map_.begin(); | |
| 21 it != pending_request_cancel_callback_map_.end(); | |
| 22 ++it) { | |
| 23 it->second.Run(); | |
| 24 } | |
| 25 } | |
| 26 | |
| 27 bool DTLSIdentityServiceHost::OnMessageReceived(const IPC::Message& message, | |
| 28 bool* message_was_ok) { | |
| 29 bool handled = true; | |
| 30 IPC_BEGIN_MESSAGE_MAP_EX(DTLSIdentityServiceHost, message, *message_was_ok) | |
| 31 IPC_MESSAGE_HANDLER(DTLSIdentityMsg_RequestIdentity, OnRequestIdentity) | |
| 32 IPC_MESSAGE_HANDLER(DTLSIdentityMsg_CancelRequest, OnCancelRequest) | |
| 33 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 34 IPC_END_MESSAGE_MAP_EX() | |
| 35 return handled; | |
| 36 } | |
| 37 | |
| 38 void DTLSIdentityServiceHost::OnRequestIdentity( | |
| 39 int request_id, | |
| 40 const GURL& origin, | |
| 41 const std::string& identity_name, | |
| 42 const std::string& common_name) { | |
| 43 DCHECK(pending_request_cancel_callback_map_.end() == | |
| 44 pending_request_cancel_callback_map_.find(request_id)); | |
| 45 | |
| 46 base::Closure cancel_callback; | |
| 47 bool success = dtls_identity_store_->RequestIdentity( | |
| 48 origin, | |
| 49 identity_name, | |
| 50 common_name, | |
| 51 base::Bind(&DTLSIdentityServiceHost::OnComplete, | |
| 52 base::Unretained(this), | |
| 53 request_id), | |
| 54 &cancel_callback); | |
| 55 if (success) | |
| 56 pending_request_cancel_callback_map_[request_id] = cancel_callback; | |
|
Ryan Sleevi
2013/06/24 23:27:07
As mentioned via e-mail, a hostile renderer could
jiayl
2013/06/25 20:36:32
Changed the DCHECK to if-return.
On 2013/06/24 23:
| |
| 57 else | |
| 58 OnComplete(request_id, net::ERR_UNEXPECTED, std::string(), std::string()); | |
| 59 } | |
| 60 | |
| 61 void DTLSIdentityServiceHost::OnCancelRequest(int request_id) { | |
| 62 DCHECK(pending_request_cancel_callback_map_.find(request_id) != | |
| 63 pending_request_cancel_callback_map_.end()); | |
| 64 pending_request_cancel_callback_map_[request_id].Run(); | |
|
Ryan Sleevi
2013/06/24 23:27:07
If |request_id| is not a valid request, this will
jiayl
2013/06/25 20:36:32
Changed the DCHECK to if-return
On 2013/06/24 23:2
| |
| 65 pending_request_cancel_callback_map_.erase(request_id); | |
| 66 } | |
|
Ryan Sleevi
2013/06/24 19:29:16
It still seems to me that you're trusting the rend
jiayl
2013/06/25 20:36:32
Rate limiting is added to WebRTCIdentityServiceHos
| |
| 67 | |
| 68 void DTLSIdentityServiceHost::OnComplete(int request_id, | |
| 69 int error, | |
| 70 const std::string& certificate, | |
| 71 const std::string& private_key) { | |
| 72 DCHECK(pending_request_cancel_callback_map_.find(request_id) != | |
| 73 pending_request_cancel_callback_map_.end()); | |
| 74 pending_request_cancel_callback_map_.erase(request_id); | |
| 75 if (error == net::OK) { | |
| 76 Send(new DTLSIdentityHostMsg_IdentityReady( | |
| 77 request_id, certificate, private_key)); | |
| 78 } else { | |
| 79 Send(new DTLSIdentityHostMsg_RequestFailed(request_id, error)); | |
| 80 } | |
| 81 } | |
| 82 | |
| 83 } // namespace content | |
| OLD | NEW |