1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-03 01:29:39 +02:00

Add unlimitedStorage to Firefox manifest; add timeout to IndexedDB access

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/416

The Chromium version of uBO has declared `unlimitedStorage` since the
extension was first published in 2014. Declaring this permission in
Firefox brings uBO inline with the Chromium version. I suspect some
reported errors could be caused by IndexedDB eviction due to the lack
of `unlimitedStorage` permission.

Additionally, a timeout has been added when uBO tries to access its
indexedDB storage. It's unclear whether this will help with the
mentioned related issue though, the root cause is still to be
identified.
This commit is contained in:
Raymond Hill 2019-03-17 09:45:28 -04:00
parent dbecb71262
commit 34a138e3ef
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 19 additions and 5 deletions

View File

@ -74,6 +74,7 @@
"privacy", "privacy",
"storage", "storage",
"tabs", "tabs",
"unlimitedStorage",
"webNavigation", "webNavigation",
"webRequest", "webRequest",
"webRequestBlocking", "webRequestBlocking",

View File

@ -226,19 +226,30 @@
table.createIndex('value', 'value', { unique: false }); table.createIndex('value', 'value', { unique: false });
}; };
req.onsuccess = function(ev) { req.onsuccess = function(ev) {
if ( resolve === undefined ) { return; }
req = undefined; req = undefined;
db = ev.target.result; db = ev.target.result;
db.onerror = db.onabort = genericErrorHandler; db.onerror = db.onabort = genericErrorHandler;
dbPromise = undefined; dbPromise = undefined;
resolve(db); resolve(db);
resolve = undefined;
}; };
req.onerror = req.onblocked = function() { req.onerror = req.onblocked = function() {
if ( resolve === undefined ) { return; }
req = undefined; req = undefined;
console.log(this.error); console.log(this.error);
db = null; db = null;
dbPromise = undefined; dbPromise = undefined;
resolve(null); resolve(null);
resolve = undefined;
}; };
setTimeout(( ) => {
if ( resolve === undefined ) { return; }
db = null;
dbPromise = undefined;
resolve(null);
resolve = undefined;
}, 5000);
}); });
return dbPromise; return dbPromise;
}; };
@ -246,8 +257,8 @@
const getFromDb = function(keys, keyvalStore, callback) { const getFromDb = function(keys, keyvalStore, callback) {
if ( typeof callback !== 'function' ) { return; } if ( typeof callback !== 'function' ) { return; }
if ( keys.length === 0 ) { return callback(keyvalStore); } if ( keys.length === 0 ) { return callback(keyvalStore); }
let promises = []; const promises = [];
let gotOne = function() { const gotOne = function() {
if ( typeof this.result !== 'object' ) { return; } if ( typeof this.result !== 'object' ) { return; }
keyvalStore[this.result.key] = this.result.value; keyvalStore[this.result.key] = this.result.value;
if ( this.result.value instanceof Blob === false ) { return; } if ( this.result.value instanceof Blob === false ) { return; }
@ -262,7 +273,7 @@
}; };
getDb().then(db => { getDb().then(db => {
if ( !db ) { return callback(); } if ( !db ) { return callback(); }
const transaction = db.transaction(STORAGE_NAME); const transaction = db.transaction(STORAGE_NAME, 'readonly');
transaction.oncomplete = transaction.oncomplete =
transaction.onerror = transaction.onerror =
transaction.onabort = ( ) => { transaction.onabort = ( ) => {
@ -272,11 +283,13 @@
}; };
const table = transaction.objectStore(STORAGE_NAME); const table = transaction.objectStore(STORAGE_NAME);
for ( const key of keys ) { for ( const key of keys ) {
let req = table.get(key); const req = table.get(key);
req.onsuccess = gotOne; req.onsuccess = gotOne;
req.onerror = noopfn; req.onerror = noopfn;
req = undefined;
} }
}).catch(reason => {
console.info(`cacheStorage.getFromDb() failed: ${reason}`);
callback();
}); });
}; };