home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / AIMP2 / aimp_2.61.583.exe / $TEMP / YandexPackSetup.msi / filEE785A375F503EDA9313B966BC1B83F2 < prev    next >
Text File  |  2010-07-12  |  10KB  |  266 lines

  1. const EXTENSION_PATH = Components.classes["@mozilla.org/network/io-service;1"]
  2.     .getService(Components.interfaces.nsIIOService).newFileURI(__LOCATION__.parent.parent).spec;
  3. Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
  4.                    .getService(Components.interfaces.mozIJSSubScriptLoader)
  5.                    .loadSubScript(EXTENSION_PATH + "modules/xb/config.js");
  6.  
  7. function CustomBarCore() {
  8.     Cu.import(this._modulesPath + "log4moz.jsm", this);
  9.     Cu.import(this._modulesPath + "Preferences.jsm", this);
  10.     Cu.import(this._modulesPath + "JSON.jsm", this);
  11.     
  12.     this._setupLogging();
  13.     this._logger.info("Hello from " + this.contractID);
  14.     
  15.     this._observerService.addObserver(this, CommonConsts.PROFILE_AFTER_CHANGE, false);
  16.     this._observerService.addObserver(this, CommonConsts.PROFILE_BEFORE_CHANGE, false);
  17.     this._observerService.addObserver(this, CommonConsts.APP_ACTION_QUIT_TOPIC, false);
  18. };
  19.  
  20. CustomBarCore.prototype = {
  21.     Lib: {},
  22.     Log4Moz: null,
  23.     Preferences: null,
  24.     JSON: null,
  25.     JSON2XML: null,
  26.     
  27.     get appName() {
  28.         return this._appName;
  29.     },
  30.     
  31.     get version() {
  32.         return this._version;
  33.     },
  34.     
  35.     get application() {
  36.         return this._appObj;
  37.     },
  38.     
  39.     get extensionPathFile() {
  40.         return Cc["@mozilla.org/extensions/manager;1"]
  41.             .getService(Ci.nsIExtensionManager)
  42.                 .getInstallLocation(EXTENSION_ID)
  43.                     .getItemLocation(EXTENSION_ID);
  44.     },
  45.     
  46.     get wrappedJSObject() {
  47.         return this;
  48.     },
  49.     
  50.     observe: function CustomBarCore_observe(subject, topic, data) {
  51.         if (topic != "http-on-modify-request") {
  52.             this._logger.debug("Observing on topic \"" + topic + "\" with subject \"" + subject + "\"");
  53.             this._logger.debug("Data is:\n" + data);
  54.         }
  55.         
  56.         switch (topic) {
  57.             case "http-on-modify-request":
  58.                 let channel = subject.QueryInterface(Ci.nsIHttpChannel);
  59.                 try {
  60.                     if (channel.URI.path.split(/\?|#|;/)[0].match(this._presetURLPattern)) {
  61.                         this._logger.debug("Check preset url: " + channel.URI.spec);
  62.                         
  63.                         try {
  64.                             channel.notificationCallbacks.QueryInterface(Components.interfaces.nsIWebBrowserPersist);
  65.                             return;
  66.                         } catch (e) {}
  67.                         
  68.                         try {
  69.                             channel.QueryInterface(Components.interfaces.nsIPropertyBag2);
  70.                             if (channel.getPropertyAsBool("isXBInstallRequest"))
  71.                                 return;
  72.                         } catch(e) {}
  73.                         
  74.                         this._logger.debug("Check preset url => cancel request and run install.");
  75.                         
  76.                         channel.cancel(Cr.NS_BINDING_ABORTED);
  77.                         this.application.installPreset(channel.URI.spec);
  78.                     }
  79.                 } catch (e) {
  80.                     this._logger.error("Error observing 'http-on-modify-request'. " + this._formatError(e));
  81.                 }
  82.                 
  83.                 break;
  84.             
  85.             case CommonConsts.PROFILE_AFTER_CHANGE:
  86.                 try {
  87.                     this._updateLoggers(true, true, true);
  88.                     this.Preferences.observe(this._dumpLogLevelPrefName, this);
  89.                     this.Preferences.observe(this._consoleLogLevelPrefName, this);
  90.                 }
  91.                 finally {
  92.                     this._initApp();
  93.                 }
  94.                 break;
  95.                 
  96.             case CommonConsts.PROFILE_BEFORE_CHANGE:
  97.                 this._destroyApp();
  98.                 break;
  99.             
  100.             case CommonConsts.APP_ACTION_QUIT_TOPIC:
  101.                 this._shutdown();
  102.                 break;
  103.             
  104.             case "nsPref:changed":
  105.                 this._updateLoggers(data == this._dumpLogLevelPrefName, data == this._consoleLogLevelPrefName);
  106.                 break;
  107.         }
  108.     },
  109.     
  110.     _version: PLATFORM_VERSION,
  111.     _libFiles: ["legacy.js", "sysutils.js", "misc.js", "ecustom.js", "overlay_prov.js", "update.js",
  112.                 "xbbase.js", "xbtypes.js", "xbcalcnodes.js", "xbparser.js",
  113.                 "xbpackage.js", "xbpackagemanifest.js", "xbdb.js", "xbcache.js",
  114.                 "xbnetwork.js", "xbfuncs.js", "xbpreset.js", "xbwndengine.js",
  115.                 "ui/builder.js", "ui/event-listener.js", "ui/behaviour.js",
  116.                     "ui/behaviour/computed.js",
  117.                     "ui/behaviour/action.js",
  118.                     "ui/behaviour/url.js",
  119.                     "ui/behaviour/attribute.js",
  120.                     "ui/behaviour/menu.js",
  121.                     "ui/behaviour/tooltip.js",
  122.                     "ui/behaviour/style.js",
  123.                     "ui/behaviour/button.js",
  124.                     "ui/behaviour/image.js",
  125.                     "ui/behaviour/icon.js",
  126.                     "ui/behaviour/grid.js",
  127.                     "ui/elements.js",
  128.                 ],
  129.     _modulesPath: "resource://" + APP_NAME + "/",
  130.     _appChromePath: "chrome://" + APP_NAME + "/",
  131.     _dumpLogLevelPrefName: APP_NAME + ".xbcore.logging.stdout.level",
  132.     _consoleLogLevelPrefName: APP_NAME + ".xbcore.logging.console.level",
  133.     _appName: APP_NAME,
  134.     _appObj: null,
  135.     _dumpAppender: null,
  136.     _consoleAppender: null,
  137.     _observerService: Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService),
  138.     _presetURLPattern: /^.+\.xb\.xml$/i,
  139.     
  140.     _setupLogging: function CustomBarCore_setupLogging() {
  141.         let root = this.Log4Moz.repository.rootLogger;
  142.         root.level = this.Log4Moz.Level.All;
  143.         
  144.         let formatter = new this.Log4Moz.BasicFormatter();
  145.         
  146.         this._consoleAppender = new this.Log4Moz.ConsoleAppender(formatter);
  147.         this._consoleAppender.level = this.Log4Moz.Level.Error;
  148.         root.addAppender(this._consoleAppender);
  149.         
  150.         this._dumpAppender = new this.Log4Moz.DumpAppender(formatter);
  151.         this._dumpAppender.level = 100;
  152.         root.addAppender(this._dumpAppender);
  153.         
  154.         this._logger = this.Log4Moz.repository.getLogger(this.appName + ".Core");
  155.         this._logger.level = this.Log4Moz.Level.Debug;
  156.     },
  157.     
  158.     _updateLoggers: function CustomBarCore_updateLoggers(checkDumpSetting, checkConsoleSetting) {
  159.         if (checkDumpSetting) {
  160.             var dumpLevel = parseInt( this.Preferences.get(this._dumpLogLevelPrefName, -1), 10 );
  161.             if (!isNaN(dumpLevel)) {
  162.                 if (dumpLevel < 0)
  163.                     dumpLevel = 100;
  164.                 this._dumpAppender.level = dumpLevel;
  165.             }
  166.         }
  167.         
  168.         if (checkConsoleSetting) {
  169.             var consoleLevel = parseInt( this.Preferences.get(this._consoleLogLevelPrefName, -1), 10 );
  170.             if (!isNaN(consoleLevel)) {
  171.                 if (consoleLevel < 0)
  172.                     consoleLevel = 100;
  173.                 this._consoleAppender.level = consoleLevel;
  174.             }
  175.         }
  176.     },
  177.     
  178.     _importDependencies: function CustomBarCore_importDependencies(modulesNames) {
  179.         if ((typeof modulesNames !== "object") || (modulesNames.constructor !== Array))
  180.             throw new TypeError("Array expected as a second parameter");
  181.         
  182.         var libChromePath =  this._appChromePath + "content/custombar/lib/";
  183.         var mozSSLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader);
  184.         
  185.         for each (let moduleName in modulesNames) {
  186.             this._logger.config("Loading module from " + moduleName);
  187.             try {
  188.                 mozSSLoader.loadSubScript(libChromePath + moduleName, this.Lib);
  189.             }
  190.             catch (e) {
  191.                 this._logger.fatal(
  192.                     "Failed loading module from " + moduleName + "\n" + this._formatError(e));
  193.                 this._logger.debug("Stack trace:\n" + e.stack);
  194.             }
  195.         };
  196.     },
  197.     
  198.     _initApp: function CustomBarCore_initApp() {
  199.         this._importDependencies(this._libFiles);
  200.         
  201.         var appScript = {};
  202.         try {
  203.             var mozSSLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader);
  204.             mozSSLoader.loadSubScript(this._appChromePath + "content/custombar/bar.js", appScript);
  205.             this._appObj = new appScript.BarApplication(this);
  206.         }
  207.         catch (e) {
  208.             this._logger.fatal("Couldn't initialize application. " + this._formatError(e));
  209.             this._logger.debug("Stack trace:\n" + Components.stack);
  210.         }
  211.         
  212.         this._observerService.addObserver(this, "http-on-modify-request", false);
  213.     },
  214.     
  215.     _destroyApp: function CustomBarCore_destroyApp() {
  216.         this._observerService.removeObserver(this, "http-on-modify-request");
  217.         
  218.         try {
  219.             this._appObj.finalize();
  220.             this._appObj = null;
  221.         } catch(e) {
  222.             this._logger.error(this._formatError(e));
  223.         }
  224.     },
  225.     
  226.     _shutdown: function CustomBarCore_shutdown(){
  227.     },
  228.     
  229.     _formatError: function CustomBarCore_formatError(e) {
  230.         if (!(e instanceof Ci.nsIException))
  231.             return ("" + e);
  232.         
  233.         let text = e.name + ": " + e.message;
  234.         if (e.fileName)
  235.             text += "\nin " + e.fileName + "\nat line " + e.lineNumber;
  236.         
  237.         return  text;
  238.     },
  239.     
  240.     classDescription: "Custom Yandex bar core JS component for " + APP_NAME,
  241.     classID: CORE_CLASS_ID,
  242.     contractID: CORE_CONTRACT_ID,
  243.     QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports, Ci.nsIObserver]),
  244.     _xpcom_factory: {
  245.         createInstance: function (outer, iid) {
  246.             if (outer != null)
  247.                 throw Components.results.NS_ERROR_NO_AGGREGATION;
  248.             if (!this._componentInstance)
  249.                 this._componentInstance = new CustomBarCore();
  250.             return this._componentInstance.QueryInterface(iid);
  251.         }
  252.     },
  253.     _xpcom_categories: [
  254.         {
  255.             category: "app-startup",
  256.             service: true
  257.         }
  258.     ]
  259. };
  260.  
  261. var components = [CustomBarCore];
  262.  
  263. function NSGetModule(compMgr, fileSpec) {
  264.     return XPCOMUtils.generateModule(components);
  265. }
  266.