1 /* coded by Ketmar // Invisible Vector (psyc://ketmar.no-ip.org/~Ketmar)
2 * Understanding is not required. Only obedience.
4 * This program is free software. It comes without any warranty, to
5 * the extent permitted by applicable law. You can redistribute it
6 * and/or modify it under the terms of the Do What The Fuck You Want
7 * To Public License, Version 2, as published by Sam Hocevar. See
8 * http://www.wtfpl.net/txt/copying/ for more details.
10 const {interfaces: Ci, utils: Cu, classes: Cc} = Components;
11 Cu.import("resource://gre/modules/Services.jsm", this);
14 ////////////////////////////////////////////////////////////////////////////////
23 let guerillaOptions = {
28 ////////////////////////////////////////////////////////////////////////////////
30 const conService = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
32 function logError () {
33 if (arguments.length) {
35 for (let idx = 0; idx < arguments.length; ++idx) {
36 //if (idx > 0) s += "\n";
37 s += ""+arguments[idx];
39 Cu.reportError(s.replace(/\0/g, ""));
43 // https://developer.mozilla.org/en-US/docs/XPCOM_Interface_Reference/nsIConsoleService#logStringMessage() - wstring / wide string
45 if (debugOptions.logEnabled && arguments.length) {
47 for (let idx = 0; idx < arguments.length; ++idx) {
48 //if (idx > 0) s += "\n";
49 s += ""+arguments[idx];
51 conService.logStringMessage(s.replace(/\0/g, ""));
56 ////////////////////////////////////////////////////////////////////////////////
57 let baseUriSpec = __SCRIPT_URI_SPEC__.substr(0, __SCRIPT_URI_SPEC__.length-"bootstrap.js".length);
58 function getResourceURI (filePath) { return baseUriSpec+filePath; }
61 ////////////////////////////////////////////////////////////////////////////////
62 function alert (str) {
63 let ps = Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService);
64 ps.alert(null, "Guerilla", ""+str);
68 ////////////////////////////////////////////////////////////////////////////////
70 // includes a javascript file with loadSubScript
71 global.include = function (src) {
73 Components.utils.import("resource://gre/modules/Services.jsm", o);
74 let uri = o.Services.io.newURI("includes/"+src, null, o.Services.io.newURI(baseUriSpec, null, null));
76 o.Services.scriptloader.loadSubScript(uri.spec, global);
78 logError("INCLUDE ERROR "+e.name+": "+e.message)
88 ////////////////////////////////////////////////////////////////////////////////
90 global.locale = Cc["@mozilla.org/chrome/chrome-registry;1"].getService(Ci.nsIXULChromeRegistry).getSelectedLocale("global");
92 // imports a commonjs style javascript file with loadSubScrpt
93 let modules = {}; // list of loaded modules
95 global.require = function (src) {
96 if (modules[src]) return modules[src];
97 // functions available to modules
99 global: global, // just in case
101 oneShotTimer: global.oneShotTimer,
102 debugOptions: global.debugOptions,
103 guerillaOptions: global.guerillaOptions,
104 require: global.require,
105 locale: global.locale,
106 logError: global.logError,
107 conlog: global.conlog,
108 getResourceURI: global.getResourceURI,
109 getUserJSDir: global.getUserJSDir,
110 getPrefLibDir: global.getPrefLibDir,
111 getUserDBDir: global.getUserDBDir,
112 getGuerillaPref: global.getGuerillaPref,
116 if (global.scacheAPI) scope.scacheAPI = scacheAPI;
118 Components.utils.import("resource://gre/modules/Services.jsm", tools);
120 let uri = tools.Services.io.newURI("modules/"+src, null, tools.Services.io.newURI(baseUriSpec, null, null));
121 tools.Services.scriptloader.loadSubScript(uri.spec, scope);
123 logError("REQUIRE ERROR "+e.name+": "+e.message)
128 modules[src] = scope.exports;
129 return scope.exports;
134 ////////////////////////////////////////////////////////////////////////////////
135 let scacheAPI = require("scriptcache.js");
136 let {wlRegister, wlUnregister, deinitInjectorStorage} = require("injector.js");
139 ////////////////////////////////////////////////////////////////////////////////
140 let {gcliInit, gcliDeinit} = require("concmd.js");
143 ////////////////////////////////////////////////////////////////////////////////
144 // ADDON_INSTALL, ADDON_UPGRADE, or ADDON_DOWNGRADE
145 function install (data, reason) {}
148 // ADDON_UNINSTALL, ADDON_UPGRADE, or ADDON_DOWNGRADE
149 function uninstall (data, reason) {}
152 ////////////////////////////////////////////////////////////////////////////////
153 // APP_STARTUP, ADDON_ENABLE, ADDON_INSTALL, ADDON_UPGRADE, or ADDON_DOWNGRADE
154 function startup (data, reason) {
155 //scacheAPI.validate();
156 setDefaultPrefs(); // always set the default prefs as they disappear on restart
163 // APP_SHUTDOWN, ADDON_DISABLE, ADDON_UNINSTALL, ADDON_UPGRADE, or ADDON_DOWNGRADE
164 function shutdown (data, reason) {
165 deinitInjectorStorage();
166 //if (reason == APP_SHUTDOWN) return;