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

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

Issue 2632553002: [DevTools] Clear local storage (Closed)
Patch Set: [DevTools] Clear local storage 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 return [this._refreshButton, this._clearButton, this._deleteButton];
60 } 63 }
61 64
62 /** 65 /**
63 * @override 66 * @override
64 */ 67 */
65 wasShown() { 68 wasShown() {
66 this._update(); 69 this._update();
67 } 70 }
68 71
69 /** 72 /**
70 * @override 73 * @override
71 */ 74 */
72 willHide() { 75 willHide() {
73 this.deleteButton.setVisible(false); 76 this._deleteButton.setEnabled(false);
74 } 77 }
75 78
76 /** 79 /**
77 * @param {!Common.Event} event 80 * @param {!Common.Event} event
78 */ 81 */
79 _domStorageItemsCleared(event) { 82 _domStorageItemsCleared(event) {
80 if (!this.isShowing() || !this._dataGrid) 83 if (!this.isShowing() || !this._dataGrid)
81 return; 84 return;
82 85
83 this._dataGrid.rootNode().removeChildren(); 86 this._dataGrid.rootNode().removeChildren();
84 this._dataGrid.addCreationNode(false); 87 this._dataGrid.addCreationNode(false);
85 this.deleteButton.setVisible(false); 88 this._deleteButton.setEnabled(false);
86 } 89 }
87 90
88 /** 91 /**
89 * @param {!Common.Event} event 92 * @param {!Common.Event} event
90 */ 93 */
91 _domStorageItemRemoved(event) { 94 _domStorageItemRemoved(event) {
92 if (!this.isShowing() || !this._dataGrid) 95 if (!this.isShowing() || !this._dataGrid)
93 return; 96 return;
94 97
95 var storageData = event.data; 98 var storageData = event.data;
96 var rootNode = this._dataGrid.rootNode(); 99 var rootNode = this._dataGrid.rootNode();
97 var children = rootNode.children; 100 var children = rootNode.children;
98 101
99 for (var i = 0; i < children.length; ++i) { 102 for (var i = 0; i < children.length; ++i) {
100 var childNode = children[i]; 103 var childNode = children[i];
101 if (childNode.data.key === storageData.key) { 104 if (childNode.data.key === storageData.key) {
102 rootNode.removeChild(childNode); 105 rootNode.removeChild(childNode);
103 this.deleteButton.setVisible(children.length > 1); 106 this._deleteButton.setEnabled(children.length > 1);
104 return; 107 return;
105 } 108 }
106 } 109 }
107 } 110 }
108 111
109 /** 112 /**
110 * @param {!Common.Event} event 113 * @param {!Common.Event} event
111 */ 114 */
112 _domStorageItemAdded(event) { 115 _domStorageItemAdded(event) {
113 if (!this.isShowing() || !this._dataGrid) 116 if (!this.isShowing() || !this._dataGrid)
114 return; 117 return;
115 118
116 var storageData = event.data; 119 var storageData = event.data;
117 var rootNode = this._dataGrid.rootNode(); 120 var rootNode = this._dataGrid.rootNode();
118 var children = rootNode.children; 121 var children = rootNode.children;
119 122
120 this.deleteButton.setVisible(true); 123 this._deleteButton.setEnabled(true);
121 124
122 for (var i = 0; i < children.length; ++i) { 125 for (var i = 0; i < children.length; ++i) {
123 if (children[i].data.key === storageData.key) 126 if (children[i].data.key === storageData.key)
124 return; 127 return;
125 } 128 }
126 129
127 var childNode = new DataGrid.DataGridNode({key: storageData.key, value: stor ageData.value}, false); 130 var childNode = new DataGrid.DataGridNode({key: storageData.key, value: stor ageData.value}, false);
128 rootNode.insertChild(childNode, children.length - 1); 131 rootNode.insertChild(childNode, children.length - 1);
129 } 132 }
130 133
(...skipping 16 matching lines...) Expand all
147 rootNode.removeChild(childNode); 150 rootNode.removeChild(childNode);
148 return; 151 return;
149 } 152 }
150 keyFound = true; 153 keyFound = true;
151 if (childNode.data.value !== storageData.value) { 154 if (childNode.data.value !== storageData.value) {
152 childNode.data.value = storageData.value; 155 childNode.data.value = storageData.value;
153 childNode.refresh(); 156 childNode.refresh();
154 childNode.select(); 157 childNode.select();
155 childNode.reveal(); 158 childNode.reveal();
156 } 159 }
157 this.deleteButton.setVisible(true); 160 this._deleteButton.setEnabled(true);
158 } 161 }
159 } 162 }
160 } 163 }
161 164
162 _update() { 165 _update() {
163 this.detachChildWidgets(); 166 this.detachChildWidgets();
164 this.domStorage.getItems(this._showDOMStorageItems.bind(this)); 167 this.domStorage.getItems(this._showDOMStorageItems.bind(this));
165 } 168 }
166 169
167 _showDOMStorageItems(error, items) { 170 _showDOMStorageItems(error, items) {
168 if (error) 171 if (error)
169 return; 172 return;
170 173
171 this._dataGrid = this._dataGridForDOMStorageItems(items); 174 this._dataGrid = this._dataGridForDOMStorageItems(items);
172 this._dataGrid.asWidget().show(this.element); 175 this._dataGrid.asWidget().show(this.element);
173 this.deleteButton.setVisible(this._dataGrid.rootNode().children.length > 1); 176 this._deleteButton.setEnabled(this._dataGrid.rootNode().children.length > 1) ;
174 } 177 }
175 178
176 _dataGridForDOMStorageItems(items) { 179 _dataGridForDOMStorageItems(items) {
177 var columns = /** @type {!Array<!DataGrid.DataGrid.ColumnDescriptor>} */ ([ 180 var columns = /** @type {!Array<!DataGrid.DataGrid.ColumnDescriptor>} */ ([
178 {id: 'key', title: Common.UIString('Key'), sortable: false, editable: true , weight: 50}, 181 {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} 182 {id: 'value', title: Common.UIString('Value'), sortable: false, editable: true, weight: 50}
180 ]); 183 ]);
181 184
182 var nodes = []; 185 var nodes = [];
183 186
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 } 249 }
247 250
248 _deleteCallback(node) { 251 _deleteCallback(node) {
249 if (!node || node.isCreationNode) 252 if (!node || node.isCreationNode)
250 return; 253 return;
251 254
252 if (this.domStorage) 255 if (this.domStorage)
253 this.domStorage.removeItem(node.data.key); 256 this.domStorage.removeItem(node.data.key);
254 } 257 }
255 }; 258 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698