Bug 1654998 - [devtools] Check supports traits directly on individual storage fronts r=ladybenko

Depends on D93081

Differential Revision: https://phabricator.services.mozilla.com/D93082
This commit is contained in:
Julian Descottes 2020-10-28 20:34:03 +00:00
Родитель b5906333d9
Коммит 148634a849
1 изменённых файлов: 39 добавлений и 32 удалений

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

@ -823,7 +823,6 @@ class StorageUI {
} }
} }
await this._readSupportsTraits(type, host);
await this.resetColumns(type, host, subType); await this.resetColumns(type, host, subType);
} }
@ -840,21 +839,24 @@ class StorageUI {
} }
} }
/** supportsAddItem(type, host) {
* Read the current supports traits for the provided storage type and update const storage = this._getStorage(type, host);
* the actorSupports flags on the UI instance. return storage?.traits.supportsAddItem || false;
* }
* Note: setting actorSupportsXYZ properties on the UI instance is incorrect
* because the value depends on each storage type. See Bug 1654998.
*/
async _readSupportsTraits(type, host) {
const { traits } = this._getStorage(type, host);
this.actorSupportsAddItem = traits.supportsAddItem; supportsRemoveItem(type, host) {
this.actorSupportsRemoveItem = traits.supportsRemoveItem; const storage = this._getStorage(type, host);
this.actorSupportsRemoveAll = traits.supportsRemoveAll; return storage?.traits.supportsRemoveItem || false;
this.actorSupportsRemoveAllSessionCookies = }
traits.supportsRemoveAllSessionCookies;
supportsRemoveAll(type, host) {
const storage = this._getStorage(type, host);
return storage?.traits.supportsRemoveAll || false;
}
supportsRemoveAllSessionCookies(type, host) {
const storage = this._getStorage(type, host);
return storage?.traits.supportsRemoveAllSessionCookies || false;
} }
/** /**
@ -862,11 +864,14 @@ class StorageUI {
*/ */
updateToolbar() { updateToolbar() {
const item = this.tree.selectedItem; const item = this.tree.selectedItem;
const howManyNodesIn = item ? item.length : 0; if (!item) {
return;
}
// The first node is just a title e.g. "Cookies" so we need to be at least const [type, host] = item;
// 2 nodes in to show the add button.
const canAdd = this.actorSupportsAddItem && howManyNodesIn > 1; // Add is only supported if the selected item has a host.
const canAdd = this.supportsAddItem(type, host) && host;
if (canAdd) { if (canAdd) {
this._addButton.hidden = false; this._addButton.hidden = false;
@ -874,6 +879,9 @@ class StorageUI {
"title", "title",
L10N.getFormatStr("storage.popupMenu.addItemLabel") L10N.getFormatStr("storage.popupMenu.addItemLabel")
); );
} else {
this._addButton.hidden = true;
this._addButton.removeAttribute("title");
} }
} }
@ -1331,13 +1339,12 @@ class StorageUI {
*/ */
onTablePopupShowing(event) { onTablePopupShowing(event) {
const selectedItem = this.tree.selectedItem; const selectedItem = this.tree.selectedItem;
const type = selectedItem[0]; const [type, host] = selectedItem;
// IndexedDB only supports removing items from object stores (level 4 of the tree) // IndexedDB only supports removing items from object stores (level 4 of the tree)
if ( if (
(!this.actorSupportsAddItem && (!this.supportsAddItem(type, host) &&
!this.actorSupportsRemoveItem && !this.supportsRemoveItem(type, host)) ||
type !== "cookies") ||
(type === "indexedDB" && selectedItem.length !== 4) (type === "indexedDB" && selectedItem.length !== 4)
) { ) {
event.preventDefault(); event.preventDefault();
@ -1347,7 +1354,7 @@ class StorageUI {
const rowId = this.table.contextMenuRowId; const rowId = this.table.contextMenuRowId;
const data = this.table.items.get(rowId); const data = this.table.items.get(rowId);
if (this.actorSupportsRemoveItem) { if (this.supportsRemoveItem(type, host)) {
const name = data[this.table.uniqueId]; const name = data[this.table.uniqueId];
const separatorRegex = new RegExp(SEPARATOR_GUID, "g"); const separatorRegex = new RegExp(SEPARATOR_GUID, "g");
const label = addEllipsis((name + "").replace(separatorRegex, "-")); const label = addEllipsis((name + "").replace(separatorRegex, "-"));
@ -1361,7 +1368,7 @@ class StorageUI {
this._tablePopupDelete.hidden = true; this._tablePopupDelete.hidden = true;
} }
if (this.actorSupportsAddItem) { if (this.supportsAddItem(type, host)) {
this._tablePopupAddItem.hidden = false; this._tablePopupAddItem.hidden = false;
this._tablePopupAddItem.setAttribute( this._tablePopupAddItem.setAttribute(
"label", "label",
@ -1372,8 +1379,8 @@ class StorageUI {
} }
let showDeleteAllSessionCookies = false; let showDeleteAllSessionCookies = false;
if (this.actorSupportsRemoveAllSessionCookies) { if (this.supportsRemoveAllSessionCookies(type, host)) {
if (type === "cookies" && selectedItem.length === 2) { if (selectedItem.length === 2) {
showDeleteAllSessionCookies = true; showDeleteAllSessionCookies = true;
} }
} }
@ -1381,12 +1388,12 @@ class StorageUI {
this._tablePopupDeleteAllSessionCookies.hidden = !showDeleteAllSessionCookies; this._tablePopupDeleteAllSessionCookies.hidden = !showDeleteAllSessionCookies;
if (type === "cookies") { if (type === "cookies") {
const host = addEllipsis(data.host); const hostString = addEllipsis(data.host);
this._tablePopupDeleteAllFrom.hidden = false; this._tablePopupDeleteAllFrom.hidden = false;
this._tablePopupDeleteAllFrom.setAttribute( this._tablePopupDeleteAllFrom.setAttribute(
"label", "label",
L10N.getFormatStr("storage.popupMenu.deleteAllFromLabel", host) L10N.getFormatStr("storage.popupMenu.deleteAllFromLabel", hostString)
); );
} else { } else {
this._tablePopupDeleteAllFrom.hidden = true; this._tablePopupDeleteAllFrom.hidden = true;
@ -1398,13 +1405,13 @@ class StorageUI {
const selectedItem = this.tree.selectedItem; const selectedItem = this.tree.selectedItem;
if (selectedItem) { if (selectedItem) {
const type = selectedItem[0]; const [type, host] = selectedItem;
// The delete all (aka clear) action is displayed for IndexedDB object stores // The delete all (aka clear) action is displayed for IndexedDB object stores
// (level 4 of tree), for Cache objects (level 3) and for the whole host (level 2) // (level 4 of tree), for Cache objects (level 3) and for the whole host (level 2)
// for other storage types (cookies, localStorage, ...). // for other storage types (cookies, localStorage, ...).
let showDeleteAll = false; let showDeleteAll = false;
if (this.actorSupportsRemoveAll) { if (this.supportsRemoveAll(type, host)) {
let level; let level;
if (type == "indexedDB") { if (type == "indexedDB") {
level = 4; level = 4;
@ -1424,7 +1431,7 @@ class StorageUI {
// The delete all session cookies action is displayed for cookie object stores // The delete all session cookies action is displayed for cookie object stores
// (level 2 of tree) // (level 2 of tree)
let showDeleteAllSessionCookies = false; let showDeleteAllSessionCookies = false;
if (this.actorSupportsRemoveAllSessionCookies) { if (this.supportsRemoveAllSessionCookies(type, host)) {
if (type === "cookies" && selectedItem.length === 2) { if (type === "cookies" && selectedItem.length === 2) {
showDeleteAllSessionCookies = true; showDeleteAllSessionCookies = true;
} }