From 23366bd7b8f734da78454a9331999e56c8428982 Mon Sep 17 00:00:00 2001 From: Jarda Snajdr Date: Mon, 4 Jul 2016 04:09:00 +0200 Subject: [PATCH] Bug 1231445 - Part 2: Change format of stores-cleared event data to support clearing any store r=mratcliffe --- devtools/client/storage/ui.js | 44 ++++++++++++++++++++++++++----- devtools/server/actors/storage.js | 18 +++++++------ 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/devtools/client/storage/ui.js b/devtools/client/storage/ui.js index 3f78b89e8c93..651f9d12a968 100644 --- a/devtools/client/storage/ui.js +++ b/devtools/client/storage/ui.js @@ -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; + } } }, diff --git a/devtools/server/actors/storage.js b/devtools/server/actors/storage.js index 64312a5f5482..204116226bbf 100644 --- a/devtools/server/actors/storage.js +++ b/devtools/server/actors/storage.js @@ -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, { * : [...], * } * Where host1, host2 are the host in which this change happened and - * [