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

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

Issue 2215773002: Add ability to add/edit cookie in Chrome Dev Tool (front-end) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Manage cookie flags from the context menu Created 4 years, 3 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/sdk/CookieParser.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 25 matching lines...) Expand all
36 * @param {function()=} selectedCallback 36 * @param {function()=} selectedCallback
37 */ 37 */
38 WebInspector.CookiesTable = function(expandable, refreshCallback, selectedCallba ck) 38 WebInspector.CookiesTable = function(expandable, refreshCallback, selectedCallba ck)
39 { 39 {
40 WebInspector.VBox.call(this); 40 WebInspector.VBox.call(this);
41 41
42 var readOnly = expandable; 42 var readOnly = expandable;
43 this._refreshCallback = refreshCallback; 43 this._refreshCallback = refreshCallback;
44 44
45 var columns = [ 45 var columns = [
46 {id: "name", title: WebInspector.UIString("Name"), sortable: true, discl osure: expandable, sort: WebInspector.DataGrid.Order.Ascending, longText: true, weight: 24}, 46 {id: "name", title: WebInspector.UIString("Name"), sortable: true, discl osure: expandable, sort: WebInspector.DataGrid.Order.Ascending, longText: true, weight: 24, editable: true},
47 {id: "value", title: WebInspector.UIString("Value"), sortable: true, lon gText: true, weight: 34}, 47 {id: "value", title: WebInspector.UIString("Value"), sortable: true, lon gText: true, weight: 34, editable: true},
48 {id: "domain", title: WebInspector.UIString("Domain"), sortable: true, w eight: 7}, 48 {id: "domain", title: WebInspector.UIString("Domain"), sortable: true, w eight: 7, editable: true},
49 {id: "path", title: WebInspector.UIString("Path"), sortable: true, weigh t: 7}, 49 {id: "path", title: WebInspector.UIString("Path"), sortable: true, weigh t: 7, editable: true},
50 {id: "expires", title: WebInspector.UIString("Expires / Max-Age"), sorta ble: true, weight: 7}, 50 {id: "expires", title: WebInspector.UIString("Expires / Max-Age"), sorta ble: true, weight: 7, editable: true},
51 {id: "size", title: WebInspector.UIString("Size"), sortable: true, align : WebInspector.DataGrid.Align.Right, weight: 7}, 51 {id: "size", title: WebInspector.UIString("Size"), sortable: true, align : WebInspector.DataGrid.Align.Right, weight: 7},
52 {id: "httpOnly", title: WebInspector.UIString("HTTP"), sortable: true, a lign: WebInspector.DataGrid.Align.Center, weight: 7}, 52 {id: "httpOnly", title: WebInspector.UIString("HTTP"), sortable: true, a lign: WebInspector.DataGrid.Align.Center, weight: 7},
53 {id: "secure", title: WebInspector.UIString("Secure"), sortable: true, a lign: WebInspector.DataGrid.Align.Center, weight: 7}, 53 {id: "secure", title: WebInspector.UIString("Secure"), sortable: true, a lign: WebInspector.DataGrid.Align.Center, weight: 7},
54 {id: "sameSite", title: WebInspector.UIString("SameSite"), sortable: tru e, align: WebInspector.DataGrid.Align.Center, weight: 7} 54 {id: "sameSite", title: WebInspector.UIString("SameSite"), sortable: tru e, align: WebInspector.DataGrid.Align.Center, weight: 7}
55 ]; 55 ];
56 56
57 if (readOnly) 57 if (readOnly)
58 this._dataGrid = new WebInspector.DataGrid(columns); 58 this._dataGrid = new WebInspector.DataGrid(columns);
59 else 59 else
60 this._dataGrid = new WebInspector.DataGrid(columns, undefined, this._onD eleteCookie.bind(this), refreshCallback, this._onContextMenu.bind(this)); 60 this._dataGrid = new WebInspector.DataGrid(columns, this._onUpdateCookie .bind(this), this._onDeleteCookie.bind(this), refreshCallback, this._onContextMe nu.bind(this));
61 61
62 this._dataGrid.setName("cookiesTable"); 62 this._dataGrid.setName("cookiesTable");
63 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SortingChanged, this._rebuildTable, this); 63 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SortingChanged, this._rebuildTable, this);
64 64
65 if (selectedCallback) 65 if (selectedCallback)
66 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SelectedNod e, selectedCallback, this); 66 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SelectedNod e, selectedCallback, this);
67 67
68 this._nextSelectedCookie = /** @type {?WebInspector.Cookie} */ (null); 68 this._nextSelectedCookie = /** @type {?WebInspector.Cookie} */ (null);
69 69
70 this._dataGrid.asWidget().show(this.element); 70 this._dataGrid.asWidget().show(this.element);
71 this._data = []; 71 this._data = [];
72 } 72 }
73 73
74 WebInspector.CookiesTable.prototype = { 74 WebInspector.CookiesTable.prototype = {
75 /** 75 /**
76 * @param {?string} domain 76 * @param {?string} domain
77 */ 77 */
78 _clearAndRefresh: function(domain) 78 _clearAndRefresh: function(domain)
79 { 79 {
80 this.clear(domain); 80 this.clear(domain);
81 this._refresh(); 81 this._refresh();
82 }, 82 },
83 83
84 /** 84 /**
85 * @param {!WebInspector.ContextMenu} contextMenu 85 * @param {!WebInspector.ContextMenu} contextMenu
86 * @param {!WebInspector.DataGridNode} node 86 * @param {!WebInspector.DataGridNode} node
87 */ 87 */
88 _onContextMenu: function(contextMenu, node) 88 _onContextMenu: function(contextMenu, node)
89 { 89 {
90 if (node === this._dataGrid.creationNode) 90 if (node.isCreationNode)
91 return; 91 return;
92 var cookie = node.cookie; 92 var cookie = node.cookie;
93 const checkmark = "\u2713";
94 contextMenu.appendCheckboxItem(WebInspector.UIString("Secure flag"), thi s._setCookieFlag.bind(this, node, "secure", cookie.secure() ? "" : checkmark), c ookie.secure(), false);
95 contextMenu.appendCheckboxItem(WebInspector.UIString("HttpOnly flag"), t his._setCookieFlag.bind(this, node, "httpOnly", cookie.httpOnly() ? "" : checkma rk), cookie.httpOnly(), false);
96 var sameSiteSubmenu = contextMenu.appendSubMenuItem(WebInspector.UIStrin g("SameSite flag"));
97 sameSiteSubmenu.appendCheckboxItem(WebInspector.UIString("<empty>"), thi s._setCookieFlag.bind(this, node, "sameSite", ""), !cookie.sameSite(), false);
98 sameSiteSubmenu.appendCheckboxItem(NetworkAgent.CookieSameSite.Lax, this ._setCookieFlag.bind(this, node, "sameSite", NetworkAgent.CookieSameSite.Lax), c ookie.sameSite() === NetworkAgent.CookieSameSite.Lax, false);
99 sameSiteSubmenu.appendCheckboxItem(NetworkAgent.CookieSameSite.Strict, t his._setCookieFlag.bind(this, node, "sameSite", NetworkAgent.CookieSameSite.Stri ct), cookie.sameSite() === NetworkAgent.CookieSameSite.Strict, false);
100 contextMenu.appendSeparator();
93 var domain = cookie.domain(); 101 var domain = cookie.domain();
94 if (domain) 102 if (domain)
95 contextMenu.appendItem(WebInspector.UIString.capitalize("Clear ^all from \"%s\"", domain), this._clearAndRefresh.bind(this, domain)); 103 contextMenu.appendItem(WebInspector.UIString.capitalize("Clear ^all from \"%s\"", domain), this._clearAndRefresh.bind(this, domain));
96 contextMenu.appendItem(WebInspector.UIString.capitalize("Clear ^all"), t his._clearAndRefresh.bind(this, null)); 104 contextMenu.appendItem(WebInspector.UIString.capitalize("Clear ^all"), t his._clearAndRefresh.bind(this, null));
97 }, 105 },
98 106
107 _setCookieFlag(node, flag, value)
108 {
109 node.data[flag] = value;
110 node.refresh();
111 this._saveNode(node);
112 },
113
99 /** 114 /**
100 * @param {!Array.<!WebInspector.Cookie>} cookies 115 * @param {!Array.<!WebInspector.Cookie>} cookies
101 */ 116 */
102 setCookies: function(cookies) 117 setCookies: function(cookies)
103 { 118 {
104 this.setCookieFolders([{cookies: cookies}]); 119 this.setCookieFolders([{cookies: cookies}]);
105 }, 120 },
106 121
107 /** 122 /**
108 * @param {!Array.<!{folderName: ?string, cookies: !Array.<!WebInspector.Coo kie>}>} cookieFolders 123 * @param {!Array.<!{folderName: ?string, cookies: !Array.<!WebInspector.Coo kie>}>} cookieFolders
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 var groupData = {name: item.folderName, value: "", domain: "", p ath: "", expires: "", size: this._totalSize(item.cookies), httpOnly: "", secure: "", sameSite: ""}; 162 var groupData = {name: item.folderName, value: "", domain: "", p ath: "", expires: "", size: this._totalSize(item.cookies), httpOnly: "", secure: "", sameSite: ""};
148 var groupNode = new WebInspector.DataGridNode(groupData); 163 var groupNode = new WebInspector.DataGridNode(groupData);
149 groupNode.selectable = true; 164 groupNode.selectable = true;
150 this._dataGrid.rootNode().appendChild(groupNode); 165 this._dataGrid.rootNode().appendChild(groupNode);
151 groupNode.element().classList.add("row-group"); 166 groupNode.element().classList.add("row-group");
152 this._populateNode(groupNode, item.cookies, selectedCookie); 167 this._populateNode(groupNode, item.cookies, selectedCookie);
153 groupNode.expand(); 168 groupNode.expand();
154 } else 169 } else
155 this._populateNode(this._dataGrid.rootNode(), item.cookies, sele ctedCookie); 170 this._populateNode(this._dataGrid.rootNode(), item.cookies, sele ctedCookie);
156 } 171 }
172 this._dataGrid.addCreationNode(false);
157 }, 173 },
158 174
159 /** 175 /**
160 * @param {!WebInspector.DataGridNode} parentNode 176 * @param {!WebInspector.DataGridNode} parentNode
161 * @param {?Array.<!WebInspector.Cookie>} cookies 177 * @param {?Array.<!WebInspector.Cookie>} cookies
162 * @param {?WebInspector.Cookie} selectedCookie 178 * @param {?WebInspector.Cookie} selectedCookie
163 */ 179 */
164 _populateNode: function(parentNode, cookies, selectedCookie) 180 _populateNode: function(parentNode, cookies, selectedCookie)
165 { 181 {
166 parentNode.removeChildren(); 182 parentNode.removeChildren();
167 if (!cookies) 183 if (!cookies)
168 return; 184 return;
169 185
170 this._sortCookies(cookies); 186 this._sortCookies(cookies);
171 for (var i = 0; i < cookies.length; ++i) { 187 for (var i = 0; i < cookies.length; ++i) {
172 var cookie = cookies[i]; 188 var cookie = cookies[i];
173 var cookieNode = this._createGridNode(cookie); 189 var cookieNode = this._createGridNode(cookie);
174 parentNode.appendChild(cookieNode); 190 parentNode.appendChild(cookieNode);
175 if (selectedCookie && selectedCookie.name() === cookie.name() && sel ectedCookie.domain() === cookie.domain() && selectedCookie.path() === cookie.pat h()) 191 if (selectedCookie && selectedCookie.name() === cookie.name() && sel ectedCookie.url() === cookie.url())
176 cookieNode.select(); 192 cookieNode.select();
177 } 193 }
178 }, 194 },
179 195
180 _totalSize: function(cookies) 196 _totalSize: function(cookies)
181 { 197 {
182 var totalSize = 0; 198 var totalSize = 0;
183 for (var i = 0; cookies && i < cookies.length; ++i) 199 for (var i = 0; cookies && i < cookies.length; ++i)
184 totalSize += cookies[i].size(); 200 totalSize += cookies[i].size();
185 return totalSize; 201 return totalSize;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 _onDeleteCookie: function(node) 288 _onDeleteCookie: function(node)
273 { 289 {
274 var cookie = node.cookie; 290 var cookie = node.cookie;
275 var neighbour = node.traverseNextNode() || node.traversePreviousNode(); 291 var neighbour = node.traverseNextNode() || node.traversePreviousNode();
276 if (neighbour) 292 if (neighbour)
277 this._nextSelectedCookie = neighbour.cookie; 293 this._nextSelectedCookie = neighbour.cookie;
278 cookie.remove(); 294 cookie.remove();
279 this._refresh(); 295 this._refresh();
280 }, 296 },
281 297
298 _onUpdateCookie: function(editingNode, columnIdentifier, oldText, newText)
299 {
300 var neighbour = editingNode.traverseNextNode() || editingNode.traversePr eviousNode();
301 if (neighbour)
302 this._nextSelectedCookie = neighbour.cookie;
303 if (this._isValidCookieData(editingNode.data)) {
304 this._saveNode(editingNode);
305 editingNode.unsaved = false;
306 } else {
307 editingNode.unsaved = true;
308 }
309 },
310
311 _saveNode: function(node)
312 {
313 var oldCookie = node.cookie;
314 var newCookie = this._createCookieFromData(node.data);
315 if(oldCookie && (newCookie.name() !== oldCookie.name() || newCookie.url( ) !== oldCookie.url()))
316 oldCookie.remove();
317 node.cookie = newCookie;
318 newCookie.save();
319
320 var idx = this._data[0].cookies.indexOf(oldCookie);
321 if(idx !== -1)
322 this._data[0].cookies[idx] = newCookie;
323 else
324 this._data[0].cookies.push(newCookie);
325
326 this._removeDupes(node);
327 this._sortCookies(this._data[0].cookies);
328 this._reorderNodes();
329 },
330
331 _reorderNodes: function()
332 {
333 var rootNode = this._dataGrid.rootNode();
334 var cookies = this._data[0].cookies;
335 for (var i = 0; i < cookies.length; ++i) {
336 var cookie = cookies[i];
337 var node = this._findNodeByCookie(cookie);
338 if(node)
339 rootNode.insertChild(node, i);
340 }
341 },
342
343 _findNodeByCookie: function(cookie)
344 {
345 var rootNode = this._dataGrid.rootNode();
346 var children = rootNode.children;
347 for (var i = children.length - 1; i >= 0; --i) {
348 var childNode = children[i];
349 if (childNode.cookie === cookie)
350 return childNode;
351 }
352 return null;
353 },
354
355 _createCookieFromData: function(data)
356 {
357 var target = WebInspector.targetManager.targets(WebInspector.Target.Capa bility.Network)[0];
358 var cookie = new WebInspector.Cookie(target, data.name, data.value, null );
359 cookie.addAttribute("domain", data.domain);
360 cookie.addAttribute("path", data.path);
361 if (data.expires) {
362 var secondsSinceEpoch = Date.parse(data.expires) / 1000;
363 cookie.addAttribute("expires", secondsSinceEpoch || undefined);
364 }
365 if (data.httpOnly)
366 cookie.addAttribute("httpOnly");
367 if (data.secure)
368 cookie.addAttribute("secure");
369 if (data.sameSite)
370 cookie.addAttribute("sameSite", data.sameSite);
371 cookie.setSize(data.name.length + data.value.length);
372 return cookie;
373 },
374
375 /**
376 * @param {!WebInspector.DataGridNode} masterNode
377 */
378 _removeDupes: function(masterNode)
379 {
380 var rootNode = this._dataGrid.rootNode();
381 var children = rootNode.children;
382 for (var i = children.length - 1; i >= 0; --i) {
383 var childNode = children[i];
384 if (childNode.cookie && childNode.cookie.name() === masterNode.cooki e.name() &&
385 childNode.cookie.url() === masterNode.cookie.url() && masterNode !== childNode)
386 rootNode.removeChild(childNode);
387 }
388 },
389
390 _isValidCookieData: function(data)
391 {
392 return (data.name || data.value) && this._isValidDomain(data.domain) && this._isValidPath(data.path) && this._isValidDate(data.expires);
393 },
394
395 _isValidDomain: function(domain)
396 {
397 var url = null;
398 try {
399 url = new URL('http://' + domain);
400 } catch(e) {
401 return false;
402 }
403 return url.hostname === domain;
404 },
405
406 _isValidPath: function(path)
407 {
408 var url = null;
409 try {
410 url = new URL('http://example.com' + path);
411 } catch(e) {
412 return false;
413 }
414 return url.pathname === path;
415 },
416
417 _isValidDate: function(date)
418 {
419 return date === '' || date === WebInspector.UIString("Session") || !isNa N(Date.parse(date));
420 },
421
282 _refresh: function() 422 _refresh: function()
283 { 423 {
284 if (this._refreshCallback) 424 if (this._refreshCallback)
285 this._refreshCallback(); 425 this._refreshCallback();
286 }, 426 },
287 427
288 __proto__: WebInspector.VBox.prototype 428 __proto__: WebInspector.VBox.prototype
289 } 429 }
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/sdk/CookieParser.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698