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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 env, obj, reinterpret_cast<intptr_t>(this)); | 58 env, obj, reinterpret_cast<intptr_t>(this)); |
59 } | 59 } |
60 | 60 |
61 AwContentsClientBridge::~AwContentsClientBridge() { | 61 AwContentsClientBridge::~AwContentsClientBridge() { |
62 JNIEnv* env = AttachCurrentThread(); | 62 JNIEnv* env = AttachCurrentThread(); |
63 | 63 |
64 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 64 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
65 if (!obj.is_null()) { | 65 if (!obj.is_null()) { |
66 // Clear the weak reference from the java peer to the native object since | 66 // Clear the weak reference from the java peer to the native object since |
67 // it is possible that java object lifetime can exceed the AwContens. | 67 // it is possible that java object lifetime can exceed the AwContens. |
68 Java_AwContentsClientBridge_setNativeContentsClientBridge(env, obj.obj(), | 68 Java_AwContentsClientBridge_setNativeContentsClientBridge(env, obj, 0); |
69 0); | |
70 } | 69 } |
71 | 70 |
72 for (IDMap<content::ClientCertificateDelegate>::iterator iter( | 71 for (IDMap<content::ClientCertificateDelegate>::iterator iter( |
73 &pending_client_cert_request_delegates_); | 72 &pending_client_cert_request_delegates_); |
74 !iter.IsAtEnd(); iter.Advance()) { | 73 !iter.IsAtEnd(); iter.Advance()) { |
75 delete iter.GetCurrentValue(); | 74 delete iter.GetCurrentValue(); |
76 } | 75 } |
77 } | 76 } |
78 | 77 |
79 void AwContentsClientBridge::AllowCertificateError( | 78 void AwContentsClientBridge::AllowCertificateError( |
(...skipping 14 matching lines...) Expand all Loading... |
94 ScopedJavaLocalRef<jbyteArray> jcert = base::android::ToJavaByteArray( | 93 ScopedJavaLocalRef<jbyteArray> jcert = base::android::ToJavaByteArray( |
95 env, reinterpret_cast<const uint8_t*>(der_string.data()), | 94 env, reinterpret_cast<const uint8_t*>(der_string.data()), |
96 der_string.length()); | 95 der_string.length()); |
97 ScopedJavaLocalRef<jstring> jurl(ConvertUTF8ToJavaString( | 96 ScopedJavaLocalRef<jstring> jurl(ConvertUTF8ToJavaString( |
98 env, request_url.spec())); | 97 env, request_url.spec())); |
99 // We need to add the callback before making the call to java side, | 98 // We need to add the callback before making the call to java side, |
100 // as it may do a synchronous callback prior to returning. | 99 // as it may do a synchronous callback prior to returning. |
101 int request_id = pending_cert_error_callbacks_.Add( | 100 int request_id = pending_cert_error_callbacks_.Add( |
102 new CertErrorCallback(callback)); | 101 new CertErrorCallback(callback)); |
103 *cancel_request = !Java_AwContentsClientBridge_allowCertificateError( | 102 *cancel_request = !Java_AwContentsClientBridge_allowCertificateError( |
104 env, obj.obj(), cert_error, jcert.obj(), jurl.obj(), request_id); | 103 env, obj, cert_error, jcert, jurl, request_id); |
105 // if the request is cancelled, then cancel the stored callback | 104 // if the request is cancelled, then cancel the stored callback |
106 if (*cancel_request) { | 105 if (*cancel_request) { |
107 pending_cert_error_callbacks_.Remove(request_id); | 106 pending_cert_error_callbacks_.Remove(request_id); |
108 } | 107 } |
109 } | 108 } |
110 | 109 |
111 void AwContentsClientBridge::ProceedSslError(JNIEnv* env, | 110 void AwContentsClientBridge::ProceedSslError(JNIEnv* env, |
112 const JavaRef<jobject>& obj, | 111 const JavaRef<jobject>& obj, |
113 jboolean proceed, | 112 jboolean proceed, |
114 jint id) { | 113 jint id) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 return; | 175 return; |
177 } | 176 } |
178 | 177 |
179 // Build the |host_name| and |port| JNI parameters, as a String and | 178 // Build the |host_name| and |port| JNI parameters, as a String and |
180 // a jint. | 179 // a jint. |
181 ScopedJavaLocalRef<jstring> host_name_ref = | 180 ScopedJavaLocalRef<jstring> host_name_ref = |
182 base::android::ConvertUTF8ToJavaString( | 181 base::android::ConvertUTF8ToJavaString( |
183 env, cert_request_info->host_and_port.host()); | 182 env, cert_request_info->host_and_port.host()); |
184 | 183 |
185 Java_AwContentsClientBridge_selectClientCertificate( | 184 Java_AwContentsClientBridge_selectClientCertificate( |
186 env, | 185 env, obj, request_id, key_types_ref, principals_ref, host_name_ref, |
187 obj.obj(), | |
188 request_id, | |
189 key_types_ref.obj(), | |
190 principals_ref.obj(), | |
191 host_name_ref.obj(), | |
192 cert_request_info->host_and_port.port()); | 186 cert_request_info->host_and_port.port()); |
193 | 187 |
194 // Release the guard. | 188 // Release the guard. |
195 ignore_result(guard.Release()); | 189 ignore_result(guard.Release()); |
196 } | 190 } |
197 | 191 |
198 // This method is inspired by OnSystemRequestCompletion() in | 192 // This method is inspired by OnSystemRequestCompletion() in |
199 // chrome/browser/ui/android/ssl_client_certificate_request.cc | 193 // chrome/browser/ui/android/ssl_client_certificate_request.cc |
200 void AwContentsClientBridge::ProvideClientCertificateResponse( | 194 void AwContentsClientBridge::ProvideClientCertificateResponse( |
201 JNIEnv* env, | 195 JNIEnv* env, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 int callback_id = pending_js_dialog_callbacks_.Add( | 278 int callback_id = pending_js_dialog_callbacks_.Add( |
285 new content::JavaScriptDialogManager::DialogClosedCallback(callback)); | 279 new content::JavaScriptDialogManager::DialogClosedCallback(callback)); |
286 ScopedJavaLocalRef<jstring> jurl( | 280 ScopedJavaLocalRef<jstring> jurl( |
287 ConvertUTF8ToJavaString(env, origin_url.spec())); | 281 ConvertUTF8ToJavaString(env, origin_url.spec())); |
288 ScopedJavaLocalRef<jstring> jmessage( | 282 ScopedJavaLocalRef<jstring> jmessage( |
289 ConvertUTF16ToJavaString(env, message_text)); | 283 ConvertUTF16ToJavaString(env, message_text)); |
290 | 284 |
291 switch (message_type) { | 285 switch (message_type) { |
292 case content::JAVASCRIPT_MESSAGE_TYPE_ALERT: { | 286 case content::JAVASCRIPT_MESSAGE_TYPE_ALERT: { |
293 devtools_instrumentation::ScopedEmbedderCallbackTask("onJsAlert"); | 287 devtools_instrumentation::ScopedEmbedderCallbackTask("onJsAlert"); |
294 Java_AwContentsClientBridge_handleJsAlert( | 288 Java_AwContentsClientBridge_handleJsAlert(env, obj, jurl, jmessage, |
295 env, obj.obj(), jurl.obj(), jmessage.obj(), callback_id); | 289 callback_id); |
296 break; | 290 break; |
297 } | 291 } |
298 case content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM: { | 292 case content::JAVASCRIPT_MESSAGE_TYPE_CONFIRM: { |
299 devtools_instrumentation::ScopedEmbedderCallbackTask("onJsConfirm"); | 293 devtools_instrumentation::ScopedEmbedderCallbackTask("onJsConfirm"); |
300 Java_AwContentsClientBridge_handleJsConfirm( | 294 Java_AwContentsClientBridge_handleJsConfirm(env, obj, jurl, jmessage, |
301 env, obj.obj(), jurl.obj(), jmessage.obj(), callback_id); | 295 callback_id); |
302 break; | 296 break; |
303 } | 297 } |
304 case content::JAVASCRIPT_MESSAGE_TYPE_PROMPT: { | 298 case content::JAVASCRIPT_MESSAGE_TYPE_PROMPT: { |
305 ScopedJavaLocalRef<jstring> jdefault_value( | 299 ScopedJavaLocalRef<jstring> jdefault_value( |
306 ConvertUTF16ToJavaString(env, default_prompt_text)); | 300 ConvertUTF16ToJavaString(env, default_prompt_text)); |
307 devtools_instrumentation::ScopedEmbedderCallbackTask("onJsPrompt"); | 301 devtools_instrumentation::ScopedEmbedderCallbackTask("onJsPrompt"); |
308 Java_AwContentsClientBridge_handleJsPrompt(env, | 302 Java_AwContentsClientBridge_handleJsPrompt(env, obj, jurl, jmessage, |
309 obj.obj(), | 303 jdefault_value, callback_id); |
310 jurl.obj(), | |
311 jmessage.obj(), | |
312 jdefault_value.obj(), | |
313 callback_id); | |
314 break; | 304 break; |
315 } | 305 } |
316 default: | 306 default: |
317 NOTREACHED(); | 307 NOTREACHED(); |
318 } | 308 } |
319 } | 309 } |
320 | 310 |
321 void AwContentsClientBridge::RunBeforeUnloadDialog( | 311 void AwContentsClientBridge::RunBeforeUnloadDialog( |
322 const GURL& origin_url, | 312 const GURL& origin_url, |
323 const content::JavaScriptDialogManager::DialogClosedCallback& callback) { | 313 const content::JavaScriptDialogManager::DialogClosedCallback& callback) { |
(...skipping 10 matching lines...) Expand all Loading... |
334 l10n_util::GetStringUTF16(IDS_BEFOREUNLOAD_MESSAGEBOX_MESSAGE); | 324 l10n_util::GetStringUTF16(IDS_BEFOREUNLOAD_MESSAGEBOX_MESSAGE); |
335 | 325 |
336 int callback_id = pending_js_dialog_callbacks_.Add( | 326 int callback_id = pending_js_dialog_callbacks_.Add( |
337 new content::JavaScriptDialogManager::DialogClosedCallback(callback)); | 327 new content::JavaScriptDialogManager::DialogClosedCallback(callback)); |
338 ScopedJavaLocalRef<jstring> jurl( | 328 ScopedJavaLocalRef<jstring> jurl( |
339 ConvertUTF8ToJavaString(env, origin_url.spec())); | 329 ConvertUTF8ToJavaString(env, origin_url.spec())); |
340 ScopedJavaLocalRef<jstring> jmessage( | 330 ScopedJavaLocalRef<jstring> jmessage( |
341 ConvertUTF16ToJavaString(env, message_text)); | 331 ConvertUTF16ToJavaString(env, message_text)); |
342 | 332 |
343 devtools_instrumentation::ScopedEmbedderCallbackTask("onJsBeforeUnload"); | 333 devtools_instrumentation::ScopedEmbedderCallbackTask("onJsBeforeUnload"); |
344 Java_AwContentsClientBridge_handleJsBeforeUnload( | 334 Java_AwContentsClientBridge_handleJsBeforeUnload(env, obj, jurl, jmessage, |
345 env, obj.obj(), jurl.obj(), jmessage.obj(), callback_id); | 335 callback_id); |
346 } | 336 } |
347 | 337 |
348 bool AwContentsClientBridge::ShouldOverrideUrlLoading(const base::string16& url, | 338 bool AwContentsClientBridge::ShouldOverrideUrlLoading(const base::string16& url, |
349 bool has_user_gesture, | 339 bool has_user_gesture, |
350 bool is_redirect, | 340 bool is_redirect, |
351 bool is_main_frame) { | 341 bool is_main_frame) { |
352 JNIEnv* env = AttachCurrentThread(); | 342 JNIEnv* env = AttachCurrentThread(); |
353 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 343 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
354 if (obj.is_null()) | 344 if (obj.is_null()) |
355 return false; | 345 return false; |
356 ScopedJavaLocalRef<jstring> jurl = ConvertUTF16ToJavaString(env, url); | 346 ScopedJavaLocalRef<jstring> jurl = ConvertUTF16ToJavaString(env, url); |
357 devtools_instrumentation::ScopedEmbedderCallbackTask( | 347 devtools_instrumentation::ScopedEmbedderCallbackTask( |
358 "shouldOverrideUrlLoading"); | 348 "shouldOverrideUrlLoading"); |
359 return Java_AwContentsClientBridge_shouldOverrideUrlLoading( | 349 return Java_AwContentsClientBridge_shouldOverrideUrlLoading( |
360 env, obj.obj(), jurl.obj(), has_user_gesture, is_redirect, is_main_frame); | 350 env, obj, jurl, has_user_gesture, is_redirect, is_main_frame); |
361 } | 351 } |
362 | 352 |
363 void AwContentsClientBridge::ConfirmJsResult(JNIEnv* env, | 353 void AwContentsClientBridge::ConfirmJsResult(JNIEnv* env, |
364 const JavaRef<jobject>&, | 354 const JavaRef<jobject>&, |
365 int id, | 355 int id, |
366 const JavaRef<jstring>& prompt) { | 356 const JavaRef<jstring>& prompt) { |
367 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 357 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
368 content::JavaScriptDialogManager::DialogClosedCallback* callback = | 358 content::JavaScriptDialogManager::DialogClosedCallback* callback = |
369 pending_js_dialog_callbacks_.Lookup(id); | 359 pending_js_dialog_callbacks_.Lookup(id); |
370 if (!callback) { | 360 if (!callback) { |
(...skipping 30 matching lines...) Expand all Loading... |
401 pending_client_cert_request_delegates_.Remove(request_id); | 391 pending_client_cert_request_delegates_.Remove(request_id); |
402 | 392 |
403 delete delegate; | 393 delete delegate; |
404 } | 394 } |
405 | 395 |
406 bool RegisterAwContentsClientBridge(JNIEnv* env) { | 396 bool RegisterAwContentsClientBridge(JNIEnv* env) { |
407 return RegisterNativesImpl(env); | 397 return RegisterNativesImpl(env); |
408 } | 398 } |
409 | 399 |
410 } // namespace android_webview | 400 } // namespace android_webview |
OLD | NEW |