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.wrappedJSObject = this;
12 this.loaded_modules = [];
13 this.loading_modules = [];
14 this.module_after_load_functions = new Object();
15 this.pending_loads = [];
18 this.require("conkeror.js");
20 this.dumpln("Error initializing.");
24 application.prototype = {
28 /* Note: resource://app currently doesn't result in xpcnativewrappers=yes */
29 module_uri_prefix: "chrome://conkeror-modules/content/",
30 subscript_loader: Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader),
31 preferences: Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService),
32 dump_error: function (e) {
33 if (e instanceof Error) {
34 this.dumpln(e.name + ": " + e.message);
35 this.dumpln(e.fileName + ":" + e.lineNumber);
37 } else if (e instanceof Ci.nsIException) {
38 this.dumpln(e.name + ": " + e.message);
39 var stack_frame = e.location;
41 this.dumpln(stack_frame.name + "()@" + stack_frame.filename + ":" + stack_frame.lineNumber);
42 stack_frame = stack_frame.caller;
45 this.dumpln("Error: " + e);
48 loaded: function (module) {
49 return (this.loaded_modules.indexOf(module) != -1);
51 provide: function(module) {
52 if (this.loaded_modules.indexOf(module) == -1)
53 this.loaded_modules.push(module);
55 skip_module_load : {},
56 load_module: function(module_name) {
57 if (this.loading_modules.indexOf(module_name) != -1)
58 throw new Error("Circular module dependency detected: "
59 + this.loading_modules.join(" -> ") + " -> " + module_name);
60 this.loading_modules.push(module_name);
62 this.subscript_loader.loadSubScript(this.module_uri_prefix + module_name,
64 this.provide(module_name);
66 if ((funcs = this.module_after_load_functions[module_name]) != null)
68 for (var i = 0; i < funcs.length; ++i)
70 delete this.module_after_load_functions[module_name];
73 catch (e if e == this.skip_module_load) {}
75 if (!(e instanceof Error) && !(e instanceof Ci.nsIException) &&
76 (String(e) == "ContentLength not available (not a local URL?)" ||
77 String(e) == "Error creating channel (invalid URL scheme?)"))
78 throw new Error("Module not found: " + this.module_uri_prefix + module_name + ": " + e);
82 this.loading_modules.pop();
85 if (this.loading_modules.length == 0)
87 while (this.pending_loads.length > 0)
89 this.require(this.pending_loads.pop());
93 require: function (module) {
94 if (!this.loaded(module))
95 this.load_module(module);
97 require_later: function (module) {
98 if (!this.loaded(module)
99 && this.pending_loads.indexOf(module) == -1)
100 this.pending_loads.push(module);
102 call_after_load: function (module, func) {
103 if (this.loaded(module))
108 if (!(funcs = this.module_after_load_functions[module]))
109 funcs = this.module_after_load_functions[module] = [];
113 dumpln: function (line) {
117 version: "$CONKEROR_VERSION$", // preprocessor variable
118 homepage: "chrome://conkeror/content/help.html",
121 QueryInterface: XPCOMUtils.generateQI([]),
123 /* XPCOM registration */
124 classDescription: "Conkeror global object",
125 classID: Components.ID("{72a7eea7-a894-47ec-93a9-a7bc172cf1ac}"),
126 contractID: "@conkeror.mozdev.org/application;1"
129 function NSGetModule(compMgr, fileSpec)
130 XPCOMUtils.generateModule([application]);