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/browser/aw_contents_client_bridge.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
| 10 #include "android_webview/browser/aw_contents.h" |
10 #include "android_webview/common/devtools_instrumentation.h" | 11 #include "android_webview/common/devtools_instrumentation.h" |
11 #include "android_webview/grit/components_strings.h" | 12 #include "android_webview/grit/components_strings.h" |
12 #include "android_webview/native/aw_contents.h" | |
13 #include "base/android/jni_android.h" | 13 #include "base/android/jni_android.h" |
14 #include "base/android/jni_array.h" | 14 #include "base/android/jni_array.h" |
15 #include "base/android/jni_string.h" | 15 #include "base/android/jni_string.h" |
16 #include "base/callback_helpers.h" | 16 #include "base/callback_helpers.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
20 #include "base/message_loop/message_loop.h" | 20 #include "base/message_loop/message_loop.h" |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/browser/client_certificate_delegate.h" | 22 #include "content/public/browser/client_certificate_delegate.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 | 96 |
97 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 97 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
98 if (obj.is_null()) | 98 if (obj.is_null()) |
99 return; | 99 return; |
100 | 100 |
101 std::string der_string; | 101 std::string der_string; |
102 net::X509Certificate::GetDEREncoded(cert->os_cert_handle(), &der_string); | 102 net::X509Certificate::GetDEREncoded(cert->os_cert_handle(), &der_string); |
103 ScopedJavaLocalRef<jbyteArray> jcert = base::android::ToJavaByteArray( | 103 ScopedJavaLocalRef<jbyteArray> jcert = base::android::ToJavaByteArray( |
104 env, reinterpret_cast<const uint8_t*>(der_string.data()), | 104 env, reinterpret_cast<const uint8_t*>(der_string.data()), |
105 der_string.length()); | 105 der_string.length()); |
106 ScopedJavaLocalRef<jstring> jurl(ConvertUTF8ToJavaString( | 106 ScopedJavaLocalRef<jstring> jurl( |
107 env, request_url.spec())); | 107 ConvertUTF8ToJavaString(env, request_url.spec())); |
108 // We need to add the callback before making the call to java side, | 108 // We need to add the callback before making the call to java side, |
109 // as it may do a synchronous callback prior to returning. | 109 // as it may do a synchronous callback prior to returning. |
110 int request_id = pending_cert_error_callbacks_.Add( | 110 int request_id = pending_cert_error_callbacks_.Add( |
111 base::MakeUnique<CertErrorCallback>(callback)); | 111 base::MakeUnique<CertErrorCallback>(callback)); |
112 *cancel_request = !Java_AwContentsClientBridge_allowCertificateError( | 112 *cancel_request = !Java_AwContentsClientBridge_allowCertificateError( |
113 env, obj, cert_error, jcert, jurl, request_id); | 113 env, obj, cert_error, jcert, jurl, request_id); |
114 // if the request is cancelled, then cancel the stored callback | 114 // if the request is cancelled, then cancel the stored callback |
115 if (*cancel_request) { | 115 if (*cancel_request) { |
116 pending_cert_error_callbacks_.Remove(request_id); | 116 pending_cert_error_callbacks_.Remove(request_id); |
117 } | 117 } |
(...skipping 20 matching lines...) Expand all Loading... |
138 net::SSLCertRequestInfo* cert_request_info, | 138 net::SSLCertRequestInfo* cert_request_info, |
139 std::unique_ptr<content::ClientCertificateDelegate> delegate) { | 139 std::unique_ptr<content::ClientCertificateDelegate> delegate) { |
140 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 140 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
141 | 141 |
142 // Add the callback to id map. | 142 // Add the callback to id map. |
143 int request_id = | 143 int request_id = |
144 pending_client_cert_request_delegates_.Add(delegate.release()); | 144 pending_client_cert_request_delegates_.Add(delegate.release()); |
145 // Make sure callback is run on error. | 145 // Make sure callback is run on error. |
146 base::ScopedClosureRunner guard(base::Bind( | 146 base::ScopedClosureRunner guard(base::Bind( |
147 &AwContentsClientBridge::HandleErrorInClientCertificateResponse, | 147 &AwContentsClientBridge::HandleErrorInClientCertificateResponse, |
148 base::Unretained(this), | 148 base::Unretained(this), request_id)); |
149 request_id)); | |
150 | 149 |
151 JNIEnv* env = base::android::AttachCurrentThread(); | 150 JNIEnv* env = base::android::AttachCurrentThread(); |
152 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 151 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
153 if (obj.is_null()) | 152 if (obj.is_null()) |
154 return; | 153 return; |
155 | 154 |
156 // Build the |key_types| JNI parameter, as a String[] | 155 // Build the |key_types| JNI parameter, as a String[] |
157 std::vector<std::string> key_types; | 156 std::vector<std::string> key_types; |
158 for (size_t i = 0; i < cert_request_info->cert_key_types.size(); ++i) { | 157 for (size_t i = 0; i < cert_request_info->cert_key_types.size(); ++i) { |
159 switch (cert_request_info->cert_key_types[i]) { | 158 switch (cert_request_info->cert_key_types[i]) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 LOG(ERROR) << "No client certificate selected"; | 216 LOG(ERROR) << "No client certificate selected"; |
218 pending_client_cert_request_delegates_.Remove(request_id); | 217 pending_client_cert_request_delegates_.Remove(request_id); |
219 delegate->ContinueWithCertificate(nullptr); | 218 delegate->ContinueWithCertificate(nullptr); |
220 delete delegate; | 219 delete delegate; |
221 return; | 220 return; |
222 } | 221 } |
223 | 222 |
224 // Make sure callback is run on error. | 223 // Make sure callback is run on error. |
225 base::ScopedClosureRunner guard(base::Bind( | 224 base::ScopedClosureRunner guard(base::Bind( |
226 &AwContentsClientBridge::HandleErrorInClientCertificateResponse, | 225 &AwContentsClientBridge::HandleErrorInClientCertificateResponse, |
227 base::Unretained(this), | 226 base::Unretained(this), request_id)); |
228 request_id)); | |
229 | 227 |
230 // Convert the encoded chain to a vector of strings. | 228 // Convert the encoded chain to a vector of strings. |
231 std::vector<std::string> encoded_chain_strings; | 229 std::vector<std::string> encoded_chain_strings; |
232 if (!encoded_chain_ref.is_null()) { | 230 if (!encoded_chain_ref.is_null()) { |
233 base::android::JavaArrayOfByteArrayToStringVector( | 231 base::android::JavaArrayOfByteArrayToStringVector( |
234 env, encoded_chain_ref.obj(), &encoded_chain_strings); | 232 env, encoded_chain_ref.obj(), &encoded_chain_strings); |
235 } | 233 } |
236 | 234 |
237 std::vector<base::StringPiece> encoded_chain; | 235 std::vector<base::StringPiece> encoded_chain; |
238 for (size_t i = 0; i < encoded_chain_strings.size(); ++i) | 236 for (size_t i = 0; i < encoded_chain_strings.size(); ++i) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 } | 306 } |
309 case content::JAVASCRIPT_DIALOG_TYPE_PROMPT: { | 307 case content::JAVASCRIPT_DIALOG_TYPE_PROMPT: { |
310 ScopedJavaLocalRef<jstring> jdefault_value( | 308 ScopedJavaLocalRef<jstring> jdefault_value( |
311 ConvertUTF16ToJavaString(env, default_prompt_text)); | 309 ConvertUTF16ToJavaString(env, default_prompt_text)); |
312 devtools_instrumentation::ScopedEmbedderCallbackTask("onJsPrompt"); | 310 devtools_instrumentation::ScopedEmbedderCallbackTask("onJsPrompt"); |
313 Java_AwContentsClientBridge_handleJsPrompt(env, obj, jurl, jmessage, | 311 Java_AwContentsClientBridge_handleJsPrompt(env, obj, jurl, jmessage, |
314 jdefault_value, callback_id); | 312 jdefault_value, callback_id); |
315 break; | 313 break; |
316 } | 314 } |
317 default: | 315 default: |
318 NOTREACHED(); | 316 NOTREACHED(); |
319 } | 317 } |
320 } | 318 } |
321 | 319 |
322 void AwContentsClientBridge::RunBeforeUnloadDialog( | 320 void AwContentsClientBridge::RunBeforeUnloadDialog( |
323 const GURL& origin_url, | 321 const GURL& origin_url, |
324 const content::JavaScriptDialogManager::DialogClosedCallback& callback) { | 322 const content::JavaScriptDialogManager::DialogClosedCallback& callback) { |
325 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 323 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
326 JNIEnv* env = AttachCurrentThread(); | 324 JNIEnv* env = AttachCurrentThread(); |
327 | 325 |
328 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 326 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 pending_client_cert_request_delegates_.Remove(request_id); | 526 pending_client_cert_request_delegates_.Remove(request_id); |
529 | 527 |
530 delete delegate; | 528 delete delegate; |
531 } | 529 } |
532 | 530 |
533 bool RegisterAwContentsClientBridge(JNIEnv* env) { | 531 bool RegisterAwContentsClientBridge(JNIEnv* env) { |
534 return RegisterNativesImpl(env); | 532 return RegisterNativesImpl(env); |
535 } | 533 } |
536 | 534 |
537 } // namespace android_webview | 535 } // namespace android_webview |
OLD | NEW |