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

Unified 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, 4 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/devtools/front_end/components_lazy/CookiesTable.js
diff --git a/third_party/WebKit/Source/devtools/front_end/components_lazy/CookiesTable.js b/third_party/WebKit/Source/devtools/front_end/components_lazy/CookiesTable.js
index 9eeb9e7a0862a7f346838fb3334112f4bfd95d11..8a006522fbd0b0458fc5a391dd20ba1c404ec625 100644
--- a/third_party/WebKit/Source/devtools/front_end/components_lazy/CookiesTable.js
+++ b/third_party/WebKit/Source/devtools/front_end/components_lazy/CookiesTable.js
@@ -43,11 +43,11 @@ WebInspector.CookiesTable = function(expandable, refreshCallback, selectedCallba
this._refreshCallback = refreshCallback;
var columns = [
- {id: "name", title: WebInspector.UIString("Name"), sortable: true, disclosure: expandable, sort: WebInspector.DataGrid.Order.Ascending, longText: true, weight: 24},
- {id: "value", title: WebInspector.UIString("Value"), sortable: true, longText: true, weight: 34},
- {id: "domain", title: WebInspector.UIString("Domain"), sortable: true, weight: 7},
- {id: "path", title: WebInspector.UIString("Path"), sortable: true, weight: 7},
- {id: "expires", title: WebInspector.UIString("Expires / Max-Age"), sortable: true, weight: 7},
+ {id: "name", title: WebInspector.UIString("Name"), sortable: true, disclosure: expandable, sort: WebInspector.DataGrid.Order.Ascending, longText: true, weight: 24, editable: true},
+ {id: "value", title: WebInspector.UIString("Value"), sortable: true, longText: true, weight: 34, editable: true},
+ {id: "domain", title: WebInspector.UIString("Domain"), sortable: true, weight: 7, editable: true},
+ {id: "path", title: WebInspector.UIString("Path"), sortable: true, weight: 7, editable: true},
+ {id: "expires", title: WebInspector.UIString("Expires / Max-Age"), sortable: true, weight: 7, editable: true},
{id: "size", title: WebInspector.UIString("Size"), sortable: true, align: WebInspector.DataGrid.Align.Right, weight: 7},
{id: "httpOnly", title: WebInspector.UIString("HTTP"), sortable: true, align: WebInspector.DataGrid.Align.Center, weight: 7},
{id: "secure", title: WebInspector.UIString("Secure"), sortable: true, align: WebInspector.DataGrid.Align.Center, weight: 7},
@@ -57,7 +57,7 @@ WebInspector.CookiesTable = function(expandable, refreshCallback, selectedCallba
if (readOnly)
this._dataGrid = new WebInspector.DataGrid(columns);
else
- this._dataGrid = new WebInspector.DataGrid(columns, undefined, this._onDeleteCookie.bind(this), refreshCallback, this._onContextMenu.bind(this));
+ this._dataGrid = new WebInspector.DataGrid(columns, this._onUpdateCookie.bind(this), this._onDeleteCookie.bind(this), refreshCallback, this._onContextMenu.bind(this));
this._dataGrid.setName("cookiesTable");
this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SortingChanged, this._rebuildTable, this);
@@ -87,15 +87,30 @@ WebInspector.CookiesTable.prototype = {
*/
_onContextMenu: function(contextMenu, node)
{
- if (node === this._dataGrid.creationNode)
+ if (node.isCreationNode)
return;
var cookie = node.cookie;
+ const checkmark = "\u2713";
+ contextMenu.appendCheckboxItem(WebInspector.UIString("Secure flag"), this._setCookieFlag.bind(this, node, "secure", cookie.secure() ? "" : checkmark), cookie.secure(), false);
+ contextMenu.appendCheckboxItem(WebInspector.UIString("HttpOnly flag"), this._setCookieFlag.bind(this, node, "httpOnly", cookie.httpOnly() ? "" : checkmark), cookie.httpOnly(), false);
+ var sameSiteSubmenu = contextMenu.appendSubMenuItem(WebInspector.UIString("SameSite flag"));
+ sameSiteSubmenu.appendCheckboxItem(WebInspector.UIString("<empty>"), this._setCookieFlag.bind(this, node, "sameSite", ""), !cookie.sameSite(), false);
+ sameSiteSubmenu.appendCheckboxItem(NetworkAgent.CookieSameSite.Lax, this._setCookieFlag.bind(this, node, "sameSite", NetworkAgent.CookieSameSite.Lax), cookie.sameSite() === NetworkAgent.CookieSameSite.Lax, false);
+ sameSiteSubmenu.appendCheckboxItem(NetworkAgent.CookieSameSite.Strict, this._setCookieFlag.bind(this, node, "sameSite", NetworkAgent.CookieSameSite.Strict), cookie.sameSite() === NetworkAgent.CookieSameSite.Strict, false);
+ contextMenu.appendSeparator();
var domain = cookie.domain();
if (domain)
contextMenu.appendItem(WebInspector.UIString.capitalize("Clear ^all from \"%s\"", domain), this._clearAndRefresh.bind(this, domain));
contextMenu.appendItem(WebInspector.UIString.capitalize("Clear ^all"), this._clearAndRefresh.bind(this, null));
},
+ _setCookieFlag(node, flag, value)
+ {
+ node.data[flag] = value;
+ node.refresh();
+ this._saveNode(node);
+ },
+
/**
* @param {!Array.<!WebInspector.Cookie>} cookies
*/
@@ -154,6 +169,7 @@ WebInspector.CookiesTable.prototype = {
} else
this._populateNode(this._dataGrid.rootNode(), item.cookies, selectedCookie);
}
+ this._dataGrid.addCreationNode(false);
},
/**
@@ -172,7 +188,7 @@ WebInspector.CookiesTable.prototype = {
var cookie = cookies[i];
var cookieNode = this._createGridNode(cookie);
parentNode.appendChild(cookieNode);
- if (selectedCookie && selectedCookie.name() === cookie.name() && selectedCookie.domain() === cookie.domain() && selectedCookie.path() === cookie.path())
+ if (selectedCookie && selectedCookie.name() === cookie.name() && selectedCookie.url() === cookie.url())
cookieNode.select();
}
},
@@ -279,6 +295,130 @@ WebInspector.CookiesTable.prototype = {
this._refresh();
},
+ _onUpdateCookie: function(editingNode, columnIdentifier, oldText, newText)
+ {
+ var neighbour = editingNode.traverseNextNode() || editingNode.traversePreviousNode();
+ if (neighbour)
+ this._nextSelectedCookie = neighbour.cookie;
+ if (this._isValidCookieData(editingNode.data)) {
+ this._saveNode(editingNode);
+ editingNode.unsaved = false;
+ } else {
+ editingNode.unsaved = true;
+ }
+ },
+
+ _saveNode: function(node)
+ {
+ var oldCookie = node.cookie;
+ var newCookie = this._createCookieFromData(node.data);
+ if(oldCookie && (newCookie.name() !== oldCookie.name() || newCookie.url() !== oldCookie.url()))
+ oldCookie.remove();
+ node.cookie = newCookie;
+ newCookie.save();
+
+ var idx = this._data[0].cookies.indexOf(oldCookie);
+ if(idx !== -1)
+ this._data[0].cookies[idx] = newCookie;
+ else
+ this._data[0].cookies.push(newCookie);
+
+ this._removeDupes(node);
+ this._sortCookies(this._data[0].cookies);
+ this._reorderNodes();
+ },
+
+ _reorderNodes: function()
+ {
+ var rootNode = this._dataGrid.rootNode();
+ var cookies = this._data[0].cookies;
+ for (var i = 0; i < cookies.length; ++i) {
+ var cookie = cookies[i];
+ var node = this._findNodeByCookie(cookie);
+ if(node)
+ rootNode.insertChild(node, i);
+ }
+ },
+
+ _findNodeByCookie: function(cookie)
+ {
+ var rootNode = this._dataGrid.rootNode();
+ var children = rootNode.children;
+ for (var i = children.length - 1; i >= 0; --i) {
+ var childNode = children[i];
+ if (childNode.cookie === cookie)
+ return childNode;
+ }
+ return null;
+ },
+
+ _createCookieFromData: function(data)
+ {
+ var target = WebInspector.targetManager.targets(WebInspector.Target.Capability.Network)[0];
+ var cookie = new WebInspector.Cookie(target, data.name, data.value, null);
+ cookie.addAttribute("domain", data.domain);
+ cookie.addAttribute("path", data.path);
+ if (data.expires) {
+ var secondsSinceEpoch = Date.parse(data.expires) / 1000;
+ cookie.addAttribute("expires", secondsSinceEpoch || undefined);
+ }
+ if (data.httpOnly)
+ cookie.addAttribute("httpOnly");
+ if (data.secure)
+ cookie.addAttribute("secure");
+ if (data.sameSite)
+ cookie.addAttribute("sameSite", data.sameSite);
+ cookie.setSize(data.name.length + data.value.length);
+ return cookie;
+ },
+
+ /**
+ * @param {!WebInspector.DataGridNode} masterNode
+ */
+ _removeDupes: function(masterNode)
+ {
+ var rootNode = this._dataGrid.rootNode();
+ var children = rootNode.children;
+ for (var i = children.length - 1; i >= 0; --i) {
+ var childNode = children[i];
+ if (childNode.cookie && childNode.cookie.name() === masterNode.cookie.name() &&
+ childNode.cookie.url() === masterNode.cookie.url() && masterNode !== childNode)
+ rootNode.removeChild(childNode);
+ }
+ },
+
+ _isValidCookieData: function(data)
+ {
+ return (data.name || data.value) && this._isValidDomain(data.domain) && this._isValidPath(data.path) && this._isValidDate(data.expires);
+ },
+
+ _isValidDomain: function(domain)
+ {
+ var url = null;
+ try {
+ url = new URL('http://' + domain);
+ } catch(e) {
+ return false;
+ }
+ return url.hostname === domain;
+ },
+
+ _isValidPath: function(path)
+ {
+ var url = null;
+ try {
+ url = new URL('http://example.com' + path);
+ } catch(e) {
+ return false;
+ }
+ return url.pathname === path;
+ },
+
+ _isValidDate: function(date)
+ {
+ return date === '' || date === WebInspector.UIString("Session") || !isNaN(Date.parse(date));
+ },
+
_refresh: function()
{
if (this._refreshCallback)
« 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