Provide a default value for extensions.update.url
[conkeror.git] / components / application.js
blob5cb6925d7babe4a8be35908ad90f61240bf6b8b9
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;
10     this.conkeror = this;
12     this.loaded_modules = [];
13     this.loading_modules = [];
14     this.module_after_load_functions = new Object();
15     this.pending_loads = [];
17     try {
18         this.require("conkeror.js");
19     } catch (e) {
20         this.dumpln("Error initializing.");
21         this.dump_error(e);
22     }
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     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);
61         try {
62             this.subscript_loader.loadSubScript(this.module_uri_prefix + module_name,
63                                                 this);
64             this.provide(module_name);
65             var funcs;
66             if ((funcs = this.module_after_load_functions[module_name]) != null)
67             {
68                 for (var i = 0; i < funcs.length; ++i)
69                     funcs[i]();
70                 delete this.module_after_load_functions[module_name];
71             }
72         }
73         catch (e if e == this.skip_module_load) {}
74         catch (e) {
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);
79             throw e;
80         }
81         finally {
82             this.loading_modules.pop();
83         }
85         if (this.loading_modules.length == 0)
86         {
87             while (this.pending_loads.length > 0)
88             {
89                 this.require(this.pending_loads.pop());
90             }
91         }
92     },
93     require: function (module) {
94         if (!this.loaded(module))
95             this.load_module(module);
96     },
97     require_later: function (module) {
98         if (!this.loaded(module)
99             && this.pending_loads.indexOf(module) == -1)
100             this.pending_loads.push(module);
101     },
102     call_after_load: function (module, func) {
103         if (this.loaded(module))
104             func();
105         else
106         {
107             var funcs;
108             if (!(funcs = this.module_after_load_functions[module]))
109                 funcs = this.module_after_load_functions[module] = [];
110             funcs.push(func);
111         }
112     },
113     dumpln: function (line) {
114         dump(line + "\n");
115     },
117     version: "$CONKEROR_VERSION$", // preprocessor variable
118     homepage: "chrome://conkeror/content/help.html",
120     /* nsISupports */
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]);