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-present eyeo GmbH | 3 * Copyright (C) 2006-present 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 138 |
139 _onDownloadStarted(downloadable) | 139 _onDownloadStarted(downloadable) |
140 { | 140 { |
141 let subscription = Subscription.fromURL(downloadable.url); | 141 let subscription = Subscription.fromURL(downloadable.url); |
142 FilterNotifier.triggerListeners("subscription.downloading", subscription); | 142 FilterNotifier.triggerListeners("subscription.downloading", subscription); |
143 }, | 143 }, |
144 | 144 |
145 _onDownloadSuccess(downloadable, responseText, errorCallback, | 145 _onDownloadSuccess(downloadable, responseText, errorCallback, |
146 redirectCallback) | 146 redirectCallback) |
147 { | 147 { |
148 let lines = responseText.split(/[\r\n]+/); | |
149 let headerMatch = /\[Adblock(?:\s*Plus\s*([\d.]+)?)?\]/i.exec(lines[0]); | |
150 if (!headerMatch) | |
151 return errorCallback("synchronize_invalid_data"); | |
152 let minVersion = headerMatch[1]; | |
153 | |
154 let parser = DownloadableSubscription.parseDownload(); | 148 let parser = DownloadableSubscription.parseDownload(); |
155 | 149 |
156 // Process filters | 150 if (!parser.process(responseText)) |
157 for (let line of lines) | 151 { |
158 parser.process(line); | 152 let {error} = parser; |
| 153 parser.delete(); |
| 154 return errorCallback(error); |
| 155 } |
159 | 156 |
160 if (!parser.verifyChecksum()) | 157 if (!parser.verifyChecksum()) |
161 return errorCallback("synchronize_checksum_mismatch"); | 158 return errorCallback("synchronize_checksum_mismatch"); |
162 | 159 |
163 if (parser.redirect) | 160 if (parser.redirect) |
164 { | 161 { |
165 let {redirect} = parser; | 162 let {redirect} = parser; |
166 parser.delete(); | 163 parser.delete(); |
167 return redirectCallback(redirect); | 164 return redirectCallback(redirect); |
168 } | 165 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 } | 201 } |
205 catch (e) | 202 catch (e) |
206 { | 203 { |
207 url = null; | 204 url = null; |
208 } | 205 } |
209 | 206 |
210 if (url && (url.protocol == "http:" || url.protocol == "https:")) | 207 if (url && (url.protocol == "http:" || url.protocol == "https:")) |
211 subscription.homepage = url.href; | 208 subscription.homepage = url.href; |
212 } | 209 } |
213 | 210 |
214 if (minVersion) | |
215 subscription.requiredVersion = minVersion; | |
216 else | |
217 delete subscription.requiredVersion; | |
218 | |
219 let expirationInterval = DEFAULT_EXPIRATION_INTERVAL; | 211 let expirationInterval = DEFAULT_EXPIRATION_INTERVAL; |
220 let expiration = parser.finalize(subscription); | 212 let expiration = parser.finalize(subscription); |
221 if (expiration != 0) | 213 if (expiration != 0) |
222 expirationInterval = expiration; | 214 expirationInterval = expiration; |
223 | 215 |
224 let [ | 216 let [ |
225 softExpiration, | 217 softExpiration, |
226 hardExpiration | 218 hardExpiration |
227 ] = downloader.processExpirationInterval(expirationInterval); | 219 ] = downloader.processExpirationInterval(expirationInterval); |
228 subscription.softExpiration = Math.round(softExpiration / MILLIS_IN_SECOND); | 220 subscription.softExpiration = Math.round(softExpiration / MILLIS_IN_SECOND); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 Array.from(subscription.filters, f => f.text).join("\n"); | 285 Array.from(subscription.filters, f => f.text).join("\n"); |
294 redirectCallback("data:text/plain," + encodeURIComponent(data)); | 286 redirectCallback("data:text/plain," + encodeURIComponent(data)); |
295 } | 287 } |
296 }, false); | 288 }, false); |
297 request.send(null); | 289 request.send(null); |
298 } | 290 } |
299 } | 291 } |
300 } | 292 } |
301 }; | 293 }; |
302 Synchronizer.init(); | 294 Synchronizer.init(); |
OLD | NEW |