Skip to content

Commit

Permalink
change executeJS to sendMessage inner method on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrys committed Oct 21, 2014
1 parent 52b9d93 commit b778cf6
Showing 1 changed file with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Message;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
Expand Down Expand Up @@ -601,6 +602,7 @@ public void forward(int index) {
}

public void navigate(String url, int index) {
//Utils.platformLog("@&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&@", "navigate("+url+")");
String cleared_url = processForNativeView(url);
Logger.I(TAG, "Cleared URL: " + url);
if (cleared_url.length() > 0) {
Expand All @@ -611,19 +613,21 @@ public void navigate(String url, int index) {
}
}

@Override

//@Override
public void executeJS(String js, int index) {

//Utils.platformLog("@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$@", "ExecuteJS("+js+")");
//((android.webkit.WebView)webView.getView()).executeJS();
if (android.os.Build.VERSION.SDK_INT >= 19) {
if ((android.os.Build.VERSION.SDK_INT < 14) || (android.os.Build.VERSION.SDK_INT >= 19)) { // 14 is 4.0, 19 is 4.4
navigate("javascript:"+js, index);
return;
}


Method mStringByEvaluatingJavaScriptFromString = null;
Object mWebViewCore;
Method mSendMessage = null;
Object mWebViewCore = null;
Object mBrowserFrame = null;
boolean mHasPossibleUseOfReflectionExecuteJS = false;
Object webViewObject = this;
Expand All @@ -637,37 +641,40 @@ public void executeJS(String js, int index) {
wc.setAccessible(true);
mWebViewCore = wc.get(webViewObject);
if (mWebViewCore != null) {

mSendMessage = mWebViewCore.getClass().getDeclaredMethod("sendMessage", Message.class);
mSendMessage.setAccessible(true);

/*
Field bf= mWebViewCore.getClass().getDeclaredField("mBrowserFrame");
bf.setAccessible(true);
mBrowserFrame = bf.get(mWebViewCore);
mStringByEvaluatingJavaScriptFromString = mBrowserFrame.getClass().getDeclaredMethod("stringByEvaluatingJavaScriptFromString", String.class);
mStringByEvaluatingJavaScriptFromString.setAccessible(true);

*/
}
mHasPossibleUseOfReflectionExecuteJS = true;
} catch (Throwable e) {
mHasPossibleUseOfReflectionExecuteJS = false;
//e.printStackTrace();
}

if (mHasPossibleUseOfReflectionExecuteJS && (mStringByEvaluatingJavaScriptFromString != null)) {
boolean mHasReflectionWasExecutedOK = false;

if (mHasPossibleUseOfReflectionExecuteJS && (mSendMessage != null)) {
try {
mStringByEvaluatingJavaScriptFromString.invoke(mBrowserFrame, js);
//mStringByEvaluatingJavaScriptFromString.invoke(mBrowserFrame, js);
Message execJSCodeMsg = Message.obtain(null, 194, js);
mSendMessage.invoke(mWebViewCore, execJSCodeMsg);
mHasReflectionWasExecutedOK = true;
//Utils.platformLog("@#########################@", "EvaluateJS("+js+")");
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
//e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
} catch (Throwable e) {
//e.printStackTrace();
}
}
else {

if (!mHasReflectionWasExecutedOK) {
//com.rhomobile.rhodes.WebView.executeJs(js, index);
navigate("javascript:"+js, index);

Expand Down

0 comments on commit b778cf6

Please sign in to comment.