From 77178daad389c2084eb2262539f19ec8e7a43372 Mon Sep 17 00:00:00 2001 From: Ian Clelland Date: Fri, 15 Mar 2013 12:00:28 -0400 Subject: [PATCH] [CB-2308] [android] Report errors when InAppBrowser fails to load page --- .../src/org/apache/cordova/InAppBrowser.java | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/framework/src/org/apache/cordova/InAppBrowser.java b/framework/src/org/apache/cordova/InAppBrowser.java index 4f3095d4..87bc63f3 100644 --- a/framework/src/org/apache/cordova/InAppBrowser.java +++ b/framework/src/org/apache/cordova/InAppBrowser.java @@ -72,6 +72,7 @@ public class InAppBrowser extends CordovaPlugin { private static final String EXIT_EVENT = "exit"; private static final String LOAD_START_EVENT = "loadstart"; private static final String LOAD_STOP_EVENT = "loadstop"; + private static final String LOAD_ERROR_EVENT = "loaderror"; private static final String CLOSE_BUTTON_CAPTION = "closebuttoncaption"; private long MAX_QUOTA = 100 * 1024 * 1024; @@ -492,16 +493,24 @@ public class InAppBrowser extends CordovaPlugin { } /** - * Create a new plugin result and send it back to JavaScript + * Create a new plugin success result and send it back to JavaScript * * @param obj a JSONObject contain event payload information */ private void sendUpdate(JSONObject obj, boolean keepCallback) { - PluginResult result = new PluginResult(PluginResult.Status.OK, obj); + sendUpdate(obj, keepCallback, PluginResult.Status.OK); + } + + /** + * Create a new plugin result and send it back to JavaScript + * + * @param obj a JSONObject contain event payload information + * @param status the status code to return to the JavaScript environment + */ private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Status status) { + PluginResult result = new PluginResult(status, obj); result.setKeepCallback(keepCallback); this.callbackContext.sendPluginResult(result); } - public class InAppChromeClient extends WebChromeClient { /** @@ -662,5 +671,22 @@ public class InAppBrowser extends CordovaPlugin { Log.d(LOG_TAG, "Should never happen"); } } + + public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { + super.onReceivedError(view, errorCode, description, failingUrl); + + try { + JSONObject obj = new JSONObject(); + obj.put("type", LOAD_ERROR_EVENT); + obj.put("url", failingUrl); + obj.put("code", errorCode); + obj.put("message", description); + + sendUpdate(obj, true, PluginResult.Status.ERROR); + } catch (JSONException ex) { + Log.d(LOG_TAG, "Should never happen"); + } + + } } }