Bug 1231445 - Part 2: Change format of stores-cleared event data to support clearing any store r=mratcliffe

This commit is contained in:
Jarda Snajdr 2016-07-04 04:09:00 +02:00
Родитель 9d2f86c967
Коммит 23366bd7b8
2 изменённых файлов: 48 добавлений и 14 удалений

Просмотреть файл

@ -253,15 +253,47 @@ StorageUI.prototype = {
/**
* Event handler for "stores-cleared" event coming from the storage actor.
*
* @param {object} argument0
* @param {object} response
* An object containing which storage types were cleared
*/
onCleared: function (response) {
let [type, host] = this.tree.selectedItem;
if (response.hasOwnProperty(type) && response[type].indexOf(host) > -1) {
this.table.clear();
this.hideSidebar();
this.emit("store-objects-cleared");
function* enumPaths() {
for (let type in response) {
if (Array.isArray(response[type])) {
// Handle the legacy response with array of hosts
for (let host of response[type]) {
yield [type, host];
}
} else {
// Handle the new format that supports clearing sub-stores in a host
for (let host in response[type]) {
let paths = response[type][host];
if (!paths.length) {
yield [type, host];
} else {
for (let path of paths) {
try {
path = JSON.parse(path);
yield [type, host, ...path];
} catch (ex) {
// ignore
}
}
}
}
}
}
}
for (let path of enumPaths()) {
// Find if the path is selected (there is max one) and clear it
if (this.tree.isSelected(path)) {
this.table.clear();
this.hideSidebar();
this.emit("store-objects-cleared");
break;
}
}
},

Просмотреть файл

@ -537,7 +537,12 @@ StorageActors.createActor({
break;
case "cleared":
this.storageActor.update("cleared", "cookies", hosts);
if (hosts.length) {
for (let host of hosts) {
data[host] = [];
}
this.storageActor.update("cleared", "cookies", data);
}
break;
}
return null;
@ -2239,16 +2244,13 @@ let StorageActor = protocol.ActorClassWithSpec(specs.storageSpec, {
* <host2>: [<store_names34>...],
* }
* Where host1, host2 are the host in which this change happened and
* [<store_namesX] is an array of the names of the changed store
* objects. Leave it empty if the host was completely removed.
* When the action is "cleared", `data` is an array of
* hosts for which the stores were cleared.
* [<store_namesX] is an array of the names of the changed store objects.
* Pass an empty array if the host itself was affected: either completely
* removed or cleared.
*/
update(action, storeType, data) {
if (action == "cleared") {
let toSend = {};
toSend[storeType] = data;
events.emit(this, "stores-" + action, toSend);
events.emit(this, "stores-cleared", { [storeType]: data });
return null;
}