Skip to content

Commit

Permalink
Adding an onError method to the ChildBrowser
Browse files Browse the repository at this point in the history
  • Loading branch information
macdonst authored and Jesse MacFadyen committed Dec 7, 2011
1 parent 29135b1 commit e75e098
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public PluginResult execute(String action, JSONArray args, String callbackId) {
if (action.equals("showWebPage")) {
this.browserCallbackId = callbackId;

// If the ChildBrowser is already open then throw an error
if (dialog != null && dialog.isShowing()) {
return new PluginResult(PluginResult.Status.ERROR, "ChildBrowser is already open");
}

result = this.showWebPage(args.getString(0), args.optJSONObject(1));

if (result.length() > 0) {
Expand Down Expand Up @@ -132,7 +137,7 @@ public String openExternal(String url, boolean usePhoneGap) {
this.ctx.startActivity(intent);
return "";
} catch (android.content.ActivityNotFoundException e) {
System.out.println("ChildBrowser: Error loading url "+url+":"+ e.toString());
Log.d(LOG_TAG, "ChildBrowser: Error loading url "+url+":"+ e.toString());
return e.toString();
}
}
Expand Down
17 changes: 11 additions & 6 deletions Android/ChildBrowser/www/childbrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ChildBrowser.prototype.showWebPage = function(url, options) {
var options = new Object();
options.showLocationBar = true;
}
PhoneGap.exec(this._onEvent, null, "ChildBrowser", "showWebPage", [url, options]);
PhoneGap.exec(this._onEvent, this._onError, "ChildBrowser", "showWebPage", [url, options]);
};

/**
Expand All @@ -54,21 +54,26 @@ ChildBrowser.prototype.openExternal = function(url, usePhoneGap) {
};

/**
* Method called when the child browser is closed.
* Method called when the child browser has an event.
*/
ChildBrowser.prototype._onEvent = function(data) {
console.log("In _onEvent");
console.log("data type = " + data.type);
if (data.type == ChildBrowser.CLOSE_EVENT && typeof window.plugins.childBrowser.onClose === "function") {
console.log("Calling onClose");
window.plugins.childBrowser.onClose();
}
if (data.type == ChildBrowser.LOCATION_CHANGED_EVENT && typeof window.plugins.childBrowser.onLocationChange === "function") {
console.log("Calling onLocChange");
window.plugins.childBrowser.onLocationChange(data.location);
}
};

/**
* Method called when the child browser has an error.
*/
ChildBrowser.prototype._onError = function(data) {
if (typeof window.plugins.childBrowser.onError === "function") {
window.plugins.childBrowser.onError(data);
}
};

/**
* Maintain API consistency with iOS
*/
Expand Down

0 comments on commit e75e098

Please sign in to comment.