CB-8180: Changing methods of interception in WebViewClient class

This closes #136
This commit is contained in:
Joe Bowser 2016-01-15 13:31:46 -08:00
parent 518596a96f
commit 212e0a34d8

View File

@ -642,6 +642,7 @@ public class InAppBrowser extends CordovaPlugin {
// WebView // WebView
inAppWebView = new WebView(cordova.getActivity()); inAppWebView = new WebView(cordova.getActivity());
inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
inAppWebView.setId(Integer.valueOf(6));
inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView)); inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView));
WebViewClient client = new InAppBrowserClient(thatWebView, edittext); WebViewClient client = new InAppBrowserClient(thatWebView, edittext);
inAppWebView.setWebViewClient(client); inAppWebView.setWebViewClient(client);
@ -756,34 +757,30 @@ public class InAppBrowser extends CordovaPlugin {
} }
/** /**
* Notify the host application that a page has started loading. * Override the URL that should be loaded
* *
* @param view The webview initiating the callback. * This handles a small subset of all the URIs that would be encountered.
* @param url The url of the page. *
* @param webView
* @param url
*/ */
@Override @Override
public void onPageStarted(WebView view, String url, Bitmap favicon) { public boolean shouldOverrideUrlLoading(WebView webView, String url) {
super.onPageStarted(view, url, favicon); if (url.startsWith(WebView.SCHEME_TEL)) {
String newloc = "";
if (url.startsWith("http:") || url.startsWith("https:") || url.startsWith("file:")) {
newloc = url;
}
// If dialing phone (tel:5551212)
else if (url.startsWith(WebView.SCHEME_TEL)) {
try { try {
Intent intent = new Intent(Intent.ACTION_DIAL); Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse(url)); intent.setData(Uri.parse(url));
cordova.getActivity().startActivity(intent); cordova.getActivity().startActivity(intent);
return true;
} catch (android.content.ActivityNotFoundException e) { } catch (android.content.ActivityNotFoundException e) {
LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString()); LOG.e(LOG_TAG, "Error dialing " + url + ": " + e.toString());
} }
} } else if (url.startsWith("geo:") || url.startsWith(WebView.SCHEME_MAILTO) || url.startsWith("market:")) {
else if (url.startsWith("geo:") || url.startsWith(WebView.SCHEME_MAILTO) || url.startsWith("market:")) {
try { try {
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url)); intent.setData(Uri.parse(url));
cordova.getActivity().startActivity(intent); cordova.getActivity().startActivity(intent);
return true;
} catch (android.content.ActivityNotFoundException e) { } catch (android.content.ActivityNotFoundException e) {
LOG.e(LOG_TAG, "Error with " + url + ": " + e.toString()); LOG.e(LOG_TAG, "Error with " + url + ": " + e.toString());
} }
@ -798,8 +795,7 @@ public class InAppBrowser extends CordovaPlugin {
int parmIndex = url.indexOf('?'); int parmIndex = url.indexOf('?');
if (parmIndex == -1) { if (parmIndex == -1) {
address = url.substring(4); address = url.substring(4);
} } else {
else {
address = url.substring(4, parmIndex); address = url.substring(4, parmIndex);
// If body, then set sms body // If body, then set sms body
@ -815,29 +811,15 @@ public class InAppBrowser extends CordovaPlugin {
intent.putExtra("address", address); intent.putExtra("address", address);
intent.setType("vnd.android-dir/mms-sms"); intent.setType("vnd.android-dir/mms-sms");
cordova.getActivity().startActivity(intent); cordova.getActivity().startActivity(intent);
return true;
} catch (android.content.ActivityNotFoundException e) { } catch (android.content.ActivityNotFoundException e) {
LOG.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString()); LOG.e(LOG_TAG, "Error sending sms " + url + ":" + e.toString());
} }
} }
else { return false;
newloc = "http://" + url;
}
if (!newloc.equals(edittext.getText().toString())) {
edittext.setText(newloc);
}
try {
JSONObject obj = new JSONObject();
obj.put("type", LOAD_START_EVENT);
obj.put("url", newloc);
sendUpdate(obj, true);
} catch (JSONException ex) {
Log.d(LOG_TAG, "Should never happen");
}
} }
public void onPageFinished(WebView view, String url) { public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url); super.onPageFinished(view, url);