Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1348)

Unified Diff: android_webview/native/aw_contents_client_bridge.cc

Issue 12091111: Implement Webviewclient.onReceivedSslError (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add a bridge for aw_contents_client Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: android_webview/native/aw_contents_client_bridge.cc
diff --git a/android_webview/native/aw_contents_client_bridge.cc b/android_webview/native/aw_contents_client_bridge.cc
new file mode 100644
index 0000000000000000000000000000000000000000..1bc7a491c0f7d5c0804b8745f4e064ee79fc94ec
--- /dev/null
+++ b/android_webview/native/aw_contents_client_bridge.cc
@@ -0,0 +1,103 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "android_webview/native/aw_contents_client_bridge.h"
+
+#include "android_webview/native/aw_contents.h"
+#include "base/android/jni_android.h"
+#include "base/android/jni_array.h"
+#include "base/android/jni_string.h"
+#include "base/callback.h"
+#include "content/public/browser/browser_thread.h"
+#include "googleurl/src/gurl.h"
+#include "jni/AwContentsClientBridge_jni.h"
+#include "net/base/x509_certificate.h"
+
+using base::android::AttachCurrentThread;
+using base::android::ConvertJavaStringToUTF16;
+using base::android::ConvertUTF8ToJavaString;
+using base::android::JavaRef;
+using base::android::ScopedJavaLocalRef;
+using content::BrowserThread;
+
+namespace android_webview {
+
+AwContentsClientBridge::AwContentsClientBridge(JNIEnv* env, jobject obj)
+ : java_ref_(env, obj) {
+}
+
+AwContentsClientBridge::~AwContentsClientBridge() {
+}
+
+void AwContentsClientBridge::AllowCertificateError(
+ int cert_error,
+ net::X509Certificate* cert,
+ const GURL& request_url,
+ const base::Callback<void(bool)>& callback,
+ bool* cancel_request) {
+
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ JNIEnv* env = AttachCurrentThread();
+
+ std::string der_string;
+ 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:
+ ScopedJavaLocalRef<jbyteArray> jcert = base::android::ToJavaByteArray(env,
+ reinterpret_cast<const uint8*>(der_string.data()), der_string.length());
+ ScopedJavaLocalRef<jstring> jurl(ConvertUTF8ToJavaString(
+ env, request_url.spec()));
+ // We need to add the callback before making the call to java side,
+ // 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:
+ int request_id = pending_cert_error_callbacks_.Add(
+ new CertErrorCallback(callback));
+ *cancel_request = !Java_AwContentsClientBridge_allowCertificateError(env,
+ 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
+ jurl.obj(), request_id);
+ // if the request is cancelled, then cancel the stored callback
+ if (*cancel_request) {
+ pending_cert_error_callbacks_.Remove(request_id);
+ }
+}
+
+void AwContentsClientBridge::ProceedSslError(JNIEnv* env, jobject obj,
+ jboolean proceed, jint id) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ CertErrorCallback* callback = pending_cert_error_callbacks_.Lookup(id);
+ if (!callback || callback->is_null()) {
+ LOG(WARNING) << "Ignoring unexpected ssl error proceed callback";
+ return;
+ }
+ callback->Run(proceed);
+ pending_cert_error_callbacks_.Remove(id);
+}
+
+// static
+// The implementation is here to provide isolation of the browser/ layer
+// from the implementation details of native/ layer.
+AwCertificateErrorHandlerBase* AwCertificateErrorHandlerBase::FromID(
+ int render_process_id,
+ int render_view_id) {
+
+ AwContents* aw_contents =
+ AwContents::FromID(render_process_id, render_view_id);
+ if (!aw_contents) return NULL;
+ return static_cast<AwCertificateErrorHandlerBase*>(
+ aw_contents->get_aw_contents_client_bridge());
+}
+
+static jint Init(JNIEnv* env,
+ jobject obj,
+ jint aw_contents) {
+ AwContentsClientBridge* client = new AwContentsClientBridge(env, obj);
+ AwContents* native_aw_contents = reinterpret_cast<AwContents*>(aw_contents);
+ DCHECK(native_aw_contents);
+ DCHECK(!native_aw_contents->get_aw_contents_client_bridge());
+ native_aw_contents->set_aw_contents_client_bridge(client);
+ return reinterpret_cast<jint>(client);
+}
+
+bool RegisterAwContentsClientBridge(JNIEnv* env) {
+ return RegisterNativesImpl(env) >= 0;
+}
+
+} // namespace android_webview

Powered by Google App Engine
This is Rietveld 408576698