sandbox.js 2.7 KB
//>>built
define(["dojo","dijit","dojox","dojo/require!dojox/secure/DOM,dojox/secure/capability,dojo/NodeList-fx,dojo/_base/url"],function(a,m,f){a.provide("dojox.secure.sandbox");a.require("dojox.secure.DOM");a.require("dojox.secure.capability");a.require("dojo.NodeList-fx");a.require("dojo._base.url");(function(){if({}.__proto__){var b=function(a){var c=Array.prototype[a];c&&!c.fixed&&((Array.prototype[a]=function(){if(this==window)throw new TypeError("Called with wrong this");return c.apply(this,arguments)}).fixed=
!0)};b("concat");b("reverse");b("sort");b("slice");b("forEach");b("filter");b("reduce");b("reduceRight");b("every");b("map");b("some")}var g=function(){return a.xhrGet.apply(a,arguments)};f.secure.sandbox=function(a){var c=f.secure.DOM(a);a=c(a);var b=f.secure._safeDojoFunctions(a,c),h=[],d="isNaN isFinite parseInt parseFloat escape unescape encodeURI encodeURIComponent decodeURI decodeURIComponent alert confirm prompt Error EvalError RangeError ReferenceError SyntaxError TypeError Date RegExp Number Object Array String Math setTimeout setInterval clearTimeout clearInterval dojo get set forEach load evaluate".split(" "),
e;for(e in b)d.push(e),h.push("var "+e+"\x3ddojo."+e);eval(h.join(";"));c.load=function(a){if(a.match(/^[\w\s]*:/))throw Error("Access denied to cross-site requests");return g({url:new b._Url(c.rootUrl,a)+"",secure:!0})};c.evaluate=function(a){f.secure.capability.validate(a,d,{document:1,element:1});a.match(/^\s*[\[\{]/)?eval("("+a+")"):eval(a)};return{loadJS:function(a){c.rootUrl=a;return g({url:a,secure:!0}).addCallback(function(a){c.evaluate(a)})},loadHTML:function(d){c.rootUrl=d;return g({url:d,
secure:!0}).addCallback(function(d){a.innerHTML=d})},evaluate:function(a){return c.evaluate(a)}}}})();f.secure._safeDojoFunctions=function(b,g){var k="mixin require isString isArray isFunction isObject isArrayLike isAlien hitch delegate partial trim disconnect subscribe unsubscribe Deferred toJson style attr".split(" "),c=f.secure.unwrap;a.NodeList.prototype.addContent.safetyCheck=function(a){g.safeHTML(a)};a.NodeList.prototype.style.safetyCheck=function(a,b){if("behavior"==a)throw Error("Can not set behavior");
g.safeCSS(b)};a.NodeList.prototype.attr.safetyCheck=function(a,b){if(b&&("src"==a||"href"==a||"style"==a))throw Error("Illegal to set "+a);};for(var l={query:function(d,e){return g(a.query(d,c(e||b)))},connect:function(b,e){var d=b;arguments[0]=c(b);if(d!=arguments[0]&&"on"!=e.substring(0,2))throw Error("Invalid event name for element");return a.connect.apply(a,arguments)},body:function(){return b},byId:function(a){return b.ownerDocument.getElementById(a)},fromJson:function(b){f.secure.capability.validate(b,
[],{});return a.fromJson(b)}},h=0;h<k.length;h++)l[k[h]]=a[k[h]];return l}});