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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/cookie_table/CookiesTable.js

Issue 2714913002: DevTools: Fixes to Storage panel inconsistencies (Closed)
Patch Set: more feedback Created 3 years, 9 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/resources/CookieItemsView.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Joseph Pecoraro 3 * Copyright (C) 2009 Joseph Pecoraro
4 * Copyright (C) 2010 Google Inc. All rights reserved. 4 * Copyright (C) 2010 Google Inc. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 9 *
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 18 matching lines...) Expand all
29 */ 29 */
30 30
31 /** 31 /**
32 * @unrestricted 32 * @unrestricted
33 */ 33 */
34 CookieTable.CookiesTable = class extends UI.VBox { 34 CookieTable.CookiesTable = class extends UI.VBox {
35 /** 35 /**
36 * @param {function(!SDK.Cookie, ?SDK.Cookie, function(?string))=} saveCallbac k 36 * @param {function(!SDK.Cookie, ?SDK.Cookie, function(?string))=} saveCallbac k
37 * @param {function()=} refreshCallback 37 * @param {function()=} refreshCallback
38 * @param {function()=} selectedCallback 38 * @param {function()=} selectedCallback
39 * @param {function(!SDK.Cookie, function())=} deleteCallback
39 * @param {string=} cookieDomain 40 * @param {string=} cookieDomain
40 */ 41 */
41 constructor(saveCallback, refreshCallback, selectedCallback, cookieDomain) { 42 constructor(saveCallback, refreshCallback, selectedCallback, deleteCallback, c ookieDomain) {
42 super(); 43 super();
43 44
44 this._saveCallback = saveCallback; 45 this._saveCallback = saveCallback;
45 this._refreshCallback = refreshCallback; 46 this._refreshCallback = refreshCallback;
47 this._deleteCallback = deleteCallback;
46 this._cookieDomain = cookieDomain; 48 this._cookieDomain = cookieDomain;
47 49
48 var editable = !!saveCallback; 50 var editable = !!saveCallback;
49 51
50 var columns = /** @type {!Array<!DataGrid.DataGrid.ColumnDescriptor>} */ ([ 52 var columns = /** @type {!Array<!DataGrid.DataGrid.ColumnDescriptor>} */ ([
51 { 53 {
52 id: 'name', 54 id: 'name',
53 title: Common.UIString('Name'), 55 title: Common.UIString('Name'),
54 sortable: true, 56 sortable: true,
55 disclosure: editable, 57 disclosure: editable,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } else { 93 } else {
92 this._dataGrid = new DataGrid.DataGrid(columns); 94 this._dataGrid = new DataGrid.DataGrid(columns);
93 } 95 }
94 96
95 this._dataGrid.setName('cookiesTable'); 97 this._dataGrid.setName('cookiesTable');
96 this._dataGrid.addEventListener(DataGrid.DataGrid.Events.SortingChanged, thi s._rebuildTable, this); 98 this._dataGrid.addEventListener(DataGrid.DataGrid.Events.SortingChanged, thi s._rebuildTable, this);
97 99
98 if (selectedCallback) 100 if (selectedCallback)
99 this._dataGrid.addEventListener(DataGrid.DataGrid.Events.SelectedNode, sel ectedCallback, this); 101 this._dataGrid.addEventListener(DataGrid.DataGrid.Events.SelectedNode, sel ectedCallback, this);
100 102
101 this._nextSelectedCookie = /** @type {?SDK.Cookie} */ (null);
102 /** @type {?string} */ 103 /** @type {?string} */
103 this._lastEditedColumnId = null; 104 this._lastEditedColumnId = null;
104 105
105 this._dataGrid.asWidget().show(this.element); 106 this._dataGrid.asWidget().show(this.element);
106 this._data = []; 107 this._data = [];
107 } 108 }
108 109
109 /** 110 /**
110 * @param {!Array.<!SDK.Cookie>} cookies 111 * @param {!Array.<!SDK.Cookie>} cookies
111 */ 112 */
(...skipping 11 matching lines...) Expand all
123 124
124 /** 125 /**
125 * @return {?SDK.Cookie} 126 * @return {?SDK.Cookie}
126 */ 127 */
127 selectedCookie() { 128 selectedCookie() {
128 var node = this._dataGrid.selectedNode; 129 var node = this._dataGrid.selectedNode;
129 return node ? node.cookie : null; 130 return node ? node.cookie : null;
130 } 131 }
131 132
132 /** 133 /**
134 * @return {{current: ?SDK.Cookie, neighbor: ?SDK.Cookie}}
135 */
136 _getSelectionCookies() {
137 var node = this._dataGrid.selectedNode;
138 var neighbor = node && (node.traverseNextNode(true) || node.traversePrevious Node(true));
139
140 return {current: node && node.cookie, neighbor: neighbor && neighbor.cookie} ;
141 }
142
143 /**
133 * @override 144 * @override
134 */ 145 */
135 willHide() { 146 willHide() {
136 this._lastEditedColumnId = null; 147 this._lastEditedColumnId = null;
137 } 148 }
138 149
150 /**
151 * @param {{current: ?SDK.Cookie, neighbor: ?SDK.Cookie}} selectionCookies
152 * @param {!Array<!SDK.Cookie>} cookies
153 * @return {?SDK.Cookie}
154 */
155 _findSelectedCookie(selectionCookies, cookies) {
156 var current = selectionCookies.current;
157 var foundCurrent = cookies.find(cookie => this._isSameCookie(cookie, current ));
158 if (foundCurrent)
159 return foundCurrent;
160
161 var neighbor = selectionCookies.neighbor;
162 var foundNeighbor = cookies.find(cookie => this._isSameCookie(cookie, neighb or));
163 if (foundNeighbor)
164 return foundNeighbor;
165
166 return null;
167 }
168
169 /**
170 * @param {!SDK.Cookie} cookieA
171 * @param {?SDK.Cookie} cookieB
172 * @return {boolean}
173 */
174 _isSameCookie(cookieA, cookieB) {
175 return !!cookieB && cookieB.name() === cookieA.name() && cookieB.domain() == = cookieA.domain() &&
176 cookieB.path() === cookieA.path();
177 }
178
139 _rebuildTable() { 179 _rebuildTable() {
140 var selectedCookie = this._nextSelectedCookie || this.selectedCookie(); 180 var selectionCookies = this._getSelectionCookies();
141 var lastEditedColumnId = this._lastEditedColumnId; 181 var lastEditedColumnId = this._lastEditedColumnId;
142 this._nextSelectedCookie = null;
143 this._lastEditedColumnId = null; 182 this._lastEditedColumnId = null;
144 this._dataGrid.rootNode().removeChildren(); 183 this._dataGrid.rootNode().removeChildren();
145 for (var i = 0; i < this._data.length; ++i) { 184 for (var i = 0; i < this._data.length; ++i) {
146 var item = this._data[i]; 185 var item = this._data[i];
186 var selectedCookie = this._findSelectedCookie(selectionCookies, item.cooki es);
147 if (item.folderName) { 187 if (item.folderName) {
148 var groupData = { 188 var groupData = {
149 name: item.folderName, 189 name: item.folderName,
150 value: '', 190 value: '',
151 domain: '', 191 domain: '',
152 path: '', 192 path: '',
153 expires: '', 193 expires: '',
154 size: this._totalSize(item.cookies), 194 size: this._totalSize(item.cookies),
155 httpOnly: '', 195 httpOnly: '',
156 secure: '', 196 secure: '',
(...skipping 24 matching lines...) Expand all
181 _populateNode(parentNode, cookies, selectedCookie, lastEditedColumnId) { 221 _populateNode(parentNode, cookies, selectedCookie, lastEditedColumnId) {
182 parentNode.removeChildren(); 222 parentNode.removeChildren();
183 if (!cookies) 223 if (!cookies)
184 return; 224 return;
185 225
186 this._sortCookies(cookies); 226 this._sortCookies(cookies);
187 for (var i = 0; i < cookies.length; ++i) { 227 for (var i = 0; i < cookies.length; ++i) {
188 var cookie = cookies[i]; 228 var cookie = cookies[i];
189 var cookieNode = this._createGridNode(cookie); 229 var cookieNode = this._createGridNode(cookie);
190 parentNode.appendChild(cookieNode); 230 parentNode.appendChild(cookieNode);
191 if (selectedCookie && selectedCookie.name() === cookie.name() && selectedC ookie.domain() === cookie.domain() && 231 if (this._isSameCookie(cookie, selectedCookie)) {
192 selectedCookie.path() === cookie.path()) {
193 cookieNode.select(); 232 cookieNode.select();
194 if (lastEditedColumnId !== null) 233 if (lastEditedColumnId !== null)
195 this._dataGrid.startEditingNextEditableColumnOfDataGridNode(cookieNode , lastEditedColumnId); 234 this._dataGrid.startEditingNextEditableColumnOfDataGridNode(cookieNode , lastEditedColumnId);
196 } 235 }
197 } 236 }
198 } 237 }
199 238
200 /** 239 /**
201 * @param {!DataGrid.DataGridNode} parentNode 240 * @param {!DataGrid.DataGridNode} parentNode
202 * @param {!SDK.Cookie} cookie 241 * @param {!SDK.Cookie} cookie
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 data.httpOnly = (cookie.httpOnly() ? checkmark : ''); 345 data.httpOnly = (cookie.httpOnly() ? checkmark : '');
307 data.secure = (cookie.secure() ? checkmark : ''); 346 data.secure = (cookie.secure() ? checkmark : '');
308 data.sameSite = cookie.sameSite() || ''; 347 data.sameSite = cookie.sameSite() || '';
309 348
310 var node = new DataGrid.DataGridNode(data); 349 var node = new DataGrid.DataGridNode(data);
311 node.cookie = cookie; 350 node.cookie = cookie;
312 node.selectable = true; 351 node.selectable = true;
313 return node; 352 return node;
314 } 353 }
315 354
355 /**
356 * @param {!DataGrid.DataGridNode} node
357 */
316 _onDeleteCookie(node) { 358 _onDeleteCookie(node) {
317 var cookie = node.cookie; 359 if (node.cookie && this._deleteCallback)
318 var neighbour = node.traverseNextNode() || node.traversePreviousNode(); 360 this._deleteCallback(node.cookie, () => this._refresh());
319 if (neighbour)
320 this._nextSelectedCookie = neighbour.cookie;
321 cookie.remove();
322 this._refresh();
323 } 361 }
324 362
325 /** 363 /**
326 * @param {!DataGrid.DataGridNode} editingNode 364 * @param {!DataGrid.DataGridNode} editingNode
327 * @param {string} columnIdentifier 365 * @param {string} columnIdentifier
328 * @param {string} oldText 366 * @param {string} oldText
329 * @param {string} newText 367 * @param {string} newText
330 */ 368 */
331 _onUpdateCookie(editingNode, columnIdentifier, oldText, newText) { 369 _onUpdateCookie(editingNode, columnIdentifier, oldText, newText) {
332 this._lastEditedColumnId = columnIdentifier; 370 this._lastEditedColumnId = columnIdentifier;
(...skipping 26 matching lines...) Expand all
359 _saveNode(node) { 397 _saveNode(node) {
360 var oldCookie = node.cookie; 398 var oldCookie = node.cookie;
361 var newCookie = this._createCookieFromData(node.data); 399 var newCookie = this._createCookieFromData(node.data);
362 node.cookie = newCookie; 400 node.cookie = newCookie;
363 this._saveCallback(newCookie, oldCookie, error => { 401 this._saveCallback(newCookie, oldCookie, error => {
364 if (!error) 402 if (!error)
365 this._refresh(); 403 this._refresh();
366 else 404 else
367 node.setDirty(true); 405 node.setDirty(true);
368 }); 406 });
369 this._nextSelectedCookie = newCookie;
370 } 407 }
371 408
372 /** 409 /**
373 * @param {!Object.<string, *>} data 410 * @param {!Object.<string, *>} data
374 * @returns {!SDK.Cookie} 411 * @returns {!SDK.Cookie}
375 */ 412 */
376 _createCookieFromData(data) { 413 _createCookieFromData(data) {
377 var cookie = new SDK.Cookie(data.name, data.value, null); 414 var cookie = new SDK.Cookie(data.name, data.value, null);
378 cookie.addAttribute('domain', data.domain); 415 cookie.addAttribute('domain', data.domain);
379 cookie.addAttribute('path', data.path); 416 cookie.addAttribute('path', data.path);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 } 464 }
428 465
429 _refresh() { 466 _refresh() {
430 if (this._refreshCallback) 467 if (this._refreshCallback)
431 this._refreshCallback(); 468 this._refreshCallback();
432 } 469 }
433 }; 470 };
434 471
435 /** @const */ 472 /** @const */
436 CookieTable.CookiesTable._expiresSessionValue = Common.UIString('Session'); 473 CookieTable.CookiesTable._expiresSessionValue = Common.UIString('Session');
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/resources/CookieItemsView.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698