Changeset 54435 in webkit


Ignore:
Timestamp:
Feb 5, 2010 11:22:43 AM (14 years ago)
Author:
pfeldman@chromium.org
Message:

2010-02-04 Pavel Feldman <pfeldman@chromium.org>

Reviewed by Timothy Hatcher.

Web Inspector: group cookies by frame, show total
cookies size, allow sorting cookie table.

https://bugs.webkit.org/show_bug.cgi?id=34617

  • English.lproj/localizedStrings.js:
  • inspector/InspectorController.cpp: (WebCore::InspectorController::deleteCookie):
  • inspector/front-end/CookieItemsView.js: (WebInspector.CookieItemsView): (WebInspector.CookieItemsView.prototype.update): (WebInspector.CookieItemsView.prototype._updateWithCookies): (WebInspector.CookieItemsView.prototype._cookiesForDomain): (WebInspector.CookieItemsView.prototype.dataGridForCookies): (WebInspector.CookieItemsView.prototype._createNodes): (WebInspector.CookieItemsView.prototype._sortData.localeCompare): (WebInspector.CookieItemsView.prototype._sortData.numberCompare): (WebInspector.CookieItemsView.prototype._sortData.expiresCompare): (WebInspector.CookieItemsView.prototype._sortData):
  • inspector/front-end/StoragePanel.js: (WebInspector.StoragePanel.prototype.showCookies): (WebInspector.CookieSidebarTreeElement): (WebInspector.CookieSidebarTreeElement.prototype.onselect): (WebInspector.CookieSidebarTreeElement.prototype.get subtitle): (WebInspector.CookieSidebarTreeElement.prototype.set subtitle):
  • inspector/front-end/inspector.js: (WebInspector.updateResource):
Location:
trunk/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r54434 r54435  
     12010-02-04  Pavel Feldman  <pfeldman@chromium.org>
     2
     3        Reviewed by Timothy Hatcher.
     4
     5        Web Inspector: group cookies by frame, show total
     6        cookies size, allow sorting cookie table.
     7
     8        https://bugs.webkit.org/show_bug.cgi?id=34617
     9
     10        * English.lproj/localizedStrings.js:
     11        * inspector/InspectorController.cpp:
     12        (WebCore::InspectorController::deleteCookie):
     13        * inspector/front-end/CookieItemsView.js:
     14        (WebInspector.CookieItemsView):
     15        (WebInspector.CookieItemsView.prototype.update):
     16        (WebInspector.CookieItemsView.prototype._updateWithCookies):
     17        (WebInspector.CookieItemsView.prototype._cookiesForDomain):
     18        (WebInspector.CookieItemsView.prototype.dataGridForCookies):
     19        (WebInspector.CookieItemsView.prototype._createNodes):
     20        (WebInspector.CookieItemsView.prototype._sortData.localeCompare):
     21        (WebInspector.CookieItemsView.prototype._sortData.numberCompare):
     22        (WebInspector.CookieItemsView.prototype._sortData.expiresCompare):
     23        (WebInspector.CookieItemsView.prototype._sortData):
     24        * inspector/front-end/StoragePanel.js:
     25        (WebInspector.StoragePanel.prototype.showCookies):
     26        (WebInspector.CookieSidebarTreeElement):
     27        (WebInspector.CookieSidebarTreeElement.prototype.onselect):
     28        (WebInspector.CookieSidebarTreeElement.prototype.get subtitle):
     29        (WebInspector.CookieSidebarTreeElement.prototype.set subtitle):
     30        * inspector/front-end/inspector.js:
     31        (WebInspector.updateResource):
     32
    1332010-02-05  Maxime Simone  <simon.maxime@gmail.com>
    234
  • trunk/WebCore/inspector/InspectorController.cpp

    r54421 r54435  
    18031803        Document* document = it->second->frame()->document();
    18041804        if (document->url().host() == domain)
    1805             WebCore::deleteCookie(document, document->cookieURL(), cookieName);
     1805            WebCore::deleteCookie(document, it->second->requestURL(), cookieName);
    18061806    }
    18071807}
  • trunk/WebCore/inspector/front-end/CookieItemsView.js

    r54351 r54435  
    2828 */
    2929
    30 WebInspector.CookieItemsView = function(cookieDomain)
     30WebInspector.CookieItemsView = function(treeElement, cookieDomain)
    3131{
    3232    WebInspector.View.call(this);
     
    4242    this.refreshButton.addEventListener("click", this._refreshButtonClicked.bind(this), false);
    4343   
     44    this._treeElement = treeElement;
    4445    this._cookieDomain = cookieDomain;
    4546}
     
    6667    {
    6768        this.element.removeChildren();
    68 
    69         var self = this;
    70         function callback(allCookies, isAdvanced) {
    71             var cookies = self._cookiesForDomain(allCookies);
    72             var dataGrid = (isAdvanced ? self.dataGridForCookies(cookies) : self.simpleDataGridForCookies(cookies));
    73             if (dataGrid) {
    74                 self._dataGrid = dataGrid;
    75                 self.element.appendChild(dataGrid.element);
    76                 self._dataGrid.updateWidths();
    77                 if (isAdvanced)
    78                     self.deleteButton.visible = true;
    79             } else {
    80                 var emptyMsgElement = document.createElement("div");
    81                 emptyMsgElement.className = "storage-table-empty";
    82                 emptyMsgElement.textContent = WebInspector.UIString("This site has no cookies.");
    83                 self.element.appendChild(emptyMsgElement);
    84                 self._dataGrid = null;
    85                 self.deleteButton.visible = false;
    86             }
    87         }
    88 
    89         WebInspector.Cookies.getCookiesAsync(callback);
    90     },
    91 
    92     _cookiesForDomain: function(allCookies)
     69        WebInspector.Cookies.getCookiesAsync(this._updateWithCookies.bind(this));
     70    },
     71
     72    _updateWithCookies: function(allCookies, isAdvanced)
     73    {
     74        var cookies = this._cookiesForDomain(allCookies, isAdvanced);
     75        var dataGrid = (isAdvanced ? this.dataGridForCookies(cookies) : this.simpleDataGridForCookies(cookies));
     76        if (dataGrid) {
     77            this._dataGrid = dataGrid;
     78            this.element.appendChild(dataGrid.element);
     79            this._dataGrid.updateWidths();
     80            if (isAdvanced)
     81                this.deleteButton.visible = true;
     82        } else {
     83            var emptyMsgElement = document.createElement("div");
     84            emptyMsgElement.className = "storage-table-empty";
     85            emptyMsgElement.textContent = WebInspector.UIString("This site has no cookies.");
     86            this.element.appendChild(emptyMsgElement);
     87            this._dataGrid = null;
     88            this.deleteButton.visible = false;
     89        }
     90    },
     91
     92    _cookiesForDomain: function(allCookies, isAdvanced)
    9393    {
    9494        var cookiesForDomain = [];
    9595        var resourceURLsForDocumentURL = [];
     96        var totalSize = 0;
    9697
    9798        for (var id in WebInspector.resources) {
    9899            var resource = WebInspector.resources[id];
    99             var match = resource.url.match(WebInspector.URLRegExp);
     100            var match = resource.documentURL.match(WebInspector.URLRegExp);
    100101            if (match && match[2] === this._cookieDomain)
    101102                resourceURLsForDocumentURL.push(resource.url);
     
    103104
    104105        for (var i = 0; i < allCookies.length; ++i) {
     106            var pushed = false;
     107            var size = allCookies[i].size;
    105108            for (var j = 0; j < resourceURLsForDocumentURL.length; ++j) {
    106109                var resourceURL = resourceURLsForDocumentURL[j];
    107110                if (WebInspector.Cookies.cookieMatchesResourceURL(allCookies[i], resourceURL)) {
    108                     cookiesForDomain.push(allCookies[i]);
    109                     break;
     111                    totalSize += size;
     112                    if (!pushed) {
     113                        pushed = true;
     114                        cookiesForDomain.push(allCookies[i]);
     115                    }
    110116                }
    111117            }
     118        }
     119
     120        if (isAdvanced) {
     121            this._treeElement.subtitle = String.sprintf(WebInspector.UIString("%d cookies (%s)"), cookiesForDomain.length,
     122                Number.bytesToString(totalSize, WebInspector.UIString));
    112123        }
    113124        return cookiesForDomain;
     
    125136        columns[0].title = WebInspector.UIString("Name");
    126137        columns[0].width = columns[0].title.length;
     138        columns[0].sortable = true;
    127139        columns[1].title = WebInspector.UIString("Value");
    128140        columns[1].width = columns[1].title.length;
     141        columns[1].sortable = true;
    129142        columns[2].title = WebInspector.UIString("Domain");
    130143        columns[2].width = columns[2].title.length;
     144        columns[2].sortable = true;
    131145        columns[3].title = WebInspector.UIString("Path");
    132146        columns[3].width = columns[3].title.length;
     147        columns[3].sortable = true;
    133148        columns[4].title = WebInspector.UIString("Expires");
    134149        columns[4].width = columns[4].title.length;
     150        columns[4].sortable = true;
    135151        columns[5].title = WebInspector.UIString("Size");
    136152        columns[5].width = columns[5].title.length;
    137153        columns[5].aligned = "right";
     154        columns[5].sortable = true;
    138155        columns[6].title = WebInspector.UIString("HTTP");
    139156        columns[6].width = columns[6].title.length;
    140157        columns[6].aligned = "centered";
     158        columns[6].sortable = true;
    141159        columns[7].title = WebInspector.UIString("Secure");
    142160        columns[7].width = columns[7].title.length;
    143161        columns[7].aligned = "centered";
    144 
    145         function updateDataAndColumn(index, value) {
    146             data[index] = value;
    147             if (value.length > columns[index].width)
    148                 columns[index].width = value.length;
    149         }
    150 
    151         var data;
    152         var nodes = [];
    153         for (var i = 0; i < cookies.length; ++i) {
    154             var cookie = cookies[i];
    155             data = {};
    156 
    157             updateDataAndColumn(0, cookie.name);
    158             updateDataAndColumn(1, cookie.value);
    159             updateDataAndColumn(2, cookie.domain);
    160             updateDataAndColumn(3, cookie.path);
    161             updateDataAndColumn(4, (cookie.session ? WebInspector.UIString("Session") : cookie.expires.toGMTString()));
    162             updateDataAndColumn(5, Number.bytesToString(cookie.size, WebInspector.UIString));
    163             updateDataAndColumn(6, (cookie.httpOnly ? "\u2713" : "")); // Checkmark
    164             updateDataAndColumn(7, (cookie.secure ? "\u2713" : "")); // Checkmark
    165 
    166             var node = new WebInspector.DataGridNode(data, false);
    167             node.cookie = cookie;
    168             node.selectable = true;
    169             nodes.push(node);
    170         }
     162        columns[7].sortable = true;
    171163
    172164        var totalColumnWidths = 0;
     
    212204
    213205        var dataGrid = new WebInspector.DataGrid(columns, null, this._deleteCookieCallback.bind(this));
    214         var length = nodes.length;
    215         for (var i = 0; i < length; ++i)
     206        var nodes = this._createNodes(dataGrid, cookies);
     207        for (var i = 0; i < nodes.length; ++i)
    216208            dataGrid.appendChild(nodes[i]);
    217         if (length > 0)
     209        if (nodes.length)
    218210            nodes[0].selected = true;
     211        dataGrid.addEventListener("sorting changed", this._sortData.bind(this, dataGrid, cookies));
    219212
    220213        return dataGrid;
     214    },
     215
     216    _createNodes: function(dataGrid, cookies)
     217    {
     218        function updateDataAndColumn(data, index, value) {
     219            data[index] = value;
     220            if (value.length > dataGrid.columns[index].width)
     221                dataGrid.columns[index].width = value.length;
     222        }
     223
     224        var nodes = [];
     225        for (var i = 0; i < cookies.length; ++i) {
     226            var data = {};
     227            var cookie = cookies[i];
     228
     229            updateDataAndColumn(data, 0, cookie.name);
     230            updateDataAndColumn(data, 1, cookie.value);
     231            updateDataAndColumn(data, 2, cookie.domain);
     232            updateDataAndColumn(data, 3, cookie.path);
     233            updateDataAndColumn(data, 4, (cookie.session ? WebInspector.UIString("Session") : cookie.expires.toGMTString()));
     234            updateDataAndColumn(data, 5, Number.bytesToString(cookie.size, WebInspector.UIString));
     235            updateDataAndColumn(data, 6, (cookie.httpOnly ? "\u2713" : "")); // Checkmark
     236            updateDataAndColumn(data, 7, (cookie.secure ? "\u2713" : "")); // Checkmark
     237
     238            var node = new WebInspector.DataGridNode(data);
     239            node.cookie = cookie;
     240            node.selectable = true;
     241            nodes.push(node);
     242        }
     243        return nodes;
     244    },
     245
     246    _sortData: function(dataGrid, cookies)
     247    {
     248        var sortDirection = dataGrid.sortOrder === "ascending" ? 1 : -1;
     249
     250        function localeCompare(field, cookie1, cookie2)
     251        {
     252            return sortDirection * (cookie1[field] + "").localeCompare(cookie2[field] + "")
     253        }
     254
     255        function numberCompare(field, cookie1, cookie2)
     256        {
     257            return sortDirection * (cookie1[field] - cookie2[field]);
     258        }
     259
     260        function expiresCompare(cookie1, cookie2)
     261        {
     262            if (cookie1.session !== cookie2.session)
     263                return sortDirection * (cookie1.session ? 1 : -1);
     264
     265            if (cookie1.session)
     266                return 0;
     267
     268            return sortDirection * (cookie1.expires.getTime() - cookie2.expires.getTime());
     269        }
     270
     271        var comparator;
     272        switch (parseInt(dataGrid.sortColumnIdentifier)) {
     273            case 0: comparator = localeCompare.bind(this, "name"); break;
     274            case 1: comparator = localeCompare.bind(this, "value"); break;
     275            case 2: comparator = localeCompare.bind(this, "domain"); break;
     276            case 3: comparator = localeCompare.bind(this, "path"); break;
     277            case 4: comparator = expiresCompare; break;
     278            case 5: comparator = numberCompare.bind(this, "size"); break;
     279            case 6: comparator = localeCompare.bind(this, "httpOnly"); break;
     280            case 7: comparator = localeCompare.bind(this, "secure"); break;
     281            default: localeCompare.bind(this, "name");
     282        }
     283
     284        cookies.sort(comparator);
     285        var nodes = this._createNodes(dataGrid, cookies);
     286
     287        dataGrid.removeChildren();
     288        for (var i = 0; i < nodes.length; ++i)
     289            dataGrid.appendChild(nodes[i]);
     290
     291        if (nodes.length)
     292            nodes[0].selected = true;
    221293    },
    222294
  • trunk/WebCore/inspector/front-end/StoragePanel.js

    r53545 r54435  
    221221    },
    222222
    223     showCookies: function(cookieDomain)
     223    showCookies: function(treeElement, cookieDomain)
    224224    {
    225225        if (this.visibleView)
     
    228228        var view = this._cookieViews[cookieDomain];
    229229        if (!view) {
    230             view = new WebInspector.CookieItemsView(cookieDomain);
     230            view = new WebInspector.CookieItemsView(treeElement, cookieDomain);
    231231            this._cookieViews[cookieDomain] = view;
    232232        }
     
    508508    WebInspector.SidebarTreeElement.call(this, "cookie-sidebar-tree-item", cookieDomain, "", null, false);
    509509    this._cookieDomain = cookieDomain;
     510    this._subtitle = "";
    510511
    511512    this.refreshTitles();
     
    515516    onselect: function()
    516517    {
    517         WebInspector.panels.storage.showCookies(this._cookieDomain);
    518     },
    519    
     518        WebInspector.panels.storage.showCookies(this, this._cookieDomain);
     519    },
     520
    520521    get mainTitle()
    521522    {
     
    530531    get subtitle()
    531532    {
    532         return "";
     533        return this._subtitle;
    533534    },
    534535
    535536    set subtitle(x)
    536537    {
    537         // Do nothing.
     538        this._subtitle = x;
     539        this.refreshTitles();
    538540    }
    539541}
  • trunk/WebCore/inspector/front-end/inspector.js

    r54421 r54435  
    10471047            this.mainResource = resource;
    10481048
    1049         this._addCookieDomain(resource.domain);
     1049        var match = payload.documentURL.match(WebInspector.URLRegExp);
     1050        if (match) {
     1051            var protocol = match[1].toLowerCase();
     1052            if (protocol.indexOf("http") === 0 || protocol === "file")
     1053                this._addCookieDomain(protocol === "file" ? "" : match[2]);
     1054        }
    10501055    }
    10511056
Note: See TracChangeset for help on using the changeset viewer.