Skip to content

Commit

Permalink
Add unlimitedStorage to Firefox manifest; add timeout to IndexedDB …
Browse files Browse the repository at this point in the history
…access

Related issue:
- uBlockOrigin/uBlock-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.
  • Loading branch information
gorhill committed Mar 17, 2019
1 parent dbecb71 commit 34a138e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions platform/firefox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"privacy",
"storage",
"tabs",
"unlimitedStorage",
"webNavigation",
"webRequest",
"webRequestBlocking",
Expand Down
23 changes: 18 additions & 5 deletions src/js/cachestorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,28 +226,39 @@
table.createIndex('value', 'value', { unique: false });
};
req.onsuccess = function(ev) {
if ( resolve === undefined ) { return; }
req = undefined;
db = ev.target.result;
db.onerror = db.onabort = genericErrorHandler;
dbPromise = undefined;
resolve(db);
resolve = undefined;
};
req.onerror = req.onblocked = function() {
if ( resolve === undefined ) { return; }
req = undefined;
console.log(this.error);
db = null;
dbPromise = undefined;
resolve(null);
resolve = undefined;
};
setTimeout(( ) => {
if ( resolve === undefined ) { return; }
db = null;
dbPromise = undefined;
resolve(null);
resolve = undefined;
}, 5000);
});
return dbPromise;
};

const getFromDb = function(keys, keyvalStore, callback) {
if ( typeof callback !== 'function' ) { return; }
if ( keys.length === 0 ) { return callback(keyvalStore); }
let promises = [];
let gotOne = function() {
const promises = [];
const gotOne = function() {
if ( typeof this.result !== 'object' ) { return; }
keyvalStore[this.result.key] = this.result.value;
if ( this.result.value instanceof Blob === false ) { return; }
Expand All @@ -262,7 +273,7 @@
};
getDb().then(db => {
if ( !db ) { return callback(); }
const transaction = db.transaction(STORAGE_NAME);
const transaction = db.transaction(STORAGE_NAME, 'readonly');
transaction.oncomplete =
transaction.onerror =
transaction.onabort = ( ) => {
Expand All @@ -272,11 +283,13 @@
};
const table = transaction.objectStore(STORAGE_NAME);
for ( const key of keys ) {
let req = table.get(key);
const req = table.get(key);
req.onsuccess = gotOne;
req.onerror = noopfn;
req = undefined;
}
}).catch(reason => {
console.info(`cacheStorage.getFromDb() failed: ${reason}`);
callback();
});
};

Expand Down

0 comments on commit 34a138e

Please sign in to comment.