-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbootstrap.js
171 lines (144 loc) · 6.15 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
/*
This file is originally developed by pdf.js
https://github.com/mozilla/pdf.js
Copyright (c) 2011 Mozilla Foundation
Contributors: Andreas Gal <[email protected]>
Chris G Jones <[email protected]>
Shaon Barman <[email protected]>
Vivien Nicolas <[email protected]>
Justin D'Arcangelo <[email protected]>
Yury Delendik
Kalervo Kujala
Adil Allawi <@ironymark>
Jakob Miland <[email protected]>
Artur Adib <[email protected]>
Brendan Dahl <[email protected]>
David Quintana <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Some codes are modified by u881831 <[email protected]>
*/
'use strict';
const RESOURCE_NAME = 'pcmanfx2';
let Cc = Components.classes;
let Ci = Components.interfaces;
let Cm = Components.manager;
let Cu = Components.utils;
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
Cu.import('resource://gre/modules/Services.jsm');
function log(str) {
Services.console.logStringMessage(str + '\n');
}
// for multiple component registrations. Only the wrapper is written by u881831
function createFactory() {
// Register/unregister a constructor as a component.
let Factory = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory]),
_targetConstructor: null,
register: function register(targetConstructor) {
this._targetConstructor = targetConstructor;
var proto = targetConstructor.prototype;
var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
registrar.registerFactory(proto.classID, proto.classDescription,
proto.contractID, this);
},
unregister: function unregister() {
var proto = this._targetConstructor.prototype;
var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
registrar.unregisterFactory(proto.classID, this);
this._targetConstructor = null;
},
// nsIFactory
createInstance: function createInstance(aOuter, iid) {
if (aOuter !== null)
throw Cr.NS_ERROR_NO_AGGREGATION;
return (new (this._targetConstructor)).QueryInterface(iid);
},
// nsIFactory
lockFactory: function lockFactory(lock) {
// No longer used as of gecko 1.7.
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
}
};
return Factory;
}
let Factories = {};
let protocolHandlerUrl = null;
// quit or refresh tabs after uninstalling or upgrading this addon
// created by u881831
function refreshTabs(close) {
var browserEnumerator = Cc["@mozilla.org/appshell/window-mediator;1"]
.getService(Ci.nsIWindowMediator)
.getEnumerator("navigator:browser");
while (browserEnumerator.hasMoreElements()) {
var tabsBrowser = browserEnumerator.getNext().gBrowser;
for (var index = tabsBrowser.browsers.length-1; index >= 0; index--) {
var loc = tabsBrowser.getBrowserAtIndex(index).contentDocument.location;
var protocol = loc.protocol.toLowerCase();
if (protocol == 'telnet:') {
if (close)
loc.href = 'about:blank'; // able to use BACK after reinstalling
else
loc.reload();
}
}
}
// stringbundle is cached by firefox before restarting by default
Cc["@mozilla.org/intl/stringbundle;1"]
.getService(Ci.nsIStringBundleService)
.flushBundles();
}
// As of Firefox 13 bootstrapped add-ons don't support automatic registering and
// unregistering of resource urls and components/contracts. Until then we do
// it programatically. See ManifestDirective ManifestParser.cpp for support.
function startup(aData, aReason) {
// Setup the resource url.
var ioService = Services.io;
var resProt = ioService.getProtocolHandler('resource')
.QueryInterface(Ci.nsIResProtocolHandler);
var aliasURI = ioService.newURI('modules/', 'UTF-8', aData.resourceURI);
resProt.setSubstitution(RESOURCE_NAME, aliasURI);
// Load the component and register it.
protocolHandlerUrl = aData.resourceURI.spec + 'components/TelnetProtocol.js';
Cu.import(protocolHandlerUrl);
Factories['telnet'] = createFactory();
Factories['telnet'].register(Protocol);
refreshTabs(); // only for upgrading
}
function shutdown(aData, aReason) {
if (aReason == APP_SHUTDOWN)
return;
var ioService = Services.io;
var resProt = ioService.getProtocolHandler('resource')
.QueryInterface(Ci.nsIResProtocolHandler);
// Remove the resource url.
resProt.setSubstitution(RESOURCE_NAME, null);
// Remove the contract/component.
Factories['telnet'].unregister();
// Unload the protocol handler
Cu.unload(protocolHandlerUrl);
protocolHandlerUrl = null;
// quit existing telnet page
if(aReason != ADDON_UPGRADE && aReason != ADDON_DOWNGRADE)
refreshTabs(true); // uninstall
//FIXME: close preferences dialogs and others opened by this addon
}
function install(aData, aReason) {
}
function uninstall(aData, aReason) {
}