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

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

Issue 2567873002: DevTools: Add ability to add and edit cookies (Closed)
Patch Set: Created 4 years 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) 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 this._refreshCallback = refreshCallback; 44 this._refreshCallback = refreshCallback;
45 45
46 var columns = /** @type {!Array<!UI.DataGrid.ColumnDescriptor>} */ ([ 46 var columns = /** @type {!Array<!UI.DataGrid.ColumnDescriptor>} */ ([
47 { 47 {
48 id: 'name', 48 id: 'name',
49 title: Common.UIString('Name'), 49 title: Common.UIString('Name'),
50 sortable: true, 50 sortable: true,
51 disclosure: expandable, 51 disclosure: expandable,
52 sort: UI.DataGrid.Order.Ascending, 52 sort: UI.DataGrid.Order.Ascending,
53 longText: true, 53 longText: true,
54 weight: 24 54 weight: 24,
55 editable: true
55 }, 56 },
56 {id: 'value', title: Common.UIString('Value'), sortable: true, longText: t rue, weight: 34}, 57 {id: 'value', title: Common.UIString('Value'), sortable: true, longText: t rue, weight: 34, editable: true},
57 {id: 'domain', title: Common.UIString('Domain'), sortable: true, weight: 7 }, 58 {id: 'domain', title: Common.UIString('Domain'), sortable: true, weight: 7 , editable: true},
58 {id: 'path', title: Common.UIString('Path'), sortable: true, weight: 7}, 59 {id: 'path', title: Common.UIString('Path'), sortable: true, weight: 7, ed itable: true},
59 {id: 'expires', title: Common.UIString('Expires / Max-Age'), sortable: tru e, weight: 7}, 60 {id: 'expires', title: Common.UIString('Expires / Max-Age'), sortable: tru e, weight: 7, editable: true},
60 {id: 'size', title: Common.UIString('Size'), sortable: true, align: UI.Dat aGrid.Align.Right, weight: 7}, 61 {id: 'size', title: Common.UIString('Size'), sortable: true, align: UI.Dat aGrid.Align.Right, weight: 7},
61 {id: 'httpOnly', title: Common.UIString('HTTP'), sortable: true, align: UI .DataGrid.Align.Center, weight: 7}, 62 {id: 'httpOnly', title: Common.UIString('HTTP'), sortable: true, align: UI .DataGrid.Align.Center, weight: 7},
62 {id: 'secure', title: Common.UIString('Secure'), sortable: true, align: UI .DataGrid.Align.Center, weight: 7}, { 63 {id: 'secure', title: Common.UIString('Secure'), sortable: true, align: UI .DataGrid.Align.Center, weight: 7}, {
63 id: 'sameSite', 64 id: 'sameSite',
64 title: Common.UIString('SameSite'), 65 title: Common.UIString('SameSite'),
65 sortable: true, 66 sortable: true,
66 align: UI.DataGrid.Align.Center, 67 align: UI.DataGrid.Align.Center,
67 weight: 7 68 weight: 7
68 } 69 }
69 ]); 70 ]);
70 71
71 if (readOnly) { 72 if (readOnly) {
72 this._dataGrid = new UI.DataGrid(columns); 73 this._dataGrid = new UI.DataGrid(columns);
73 } else { 74 } else {
74 this._dataGrid = new UI.DataGrid(columns, undefined, this._onDeleteCookie. bind(this), refreshCallback); 75 this._dataGrid = new UI.DataGrid(columns, this._onUpdateCookie.bind(this), this._onDeleteCookie.bind(this), refreshCallback);
75 this._dataGrid.setRowContextMenuCallback(this._onRowContextMenu.bind(this) ); 76 this._dataGrid.setRowContextMenuCallback(this._onRowContextMenu.bind(this) );
76 } 77 }
77 78
78 this._dataGrid.setName('cookiesTable'); 79 this._dataGrid.setName('cookiesTable');
79 this._dataGrid.addEventListener(UI.DataGrid.Events.SortingChanged, this._reb uildTable, this); 80 this._dataGrid.addEventListener(UI.DataGrid.Events.SortingChanged, this._reb uildTable, this);
80 81
81 if (selectedCallback) 82 if (selectedCallback)
82 this._dataGrid.addEventListener(UI.DataGrid.Events.SelectedNode, selectedC allback, this); 83 this._dataGrid.addEventListener(UI.DataGrid.Events.SelectedNode, selectedC allback, this);
83 84
84 this._nextSelectedCookie = /** @type {?SDK.Cookie} */ (null); 85 this._nextSelectedCookie = /** @type {?SDK.Cookie} */ (null);
86 this._lastEditedColumnId = /** @type {?string} */ (null);
85 87
86 this._dataGrid.asWidget().show(this.element); 88 this._dataGrid.asWidget().show(this.element);
87 this._data = []; 89 this._data = [];
88 } 90 }
89 91
90 /** 92 /**
91 * @param {?string} domain 93 * @param {?string} domain
92 */ 94 */
93 _clearAndRefresh(domain) { 95 _clearAndRefresh(domain) {
94 this.clear(domain); 96 this.clear(domain);
95 this._refresh(); 97 this._refresh();
96 } 98 }
97 99
98 /** 100 /**
99 * @param {!UI.ContextMenu} contextMenu 101 * @param {!UI.ContextMenu} contextMenu
100 * @param {!UI.DataGridNode} node 102 * @param {!UI.DataGridNode} node
101 */ 103 */
102 _onRowContextMenu(contextMenu, node) { 104 _onRowContextMenu(contextMenu, node) {
103 if (node === this._dataGrid.creationNode) 105 if (node.isCreationNode)
104 return; 106 return;
105 var domain = node.cookie.domain(); 107
108 const cookie = node.cookie;
109 const checkmark = '\u2713';
110 contextMenu.appendCheckboxItem(
111 Common.UIString('Secure flag'),
112 this._setCookieFlag.bind(this, node, 'secure', cookie.secure() ? '' : chec kmark),
113 cookie.secure(),
114 false
115 );
116 contextMenu.appendCheckboxItem(
117 Common.UIString('HttpOnly flag'),
118 this._setCookieFlag.bind(this, node, 'httpOnly', cookie.httpOnly() ? '' : checkmark),
119 cookie.httpOnly(),
120 false
121 );
122
123 var sameSiteSubmenu = contextMenu.appendSubMenuItem(Common.UIString('SameSit e flag'));
124 sameSiteSubmenu.appendCheckboxItem(
125 Common.UIString('<empty>'),
126 this._setCookieFlag.bind(this, node, 'sameSite', ''),
127 !cookie.sameSite(),
128 false
129 );
130 sameSiteSubmenu.appendCheckboxItem(
131 Protocol.Network.CookieSameSite.Lax,
132 this._setCookieFlag.bind(this, node, 'sameSite', Protocol.Network.CookieSa meSite.Lax),
133 cookie.sameSite() === Protocol.Network.CookieSameSite.Lax,
134 false
135 );
136 sameSiteSubmenu.appendCheckboxItem(
137 Protocol.Network.CookieSameSite.Strict,
138 this._setCookieFlag.bind(this, node, 'sameSite', Protocol.Network.CookieSa meSite.Strict),
139 cookie.sameSite() === Protocol.Network.CookieSameSite.Strict,
140 false
141 );
142 contextMenu.appendSeparator();
143
144 var domain = cookie.domain();
106 if (domain) { 145 if (domain) {
107 contextMenu.appendItem( 146 contextMenu.appendItem(
108 Common.UIString.capitalize('Clear ^all from "%s"', domain), this._clea rAndRefresh.bind(this, domain)); 147 Common.UIString.capitalize('Clear ^all from "%s"', domain), this._clea rAndRefresh.bind(this, domain));
109 } 148 }
110 contextMenu.appendItem(Common.UIString.capitalize('Clear ^all'), this._clear AndRefresh.bind(this, null)); 149 contextMenu.appendItem(Common.UIString.capitalize('Clear ^all'), this._clear AndRefresh.bind(this, null));
111 } 150 }
112 151
152 _setCookieFlag(node, flag, value) {
153 node.data[flag] = value;
154 node.refresh();
155 this._saveNode(node);
156 }
157
113 /** 158 /**
114 * @param {!Array.<!SDK.Cookie>} cookies 159 * @param {!Array.<!SDK.Cookie>} cookies
115 */ 160 */
116 setCookies(cookies) { 161 setCookies(cookies) {
117 this.setCookieFolders([{cookies: cookies}]); 162 this.setCookieFolders([{cookies: cookies}]);
118 } 163 }
119 164
120 /** 165 /**
121 * @param {!Array.<!{folderName: ?string, cookies: !Array.<!SDK.Cookie>}>} coo kieFolders 166 * @param {!Array.<!{folderName: ?string, cookies: !Array.<!SDK.Cookie>}>} coo kieFolders
122 */ 167 */
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 var groupNode = new UI.DataGridNode(groupData); 212 var groupNode = new UI.DataGridNode(groupData);
168 groupNode.selectable = true; 213 groupNode.selectable = true;
169 this._dataGrid.rootNode().appendChild(groupNode); 214 this._dataGrid.rootNode().appendChild(groupNode);
170 groupNode.element().classList.add('row-group'); 215 groupNode.element().classList.add('row-group');
171 this._populateNode(groupNode, item.cookies, selectedCookie); 216 this._populateNode(groupNode, item.cookies, selectedCookie);
172 groupNode.expand(); 217 groupNode.expand();
173 } else { 218 } else {
174 this._populateNode(this._dataGrid.rootNode(), item.cookies, selectedCook ie); 219 this._populateNode(this._dataGrid.rootNode(), item.cookies, selectedCook ie);
175 } 220 }
176 } 221 }
222
223 this._dataGrid.addCreationNode(false);
177 } 224 }
178 225
179 /** 226 /**
180 * @param {!UI.DataGridNode} parentNode 227 * @param {!UI.DataGridNode} parentNode
181 * @param {?Array.<!SDK.Cookie>} cookies 228 * @param {?Array.<!SDK.Cookie>} cookies
182 * @param {?SDK.Cookie} selectedCookie 229 * @param {?SDK.Cookie} selectedCookie
183 */ 230 */
184 _populateNode(parentNode, cookies, selectedCookie) { 231 _populateNode(parentNode, cookies, selectedCookie) {
185 parentNode.removeChildren(); 232 parentNode.removeChildren();
186 if (!cookies) 233 if (!cookies)
187 return; 234 return;
188 235
189 this._sortCookies(cookies); 236 this._sortCookies(cookies);
190 for (var i = 0; i < cookies.length; ++i) { 237 for (var i = 0; i < cookies.length; ++i) {
191 var cookie = cookies[i]; 238 var cookie = cookies[i];
192 var cookieNode = this._createGridNode(cookie); 239 var cookieNode = this._createGridNode(cookie);
193 parentNode.appendChild(cookieNode); 240 parentNode.appendChild(cookieNode);
194 if (selectedCookie && selectedCookie.name() === cookie.name() && selectedC ookie.domain() === cookie.domain() && 241 if (selectedCookie && selectedCookie.name() === cookie.name() && selectedC ookie.domain() === cookie.domain() &&
195 selectedCookie.path() === cookie.path()) 242 selectedCookie.path() === cookie.path()) {
196 cookieNode.select(); 243 cookieNode.select();
244 if (this._lastEditedColumnId !== null) {
245 const column = this._dataGrid._columns[this._lastEditedColumnId];
246 const cellIndex = this._dataGrid._visibleColumnsArray.indexOf(column);
247 const nextEditableColumn = this._dataGrid._nextEditableColumn(cellInde x);
248 if (nextEditableColumn !== -1)
249 this._dataGrid._startEditingColumnOfDataGridNode(cookieNode, nextEdi tableColumn);
250 this._lastEditedColumnId = null;
251 }
252 }
197 } 253 }
198 } 254 }
199 255
200 _totalSize(cookies) { 256 _totalSize(cookies) {
201 var totalSize = 0; 257 var totalSize = 0;
202 for (var i = 0; cookies && i < cookies.length; ++i) 258 for (var i = 0; cookies && i < cookies.length; ++i)
203 totalSize += cookies[i].size(); 259 totalSize += cookies[i].size();
204 return totalSize; 260 return totalSize;
205 } 261 }
206 262
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 357
302 _onDeleteCookie(node) { 358 _onDeleteCookie(node) {
303 var cookie = node.cookie; 359 var cookie = node.cookie;
304 var neighbour = node.traverseNextNode() || node.traversePreviousNode(); 360 var neighbour = node.traverseNextNode() || node.traversePreviousNode();
305 if (neighbour) 361 if (neighbour)
306 this._nextSelectedCookie = neighbour.cookie; 362 this._nextSelectedCookie = neighbour.cookie;
307 cookie.remove(); 363 cookie.remove();
308 this._refresh(); 364 this._refresh();
309 } 365 }
310 366
367 _onUpdateCookie(editingNode, columnIdentifier, oldText, newText) {
368 this._lastEditedColumnId = columnIdentifier;
369 this._setDefaults(editingNode);
370 this._saveNode(editingNode);
371 }
372
373 _setDefaults(node) {
374 if (node.data.name === null)
375 node.data.name = '';
376 if (node.data.value === null)
377 node.data.value = '';
378 if (node.data.domain === null) {
379 var target = SDK.targetManager.targets(SDK.Target.Capability.Network)[0];
380 var url = new URL(target.inspectedURL());
381 node.data.domain = url.hostname;
382 }
383 if (node.data.path === null)
384 node.data.path = '/';
385 if (node.data.expires === null)
386 node.data.expires = '';
387 }
388
389 _saveNode(node) {
390 var oldCookie = node.cookie;
391 var newCookie = this._createCookieFromData(node.data);
392 if (oldCookie && (newCookie.name() !== oldCookie.name() || newCookie.url() ! == oldCookie.url())) oldCookie.remove();
393 node.cookie = newCookie;
394 newCookie.save();
395 this._nextSelectedCookie = newCookie;
396 this._refresh();
397 }
398
399 _createCookieFromData(data) {
400 var target = SDK.targetManager.targets(SDK.Target.Capability.Network)[0];
401 var cookie = new SDK.Cookie(target, data.name, data.value, null);
402 cookie.addAttribute('domain', data.domain);
403 cookie.addAttribute('path', data.path);
404 if (data.expires) {
405 var secondsSinceEpoch = Date.parse(data.expires) / 1000;
406 cookie.addAttribute('expires', secondsSinceEpoch || undefined);
407 }
408 if (data.httpOnly)
409 cookie.addAttribute('httpOnly');
410 if (data.secure)
411 cookie.addAttribute('secure');
412 if (data.sameSite)
413 cookie.addAttribute('sameSite', data.sameSite);
414 cookie.setSize(data.name.length + data.value.length);
415 return cookie;
416 }
417
311 _refresh() { 418 _refresh() {
312 if (this._refreshCallback) 419 if (this._refreshCallback)
313 this._refreshCallback(); 420 this._refreshCallback();
314 } 421 }
315 }; 422 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698