| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 require.scopes["io"] = (function() | 350 require.scopes["io"] = (function() |
| 351 { | 351 { |
| 352 var exports = {}; | 352 var exports = {}; |
| 353 var keyPrefix = "file:"; | 353 var keyPrefix = "file:"; |
| 354 | 354 |
| 355 function fileToKey(file) | 355 function fileToKey(file) |
| 356 { | 356 { |
| 357 return keyPrefix + (file instanceof FakeFile ? file.path : file.spec); | 357 return keyPrefix + (file instanceof FakeFile ? file.path : file.spec); |
| 358 } | 358 } |
| 359 | 359 |
| 360 function loadFile(file) | 360 function loadFile(file, successCallback, errorCallback) |
| 361 { | 361 { |
| 362 return new Promise(function(resolve, reject) | 362 var key = fileToKey(file); |
| 363 { | 363 // Make sure we do not have subscriptions in localStorage from older version s first |
| 364 var key = fileToKey(file); | 364 var entry = localStorage.getItem(key); |
| 365 ext.storage.get([key], function(items) | 365 if (typeof entry == "string") |
| 366 { | 366 { |
| 367 var entry = items[key]; | 367 try |
| 368 if (entry) | 368 { |
| 369 { | 369 entry = JSON.parse(entry); |
| 370 resolve(entry); | 370 } |
| 371 } | 371 catch(err) |
| 372 else | 372 { |
| 373 { | 373 setTimeout(errorCallback(new Error("File is corrupted"))); |
| 374 try | 374 return; |
| 375 { | 375 } |
| 376 entry = localforage.getItem(key, function(err, value) | 376 setTimeout(successCallback(entry)); |
|
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 { | 377 return; |
| 378 if (err || !value) | 378 } |
| 379 { | 379 // Now try to read from IndexedDB |
|
kzar
2016/10/05 12:14:17
Nit: No need for braces around if... else... claus
| |
| 380 reject(new Error("File doesn't exist")); | 380 localforage.getItem(key, function(err, value) |
| 381 } | 381 { |
| 382 else | 382 if (err || !value) |
| 383 { | 383 errorCallback(new Error("File doesn't exist")); |
| 384 resolve(value); | 384 else |
| 385 } | 385 successCallback(value); |
| 386 }); | 386 }); |
| 387 } | 387 } |
| 388 catch (err) | 388 |
| 389 {} | |
| 390 } | |
| 391 }); | |
| 392 }.bind(this)); | |
| 393 } | |
| 394 function saveFile(file, data, callback) | 389 function saveFile(file, data, callback) |
| 395 { | 390 { |
| 396 var entry = {}; | |
| 397 var key = fileToKey(file); | 391 var key = fileToKey(file); |
| 398 entry[key] = { | 392 var entry = { |
|
kzar
2016/10/05 12:14:17
Since this review is for changes to adblockplusedg
| |
| 399 lastModified: Date.now(), | 393 lastModified: Date.now(), |
| 400 content: data | 394 content: data |
| 401 }; | 395 }; |
| 402 | 396 |
| 403 if (typeof browser == "undefined") | 397 localStorage.removeItem(key); |
| 404 { | 398 localforage.setItem(key, 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.
| |
| 407 } | |
| 408 else | |
| 409 { | |
| 410 // Use IndexedDB to store data | |
|
kzar
2016/10/05 12:14:17
This comment seems kind of pointless.
| |
| 411 ext.storage.remove(key); | |
| 412 localforage.setItem(key, entry[key], callback); | |
| 413 } | |
| 414 } | 399 } |
| 415 exports.IO = { | 400 exports.IO = { |
| 416 resolveFilePath: function(path) | 401 resolveFilePath: function(path) |
| 417 { | 402 { |
| 418 return new FakeFile(path); | 403 return new FakeFile(path); |
| 419 }, | 404 }, |
| 420 readFromFile: function(file, listener, callback) | 405 readFromFile: function(file, listener, callback) |
| 421 { | 406 { |
| 422 function onLoaded(entry) | 407 function onLoaded(entry) |
| 423 { | 408 { |
| 424 if ("content" in entry) | 409 if ("content" in entry) |
| 425 { | 410 { |
| 426 for (var _loopIndex15 = 0; _loopIndex15 < entry.content.length; ++_loo pIndex15) | 411 for (var _loopIndex15 = 0; _loopIndex15 < entry.content.length; ++_loo pIndex15) |
| 427 { | 412 { |
| 428 var line = entry.content[_loopIndex15]; | 413 var line = entry.content[_loopIndex15]; |
| 429 listener.process(line); | 414 listener.process(line); |
| 430 } | 415 } |
| 431 } | 416 } |
| 432 callback(null); | 417 callback(null); |
| 433 } | 418 } |
| 434 loadFile(file).then(onLoaded, callback); | 419 loadFile(file, onLoaded, callback); |
| 435 }, | 420 }, |
| 436 writeToFile: function(file, data, callback) | 421 writeToFile: function(file, data, callback) |
| 437 { | 422 { |
| 438 saveFile(file, data, callback); | 423 saveFile(file, data, callback); |
| 439 }, | 424 }, |
| 440 copyFile: function(fromFile, toFile, callback) | 425 copyFile: function(fromFile, toFile, callback) |
| 441 { | 426 { |
| 442 function onLoaded(entry) | 427 function onLoaded(entry) |
| 443 { | 428 { |
| 444 saveFile(toFile, entry.content, callback); | 429 saveFile(toFile, entry.content, callback); |
| 445 } | 430 } |
| 446 loadFile(file).then(onLoaded, callback); | 431 loadFile(file, onLoaded, callback); |
| 447 }, | 432 }, |
| 448 renameFile: function(fromFile, newName, callback) | 433 renameFile: function(fromFile, newName, callback) |
| 449 { | 434 { |
| 450 function onLoaded() | 435 function onLoaded() |
| 451 { | 436 { |
| 452 ext.storage.remove(fileToKey(fromFile), function() | 437 ext.storage.remove(fileToKey(fromFile), function() |
| 453 { | 438 { |
| 454 ext.storage.set(keyPrefix + newName, entry, callback); | 439 ext.storage.set(keyPrefix + newName, entry, callback); |
| 455 }); | 440 }); |
| 456 } | 441 } |
| 457 loadFile(file).then(onLoaded, callback); | 442 loadFile(file, onLoaded, callback); |
| 458 }, | 443 }, |
| 459 removeFile: function(file, callback) | 444 removeFile: function(file, callback) |
| 460 { | 445 { |
| 461 ext.storage.remove(fileToKey(file), callback); | 446 ext.storage.remove(fileToKey(file), callback); |
| 462 }, | 447 }, |
| 463 statFile: function(file, callback) | 448 statFile: function(file, callback) |
| 464 { | 449 { |
| 465 function onLoaded(entry) | 450 function onLoaded(entry) |
| 466 { | 451 { |
| 467 callback(null, | 452 callback(null, |
| 468 { | 453 { |
| 469 exists: true, | 454 exists: true, |
| 470 lastModified: entry.lastModified | 455 lastModified: entry.lastModified |
| 471 }); | 456 }); |
| 472 } | 457 } |
| 473 loadFile(file).then(onLoaded, callback); | 458 loadFile(file, onLoaded, callback); |
| 474 } | 459 } |
| 475 }; | 460 }; |
| 476 return exports; | 461 return exports; |
| 477 })(); | 462 })(); |
| 478 require.scopes["downloader"] = (function() | 463 require.scopes["downloader"] = (function() |
| 479 { | 464 { |
| 480 var exports = {}; | 465 var exports = {}; |
| 481 var Utils = require("utils").Utils; | 466 var Utils = require("utils").Utils; |
| 482 var MILLIS_IN_SECOND = exports.MILLIS_IN_SECOND = 1000; | 467 var MILLIS_IN_SECOND = exports.MILLIS_IN_SECOND = 1000; |
| 483 var MILLIS_IN_MINUTE = exports.MILLIS_IN_MINUTE = 60 * MILLIS_IN_SECOND; | 468 var MILLIS_IN_MINUTE = exports.MILLIS_IN_MINUTE = 60 * MILLIS_IN_SECOND; |
| (...skipping 6088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6572 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); | 6557 search.push("notificationDownloadCount=" + encodeURIComponent(downlCount)); |
| 6573 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc h.join("&")); | 6558 chrome.runtime.setUninstallURL(Utils.getDocLink("uninstalled") + "&" + searc h.join("&")); |
| 6574 } | 6559 } |
| 6575 if ("setUninstallURL" in chrome.runtime) | 6560 if ("setUninstallURL" in chrome.runtime) |
| 6576 { | 6561 { |
| 6577 Prefs.untilLoaded.then(setUninstallURL); | 6562 Prefs.untilLoaded.then(setUninstallURL); |
| 6578 Prefs.on("notificationdata", setUninstallURL); | 6563 Prefs.on("notificationdata", setUninstallURL); |
| 6579 } | 6564 } |
| 6580 return exports; | 6565 return exports; |
| 6581 })(); | 6566 })(); |
| LEFT | RIGHT |