OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/ui/android/ssl_client_certificate_request.h" | 5 #include "chrome/browser/ui/android/ssl_client_certificate_request.h" |
6 | 6 |
7 #include "base/android/jni_array.h" | 7 #include "base/android/jni_array.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 // |request_id| is the id passed to | 114 // |request_id| is the id passed to |
115 // Java_SSLClientCertificateRequest_selectClientCertificate() in Start(). | 115 // Java_SSLClientCertificateRequest_selectClientCertificate() in Start(). |
116 // |encoded_chain_ref| is a JNI reference to a Java array of byte arrays, | 116 // |encoded_chain_ref| is a JNI reference to a Java array of byte arrays, |
117 // each item holding a DER-encoded X.509 certificate. | 117 // each item holding a DER-encoded X.509 certificate. |
118 // |private_key_ref| is the platform PrivateKey object JNI reference for | 118 // |private_key_ref| is the platform PrivateKey object JNI reference for |
119 // the client certificate. | 119 // the client certificate. |
120 // Note: both |encoded_chain_ref| and |private_key_ref| will be NULL if | 120 // Note: both |encoded_chain_ref| and |private_key_ref| will be NULL if |
121 // the user didn't select a certificate. | 121 // the user didn't select a certificate. |
122 static void OnSystemRequestCompletion( | 122 static void OnSystemRequestCompletion( |
123 JNIEnv* env, | 123 JNIEnv* env, |
124 jclass clazz, | 124 const JavaParamRef<jclass>& clazz, |
125 jlong request_id, | 125 jlong request_id, |
126 jobjectArray encoded_chain_ref, | 126 const JavaParamRef<jobjectArray>& encoded_chain_ref, |
127 jobject private_key_ref) { | 127 const JavaParamRef<jobject>& private_key_ref) { |
128 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 128 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
129 | 129 |
130 // Take back ownership of the delegate object. | 130 // Take back ownership of the delegate object. |
131 scoped_ptr<content::ClientCertificateDelegate> delegate( | 131 scoped_ptr<content::ClientCertificateDelegate> delegate( |
132 reinterpret_cast<content::ClientCertificateDelegate*>(request_id)); | 132 reinterpret_cast<content::ClientCertificateDelegate*>(request_id)); |
133 | 133 |
134 if (encoded_chain_ref == NULL || private_key_ref == NULL) { | 134 if (encoded_chain_ref == NULL || private_key_ref == NULL) { |
135 LOG(ERROR) << "No client certificate selected"; | 135 LOG(ERROR) << "No client certificate selected"; |
136 delegate->ContinueWithCertificate(nullptr); | 136 delegate->ContinueWithCertificate(nullptr); |
137 return; | 137 return; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 base::Bind(&RecordClientCertificateKey, client_cert, | 172 base::Bind(&RecordClientCertificateKey, client_cert, |
173 base::Passed(&private_key)), | 173 base::Passed(&private_key)), |
174 base::Bind(&content::ClientCertificateDelegate::ContinueWithCertificate, | 174 base::Bind(&content::ClientCertificateDelegate::ContinueWithCertificate, |
175 base::Owned(delegate.release()), client_cert)); | 175 base::Owned(delegate.release()), client_cert)); |
176 } | 176 } |
177 | 177 |
178 static void NotifyClientCertificatesChanged() { | 178 static void NotifyClientCertificatesChanged() { |
179 net::CertDatabase::GetInstance()->OnAndroidKeyStoreChanged(); | 179 net::CertDatabase::GetInstance()->OnAndroidKeyStoreChanged(); |
180 } | 180 } |
181 | 181 |
182 static void NotifyClientCertificatesChangedOnIOThread(JNIEnv* env, jclass) { | 182 static void NotifyClientCertificatesChangedOnIOThread( |
| 183 JNIEnv* env, |
| 184 const JavaParamRef<jclass>&) { |
183 if (content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { | 185 if (content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)) { |
184 NotifyClientCertificatesChanged(); | 186 NotifyClientCertificatesChanged(); |
185 } else { | 187 } else { |
186 content::BrowserThread::PostTask( | 188 content::BrowserThread::PostTask( |
187 content::BrowserThread::IO, | 189 content::BrowserThread::IO, |
188 FROM_HERE, | 190 FROM_HERE, |
189 base::Bind(&NotifyClientCertificatesChanged)); | 191 base::Bind(&NotifyClientCertificatesChanged)); |
190 } | 192 } |
191 } | 193 } |
192 | 194 |
193 bool RegisterSSLClientCertificateRequestAndroid(JNIEnv* env) { | 195 bool RegisterSSLClientCertificateRequestAndroid(JNIEnv* env) { |
194 return RegisterNativesImpl(env); | 196 return RegisterNativesImpl(env); |
195 } | 197 } |
196 | 198 |
197 } // namespace android | 199 } // namespace android |
198 | 200 |
199 void ShowSSLClientCertificateSelector( | 201 void ShowSSLClientCertificateSelector( |
200 content::WebContents* contents, | 202 content::WebContents* contents, |
201 net::SSLCertRequestInfo* cert_request_info, | 203 net::SSLCertRequestInfo* cert_request_info, |
202 scoped_ptr<content::ClientCertificateDelegate> delegate) { | 204 scoped_ptr<content::ClientCertificateDelegate> delegate) { |
203 ui::WindowAndroid* window = | 205 ui::WindowAndroid* window = |
204 WindowAndroidHelper::FromWebContents(contents)->GetWindowAndroid(); | 206 WindowAndroidHelper::FromWebContents(contents)->GetWindowAndroid(); |
205 DCHECK(window); | 207 DCHECK(window); |
206 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 208 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
207 StartClientCertificateRequest(cert_request_info, window, delegate.Pass()); | 209 StartClientCertificateRequest(cert_request_info, window, delegate.Pass()); |
208 } | 210 } |
209 | 211 |
210 } // namespace chrome | 212 } // namespace chrome |
OLD | NEW |