"use strict";module.metadata={"stability":"experimental"};const{Cc,Ci,CC,Cu}=require('chrome');const systemPrincipal=CC('@mozilla.org/systemprincipal;1','nsIPrincipal')();const scriptLoader=Cc['@mozilla.org/moz/jssubscript-loader;1'].getService(Ci.mozIJSSubScriptLoader);const self=require('sdk/self');const{getTabId,getTabForContentWindow}=require('../tabs/utils');const{getInnerId}=require('../window/utils');const{devtools}=Cu.import("resource://gre/modules/devtools/Loader.jsm",{});const{require:devtoolsRequire}=devtools;const{addContentGlobal,removeContentGlobal}=devtoolsRequire("devtools/server/content-globals");function sandbox(target,options){options=options||{};options.metadata=options.metadata?options.metadata:{};options.metadata.addonID=options.metadata.addonID?options.metadata.addonID:self.id;let sandbox=Cu.Sandbox(target||systemPrincipal,options);Cu.setSandboxMetadata(sandbox,options.metadata);let innerWindowID=options.metadata['inner-window-id']
if(innerWindowID){addContentGlobal({global:sandbox,'inner-window-id':innerWindowID});}
return sandbox;}
exports.sandbox=sandbox;function evaluate(sandbox,code,uri,line,version){return Cu.evalInSandbox(code,sandbox,version||'1.8',uri||'',line||1);}
exports.evaluate=evaluate;function load(sandbox,uri){if(uri.indexOf('data:')===0){let source=uri.substr(uri.indexOf(',')+1);return evaluate(sandbox,decodeURIComponent(source),'1.8',uri,0);}else{return scriptLoader.loadSubScript(uri,sandbox,'UTF-8');}}
exports.load=load;exports.nuke=Cu.nukeSandbox