123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353 |
- if(!dojo._hasResource["dojox.secure.sandbox"]){
- dojo._hasResource["dojox.secure.sandbox"] = true;
- dojo.provide("dojox.secure.sandbox");
- dojo.require("dojox.secure.DOM");
- dojo.require("dojox.secure.capability");
- dojo.require("dojo.NodeList-fx");
- (function() {
- var oldTimeout = setTimeout;
- var oldInterval = setInterval;
- if({}.__proto__){
-
- var fixMozArrayFunction = function (name) {
- var method = Array.prototype[name];
- if(method && !method.fixed){
- (Array.prototype[name] = function () {
- if (this == window) {
- throw new TypeError("Called with wrong this");
- }
- return method.apply(this, arguments);
- }).fixed = true;
- }
- };
-
- fixMozArrayFunction('concat');
- fixMozArrayFunction('reverse');
- fixMozArrayFunction('sort');
- fixMozArrayFunction("slice");
- fixMozArrayFunction("forEach");
- fixMozArrayFunction("filter");
- fixMozArrayFunction("reduce");
- fixMozArrayFunction("reduceRight");
- fixMozArrayFunction("every");
- fixMozArrayFunction("map");
- fixMozArrayFunction("some");
- }
- var xhrGet = function(){
- return dojo.xhrGet.apply(dojo,arguments);
- };
- dojox.secure.sandbox = function(element) {
-
-
-
-
-
-
-
-
-
-
-
-
- var wrap = dojox.secure.DOM(element);
- element = wrap(element);
- var document = element.ownerDocument;
- var mixin, dojo = dojox.secure._safeDojoFunctions(element,wrap);
- var imports= [];
- var safeCalls = ["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"];
- for(var i in dojo){
- safeCalls.push(i);
- imports.push("var " + i + "=dojo." + i);
- }
-
- eval(imports.join(";"));
- function get(obj,prop) {
-
- prop = '' + prop;
- if(dojox.secure.badProps.test(prop)) {
- throw new Error("bad property access");
- }
- if(obj.__get__) {
- return obj.__get__(prop);
- }
- return obj[prop];
- }
- function set(obj,prop,value) {
-
- prop = '' + prop;
- get(obj,prop); // test it
- if(obj.__set) {
- return obj.__set(prop);
- }
- obj[prop] = value;
- return value;
- }
- function forEach(obj,fun) {
-
- if(typeof fun != "function"){
- throw new TypeError();
- }
- if("length" in obj) {
-
- if(obj.__get__) {
-
- var len = obj.__get__('length');
- for (var i = 0; i < len; i++) {
- if(i in obj) {
- fun.call(obj, obj.__get__(i), i, obj);
- }
- }
- }
- else {
-
- len = obj.length;
- for (i = 0; i < len; i++) {
- if(i in obj) {
- fun.call(obj, obj[i], i, obj);
- }
- }
- }
- }
- else {
-
- for (i in obj) {
- fun.call(obj, get(obj,i), i, obj);
- }
- }
- }
- function Class(/*Function*/superclass, /*Object*/properties, /*Object*/classProperties) {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var proto,superConstructor,ourConstructor;
- var arg;
- for (var i = 0, l = arguments.length; typeof (arg = arguments[i]) == 'function' && i < l; i++) {
-
- if(proto) {
- mixin(proto,arg.prototype);
- }
- else {
-
-
- superConstructor = arg;
- var F = function() {};
- F.prototype = arg.prototype;
- proto = new F;
- }
- }
-
- if(arg) {
-
- for (var j in arg) {
-
- var value = arg[j];
- if(typeof value == 'function') {
- arg[j] = function() {
- if(this instanceof Class){
- return arguments.callee.__rawMethod__.apply(this,arguments);
- }
- throw new Error("Method called on wrong object");
- };
- arg[j].__rawMethod__ = value;
- }
- }
- if(arg.hasOwnProperty('constructor')) {
- ourConstructor = arg.constructor;
- }
- }
- proto = proto ? mixin(proto,arg) : arg;
- function Class() {
-
- if(superConstructor){
- superConstructor.apply(this,arguments);
- }
- if(ourConstructor){
- ourConstructor.apply(this,arguments);
- }
- }
- mixin(Class,arguments[i]);
- proto.constructor = Class;
- Class.prototype = proto;
- return Class;
- }
- function checkString(func){
- if(typeof func != 'function') {
- throw new Error("String is not allowed in setTimeout/setInterval");
- }
- }
- function setTimeout(func,time) {
-
- checkString(func);
- return oldTimeout(func,time);
- }
- function setInterval(func,time) {
-
- checkString(func);
- return oldInterval(func,time);
- }
- function evaluate(script){
-
- return wrap.evaluate(script);
- }
- var load = wrap.load = function(url){
-
- if (url.match(/^[\w\s]*:/)){
- throw new Error("Access denied to cross-site requests");
- }
- return xhrGet({url:(new dojo._Url(wrap.rootUrl,url))+'',secure:true});
- }
- wrap.evaluate = function(script){
-
- dojox.secure.capability.validate(script,safeCalls,
- {document:1,element:1});
-
-
- if(script.match(/^\s*[\[\{]/)) {
- var result = eval('(' + script + ')');
-
- }
- else {
- eval(script);
- }
-
- };
- return {
- loadJS : function(url){
-
-
-
-
-
-
- wrap.rootUrl = url;
- return xhrGet({url:url,secure:true}).addCallback(function(result) {
- evaluate(result,element );
- });
- },
- loadHTML : function(url){
-
-
-
-
-
-
-
-
- wrap.rootUrl = url;
- return xhrGet({url:url,secure:true}).addCallback(function(result){
- element.innerHTML = result;
- });
- },
- evaluate : function(script){
-
-
-
-
-
- return wrap.evaluate(script);
- }
-
- };
- };
- })();
- dojox.secure._safeDojoFunctions = function(element,wrap) {
-
- var safeFunctions = ["mixin","require","isString","isArray","isFunction","isObject","isArrayLike","isAlien",
- "hitch","delegate","partial","trim","disconnect","subscribe","unsubscribe","Deferred","toJson","style","attr"];
-
- var doc = element.ownerDocument;
- var unwrap = dojox.secure.unwrap;
- dojo.NodeList.prototype.addContent.safetyCheck = function(content){
- wrap.safeHTML(content);
- };
- dojo.NodeList.prototype.style.safetyCheck = function(name,value){
- if(name=='behavior'){
- throw new Error("Can not set behavior");
- }
- wrap.safeCSS(value);
- };
- dojo.NodeList.prototype.attr.safetyCheck = function(name,value){
- if (value && (name == 'src' || name == 'href' || name=='style')){
- throw new Error("Illegal to set " + name);
- }
- };
- var safe = {
- query : function(query,root) {
- return wrap(dojo.query(query,unwrap(root || element)));
- },
- connect: function(el,event) {
- var obj = el;
- arguments[0] = unwrap(el);
- if(obj!=arguments[0] && event.substring(0,2) != 'on'){
-
- throw new Error("Invalid event name for element");
- }
- return dojo.connect.apply(dojo,arguments);
- },
- body : function() {
- return element;
- },
- byId : function(id) {
- return element.ownerDocument.getElementById(id);
- },
- fromJson : function(str) {
-
- dojox.secure.capability.validate(str,[],{});
- return dojo.fromJson(str);
- }
- };
- for (var i = 0; i < safeFunctions.length; i++) {
- safe[safeFunctions[i]] = dojo[safeFunctions[i]];
- }
- return safe;
- };
- }
|