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 >
Wrap
Text File
|
2010-07-12
|
10KB
|
266 lines
const EXTENSION_PATH = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService).newFileURI(__LOCATION__.parent.parent).spec;
Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Components.interfaces.mozIJSSubScriptLoader)
.loadSubScript(EXTENSION_PATH + "modules/xb/config.js");
function CustomBarCore() {
Cu.import(this._modulesPath + "log4moz.jsm", this);
Cu.import(this._modulesPath + "Preferences.jsm", this);
Cu.import(this._modulesPath + "JSON.jsm", this);
this._setupLogging();
this._logger.info("Hello from " + this.contractID);
this._observerService.addObserver(this, CommonConsts.PROFILE_AFTER_CHANGE, false);
this._observerService.addObserver(this, CommonConsts.PROFILE_BEFORE_CHANGE, false);
this._observerService.addObserver(this, CommonConsts.APP_ACTION_QUIT_TOPIC, false);
};
CustomBarCore.prototype = {
Lib: {},
Log4Moz: null,
Preferences: null,
JSON: null,
JSON2XML: null,
get appName() {
return this._appName;
},
get version() {
return this._version;
},
get application() {
return this._appObj;
},
get extensionPathFile() {
return Cc["@mozilla.org/extensions/manager;1"]
.getService(Ci.nsIExtensionManager)
.getInstallLocation(EXTENSION_ID)
.getItemLocation(EXTENSION_ID);
},
get wrappedJSObject() {
return this;
},
observe: function CustomBarCore_observe(subject, topic, data) {
if (topic != "http-on-modify-request") {
this._logger.debug("Observing on topic \"" + topic + "\" with subject \"" + subject + "\"");
this._logger.debug("Data is:\n" + data);
}
switch (topic) {
case "http-on-modify-request":
let channel = subject.QueryInterface(Ci.nsIHttpChannel);
try {
if (channel.URI.path.split(/\?|#|;/)[0].match(this._presetURLPattern)) {
this._logger.debug("Check preset url: " + channel.URI.spec);
try {
channel.notificationCallbacks.QueryInterface(Components.interfaces.nsIWebBrowserPersist);
return;
} catch (e) {}
try {
channel.QueryInterface(Components.interfaces.nsIPropertyBag2);
if (channel.getPropertyAsBool("isXBInstallRequest"))
return;
} catch(e) {}
this._logger.debug("Check preset url => cancel request and run install.");
channel.cancel(Cr.NS_BINDING_ABORTED);
this.application.installPreset(channel.URI.spec);
}
} catch (e) {
this._logger.error("Error observing 'http-on-modify-request'. " + this._formatError(e));
}
break;
case CommonConsts.PROFILE_AFTER_CHANGE:
try {
this._updateLoggers(true, true, true);
this.Preferences.observe(this._dumpLogLevelPrefName, this);
this.Preferences.observe(this._consoleLogLevelPrefName, this);
}
finally {
this._initApp();
}
break;
case CommonConsts.PROFILE_BEFORE_CHANGE:
this._destroyApp();
break;
case CommonConsts.APP_ACTION_QUIT_TOPIC:
this._shutdown();
break;
case "nsPref:changed":
this._updateLoggers(data == this._dumpLogLevelPrefName, data == this._consoleLogLevelPrefName);
break;
}
},
_version: PLATFORM_VERSION,
_libFiles: ["legacy.js", "sysutils.js", "misc.js", "ecustom.js", "overlay_prov.js", "update.js",
"xbbase.js", "xbtypes.js", "xbcalcnodes.js", "xbparser.js",
"xbpackage.js", "xbpackagemanifest.js", "xbdb.js", "xbcache.js",
"xbnetwork.js", "xbfuncs.js", "xbpreset.js", "xbwndengine.js",
"ui/builder.js", "ui/event-listener.js", "ui/behaviour.js",
"ui/behaviour/computed.js",
"ui/behaviour/action.js",
"ui/behaviour/url.js",
"ui/behaviour/attribute.js",
"ui/behaviour/menu.js",
"ui/behaviour/tooltip.js",
"ui/behaviour/style.js",
"ui/behaviour/button.js",
"ui/behaviour/image.js",
"ui/behaviour/icon.js",
"ui/behaviour/grid.js",
"ui/elements.js",
],
_modulesPath: "resource://" + APP_NAME + "/",
_appChromePath: "chrome://" + APP_NAME + "/",
_dumpLogLevelPrefName: APP_NAME + ".xbcore.logging.stdout.level",
_consoleLogLevelPrefName: APP_NAME + ".xbcore.logging.console.level",
_appName: APP_NAME,
_appObj: null,
_dumpAppender: null,
_consoleAppender: null,
_observerService: Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService),
_presetURLPattern: /^.+\.xb\.xml$/i,
_setupLogging: function CustomBarCore_setupLogging() {
let root = this.Log4Moz.repository.rootLogger;
root.level = this.Log4Moz.Level.All;
let formatter = new this.Log4Moz.BasicFormatter();
this._consoleAppender = new this.Log4Moz.ConsoleAppender(formatter);
this._consoleAppender.level = this.Log4Moz.Level.Error;
root.addAppender(this._consoleAppender);
this._dumpAppender = new this.Log4Moz.DumpAppender(formatter);
this._dumpAppender.level = 100;
root.addAppender(this._dumpAppender);
this._logger = this.Log4Moz.repository.getLogger(this.appName + ".Core");
this._logger.level = this.Log4Moz.Level.Debug;
},
_updateLoggers: function CustomBarCore_updateLoggers(checkDumpSetting, checkConsoleSetting) {
if (checkDumpSetting) {
var dumpLevel = parseInt( this.Preferences.get(this._dumpLogLevelPrefName, -1), 10 );
if (!isNaN(dumpLevel)) {
if (dumpLevel < 0)
dumpLevel = 100;
this._dumpAppender.level = dumpLevel;
}
}
if (checkConsoleSetting) {
var consoleLevel = parseInt( this.Preferences.get(this._consoleLogLevelPrefName, -1), 10 );
if (!isNaN(consoleLevel)) {
if (consoleLevel < 0)
consoleLevel = 100;
this._consoleAppender.level = consoleLevel;
}
}
},
_importDependencies: function CustomBarCore_importDependencies(modulesNames) {
if ((typeof modulesNames !== "object") || (modulesNames.constructor !== Array))
throw new TypeError("Array expected as a second parameter");
var libChromePath = this._appChromePath + "content/custombar/lib/";
var mozSSLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader);
for each (let moduleName in modulesNames) {
this._logger.config("Loading module from " + moduleName);
try {
mozSSLoader.loadSubScript(libChromePath + moduleName, this.Lib);
}
catch (e) {
this._logger.fatal(
"Failed loading module from " + moduleName + "\n" + this._formatError(e));
this._logger.debug("Stack trace:\n" + e.stack);
}
};
},
_initApp: function CustomBarCore_initApp() {
this._importDependencies(this._libFiles);
var appScript = {};
try {
var mozSSLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader);
mozSSLoader.loadSubScript(this._appChromePath + "content/custombar/bar.js", appScript);
this._appObj = new appScript.BarApplication(this);
}
catch (e) {
this._logger.fatal("Couldn't initialize application. " + this._formatError(e));
this._logger.debug("Stack trace:\n" + Components.stack);
}
this._observerService.addObserver(this, "http-on-modify-request", false);
},
_destroyApp: function CustomBarCore_destroyApp() {
this._observerService.removeObserver(this, "http-on-modify-request");
try {
this._appObj.finalize();
this._appObj = null;
} catch(e) {
this._logger.error(this._formatError(e));
}
},
_shutdown: function CustomBarCore_shutdown(){
},
_formatError: function CustomBarCore_formatError(e) {
if (!(e instanceof Ci.nsIException))
return ("" + e);
let text = e.name + ": " + e.message;
if (e.fileName)
text += "\nin " + e.fileName + "\nat line " + e.lineNumber;
return text;
},
classDescription: "Custom Yandex bar core JS component for " + APP_NAME,
classID: CORE_CLASS_ID,
contractID: CORE_CONTRACT_ID,
QueryInterface: XPCOMUtils.generateQI([Ci.nsISupports, Ci.nsIObserver]),
_xpcom_factory: {
createInstance: function (outer, iid) {
if (outer != null)
throw Components.results.NS_ERROR_NO_AGGREGATION;
if (!this._componentInstance)
this._componentInstance = new CustomBarCore();
return this._componentInstance.QueryInterface(iid);
}
},
_xpcom_categories: [
{
category: "app-startup",
service: true
}
]
};
var components = [CustomBarCore];
function NSGetModule(compMgr, fileSpec) {
return XPCOMUtils.generateModule(components);
}