2017-03-05 06:25:55 -07:00
|
|
|
/*******************************************************************************
|
|
|
|
|
|
|
|
uBlock Origin - a browser extension to block requests.
|
|
|
|
Copyright (C) 2017 Raymond Hill
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program 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 this program. If not, see {http://www.gnu.org/licenses/}.
|
|
|
|
|
|
|
|
Home: https://github.com/gorhill/uBlock
|
|
|
|
*/
|
|
|
|
|
|
|
|
// For background page
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/******************************************************************************/
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
let µb = µBlock;
|
2017-08-22 06:00:46 -06:00
|
|
|
let migratedKeys = new Set();
|
2017-08-29 16:32:00 -06:00
|
|
|
let reCacheStorageKeys = /^(?:assetCacheRegistry|assetSourceRegistry|cache\/.+|selfie)$/;
|
2017-03-05 06:25:55 -07:00
|
|
|
|
|
|
|
let migrateAll = function(callback) {
|
|
|
|
let migrateKeyValue = function(details, callback) {
|
2017-08-22 06:00:46 -06:00
|
|
|
// https://github.com/gorhill/uBlock/issues/2653
|
|
|
|
// Be ready to deal graciously with corrupted DB.
|
|
|
|
if ( migratedKeys.has(details.key) ) {
|
|
|
|
callback();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
migratedKeys.add(details.key);
|
2017-03-05 06:25:55 -07:00
|
|
|
let bin = {};
|
|
|
|
bin[details.key] = JSON.parse(details.value);
|
2017-08-29 16:32:00 -06:00
|
|
|
if ( reCacheStorageKeys.test(details.key) ) {
|
|
|
|
vAPI.cacheStorage.set(bin, callback);
|
|
|
|
} else {
|
|
|
|
vAPI.storage.set(bin, callback);
|
|
|
|
}
|
2017-03-05 06:25:55 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
let migrateNext = function() {
|
|
|
|
self.browser.runtime.sendMessage({ what: 'webext:storageMigrateNext' }, response => {
|
|
|
|
if ( response.key === undefined ) {
|
2017-08-22 06:00:46 -06:00
|
|
|
if ( migratedKeys.size !== 0 ) {
|
2017-03-05 06:25:55 -07:00
|
|
|
self.browser.runtime.reload();
|
|
|
|
} else {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
migrateKeyValue(response, migrateNext);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-03-25 08:57:11 -06:00
|
|
|
self.browser.storage.local.get('legacyStorageMigrated', bin => {
|
|
|
|
if ( bin && bin.legacyStorageMigrated ) {
|
|
|
|
self.browser.runtime.sendMessage({ what: 'webext:storageMigrateDone' });
|
|
|
|
return callback();
|
|
|
|
}
|
2017-08-29 16:32:00 -06:00
|
|
|
vAPI.storage.set({ legacyStorageMigrated: true });
|
2017-03-25 08:57:11 -06:00
|
|
|
migrateNext();
|
|
|
|
});
|
2017-03-05 06:25:55 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
µb.onBeforeStartQueue.push(migrateAll);
|
|
|
|
})();
|
|
|
|
|
|
|
|
/******************************************************************************/
|