| 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 <memory> |
| 7 #include <utility> | 8 #include <utility> |
| 8 | 9 |
| 9 #include "android_webview/common/devtools_instrumentation.h" | 10 #include "android_webview/common/devtools_instrumentation.h" |
| 10 #include "android_webview/native/aw_contents.h" | 11 #include "android_webview/native/aw_contents.h" |
| 11 #include "base/android/jni_android.h" | 12 #include "base/android/jni_android.h" |
| 12 #include "base/android/jni_array.h" | 13 #include "base/android/jni_array.h" |
| 13 #include "base/android/jni_string.h" | 14 #include "base/android/jni_string.h" |
| 14 #include "base/callback_helpers.h" | 15 #include "base/callback_helpers.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 std::string der_string; | 96 std::string der_string; |
| 96 net::X509Certificate::GetDEREncoded(cert->os_cert_handle(), &der_string); | 97 net::X509Certificate::GetDEREncoded(cert->os_cert_handle(), &der_string); |
| 97 ScopedJavaLocalRef<jbyteArray> jcert = base::android::ToJavaByteArray( | 98 ScopedJavaLocalRef<jbyteArray> jcert = base::android::ToJavaByteArray( |
| 98 env, reinterpret_cast<const uint8_t*>(der_string.data()), | 99 env, reinterpret_cast<const uint8_t*>(der_string.data()), |
| 99 der_string.length()); | 100 der_string.length()); |
| 100 ScopedJavaLocalRef<jstring> jurl(ConvertUTF8ToJavaString( | 101 ScopedJavaLocalRef<jstring> jurl(ConvertUTF8ToJavaString( |
| 101 env, request_url.spec())); | 102 env, request_url.spec())); |
| 102 // We need to add the callback before making the call to java side, | 103 // We need to add the callback before making the call to java side, |
| 103 // as it may do a synchronous callback prior to returning. | 104 // as it may do a synchronous callback prior to returning. |
| 104 int request_id = pending_cert_error_callbacks_.Add( | 105 int request_id = pending_cert_error_callbacks_.Add( |
| 105 new CertErrorCallback(callback)); | 106 base::MakeUnique<CertErrorCallback>(callback)); |
| 106 *cancel_request = !Java_AwContentsClientBridge_allowCertificateError( | 107 *cancel_request = !Java_AwContentsClientBridge_allowCertificateError( |
| 107 env, obj, cert_error, jcert, jurl, request_id); | 108 env, obj, cert_error, jcert, jurl, request_id); |
| 108 // if the request is cancelled, then cancel the stored callback | 109 // if the request is cancelled, then cancel the stored callback |
| 109 if (*cancel_request) { | 110 if (*cancel_request) { |
| 110 pending_cert_error_callbacks_.Remove(request_id); | 111 pending_cert_error_callbacks_.Remove(request_id); |
| 111 } | 112 } |
| 112 } | 113 } |
| 113 | 114 |
| 114 void AwContentsClientBridge::ProceedSslError(JNIEnv* env, | 115 void AwContentsClientBridge::ProceedSslError(JNIEnv* env, |
| 115 const JavaRef<jobject>& obj, | 116 const JavaRef<jobject>& obj, |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 274 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 274 JNIEnv* env = AttachCurrentThread(); | 275 JNIEnv* env = AttachCurrentThread(); |
| 275 | 276 |
| 276 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 277 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 277 if (obj.is_null()) { | 278 if (obj.is_null()) { |
| 278 callback.Run(false, base::string16()); | 279 callback.Run(false, base::string16()); |
| 279 return; | 280 return; |
| 280 } | 281 } |
| 281 | 282 |
| 282 int callback_id = pending_js_dialog_callbacks_.Add( | 283 int callback_id = pending_js_dialog_callbacks_.Add( |
| 283 new content::JavaScriptDialogManager::DialogClosedCallback(callback)); | 284 base::MakeUnique<content::JavaScriptDialogManager::DialogClosedCallback>( |
| 285 callback)); |
| 284 ScopedJavaLocalRef<jstring> jurl( | 286 ScopedJavaLocalRef<jstring> jurl( |
| 285 ConvertUTF8ToJavaString(env, origin_url.spec())); | 287 ConvertUTF8ToJavaString(env, origin_url.spec())); |
| 286 ScopedJavaLocalRef<jstring> jmessage( | 288 ScopedJavaLocalRef<jstring> jmessage( |
| 287 ConvertUTF16ToJavaString(env, message_text)); | 289 ConvertUTF16ToJavaString(env, message_text)); |
| 288 | 290 |
| 289 switch (message_type) { | 291 switch (message_type) { |
| 290 case content::JAVASCRIPT_MESSAGE_TYPE_ALERT: { | 292 case content::JAVASCRIPT_MESSAGE_TYPE_ALERT: { |
| 291 devtools_instrumentation::ScopedEmbedderCallbackTask("onJsAlert"); | 293 devtools_instrumentation::ScopedEmbedderCallbackTask("onJsAlert"); |
| 292 Java_AwContentsClientBridge_handleJsAlert(env, obj, jurl, jmessage, | 294 Java_AwContentsClientBridge_handleJsAlert(env, obj, jurl, jmessage, |
| 293 callback_id); | 295 callback_id); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 321 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 323 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 322 if (obj.is_null()) { | 324 if (obj.is_null()) { |
| 323 callback.Run(false, base::string16()); | 325 callback.Run(false, base::string16()); |
| 324 return; | 326 return; |
| 325 } | 327 } |
| 326 | 328 |
| 327 const base::string16 message_text = | 329 const base::string16 message_text = |
| 328 l10n_util::GetStringUTF16(IDS_BEFOREUNLOAD_MESSAGEBOX_MESSAGE); | 330 l10n_util::GetStringUTF16(IDS_BEFOREUNLOAD_MESSAGEBOX_MESSAGE); |
| 329 | 331 |
| 330 int callback_id = pending_js_dialog_callbacks_.Add( | 332 int callback_id = pending_js_dialog_callbacks_.Add( |
| 331 new content::JavaScriptDialogManager::DialogClosedCallback(callback)); | 333 base::MakeUnique<content::JavaScriptDialogManager::DialogClosedCallback>( |
| 334 callback)); |
| 332 ScopedJavaLocalRef<jstring> jurl( | 335 ScopedJavaLocalRef<jstring> jurl( |
| 333 ConvertUTF8ToJavaString(env, origin_url.spec())); | 336 ConvertUTF8ToJavaString(env, origin_url.spec())); |
| 334 ScopedJavaLocalRef<jstring> jmessage( | 337 ScopedJavaLocalRef<jstring> jmessage( |
| 335 ConvertUTF16ToJavaString(env, message_text)); | 338 ConvertUTF16ToJavaString(env, message_text)); |
| 336 | 339 |
| 337 devtools_instrumentation::ScopedEmbedderCallbackTask("onJsBeforeUnload"); | 340 devtools_instrumentation::ScopedEmbedderCallbackTask("onJsBeforeUnload"); |
| 338 Java_AwContentsClientBridge_handleJsBeforeUnload(env, obj, jurl, jmessage, | 341 Java_AwContentsClientBridge_handleJsBeforeUnload(env, obj, jurl, jmessage, |
| 339 callback_id); | 342 callback_id); |
| 340 } | 343 } |
| 341 | 344 |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 pending_client_cert_request_delegates_.Remove(request_id); | 452 pending_client_cert_request_delegates_.Remove(request_id); |
| 450 | 453 |
| 451 delete delegate; | 454 delete delegate; |
| 452 } | 455 } |
| 453 | 456 |
| 454 bool RegisterAwContentsClientBridge(JNIEnv* env) { | 457 bool RegisterAwContentsClientBridge(JNIEnv* env) { |
| 455 return RegisterNativesImpl(env); | 458 return RegisterNativesImpl(env); |
| 456 } | 459 } |
| 457 | 460 |
| 458 } // namespace android_webview | 461 } // namespace android_webview |
| OLD | NEW |