1 /*** -*- Mode: Javascript; tab-width: 2;
3 The contents of this file are subject to the Mozilla Public
4 License Version 1.1 (the "License"); you may not use this file
5 except in compliance with the License. You may obtain a copy of
6 the License at http://www.mozilla.org/MPL/
8 Software distributed under the License is distributed on an "AS
9 IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10 implied. See the License for the specific language governing
11 rights and limitations under the License.
13 The Original Code is jslib team code.
14 The Initial Developer of the Original Code is jslib team.
16 Portions created by jslib team are
17 Copyright (C) 2000 jslib team. All
20 Original Author: Pete Collins <pete@mozdevgroup.com>
21 Contributor(s): Martin Kutschker <Martin.T.Kutschker@blackbox.net>
26 * insure jslib base is not already loaded
28 if (typeof(JS_LIB_LOADED) != "boolean")
32 const JS_LIB_LOADED = true;
34 const JS_LIBRARY = "jslib";
35 const JS_LIB_FILE = "jslib.js"
36 const JS_LIB_PATH = "chrome://beagle/content/jslib/";
37 const JS_LIB_VERSION = "0.1.184-modified";
38 const JS_LIB_AUTHORS = "\tPete Collins <pete@mozdevgroup.com>\n"
39 + "\tNeil Deakin <neil@mozdevgroup.com>\n"
40 + "\tEric Plaster <plaster@urbanrage.com>\n"
41 + "\tMartin.T.Kutschker <Martin.T.Kutschker@blackbox.net>\n";
42 const JS_LIB_BUILD = "mozilla 1.3+";
43 const JS_LIB_ABOUT = "\tThis is an effort to provide a fully "
44 + "functional js library\n"
45 + "\tfor mozilla package authors to use "
46 + "in their applications\n";
47 const JS_LIB_HOME = "http://jslib.mozdev.org/";
52 const jslibRes = C.results;
53 const jslibI = C.interfaces;
55 const JS_LIB_OK = jslibRes.NS_OK;
58 const jslib_results = jslibRes;
60 if (typeof(JS_LIB_DEBUG) != "boolean")
61 var JS_LIB_DEBUG = ON;
63 var JS_LIB_DEBUG_ALERT = OFF;
64 var JS_LIB_ERROR = ON;
65 var JS_LIB_ERROR_ALERT = OFF;
67 const JS_LIB_HELP = "\n\nWelcome to jslib version "+JS_LIB_VERSION+"\n\n"
68 + "Global Constants:\n\n"
69 + "JS_LIBRARY \n\t"+JS_LIBRARY +"\n"
70 + "JS_LIB_FILE \n\t"+JS_LIB_FILE +"\n"
71 + "JS_LIB_PATH \n\t"+JS_LIB_PATH +"\n"
72 + "JS_LIB_VERSION \n\t"+JS_LIB_VERSION +"\n"
73 + "JS_LIB_AUTHORS \n" +JS_LIB_AUTHORS
74 + "JS_LIB_BUILD \n\t"+JS_LIB_BUILD +"\n"
75 + "JS_LIB_ABOUT \n" +JS_LIB_ABOUT
76 + "JS_LIB_HOME \n\t"+JS_LIB_HOME +"\n\n"
77 + "Global Variables:\n\n"
78 + " JS_LIB_DEBUG\n JS_LIB_ERROR\n\n";
81 function jslibGetService (aURL, aInterface)
85 // determine how 'aInterface' is passed and handle accordingly
86 switch (typeof(aInterface))
89 rv = C.classes[aURL].getService(aInterface);
93 rv = C.classes[aURL].getService(C.interfaces[aInterface]);
97 rv = C.classes[aURL].getService();
106 function jslibCreateInstance (aURL, aInterface)
110 rv = C.classes[aURL].createInstance(C.interfaces[aInterface]);
117 function jslibGetInterface (aInterface)
121 rv = C.interfaces[aInterface];
128 function jslibQI (aObj, aInterface)
131 return aObj.QueryInterface(C.interfaces[aInterface]);
133 throw ("Unable to QI " + aObj + " to " + aInterface);
137 /****************************************************************
138 * void include(aScriptPath) *
139 * aScriptPath is an argument of string lib chrome path *
140 * returns NS_OK on success, 1 if file is already loaded and *
141 * - errorno or throws exception on failure *
143 * var path='chrome://jslib/content/io/file.js'; *
146 * include(jslib_file); *
148 * outputs: void(null) *
149 ****************************************************************/
151 function include (aScriptPath)
154 dump("include: Missing file path argument\n");
155 throw - jslibRes.NS_ERROR_XPC_NOT_ENOUGH_ARGS;
158 if (aScriptPath == JS_LIB_PATH+JS_LIB_FILE) {
159 dump("include: "+aScriptPath+" is already loaded!\n");
160 throw - jslibRes.NS_ERROR_INVALID_ARG;
163 var start = aScriptPath.lastIndexOf('/') + 1;
164 var end = aScriptPath.lastIndexOf('.');
165 var slice = aScriptPath.length - end;
166 var loadID = aScriptPath.substring(start, (aScriptPath.length - slice));
168 if (typeof(this['JS_'+loadID.toUpperCase()+'_LOADED']) == "boolean")
169 return jslibRes.NS_OK;
173 if (jslibNeedsPrivs())
174 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
175 jslibGetService("@mozilla.org/moz/jssubscript-loader;1",
176 "mozIJSSubScriptLoader").loadSubScript(aScriptPath);
178 dump("include: "+aScriptPath+"\n");
180 const msg = aScriptPath+" is not a valid path or is already loaded\n";
182 dump("include: "+msg+"\n");
183 rv = - jslibRes.NS_ERROR_INVALID_ARG;
188 function jslibNeedsPrivs ()
191 if (typeof(this.location) == "object") {
192 var proto = this.location.protocol;
193 rv = (proto == "file:")
198 // include debug methods
199 const jslib_debug = JS_LIB_PATH+'debug/debug.js';
200 include(jslib_debug);
202 function jslibUninstall (aPackage, aCallback)
205 throw - jslibRes.NS_ERROR_INVALID_ARG;
207 include (jslib_window);
208 var win = new CommonWindow(null, 400, 400);
209 win.position = JS_MIDDLE_CENTER;
210 win.openUninstallWindow(aPackage, aCallback);
213 /*********** Launch JSLIB Splash ***************/
214 function jslibLaunchSplash ()
216 include (jslib_window);
217 var win = new CommonWindow("chrome://jslib/content/splash.xul", 400, 220);
218 win.position = JS_MIDDLE_CENTER;
223 function jslib_turnDumpOn () { jslibTurnDumpOn(); }
225 function jslibTurnDumpOn ()
227 include (jslib_prefs);
229 var pref = new Prefs();
230 const prefStr = "browser.dom.window.dump.enabled"
232 // turn dump on if not enabled
233 if (!pref.getBool(prefStr)) {
234 pref.setBool(prefStr, true);
241 function jslib_turnDumpOff () { jslibTurnDumpOff(); }
243 function jslibTurnDumpOff ()
245 include (jslib_prefs);
247 var pref = new Prefs();
248 const prefStr = "browser.dom.window.dump.enabled"
250 // turn dump off if enabled
251 if (pref.getBool(prefStr)) {
252 pref.setBool(prefStr, false);
258 const jslib_modules = JS_LIB_PATH+'modules.js';
259 include (jslib_modules);
263 } // end jslib load test