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

Unified 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: Code review fixes - part 2. 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 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/resources/CookieItemsView.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 9fe4e6de1f9ff5d36fdb52d5d44006d2783d7b5c..b96f8864264dc674d0488c263220e7e5720b4462 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
@@ -33,30 +33,33 @@
*/
Components.CookiesTable = class extends UI.VBox {
/**
- * @param {boolean} expandable
+ * @param {boolean} readOnly
* @param {function()=} refreshCallback
* @param {function()=} selectedCallback
+ * @param {string=} cookieDomain
*/
- constructor(expandable, refreshCallback, selectedCallback) {
+ constructor(readOnly, refreshCallback, selectedCallback, cookieDomain) {
super();
- var readOnly = expandable;
+ this._readOnly = readOnly;
this._refreshCallback = refreshCallback;
+ this._cookieDomain = cookieDomain;
var columns = /** @type {!Array<!UI.DataGrid.ColumnDescriptor>} */ ([
{
id: 'name',
title: Common.UIString('Name'),
sortable: true,
- disclosure: expandable,
+ disclosure: !this._readOnly,
sort: UI.DataGrid.Order.Ascending,
longText: true,
- weight: 24
+ weight: 24,
+ editable: true
allada 2016/12/14 03:04:15 Shouldn't we still address this? by setting it whe
kdzwinel 2016/12/14 14:26:50 Ah! It wasn't intended. I just missed this one.
},
- {id: 'value', title: Common.UIString('Value'), sortable: true, longText: true, weight: 34},
- {id: 'domain', title: Common.UIString('Domain'), sortable: true, weight: 7},
- {id: 'path', title: Common.UIString('Path'), sortable: true, weight: 7},
- {id: 'expires', title: Common.UIString('Expires / Max-Age'), sortable: true, weight: 7},
+ {id: 'value', title: Common.UIString('Value'), sortable: true, longText: true, weight: 34, editable: !this._readOnly},
+ {id: 'domain', title: Common.UIString('Domain'), sortable: true, weight: 7, editable: !this._readOnly},
+ {id: 'path', title: Common.UIString('Path'), sortable: true, weight: 7, editable: !this._readOnly},
+ {id: 'expires', title: Common.UIString('Expires / Max-Age'), sortable: true, weight: 7, editable: !this._readOnly},
{id: 'size', title: Common.UIString('Size'), sortable: true, align: UI.DataGrid.Align.Right, weight: 7},
{id: 'httpOnly', title: Common.UIString('HTTP'), sortable: true, align: UI.DataGrid.Align.Center, weight: 7},
{id: 'secure', title: Common.UIString('Secure'), sortable: true, align: UI.DataGrid.Align.Center, weight: 7}, {
@@ -68,10 +71,10 @@ Components.CookiesTable = class extends UI.VBox {
}
]);
- if (readOnly) {
+ if (this._readOnly) {
this._dataGrid = new UI.DataGrid(columns);
} else {
- this._dataGrid = new UI.DataGrid(columns, undefined, this._onDeleteCookie.bind(this), refreshCallback);
+ this._dataGrid = new UI.DataGrid(columns, this._onUpdateCookie.bind(this), this._onDeleteCookie.bind(this), refreshCallback);
this._dataGrid.setRowContextMenuCallback(this._onRowContextMenu.bind(this));
}
@@ -82,6 +85,8 @@ Components.CookiesTable = class extends UI.VBox {
this._dataGrid.addEventListener(UI.DataGrid.Events.SelectedNode, selectedCallback, this);
this._nextSelectedCookie = /** @type {?SDK.Cookie} */ (null);
+ /** @type {?string} */
+ this._lastEditedColumnId = null;
this._dataGrid.asWidget().show(this.element);
this._data = [];
@@ -100,9 +105,45 @@ Components.CookiesTable = class extends UI.VBox {
* @param {!UI.DataGridNode} node
*/
_onRowContextMenu(contextMenu, node) {
- if (node === this._dataGrid.creationNode)
+ if (node.isCreationNode)
return;
- var domain = node.cookie.domain();
+
+ const cookie = node.cookie;
+ const checkmark = '\u2713';
+ contextMenu.appendCheckboxItem(
+ Common.UIString('Secure flag'),
+ this._setCookieFlag.bind(this, node, 'secure', cookie.secure() ? '' : checkmark),
+ cookie.secure(),
+ false
+ );
+ contextMenu.appendCheckboxItem(
+ Common.UIString('HttpOnly flag'),
+ this._setCookieFlag.bind(this, node, 'httpOnly', cookie.httpOnly() ? '' : checkmark),
+ cookie.httpOnly(),
+ false
+ );
+
+ var sameSiteSubmenu = contextMenu.appendSubMenuItem(Common.UIString('SameSite flag'));
+ sameSiteSubmenu.appendItem(
+ Common.UIString('No Restriction'),
+ this._setCookieFlag.bind(this, node, 'sameSite', ''),
+ false
+ );
+ sameSiteSubmenu.appendCheckboxItem(
+ Protocol.Network.CookieSameSite.Lax,
+ this._setCookieFlag.bind(this, node, 'sameSite', Protocol.Network.CookieSameSite.Lax),
+ cookie.sameSite() === Protocol.Network.CookieSameSite.Lax,
+ false
+ );
+ sameSiteSubmenu.appendCheckboxItem(
+ Protocol.Network.CookieSameSite.Strict,
+ this._setCookieFlag.bind(this, node, 'sameSite', Protocol.Network.CookieSameSite.Strict),
+ cookie.sameSite() === Protocol.Network.CookieSameSite.Strict,
+ false
+ );
+ contextMenu.appendSeparator();
+
+ var domain = cookie.domain();
if (domain) {
contextMenu.appendItem(
Common.UIString.capitalize('Clear ^all from "%s"', domain), this._clearAndRefresh.bind(this, domain));
@@ -110,6 +151,12 @@ Components.CookiesTable = class extends UI.VBox {
contextMenu.appendItem(Common.UIString.capitalize('Clear ^all'), this._clearAndRefresh.bind(this, null));
}
+ _setCookieFlag(node, flag, value) {
+ node.data[flag] = value;
+ node.refresh();
+ this._saveNode(node);
+ }
+
/**
* @param {!Array.<!SDK.Cookie>} cookies
*/
@@ -146,9 +193,18 @@ Components.CookiesTable = class extends UI.VBox {
}
}
+ /**
+ * @override
+ */
+ willHide() {
+ this._lastEditedColumnId = null;
+ }
+
_rebuildTable() {
var selectedCookie = this._nextSelectedCookie || this.selectedCookie();
+ var lastEditedColumnId = this._lastEditedColumnId;
this._nextSelectedCookie = null;
+ this._lastEditedColumnId = null;
this._dataGrid.rootNode().removeChildren();
for (var i = 0; i < this._data.length; ++i) {
var item = this._data[i];
@@ -168,20 +224,23 @@ Components.CookiesTable = class extends UI.VBox {
groupNode.selectable = true;
this._dataGrid.rootNode().appendChild(groupNode);
groupNode.element().classList.add('row-group');
- this._populateNode(groupNode, item.cookies, selectedCookie);
+ this._populateNode(groupNode, item.cookies, selectedCookie, lastEditedColumnId);
groupNode.expand();
} else {
- this._populateNode(this._dataGrid.rootNode(), item.cookies, selectedCookie);
+ this._populateNode(this._dataGrid.rootNode(), item.cookies, selectedCookie, lastEditedColumnId);
}
}
+ if (!this._readOnly)
+ this._dataGrid.addCreationNode(false);
}
/**
* @param {!UI.DataGridNode} parentNode
* @param {?Array.<!SDK.Cookie>} cookies
* @param {?SDK.Cookie} selectedCookie
+ * @param {?string} lastEditedColumnId
*/
- _populateNode(parentNode, cookies, selectedCookie) {
+ _populateNode(parentNode, cookies, selectedCookie, lastEditedColumnId) {
parentNode.removeChildren();
if (!cookies)
return;
@@ -192,8 +251,11 @@ Components.CookiesTable = class extends UI.VBox {
var cookieNode = this._createGridNode(cookie);
parentNode.appendChild(cookieNode);
if (selectedCookie && selectedCookie.name() === cookie.name() && selectedCookie.domain() === cookie.domain() &&
- selectedCookie.path() === cookie.path())
+ selectedCookie.path() === cookie.path()) {
cookieNode.select();
+ if (lastEditedColumnId !== null)
+ this._dataGrid.startEditingNextEditableColumnOfDataGridNode(cookieNode, lastEditedColumnId);
+ }
}
}
@@ -308,6 +370,114 @@ Components.CookiesTable = class extends UI.VBox {
this._refresh();
}
+ /**
+ * @param {!UI.DataGridNode} editingNode
+ * @param {string} columnIdentifier
+ * @param {string} oldText
+ * @param {string} newText
+ */
+ _onUpdateCookie(editingNode, columnIdentifier, oldText, newText) {
+ this._lastEditedColumnId = columnIdentifier;
+ this._setDefaults(editingNode);
+ if (this._isValidCookieData(editingNode.data))
+ this._saveNode(editingNode);
+ else
+ editingNode.unsaved = true;
+ }
+
+ /**
+ * @param {!UI.DataGridNode} node
+ */
+ _setDefaults(node) {
+ if (node.data.name === null)
+ node.data.name = '';
+ if (node.data.value === null)
+ node.data.value = '';
+ if (node.data.domain === null)
+ node.data.domain = this._cookieDomain;
+ if (node.data.path === null)
+ node.data.path = '/';
+ if (node.data.expires === null)
+ node.data.expires = Common.UIString('Session');
+ }
+
+ /**
+ * @param {!UI.DataGridNode} node
+ */
+ _saveNode(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((error, success) => {
+ if (success)
+ this._refresh();
+ else
+ node.unsaved = true;
+ });
+ this._nextSelectedCookie = newCookie;
+ }
+
+ /**
+ * @param {!Object.<string, *>} data
+ * @returns {SDK.Cookie}
+ */
+ _createCookieFromData(data) {
+ var target = SDK.targetManager.targets(SDK.Target.Capability.Network)[0];
+ var cookie = new SDK.Cookie(target, data.name, data.value, null);
+ cookie.addAttribute('domain', data.domain);
+ cookie.addAttribute('path', data.path);
+ if (data.expires && data.expires !== Common.UIString('Session')) {
+ var secondsSinceEpoch = Math.floor(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 {!Object.<string, *>} data
+ * @returns {boolean}
+ */
+ _isValidCookieData(data) {
+ return (data.name || data.value) && this._isValidDomain(data.domain) && this._isValidPath(data.path) && this._isValidDate(data.expires);
+ }
+
+ /**
+ * @param {string} domain
+ * @returns {boolean}
+ */
+ _isValidDomain(domain) {
+ if (!domain)
+ return true;
+ var parsedURL = ('http://' + domain).asParsedURL();
+ return !!parsedURL && parsedURL.domain() === domain;
allada 2016/12/14 03:04:15 Any reason we are double-banging this? I thought i
kdzwinel 2016/12/14 14:26:50 without the double-bang this method may return nul
+ }
+
+ /**
+ * @param {string} path
+ * @returns {boolean}
+ */
+ _isValidPath(path) {
+ var parsedURL = ('http://example.com' + path).asParsedURL();
+ return !!parsedURL && parsedURL.path === path;
allada 2016/12/14 03:04:15 Same as above.
+ }
+
+ /**
+ * @param {string} date
+ * @returns {boolean}
+ */
+ _isValidDate(date) {
+ return date === '' || date === Common.UIString('Session') || !isNaN(Date.parse(date));
allada 2016/12/14 03:04:15 I think we can just this here: return !isNaN(Date.
kdzwinel 2016/12/14 14:26:50 This will cause empty string and `Common.UIString(
+ }
+
_refresh() {
if (this._refreshCallback)
this._refreshCallback();
« 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