Delete file user_variables.js (duplicates content in utils.js)
[conkeror.git] / components / application.js
blobaa28a1387890d04e9d44bc541eca583f03a3acdc
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;
9     this.conkeror = this;
11     this.loaded_modules = [];
12     this.loading_modules = [];
13     this.module_after_load_functions = new Object();
14     this.pending_loads = [];
16     try {
17         this.require("conkeror.js");
18     } catch (e) {
19         this.dumpln("Error initializing.");
20         this.dump_error(e);
21     }
24 application.prototype = {
25     Cc: Cc,
26     Ci: Ci,
27     Cr: Cr,
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);
36             dump(e.stack);
37         } else if (e instanceof Ci.nsIException) {
38             this.dumpln(e.name + ": " + e.message);
39             var stack_frame = e.location;
40             while (stack_frame) {
41                 this.dumpln(stack_frame.name + "()@" + stack_frame.filename + ":" + stack_frame.lineNumber);
42                 stack_frame = stack_frame.caller;
43             }
44         } else {
45             this.dumpln("Error: " + e);
46         }
47     },
48     loaded: function (module) {
49         return (this.loaded_modules.indexOf(module) != -1);
50     },
51     provide: function(module) {
52         if (this.loaded_modules.indexOf(module) == -1)
53             this.loaded_modules.push(module);
54     },
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);
60         try {
61             this.subscript_loader.loadSubScript(this.module_uri_prefix + module_name,
62                                                 this);
63         } catch (e) {
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);
68             throw e;
69         } finally {
70             this.loading_modules.pop();
71         }
72         this.provide(module_name);
73         var funcs;
74         if ((funcs = this.module_after_load_functions[module_name]) != null)
75         {
76             for (var i = 0; i < funcs.length; ++i)
77                 funcs[i]();
78             delete this.module_after_load_functions[module_name];
79         }
80         if (this.loading_modules.length == 0)
81         {
82             while (this.pending_loads.length > 0)
83             {
84                 this.require(this.pending_loads.pop());
85             }
86         }
87     },
88     require: function (module) {
89         if (!this.loaded(module))
90             this.load_module(module);
91     },
92     require_later: function (module) {
93         if (!this.loaded(module)
94             && this.pending_loads.indexOf(module) == -1)
95             this.pending_loads.push(module);
96     },
97     call_after_load: function (module, func) {
98         if (this.loaded(module))
99             func();
100         else
101         {
102             var funcs;
103             if (!(funcs = this.module_after_load_functions[module]))
104                 funcs = this.module_after_load_functions[module] = [];
105             funcs.push(func);
106         }
107     },
108     dumpln: function (line) {
109         dump(line + "\n");
110     },
112     version: "$CONKEROR_VERSION$", // preprocessor variable
113     homepage: "chrome://conkeror/content/help.html",
115     /* nsISupports */
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]);