"use strict";
_kangoLoader.add("kango/backgroundscript_engine", function(require, exports, module) {
function BackgroundScriptEngine(){this._sandbox=null,this._window=null,EventTarget.call(this)}var core=require("kango/core"),extensionInfo=require("kango/extension_info"),lang=require("kango/lang"),io=require("kango/io"),console=require("kango/console"),utils=require("kango/utils"),func=utils.func,object=utils.object,EventTarget=utils.EventTarget;BackgroundScriptEngine.prototype=object.extend(EventTarget,{init:function(){var n=core.createApiInstance("background");this._sandbox=lang.createHTMLSandbox("background.html",func.bind(function(e){this._window=e,this.fireEvent("init",{window:e}),this._initScripts(e,n.obj,func.bind(function(){this.fireEvent("load",{window:e})},this))},this),func.bind(function(e){n.clear(),this.fireEvent("unload",{window:e})},this))},getDOMWindow:function(){return this._window},dispose:function(){this.removeAllEventListeners(),this._window=null,null!=this._sandbox&&(this._sandbox.dispose(),this._sandbox=null)},isLoaded:function(){var n=this.getDOMWindow();return null!=n&&"complete"==n.document.readyState&&"undefined"!=typeof n.kango},_initScripts:function(n,e,t){object.forEach(e,function(e,t){n[t]=e});var i=n.document,o=extensionInfo.background_scripts;if("undefined"!=typeof o&&o.length>0){var r=0,a=function(){var n=i.createElement("script");n.setAttribute("type","text/javascript"),n.setAttribute("src",io.getExtensionFileUrl(o[r]));var e=function(){r++,r<o.length?a():t()};n.onerror=function(){console.error("Unable to load "+o[r])},"undefined"!=typeof n.onreadystatechange?n.onreadystatechange=function(){"complete"==n.readyState&&e()}:n.onload=e,i.body.appendChild(n)};a()}}}),module.exports=new BackgroundScriptEngine,core.addEventListener("ready",function(){var n=module.exports;n.init()});
});