Skip to content

Commit

Permalink
Finalise Apache Cordova v4 plugin for android
Browse files Browse the repository at this point in the history
see #6 and #8
  • Loading branch information
hypery2k committed Oct 8, 2015
1 parent ea79ef5 commit 2c78b0f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
/*
The MIT License (MIT)
Copyright (c) 2015 Martin Reinhardt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Certificate Plugin for Cordova
*/
package de.martinreinhardt.cordova.plugins;

Expand All @@ -36,13 +36,13 @@ of this software and associated documentation files (the "Software"), to deal
import android.webkit.WebView;

/**
*
*
* Certificates Cordova WebView Client
*
*
* author, Martin Reinhardt on 23.06.14.
*
*
* Copyright Martin Reinhardt 2014. All rights reserved.
*
*
*/
public class CertificatesCordovaWebViewClient extends SystemWebViewClient {

Expand All @@ -54,7 +54,7 @@ public class CertificatesCordovaWebViewClient extends SystemWebViewClient {
private boolean allowUntrusted = false;

/**
*
*
* @param cordova
*/
public CertificatesCordovaWebViewClient(SystemWebViewEngine parentEngine) {
Expand All @@ -70,8 +70,8 @@ public boolean isAllowUntrusted() {
}

/**
*
*
*
*
* @param pAllowUntrusted
* the allowUntrusted to set
*/
Expand All @@ -80,7 +80,7 @@ public void setAllowUntrusted(final boolean pAllowUntrusted) {
}

/**
* @see org.apache.cordova.CordovaWebViewClient#onReceivedSslError(WebView,
* @see org.apache.cordova.SystemWebViewClient#onReceivedSslError(WebView,
* SslErrorHandler, SslError)
*/
@Override
Expand All @@ -90,7 +90,7 @@ public void onReceivedSslError(WebView view, SslErrorHandler handler,
if (isAllowUntrusted()) {
handler.proceed();
} else {
handler.cancel();
super.onReceivedSslError(view, handler, error);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,48 +1,51 @@
/*
The MIT License (MIT)
Copyright (c) 2014 Martin Reinhardt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Certificate Plugin for Cordova
*/
package de.martinreinhardt.cordova.plugins;

import org.apache.cordova.engine.SystemWebViewEngine;
import org.apache.cordova.engine.SystemWebView;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaActivity;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.json.JSONArray;
import org.json.JSONException;

import android.util.Log;

/**
*
*
* Certificate Plugin for Cordova
*
*
* author, Martin Reinhardt on 23.06.14.
*
*
* Copyright Martin Reinhardt 2014. All rights reserved.
*
*
*/
public class CertificatesPlugin extends CordovaPlugin {

Expand All @@ -58,22 +61,22 @@ public class CertificatesPlugin extends CordovaPlugin {

/**
* Executes the request.
*
*
* This method is called from the WebView thread. To do a non-trivial amount
* of work, use: cordova.getThreadPool().execute(runnable);
*
*
* To run on the UI thread, use:
* cordova.getActivity().runOnUiThread(runnable);
*
*
* @param action
* The action to execute. (Currently "setUntrusted only")
* @param args
* The exec() arguments.
* @param callbackContext
* The callback context used when calling back into JavaScript.
* @return Whether the action was valid.
*
*
*
*
*/
@Override
public boolean execute(String action, JSONArray args,
Expand All @@ -84,11 +87,14 @@ public boolean execute(String action, JSONArray args,
Log.d(LOG_TAG, "Setting allowUntrusted to " + allowUntrusted);
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
CertificatesCordovaWebViewClient cWebClient = new CertificatesCordovaWebViewClient(cordova);
cWebClient.setAllowUntrusted(allowUntrusted);
webView.setWebViewClient(cWebClient);
CordovaActivity ca = (CordovaActivity) cordova.getActivity();
ca.clearCache();
SystemWebView view = (SystemWebView)webView.getView();
CertificatesCordovaWebViewClient cWebClient =
new CertificatesCordovaWebViewClient((SystemWebViewEngine)webView.getEngine());

cWebClient.setAllowUntrusted(allowUntrusted);
webView.clearCache();
view.setWebViewClient(cWebClient);
}
});
callbackContext.success();
Expand Down

0 comments on commit 2c78b0f

Please sign in to comment.