2017-10-12 19:00:04 +00:00
|
|
|
/*jslint es6: true*/
|
|
|
|
/*global window*/
|
|
|
|
(function () {
|
|
|
|
"use strict";
|
|
|
|
|
2017-10-14 20:24:18 +00:00
|
|
|
const rootObject = window.browser || window.chrome;
|
|
|
|
const defaultConservativeRules = window.WEB_API_MANAGER.defaults.conservative;
|
2017-10-12 19:00:04 +00:00
|
|
|
const webApiManagerKeySettingsKey = "webApiManagerDomainRules";
|
2017-10-14 20:24:18 +00:00
|
|
|
const storageObject = rootObject.storage;
|
2017-10-12 19:00:04 +00:00
|
|
|
|
|
|
|
const get = function (callback) {
|
|
|
|
storageObject.local.get(webApiManagerKeySettingsKey, function (results) {
|
2017-10-14 20:24:18 +00:00
|
|
|
|
|
|
|
let loadedDomainRules = results && results[webApiManagerKeySettingsKey];
|
|
|
|
|
|
|
|
// If there are no currently saved domain rules, then create
|
|
|
|
// a stubbed out one, using the conservative blocking rule set.
|
|
|
|
if (!loadedDomainRules || Object.keys(loadedDomainRules).length === 0) {
|
|
|
|
loadedDomainRules = {
|
|
|
|
"(default)": defaultConservativeRules
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(loadedDomainRules);
|
2017-10-12 19:00:04 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const set = function (object, callback) {
|
|
|
|
const valueToStore = {};
|
|
|
|
valueToStore[webApiManagerKeySettingsKey] = object;
|
|
|
|
storageObject.local.set(valueToStore, callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
window.WEB_API_MANAGER.storageLib = {
|
|
|
|
get,
|
|
|
|
set
|
|
|
|
};
|
|
|
|
}());
|