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" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 } | 50 } |
51 ~RTCCertificateIdentityObserver() override {} | 51 ~RTCCertificateIdentityObserver() override {} |
52 | 52 |
53 // Perform |store|->RequestIdentity with this identity observer and ensure | 53 // Perform |store|->RequestIdentity with this identity observer and ensure |
54 // 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 |
55 // 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. |
56 void RequestIdentity( | 56 void RequestIdentity( |
57 const blink::WebRTCKeyParams& key_params, | 57 const blink::WebRTCKeyParams& key_params, |
58 const GURL& url, | 58 const GURL& url, |
59 const GURL& first_party_for_cookies, | 59 const GURL& first_party_for_cookies, |
| 60 const rtc::Optional<uint64_t>& expires_ms, |
60 std::unique_ptr<blink::WebRTCCertificateCallback> observer) { | 61 std::unique_ptr<blink::WebRTCCertificateCallback> observer) { |
61 DCHECK(main_thread_->BelongsToCurrentThread()); | 62 DCHECK(main_thread_->BelongsToCurrentThread()); |
62 DCHECK(!observer_) << "Already have a RequestIdentity in progress."; | 63 DCHECK(!observer_) << "Already have a RequestIdentity in progress."; |
63 key_params_ = key_params; | 64 key_params_ = key_params; |
64 observer_ = std::move(observer); | 65 observer_ = std::move(observer); |
65 DCHECK(observer_); | 66 DCHECK(observer_); |
66 // Identity request must be performed on the WebRTC signaling thread. | 67 // Identity request must be performed on the WebRTC signaling thread. |
67 signaling_thread_->PostTask(FROM_HERE, base::Bind( | 68 signaling_thread_->PostTask(FROM_HERE, base::Bind( |
68 &RTCCertificateIdentityObserver::RequestIdentityOnWebRtcSignalingThread, | 69 &RTCCertificateIdentityObserver::RequestIdentityOnWebRtcSignalingThread, |
69 this, url, first_party_for_cookies)); | 70 this, url, first_party_for_cookies, expires_ms)); |
70 } | 71 } |
71 | 72 |
72 private: | 73 private: |
73 void RequestIdentityOnWebRtcSignalingThread( | 74 void RequestIdentityOnWebRtcSignalingThread( |
74 GURL url, | 75 GURL url, |
75 GURL first_party_for_cookies) { | 76 GURL first_party_for_cookies, |
| 77 rtc::Optional<uint64_t> expires_ms) { |
76 DCHECK(signaling_thread_->BelongsToCurrentThread()); | 78 DCHECK(signaling_thread_->BelongsToCurrentThread()); |
77 rtc::scoped_ptr<PeerConnectionIdentityStore> store( | 79 rtc::scoped_ptr<PeerConnectionIdentityStore> store( |
78 new PeerConnectionIdentityStore(main_thread_, signaling_thread_, url, | 80 new PeerConnectionIdentityStore(main_thread_, signaling_thread_, url, |
79 first_party_for_cookies)); | 81 first_party_for_cookies)); |
80 // Request identity with |this| as the observer. OnSuccess/OnFailure will be | 82 // Request identity with |this| as the observer. OnSuccess/OnFailure will be |
81 // called asynchronously. | 83 // called asynchronously. |
82 store->RequestIdentity(WebRTCKeyParamsToKeyParams(key_params_), this); | 84 store->RequestIdentity(WebRTCKeyParamsToKeyParams(key_params_), |
| 85 expires_ms, this); |
83 } | 86 } |
84 | 87 |
85 // webrtc::DtlsIdentityRequestObserver implementation. | 88 // webrtc::DtlsIdentityRequestObserver implementation. |
86 void OnFailure(int error) override { | 89 void OnFailure(int error) override { |
87 DCHECK(signaling_thread_->BelongsToCurrentThread()); | 90 DCHECK(signaling_thread_->BelongsToCurrentThread()); |
88 DCHECK(observer_); | 91 DCHECK(observer_); |
89 main_thread_->PostTask(FROM_HERE, base::Bind( | 92 main_thread_->PostTask(FROM_HERE, base::Bind( |
90 &RTCCertificateIdentityObserver::DoCallbackOnMainThread, | 93 &RTCCertificateIdentityObserver::DoCallbackOnMainThread, |
91 this, nullptr)); | 94 this, nullptr)); |
92 } | 95 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 DISALLOW_COPY_AND_ASSIGN(RTCCertificateIdentityObserver); | 140 DISALLOW_COPY_AND_ASSIGN(RTCCertificateIdentityObserver); |
138 }; | 141 }; |
139 | 142 |
140 } // namespace | 143 } // namespace |
141 | 144 |
142 void RTCCertificateGenerator::generateCertificate( | 145 void RTCCertificateGenerator::generateCertificate( |
143 const blink::WebRTCKeyParams& key_params, | 146 const blink::WebRTCKeyParams& key_params, |
144 const blink::WebURL& url, | 147 const blink::WebURL& url, |
145 const blink::WebURL& first_party_for_cookies, | 148 const blink::WebURL& first_party_for_cookies, |
146 std::unique_ptr<blink::WebRTCCertificateCallback> observer) { | 149 std::unique_ptr<blink::WebRTCCertificateCallback> observer) { |
| 150 generateCertificateWithOptionalExpiration( |
| 151 key_params, url, first_party_for_cookies, rtc::Optional<uint64_t>(), |
| 152 std::move(observer)); |
| 153 } |
| 154 |
| 155 void RTCCertificateGenerator::generateCertificateWithExpiration( |
| 156 const blink::WebRTCKeyParams& key_params, |
| 157 const blink::WebURL& url, |
| 158 const blink::WebURL& first_party_for_cookies, |
| 159 uint64_t expires_ms, |
| 160 std::unique_ptr<blink::WebRTCCertificateCallback> observer) { |
| 161 generateCertificateWithOptionalExpiration( |
| 162 key_params, url, first_party_for_cookies, |
| 163 rtc::Optional<uint64_t>(expires_ms), std::move(observer)); |
| 164 } |
| 165 |
| 166 void RTCCertificateGenerator::generateCertificateWithOptionalExpiration( |
| 167 const blink::WebRTCKeyParams& key_params, |
| 168 const blink::WebURL& url, |
| 169 const blink::WebURL& first_party_for_cookies, |
| 170 const rtc::Optional<uint64_t>& expires_ms, |
| 171 std::unique_ptr<blink::WebRTCCertificateCallback> observer) { |
147 DCHECK(isSupportedKeyParams(key_params)); | 172 DCHECK(isSupportedKeyParams(key_params)); |
148 | 173 |
149 #if defined(ENABLE_WEBRTC) | 174 #if defined(ENABLE_WEBRTC) |
150 const scoped_refptr<base::SingleThreadTaskRunner> main_thread = | 175 const scoped_refptr<base::SingleThreadTaskRunner> main_thread = |
151 base::ThreadTaskRunnerHandle::Get(); | 176 base::ThreadTaskRunnerHandle::Get(); |
152 | 177 |
153 PeerConnectionDependencyFactory* pc_dependency_factory = | 178 PeerConnectionDependencyFactory* pc_dependency_factory = |
154 RenderThreadImpl::current()->GetPeerConnectionDependencyFactory(); | 179 RenderThreadImpl::current()->GetPeerConnectionDependencyFactory(); |
155 pc_dependency_factory->EnsureInitialized(); | 180 pc_dependency_factory->EnsureInitialized(); |
156 const scoped_refptr<base::SingleThreadTaskRunner> signaling_thread = | 181 const scoped_refptr<base::SingleThreadTaskRunner> signaling_thread = |
157 pc_dependency_factory->GetWebRtcSignalingThread(); | 182 pc_dependency_factory->GetWebRtcSignalingThread(); |
158 | 183 |
159 rtc::scoped_refptr<RTCCertificateIdentityObserver> identity_observer( | 184 rtc::scoped_refptr<RTCCertificateIdentityObserver> identity_observer( |
160 new rtc::RefCountedObject<RTCCertificateIdentityObserver>( | 185 new rtc::RefCountedObject<RTCCertificateIdentityObserver>( |
161 main_thread, signaling_thread)); | 186 main_thread, signaling_thread)); |
162 // |identity_observer| lives until request has completed. | 187 // |identity_observer| lives until request has completed. |
163 identity_observer->RequestIdentity(key_params, url, first_party_for_cookies, | 188 identity_observer->RequestIdentity(key_params, url, first_party_for_cookies, |
164 std::move(observer)); | 189 expires_ms, std::move(observer)); |
165 #else | 190 #else |
166 observer->onError(); | 191 observer->onError(); |
167 #endif | 192 #endif |
168 } | 193 } |
169 | 194 |
170 bool RTCCertificateGenerator::isSupportedKeyParams( | 195 bool RTCCertificateGenerator::isSupportedKeyParams( |
171 const blink::WebRTCKeyParams& key_params) { | 196 const blink::WebRTCKeyParams& key_params) { |
172 return WebRTCKeyParamsToKeyParams(key_params).IsValid(); | 197 return WebRTCKeyParamsToKeyParams(key_params).IsValid(); |
173 } | 198 } |
174 | 199 |
175 } // namespace content | 200 } // namespace content |
OLD | NEW |