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);
8 this.wrappedJSObject = this;
11 this.loaded_modules = [];
12 this.loading_modules = [];
13 this.module_after_load_functions = new Object();
14 this.pending_loads = [];
17 this.require("conkeror.js");
19 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 load_module: function(module_name) {
56 if (this.loading_modules.indexOf(module_name) != -1)
57 throw new Error("Circular module dependency detected: "
58 + this.loading_modules.join(" -> ") + " -> " + module_name);
59 this.loading_modules.push(module_name);
61 this.subscript_loader.loadSubScript(this.module_uri_prefix + module_name,
64 if (!(e instanceof Error) && !(e instanceof Ci.nsIException) &&
65 (String(e) == "ContentLength not available (not a local URL?)" ||
66 String(e) == "Error creating channel (invalid URL scheme?)"))
67 throw new Error("Module not found: " + this.module_uri_prefix + module_name + ": " + e);
70 this.loading_modules.pop();
72 this.provide(module_name);
74 if ((funcs = this.module_after_load_functions[module_name]) != null)
76 for (var i = 0; i < funcs.length; ++i)
78 delete this.module_after_load_functions[module_name];
80 if (this.loading_modules.length == 0)
82 while (this.pending_loads.length > 0)
84 this.require(this.pending_loads.pop());
88 require: function (module) {
89 if (!this.loaded(module))
90 this.load_module(module);
92 require_later: function (module) {
93 if (!this.loaded(module)
94 && this.pending_loads.indexOf(module) == -1)
95 this.pending_loads.push(module);
97 call_after_load: function (module, func) {
98 if (this.loaded(module))
103 if (!(funcs = this.module_after_load_functions[module]))
104 funcs = this.module_after_load_functions[module] = [];
108 dumpln: function (line) {
112 version: "$CONKEROR_VERSION$", // preprocessor variable
113 homepage: "chrome://conkeror/content/help.html",
116 QueryInterface: XPCOMUtils.generateQI([]),
118 /* XPCOM registration */
119 classDescription: "Conkeror global object",
120 classID: Components.ID("{72a7eea7-a894-47ec-93a9-a7bc172cf1ac}"),
121 contractID: "@conkeror.mozdev.org/application;1"
124 function NSGetModule(compMgr, fileSpec)
125 XPCOMUtils.generateModule([application]);