| 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-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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 } | 358 } |
| 359 | 359 |
| 360 function loadFile(file) | 360 function loadFile(file) |
| 361 { | 361 { |
| 362 return new Promise(function(resolve, reject) | 362 return new Promise(function(resolve, reject) |
| 363 { | 363 { |
| 364 var key = fileToKey(file); | 364 var key = fileToKey(file); |
| 365 ext.storage.get([key], function(items) | 365 ext.storage.get([key], function(items) |
| 366 { | 366 { |
| 367 var entry = items[key]; | 367 var entry = items[key]; |
| 368 if (!entry) | |
| 369 { | |
| 370 try | |
| 371 { | |
| 372 entry = JSON.parse(window.localStorage.getItem(key)); | |
| 373 } | |
| 374 catch (err) | |
| 375 {} | |
| 376 } | |
| 377 if (entry) | 368 if (entry) |
| 378 { | 369 { |
| 379 resolve(entry); | 370 resolve(entry); |
| 380 } | 371 } |
| 381 else | 372 else |
| 382 { | 373 { |
| 383 reject(new Error("File doesn't exist")); | 374 try |
| 375 { | |
| 376 entry = localforage.getItem(key, function(err, value) | |
|
kzar
2016/10/05 12:14:17
Since apparently `localforage.getItem` returns a p
Oleksandr
2016/10/05 13:32:40
I am not 100% sure I follow your suggestion, but w
kzar
2016/10/05 13:46:53
I mean for you do to something like this (untested
Oleksandr
2016/10/05 21:07:40
That won't work because like I said above we also
Sebastian Noack
2016/10/05 21:27:31
Why do we have to call ext.storage.get() first? I
Oleksandr
2016/10/05 21:49:12
Current ABP for Edge users have their subscription
Sebastian Noack
2016/10/05 21:53:30
Do they? Don't we use localStorage here in the ver
Oleksandr
2016/10/05 22:57:35
Ah, you're right. Version 0.9.6, which is the curr
| |
| 377 { | |
| 378 if (err || !value) | |
| 379 { | |
|
kzar
2016/10/05 12:14:17
Nit: No need for braces around if... else... claus
| |
| 380 reject(new Error("File doesn't exist")); | |
| 381 } | |
| 382 else | |
| 383 { | |
| 384 resolve(value); | |
| 385 } | |
| 386 }); | |
| 387 } | |
| 388 catch (err) | |
| 389 {} | |
| 384 } | 390 } |
| 385 }); | 391 }); |
| 386 }.bind(this)); | 392 }.bind(this)); |
| 387 } | 393 } |
| 388 function saveFile(file, data, callback) | 394 function saveFile(file, data, callback) |
| 389 { | 395 { |
| 390 var entry = {}; | 396 var entry = {}; |
| 391 var key = fileToKey(file); | 397 var key = fileToKey(file); |
| 398 entry[key] = { | |
|
kzar
2016/10/05 12:14:17
Since this review is for changes to adblockplusedg
| |
| 399 lastModified: Date.now(), | |
| 400 content: data | |
| 401 }; | |
| 392 | 402 |
| 393 if (typeof browser == "undefined") | 403 if (typeof browser == "undefined") |
| 394 { | 404 { |
| 395 entry[key] = { | |
| 396 lastModified: Date.now(), | |
| 397 content: data | |
| 398 }; | |
| 399 ext.storage.set(entry, callback); | 405 ext.storage.set(entry, callback); |
| 406 callback(); | |
|
kzar
2016/10/05 12:14:17
Could you explain this change? How come ext.storag
Oleksandr
2016/10/05 13:32:40
Yeah, that was a bug.
| |
| 400 } | 407 } |
| 401 else | 408 else |
| 402 { | 409 { |
| 403 var processedData = LZString.compressToUTF16(JSON.stringify(data)); | 410 // Use IndexedDB to store data |
|
kzar
2016/10/05 12:14:17
This comment seems kind of pointless.
| |
| 404 ext.storage.remove(key); | 411 ext.storage.remove(key); |
| 405 entry[key] = { | 412 localforage.setItem(key, entry[key], callback); |
| 406 lastModified: Date.now(), | |
| 407 content: processedData, | |
| 408 compressed: true | |
| 409 }; | |
| 410 window.localStorage.setItem(key, JSON.stringify(entry[key])); | |
| 411 setTimeout(callback, 0); | |
| 412 } | 413 } |
| 413 callback(); | |
| 414 } | 414 } |
| 415 exports.IO = { | 415 exports.IO = { |
| 416 resolveFilePath: function(path) | 416 resolveFilePath: function(path) |
| 417 { | 417 { |
| 418 return new FakeFile(path); | 418 return new FakeFile(path); |
| 419 }, | 419 }, |
| 420 readFromFile: function(file, listener, callback) | 420 readFromFile: function(file, listener, callback) |
| 421 { | 421 { |
| 422 function onLoaded(entry) | 422 function onLoaded(entry) |
| 423 { | 423 { |
| 424 if ("content" in entry) | 424 if ("content" in entry) |
| 425 { | 425 { |
| 426 if (entry["compressed"]) | |
| 427 { | |
| 428 entry.content = JSON.parse(LZString.decompressFromUTF16(entry.conten t)); | |
| 429 } | |
| 430 for (var _loopIndex15 = 0; _loopIndex15 < entry.content.length; ++_loo pIndex15) | 426 for (var _loopIndex15 = 0; _loopIndex15 < entry.content.length; ++_loo pIndex15) |
| 431 { | 427 { |
| 432 var line = entry.content[_loopIndex15]; | 428 var line = entry.content[_loopIndex15]; |
| 433 listener.process(line); | 429 listener.process(line); |
| 434 } | 430 } |
| 435 } | 431 } |
| 436 callback(null); | 432 callback(null); |
| 437 } | 433 } |
| 438 loadFile(file).then(onLoaded, callback); | 434 loadFile(file).then(onLoaded, callback); |
| 439 }, | 435 }, |
| (...skipping 6136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6576 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); | 6572 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); |
| 6577 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc h.join("&")); | 6573 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc h.join("&")); |
| 6578 } | 6574 } |
| 6579 if ("setUninstallURL" in chrome.runtime) | 6575 if ("setUninstallURL" in chrome.runtime) |
| 6580 { | 6576 { |
| 6581 Prefs.untilLoaded.then(setUninstallURL); | 6577 Prefs.untilLoaded.then(setUninstallURL); |
| 6582 Prefs.on("notificationdata", setUninstallURL); | 6578 Prefs.on("notificationdata", setUninstallURL); |
| 6583 } | 6579 } |
| 6584 return exports; | 6580 return exports; |
| 6585 })(); | 6581 })(); |
| OLD | NEW |