Changeset 54435 in webkit
- Timestamp:
- Feb 5, 2010 11:22:43 AM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r54434 r54435 1 2010-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 1 33 2010-02-05 Maxime Simone <simon.maxime@gmail.com> 2 34 -
trunk/WebCore/inspector/InspectorController.cpp
r54421 r54435 1803 1803 Document* document = it->second->frame()->document(); 1804 1804 if (document->url().host() == domain) 1805 WebCore::deleteCookie(document, document->cookieURL(), cookieName);1805 WebCore::deleteCookie(document, it->second->requestURL(), cookieName); 1806 1806 } 1807 1807 } -
trunk/WebCore/inspector/front-end/CookieItemsView.js
r54351 r54435 28 28 */ 29 29 30 WebInspector.CookieItemsView = function( cookieDomain)30 WebInspector.CookieItemsView = function(treeElement, cookieDomain) 31 31 { 32 32 WebInspector.View.call(this); … … 42 42 this.refreshButton.addEventListener("click", this._refreshButtonClicked.bind(this), false); 43 43 44 this._treeElement = treeElement; 44 45 this._cookieDomain = cookieDomain; 45 46 } … … 66 67 { 67 68 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) 93 93 { 94 94 var cookiesForDomain = []; 95 95 var resourceURLsForDocumentURL = []; 96 var totalSize = 0; 96 97 97 98 for (var id in WebInspector.resources) { 98 99 var resource = WebInspector.resources[id]; 99 var match = resource. url.match(WebInspector.URLRegExp);100 var match = resource.documentURL.match(WebInspector.URLRegExp); 100 101 if (match && match[2] === this._cookieDomain) 101 102 resourceURLsForDocumentURL.push(resource.url); … … 103 104 104 105 for (var i = 0; i < allCookies.length; ++i) { 106 var pushed = false; 107 var size = allCookies[i].size; 105 108 for (var j = 0; j < resourceURLsForDocumentURL.length; ++j) { 106 109 var resourceURL = resourceURLsForDocumentURL[j]; 107 110 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 } 110 116 } 111 117 } 118 } 119 120 if (isAdvanced) { 121 this._treeElement.subtitle = String.sprintf(WebInspector.UIString("%d cookies (%s)"), cookiesForDomain.length, 122 Number.bytesToString(totalSize, WebInspector.UIString)); 112 123 } 113 124 return cookiesForDomain; … … 125 136 columns[0].title = WebInspector.UIString("Name"); 126 137 columns[0].width = columns[0].title.length; 138 columns[0].sortable = true; 127 139 columns[1].title = WebInspector.UIString("Value"); 128 140 columns[1].width = columns[1].title.length; 141 columns[1].sortable = true; 129 142 columns[2].title = WebInspector.UIString("Domain"); 130 143 columns[2].width = columns[2].title.length; 144 columns[2].sortable = true; 131 145 columns[3].title = WebInspector.UIString("Path"); 132 146 columns[3].width = columns[3].title.length; 147 columns[3].sortable = true; 133 148 columns[4].title = WebInspector.UIString("Expires"); 134 149 columns[4].width = columns[4].title.length; 150 columns[4].sortable = true; 135 151 columns[5].title = WebInspector.UIString("Size"); 136 152 columns[5].width = columns[5].title.length; 137 153 columns[5].aligned = "right"; 154 columns[5].sortable = true; 138 155 columns[6].title = WebInspector.UIString("HTTP"); 139 156 columns[6].width = columns[6].title.length; 140 157 columns[6].aligned = "centered"; 158 columns[6].sortable = true; 141 159 columns[7].title = WebInspector.UIString("Secure"); 142 160 columns[7].width = columns[7].title.length; 143 161 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; 171 163 172 164 var totalColumnWidths = 0; … … 212 204 213 205 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) 216 208 dataGrid.appendChild(nodes[i]); 217 if ( length > 0)209 if (nodes.length) 218 210 nodes[0].selected = true; 211 dataGrid.addEventListener("sorting changed", this._sortData.bind(this, dataGrid, cookies)); 219 212 220 213 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; 221 293 }, 222 294 -
trunk/WebCore/inspector/front-end/StoragePanel.js
r53545 r54435 221 221 }, 222 222 223 showCookies: function( cookieDomain)223 showCookies: function(treeElement, cookieDomain) 224 224 { 225 225 if (this.visibleView) … … 228 228 var view = this._cookieViews[cookieDomain]; 229 229 if (!view) { 230 view = new WebInspector.CookieItemsView( cookieDomain);230 view = new WebInspector.CookieItemsView(treeElement, cookieDomain); 231 231 this._cookieViews[cookieDomain] = view; 232 232 } … … 508 508 WebInspector.SidebarTreeElement.call(this, "cookie-sidebar-tree-item", cookieDomain, "", null, false); 509 509 this._cookieDomain = cookieDomain; 510 this._subtitle = ""; 510 511 511 512 this.refreshTitles(); … … 515 516 onselect: function() 516 517 { 517 WebInspector.panels.storage.showCookies(this ._cookieDomain);518 }, 519 518 WebInspector.panels.storage.showCookies(this, this._cookieDomain); 519 }, 520 520 521 get mainTitle() 521 522 { … … 530 531 get subtitle() 531 532 { 532 return "";533 return this._subtitle; 533 534 }, 534 535 535 536 set subtitle(x) 536 537 { 537 // Do nothing. 538 this._subtitle = x; 539 this.refreshTitles(); 538 540 } 539 541 } -
trunk/WebCore/inspector/front-end/inspector.js
r54421 r54435 1047 1047 this.mainResource = resource; 1048 1048 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 } 1050 1055 } 1051 1056
Note: See TracChangeset
for help on using the changeset viewer.