OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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/renderer/media/rtc_certificate_generator.h" | 5 #include "content/renderer/media/rtc_certificate_generator.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" |
11 #include "content/renderer/media/peer_connection_identity_store.h" | 12 #include "content/renderer/media/peer_connection_identity_store.h" |
12 #include "content/renderer/media/rtc_certificate.h" | 13 #include "content/renderer/media/rtc_certificate.h" |
13 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" | 14 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" |
14 #include "content/renderer/render_thread_impl.h" | 15 #include "content/renderer/render_thread_impl.h" |
15 #include "third_party/webrtc/base/rtccertificate.h" | 16 #include "third_party/webrtc/base/rtccertificate.h" |
16 #include "third_party/webrtc/base/scoped_ref_ptr.h" | 17 #include "third_party/webrtc/base/scoped_ref_ptr.h" |
17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
18 | 19 |
19 namespace content { | 20 namespace content { |
20 namespace { | 21 namespace { |
(...skipping 28 matching lines...) Expand all Loading... |
49 } | 50 } |
50 ~RTCCertificateIdentityObserver() override {} | 51 ~RTCCertificateIdentityObserver() override {} |
51 | 52 |
52 // Perform |store|->RequestIdentity with this identity observer and ensure | 53 // Perform |store|->RequestIdentity with this identity observer and ensure |
53 // that this identity observer is not deleted until the request has completed | 54 // that this identity observer is not deleted until the request has completed |
54 // by holding on to a reference to itself for the duration of the request. | 55 // by holding on to a reference to itself for the duration of the request. |
55 void RequestIdentity( | 56 void RequestIdentity( |
56 const blink::WebRTCKeyParams& key_params, | 57 const blink::WebRTCKeyParams& key_params, |
57 const GURL& url, | 58 const GURL& url, |
58 const GURL& first_party_for_cookies, | 59 const GURL& first_party_for_cookies, |
59 blink::WebPassOwnPtr<blink::WebRTCCertificateCallback> observer) { | 60 std::unique_ptr<blink::WebRTCCertificateCallback> observer) { |
60 DCHECK(main_thread_->BelongsToCurrentThread()); | 61 DCHECK(main_thread_->BelongsToCurrentThread()); |
61 DCHECK(!observer_) << "Already have a RequestIdentity in progress."; | 62 DCHECK(!observer_) << "Already have a RequestIdentity in progress."; |
62 key_params_ = key_params; | 63 key_params_ = key_params; |
63 observer_ = observer; | 64 observer_ = std::move(observer); |
64 DCHECK(observer_); | 65 DCHECK(observer_); |
65 // Identity request must be performed on the WebRTC signaling thread. | 66 // Identity request must be performed on the WebRTC signaling thread. |
66 signaling_thread_->PostTask(FROM_HERE, base::Bind( | 67 signaling_thread_->PostTask(FROM_HERE, base::Bind( |
67 &RTCCertificateIdentityObserver::RequestIdentityOnWebRtcSignalingThread, | 68 &RTCCertificateIdentityObserver::RequestIdentityOnWebRtcSignalingThread, |
68 this, url, first_party_for_cookies)); | 69 this, url, first_party_for_cookies)); |
69 } | 70 } |
70 | 71 |
71 private: | 72 private: |
72 void RequestIdentityOnWebRtcSignalingThread( | 73 void RequestIdentityOnWebRtcSignalingThread( |
73 GURL url, | 74 GURL url, |
(...skipping 26 matching lines...) Expand all Loading... |
100 reinterpret_cast<const unsigned char*>(der_private_key.data()), | 101 reinterpret_cast<const unsigned char*>(der_private_key.data()), |
101 der_private_key.length()); | 102 der_private_key.length()); |
102 OnSuccess(rtc::scoped_ptr<rtc::SSLIdentity>( | 103 OnSuccess(rtc::scoped_ptr<rtc::SSLIdentity>( |
103 rtc::SSLIdentity::FromPEMStrings(pem_key, pem_cert))); | 104 rtc::SSLIdentity::FromPEMStrings(pem_key, pem_cert))); |
104 } | 105 } |
105 void OnSuccess(rtc::scoped_ptr<rtc::SSLIdentity> identity) override { | 106 void OnSuccess(rtc::scoped_ptr<rtc::SSLIdentity> identity) override { |
106 DCHECK(signaling_thread_->BelongsToCurrentThread()); | 107 DCHECK(signaling_thread_->BelongsToCurrentThread()); |
107 DCHECK(observer_); | 108 DCHECK(observer_); |
108 rtc::scoped_refptr<rtc::RTCCertificate> certificate = | 109 rtc::scoped_refptr<rtc::RTCCertificate> certificate = |
109 rtc::RTCCertificate::Create(std::move(identity)); | 110 rtc::RTCCertificate::Create(std::move(identity)); |
110 main_thread_->PostTask(FROM_HERE, base::Bind( | 111 main_thread_->PostTask( |
111 &RTCCertificateIdentityObserver::DoCallbackOnMainThread, | 112 FROM_HERE, |
112 this, new RTCCertificate(key_params_, certificate))); | 113 base::Bind(&RTCCertificateIdentityObserver::DoCallbackOnMainThread, |
| 114 this, base::Passed(base::WrapUnique( |
| 115 new RTCCertificate(key_params_, certificate))))); |
113 } | 116 } |
114 | 117 |
115 void DoCallbackOnMainThread(blink::WebRTCCertificate* certificate) { | 118 void DoCallbackOnMainThread( |
| 119 std::unique_ptr<blink::WebRTCCertificate> certificate) { |
116 DCHECK(main_thread_->BelongsToCurrentThread()); | 120 DCHECK(main_thread_->BelongsToCurrentThread()); |
117 DCHECK(observer_); | 121 DCHECK(observer_); |
118 if (certificate) | 122 if (certificate) |
119 observer_->onSuccess(blink::adoptWebPtr(certificate)); | 123 observer_->onSuccess(std::move(certificate)); |
120 else | 124 else |
121 observer_->onError(); | 125 observer_->onError(); |
122 observer_.reset(); | 126 observer_.reset(); |
123 } | 127 } |
124 | 128 |
125 // The main thread is the renderer thread. | 129 // The main thread is the renderer thread. |
126 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_; | 130 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_; |
127 // The signaling thread is a WebRTC thread used to invoke | 131 // The signaling thread is a WebRTC thread used to invoke |
128 // PeerConnectionIdentityStore::RequestIdentity on, as is required. | 132 // PeerConnectionIdentityStore::RequestIdentity on, as is required. |
129 const scoped_refptr<base::SingleThreadTaskRunner> signaling_thread_; | 133 const scoped_refptr<base::SingleThreadTaskRunner> signaling_thread_; |
130 blink::WebRTCKeyParams key_params_; | 134 blink::WebRTCKeyParams key_params_; |
131 scoped_ptr<blink::WebRTCCertificateCallback> observer_; | 135 scoped_ptr<blink::WebRTCCertificateCallback> observer_; |
132 | 136 |
133 DISALLOW_COPY_AND_ASSIGN(RTCCertificateIdentityObserver); | 137 DISALLOW_COPY_AND_ASSIGN(RTCCertificateIdentityObserver); |
134 }; | 138 }; |
135 | 139 |
136 } // namespace | 140 } // namespace |
137 | 141 |
138 void RTCCertificateGenerator::generateCertificate( | 142 void RTCCertificateGenerator::generateCertificate( |
139 const blink::WebRTCKeyParams& key_params, | 143 const blink::WebRTCKeyParams& key_params, |
140 const blink::WebURL& url, | 144 const blink::WebURL& url, |
141 const blink::WebURL& first_party_for_cookies, | 145 const blink::WebURL& first_party_for_cookies, |
142 blink::WebPassOwnPtr<blink::WebRTCCertificateCallback> observer) { | 146 std::unique_ptr<blink::WebRTCCertificateCallback> observer) { |
143 DCHECK(isSupportedKeyParams(key_params)); | 147 DCHECK(isSupportedKeyParams(key_params)); |
144 | 148 |
145 #if defined(ENABLE_WEBRTC) | 149 #if defined(ENABLE_WEBRTC) |
146 const scoped_refptr<base::SingleThreadTaskRunner> main_thread = | 150 const scoped_refptr<base::SingleThreadTaskRunner> main_thread = |
147 base::ThreadTaskRunnerHandle::Get(); | 151 base::ThreadTaskRunnerHandle::Get(); |
148 | 152 |
149 PeerConnectionDependencyFactory* pc_dependency_factory = | 153 PeerConnectionDependencyFactory* pc_dependency_factory = |
150 RenderThreadImpl::current()->GetPeerConnectionDependencyFactory(); | 154 RenderThreadImpl::current()->GetPeerConnectionDependencyFactory(); |
151 pc_dependency_factory->EnsureInitialized(); | 155 pc_dependency_factory->EnsureInitialized(); |
152 const scoped_refptr<base::SingleThreadTaskRunner> signaling_thread = | 156 const scoped_refptr<base::SingleThreadTaskRunner> signaling_thread = |
153 pc_dependency_factory->GetWebRtcSignalingThread(); | 157 pc_dependency_factory->GetWebRtcSignalingThread(); |
154 | 158 |
155 rtc::scoped_refptr<RTCCertificateIdentityObserver> identity_observer( | 159 rtc::scoped_refptr<RTCCertificateIdentityObserver> identity_observer( |
156 new rtc::RefCountedObject<RTCCertificateIdentityObserver>( | 160 new rtc::RefCountedObject<RTCCertificateIdentityObserver>( |
157 main_thread, signaling_thread)); | 161 main_thread, signaling_thread)); |
158 // |identity_observer| lives until request has completed. | 162 // |identity_observer| lives until request has completed. |
159 identity_observer->RequestIdentity( | 163 identity_observer->RequestIdentity(key_params, url, first_party_for_cookies, |
160 key_params, url, first_party_for_cookies, observer); | 164 std::move(observer)); |
161 #else | 165 #else |
162 observer->onError(); | 166 observer->onError(); |
163 #endif | 167 #endif |
164 } | 168 } |
165 | 169 |
166 bool RTCCertificateGenerator::isSupportedKeyParams( | 170 bool RTCCertificateGenerator::isSupportedKeyParams( |
167 const blink::WebRTCKeyParams& key_params) { | 171 const blink::WebRTCKeyParams& key_params) { |
168 return WebRTCKeyParamsToKeyParams(key_params).IsValid(); | 172 return WebRTCKeyParamsToKeyParams(key_params).IsValid(); |
169 } | 173 } |
170 | 174 |
171 } // namespace content | 175 } // namespace content |
OLD | NEW |