summaryrefslogtreecommitdiff
path: root/webhelper
diff options
context:
space:
mode:
authorPhilip Chimento <philip@endlessm.com>2013-09-09 22:14:28 -0700
committerPhilip Chimento <philip@endlessm.com>2013-09-16 10:30:42 -0700
commite05a96375c7e6f26af836bd7e19bf99014a1e7cf (patch)
tree26f112144a60e9b4dc2c4528d637552d3c327587 /webhelper
parent6d595d347c6d454edc4749333edd413e9640a99d (diff)
Better error checking on web actions
- Move normal URI test to the top - Throw an exception if a nonexistent web action is called. [endlessm/eos-sdk#290]
Diffstat (limited to 'webhelper')
-rw-r--r--webhelper/webhelper.js59
1 files changed, 30 insertions, 29 deletions
diff --git a/webhelper/webhelper.js b/webhelper/webhelper.js
index 8286d9f..7ec17a6 100644
--- a/webhelper/webhelper.js
+++ b/webhelper/webhelper.js
@@ -23,38 +23,39 @@ const Application = new Lang.Class({
web_actions_handler: function(webview, frame, request, action, policy_decision) {
let uri = request.get_uri();
- if(uri.indexOf(EOS_URI_SCHEME) == 0) {
- // get the name and parameters for the desired function
- let f_call = uri.substring(EOS_URI_SCHEME.length, uri.length).split('?');
- var function_name = f_call[0];
- var parameters = {};
-
- if(f_call[1]) {
- // there are parameters
- let params = f_call[1].split('&');
- params.forEach(function(entry) {
- let param = entry.split('=');
-
- if(param.length == 2) {
- param[0] = decodeURIComponent(param[0]);
- param[1] = decodeURIComponent(param[1]);
- // and now we add it...
- parameters[param[0]] = param[1];
- }
- });
- }
-
- if(this._webActions[function_name])
- Lang.bind(this, this._webActions[function_name])(parameters);
- else
- print('Unknown function '+function_name);
-
- policy_decision.ignore();
- return true;
- } else {
+ if(uri.indexOf(EOS_URI_SCHEME) !== 0) {
// this is a regular URL, just navigate there
return false;
}
+
+ // get the name and parameters for the desired function
+ let f_call = uri.substring(EOS_URI_SCHEME.length, uri.length).split('?');
+ var function_name = f_call[0];
+ var parameters = {};
+
+ if(f_call[1]) {
+ // there are parameters
+ let params = f_call[1].split('&');
+ params.forEach(function(entry) {
+ let param = entry.split('=');
+
+ if(param.length == 2) {
+ param[0] = decodeURIComponent(param[0]);
+ param[1] = decodeURIComponent(param[1]);
+ // and now we add it...
+ parameters[param[0]] = param[1];
+ }
+ });
+ }
+
+ if(this._webActions[function_name])
+ Lang.bind(this, this._webActions[function_name])(parameters);
+ else
+ throw new Error("Undefined WebHelper action '%s'. Did you add it " +
+ "to your app's _webActions object?".format(function_name));
+
+ policy_decision.ignore();
+ return true;
},
// convenience functions