Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/resources/DOMStorageItemsView.js

Issue 2632553002: [DevTools] Clear local storage (Closed)
Patch Set: Addressed comments, moved the toolbar. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Nokia Inc. All rights reserved. 2 * Copyright (C) 2008 Nokia Inc. All rights reserved.
3 * Copyright (C) 2013 Samsung Electronics. All rights reserved. 3 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 17 matching lines...) Expand all
28 * @unrestricted 28 * @unrestricted
29 */ 29 */
30 Resources.DOMStorageItemsView = class extends UI.SimpleView { 30 Resources.DOMStorageItemsView = class extends UI.SimpleView {
31 constructor(domStorage) { 31 constructor(domStorage) {
32 super(Common.UIString('DOM Storage')); 32 super(Common.UIString('DOM Storage'));
33 33
34 this.domStorage = domStorage; 34 this.domStorage = domStorage;
35 35
36 this.element.classList.add('storage-view', 'table'); 36 this.element.classList.add('storage-view', 'table');
37 37
38 this.deleteButton = new UI.ToolbarButton(Common.UIString('Delete'), 'largeic on-delete'); 38 this._deleteButton = new UI.ToolbarButton(Common.UIString('Delete'), 'largei con-delete');
39 this.deleteButton.setVisible(false); 39 this._deleteButton.setEnabled(false);
40 this.deleteButton.addEventListener(UI.ToolbarButton.Events.Click, this._dele teButtonClicked, this); 40 this._deleteButton.addEventListener(UI.ToolbarButton.Events.Click, this._del eteButtonClicked, this);
41 41
42 this.refreshButton = new UI.ToolbarButton(Common.UIString('Refresh'), 'large icon-refresh'); 42 this._clearButton = new UI.ToolbarButton(Common.UIString('Clear All'), 'larg eicon-clear');
43 this.refreshButton.addEventListener(UI.ToolbarButton.Events.Click, this._ref reshButtonClicked, this); 43 this._clearButton.addEventListener(UI.ToolbarButton.Events.Click, () => this .domStorage.clear(), this);
44
45 this._refreshButton = new UI.ToolbarButton(Common.UIString('Refresh'), 'larg eicon-refresh');
46 this._refreshButton.addEventListener(UI.ToolbarButton.Events.Click, this._re freshButtonClicked, this);
44 47
45 this.domStorage.addEventListener( 48 this.domStorage.addEventListener(
46 Resources.DOMStorage.Events.DOMStorageItemsCleared, this._domStorageItem sCleared, this); 49 Resources.DOMStorage.Events.DOMStorageItemsCleared, this._domStorageItem sCleared, this);
47 this.domStorage.addEventListener( 50 this.domStorage.addEventListener(
48 Resources.DOMStorage.Events.DOMStorageItemRemoved, this._domStorageItemR emoved, this); 51 Resources.DOMStorage.Events.DOMStorageItemRemoved, this._domStorageItemR emoved, this);
49 this.domStorage.addEventListener(Resources.DOMStorage.Events.DOMStorageItemA dded, this._domStorageItemAdded, this); 52 this.domStorage.addEventListener(Resources.DOMStorage.Events.DOMStorageItemA dded, this._domStorageItemAdded, this);
50 this.domStorage.addEventListener( 53 this.domStorage.addEventListener(
51 Resources.DOMStorage.Events.DOMStorageItemUpdated, this._domStorageItemU pdated, this); 54 Resources.DOMStorage.Events.DOMStorageItemUpdated, this._domStorageItemU pdated, this);
52 } 55 }
53 56
54 /** 57 /**
55 * @override 58 * @override
56 * @return {!Array.<!UI.ToolbarItem>} 59 * @return {!Array.<!UI.ToolbarItem>}
57 */ 60 */
58 syncToolbarItems() { 61 syncToolbarItems() {
59 return [this.refreshButton, this.deleteButton]; 62 if (this.domStorage.isLocalStorage)
pfeldman 2017/01/19 23:38:45 Why different toolbars?
eostroukhov 2017/01/20 19:24:00 We do not have a way to wipe session storage - htt
63 return [this._refreshButton, this._clearButton, this._deleteButton];
64 else
65 return [this._refreshButton, this._deleteButton];
60 } 66 }
61 67
62 /** 68 /**
63 * @override 69 * @override
64 */ 70 */
65 wasShown() { 71 wasShown() {
66 this._update(); 72 this._update();
67 } 73 }
68 74
69 /** 75 /**
70 * @override 76 * @override
71 */ 77 */
72 willHide() { 78 willHide() {
73 this.deleteButton.setVisible(false); 79 this._deleteButton.setEnabled(false);
74 } 80 }
75 81
76 /** 82 /**
77 * @param {!Common.Event} event 83 * @param {!Common.Event} event
78 */ 84 */
79 _domStorageItemsCleared(event) { 85 _domStorageItemsCleared(event) {
80 if (!this.isShowing() || !this._dataGrid) 86 if (!this.isShowing() || !this._dataGrid)
81 return; 87 return;
82 88
83 this._dataGrid.rootNode().removeChildren(); 89 this._dataGrid.rootNode().removeChildren();
84 this._dataGrid.addCreationNode(false); 90 this._dataGrid.addCreationNode(false);
85 this.deleteButton.setVisible(false); 91 this._deleteButton.setEnabled(false);
86 } 92 }
87 93
88 /** 94 /**
89 * @param {!Common.Event} event 95 * @param {!Common.Event} event
90 */ 96 */
91 _domStorageItemRemoved(event) { 97 _domStorageItemRemoved(event) {
92 if (!this.isShowing() || !this._dataGrid) 98 if (!this.isShowing() || !this._dataGrid)
93 return; 99 return;
94 100
95 var storageData = event.data; 101 var storageData = event.data;
96 var rootNode = this._dataGrid.rootNode(); 102 var rootNode = this._dataGrid.rootNode();
97 var children = rootNode.children; 103 var children = rootNode.children;
98 104
99 for (var i = 0; i < children.length; ++i) { 105 for (var i = 0; i < children.length; ++i) {
100 var childNode = children[i]; 106 var childNode = children[i];
101 if (childNode.data.key === storageData.key) { 107 if (childNode.data.key === storageData.key) {
102 rootNode.removeChild(childNode); 108 rootNode.removeChild(childNode);
103 this.deleteButton.setVisible(children.length > 1); 109 this._deleteButton.setEnabled(children.length > 1);
104 return; 110 return;
105 } 111 }
106 } 112 }
107 } 113 }
108 114
109 /** 115 /**
110 * @param {!Common.Event} event 116 * @param {!Common.Event} event
111 */ 117 */
112 _domStorageItemAdded(event) { 118 _domStorageItemAdded(event) {
113 if (!this.isShowing() || !this._dataGrid) 119 if (!this.isShowing() || !this._dataGrid)
114 return; 120 return;
115 121
116 var storageData = event.data; 122 var storageData = event.data;
117 var rootNode = this._dataGrid.rootNode(); 123 var rootNode = this._dataGrid.rootNode();
118 var children = rootNode.children; 124 var children = rootNode.children;
119 125
120 this.deleteButton.setVisible(true); 126 this._deleteButton.setEnabled(true);
121 127
122 for (var i = 0; i < children.length; ++i) { 128 for (var i = 0; i < children.length; ++i) {
123 if (children[i].data.key === storageData.key) 129 if (children[i].data.key === storageData.key)
124 return; 130 return;
125 } 131 }
126 132
127 var childNode = new DataGrid.DataGridNode({key: storageData.key, value: stor ageData.value}, false); 133 var childNode = new DataGrid.DataGridNode({key: storageData.key, value: stor ageData.value}, false);
128 rootNode.insertChild(childNode, children.length - 1); 134 rootNode.insertChild(childNode, children.length - 1);
129 } 135 }
130 136
(...skipping 16 matching lines...) Expand all
147 rootNode.removeChild(childNode); 153 rootNode.removeChild(childNode);
148 return; 154 return;
149 } 155 }
150 keyFound = true; 156 keyFound = true;
151 if (childNode.data.value !== storageData.value) { 157 if (childNode.data.value !== storageData.value) {
152 childNode.data.value = storageData.value; 158 childNode.data.value = storageData.value;
153 childNode.refresh(); 159 childNode.refresh();
154 childNode.select(); 160 childNode.select();
155 childNode.reveal(); 161 childNode.reveal();
156 } 162 }
157 this.deleteButton.setVisible(true); 163 this._deleteButton.setEnabled(true);
158 } 164 }
159 } 165 }
160 } 166 }
161 167
162 _update() { 168 _update() {
163 this.detachChildWidgets(); 169 this.detachChildWidgets();
164 this.domStorage.getItems(this._showDOMStorageItems.bind(this)); 170 this.domStorage.getItems(this._showDOMStorageItems.bind(this));
165 } 171 }
166 172
167 _showDOMStorageItems(error, items) { 173 _showDOMStorageItems(error, items) {
168 if (error) 174 if (error)
169 return; 175 return;
170 176
171 this._dataGrid = this._dataGridForDOMStorageItems(items); 177 this._dataGrid = this._dataGridForDOMStorageItems(items);
172 this._dataGrid.asWidget().show(this.element); 178 this._dataGrid.asWidget().show(this.element);
173 this.deleteButton.setVisible(this._dataGrid.rootNode().children.length > 1); 179 this._deleteButton.setEnabled(this._dataGrid.rootNode().children.length > 1) ;
174 } 180 }
175 181
176 _dataGridForDOMStorageItems(items) { 182 _dataGridForDOMStorageItems(items) {
177 var columns = /** @type {!Array<!DataGrid.DataGrid.ColumnDescriptor>} */ ([ 183 var columns = /** @type {!Array<!DataGrid.DataGrid.ColumnDescriptor>} */ ([
178 {id: 'key', title: Common.UIString('Key'), sortable: false, editable: true , weight: 50}, 184 {id: 'key', title: Common.UIString('Key'), sortable: false, editable: true , weight: 50},
179 {id: 'value', title: Common.UIString('Value'), sortable: false, editable: true, weight: 50} 185 {id: 'value', title: Common.UIString('Value'), sortable: false, editable: true, weight: 50}
180 ]); 186 ]);
181 187
182 var nodes = []; 188 var nodes = [];
183 189
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 } 252 }
247 253
248 _deleteCallback(node) { 254 _deleteCallback(node) {
249 if (!node || node.isCreationNode) 255 if (!node || node.isCreationNode)
250 return; 256 return;
251 257
252 if (this.domStorage) 258 if (this.domStorage)
253 this.domStorage.removeItem(node.data.key); 259 this.domStorage.removeItem(node.data.key);
254 } 260 }
255 }; 261 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698