| Index: edge/ext/background.js |
| =================================================================== |
| new file mode 100644 |
| --- /dev/null |
| +++ b/edge/ext/background.js |
| @@ -0,0 +1,79 @@ |
| +/* |
| + * This file is part of Adblock Plus <https://adblockplus.org/>, |
| + * Copyright (C) 2006-2016 Eyeo GmbH |
| + * |
| + * Adblock Plus is free software: you can redistribute it and/or modify |
| + * it under the terms of the GNU General Public License version 3 as |
| + * published by the Free Software Foundation. |
| + * |
| + * Adblock Plus is distributed in the hope that it will be useful, |
| + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| + * GNU General Public License for more details. |
| + * |
| + * You should have received a copy of the GNU General Public License |
| + * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| + */ |
| + |
| +(function() |
| +{ |
| + /* |
| + * Storage redirection to localforage. In Windows 10 Anniversary Update |
|
kzar
2016/12/13 10:24:04
The comment looks much more useful now thanks. Cou
|
| + * Microsoft Edge has a 1Mb limit on the amount of bytes per transaction in |
| + * storage.local. Also unlimitedStorage permision is not honoured. Which is why |
| + * we have to use IndexedDB until those issues are fixed in Creators Update. |
| + * For reference it is supposed to be fixed in Windows 10 build 14986. |
| + */ |
| + |
| + ext.storage = { |
| + get: function(keys, callback) |
| + { |
| + var promisedValues = keys.map(key => |
| + { |
| + return localforage.getItem(key); |
| + }); |
| + Promise.all(promisedValues).then(values => |
| + { |
| + var items = {}; |
| + for (let i = 0; i < keys.length; i++) |
| + { |
| + if (values[i] != null) |
| + items[keys[i]] = values[i]; |
| + } |
| + callback(items); |
| + }).catch(err => |
|
kzar
2016/12/13 10:24:04
The indentation here for the catch is wrong. Also
|
| + { |
| + callback(null); |
| + }); |
| + }, |
| + set: function(key, value, callback) |
| + { |
| + function internalSet(oldValue) |
|
kzar
2016/12/13 10:24:04
Nit: setThenDispatch or setThenCallback or somethi
|
| + { |
| + localforage.setItem(key, value).then(() => |
| + { |
| + if (callback) |
| + callback(null); |
| + var changes = {}; |
|
kzar
2016/12/13 10:24:04
Please move the `var changes = {};` line down, so
|
| + var change = changes[key] = {}; |
| + change.oldValue = oldValue; |
| + change.newValue = value; |
| + |
| + ext.storage.onChanged._dispatch(changes); |
| + }).catch((err) => |
| + { |
| + if (callback) |
| + callback(err); |
| + }); |
| + }; |
| + |
| + localforage.getItem(key).then(oldValue => internalSet(oldValue)) |
|
kzar
2016/12/13 10:24:04
No need to wrap internalSet with another function.
|
| + .catch(err => internalSet(null)); |
| + }, |
| + remove: function(key, callback) |
| + { |
| + localforage.removeItem(key, callback); |
|
kzar
2016/12/13 10:24:04
Why wrap localforage.removeItem at all? How about
|
| + }, |
| + onChanged: new ext._EventTarget() |
| + }; |
| +})(); |