Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #55 from manifoldjs/v0.2.0
Browse files Browse the repository at this point in the history
Updated script injection to support Crosswalk
  • Loading branch information
msrodri committed Nov 26, 2015
2 parents a31b045 + 7009ef9 commit 0c9bbaa
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/android/HostedWebApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

import org.apache.cordova.PluginResult;
import org.apache.cordova.Whitelist;
import org.apache.cordova.engine.SystemWebView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
Expand Down Expand Up @@ -540,13 +540,18 @@ public void run() {
me.activity.runOnUiThread(new Runnable() {
@Override
public void run() {
SystemWebView webView = (SystemWebView) me.webView.getEngine().getView();
if (webView != null) {
webView.evaluateJavascript(scriptToInject, resultCallback);
} else {
Log.v(LOG_TAG, String.format("WARNING: Unexpected Webview type. Expected: '%s'. Found: '%s'", SystemWebView.class.getName(), me.webView.getEngine().getView().getClass().getName()));
View webView = me.webView.getEngine().getView();

try {
Method evaluateJavaScriptMethod = webView.getClass().getMethod("evaluateJavascript", new Class[]{ String.class, (Class<ValueCallback<String>>)(Class<?>)ValueCallback.class });
evaluateJavaScriptMethod.invoke(webView, scriptToInject, resultCallback);
} catch (Exception e) {
Log.v(LOG_TAG, String.format("WARNING: Webview does not support 'evaluateJavascript' method. Webview type: '%s'", webView.getClass().getName()));
me.webView.getEngine().loadUrl("javascript:" + Uri.encode(scriptToInject), false);
resultCallback.onReceiveValue(null);

if (resultCallback != null) {
resultCallback.onReceiveValue(null);
}
}
}
});
Expand Down

0 comments on commit 0c9bbaa

Please sign in to comment.