Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/synchronizer.js

Issue 29630576: Issue 5146 - Part 2: Process http response in C++ (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Patch Set: Rebased Created Aug. 14, 2018, 12:45 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « compiled/subscription/DownloadableSubscription.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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.redirect) 157 if (parser.redirect)
161 { 158 {
162 let {redirect} = parser; 159 let {redirect} = parser;
163 parser.delete(); 160 parser.delete();
164 return redirectCallback(redirect); 161 return redirectCallback(redirect);
165 } 162 }
166 163
167 // Handle redirects 164 // Handle redirects
168 let subscription = Subscription.fromURL(downloadable.redirectURL || 165 let subscription = Subscription.fromURL(downloadable.redirectURL ||
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 } 198 }
202 catch (e) 199 catch (e)
203 { 200 {
204 url = null; 201 url = null;
205 } 202 }
206 203
207 if (url && (url.protocol == "http:" || url.protocol == "https:")) 204 if (url && (url.protocol == "http:" || url.protocol == "https:"))
208 subscription.homepage = url.href; 205 subscription.homepage = url.href;
209 } 206 }
210 207
211 if (minVersion)
212 subscription.requiredVersion = minVersion;
213 else
214 delete subscription.requiredVersion;
215
216 let expirationInterval = DEFAULT_EXPIRATION_INTERVAL; 208 let expirationInterval = DEFAULT_EXPIRATION_INTERVAL;
217 let expiration = parser.finalize(subscription); 209 let expiration = parser.finalize(subscription);
218 if (expiration != 0) 210 if (expiration != 0)
219 expirationInterval = expiration; 211 expirationInterval = expiration;
220 212
221 let [ 213 let [
222 softExpiration, 214 softExpiration,
223 hardExpiration 215 hardExpiration
224 ] = downloader.processExpirationInterval(expirationInterval); 216 ] = downloader.processExpirationInterval(expirationInterval);
225 subscription.softExpiration = Math.round(softExpiration / MILLIS_IN_SECOND); 217 subscription.softExpiration = Math.round(softExpiration / MILLIS_IN_SECOND);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 Array.from(subscription.filters, f => f.text).join("\n"); 282 Array.from(subscription.filters, f => f.text).join("\n");
291 redirectCallback("data:text/plain," + encodeURIComponent(data)); 283 redirectCallback("data:text/plain," + encodeURIComponent(data));
292 } 284 }
293 }, false); 285 }, false);
294 request.send(null); 286 request.send(null);
295 } 287 }
296 } 288 }
297 } 289 }
298 }; 290 };
299 Synchronizer.init(); 291 Synchronizer.init();
OLDNEW
« no previous file with comments | « compiled/subscription/DownloadableSubscription.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld