1 const Cc = Components.classes;
2 const Ci = Components.interfaces;
3 const Cr = Components.results;
4 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
6 function application () {
7 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm", this);
9 this.JSON = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON);
11 this.wrappedJSObject = this;
14 this.loaded_modules = [];
15 this.loading_modules = [];
16 this.module_after_load_functions = new Object();
17 this.pending_loads = [];
20 this.require("conkeror.js");
22 this.dumpln("Error initializing.");
26 application.prototype = {
30 /* Note: resource://app currently doesn't result in xpcnativewrappers=yes */
31 module_uri_prefix: "chrome://conkeror-modules/content/",
32 subscript_loader: Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader),
33 preferences: Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService),
34 dump_error: function (e) {
35 if (e instanceof Error) {
36 this.dumpln(e.name + ": " + e.message);
37 this.dumpln(e.fileName + ":" + e.lineNumber);
39 } else if (e instanceof Ci.nsIException) {
40 this.dumpln(e.name + ": " + e.message);
41 var stack_frame = e.location;
43 this.dumpln(stack_frame.name + "()@" + stack_frame.filename + ":" + stack_frame.lineNumber);
44 stack_frame = stack_frame.caller;
47 this.dumpln("Error: " + e);
50 loaded: function (module) {
51 return (this.loaded_modules.indexOf(module) != -1);
53 provide: function(module) {
54 if (this.loaded_modules.indexOf(module) == -1)
55 this.loaded_modules.push(module);
57 skip_module_load : {},
58 load_module: function(module_name) {
59 if (this.loading_modules.indexOf(module_name) != -1)
60 throw new Error("Circular module dependency detected: "
61 + this.loading_modules.join(" -> ") + " -> " + module_name);
62 this.loading_modules.push(module_name);
64 this.subscript_loader.loadSubScript(this.module_uri_prefix + module_name,
66 this.provide(module_name);
68 if ((funcs = this.module_after_load_functions[module_name]) != null)
70 for (var i = 0; i < funcs.length; ++i)
72 delete this.module_after_load_functions[module_name];
75 catch (e if e == this.skip_module_load) {}
77 if (!(e instanceof Error) && !(e instanceof Ci.nsIException) &&
78 (String(e) == "ContentLength not available (not a local URL?)" ||
79 String(e) == "Error creating channel (invalid URL scheme?)"))
80 throw new Error("Module not found: " + this.module_uri_prefix + module_name + ": " + e);
84 this.loading_modules.pop();
87 if (this.loading_modules.length == 0)
89 while (this.pending_loads.length > 0)
91 this.require(this.pending_loads.pop());
95 require: function (module) {
96 if (!this.loaded(module))
97 this.load_module(module);
99 require_later: function (module) {
100 if (!this.loaded(module)
101 && this.pending_loads.indexOf(module) == -1)
102 this.pending_loads.push(module);
104 call_after_load: function (module, func) {
105 if (this.loaded(module))
110 if (!(funcs = this.module_after_load_functions[module]))
111 funcs = this.module_after_load_functions[module] = [];
115 dumpln: function (line) {
119 version: "$CONKEROR_VERSION$", // preprocessor variable
120 homepage: "chrome://conkeror/content/help.html",
123 QueryInterface: XPCOMUtils.generateQI([]),
125 /* XPCOM registration */
126 classDescription: "Conkeror global object",
127 classID: Components.ID("{72a7eea7-a894-47ec-93a9-a7bc172cf1ac}"),
128 contractID: "@conkeror.mozdev.org/application;1"
131 function NSGetModule(compMgr, fileSpec)
132 XPCOMUtils.generateModule([application]);