utils.js: send_http_request: eliminate some warnings
[conkeror.git] / components / application.js
blobc5c5b2ddce16a28336a67b99817d6b4b59af8a8d
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;
12     this.conkeror = this;
14     this.loaded_modules = [];
15     this.loading_modules = [];
16     this.module_after_load_functions = new Object();
17     this.pending_loads = [];
19     try {
20         this.require("conkeror.js");
21     } catch (e) {
22         this.dumpln("Error initializing.");
23         this.dump_error(e);
24     }
26 application.prototype = {
27     Cc: Cc,
28     Ci: Ci,
29     Cr: Cr,
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);
38             dump(e.stack);
39         } else if (e instanceof Ci.nsIException) {
40             this.dumpln(e.name + ": " + e.message);
41             var stack_frame = e.location;
42             while (stack_frame) {
43                 this.dumpln(stack_frame.name + "()@" + stack_frame.filename + ":" + stack_frame.lineNumber);
44                 stack_frame = stack_frame.caller;
45             }
46         } else {
47             this.dumpln("Error: " + e);
48         }
49     },
50     loaded: function (module) {
51         return (this.loaded_modules.indexOf(module) != -1);
52     },
53     provide: function(module) {
54         if (this.loaded_modules.indexOf(module) == -1)
55             this.loaded_modules.push(module);
56     },
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);
63         try {
64             this.subscript_loader.loadSubScript(this.module_uri_prefix + module_name,
65                                                 this);
66             this.provide(module_name);
67             var funcs;
68             if ((funcs = this.module_after_load_functions[module_name]) != null)
69             {
70                 for (var i = 0; i < funcs.length; ++i)
71                     funcs[i]();
72                 delete this.module_after_load_functions[module_name];
73             }
74         }
75         catch (e if e == this.skip_module_load) {}
76         catch (e) {
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);
81             throw e;
82         }
83         finally {
84             this.loading_modules.pop();
85         }
87         if (this.loading_modules.length == 0)
88         {
89             while (this.pending_loads.length > 0)
90             {
91                 this.require(this.pending_loads.pop());
92             }
93         }
94     },
95     require: function (module) {
96         if (!this.loaded(module))
97             this.load_module(module);
98     },
99     require_later: function (module) {
100         if (!this.loaded(module)
101             && this.pending_loads.indexOf(module) == -1)
102             this.pending_loads.push(module);
103     },
104     call_after_load: function (module, func) {
105         if (this.loaded(module))
106             func();
107         else
108         {
109             var funcs;
110             if (!(funcs = this.module_after_load_functions[module]))
111                 funcs = this.module_after_load_functions[module] = [];
112             funcs.push(func);
113         }
114     },
115     dumpln: function (line) {
116         dump(line + "\n");
117     },
119     version: "$CONKEROR_VERSION$", // preprocessor variable
120     homepage: "chrome://conkeror/content/help.html",
122     /* nsISupports */
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]);