From f856536cc2ce3acb00bba923cfaeed95a5ada997 Mon Sep 17 00:00:00 2001 From: Anthony Decena Date: Sat, 10 Dec 2011 09:59:10 -0800 Subject: [PATCH] [TIMOB-6426] Simplified version of the openURL() method The canOpenURL() method will always return true. The simplified version of the openURL() url method just parses out the source and protocol, whitelists some known sources and does some custom scheme checking. --- mobileweb/src/Ti.Platform/platform.js | 58 ++++----------------------- 1 file changed, 8 insertions(+), 50 deletions(-) diff --git a/mobileweb/src/Ti.Platform/platform.js b/mobileweb/src/Ti.Platform/platform.js index 60c89830a55..a517ce27a72 100644 --- a/mobileweb/src/Ti.Platform/platform.js +++ b/mobileweb/src/Ti.Platform/platform.js @@ -113,66 +113,24 @@ set: function(val){return false;} }); - - function _canOpenURL(str) { - var o = _canOpenURL.options, - m = o.parser[o.strictMode ? "strict" : "loose"].exec(str), - uri = {}, - i = 14; - - while (i--) uri[o.key[i]] = m[i] || ""; - - uri[o.q.name] = {}; - uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) { - if ($1) uri[o.q.name][$1] = $2; - }); - - return uri; - }; - - _canOpenURL.options = { - strictMode: false, - key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], - q: { - name: "queryKey", - parser: /(?:^|&)([^&=]*)=?([^&]*)/g - }, - parser: { - strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, - loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ - } - }; // Methods api.canOpenURL = function(url){ - // quickly cover the protocols we know how to handle - if (/^(https?|ftp|localhost|\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/.test(url)) { - return true; - } - if (/^([tel|sms|mailto])/.test(url)) { return false; } - - // if none of the above, parse the uri and use the parts to determine how its handled. - // this is how we'll deal with custom url schemes ie: my-app:someappname' - var uri = _canOpenURL(url); - if (typeof uri !== "object") {return true;} - if (uri.protocol === "") { - return true; - } else { - return /^([\/?#]|[\w\d-]+^:[\w\d]+^@)/.test(uri.protocol); - } + true; }; api.createUUID = function(){ return Ti._5.createUUID(); }; api.openURL = function(url){ - if (api.canOpenURL(url)) { - window.open(url); - } else { - setTimeout(function () { + var m = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?/.exec(url); + if ( (/^([tel|sms|mailto])/.test(url) || /^([\/?#]|[\w\d-]+^:[\w\d]+^@)/.test(m[1])) && !/^(localhost)/.test(url) ) { + setTimeout(function () { window.location.href = url; - }, 1); - } + }, 1); + } else { + window.open(url); + } }; var _id = localStorage && localStorage.getItem("html5_titaniumPlatformId") ?