@@ -6,53 +6,13 @@ Cu.import("resource://gre/modules/AddonManager.jsm");
6
6
7
7
const branch = "extensions.ublock0-updater." ;
8
8
const XMLHttpRequest = CC ( "@mozilla.org/xmlextras/xmlhttprequest;1" , "nsIXMLHttpRequest" ) ;
9
- const u0id = "[email protected] " , u0Data = `<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
10
- <RDF:Description about="urn:mozilla:extension:[email protected] ">
11
- <em:updates>
12
- <RDF:Seq>
13
- <RDF:li>
14
- <RDF:Description>
15
- <em:version>%VERSION%</em:version>
16
- <em:targetApplication>
17
- <RDF:Description>
18
- <em:id>{8de7fcbb-c55c-4fbe-bfc5-fc555c87dbc4}</em:id>
19
- <em:minVersion>27.0.0</em:minVersion>
20
- <em:maxVersion>28.*</em:maxVersion>
21
- <em:updateLink>https://github.com/gorhill/uBlock-for-firefox-legacy/releases/download/firefox-legacy-%VERSION%/uBlock0.firefox-legacy.xpi</em:updateLink>
22
- </RDF:Description>
23
- </em:targetApplication>
24
- <em:targetApplication>
25
- <RDF:Description>
26
- <em:id>{92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}</em:id>
27
- <em:minVersion>2.40</em:minVersion>
28
- <em:maxVersion>*</em:maxVersion>
29
- <em:updateLink>https://github.com/gorhill/uBlock-for-firefox-legacy/releases/download/firefox-legacy-%VERSION%/uBlock0.firefox-legacy.xpi</em:updateLink>
30
- </RDF:Description>
31
- </em:targetApplication>
32
- <em:targetApplication>
33
- <RDF:Description>
34
- <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
35
- <em:minVersion>45.0</em:minVersion>
36
- <em:maxVersion>56.*</em:maxVersion>
37
- <em:updateLink>https://github.com/gorhill/uBlock-for-firefox-legacy/releases/download/firefox-legacy-%VERSION%/uBlock0.firefox-legacy.xpi</em:updateLink>
38
- </RDF:Description>
39
- </em:targetApplication>
40
- <em:targetApplication>
41
- <RDF:Description>
42
- <em:id>{3550f703-e582-4d05-9a08-453d09bdfdc6}</em:id>
43
- <em:minVersion>38.0</em:minVersion>
44
- <em:maxVersion>*</em:maxVersion>
45
- <em:updateLink>https://github.com/gorhill/uBlock-for-firefox-legacy/releases/download/firefox-legacy-%VERSION%/uBlock0.firefox-legacy.xpi</em:updateLink>
46
- </RDF:Description>
47
- </em:targetApplication>
48
- </RDF:Description>
49
- </RDF:li>
50
- </RDF:Seq>
51
- </em:updates>
52
- </RDF:Description>
53
- </RDF:RDF>` ;
9
+
10
+ const u0updateURL = 'https://raw.githubusercontent.com/gorhill/uBlock-for-firefox-legacy/master/dist/update/update.xml' ;
11
+ const versionMask = / < e m : v e r s i o n > ( \d + \. \d + \. \d + (?: \. \d + ) ? ) < \/ e m : v e r s i o n > / ;
12
+ const emptyData = '<?xml version="1.0" encoding="UTF-8"?>' +
13
+ '<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#"></RDF:RDF>' ;
54
14
55
- var u0Beta = false , u0Ver = "" ;
15
+ var u0Data = "" , u0Ver = "" ;
56
16
57
17
var httpObserver = {
58
18
observe : function ( subject , topic , data ) {
@@ -68,6 +28,8 @@ var httpObserver = {
68
28
subject . QueryInterface ( Ci . nsITraceableChannel ) ;
69
29
var newListener = new TracingListener ( ) ;
70
30
newListener . originalListener = subject . setNewListener ( newListener ) ;
31
+ } else if ( subject . URI . spec == u0updateURL ) {
32
+ selfDestruct ( ) ;
71
33
}
72
34
}
73
35
} ,
@@ -110,11 +72,11 @@ TracingListener.prototype = {
110
72
}
111
73
} ,
112
74
onStopRequest : function ( request , context , statusCode ) {
113
- var data = '<?xml version="1.0" encoding="UTF-8"?>' ;
114
- if ( u0Ver != "" ) {
115
- data + = u0Data . replace ( / % V E R S I O N % / g , u0Ver ) ;
75
+ var data ;
76
+ if ( u0Ver != "" && u0Data != "" ) {
77
+ data = u0Data ;
116
78
} else {
117
- data += '<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#"></RDF:RDF>' ;
79
+ data = emptyData ;
118
80
}
119
81
var storageStream = CCIN ( "@mozilla.org/storagestream;1" , "nsIStorageStream" ) ;
120
82
storageStream . init ( 8192 , data . length , null ) ;
@@ -139,36 +101,19 @@ TracingListener.prototype = {
139
101
}
140
102
}
141
103
142
- var prefObserver = {
143
- observe : function ( subject , topic , data ) {
144
- if ( topic == "nsPref:changed" && data == "u0Beta" ) {
145
- u0Beta = Services . prefs . getBranch ( branch ) . getBoolPref ( "u0Beta" ) ;
146
- u0Ver = "" ;
147
- AddonManager . getAllInstalls ( function ( aList ) {
148
- for ( var addon of aList ) {
149
- if ( addon . existingAddon && addon . existingAddon . id == u0id ) {
150
- addon . cancel ( ) ;
151
- }
152
- }
153
- } )
154
- }
155
- } ,
156
- register : function ( ) {
157
- this . prefBranch = Services . prefs . getBranch ( branch ) ;
158
- this . prefBranch . addObserver ( "" , this , false ) ;
159
- } ,
160
- unregister : function ( ) {
161
- this . prefBranch . removeObserver ( "" , this ) ;
162
- }
163
- }
164
-
165
104
function doUpdate ( newVer ) {
166
105
if ( newVer != u0Ver ) {
167
106
u0Ver = newVer ;
107
+ var updateInstallListener = {
108
+ onInstallEnded : function ( aInstall , aAddon ) {
109
+ selfDestruct ( ) ;
110
+ }
111
+ }
168
112
AddonManager . getAddonByID ( u0id , function ( addon ) {
169
113
addon . findUpdates ( {
170
114
onUpdateAvailable : function ( aAddon , aInstall ) {
171
115
if ( aAddon . permissions & AddonManager . PERM_CAN_UPGRADE && AddonManager . shouldAutoUpdate ( aAddon ) ) {
116
+ aInstall . addListener ( updateInstallListener ) ;
172
117
aInstall . install ( ) ;
173
118
}
174
119
}
@@ -178,65 +123,55 @@ function doUpdate(newVer) {
178
123
}
179
124
180
125
function checkUpdate ( ) {
181
- var ver , vermask , request = new XMLHttpRequest ( ) ;
182
- if ( u0Beta ) {
183
- vermask = / t r e e \/ f i r e f o x \- l e g a c y \- ( \d + ( \. \w + ) + ) / ;
184
- } else {
185
- vermask = / t r e e \/ f i r e f o x \- l e g a c y \- ( \d + \. \d + \. \d + (?: \. \d + ) ? ) / ;
186
- }
187
- request . open ( "GET" , "https://github.com/gorhill/uBlock-for-firefox-legacy/refs-tags/master?source_action=disambiguate&source_controller=files&tag_name=firefox-legacy&q=firefox-legacy" ) ;
126
+ var ver , request = new XMLHttpRequest ( ) ;
127
+ request . open ( "GET" , u0updateURL + "?_=self" ) ;
188
128
request . onload = function ( ) {
189
- if ( ( ver = vermask . exec ( request . responseText ) ) !== null ) {
129
+ if ( ( ver = versionMask . exec ( request . responseText ) ) !== null ) {
130
+ u0Data = request . responseText ;
190
131
doUpdate ( ver [ 1 ] ) ;
191
132
}
192
133
}
193
134
request . send ( ) ;
194
135
}
195
136
196
- var selfDestruct = {
197
- run : function ( wait ) {
198
- var mrw = Services . wm . getMostRecentWindow ( "navigator:browser" ) ;
199
- if ( mrw && typeof mrw . getBrowser === "function" ) {
200
- mrw . getBrowser ( ) . loadOneTab ( "https://github.com/JustOff/ublock0-updater/issues/112?goodbye" , { inBackground : true } ) ;
201
- AddonManager . getAddonByID ( "[email protected] " , function ( addon ) {
202
- addon . uninstall ( ) ;
203
- } ) ;
204
- } else if ( wait ) {
205
- Services . obs . addObserver ( this , "sessionstore-windows-restored" , false ) ;
206
- } else {
207
- Cu . reportError ( "uBlock Origin Updater: Something went wrong." ) ;
137
+ function selfDestruct ( ) {
138
+ AddonManager . getAddonByID ( u0id , function ( addon ) {
139
+ if ( addon && Services . vc . compare ( addon . version , "1.16.4.17" ) >= 0 ) {
140
+ var goodbay = false , goodbayUrl = "https://github.com/JustOff/ublock0-updater/issues/112?_=goodbye-" ,
141
+ appInfo = Cc [ "@mozilla.org/xre/app-info;1" ] . getService ( Ci . nsIXULAppInfo ) ;
142
+ if ( appInfo . ID == "{3550f703-e582-4d05-9a08-453d09bdfdc6}" ) {
143
+ var mrw = Services . wm . getMostRecentWindow ( "mail:3pane" ) ;
144
+ if ( mrw && typeof mrw . openLinkExternally === "function" ) {
145
+ mrw . openLinkExternally ( goodbayUrl + "mail" ) ;
146
+ goodbay = true ;
147
+ }
148
+ } else {
149
+ var mrw = Services . wm . getMostRecentWindow ( "navigator:browser" ) ;
150
+ if ( mrw && typeof mrw . getBrowser === "function" ) {
151
+ mrw . getBrowser ( ) . loadOneTab ( goodbayUrl + "browser" , { inBackground : true } ) ;
152
+ goodbay = true ;
153
+ }
154
+ }
155
+ if ( goodbay ) {
156
+ AddonManager . getAddonByID ( selfId , function ( addon ) {
157
+ addon . uninstall ( ) ;
158
+ } ) ;
159
+ }
208
160
}
209
- } ,
210
- observe : function ( subject , topic , data ) {
211
- if ( topic != "sessionstore-windows-restored" ) { return ; }
212
- Services . obs . removeObserver ( this , "sessionstore-windows-restored" ) ;
213
- this . run ( false /* no wait */ ) ;
214
- }
215
- }
216
-
217
- function sayGoodbye ( ) {
161
+ } ) ;
218
162
}
219
163
220
164
function startup ( data , reason ) {
221
165
try {
222
- u0Beta = Services . prefs . getBranch ( branch ) . getBoolPref ( "u0Beta" ) ;
166
+ Services . prefs . getBranch ( branch ) . clearUserPref ( "u0Beta" ) ;
223
167
} catch ( e ) { }
224
- AddonManager . getAddonByID ( "[email protected] " , function ( addon ) {
225
- if ( addon && Services . vc . compare ( addon . version , "1.16.4.17" ) >= 0 ) {
226
- selfDestruct . run ( true /* wait */ ) ;
227
- } else {
228
- prefObserver . register ( ) ;
229
- httpObserver . register ( ) ;
230
- }
231
- } ) ;
168
+ httpObserver . register ( ) ;
169
+ selfDestruct ( ) ;
232
170
}
233
171
234
172
function shutdown ( data , reason ) {
235
173
if ( reason == APP_SHUTDOWN ) return ;
236
- try {
237
- httpObserver . unregister ( ) ;
238
- prefObserver . unregister ( ) ;
239
- } catch ( e ) { }
174
+ httpObserver . unregister ( ) ;
240
175
}
241
176
242
177
function install ( ) { } ;
0 commit comments