| Left: | ||
| Right: |
| 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-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 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 26 matching lines...) Expand all Loading... | |
| 37 onShutdown = { | 37 onShutdown = { |
| 38 done: false, | 38 done: false, |
| 39 add: function() {}, | 39 add: function() {}, |
| 40 remove: function() {} | 40 remove: function() {} |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 // | 43 // |
| 44 // XPCOM emulation | 44 // XPCOM emulation |
| 45 // | 45 // |
| 46 | 46 |
| 47 var Components = | 47 const Components = |
| 48 { | 48 { |
| 49 interfaces: | 49 interfaces: |
| 50 { | 50 { |
| 51 nsIFile: {DIRECTORY_TYPE: 0}, | |
|
sergei
2017/08/11 12:49:39
Some parts of Components seem to be removed long a
| |
| 52 nsIFileURL: function() {}, | |
| 53 nsIHttpChannel: function() {}, | 51 nsIHttpChannel: function() {}, |
| 54 nsITimer: {TYPE_REPEATING_SLACK: 0}, | 52 nsITimer: {TYPE_REPEATING_SLACK: 0}, |
| 55 nsIInterfaceRequestor: null, | |
| 56 nsIChannelEventSink: null | |
| 57 }, | 53 }, |
| 58 classes: | 54 classes: |
| 59 { | 55 { |
| 60 "@mozilla.org/timer;1": | 56 "@mozilla.org/timer;1": |
| 61 { | 57 { |
| 62 createInstance: function() | 58 createInstance: function() |
| 63 { | 59 { |
| 64 return new FakeTimer(); | 60 return new FakeTimer(); |
| 65 } | 61 } |
| 66 }, | 62 }, |
| 67 "@mozilla.org/xmlextras/xmlhttprequest;1": | |
| 68 { | |
| 69 createInstance: function() | |
| 70 { | |
| 71 return new XMLHttpRequest(); | |
| 72 } | |
| 73 } | |
| 74 }, | 63 }, |
| 75 results: {}, | |
| 76 utils: { | 64 utils: { |
| 77 reportError: function(e) | 65 reportError: function(e) |
| 78 { | 66 { |
| 79 console.error(e); | 67 console.error(e); |
| 80 console.trace(); | 68 console.trace(); |
| 81 }, | 69 }, |
| 82 import: function() | 70 import: function(resource) |
| 83 { | 71 { |
| 72 let match = /^resource:\/\/gre\/modules\/(.+)\.jsm$/.exec(resource); | |
|
sergei
2017/08/11 12:49:38
it's taken from https://github.com/adblockplus/adb
| |
| 73 let resourceName = match && match[1]; | |
| 74 if (resourceName && Cu.import.resources.has(resourceName)) | |
| 75 return {[resourceName]: Cu.import.resources.get(resourceName)}; | |
| 76 throw new Error("Attempt to import unknown JavaScript module " + resource) ; | |
| 84 } | 77 } |
| 85 }, | 78 }, |
| 86 manager: null, | |
| 87 ID: function() | |
| 88 { | |
| 89 return null; | |
| 90 } | |
| 91 }; | 79 }; |
| 80 | |
| 92 const Cc = Components.classes; | 81 const Cc = Components.classes; |
| 93 const Ci = Components.interfaces; | 82 const Ci = Components.interfaces; |
| 94 const Cr = Components.results; | |
| 95 const Cu = Components.utils; | 83 const Cu = Components.utils; |
| 96 | 84 |
| 97 var XPCOMUtils = | 85 Cu.import.resources = new Map(); |
| 86 | |
| 87 Cu.import.resources.set("XPCOMUtils", | |
| 98 { | 88 { |
| 99 generateQI: function() {} | 89 generateQI: function() {} |
| 100 }; | 90 }); |
| 101 | |
| 102 // | |
| 103 // Fake nsIFile implementation for our I/O | |
| 104 // | |
| 105 | |
| 106 function FakeFile(path) | |
|
sergei
2017/08/11 12:49:38
Removed because of #5059
| |
| 107 { | |
| 108 this.path = path; | |
| 109 } | |
| 110 FakeFile.prototype = | |
| 111 { | |
| 112 get leafName() | |
| 113 { | |
| 114 return this.path; | |
| 115 }, | |
| 116 set leafName(value) | |
| 117 { | |
| 118 this.path = value; | |
| 119 }, | |
| 120 append: function(path) | |
| 121 { | |
| 122 this.path += path; | |
| 123 }, | |
| 124 clone: function() | |
| 125 { | |
| 126 return new FakeFile(this.path); | |
| 127 }, | |
| 128 get parent() | |
| 129 { | |
| 130 return {create: function() {}}; | |
| 131 }, | |
| 132 normalize: function() {} | |
| 133 }; | |
| 134 | 91 |
| 135 // | 92 // |
| 136 // Services.jsm module emulation | 93 // Services.jsm module emulation |
| 137 // | 94 // |
| 138 | 95 |
| 139 var Services = | 96 Cu.import.resources.set("Services", |
| 140 { | 97 { |
| 141 io: { | |
| 142 newURI: function(uri) | |
| 143 { | |
| 144 if (!uri.length || uri[0] == "~") | |
| 145 throw new Error("Invalid URI"); | |
| 146 | |
| 147 /^([^:\/]*)/.test(uri); | |
| 148 var scheme = RegExp.$1.toLowerCase(); | |
| 149 | |
| 150 return { | |
| 151 scheme: scheme, | |
| 152 spec: uri, | |
| 153 QueryInterface: function() | |
| 154 { | |
| 155 return this; | |
| 156 } | |
| 157 }; | |
| 158 }, | |
| 159 newFileURI: function(file) | |
| 160 { | |
| 161 var result = this.newURI("file:///" + file.path); | |
| 162 result.file = file; | |
| 163 return result; | |
| 164 } | |
| 165 }, | |
| 166 obs: { | 98 obs: { |
| 167 addObserver: function() {}, | 99 addObserver: function() {}, |
| 168 removeObserver: function() {} | 100 removeObserver: function() {} |
| 169 }, | 101 }, |
| 170 vc: { | 102 vc: { |
| 171 compare: function(v1, v2) | 103 compare: function(v1, v2) |
| 172 { | 104 { |
| 173 function parsePart(s) | 105 function parsePart(s) |
| 174 { | 106 { |
| 175 if (!s) | 107 if (!s) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 var parts2 = v2.split("."); | 160 var parts2 = v2.split("."); |
| 229 for (var i = 0; i < Math.max(parts1.length, parts2.length); i++) | 161 for (var i = 0; i < Math.max(parts1.length, parts2.length); i++) |
| 230 { | 162 { |
| 231 var result = compareParts(parsePart(parts1[i]), parsePart(parts2[i])); | 163 var result = compareParts(parsePart(parts1[i]), parsePart(parts2[i])); |
| 232 if (result) | 164 if (result) |
| 233 return result; | 165 return result; |
| 234 } | 166 } |
| 235 return 0; | 167 return 0; |
| 236 } | 168 } |
| 237 } | 169 } |
| 238 } | 170 }); |
| 239 | |
| 240 // | |
| 241 // FileUtils.jsm module emulation | |
| 242 // | |
| 243 | |
| 244 var FileUtils = | |
| 245 { | |
| 246 PERMS_DIRECTORY: 0 | |
| 247 }; | |
| 248 | 171 |
| 249 function FakeTimer() | 172 function FakeTimer() |
| 250 { | 173 { |
| 251 } | 174 } |
| 252 FakeTimer.prototype = | 175 FakeTimer.prototype = |
| 253 { | 176 { |
| 254 delay: 0, | 177 delay: 0, |
| 255 callback: null, | 178 callback: null, |
| 256 initWithCallback: function(callback, delay) | 179 initWithCallback: function(callback, delay) |
| 257 { | 180 { |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 511 var kValue = o[k]; | 434 var kValue = o[k]; |
| 512 if (predicate.call(thisArg, kValue, k, o)) { | 435 if (predicate.call(thisArg, kValue, k, o)) { |
| 513 return kValue; | 436 return kValue; |
| 514 } | 437 } |
| 515 // e. Increase k by 1. | 438 // e. Increase k by 1. |
| 516 k++; | 439 k++; |
| 517 } | 440 } |
| 518 } | 441 } |
| 519 }); | 442 }); |
| 520 } | 443 } |
| OLD | NEW |