diff --git a/android/src/com/universalavenue/ticrosswalk/WebView.java b/android/src/com/universalavenue/ticrosswalk/WebView.java index 5c416a4..daf8321 100644 --- a/android/src/com/universalavenue/ticrosswalk/WebView.java +++ b/android/src/com/universalavenue/ticrosswalk/WebView.java @@ -31,6 +31,7 @@ import android.graphics.Color; import org.xwalk.core.XWalkView; +import org.xwalk.core.XWalkNavigationHistory.Direction; public class WebView extends TiUIView implements OnLifecycleEvent { @@ -105,17 +106,43 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP super.propertyChanged(key, oldValue, newValue, proxy); } + public XWalkView getXWalkView() + { + return (XWalkView) getNativeView(); + } + + public boolean canGoBack() + { + return getXWalkView().getNavigationHistory().canGoBack(); + } + + public boolean canGoForward() + { + return getXWalkView().getNavigationHistory().canGoForward(); + } + + public void goBack() + { + getXWalkView().getNavigationHistory().navigate(Direction.BACKWARD, 1); + } + + public void goForward() + { + getXWalkView().getNavigationHistory().navigate(Direction.FORWARD, 1); + } + + public void setUrl(String url) { Log.d(LCAT, "Loading new url: " + url); - XWalkView view = (XWalkView)getNativeView(); + XWalkView view = getXWalkView(); view.load(url, null); } public void setHtml(String html) { Log.d(LCAT, "Loading html string"); - XWalkView view = (XWalkView)getNativeView(); + XWalkView view = getXWalkView(); view.load(null, html); } @@ -132,7 +159,7 @@ public void onStart(Activity activity) { @Override public void onPause(Activity activity) { Log.i(LCAT, "onPause"); - XWalkView view = (XWalkView) getNativeView(); + XWalkView view = getXWalkView(); if (view != null) { Log.i(LCAT, "onPause view found"); view.pauseTimers(); @@ -143,7 +170,7 @@ public void onPause(Activity activity) { @Override public void onResume(Activity activity) { Log.i(LCAT, "onResume"); - XWalkView view = (XWalkView) getNativeView(); + XWalkView view = getXWalkView(); if (view != null) { Log.i(LCAT, "onResume view found"); view.resumeTimers(); @@ -154,7 +181,7 @@ public void onResume(Activity activity) { @Override public void onDestroy(Activity activity) { Log.i(LCAT, "onDestroy"); - XWalkView view = (XWalkView) getNativeView(); + XWalkView view = getXWalkView(); if (view != null) { Log.i(LCAT, "onDestroy view found"); view.onDestroy(); @@ -167,7 +194,7 @@ public void onStop(Activity activity) { } public void onActivityResult(int requestCode, int resultCode, Intent data) { - XWalkView view = (XWalkView) getNativeView(); + XWalkView view = getXWalkView(); Log.i(LCAT, "onActivityResult"); if (view != null) { Log.i(LCAT, "onActivityResult view found"); @@ -177,7 +204,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { public void onNewIntent(Intent intent) { Log.i(LCAT, "onNewIntent"); - XWalkView view = (XWalkView) getNativeView(); + XWalkView view = getXWalkView(); if (view != null) { Log.i(LCAT, "onNewIntent view found"); view.onNewIntent(intent); diff --git a/android/src/com/universalavenue/ticrosswalk/WebViewProxy.java b/android/src/com/universalavenue/ticrosswalk/WebViewProxy.java index 503254e..0cc0908 100644 --- a/android/src/com/universalavenue/ticrosswalk/WebViewProxy.java +++ b/android/src/com/universalavenue/ticrosswalk/WebViewProxy.java @@ -50,6 +50,11 @@ public TiUIView createView(Activity activity) return view; } + public WebView getWebView() + { + return (WebView) peekView(); + } + // Handle creation options @Override public void handleCreationDict(KrollDict options) @@ -73,6 +78,42 @@ public void handleCreationArgs(KrollModule createdInModule, Object[] args) super.handleCreationArgs(createdInModule, args); } + @Kroll.method + public boolean canGoBack() + { + WebView view = getWebView(); + if (view != null) { + return view.canGoBack(); + } + return false; + } + + @Kroll.method + public boolean canGoForward() + { + WebView view = getWebView(); + if (view != null) { + return view.canGoForward(); + } + return false; + } + + @Kroll.method + public void goBack() + { + if (canGoBack()) { + getWebView().goBack(); + } + } + + @Kroll.method + public void goForward() + { + if (canGoForward()) { + getWebView().goForward(); + } + } + @Kroll.setProperty @Kroll.method public void setUrl(String url) { setPropertyAndFire("url", url); @@ -85,7 +126,7 @@ public void setHtml(String html) { @Kroll.method public Object evalJS(String code) { - WebView view = (WebView) peekView(); + WebView view = getWebView(); if (view == null) { Log.e(LCAT, "evalJS failed, view not available"); @@ -98,7 +139,7 @@ public Object evalJS(String code) { @Kroll.method public void evalAsync(final String code, @Kroll.argument(optional=true) KrollFunction callback) { - WebView view = (WebView) peekView(); + WebView view = getWebView(); if (view == null) { Log.e(LCAT, "evalAsync failed, view not available"); @@ -123,7 +164,7 @@ public void onReceiveValue(String s) { getActivity().runOnUiThread(new Runnable () { @Override public void run() { - WebView view = (WebView) peekView(); + WebView view = getWebView(); if (view != null) { XWalkView webView = (XWalkView) view.getNativeView(); if (webView != null) {