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: |
68 { | 67 { |
69 "@mozilla.org/timer;1": | 68 "@mozilla.org/timer;1": |
70 { | 69 { |
71 createInstance() { return new FakeTimer(); } | 70 createInstance() { return new FakeTimer(); } |
72 }, | 71 }, |
73 "@mozilla.org/xmlextras/xmlhttprequest;1": | 72 "@mozilla.org/xmlextras/xmlhttprequest;1": |
74 { | 73 { |
75 createInstance() { return new XMLHttpRequest(); } | 74 createInstance() { return new XMLHttpRequest(); } |
76 } | 75 } |
77 }, | 76 }, |
78 results: {}, | 77 results: {}, |
79 utils: { | 78 utils: { |
80 import() | 79 import(resource) |
81 { | 80 { |
| 81 let match = /^resource:\/\/gre\/modules\/(.+)\.jsm$/.exec(resource); |
| 82 let resourceName = match && match[1]; |
| 83 if (resourceName && Cu.import.resources.has(resourceName)) |
| 84 return {[resourceName]: Cu.import.resources.get(resourceName)}; |
82 }, | 85 }, |
83 reportError(e) | 86 reportError(e) |
84 { | 87 { |
85 console.error(e); | 88 console.error(e); |
86 console.trace(); | 89 console.trace(); |
87 } | 90 } |
88 }, | 91 }, |
89 manager: null, | 92 manager: null, |
90 ID() { return null; } | 93 ID() { return null; } |
91 }; | 94 }; |
92 const Cc = Components.classes; | 95 const Cc = Components.classes; |
93 const Ci = Components.interfaces; | 96 const Ci = Components.interfaces; |
94 const Cr = Components.results; | 97 const Cr = Components.results; |
95 const Cu = Components.utils; | 98 const Cu = Components.utils; |
96 | 99 |
97 let XPCOMUtils = | 100 Cu.import.resources = new Map(); |
98 { | 101 |
| 102 Cu.import.resources.set("XPCOMUtils", { |
99 generateQI() {} | 103 generateQI() {} |
100 }; | 104 }); |
101 | 105 |
102 // | 106 // |
103 // Fake nsIFile implementation for our I/O | 107 // Fake nsIFile implementation for our I/O |
104 // | 108 // |
105 | 109 |
106 function FakeFile(path) | 110 function FakeFile(path) |
107 { | 111 { |
108 this.path = path; | 112 this.path = path; |
109 } | 113 } |
110 FakeFile.prototype = | 114 FakeFile.prototype = |
(...skipping 18 matching lines...) Expand all Loading... |
129 { | 133 { |
130 return {create() {}}; | 134 return {create() {}}; |
131 }, | 135 }, |
132 normalize() {} | 136 normalize() {} |
133 }; | 137 }; |
134 | 138 |
135 // | 139 // |
136 // Services.jsm module emulation | 140 // Services.jsm module emulation |
137 // | 141 // |
138 | 142 |
139 let Services = | 143 Cu.import.resources.set("Services", { |
140 { | |
141 obs: { | 144 obs: { |
142 addObserver() {}, | 145 addObserver() {}, |
143 removeObserver() {} | 146 removeObserver() {} |
144 }, | 147 }, |
145 vc: { | 148 vc: { |
146 compare(v1, v2) | 149 compare(v1, v2) |
147 { | 150 { |
148 function parsePart(s) | 151 function parsePart(s) |
149 { | 152 { |
150 if (!s) | 153 if (!s) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 let parts2 = v2.split("."); | 206 let parts2 = v2.split("."); |
204 for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) | 207 for (let i = 0; i < Math.max(parts1.length, parts2.length); i++) |
205 { | 208 { |
206 let result = compareParts(parsePart(parts1[i]), parsePart(parts2[i])); | 209 let result = compareParts(parsePart(parts1[i]), parsePart(parts2[i])); |
207 if (result) | 210 if (result) |
208 return result; | 211 return result; |
209 } | 212 } |
210 return 0; | 213 return 0; |
211 } | 214 } |
212 } | 215 } |
213 } | 216 }); |
214 | 217 |
215 // | 218 // |
216 // FileUtils.jsm module emulation | 219 // FileUtils.jsm module emulation |
217 // | 220 // |
218 | 221 |
219 let FileUtils = | 222 Cu.import.resources.set("FileUtils", { |
220 { | |
221 PERMS_DIRECTORY: 0 | 223 PERMS_DIRECTORY: 0 |
222 }; | 224 }); |
223 | 225 |
224 function FakeTimer() | 226 function FakeTimer() |
225 { | 227 { |
226 } | 228 } |
227 FakeTimer.prototype = | 229 FakeTimer.prototype = { |
228 { | |
229 delay: 0, | 230 delay: 0, |
230 callback: null, | 231 callback: null, |
231 initWithCallback(callback, delay) | 232 initWithCallback(callback, delay) |
232 { | 233 { |
233 this.callback = callback; | 234 this.callback = callback; |
234 this.delay = delay; | 235 this.delay = delay; |
235 this.scheduleTimeout(); | 236 this.scheduleTimeout(); |
236 }, | 237 }, |
237 scheduleTimeout() | 238 scheduleTimeout() |
238 { | 239 { |
239 window.setTimeout(() => | 240 window.setTimeout(() => |
240 { | 241 { |
241 try | 242 try |
242 { | 243 { |
243 this.callback(); | 244 this.callback(); |
244 } | 245 } |
245 catch(e) | 246 catch (e) |
246 { | 247 { |
247 Cu.reportError(e); | 248 Cu.reportError(e); |
248 } | 249 } |
249 this.scheduleTimeout(); | 250 this.scheduleTimeout(); |
250 }, this.delay); | 251 }, this.delay); |
251 } | 252 } |
252 }; | 253 }; |
253 | 254 |
254 // | 255 // |
255 // Add a channel property to XMLHttpRequest, Synchronizer needs it | 256 // Add a channel property to XMLHttpRequest, Synchronizer needs it |
256 // | 257 // |
257 | 258 |
258 XMLHttpRequest.prototype.channel = | 259 XMLHttpRequest.prototype.channel = { |
259 { | |
260 status: -1, | 260 status: -1, |
261 notificationCallbacks: {}, | 261 notificationCallbacks: {}, |
262 loadFlags: 0, | 262 loadFlags: 0, |
263 INHIBIT_CACHING: 0, | 263 INHIBIT_CACHING: 0, |
264 VALIDATE_ALWAYS: 0, | 264 VALIDATE_ALWAYS: 0, |
265 QueryInterface() | 265 QueryInterface() |
266 { | 266 { |
267 return this; | 267 return this; |
268 } | 268 } |
269 }; | 269 }; |
OLD | NEW |