-
Notifications
You must be signed in to change notification settings - Fork 8
/
bootstrap.js
102 lines (79 loc) · 3.34 KB
/
bootstrap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* See license.txt for terms of usage */
// ********************************************************************************************* //
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const Cm = Components.manager;
Cm.QueryInterface(Ci.nsIComponentRegistrar);
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/AddonManager.jsm");
const MY_URL = "resource://ccdump/";
// ********************************************************************************************* //
// Bootstrap API
var global = this;
function startup(aData, aReason)
{
var resource = Services.io.getProtocolHandler("resource").
QueryInterface(Ci.nsIResProtocolHandler);
resource.setSubstitution("ccdump", aData.resourceURI);
Cm.registerFactory(AboutCC.prototype.classID,
AboutCC.prototype.classDescription,
AboutCC.prototype.contractID,
AboutCCFactory);
}
function shutdown(aData, aReason)
{
if (aReason == APP_SHUTDOWN)
return;
var resource = Services.io.getProtocolHandler("resource").QueryInterface(Ci.nsIResProtocolHandler);
resource.setSubstitution("ccdump", null);
Cm.unregisterFactory(AboutCC.prototype.classID, AboutCCFactory);
}
function install(aData, aReason)
{
// xxxHonza: open about:ccdump for the first time?
}
function uninstall(aData, aReason)
{
}
// ********************************************************************************************* //
// about:ccdump
function AboutCC()
{
}
AboutCC.prototype =
{
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]),
classDescription: "about:ccdump",
classID: Components.ID("{D5889F72-0F01-4aee-9B88-FEACC5038C34}"),
contractID: "@mozilla.org/network/protocol/about;1?what=ccdump",
newChannel: function(uri)
{
// The module loader is synchronous so, make sure that the <div id="content">
// is defined before main.js is included. This element represents the entire
// application UI
var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var html = 'data:text/html,<!DOCTYPE html><html><head>\n'
+ '<link href="' + MY_URL + 'skin/classic/main.css" rel="stylesheet" type="text/css">\n'
+ '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">\n'
+ '<script src="' + MY_URL + 'content/loader.js" type="application/javascript;version=1.8"></script>\n'
+ '</head><body>\n'
+ "<div id='content'></div>\n"
+ '<script src="' + MY_URL + 'content/main.js" type="application/javascript;version=1.8"></script>\n'
+ "</body></html>\n";
var securityManager = Cc["@mozilla.org/scriptsecuritymanager;1"].
getService(Ci.nsIScriptSecurityManager);
var principal = securityManager.getSystemPrincipal();
var channel = ioService.newChannel(html, null, null);
channel.originalURI = uri;
channel.owner = principal;
return channel;
},
getURIFlags: function(uri)
{
return Ci.nsIAboutModule.ALLOW_SCRIPT;
}
}
const AboutCCFactory = XPCOMUtils.generateNSGetFactory([AboutCC])(AboutCC.prototype.classID);
// ********************************************************************************************* //