Title: [137585] trunk
Revision
137585
Author
[email protected]
Date
2012-12-13 05:05:29 -0800 (Thu, 13 Dec 2012)

Log Message

Web Inspector: Network: Sorting cookies by size is broken.
https://bugs.webkit.org/show_bug.cgi?id=104893

Patch by Eugene Klyuchnikov <[email protected]> on 2012-12-13
Reviewed by Alexander Pavlov.

Source/WebCore:

Problem: cookie "size" is not a field now; its value is accessible
through getter method.

Solution: make cookie fields uniformly accessible (add getters for name,
type and value).

* inspector/front-end/CookieItemsView.js: Adopt changes.
* inspector/front-end/CookieParser.js:
(WebInspector.Cookie): Refine JsDoc.
(WebInspector.Cookie.prototype.name): Added getter.
(WebInspector.Cookie.prototype.value): Ditto.
(WebInspector.Cookie.prototype.type): Ditto.
(WebInspector.Cookies.buildCookiesFromString): Adopt changes.
(WebInspector.Cookies.buildCookieProtocolObject): Ditto.
* inspector/front-end/CookiesTable.js:
(WebInspector.CookiesTable): Remove unused parameter.
(WebInspector.CookiesTable.prototype._sortCookies):
Use getters instead of field names.
(WebInspector.CookiesTable.prototype._createGridNode): Adopt changes.
* inspector/front-end/HAREntry.js: Ditto.
* inspector/front-end/RequestCookiesView.js: Ditto.

LayoutTests:

Adopt new cookie field accessors.

* inspector/cookie-parser.html: Adopt new cookie field accessors.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (137584 => 137585)


--- trunk/LayoutTests/ChangeLog	2012-12-13 12:50:04 UTC (rev 137584)
+++ trunk/LayoutTests/ChangeLog	2012-12-13 13:05:29 UTC (rev 137585)
@@ -1,3 +1,14 @@
+2012-12-13  Eugene Klyuchnikov  <[email protected]>
+
+        Web Inspector: Network: Sorting cookies by size is broken.
+        https://bugs.webkit.org/show_bug.cgi?id=104893
+
+        Reviewed by Alexander Pavlov.
+
+        Adopt new cookie field accessors.
+
+        * inspector/cookie-parser.html: Adopt new cookie field accessors.
+
 2012-12-13  Grzegorz Czajkowski  <[email protected]>
 
         [Mac][WK2] Unreviewed, spelling-unified-emulation.html fails after 137571

Modified: trunk/LayoutTests/inspector/cookie-parser.html (137584 => 137585)


--- trunk/LayoutTests/inspector/cookie-parser.html	2012-12-13 12:50:04 UTC (rev 137584)
+++ trunk/LayoutTests/inspector/cookie-parser.html	2012-12-13 13:05:29 UTC (rev 137585)
@@ -11,7 +11,7 @@
     var requestDate = new Date("Mon Oct 18 2010 17:00:00 GMT+0000");
     var expires = cookie.expiresDate(requestDate);
 
-    var output = "name: " + cookie.name + ", value: " + cookie.value + ", httpOnly: " + cookie.httpOnly() +
+    var output = "name: " + cookie.name() + ", value: " + cookie.value() + ", httpOnly: " + cookie.httpOnly() +
         ", secure: " + cookie.secure() + ", session: " + cookie.session() + ", path: " + cookie.path() +
         ", domain: " + cookie.domain() + ", port: " + cookie.port() +
         ", expires: " + (expires ? expires.getTime() : "n/a") +

Modified: trunk/Source/WebCore/ChangeLog (137584 => 137585)


--- trunk/Source/WebCore/ChangeLog	2012-12-13 12:50:04 UTC (rev 137584)
+++ trunk/Source/WebCore/ChangeLog	2012-12-13 13:05:29 UTC (rev 137585)
@@ -1,3 +1,32 @@
+2012-12-13  Eugene Klyuchnikov  <[email protected]>
+
+        Web Inspector: Network: Sorting cookies by size is broken.
+        https://bugs.webkit.org/show_bug.cgi?id=104893
+
+        Reviewed by Alexander Pavlov.
+
+        Problem: cookie "size" is not a field now; its value is accessible
+        through getter method.
+
+        Solution: make cookie fields uniformly accessible (add getters for name,
+        type and value).
+
+        * inspector/front-end/CookieItemsView.js: Adopt changes.
+        * inspector/front-end/CookieParser.js:
+        (WebInspector.Cookie): Refine JsDoc.
+        (WebInspector.Cookie.prototype.name): Added getter.
+        (WebInspector.Cookie.prototype.value): Ditto.
+        (WebInspector.Cookie.prototype.type): Ditto.
+        (WebInspector.Cookies.buildCookiesFromString): Adopt changes.
+        (WebInspector.Cookies.buildCookieProtocolObject): Ditto.
+        * inspector/front-end/CookiesTable.js:
+        (WebInspector.CookiesTable): Remove unused parameter.
+        (WebInspector.CookiesTable.prototype._sortCookies):
+        Use getters instead of field names.
+        (WebInspector.CookiesTable.prototype._createGridNode): Adopt changes.
+        * inspector/front-end/HAREntry.js: Ditto.
+        * inspector/front-end/RequestCookiesView.js: Ditto.
+
 2012-12-13  Kentaro Hara  <[email protected]>
 
         Unreviewed, rolling out r137569.

Modified: trunk/Source/WebCore/inspector/front-end/CookieItemsView.js (137584 => 137585)


--- trunk/Source/WebCore/inspector/front-end/CookieItemsView.js	2012-12-13 12:50:04 UTC (rev 137584)
+++ trunk/Source/WebCore/inspector/front-end/CookieItemsView.js	2012-12-13 13:05:29 UTC (rev 137585)
@@ -92,7 +92,7 @@
         }
 
         if (!this._cookiesTable)
-            this._cookiesTable = isAdvanced ? new WebInspector.CookiesTable(this._cookieDomain, false, this._deleteCookie.bind(this), this._update.bind(this)) : new WebInspector.SimpleCookiesTable();
+            this._cookiesTable = isAdvanced ? new WebInspector.CookiesTable(false, this._deleteCookie.bind(this), this._update.bind(this)) : new WebInspector.SimpleCookiesTable();
 
         this._cookiesTable.setCookies(this._cookies);
         this._emptyView.detach();
@@ -139,11 +139,11 @@
     },
 
     /**
-     * @param {WebInspector.Cookie} cookie
+     * @param {!WebInspector.Cookie} cookie
      */
     _deleteCookie: function(cookie)
     {
-        PageAgent.deleteCookie(cookie.name, this._cookieDomain);
+        PageAgent.deleteCookie(cookie.name(), this._cookieDomain);
         this._update();
     },
 
@@ -198,12 +198,12 @@
         this._dataGrid.rootNode().removeChildren();
         var addedCookies = {};
         for (var i = 0; i < cookies.length; ++i) {
-            if (addedCookies[cookies[i].name])
+            if (addedCookies[cookies[i].name()])
                 continue;
-            addedCookies[cookies[i].name] = true;
+            addedCookies[cookies[i].name()] = true;
             var data = ""
-            data[0] = cookies[i].name;
-            data[1] = cookies[i].value;
+            data[0] = cookies[i].name();
+            data[1] = cookies[i].value();
 
             var node = new WebInspector.DataGridNode(data, false);
             node.selectable = true;

Modified: trunk/Source/WebCore/inspector/front-end/CookieParser.js (137584 => 137585)


--- trunk/Source/WebCore/inspector/front-end/CookieParser.js	2012-12-13 12:50:04 UTC (rev 137584)
+++ trunk/Source/WebCore/inspector/front-end/CookieParser.js	2012-12-13 13:05:29 UTC (rev 137585)
@@ -162,8 +162,8 @@
     },
 
     /**
-     * @param {WebInspector.CookieParser.KeyValue} keyValue
-     * @param {number} type
+     * @param {!WebInspector.CookieParser.KeyValue} keyValue
+     * @param {!WebInspector.Cookie.Type} type
      */
     _addCookie: function(keyValue, type)
     {
@@ -200,20 +200,44 @@
  * @constructor
  * @param {string} name
  * @param {string} value
- * @param {number=} type
+ * @param {?WebInspector.Cookie.Type} type
  */
 WebInspector.Cookie = function(name, value, type)
 {
-    this.name = name;
-    this.value = value;
-    this.type = type;
+    this._name = name;
+    this._value = value;
+    this._type = type;
     this._attributes = {};
 }
 
 WebInspector.Cookie.prototype = {
     /**
+     * @return {string}
+     */
+    name: function()
+    {
+        return this._name;
+    },
+
+    /**
+     * @return {string}
+     */
+    value: function()
+    {
+        return this._value;
+    },
+
+    /**
+     * @return {?WebInspector.Cookie.Type}
+     */
+    type: function()
+    {
+        return this._type;
+    },
+
+    /**
      * @return {boolean}
-     */ 
+     */
     httpOnly: function()
     {
         return "httponly" in this._attributes;
@@ -221,7 +245,7 @@
 
     /**
      * @return {boolean}
-     */ 
+     */
     secure: function()
     {
         return "secure" in this._attributes;
@@ -229,7 +253,7 @@
 
     /**
      * @return {boolean}
-     */ 
+     */
     session: function()
     {
         // RFC 2965 suggests using Discard attribute to mark session cookies, but this does not seem to be widely used.
@@ -239,7 +263,7 @@
 
     /**
      * @return {string}
-     */ 
+     */
     path: function()
     {
         return this._attributes["path"];
@@ -247,7 +271,7 @@
 
     /**
      * @return {string}
-     */ 
+     */
     port: function()
     {
         return this._attributes["port"];
@@ -255,7 +279,7 @@
 
     /**
      * @return {string}
-     */ 
+     */
     domain: function()
     {
         return this._attributes["domain"];
@@ -263,7 +287,7 @@
 
     /**
      * @return {string}
-     */ 
+     */
     expires: function()
     {
         return this._attributes["expires"];
@@ -271,7 +295,7 @@
 
     /**
      * @return {string}
-     */ 
+     */
     maxAge: function()
     {
         return this._attributes["max-age"];
@@ -279,7 +303,7 @@
 
     /**
      * @return {number}
-     */ 
+     */
     size: function()
     {
         return this._size;
@@ -287,7 +311,7 @@
 
     /**
      * @param {number} size
-     */ 
+     */
     setSize: function(size)
     {
         this._size = size;
@@ -295,7 +319,7 @@
 
     /**
      * @return {Date}
-     */ 
+     */
     expiresDate: function(requestDate)
     {
         // RFC 6265 indicates that the max-age attribute takes precedence over the expires attribute
@@ -312,7 +336,7 @@
 
     /**
      * @return {Object}
-     */ 
+     */
     attributes: function()
     {
         return this._attributes;
@@ -321,13 +345,16 @@
     /**
      * @param {string} key 
      * @param {string=} value 
-     */ 
+     */
     addAttribute: function(key, value)
     {
         this._attributes[key.toLowerCase()] = value;
     }
 }
 
+/**
+ * @enum {number}
+ */
 WebInspector.Cookie.Type = {
     Request: 0,
     Response: 1
@@ -357,8 +384,8 @@
 
 /**
  * @param {string} rawCookieString 
- * @return {Array.<WebInspector.Cookie>} 
- */ 
+ * @return {Array.<WebInspector.Cookie>}
+ */
 WebInspector.Cookies.buildCookiesFromString = function(rawCookieString)
 {
     var rawCookies = rawCookieString.split(/;\s*/);
@@ -371,7 +398,7 @@
             var name = rawCookie.substring(0, delimIndex);
             var value = rawCookie.substring(delimIndex + 1);
             var size = name.length + value.length;
-            var cookie = new WebInspector.Cookie(name, value);
+            var cookie = new WebInspector.Cookie(name, value, null);
             cookie.setSize(size);
             cookies.push(cookie);
         }
@@ -381,12 +408,12 @@
 }
 
 /**
- * @param {Object} protocolCookie 
- * @return {WebInspector.Cookie} 
- */ 
+ * @param {Object} protocolCookie
+ * @return {!WebInspector.Cookie}
+ */
 WebInspector.Cookies.buildCookieProtocolObject = function(protocolCookie)
 {
-    var cookie = new WebInspector.Cookie(protocolCookie.name, protocolCookie.value);
+    var cookie = new WebInspector.Cookie(protocolCookie.name, protocolCookie.value, null);
     cookie.addAttribute("domain", protocolCookie["domain"]);
     cookie.addAttribute("path", protocolCookie["path"]);
     cookie.addAttribute("port", protocolCookie["port"]);
@@ -403,7 +430,7 @@
 /**
  * @param {WebInspector.Cookie} cookie 
  * @param {string} resourceURL
- */ 
+ */
 WebInspector.Cookies.cookieMatchesResourceURL = function(cookie, resourceURL)
 {
     var url = ""
@@ -417,7 +444,7 @@
 /**
  * @param {string} cookieDomain 
  * @param {string} resourceDomain
- */ 
+ */
 WebInspector.Cookies.cookieDomainMatchesResourceDomain = function(cookieDomain, resourceDomain)
 {
     if (cookieDomain.charAt(0) !== '.')

Modified: trunk/Source/WebCore/inspector/front-end/CookiesTable.js (137584 => 137585)


--- trunk/Source/WebCore/inspector/front-end/CookiesTable.js	2012-12-13 12:50:04 UTC (rev 137584)
+++ trunk/Source/WebCore/inspector/front-end/CookiesTable.js	2012-12-13 13:05:29 UTC (rev 137585)
@@ -31,16 +31,15 @@
 /**
  * @constructor
  * @extends {WebInspector.View}
- * @param {function(WebInspector.Cookie)=} deleteCallback
+ * @param {boolean} expandable
+ * @param {function(!WebInspector.Cookie)=} deleteCallback
  * @param {function()=} refreshCallback
  */
-WebInspector.CookiesTable = function(cookieDomain, expandable, deleteCallback, refreshCallback)
+WebInspector.CookiesTable = function(expandable, deleteCallback, refreshCallback)
 {
     WebInspector.View.call(this);
     this.element.className = "fill";
 
-    this._cookieDomain = cookieDomain;
-
     var columns = { 0: {}, 1: {}, 2: {}, 3: {}, 4: {}, 5: {}, 6: {}, 7: {} };
     columns[0].title = WebInspector.UIString("Name");
     columns[0].sortable = true;
@@ -127,8 +126,8 @@
     },
 
     /**
-     * @param {WebInspector.DataGridNode} parentNode
-     * @param {Array.<WebInspector.Cookie>} cookies
+     * @param {!WebInspector.DataGridNode} parentNode
+     * @param {?Array.<!WebInspector.Cookie>} cookies
      */
     _populateNode: function(parentNode, cookies)
     {
@@ -154,18 +153,21 @@
         return totalSize;
     },
 
+    /**
+     * @param {!Array.<!WebInspector.Cookie>} cookies
+     */
     _sortCookies: function(cookies)
     {
         var sortDirection = this._dataGrid.sortOrder === "ascending" ? 1 : -1;
 
-        function localeCompare(field, cookie1, cookie2)
+        function localeCompare(getter, cookie1, cookie2)
         {
-            return sortDirection * (cookie1[field] + "").localeCompare(cookie2[field] + "")
+            return sortDirection * (getter.apply(cookie1) + "").localeCompare(getter.apply(cookie2) + "")
         }
 
-        function numberCompare(field, cookie1, cookie2)
+        function numberCompare(getter, cookie1, cookie2)
         {
-            return sortDirection * (cookie1[field] - cookie2[field]);
+            return sortDirection * (getter.apply(cookie1) - getter.apply(cookie2));
         }
 
         function expiresCompare(cookie1, cookie2)
@@ -185,31 +187,32 @@
 
         var comparator;
         switch (parseInt(this._dataGrid.sortColumnIdentifier, 10)) {
-            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 0: comparator = localeCompare.bind(null, WebInspector.Cookie.prototype.name); break;
+            case 1: comparator = localeCompare.bind(null, WebInspector.Cookie.prototype.value); break;
+            case 2: comparator = localeCompare.bind(null, WebInspector.Cookie.prototype.domain); break;
+            case 3: comparator = localeCompare.bind(null, WebInspector.Cookie.prototype.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");
+            case 5: comparator = numberCompare.bind(null, WebInspector.Cookie.prototype.size); break;
+            case 6: comparator = localeCompare.bind(null, WebInspector.Cookie.prototype.httpOnly); break;
+            case 7: comparator = localeCompare.bind(null, WebInspector.Cookie.prototype.secure); break;
+            default: localeCompare.bind(null, WebInspector.Cookie.prototype.name);
         }
 
         cookies.sort(comparator);
     },
 
     /**
-     * @param {WebInspector.Cookie} cookie
+     * @param {!WebInspector.Cookie} cookie
+     * @return {!WebInspector.DataGridNode}
      */
     _createGridNode: function(cookie)
     {
         var data = ""
-        data[0] = cookie.name;
-        data[1] = cookie.value;
+        data[0] = cookie.name();
+        data[1] = cookie.value();
         data[2] = cookie.domain() || "";
         data[3] = cookie.path() || "";
-        if (cookie.type === WebInspector.Cookie.Type.Request)
+        if (cookie.type() === WebInspector.Cookie.Type.Request)
             data[4] = "";
         else if (cookie.maxAge())
             data[4] = Number.secondsToString(parseInt(cookie.maxAge(), 10));

Modified: trunk/Source/WebCore/inspector/front-end/HAREntry.js (137584 => 137585)


--- trunk/Source/WebCore/inspector/front-end/HAREntry.js	2012-12-13 12:50:04 UTC (rev 137584)
+++ trunk/Source/WebCore/inspector/front-end/HAREntry.js	2012-12-13 13:05:29 UTC (rev 137585)
@@ -202,8 +202,8 @@
     _buildCookie: function(cookie)
     {
         return {
-            name: cookie.name,
-            value: cookie.value,
+            name: cookie.name(),
+            value: cookie.value(),
             path: cookie.path(),
             domain: cookie.domain(),
             expires: cookie.expiresDate(new Date(this._request.startTime * 1000)),

Modified: trunk/Source/WebCore/inspector/front-end/RequestCookiesView.js (137584 => 137585)


--- trunk/Source/WebCore/inspector/front-end/RequestCookiesView.js	2012-12-13 12:50:04 UTC (rev 137584)
+++ trunk/Source/WebCore/inspector/front-end/RequestCookiesView.js	2012-12-13 13:05:29 UTC (rev 137585)
@@ -68,7 +68,7 @@
     {
         this.detachChildViews();
 
-        this._cookiesTable = new WebInspector.CookiesTable(null, true);
+        this._cookiesTable = new WebInspector.CookiesTable(true);
         this._cookiesTable.addCookiesFolder(WebInspector.UIString("Request Cookies"), this._request.requestCookies);
         this._cookiesTable.addCookiesFolder(WebInspector.UIString("Response Cookies"), this._request.responseCookies);
         this._cookiesTable.show(this.element);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to