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

Unified Diff: android_webview/native/aw_contents.cc

Issue 12091111: Implement Webviewclient.onReceivedSslError (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed code review Created 7 years, 11 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.cc
diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc
index f170e4927ac7041ee9ce4006daaf45e2d441da1d..6564971f3034c3b9bf8935dcf3a99654b098cdb0 100644
--- a/android_webview/native/aw_contents.cc
+++ b/android_webview/native/aw_contents.cc
@@ -35,6 +35,7 @@
#include "content/public/browser/cert_store.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/common/ssl_status.h"
#include "jni/AwContents_jni.h"
@@ -115,6 +116,23 @@ AwContents* AwContents::FromWebContents(WebContents* web_contents) {
return AwContentsUserData::GetContents(web_contents);
}
+// 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) {
+
+ const content::RenderViewHost* host =
mkosiba (inactive) 2013/02/04 12:51:31 uber nit: normally this is called the rvh, not hos
sgurun-gerrit only 2013/02/21 23:32:32 Done.
+ content::RenderViewHost::FromID(render_process_id, render_view_id);
+ DCHECK(host);
mkosiba (inactive) 2013/02/04 12:51:31 please make this robust to NULLs. It's likely for
sgurun-gerrit only 2013/02/21 23:32:32 Done.
+ content::WebContents* web_contents =
+ content::WebContents::FromRenderViewHost(host);
+ DCHECK(web_contents);
+ return static_cast<AwCertificateErrorHandlerBase*>
mkosiba (inactive) 2013/02/04 12:51:31 nit: I think the common pattern is to leave the op
sgurun-gerrit only 2013/02/21 23:32:32 Done.
+ (AwContents::FromWebContents(web_contents));
+}
+
AwContents::AwContents(JNIEnv* env,
jobject obj,
jobject web_contents_delegate)
@@ -917,4 +935,36 @@ void AwContents::OnPictureUpdated(int process_id, int render_view_id) {
Invalidate();
}
+void AwContents::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);
+ 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()));
+ ssl_error_callback_ = callback;
boliu 2013/02/02 03:51:29 Only save callback if cancel_request is false? But
mkosiba (inactive) 2013/02/04 12:51:31 IMO it would be helpful if we had a bridge from Ch
sgurun-gerrit only 2013/02/21 23:32:32 Makes sense. adding a bridge for the aw_content_c
sgurun-gerrit only 2013/02/21 23:32:32 we are now saving all the callbacks. On 2013/02/0
+ *cancel_request = Java_AwContents_cancelCertificateError(env,
+ java_ref_.get(env).obj(), reinterpret_cast<jint>(cert_error), jcert.obj(),
+ jurl.obj());
+}
+
+void AwContents::ProceedSslError(JNIEnv* env, jobject obj, jboolean proceed) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (ssl_error_callback_.is_null()) {
+ LOG(WARNING) << "Ignoring unexpected ssl error proceed callback";
+ return;
+ }
+ ssl_error_callback_.Run(proceed);
+ ssl_error_callback_.Reset();
+}
+
+
} // namespace android_webview

Powered by Google App Engine
This is Rietveld 408576698