@Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); webView.changeProxyUrl(url); KrollDict data = new KrollDict(); data.put("url", url); webView.getProxy().fireEvent("load", data); }
@Override public boolean interceptOnBackPressed() { TiUIWebView view = (TiUIWebView) peekView(); if (view == null) { return false; } return view.interceptOnBackPressed(); }
private boolean shouldHandleMimeType(String mimeType, String url) { if (mimeType.startsWith("video/")) { Intent intent = new Intent(); intent.setClass(webView.getProxy().getContext(), TiVideoActivity.class); intent.putExtra("contentURL", url); intent.putExtra("play", true); webView.getProxy().getTiContext().getActivity().startActivity(intent); return true; } return false; }
@Override public TiUIView createView(Activity activity) { ((TiBaseActivity) activity).addOnLifecycleEventListener(this); ((TiBaseActivity) activity).addInterceptOnBackPressedEventListener(this); TiUIWebView webView = new TiUIWebView(this); if (postCreateMessage != null) { sendPostCreateMessage(webView.getWebView(), postCreateMessage); postCreateMessage = null; } return webView; }
@Kroll.method public Object evalJS(String code) { // If the view doesn't even exist yet, // or if it once did exist but doesn't anymore // (like if the proxy was removed from a parent), // we absolutely should not try to get a JS value // from it. TiUIWebView view = (TiUIWebView) peekView(); if (view == null) { Log.w(TAG, "WebView not available, returning null for evalJS result."); return null; } return view.getJSValue(code); }
@Kroll.method @Kroll.getProperty public String getUserAgent() { TiUIWebView currWebView = getWebView(); if (currWebView != null) { if (TiApplication.isUIThread()) { return currWebView.getUserAgentString(); } else { return (String) TiMessenger.sendBlockingMainMessage(getMainHandler().obtainMessage(MSG_GET_USER_AGENT)); } } return ""; }
@Kroll.method @Kroll.setProperty public void setUserAgent(String userAgent) { TiUIWebView currWebView = getWebView(); if (currWebView != null) { if (TiApplication.isUIThread()) { currWebView.setUserAgentString(userAgent); } else { Message message = getMainHandler().obtainMessage(MSG_SET_USER_AGENT); message.obj = userAgent; message.sendToTarget(); } } }
@Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); KrollDict data = new KrollDict(); data.put("url", url); webView.getProxy().fireEvent("beforeload", data); }
@Override public boolean shouldOverrideUrlLoading(final WebView view, String url) { if (DBG) { Log.d(LCAT, "url=" + url); } if (URLUtil.isAssetUrl(url) || URLUtil.isContentUrl(url) || URLUtil.isFileUrl(url)) { // go through the proxy to ensure we're on the UI thread webView.getProxy().setProperty("url", url, true); return true; } else if (url.startsWith(WebView.SCHEME_TEL)) { Log.i(LCAT, "Launching dialer for " + url); Intent dialer = Intent.createChooser(new Intent(Intent.ACTION_DIAL, Uri.parse(url)), "Choose Dialer"); webView.getProxy().getTiContext().getActivity().startActivity(dialer); return true; } else if (url.startsWith(WebView.SCHEME_MAILTO)) { Log.i(LCAT, "Launching mailer for " + url); Intent mailer = Intent.createChooser(new Intent(Intent.ACTION_SENDTO, Uri.parse(url)), "Send Message"); webView.getProxy().getTiContext().getActivity().startActivity(mailer); return true; } else if (url.startsWith(WebView.SCHEME_GEO)) { Log.i(LCAT, "Launching app for " + url); /*geo:latitude,longitude geo:latitude,longitude?z=zoom geo:0,0?q=my+street+address geo:0,0?q=business+near+city */ Intent geoviewer = Intent.createChooser(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), "Choose Viewer"); webView.getProxy().getTiContext().getActivity().startActivity(geoviewer); return true; } else { String extension = MimeTypeMap.getFileExtensionFromUrl(url); String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); if (mimeType != null) { return shouldHandleMimeType(mimeType, url); } if (DBG) { Log.e(LCAT, "NEED to Handle " + url); } return super.shouldOverrideUrlLoading(view, url); } }
@Override public void onDestroy(Activity activity) { TiUIWebView webView = (TiUIWebView) peekView(); if (webView == null) { return; } // We allow JS polling to continue until we exit the app. If we want to stop the polling when // the app is // backgrounded, we would need to move this to onStop(), and add the appropriate logic in // onResume() to restart // the polling. webView.destroyWebViewBinding(); WebView nativeWebView = webView.getWebView(); if (nativeWebView == null) { return; } nativeWebView.stopLoading(); super.releaseViews(); }
@Kroll.method public void setHtml(String html, @Kroll.argument(optional = true) KrollDict d) { setProperty(TiC.PROPERTY_HTML, html); setProperty(OPTIONS_IN_SETHTML, d); // If the web view has not been created yet, don't set html here. It will be set in // processProperties() when the // view is created. TiUIView v = peekView(); if (v != null) { if (TiApplication.isUIThread()) { ((TiUIWebView) v).setHtml(html, d); } else { getMainHandler().sendEmptyMessage(MSG_SET_HTML); } } }
public TiWebViewClient(TiUIWebView tiWebView, WebView webView) { super(); this.webView = tiWebView; binding = new TiWebViewBinding(tiWebView.getProxy().getTiContext(), webView); }