OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 remove() {} | 46 remove() {} |
47 }; | 47 }; |
48 | 48 |
49 // | 49 // |
50 // XPCOM emulation | 50 // XPCOM emulation |
51 // | 51 // |
52 | 52 |
53 function nsIFileURL() {} | 53 function nsIFileURL() {} |
54 function nsIHttpChannel() {} | 54 function nsIHttpChannel() {} |
55 | 55 |
56 let Components = | 56 let Components = { |
57 { | |
58 interfaces: | 57 interfaces: |
59 { | 58 { |
60 nsIFile: {DIRECTORY_TYPE: 0}, | 59 nsIFile: {DIRECTORY_TYPE: 0}, |
61 nsIFileURL, | 60 nsIFileURL, |
62 nsIHttpChannel, | 61 nsIHttpChannel, |
63 nsITimer: {TYPE_REPEATING_SLACK: 0}, | 62 nsITimer: {TYPE_REPEATING_SLACK: 0}, |
64 nsIInterfaceRequestor: null, | 63 nsIInterfaceRequestor: null, |
65 nsIChannelEventSink: null | 64 nsIChannelEventSink: null |
66 }, | 65 }, |
67 classes: | 66 classes: |
(...skipping 19 matching lines...) Expand all Loading... |
87 } | 86 } |
88 }, | 87 }, |
89 manager: null, | 88 manager: null, |
90 ID() { return null; } | 89 ID() { return null; } |
91 }; | 90 }; |
92 const Cc = Components.classes; | 91 const Cc = Components.classes; |
93 const Ci = Components.interfaces; | 92 const Ci = Components.interfaces; |
94 const Cr = Components.results; | 93 const Cr = Components.results; |
95 const Cu = Components.utils; | 94 const Cu = Components.utils; |
96 | 95 |
97 let XPCOMUtils = | 96 let XPCOMUtils = { |
98 { | |
99 generateQI() {} | 97 generateQI() {} |
100 }; | 98 }; |
101 | 99 |
102 // | 100 // |
103 // Fake nsIFile implementation for our I/O | 101 // Fake nsIFile implementation for our I/O |
104 // | 102 // |
105 | 103 |
106 function FakeFile(path) | 104 function FakeFile(path) |
107 { | 105 { |
108 this.path = path; | 106 this.path = path; |
(...skipping 20 matching lines...) Expand all Loading... |
129 { | 127 { |
130 return {create() {}}; | 128 return {create() {}}; |
131 }, | 129 }, |
132 normalize() {} | 130 normalize() {} |
133 }; | 131 }; |
134 | 132 |
135 // | 133 // |
136 // Services.jsm module emulation | 134 // Services.jsm module emulation |
137 // | 135 // |
138 | 136 |
139 let Services = | 137 let Services = { |
140 { | |
141 obs: { | 138 obs: { |
142 addObserver() {}, | 139 addObserver() {}, |
143 removeObserver() {} | 140 removeObserver() {} |
144 }, | 141 }, |
145 vc: { | 142 vc: { |
146 compare(v1, v2) | 143 compare(v1, v2) |
147 { | 144 { |
148 function parsePart(s) | 145 function parsePart(s) |
149 { | 146 { |
150 if (!s) | 147 if (!s) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 let parts2 = v2.split("."); | 200 let parts2 = v2.split("."); |
204 for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) | 201 for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) |
205 { | 202 { |
206 let result = compareParts(parsePart(parts1[i]), parsePart(parts2[i])); | 203 let result = compareParts(parsePart(parts1[i]), parsePart(parts2[i])); |
207 if (result) | 204 if (result) |
208 return result; | 205 return result; |
209 } | 206 } |
210 return 0; | 207 return 0; |
211 } | 208 } |
212 } | 209 } |
213 } | 210 }; |
214 | 211 |
215 // | 212 // |
216 // FileUtils.jsm module emulation | 213 // FileUtils.jsm module emulation |
217 // | 214 // |
218 | 215 |
219 let FileUtils = | 216 let FileUtils = { |
220 { | |
221 PERMS_DIRECTORY: 0 | 217 PERMS_DIRECTORY: 0 |
222 }; | 218 }; |
223 | 219 |
224 function FakeTimer() | 220 function FakeTimer() |
225 { | 221 { |
226 } | 222 } |
227 FakeTimer.prototype = | 223 FakeTimer.prototype = { |
228 { | |
229 delay: 0, | 224 delay: 0, |
230 callback: null, | 225 callback: null, |
231 initWithCallback(callback, delay) | 226 initWithCallback(callback, delay) |
232 { | 227 { |
233 this.callback = callback; | 228 this.callback = callback; |
234 this.delay = delay; | 229 this.delay = delay; |
235 this.scheduleTimeout(); | 230 this.scheduleTimeout(); |
236 }, | 231 }, |
237 scheduleTimeout() | 232 scheduleTimeout() |
238 { | 233 { |
239 window.setTimeout(() => | 234 window.setTimeout(() => |
240 { | 235 { |
241 try | 236 try |
242 { | 237 { |
243 this.callback(); | 238 this.callback(); |
244 } | 239 } |
245 catch(e) | 240 catch (e) |
246 { | 241 { |
247 Cu.reportError(e); | 242 Cu.reportError(e); |
248 } | 243 } |
249 this.scheduleTimeout(); | 244 this.scheduleTimeout(); |
250 }, this.delay); | 245 }, this.delay); |
251 } | 246 } |
252 }; | 247 }; |
253 | 248 |
254 // | 249 // |
255 // Add a channel property to XMLHttpRequest, Synchronizer needs it | 250 // Add a channel property to XMLHttpRequest, Synchronizer needs it |
256 // | 251 // |
257 | 252 |
258 XMLHttpRequest.prototype.channel = | 253 XMLHttpRequest.prototype.channel = { |
259 { | |
260 status: -1, | 254 status: -1, |
261 notificationCallbacks: {}, | 255 notificationCallbacks: {}, |
262 loadFlags: 0, | 256 loadFlags: 0, |
263 INHIBIT_CACHING: 0, | 257 INHIBIT_CACHING: 0, |
264 VALIDATE_ALWAYS: 0, | 258 VALIDATE_ALWAYS: 0, |
265 QueryInterface() | 259 QueryInterface() |
266 { | 260 { |
267 return this; | 261 return this; |
268 } | 262 } |
269 }; | 263 }; |
OLD | NEW |