From efe8d24597579aa085e01f2d89c92d2565da8184 Mon Sep 17 00:00:00 2001 From: Victor Costan Date: Mon, 10 Nov 2014 11:30:11 -0500 Subject: [PATCH] Align SSL error behavior with Cordova-Android. Cordova-Android ignores all SSL errors for debug builds, and fails on SSL errors in release builds. Crosswalk-Cordova-Android shows an alert dialog that lets the user ignore the SSL error or cancel the request. This behavior is surprising to Web platform developers, as typical browser behavior matches that of Cordova-Android for release builds. This change implements the Cordova-Android behavior, using the recently introduced XWalkResourceClient::onReceivedSslError() hook. --- .../apache/cordova/CordovaWebViewClient.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/framework/src/org/apache/cordova/CordovaWebViewClient.java b/framework/src/org/apache/cordova/CordovaWebViewClient.java index c8e53d74..438dab8b 100755 --- a/framework/src/org/apache/cordova/CordovaWebViewClient.java +++ b/framework/src/org/apache/cordova/CordovaWebViewClient.java @@ -161,6 +161,34 @@ public void onReceivedLoadError(XWalkView view, int errorCode, String descriptio public boolean shouldOverrideUrlLoading(XWalkView view, String url) { return helper.shouldOverrideUrlLoading(view, url); } + + /** + * Notify the host application that an SSL error occurred while loading a + * resource. The host application must call either callback.onReceiveValue(true) + * or callback.onReceiveValue(false). Note that the decision may be + * retained for use in response to future SSL errors. The default behavior + * is to pop up a dialog. + */ + public void onReceivedSslError(XWalkView view, ValueCallback callback, SslError error) { + final String packageName = this.cordova.getActivity().getPackageName(); + final PackageManager pm = this.cordova.getActivity().getPackageManager(); + + ApplicationInfo appInfo; + try { + appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA); + if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) { + // debug = true + callback.onReceiveValue(true); + return; + } else { + // debug = false + callback.onReceiveValue(false); + } + } catch (NameNotFoundException e) { + // When it doubt, lock it out! + callback.onReceiveValue(false); + } + } /** * Sets the authentication token.