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

Side by Side Diff: chrome/browser/ui/android/ssl_client_certificate_request.cc

Issue 159173002: Refactor ActivityStatus to not store current activity (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed Comments Created 6 years, 10 months 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 | Annotate | Revision Log
OLDNEW
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"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "chrome/browser/ssl/ssl_client_certificate_selector.h" 15 #include "chrome/browser/ssl/ssl_client_certificate_selector.h"
16 #include "chrome/browser/ui/android/window_android_helper.h"
16 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
17 #include "jni/SSLClientCertificateRequest_jni.h" 18 #include "jni/SSLClientCertificateRequest_jni.h"
18 #include "net/android/keystore_openssl.h" 19 #include "net/android/keystore_openssl.h"
19 #include "net/base/host_port_pair.h" 20 #include "net/base/host_port_pair.h"
20 #include "net/cert/x509_certificate.h" 21 #include "net/cert/x509_certificate.h"
21 #include "net/ssl/openssl_client_key_store.h" 22 #include "net/ssl/openssl_client_key_store.h"
22 #include "net/ssl/ssl_cert_request_info.h" 23 #include "net/ssl/ssl_cert_request_info.h"
23 #include "net/ssl/ssl_client_cert_type.h" 24 #include "net/ssl/ssl_client_cert_type.h"
25 #include "ui/base/android/window_android.h"
24 26
25 namespace chrome { 27 namespace chrome {
26 28
27 namespace { 29 namespace {
28 30
29 typedef net::OpenSSLClientKeyStore::ScopedEVP_PKEY ScopedEVP_PKEY; 31 typedef net::OpenSSLClientKeyStore::ScopedEVP_PKEY ScopedEVP_PKEY;
30 32
31 // Must be called on the I/O thread to record a client certificate 33 // Must be called on the I/O thread to record a client certificate
32 // and its private key in the OpenSSLClientKeyStore. 34 // and its private key in the OpenSSLClientKeyStore.
33 void RecordClientCertificateKey( 35 void RecordClientCertificateKey(
34 const scoped_refptr<net::X509Certificate>& client_cert, 36 const scoped_refptr<net::X509Certificate>& client_cert,
35 ScopedEVP_PKEY private_key) { 37 ScopedEVP_PKEY private_key) {
36 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 38 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
37 net::OpenSSLClientKeyStore::GetInstance()->RecordClientCertPrivateKey( 39 net::OpenSSLClientKeyStore::GetInstance()->RecordClientCertPrivateKey(
38 client_cert.get(), private_key.get()); 40 client_cert.get(), private_key.get());
39 } 41 }
40 42
41 void StartClientCertificateRequest( 43 void StartClientCertificateRequest(
42 const net::SSLCertRequestInfo* cert_request_info, 44 const net::SSLCertRequestInfo* cert_request_info,
45 const ui::WindowAndroid* window,
43 const chrome::SelectCertificateCallback& callback) { 46 const chrome::SelectCertificateCallback& callback) {
44 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 47 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
45 48
49 if (!window) {
Ted C 2014/02/13 04:38:44 Since you DCHECK window below, you should be able
David Trainor- moved to gerrit 2014/02/13 05:03:55 Yeah I thought about that too, but was trying to f
David Trainor- moved to gerrit 2014/02/14 19:13:36 Done.
50 LOG(ERROR) << "Invalid WindowAndroid";
51 return;
52 }
53
46 // Ensure that callback(NULL) is posted as a task on the UI thread 54 // Ensure that callback(NULL) is posted as a task on the UI thread
47 // in case of an error. 55 // in case of an error.
48 base::Closure post_task_closure = base::Bind( 56 base::Closure post_task_closure = base::Bind(
49 base::IgnoreResult(&content::BrowserThread::PostTask), 57 base::IgnoreResult(&content::BrowserThread::PostTask),
50 content::BrowserThread::UI, 58 content::BrowserThread::UI,
51 FROM_HERE, 59 FROM_HERE,
52 base::Bind(callback, scoped_refptr<net::X509Certificate>())); 60 base::Bind(callback, scoped_refptr<net::X509Certificate>()));
53 61
54 base::ScopedClosureRunner guard(post_task_closure); 62 base::ScopedClosureRunner guard(post_task_closure);
55 63
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 105
98 // Create a copy of the callback on the heap so that its address 106 // Create a copy of the callback on the heap so that its address
99 // and ownership can be passed through and returned from Java via JNI. 107 // and ownership can be passed through and returned from Java via JNI.
100 scoped_ptr<chrome::SelectCertificateCallback> request( 108 scoped_ptr<chrome::SelectCertificateCallback> request(
101 new chrome::SelectCertificateCallback(callback)); 109 new chrome::SelectCertificateCallback(callback));
102 110
103 jint request_id = reinterpret_cast<jint>(request.get()); 111 jint request_id = reinterpret_cast<jint>(request.get());
104 112
105 if (!chrome::android:: 113 if (!chrome::android::
106 Java_SSLClientCertificateRequest_selectClientCertificate( 114 Java_SSLClientCertificateRequest_selectClientCertificate(
107 env, request_id, key_types_ref.obj(), principals_ref.obj(), 115 env,
108 host_name_ref.obj(), cert_request_info->host_and_port.port())) { 116 request_id,
117 window->GetJavaObject().obj(),
118 key_types_ref.obj(),
119 principals_ref.obj(),
120 host_name_ref.obj(),
121 cert_request_info->host_and_port.port())) {
109 return; 122 return;
110 } 123 }
111 124
112 ignore_result(guard.Release()); 125 ignore_result(guard.Release());
113 126
114 // Ownership was transferred to Java. 127 // Ownership was transferred to Java.
115 chrome::SelectCertificateCallback* ALLOW_UNUSED dummy = 128 chrome::SelectCertificateCallback* ALLOW_UNUSED dummy =
116 request.release(); 129 request.release();
117 } 130 }
118 131
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 return RegisterNativesImpl(env); 212 return RegisterNativesImpl(env);
200 } 213 }
201 214
202 } // namespace android 215 } // namespace android
203 216
204 void ShowSSLClientCertificateSelector( 217 void ShowSSLClientCertificateSelector(
205 content::WebContents* contents, 218 content::WebContents* contents,
206 const net::HttpNetworkSession* network_session, 219 const net::HttpNetworkSession* network_session,
207 net::SSLCertRequestInfo* cert_request_info, 220 net::SSLCertRequestInfo* cert_request_info,
208 const chrome::SelectCertificateCallback& callback) { 221 const chrome::SelectCertificateCallback& callback) {
222 ui::WindowAndroid* window =
223 WindowAndroidHelper::FromWebContents(contents)->GetWindowAndroid();
224 DCHECK(window);
209 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 225 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
210 StartClientCertificateRequest(cert_request_info, callback); 226 StartClientCertificateRequest(cert_request_info, window, callback);
211 } 227 }
212 228
213 } // namespace chrome 229 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698