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 #ifndef CHROME_BROWSER_UI_ANDROID_SSL_CLIENT_CERTIFICATE_REQUEST_H_ | |
| 6 #define CHROME_BROWSER_UI_ANDROID_SSL_CLIENT_CERTIFICATE_REQUEST_H_ | |
| 7 | |
| 8 #include <jni.h> | |
| 9 | |
| 10 #include "base/android/scoped_java_ref.h" | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "base/string_piece.h" | |
| 14 | |
| 15 namespace net { | |
| 16 class SSLCertRequestInfo; | |
| 17 } // namespace net | |
| 18 | |
| 19 namespace browser { | |
| 20 namespace android { | |
| 21 | |
| 22 // This is the C++ counterpart of the Java SSLClientCertificateRequest | |
| 23 // class. Usage example: | |
| 24 // | |
| 25 // 1/ Create your own subclass and override the OnCompletion() method. | |
| 26 // | |
| 27 // class MyRequest : public SSLClientCertificateRequest { | |
| 28 // ... | |
| 29 // virtual void OnCompletion(....) OVERRIDE; | |
| 30 // ... | |
| 31 // }; | |
| 32 // | |
| 33 // 2/ Start an asynchronous client certificate on the UI thread with: | |
| 34 // | |
| 35 // scoped_refptr<MyRequest> my_request(new MyRequest()); | |
| 36 // if (!my_request->Start(cert_request_info)) { | |
| 37 // LOG(ERROR) << "Could not start client certificate selection"; | |
| 38 // ... | |
| 39 // } | |
| 40 // | |
| 41 // 3/ Later, the UI thread will call back your request's OnCompletion() | |
| 42 // method with the results. | |
| 43 // | |
| 44 // Note the following limitations, coming from the platform APIS: | |
| 45 // | |
| 46 // - It's not possible to cancel a request once it has been started. | |
| 47 // | |
| 48 // - Each request will launch a system activity which pauses the UI | |
| 49 // thread. | |
| 50 // | |
| 51 // - If the user fails to select a certificate, fails to unlock access | |
| 52 // to the credential storage, or another error occurs, the | |
| 53 // OnCompletion method is called with NULL parameters. There is no | |
| 54 // way to know exactly what happened though. | |
| 55 // | |
| 56 // This class must only be used on the UI thread. | |
| 57 class SSLClientCertificateRequest | |
| 58 : public base::RefCounted<SSLClientCertificateRequest> { | |
| 59 public: | |
| 60 SSLClientCertificateRequest() { } | |
| 61 | |
| 62 // Launch an asynchronous client certificate system activity. | |
| 63 // |cert_request_info| holds the client certificate request details. | |
| 64 // Returns true on success, false otherwise. Note that failure only | |
| 65 // means that the system activity could not be launched. | |
| 66 // On success, this increments the delegate's reference count. | |
| 67 bool Start(const net::SSLCertRequestInfo* cert_request_info); | |
| 68 | |
| 69 // Called to pass the result of client certificate selection. | |
| 70 // |encoded_chain| is the encoded selected client certificate chain, | |
| 71 // where each item is a DER-encoded X.509 certificate. | |
| 72 // |private_key| is local JNI reference to the platform's | |
| 73 // PrivateKey object for this certificate. | |
| 74 // Note: both parameters will be NULL to indicate the user didn't | |
| 75 // select a certificate. | |
| 76 virtual void OnCompletion( | |
| 77 std::vector<base::StringPiece>* encoded_chain, | |
| 78 jobject private_key) = 0; | |
| 79 | |
| 80 // Called from JNI to pass the client certificate selection result. | |
| 81 // Note: this method is only public to be called from the auto-generated | |
| 82 // JNI wrapper code. Internal use only. | |
| 83 void OnRequestCompletion(JNIEnv* env, | |
| 84 jobject object, | |
| 85 jobjectArray encoded_chain_ref, | |
| 86 jobject private_key_ref); | |
|
Ryan Sleevi
2013/03/04 23:47:21
Method naming: It's not at all clear how SSLClient
| |
| 87 | |
| 88 protected: | |
| 89 virtual ~SSLClientCertificateRequest() { } | |
| 90 | |
| 91 private: | |
| 92 friend class base::RefCounted<SSLClientCertificateRequest>; | |
| 93 | |
| 94 DISALLOW_COPY_AND_ASSIGN(SSLClientCertificateRequest); | |
| 95 }; | |
| 96 | |
| 97 } // namespace android | |
| 98 } // namespace browser | |
| 99 | |
| 100 // Register JNI methods. | |
| 101 bool RegisterSSLClientCertificateRequestAndroid(JNIEnv* env); | |
|
Ryan Sleevi
2013/03/04 23:47:21
why does this have to be in the global namespace?
digit1
2013/03/05 16:54:00
Most of similar functions that are called from chr
| |
| 102 | |
| 103 #endif // CHROME_BROWSER_UI_ANDROID_SSL_CLIENT_CERTIFICATE_REQUEST_H_ | |
| OLD | NEW |