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 #include "android_webview/native/aw_contents_client_bridge.h" | |
6 | |
7 #include "android_webview/native/aw_contents.h" | |
8 #include "base/android/jni_android.h" | |
9 #include "base/android/jni_array.h" | |
10 #include "base/android/jni_string.h" | |
11 #include "base/callback.h" | |
12 #include "content/public/browser/browser_thread.h" | |
13 #include "googleurl/src/gurl.h" | |
14 #include "jni/AwContentsClientBridge_jni.h" | |
15 #include "net/base/x509_certificate.h" | |
16 | |
17 using base::android::AttachCurrentThread; | |
18 using base::android::ConvertJavaStringToUTF16; | |
19 using base::android::ConvertUTF8ToJavaString; | |
20 using base::android::JavaRef; | |
21 using base::android::ScopedJavaLocalRef; | |
22 using content::BrowserThread; | |
23 | |
24 namespace android_webview { | |
25 | |
26 AwContentsClientBridge::AwContentsClientBridge(JNIEnv* env, jobject obj) | |
27 : java_ref_(env, obj) { | |
28 } | |
29 | |
30 AwContentsClientBridge::~AwContentsClientBridge() { | |
31 } | |
32 | |
33 void AwContentsClientBridge::AllowCertificateError( | |
34 int cert_error, | |
35 net::X509Certificate* cert, | |
36 const GURL& request_url, | |
37 const base::Callback<void(bool)>& callback, | |
38 bool* cancel_request) { | |
39 | |
40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
41 JNIEnv* env = AttachCurrentThread(); | |
42 | |
43 std::string der_string; | |
44 net::X509Certificate::GetDEREncoded(cert->os_cert_handle(),&der_string); | |
joth
2013/02/22 01:15:45
nit: space after comma
sgurun-gerrit only
2013/02/22 01:48:07
will fix
On 2013/02/22 01:15:45, joth wrote:
| |
45 ScopedJavaLocalRef<jbyteArray> jcert = base::android::ToJavaByteArray(env, | |
46 reinterpret_cast<const uint8*>(der_string.data()), der_string.length()); | |
47 ScopedJavaLocalRef<jstring> jurl(ConvertUTF8ToJavaString( | |
48 env, request_url.spec())); | |
49 // We need to add the callback before making the call to java side, | |
50 // as it may do an asynchronous callback prior to returning. | |
joth
2013/02/22 01:15:45
I think you mean: an async -> a synchronous ?
sgurun-gerrit only
2013/02/22 01:48:07
yeah.
On 2013/02/22 01:15:45, joth wrote:
| |
51 int request_id = pending_cert_error_callbacks_.Add( | |
52 new CertErrorCallback(callback)); | |
53 *cancel_request = !Java_AwContentsClientBridge_allowCertificateError(env, | |
54 java_ref_.get(env).obj(), reinterpret_cast<jint>(cert_error), jcert.obj(), | |
joth
2013/02/22 01:15:45
java_ref_ is a weak ref, so we need to always prom
sgurun-gerrit only
2013/02/22 01:48:07
Aha... right. But I think I was just looking at th
| |
55 jurl.obj(), request_id); | |
56 // if the request is cancelled, then cancel the stored callback | |
57 if (*cancel_request) { | |
58 pending_cert_error_callbacks_.Remove(request_id); | |
59 } | |
60 } | |
61 | |
62 void AwContentsClientBridge::ProceedSslError(JNIEnv* env, jobject obj, | |
63 jboolean proceed, jint id) { | |
64 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
65 CertErrorCallback* callback = pending_cert_error_callbacks_.Lookup(id); | |
66 if (!callback || callback->is_null()) { | |
67 LOG(WARNING) << "Ignoring unexpected ssl error proceed callback"; | |
68 return; | |
69 } | |
70 callback->Run(proceed); | |
71 pending_cert_error_callbacks_.Remove(id); | |
72 } | |
73 | |
74 // static | |
75 // The implementation is here to provide isolation of the browser/ layer | |
76 // from the implementation details of native/ layer. | |
77 AwCertificateErrorHandlerBase* AwCertificateErrorHandlerBase::FromID( | |
78 int render_process_id, | |
79 int render_view_id) { | |
80 | |
81 AwContents* aw_contents = | |
82 AwContents::FromID(render_process_id, render_view_id); | |
83 if (!aw_contents) return NULL; | |
84 return static_cast<AwCertificateErrorHandlerBase*>( | |
85 aw_contents->get_aw_contents_client_bridge()); | |
86 } | |
87 | |
88 static jint Init(JNIEnv* env, | |
89 jobject obj, | |
90 jint aw_contents) { | |
91 AwContentsClientBridge* client = new AwContentsClientBridge(env, obj); | |
92 AwContents* native_aw_contents = reinterpret_cast<AwContents*>(aw_contents); | |
93 DCHECK(native_aw_contents); | |
94 DCHECK(!native_aw_contents->get_aw_contents_client_bridge()); | |
95 native_aw_contents->set_aw_contents_client_bridge(client); | |
96 return reinterpret_cast<jint>(client); | |
97 } | |
98 | |
99 bool RegisterAwContentsClientBridge(JNIEnv* env) { | |
100 return RegisterNativesImpl(env) >= 0; | |
101 } | |
102 | |
103 } // namespace android_webview | |
OLD | NEW |