Skip to content
Permalink
Browse files
2010-10-25 Andrey Kosyakov <caseq@chromium.org>
        Reviewed by Pavel Feldman.

        Web Inspector: Show cookie data in the request headers in network pane
        https://bugs.webkit.org/show_bug.cgi?id=16531

        * inspector/front-end/CookieItemsView.js:
        (WebInspector.CookieItemsView): Factor out common cookies grid logic to CookiesTable
        (WebInspector.CookieItemsView.prototype._populateDataGrid):
        * inspector/front-end/CookieParser.js: Store cookie type (request/response) within a cookie.
        (WebInspector.CookieParser.prototype.parseCookie):
        (WebInspector.CookieParser.prototype.parseSetCookie):
        (WebInspector.CookieParser.prototype._addCookie):
        (WebInspector.Cookie):
        * inspector/front-end/DataGrid.js:
        (WebInspector.DataGrid.prototype.autoSizeColumns): Optionally, traverse nested nodes when looking for max field widths.
        (WebInspector.DataGrid.prototype._enumerateChildren):
        (WebInspector.DataGrid.prototype.updateWidths): Skip attempt to calculate column widths if grid is not attached to DOM tree yet.
        * inspector/front-end/FontView.js:
        (WebInspector.FontView.prototype.resize):
        * inspector/front-end/ResourceView.js:
        (WebInspector.ResourceView.prototype.resize):
        (WebInspector.ResourceView.prototype._selectTab):
        (WebInspector.ResourceView.prototype._selectCookiesTab):
        (WebInspector.ResourceView.prototype._innerSelectContentTab):
        (WebInspector.ResourceView.prototype._refreshRequestHeaders):
        (WebInspector.ResourceView.prototype._refreshResponseHeaders):
        (WebInspector.ResourceView.prototype._refreshHeaders):
        (WebInspector.ResourceView.prototype._refreshCookies):
        (WebInspector.ResourceCookiesTab):
        (WebInspector.ResourceCookiesTab.prototype.set requestCookies):
        (WebInspector.ResourceCookiesTab.prototype.set responseCookies):
        (WebInspector.ResourceCookiesTab.prototype._populateDataGrid):
        (WebInspector.ResourceCookiesTab.prototype._populateCookies):
        (WebInspector.ResourceCookiesTab.prototype._createFolder):
        * inspector/front-end/SourceView.js:
        (WebInspector.SourceView.prototype.resize):
        * inspector/front-end/inspector.css:
        (.resource-view .resource-view-cookies):
        (.resource-view.headers-visible .resource-view-cookies):
        (.resource-view-cookies.table .data-grid):
        (.resource-view-cookies .data-grid .row-group):


Canonical link: https://commits.webkit.org/61061@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@70529 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
caseq committed Oct 26, 2010
1 parent 33e7214 commit 3e6a46e0ed8f84853918b4671ca79bec73903cbb
Showing 9 changed files with 329 additions and 121 deletions.
@@ -1,3 +1,47 @@
2010-10-25 Andrey Kosyakov <caseq@chromium.org>

Reviewed by Pavel Feldman.

Web Inspector: Show cookie data in the request headers in network pane
https://bugs.webkit.org/show_bug.cgi?id=16531

* inspector/front-end/CookieItemsView.js:
(WebInspector.CookieItemsView): Factor out common cookies grid logic to CookiesTable
(WebInspector.CookieItemsView.prototype._populateDataGrid):
* inspector/front-end/CookieParser.js: Store cookie type (request/response) within a cookie.
(WebInspector.CookieParser.prototype.parseCookie):
(WebInspector.CookieParser.prototype.parseSetCookie):
(WebInspector.CookieParser.prototype._addCookie):
(WebInspector.Cookie):
* inspector/front-end/DataGrid.js:
(WebInspector.DataGrid.prototype.autoSizeColumns): Optionally, traverse nested nodes when looking for max field widths.
(WebInspector.DataGrid.prototype._enumerateChildren):
(WebInspector.DataGrid.prototype.updateWidths): Skip attempt to calculate column widths if grid is not attached to DOM tree yet.
* inspector/front-end/FontView.js:
(WebInspector.FontView.prototype.resize):
* inspector/front-end/ResourceView.js:
(WebInspector.ResourceView.prototype.resize):
(WebInspector.ResourceView.prototype._selectTab):
(WebInspector.ResourceView.prototype._selectCookiesTab):
(WebInspector.ResourceView.prototype._innerSelectContentTab):
(WebInspector.ResourceView.prototype._refreshRequestHeaders):
(WebInspector.ResourceView.prototype._refreshResponseHeaders):
(WebInspector.ResourceView.prototype._refreshHeaders):
(WebInspector.ResourceView.prototype._refreshCookies):
(WebInspector.ResourceCookiesTab):
(WebInspector.ResourceCookiesTab.prototype.set requestCookies):
(WebInspector.ResourceCookiesTab.prototype.set responseCookies):
(WebInspector.ResourceCookiesTab.prototype._populateDataGrid):
(WebInspector.ResourceCookiesTab.prototype._populateCookies):
(WebInspector.ResourceCookiesTab.prototype._createFolder):
* inspector/front-end/SourceView.js:
(WebInspector.SourceView.prototype.resize):
* inspector/front-end/inspector.css:
(.resource-view .resource-view-cookies):
(.resource-view.headers-visible .resource-view-cookies):
(.resource-view-cookies.table .data-grid):
(.resource-view-cookies .data-grid .row-group):

2010-10-26 Sheriff Bot <webkit.review.bot@gmail.com>

Unreviewed, rolling out r70518.
Binary file not shown.
@@ -27,12 +27,141 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

WebInspector.CookieItemsView = function(treeElement, cookieDomain)
WebInspector.CookiesTable = function()
{
WebInspector.View.call(this);

this.element.addStyleClass("storage-view");
this.element.addStyleClass("table");
}

WebInspector.CookiesTable.prototype = {
resize: function()
{
if (!this._dataGrid)
return;

if (this._autoSizingDone)
this._dataGrid.updateWidths();
else {
this._autoSizingDone = true;
this._dataGrid.autoSizeColumns(4, 45, 1);
}
},

_createDataGrid: function(expandable)
{
var columns = { 0: {}, 1: {}, 2: {}, 3: {}, 4: {}, 5: {}, 6: {}, 7: {} };
columns[0].title = WebInspector.UIString("Name");
columns[0].sortable = true;
columns[0].disclosure = expandable;
columns[1].title = WebInspector.UIString("Value");
columns[1].sortable = true;
columns[2].title = WebInspector.UIString("Domain");
columns[2].sortable = true;
columns[3].title = WebInspector.UIString("Path");
columns[3].sortable = true;
columns[4].title = WebInspector.UIString("Expires");
columns[4].sortable = true;
columns[5].title = WebInspector.UIString("Size");
columns[5].aligned = "right";
columns[5].sortable = true;
columns[6].title = WebInspector.UIString("HTTP");
columns[6].aligned = "centered";
columns[6].sortable = true;
columns[7].title = WebInspector.UIString("Secure");
columns[7].aligned = "centered";
columns[7].sortable = true;

var deleteCallback = this._deleteCookieCallback ? this._deleteCookieCallback.bind(this) : null;
this._dataGrid = new WebInspector.DataGrid(columns, null, deleteCallback);
this._dataGrid.addEventListener("sorting changed", this._populateDataGrid, this);
this.element.appendChild(this._dataGrid.element);
},

_populateCookies: function(parentNode, cookies)
{
var selectedCookie = this._dataGrid.selectedNode ? this._dataGrid.selectedNode.cookie : null;
parentNode.removeChildren();
if (!cookies)
return;
this._sortCookies(cookies);
var totalSize = 0;
for (var i = 0; i < cookies.length; ++i) {
var cookieNode = this._createGridNode(cookies[i]);
parentNode.appendChild(cookieNode);
if (selectedCookie === cookies[i])
cookieNode.selected = true;
}
},

_sortCookies: function(cookies)
{
var sortDirection = this._dataGrid.sortOrder === "ascending" ? 1 : -1;

function localeCompare(field, cookie1, cookie2)
{
return sortDirection * (cookie1[field] + "").localeCompare(cookie2[field] + "")
}

function numberCompare(field, cookie1, cookie2)
{
return sortDirection * (cookie1[field] - cookie2[field]);
}

function expiresCompare(cookie1, cookie2)
{
if (cookie1.session !== cookie2.session)
return sortDirection * (cookie1.session ? 1 : -1);

if (cookie1.session)
return 0;

return sortDirection * (cookie1.expires - cookie2.expires);
}

var comparator;
switch (parseInt(this._dataGrid.sortColumnIdentifier)) {
case 0: comparator = localeCompare.bind(this, "name"); break;
case 1: comparator = localeCompare.bind(this, "value"); break;
case 2: comparator = localeCompare.bind(this, "domain"); break;
case 3: comparator = localeCompare.bind(this, "path"); break;
case 4: comparator = expiresCompare; break;
case 5: comparator = numberCompare.bind(this, "size"); break;
case 6: comparator = localeCompare.bind(this, "httpOnly"); break;
case 7: comparator = localeCompare.bind(this, "secure"); break;
default: localeCompare.bind(this, "name");
}

cookies.sort(comparator);
},

_createGridNode: function(cookie)
{
var data = {};
data[0] = cookie.name;
data[1] = cookie.value;
data[2] = cookie.domain || "";
data[3] = cookie.path || "";
data[4] = cookie.type === WebInspector.Cookie.Type.Request ? "" :
(cookie.session ? WebInspector.UIString("Session") : new Date(cookie.expires).toGMTString());
data[5] = cookie.size;
data[6] = (cookie.httpOnly ? "\u2713" : ""); // Checkmark
data[7] = (cookie.secure ? "\u2713" : ""); // Checkmark

var node = new WebInspector.DataGridNode(data);
node.cookie = cookie;
node.selectable = true;
return node;
}
};

WebInspector.CookiesTable.prototype.__proto__ = WebInspector.View.prototype;

WebInspector.CookieItemsView = function(treeElement, cookieDomain)
{
WebInspector.CookiesTable.call(this);

this.element.addStyleClass("storage-view");

this.deleteButton = new WebInspector.StatusBarButton(WebInspector.UIString("Delete"), "delete-storage-status-bar-item");
this.deleteButton.visible = false;
@@ -143,101 +272,9 @@ WebInspector.CookieItemsView.prototype = {
}
},

_createDataGrid: function()
{
var columns = { 0: {}, 1: {}, 2: {}, 3: {}, 4: {}, 5: {}, 6: {}, 7: {} };
columns[0].title = WebInspector.UIString("Name");
columns[0].sortable = true;
columns[1].title = WebInspector.UIString("Value");
columns[1].sortable = true;
columns[2].title = WebInspector.UIString("Domain");
columns[2].sortable = true;
columns[3].title = WebInspector.UIString("Path");
columns[3].sortable = true;
columns[4].title = WebInspector.UIString("Expires");
columns[4].sortable = true;
columns[5].title = WebInspector.UIString("Size");
columns[5].aligned = "right";
columns[5].sortable = true;
columns[6].title = WebInspector.UIString("HTTP");
columns[6].aligned = "centered";
columns[6].sortable = true;
columns[7].title = WebInspector.UIString("Secure");
columns[7].aligned = "centered";
columns[7].sortable = true;

this._dataGrid = new WebInspector.DataGrid(columns, null, this._deleteCookieCallback.bind(this));
this._dataGrid.addEventListener("sorting changed", this._populateDataGrid, this);
this.element.appendChild(this._dataGrid.element);
this._dataGrid.updateWidths();
},

_populateDataGrid: function()
{
var selectedCookie = this._dataGrid.selectedNode ? this._dataGrid.selectedNode.cookie : null;
var sortDirection = this._dataGrid.sortOrder === "ascending" ? 1 : -1;

function localeCompare(field, cookie1, cookie2)
{
return sortDirection * (cookie1[field] + "").localeCompare(cookie2[field] + "")
}

function numberCompare(field, cookie1, cookie2)
{
return sortDirection * (cookie1[field] - cookie2[field]);
}

function expiresCompare(cookie1, cookie2)
{
if (cookie1.session !== cookie2.session)
return sortDirection * (cookie1.session ? 1 : -1);

if (cookie1.session)
return 0;

return sortDirection * (cookie1.expires - cookie2.expires);
}

var comparator;
switch (parseInt(this._dataGrid.sortColumnIdentifier)) {
case 0: comparator = localeCompare.bind(this, "name"); break;
case 1: comparator = localeCompare.bind(this, "value"); break;
case 2: comparator = localeCompare.bind(this, "domain"); break;
case 3: comparator = localeCompare.bind(this, "path"); break;
case 4: comparator = expiresCompare; break;
case 5: comparator = numberCompare.bind(this, "size"); break;
case 6: comparator = localeCompare.bind(this, "httpOnly"); break;
case 7: comparator = localeCompare.bind(this, "secure"); break;
default: localeCompare.bind(this, "name");
}

this._cookies.sort(comparator);

this._dataGrid.removeChildren();
var nodeToSelect;
for (var i = 0; i < this._cookies.length; ++i) {
var data = {};
var cookie = this._cookies[i];
data[0] = cookie.name;
data[1] = cookie.value;
data[2] = cookie.domain;
data[3] = cookie.path;
data[4] = (cookie.session ? WebInspector.UIString("Session") : new Date(cookie.expires).toGMTString());
data[5] = Number.bytesToString(cookie.size, WebInspector.UIString);
data[6] = (cookie.httpOnly ? "\u2713" : ""); // Checkmark
data[7] = (cookie.secure ? "\u2713" : ""); // Checkmark

var node = new WebInspector.DataGridNode(data);
node.cookie = cookie;
node.selectable = true;
this._dataGrid.appendChild(node);
if (cookie === selectedCookie)
nodeToSelect = node;
}
if (nodeToSelect)
nodeToSelect.selected = true;
else
this._dataGrid.children[0].selected = true;
this._populateCookies(this._dataGrid, this._cookies);
},

_createSimpleDataGrid: function()
@@ -273,12 +310,6 @@ WebInspector.CookieItemsView.prototype = {
this._dataGrid.children[0].selected = true;
},

resize: function()
{
if (this._dataGrid)
this._dataGrid.updateWidths();
},

_deleteButtonClicked: function(event)
{
if (!this._dataGrid || !this._dataGrid.selectedNode)
@@ -300,4 +331,5 @@ WebInspector.CookieItemsView.prototype = {
}
}

WebInspector.CookieItemsView.prototype.__proto__ = WebInspector.View.prototype;
WebInspector.CookieItemsView.prototype.__proto__ = WebInspector.CookiesTable.prototype;

@@ -54,7 +54,7 @@ WebInspector.CookieParser.prototype = {
if (kv.key.charAt(0) === "$" && this._lastCookie)
this._lastCookie.addAttribute(kv.key.slice(1), kv.value);
else if (kv.key.toLowerCase() !== "$version" && typeof kv.value === "string")
this._addCookie(kv);
this._addCookie(kv, WebInspector.Cookie.Type.Request);
this._advanceAndCheckCookieDelimiter();
}
this._flushCookie();
@@ -69,7 +69,7 @@ WebInspector.CookieParser.prototype = {
if (this._lastCookie)
this._lastCookie.addAttribute(kv.key, kv.value);
else
this._addCookie(kv);
this._addCookie(kv, WebInspector.Cookie.Type.Response);
if (this._advanceAndCheckCookieDelimiter())
this._flushCookie();
}
@@ -128,14 +128,14 @@ WebInspector.CookieParser.prototype = {
return match[0].match("\n") !== null;
},

_addCookie: function(keyValue)
_addCookie: function(keyValue, type)
{
if (this._lastCookie)
this._lastCookie.size = keyValue.position - this._lastCookiePosition;
// Mozilla bug 169091: Mozilla, IE and Chrome treat signle token (w/o "=") as
// Mozilla bug 169091: Mozilla, IE and Chrome treat single token (w/o "=") as
// specifying a value for a cookie with empty name.
this._lastCookie = keyValue.value ? new WebInspector.Cookie(keyValue.key, keyValue.value) :
new WebInspector.Cookie("", keyValue.key);
this._lastCookie = keyValue.value ? new WebInspector.Cookie(keyValue.key, keyValue.value, type) :
new WebInspector.Cookie("", keyValue.key, type);
this._lastCookiePosition = keyValue.position;
this._cookies.push(this._lastCookie);
}
@@ -151,10 +151,11 @@ WebInspector.CookieParser.parseSetCookie = function(header)
return (new WebInspector.CookieParser()).parseSetCookie(header);
}

WebInspector.Cookie = function(name, value)
WebInspector.Cookie = function(name, value, type)
{
this.name = name;
this.value = value;
this.type = type;
this._attributes = {};
}

@@ -202,3 +203,8 @@ WebInspector.Cookie.prototype = {
this._attributes[key.toLowerCase()] = value;
}
}

WebInspector.Cookie.Type = {
Request: 0,
Response: 1
};

0 comments on commit 3e6a46e

Please sign in to comment.