Web Inspector: Plumb and expose cookie clearing options throughout the...

Web Inspector: Plumb and expose cookie clearing options throughout the Resources Cookies tree and views
https://bugs.webkit.org/show_bug.cgi?id=87140

Patch by PhistucK <phistuck@chromium.org> on 2013-03-27
Reviewed by Vsevolod Vlasov.

Added cookie clearing buttons and context menu options
throughout the tree and views.
Drive by -
- Made sure the delete button is only visible
when a cookie is selected.
- Fixed a wrong JSDoc comment.

* inspector/front-end/CookieItemsView.js:
(WebInspector.CookieItemsView):
(WebInspector.CookieItemsView.prototype.statusBarItems):
(WebInspector.CookieItemsView.prototype._updateWithCookies):
(WebInspector.CookieItemsView.prototype.clear):
Added. Clears the entire cookie view.
(WebInspector.CookieItemsView.prototype._clearButtonClicked):
Added. Ditto (when clicking on the button).
(WebInspector.CookieItemsView.prototype._showDeleteButton):
Added. Shows the delete button when selecting a cookie row.
* inspector/CookiesTable.js:
(WebInspector.CookiesTable):
(WebInspector.CookiesTable.prototype._clearAndRefresh):
Added. Clears the cookies of the current table and updates it.
(WebInspector.CookiesTable.prototype._handleContextMenuEvent):
Added. Manages the context menu within the table.
(WebInspector.CookiesTable.prototype.clear):
Added. Clears the cookies of the current table.
(WebInspector.CookiesTable.prototype.setCookies):
 Fixed a wrong JSDoc comment structure.
* inspector/front-end/ResourcesPanel.js:
(WebInspector.ResourcesPanel.prototype.clearCookies):
Added. Clears the cookies of the given domain view.
(WebInspector.CookieTreeElement.prototype.onattach):
Added. Adds a contextmenu handler.
(WebInspector.CookieTreeElement.prototype._handleContextMenuEvent):
Added. Manages the context menu within cookie tree.
(WebInspector.CookieTreeElement.prototype._clearCookies):
Added. Clears the cookies of the view of the tree item.
* inspector/front-end/treeoutline.js:
(TreeOutline): Fixed a wrong JSDoc comment.

* English.lproj/localizedStrings.js:
Added strings for the context menu options.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@147031 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent fa0f4dde
2013-03-27 PhistucK <phistuck@chromium.org>
Web Inspector: Plumb and expose cookie clearing options throughout the Resources Cookies tree and views
https://bugs.webkit.org/show_bug.cgi?id=87140
Reviewed by Vsevolod Vlasov.
Added cookie clearing buttons and context menu options
throughout the tree and views.
Drive by -
- Made sure the delete button is only visible
when a cookie is selected.
- Fixed a wrong JSDoc comment.
* inspector/front-end/CookieItemsView.js:
(WebInspector.CookieItemsView):
(WebInspector.CookieItemsView.prototype.statusBarItems):
(WebInspector.CookieItemsView.prototype._updateWithCookies):
(WebInspector.CookieItemsView.prototype.clear):
Added. Clears the entire cookie view.
(WebInspector.CookieItemsView.prototype._clearButtonClicked):
Added. Ditto (when clicking on the button).
(WebInspector.CookieItemsView.prototype._showDeleteButton):
Added. Shows the delete button when selecting a cookie row.
* inspector/CookiesTable.js:
(WebInspector.CookiesTable):
(WebInspector.CookiesTable.prototype._clearAndRefresh):
Added. Clears the cookies of the current table and updates it.
(WebInspector.CookiesTable.prototype._handleContextMenuEvent):
Added. Manages the context menu within the table.
(WebInspector.CookiesTable.prototype.clear):
Added. Clears the cookies of the current table.
(WebInspector.CookiesTable.prototype.setCookies):
Fixed a wrong JSDoc comment structure.
* inspector/front-end/ResourcesPanel.js:
(WebInspector.ResourcesPanel.prototype.clearCookies):
Added. Clears the cookies of the given domain view.
(WebInspector.CookieTreeElement.prototype.onattach):
Added. Adds a contextmenu handler.
(WebInspector.CookieTreeElement.prototype._handleContextMenuEvent):
Added. Manages the context menu within cookie tree.
(WebInspector.CookieTreeElement.prototype._clearCookies):
Added. Clears the cookies of the view of the tree item.
* inspector/front-end/treeoutline.js:
(TreeOutline): Fixed a wrong JSDoc comment.
* English.lproj/localizedStrings.js:
Added strings for the context menu options.
2013-03-27 Andrey Lushnikov <lushnikov@chromium.org>
Web Inspector: [DTE] implement "tokenAtTextPosition" method
......@@ -105,6 +105,10 @@ localizedStrings["Call Stack"] = "Call Stack";
localizedStrings["Call"] = "Call";
localizedStrings["Calls"] = "Calls";
localizedStrings["Cannot find corresponding heap snapshot node"] = "Cannot find corresponding heap snapshot node";
localizedStrings["Clear All"] = "Clear All";
localizedStrings["Clear all"] = "Clear all";
localizedStrings["Clear all from \"%s\""] = "Clear all from \"%s\"";
localizedStrings["Clear All from \"%s\""] = "Clear All from \"%s\"";
localizedStrings["Clear all profiles."] = "Clear all profiles.";
localizedStrings["Clear Browser Cache"] = "Clear Browser Cache";
localizedStrings["Clear browser cache"] = "Clear browser cache";
......
......@@ -41,6 +41,10 @@ WebInspector.CookieItemsView = function(treeElement, cookieDomain)
this._deleteButton.visible = false;
this._deleteButton.addEventListener("click", this._deleteButtonClicked, this);
this._clearButton = new WebInspector.StatusBarButton(WebInspector.UIString("Clear"), "clear-storage-status-bar-item");
this._clearButton.visible = false;
this._clearButton.addEventListener("click", this._clearButtonClicked, this);
this._refreshButton = new WebInspector.StatusBarButton(WebInspector.UIString("Refresh"), "refresh-storage-status-bar-item");
this._refreshButton.addEventListener("click", this._refreshButtonClicked, this);
......@@ -56,7 +60,7 @@ WebInspector.CookieItemsView = function(treeElement, cookieDomain)
WebInspector.CookieItemsView.prototype = {
get statusBarItems()
{
return [this._refreshButton.element, this._deleteButton.element];
return [this._refreshButton.element, this._clearButton.element, this._deleteButton.element];
},
wasShown: function()
......@@ -85,6 +89,7 @@ WebInspector.CookieItemsView.prototype = {
if (!this._cookies.length) {
// Nothing to show.
this._emptyView.show(this.element);
this._clearButton.visible = false;
this._deleteButton.visible = false;
if (this._cookiesTable)
this._cookiesTable.detach();
......@@ -92,7 +97,7 @@ WebInspector.CookieItemsView.prototype = {
}
if (!this._cookiesTable)
this._cookiesTable = isAdvanced ? new WebInspector.CookiesTable(false, this._update.bind(this)) : new WebInspector.SimpleCookiesTable();
this._cookiesTable = isAdvanced ? new WebInspector.CookiesTable(false, this._update.bind(this), this._showDeleteButton.bind(this)) : new WebInspector.SimpleCookiesTable();
this._cookiesTable.setCookies(this._cookies);
this._emptyView.detach();
......@@ -100,7 +105,8 @@ WebInspector.CookieItemsView.prototype = {
if (isAdvanced) {
this._treeElement.subtitle = String.sprintf(WebInspector.UIString("%d cookies (%s)"), this._cookies.length,
Number.bytesToString(this._totalSize));
this._deleteButton.visible = true;
this._clearButton.visible = true;
this._deleteButton.visible = !!this._cookiesTable.selectedCookie();
}
},
......@@ -138,6 +144,22 @@ WebInspector.CookieItemsView.prototype = {
return cookies;
},
clear: function()
{
this._cookiesTable.clear();
this._update();
},
_clearButtonClicked: function()
{
this.clear();
},
_showDeleteButton: function()
{
this._deleteButton.visible = true;
},
_deleteButtonClicked: function()
{
var selectedCookie = this._cookiesTable.selectedCookie();
......
......@@ -33,8 +33,9 @@
* @extends {WebInspector.View}
* @param {boolean} expandable
* @param {function()=} refreshCallback
* @param {function()=} selectedCallback
*/
WebInspector.CookiesTable = function(expandable, refreshCallback)
WebInspector.CookiesTable = function(expandable, refreshCallback, selectedCallback)
{
WebInspector.View.call(this);
this.element.className = "fill";
......@@ -53,9 +54,18 @@ WebInspector.CookiesTable = function(expandable, refreshCallback)
{id: "secure", title: WebInspector.UIString("Secure"), sortable: true, align: WebInspector.DataGrid.Align.Center, width: "7%"}
];
this._dataGrid = new WebInspector.DataGrid(columns, null, readOnly ? null : this._onDeleteCookie.bind(this), refreshCallback);
if (readOnly)
this._dataGrid = new WebInspector.DataGrid(columns, null, null, refreshCallback);
else {
this._dataGrid = new WebInspector.DataGrid(columns);
this._dataGrid.element.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this), true);
}
this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SortingChanged, this._rebuildTable, this);
if (selectedCallback)
this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SelectedNode, selectedCallback, this);
this._nextSelectedCookie = /** @type {?WebInspector.Cookie} */ (null);
this._dataGrid.show(this.element);
......@@ -69,7 +79,44 @@ WebInspector.CookiesTable.prototype = {
this._dataGrid.updateWidths();
},
/*
/**
* @param {?string} domain
*/
_clearAndRefresh: function(domain)
{
this.clear(domain);
if (this._refreshCallback)
this._refreshCallback();
},
_handleContextMenuEvent: function(event)
{
var gridNode = this._dataGrid.dataGridNodeFromNode(event.target);
if (!gridNode)
return;
var contextMenu = new WebInspector.ContextMenu(event);
var cookie = gridNode.cookie;
if (this._refreshCallback)
contextMenu.appendItem(WebInspector.UIString("Refresh"), this._refreshCallback);
if (cookie) {
contextMenu.appendItem(WebInspector.UIString("Delete"), this._onDeleteCookie.bind(this, gridNode));
contextMenu.appendSeparator();
var cookieDomain = cookie.domain();
contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Clear all from \"%s\"" : "Clear All from \"%s\"", cookieDomain), this._clearAndRefresh.bind(this, cookieDomain));
} else
contextMenu.appendSeparator();
contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Clear all" : "Clear All"), this._clearAndRefresh.bind(this, null));
contextMenu.show();
},
/**
* @param {!Array.<!WebInspector.Cookie>} cookies
*/
setCookies: function(cookies)
......@@ -95,6 +142,20 @@ WebInspector.CookiesTable.prototype = {
return node ? node.cookie : null;
},
/**
* @param {string=} domain
*/
clear: function(domain)
{
for (var i = 0, length = this._data.length; i < length; ++i) {
var cookies = this._data[i].cookies;
for (var j = 0, cookieCount = cookies.length; j < cookieCount; ++j) {
if (!domain || cookies[j].domain() === domain)
cookies[j].remove();
}
}
},
_rebuildTable: function()
{
var selectedCookie = this._nextSelectedCookie || this.selectedCookie();
......
......@@ -513,6 +513,14 @@ WebInspector.ResourcesPanel.prototype = {
this._innerShowView(view);
},
/**
* @param {string} cookieDomain
*/
clearCookies: function(cookieDomain)
{
this._cookieViews[cookieDomain].clear();
},
showApplicationCache: function(frameId)
{
if (!this._applicationCacheViews[frameId])
......@@ -1939,6 +1947,30 @@ WebInspector.CookieTreeElement.prototype = {
return "cookies://" + this._cookieDomain;
},
onattach: function()
{
WebInspector.BaseStorageTreeElement.prototype.onattach.call(this);
this.listItemElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this), true);
},
/**
* @param {Event} event
*/
_handleContextMenuEvent: function(event)
{
var contextMenu = new WebInspector.ContextMenu(event);
contextMenu.appendItem(WebInspector.UIString("Clear"), this._clearCookies.bind(this));
contextMenu.show();
},
/**
* @param {string} domain
*/
_clearCookies: function(domain)
{
this._storagePanel.clearCookies(this._cookieDomain);
},
onselect: function(selectedByUser)
{
WebInspector.BaseStorageTreeElement.prototype.onselect.call(this, selectedByUser);
......
......@@ -28,6 +28,7 @@
/**
* @constructor
* @param {Element} listNode
* @param {boolean=} nonFocusable
*/
function TreeOutline(listNode, nonFocusable)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment