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 "android_webview/native/aw_contents_client_bridge.h" | 5 #include "android_webview/native/aw_contents_client_bridge.h" |
6 | 6 |
7 #include "android_webview/common/devtools_instrumentation.h" | 7 #include "android_webview/common/devtools_instrumentation.h" |
8 #include "android_webview/native/aw_contents.h" | 8 #include "android_webview/native/aw_contents.h" |
9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 int request_id = pending_cert_error_callbacks_.Add( | 101 int request_id = pending_cert_error_callbacks_.Add( |
102 new CertErrorCallback(callback)); | 102 new CertErrorCallback(callback)); |
103 *cancel_request = !Java_AwContentsClientBridge_allowCertificateError( | 103 *cancel_request = !Java_AwContentsClientBridge_allowCertificateError( |
104 env, obj.obj(), cert_error, jcert.obj(), jurl.obj(), request_id); | 104 env, obj.obj(), cert_error, jcert.obj(), jurl.obj(), request_id); |
105 // if the request is cancelled, then cancel the stored callback | 105 // if the request is cancelled, then cancel the stored callback |
106 if (*cancel_request) { | 106 if (*cancel_request) { |
107 pending_cert_error_callbacks_.Remove(request_id); | 107 pending_cert_error_callbacks_.Remove(request_id); |
108 } | 108 } |
109 } | 109 } |
110 | 110 |
111 void AwContentsClientBridge::ProceedSslError(JNIEnv* env, jobject obj, | 111 void AwContentsClientBridge::ProceedSslError(JNIEnv* env, |
112 jboolean proceed, jint id) { | 112 const JavaRef<jobject>& obj, |
| 113 jboolean proceed, |
| 114 jint id) { |
113 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 115 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
114 CertErrorCallback* callback = pending_cert_error_callbacks_.Lookup(id); | 116 CertErrorCallback* callback = pending_cert_error_callbacks_.Lookup(id); |
115 if (!callback || callback->is_null()) { | 117 if (!callback || callback->is_null()) { |
116 LOG(WARNING) << "Ignoring unexpected ssl error proceed callback"; | 118 LOG(WARNING) << "Ignoring unexpected ssl error proceed callback"; |
117 return; | 119 return; |
118 } | 120 } |
119 callback->Run(proceed); | 121 callback->Run(proceed); |
120 pending_cert_error_callbacks_.Remove(id); | 122 pending_cert_error_callbacks_.Remove(id); |
121 } | 123 } |
122 | 124 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 cert_request_info->host_and_port.port()); | 191 cert_request_info->host_and_port.port()); |
190 | 192 |
191 // Release the guard. | 193 // Release the guard. |
192 ignore_result(guard.Release()); | 194 ignore_result(guard.Release()); |
193 } | 195 } |
194 | 196 |
195 // This method is inspired by OnSystemRequestCompletion() in | 197 // This method is inspired by OnSystemRequestCompletion() in |
196 // chrome/browser/ui/android/ssl_client_certificate_request.cc | 198 // chrome/browser/ui/android/ssl_client_certificate_request.cc |
197 void AwContentsClientBridge::ProvideClientCertificateResponse( | 199 void AwContentsClientBridge::ProvideClientCertificateResponse( |
198 JNIEnv* env, | 200 JNIEnv* env, |
199 jobject obj, | 201 const JavaRef<jobject>& obj, |
200 int request_id, | 202 int request_id, |
201 jobjectArray encoded_chain_ref, | 203 const JavaRef<jobjectArray>& encoded_chain_ref, |
202 jobject private_key_ref) { | 204 const JavaRef<jobject>& private_key_ref) { |
203 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 205 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
204 | 206 |
205 content::ClientCertificateDelegate* delegate = | 207 content::ClientCertificateDelegate* delegate = |
206 pending_client_cert_request_delegates_.Lookup(request_id); | 208 pending_client_cert_request_delegates_.Lookup(request_id); |
207 DCHECK(delegate); | 209 DCHECK(delegate); |
208 | 210 |
209 if (encoded_chain_ref == NULL || private_key_ref == NULL) { | 211 if (encoded_chain_ref.is_null() || private_key_ref.is_null()) { |
210 LOG(ERROR) << "No client certificate selected"; | 212 LOG(ERROR) << "No client certificate selected"; |
211 pending_client_cert_request_delegates_.Remove(request_id); | 213 pending_client_cert_request_delegates_.Remove(request_id); |
212 delegate->ContinueWithCertificate(nullptr); | 214 delegate->ContinueWithCertificate(nullptr); |
213 delete delegate; | 215 delete delegate; |
214 return; | 216 return; |
215 } | 217 } |
216 | 218 |
217 // Make sure callback is run on error. | 219 // Make sure callback is run on error. |
218 base::ScopedClosureRunner guard(base::Bind( | 220 base::ScopedClosureRunner guard(base::Bind( |
219 &AwContentsClientBridge::HandleErrorInClientCertificateResponse, | 221 &AwContentsClientBridge::HandleErrorInClientCertificateResponse, |
220 base::Unretained(this), | 222 base::Unretained(this), |
221 request_id)); | 223 request_id)); |
222 | 224 |
223 // Convert the encoded chain to a vector of strings. | 225 // Convert the encoded chain to a vector of strings. |
224 std::vector<std::string> encoded_chain_strings; | 226 std::vector<std::string> encoded_chain_strings; |
225 if (encoded_chain_ref) { | 227 if (!encoded_chain_ref.is_null()) { |
226 base::android::JavaArrayOfByteArrayToStringVector( | 228 base::android::JavaArrayOfByteArrayToStringVector( |
227 env, encoded_chain_ref, &encoded_chain_strings); | 229 env, encoded_chain_ref.obj(), &encoded_chain_strings); |
228 } | 230 } |
229 | 231 |
230 std::vector<base::StringPiece> encoded_chain; | 232 std::vector<base::StringPiece> encoded_chain; |
231 for (size_t i = 0; i < encoded_chain_strings.size(); ++i) | 233 for (size_t i = 0; i < encoded_chain_strings.size(); ++i) |
232 encoded_chain.push_back(encoded_chain_strings[i]); | 234 encoded_chain.push_back(encoded_chain_strings[i]); |
233 | 235 |
234 // Create the X509Certificate object from the encoded chain. | 236 // Create the X509Certificate object from the encoded chain. |
235 scoped_refptr<net::X509Certificate> client_cert( | 237 scoped_refptr<net::X509Certificate> client_cert( |
236 net::X509Certificate::CreateFromDERCertChain(encoded_chain)); | 238 net::X509Certificate::CreateFromDERCertChain(encoded_chain)); |
237 if (!client_cert.get()) { | 239 if (!client_cert.get()) { |
238 LOG(ERROR) << "Could not decode client certificate chain"; | 240 LOG(ERROR) << "Could not decode client certificate chain"; |
239 return; | 241 return; |
240 } | 242 } |
241 | 243 |
242 // Create an EVP_PKEY wrapper for the private key JNI reference. | 244 // Create an EVP_PKEY wrapper for the private key JNI reference. |
243 crypto::ScopedEVP_PKEY private_key( | 245 crypto::ScopedEVP_PKEY private_key( |
244 net::android::GetOpenSSLPrivateKeyWrapper(private_key_ref)); | 246 net::android::GetOpenSSLPrivateKeyWrapper(private_key_ref.obj())); |
245 if (!private_key.get()) { | 247 if (!private_key.get()) { |
246 LOG(ERROR) << "Could not create OpenSSL wrapper for private key"; | 248 LOG(ERROR) << "Could not create OpenSSL wrapper for private key"; |
247 return; | 249 return; |
248 } | 250 } |
249 | 251 |
250 // Release the guard and |pending_client_cert_request_delegates_| references | 252 // Release the guard and |pending_client_cert_request_delegates_| references |
251 // to |delegate|. | 253 // to |delegate|. |
252 pending_client_cert_request_delegates_.Remove(request_id); | 254 pending_client_cert_request_delegates_.Remove(request_id); |
253 ignore_result(guard.Release()); | 255 ignore_result(guard.Release()); |
254 | 256 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 ConvertUTF8ToJavaString(env, origin_url.spec())); | 336 ConvertUTF8ToJavaString(env, origin_url.spec())); |
335 ScopedJavaLocalRef<jstring> jmessage( | 337 ScopedJavaLocalRef<jstring> jmessage( |
336 ConvertUTF16ToJavaString(env, message_text)); | 338 ConvertUTF16ToJavaString(env, message_text)); |
337 | 339 |
338 devtools_instrumentation::ScopedEmbedderCallbackTask("onJsBeforeUnload"); | 340 devtools_instrumentation::ScopedEmbedderCallbackTask("onJsBeforeUnload"); |
339 Java_AwContentsClientBridge_handleJsBeforeUnload( | 341 Java_AwContentsClientBridge_handleJsBeforeUnload( |
340 env, obj.obj(), jurl.obj(), jmessage.obj(), callback_id); | 342 env, obj.obj(), jurl.obj(), jmessage.obj(), callback_id); |
341 } | 343 } |
342 | 344 |
343 void AwContentsClientBridge::ConfirmJsResult(JNIEnv* env, | 345 void AwContentsClientBridge::ConfirmJsResult(JNIEnv* env, |
344 jobject, | 346 const JavaRef<jobject>&, |
345 int id, | 347 int id, |
346 jstring prompt) { | 348 const JavaRef<jstring>& prompt) { |
347 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 349 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
348 content::JavaScriptDialogManager::DialogClosedCallback* callback = | 350 content::JavaScriptDialogManager::DialogClosedCallback* callback = |
349 pending_js_dialog_callbacks_.Lookup(id); | 351 pending_js_dialog_callbacks_.Lookup(id); |
350 if (!callback) { | 352 if (!callback) { |
351 LOG(WARNING) << "Unexpected JS dialog confirm. " << id; | 353 LOG(WARNING) << "Unexpected JS dialog confirm. " << id; |
352 return; | 354 return; |
353 } | 355 } |
354 base::string16 prompt_text; | 356 base::string16 prompt_text; |
355 if (prompt) { | 357 if (!prompt.is_null()) { |
356 prompt_text = ConvertJavaStringToUTF16(env, prompt); | 358 prompt_text = ConvertJavaStringToUTF16(env, prompt); |
357 } | 359 } |
358 callback->Run(true, prompt_text); | 360 callback->Run(true, prompt_text); |
359 pending_js_dialog_callbacks_.Remove(id); | 361 pending_js_dialog_callbacks_.Remove(id); |
360 } | 362 } |
361 | 363 |
362 void AwContentsClientBridge::CancelJsResult(JNIEnv*, jobject, int id) { | 364 void AwContentsClientBridge::CancelJsResult(JNIEnv*, |
| 365 const JavaRef<jobject>&, |
| 366 int id) { |
363 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 367 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
364 content::JavaScriptDialogManager::DialogClosedCallback* callback = | 368 content::JavaScriptDialogManager::DialogClosedCallback* callback = |
365 pending_js_dialog_callbacks_.Lookup(id); | 369 pending_js_dialog_callbacks_.Lookup(id); |
366 if (!callback) { | 370 if (!callback) { |
367 LOG(WARNING) << "Unexpected JS dialog cancel. " << id; | 371 LOG(WARNING) << "Unexpected JS dialog cancel. " << id; |
368 return; | 372 return; |
369 } | 373 } |
370 callback->Run(false, base::string16()); | 374 callback->Run(false, base::string16()); |
371 pending_js_dialog_callbacks_.Remove(id); | 375 pending_js_dialog_callbacks_.Remove(id); |
372 } | 376 } |
373 | 377 |
374 // Use to cleanup if there is an error in client certificate response. | 378 // Use to cleanup if there is an error in client certificate response. |
375 void AwContentsClientBridge::HandleErrorInClientCertificateResponse( | 379 void AwContentsClientBridge::HandleErrorInClientCertificateResponse( |
376 int request_id) { | 380 int request_id) { |
377 content::ClientCertificateDelegate* delegate = | 381 content::ClientCertificateDelegate* delegate = |
378 pending_client_cert_request_delegates_.Lookup(request_id); | 382 pending_client_cert_request_delegates_.Lookup(request_id); |
379 pending_client_cert_request_delegates_.Remove(request_id); | 383 pending_client_cert_request_delegates_.Remove(request_id); |
380 | 384 |
381 delete delegate; | 385 delete delegate; |
382 } | 386 } |
383 | 387 |
384 bool RegisterAwContentsClientBridge(JNIEnv* env) { | 388 bool RegisterAwContentsClientBridge(JNIEnv* env) { |
385 return RegisterNativesImpl(env); | 389 return RegisterNativesImpl(env); |
386 } | 390 } |
387 | 391 |
388 } // namespace android_webview | 392 } // namespace android_webview |
OLD | NEW |