| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Joseph Pecoraro | 3 * Copyright (C) 2009 Joseph Pecoraro |
| 4 * Copyright (C) 2010 Google Inc. All rights reserved. | 4 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * | 9 * |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| 11 * notice, this list of conditions and the following disclaimer. | 11 * notice, this list of conditions and the following disclaimer. |
| 12 * 2. Redistributions in binary form must reproduce the above copyright | 12 * 2. Redistributions in binary form must reproduce the above copyright |
| 13 * notice, this list of conditions and the following disclaimer in the | 13 * notice, this list of conditions and the following disclaimer in the |
| 14 * documentation and/or other materials provided with the distribution. | 14 * documentation and/or other materials provided with the distribution. |
| 15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of | 15 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of |
| 16 * its contributors may be used to endorse or promote products derived | 16 * its contributors may be used to endorse or promote products derived |
| 17 * from this software without specific prior written permission. | 17 * from this software without specific prior written permission. |
| 18 * | 18 * |
| 19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 19 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 20 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 22 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | |
| 31 /** | 30 /** |
| 32 * @constructor | 31 * @unrestricted |
| 33 * @extends {WebInspector.VBox} | |
| 34 * @param {boolean} expandable | |
| 35 * @param {function()=} refreshCallback | |
| 36 * @param {function()=} selectedCallback | |
| 37 */ | 32 */ |
| 38 WebInspector.CookiesTable = function(expandable, refreshCallback, selectedCallba
ck) | 33 WebInspector.CookiesTable = class extends WebInspector.VBox { |
| 39 { | 34 /** |
| 40 WebInspector.VBox.call(this); | 35 * @param {boolean} expandable |
| 36 * @param {function()=} refreshCallback |
| 37 * @param {function()=} selectedCallback |
| 38 */ |
| 39 constructor(expandable, refreshCallback, selectedCallback) { |
| 40 super(); |
| 41 | 41 |
| 42 var readOnly = expandable; | 42 var readOnly = expandable; |
| 43 this._refreshCallback = refreshCallback; | 43 this._refreshCallback = refreshCallback; |
| 44 | 44 |
| 45 var columns = /** @type {!Array<!WebInspector.DataGrid.ColumnDescriptor>} */
([ | 45 var columns = /** @type {!Array<!WebInspector.DataGrid.ColumnDescriptor>} */
([ |
| 46 {id: "name", title: WebInspector.UIString("Name"), sortable: true, discl
osure: expandable, sort: WebInspector.DataGrid.Order.Ascending, longText: true,
weight: 24}, | 46 { |
| 47 {id: "value", title: WebInspector.UIString("Value"), sortable: true, lon
gText: true, weight: 34}, | 47 id: 'name', |
| 48 {id: "domain", title: WebInspector.UIString("Domain"), sortable: true, w
eight: 7}, | 48 title: WebInspector.UIString('Name'), |
| 49 {id: "path", title: WebInspector.UIString("Path"), sortable: true, weigh
t: 7}, | 49 sortable: true, |
| 50 {id: "expires", title: WebInspector.UIString("Expires / Max-Age"), sorta
ble: true, weight: 7}, | 50 disclosure: expandable, |
| 51 {id: "size", title: WebInspector.UIString("Size"), sortable: true, align
: WebInspector.DataGrid.Align.Right, weight: 7}, | 51 sort: WebInspector.DataGrid.Order.Ascending, |
| 52 {id: "httpOnly", title: WebInspector.UIString("HTTP"), sortable: true, a
lign: WebInspector.DataGrid.Align.Center, weight: 7}, | 52 longText: true, |
| 53 {id: "secure", title: WebInspector.UIString("Secure"), sortable: true, a
lign: WebInspector.DataGrid.Align.Center, weight: 7}, | 53 weight: 24 |
| 54 {id: "sameSite", title: WebInspector.UIString("SameSite"), sortable: tru
e, align: WebInspector.DataGrid.Align.Center, weight: 7} | 54 }, |
| 55 {id: 'value', title: WebInspector.UIString('Value'), sortable: true, longT
ext: true, weight: 34}, |
| 56 {id: 'domain', title: WebInspector.UIString('Domain'), sortable: true, wei
ght: 7}, |
| 57 {id: 'path', title: WebInspector.UIString('Path'), sortable: true, weight:
7}, |
| 58 {id: 'expires', title: WebInspector.UIString('Expires / Max-Age'), sortabl
e: true, weight: 7}, { |
| 59 id: 'size', |
| 60 title: WebInspector.UIString('Size'), |
| 61 sortable: true, |
| 62 align: WebInspector.DataGrid.Align.Right, |
| 63 weight: 7 |
| 64 }, |
| 65 { |
| 66 id: 'httpOnly', |
| 67 title: WebInspector.UIString('HTTP'), |
| 68 sortable: true, |
| 69 align: WebInspector.DataGrid.Align.Center, |
| 70 weight: 7 |
| 71 }, |
| 72 { |
| 73 id: 'secure', |
| 74 title: WebInspector.UIString('Secure'), |
| 75 sortable: true, |
| 76 align: WebInspector.DataGrid.Align.Center, |
| 77 weight: 7 |
| 78 }, |
| 79 { |
| 80 id: 'sameSite', |
| 81 title: WebInspector.UIString('SameSite'), |
| 82 sortable: true, |
| 83 align: WebInspector.DataGrid.Align.Center, |
| 84 weight: 7 |
| 85 } |
| 55 ]); | 86 ]); |
| 56 | 87 |
| 57 if (readOnly) { | 88 if (readOnly) { |
| 58 this._dataGrid = new WebInspector.DataGrid(columns); | 89 this._dataGrid = new WebInspector.DataGrid(columns); |
| 59 } else { | 90 } else { |
| 60 this._dataGrid = new WebInspector.DataGrid(columns, undefined, this._onD
eleteCookie.bind(this), refreshCallback); | 91 this._dataGrid = new WebInspector.DataGrid(columns, undefined, this._onDel
eteCookie.bind(this), refreshCallback); |
| 61 this._dataGrid.setRowContextMenuCallback(this._onRowContextMenu.bind(thi
s)); | 92 this._dataGrid.setRowContextMenuCallback(this._onRowContextMenu.bind(this)
); |
| 62 } | 93 } |
| 63 | 94 |
| 64 this._dataGrid.setName("cookiesTable"); | 95 this._dataGrid.setName('cookiesTable'); |
| 65 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SortingChanged,
this._rebuildTable, this); | 96 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SortingChanged,
this._rebuildTable, this); |
| 66 | 97 |
| 67 if (selectedCallback) | 98 if (selectedCallback) |
| 68 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SelectedNod
e, selectedCallback, this); | 99 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SelectedNode,
selectedCallback, this); |
| 69 | 100 |
| 70 this._nextSelectedCookie = /** @type {?WebInspector.Cookie} */ (null); | 101 this._nextSelectedCookie = /** @type {?WebInspector.Cookie} */ (null); |
| 71 | 102 |
| 72 this._dataGrid.asWidget().show(this.element); | 103 this._dataGrid.asWidget().show(this.element); |
| 73 this._data = []; | 104 this._data = []; |
| 105 } |
| 106 |
| 107 /** |
| 108 * @param {?string} domain |
| 109 */ |
| 110 _clearAndRefresh(domain) { |
| 111 this.clear(domain); |
| 112 this._refresh(); |
| 113 } |
| 114 |
| 115 /** |
| 116 * @param {!WebInspector.ContextMenu} contextMenu |
| 117 * @param {!WebInspector.DataGridNode} node |
| 118 */ |
| 119 _onRowContextMenu(contextMenu, node) { |
| 120 if (node === this._dataGrid.creationNode) |
| 121 return; |
| 122 var domain = node.cookie.domain(); |
| 123 if (domain) |
| 124 contextMenu.appendItem( |
| 125 WebInspector.UIString.capitalize('Clear ^all from "%s"', domain), this
._clearAndRefresh.bind(this, domain)); |
| 126 contextMenu.appendItem(WebInspector.UIString.capitalize('Clear ^all'), this.
_clearAndRefresh.bind(this, null)); |
| 127 } |
| 128 |
| 129 /** |
| 130 * @param {!Array.<!WebInspector.Cookie>} cookies |
| 131 */ |
| 132 setCookies(cookies) { |
| 133 this.setCookieFolders([{cookies: cookies}]); |
| 134 } |
| 135 |
| 136 /** |
| 137 * @param {!Array.<!{folderName: ?string, cookies: !Array.<!WebInspector.Cooki
e>}>} cookieFolders |
| 138 */ |
| 139 setCookieFolders(cookieFolders) { |
| 140 this._data = cookieFolders; |
| 141 this._rebuildTable(); |
| 142 } |
| 143 |
| 144 /** |
| 145 * @return {?WebInspector.Cookie} |
| 146 */ |
| 147 selectedCookie() { |
| 148 var node = this._dataGrid.selectedNode; |
| 149 return node ? node.cookie : null; |
| 150 } |
| 151 |
| 152 /** |
| 153 * @param {?string=} domain |
| 154 */ |
| 155 clear(domain) { |
| 156 for (var i = 0, length = this._data.length; i < length; ++i) { |
| 157 var cookies = this._data[i].cookies; |
| 158 for (var j = 0, cookieCount = cookies.length; j < cookieCount; ++j) { |
| 159 if (!domain || cookies[j].domain() === domain) |
| 160 cookies[j].remove(); |
| 161 } |
| 162 } |
| 163 } |
| 164 |
| 165 _rebuildTable() { |
| 166 var selectedCookie = this._nextSelectedCookie || this.selectedCookie(); |
| 167 this._nextSelectedCookie = null; |
| 168 this._dataGrid.rootNode().removeChildren(); |
| 169 for (var i = 0; i < this._data.length; ++i) { |
| 170 var item = this._data[i]; |
| 171 if (item.folderName) { |
| 172 var groupData = { |
| 173 name: item.folderName, |
| 174 value: '', |
| 175 domain: '', |
| 176 path: '', |
| 177 expires: '', |
| 178 size: this._totalSize(item.cookies), |
| 179 httpOnly: '', |
| 180 secure: '', |
| 181 sameSite: '' |
| 182 }; |
| 183 var groupNode = new WebInspector.DataGridNode(groupData); |
| 184 groupNode.selectable = true; |
| 185 this._dataGrid.rootNode().appendChild(groupNode); |
| 186 groupNode.element().classList.add('row-group'); |
| 187 this._populateNode(groupNode, item.cookies, selectedCookie); |
| 188 groupNode.expand(); |
| 189 } else |
| 190 this._populateNode(this._dataGrid.rootNode(), item.cookies, selectedCook
ie); |
| 191 } |
| 192 } |
| 193 |
| 194 /** |
| 195 * @param {!WebInspector.DataGridNode} parentNode |
| 196 * @param {?Array.<!WebInspector.Cookie>} cookies |
| 197 * @param {?WebInspector.Cookie} selectedCookie |
| 198 */ |
| 199 _populateNode(parentNode, cookies, selectedCookie) { |
| 200 parentNode.removeChildren(); |
| 201 if (!cookies) |
| 202 return; |
| 203 |
| 204 this._sortCookies(cookies); |
| 205 for (var i = 0; i < cookies.length; ++i) { |
| 206 var cookie = cookies[i]; |
| 207 var cookieNode = this._createGridNode(cookie); |
| 208 parentNode.appendChild(cookieNode); |
| 209 if (selectedCookie && selectedCookie.name() === cookie.name() && selectedC
ookie.domain() === cookie.domain() && |
| 210 selectedCookie.path() === cookie.path()) |
| 211 cookieNode.select(); |
| 212 } |
| 213 } |
| 214 |
| 215 _totalSize(cookies) { |
| 216 var totalSize = 0; |
| 217 for (var i = 0; cookies && i < cookies.length; ++i) |
| 218 totalSize += cookies[i].size(); |
| 219 return totalSize; |
| 220 } |
| 221 |
| 222 /** |
| 223 * @param {!Array.<!WebInspector.Cookie>} cookies |
| 224 */ |
| 225 _sortCookies(cookies) { |
| 226 var sortDirection = this._dataGrid.isSortOrderAscending() ? 1 : -1; |
| 227 |
| 228 /** |
| 229 * @param {string} property |
| 230 * @param {!WebInspector.Cookie} cookie1 |
| 231 * @param {!WebInspector.Cookie} cookie2 |
| 232 */ |
| 233 function compareTo(property, cookie1, cookie2) { |
| 234 return sortDirection * |
| 235 (String(cookie1[property] || cookie1['name'])).compareTo(String(cookie
2[property] || cookie2['name'])); |
| 236 } |
| 237 |
| 238 /** |
| 239 * @param {!WebInspector.Cookie} cookie1 |
| 240 * @param {!WebInspector.Cookie} cookie2 |
| 241 */ |
| 242 function numberCompare(cookie1, cookie2) { |
| 243 return sortDirection * (cookie1.size() - cookie2.size()); |
| 244 } |
| 245 |
| 246 /** |
| 247 * @param {!WebInspector.Cookie} cookie1 |
| 248 * @param {!WebInspector.Cookie} cookie2 |
| 249 */ |
| 250 function expiresCompare(cookie1, cookie2) { |
| 251 if (cookie1.session() !== cookie2.session()) |
| 252 return sortDirection * (cookie1.session() ? 1 : -1); |
| 253 |
| 254 if (cookie1.session()) |
| 255 return 0; |
| 256 |
| 257 if (cookie1.maxAge() && cookie2.maxAge()) |
| 258 return sortDirection * (cookie1.maxAge() - cookie2.maxAge()); |
| 259 if (cookie1.expires() && cookie2.expires()) |
| 260 return sortDirection * (cookie1.expires() - cookie2.expires()); |
| 261 return sortDirection * (cookie1.expires() ? 1 : -1); |
| 262 } |
| 263 |
| 264 var comparator; |
| 265 var columnId = this._dataGrid.sortColumnId() || 'name'; |
| 266 if (columnId === 'expires') |
| 267 comparator = expiresCompare; |
| 268 else if (columnId === 'size') |
| 269 comparator = numberCompare; |
| 270 else |
| 271 comparator = compareTo.bind(null, columnId); |
| 272 cookies.sort(comparator); |
| 273 } |
| 274 |
| 275 /** |
| 276 * @param {!WebInspector.Cookie} cookie |
| 277 * @return {!WebInspector.DataGridNode} |
| 278 */ |
| 279 _createGridNode(cookie) { |
| 280 var data = {}; |
| 281 data.name = cookie.name(); |
| 282 data.value = cookie.value(); |
| 283 if (cookie.type() === WebInspector.Cookie.Type.Request) { |
| 284 data.domain = WebInspector.UIString('N/A'); |
| 285 data.path = WebInspector.UIString('N/A'); |
| 286 data.expires = WebInspector.UIString('N/A'); |
| 287 } else { |
| 288 data.domain = cookie.domain() || ''; |
| 289 data.path = cookie.path() || ''; |
| 290 if (cookie.maxAge()) |
| 291 data.expires = Number.secondsToString(parseInt(cookie.maxAge(), 10)); |
| 292 else if (cookie.expires()) |
| 293 data.expires = new Date(cookie.expires()).toISOString(); |
| 294 else |
| 295 data.expires = WebInspector.UIString('Session'); |
| 296 } |
| 297 data.size = cookie.size(); |
| 298 const checkmark = '\u2713'; |
| 299 data.httpOnly = (cookie.httpOnly() ? checkmark : ''); |
| 300 data.secure = (cookie.secure() ? checkmark : ''); |
| 301 data.sameSite = cookie.sameSite() || ''; |
| 302 |
| 303 var node = new WebInspector.DataGridNode(data); |
| 304 node.cookie = cookie; |
| 305 node.selectable = true; |
| 306 return node; |
| 307 } |
| 308 |
| 309 _onDeleteCookie(node) { |
| 310 var cookie = node.cookie; |
| 311 var neighbour = node.traverseNextNode() || node.traversePreviousNode(); |
| 312 if (neighbour) |
| 313 this._nextSelectedCookie = neighbour.cookie; |
| 314 cookie.remove(); |
| 315 this._refresh(); |
| 316 } |
| 317 |
| 318 _refresh() { |
| 319 if (this._refreshCallback) |
| 320 this._refreshCallback(); |
| 321 } |
| 74 }; | 322 }; |
| 75 | |
| 76 WebInspector.CookiesTable.prototype = { | |
| 77 /** | |
| 78 * @param {?string} domain | |
| 79 */ | |
| 80 _clearAndRefresh: function(domain) | |
| 81 { | |
| 82 this.clear(domain); | |
| 83 this._refresh(); | |
| 84 }, | |
| 85 | |
| 86 /** | |
| 87 * @param {!WebInspector.ContextMenu} contextMenu | |
| 88 * @param {!WebInspector.DataGridNode} node | |
| 89 */ | |
| 90 _onRowContextMenu: function(contextMenu, node) | |
| 91 { | |
| 92 if (node === this._dataGrid.creationNode) | |
| 93 return; | |
| 94 var domain = node.cookie.domain(); | |
| 95 if (domain) | |
| 96 contextMenu.appendItem(WebInspector.UIString.capitalize("Clear ^all
from \"%s\"", domain), this._clearAndRefresh.bind(this, domain)); | |
| 97 contextMenu.appendItem(WebInspector.UIString.capitalize("Clear ^all"), t
his._clearAndRefresh.bind(this, null)); | |
| 98 }, | |
| 99 | |
| 100 /** | |
| 101 * @param {!Array.<!WebInspector.Cookie>} cookies | |
| 102 */ | |
| 103 setCookies: function(cookies) | |
| 104 { | |
| 105 this.setCookieFolders([{cookies: cookies}]); | |
| 106 }, | |
| 107 | |
| 108 /** | |
| 109 * @param {!Array.<!{folderName: ?string, cookies: !Array.<!WebInspector.Coo
kie>}>} cookieFolders | |
| 110 */ | |
| 111 setCookieFolders: function(cookieFolders) | |
| 112 { | |
| 113 this._data = cookieFolders; | |
| 114 this._rebuildTable(); | |
| 115 }, | |
| 116 | |
| 117 /** | |
| 118 * @return {?WebInspector.Cookie} | |
| 119 */ | |
| 120 selectedCookie: function() | |
| 121 { | |
| 122 var node = this._dataGrid.selectedNode; | |
| 123 return node ? node.cookie : null; | |
| 124 }, | |
| 125 | |
| 126 /** | |
| 127 * @param {?string=} domain | |
| 128 */ | |
| 129 clear: function(domain) | |
| 130 { | |
| 131 for (var i = 0, length = this._data.length; i < length; ++i) { | |
| 132 var cookies = this._data[i].cookies; | |
| 133 for (var j = 0, cookieCount = cookies.length; j < cookieCount; ++j)
{ | |
| 134 if (!domain || cookies[j].domain() === domain) | |
| 135 cookies[j].remove(); | |
| 136 } | |
| 137 } | |
| 138 }, | |
| 139 | |
| 140 _rebuildTable: function() | |
| 141 { | |
| 142 var selectedCookie = this._nextSelectedCookie || this.selectedCookie(); | |
| 143 this._nextSelectedCookie = null; | |
| 144 this._dataGrid.rootNode().removeChildren(); | |
| 145 for (var i = 0; i < this._data.length; ++i) { | |
| 146 var item = this._data[i]; | |
| 147 if (item.folderName) { | |
| 148 var groupData = {name: item.folderName, value: "", domain: "", p
ath: "", expires: "", size: this._totalSize(item.cookies), httpOnly: "", secure:
"", sameSite: ""}; | |
| 149 var groupNode = new WebInspector.DataGridNode(groupData); | |
| 150 groupNode.selectable = true; | |
| 151 this._dataGrid.rootNode().appendChild(groupNode); | |
| 152 groupNode.element().classList.add("row-group"); | |
| 153 this._populateNode(groupNode, item.cookies, selectedCookie); | |
| 154 groupNode.expand(); | |
| 155 } else | |
| 156 this._populateNode(this._dataGrid.rootNode(), item.cookies, sele
ctedCookie); | |
| 157 } | |
| 158 }, | |
| 159 | |
| 160 /** | |
| 161 * @param {!WebInspector.DataGridNode} parentNode | |
| 162 * @param {?Array.<!WebInspector.Cookie>} cookies | |
| 163 * @param {?WebInspector.Cookie} selectedCookie | |
| 164 */ | |
| 165 _populateNode: function(parentNode, cookies, selectedCookie) | |
| 166 { | |
| 167 parentNode.removeChildren(); | |
| 168 if (!cookies) | |
| 169 return; | |
| 170 | |
| 171 this._sortCookies(cookies); | |
| 172 for (var i = 0; i < cookies.length; ++i) { | |
| 173 var cookie = cookies[i]; | |
| 174 var cookieNode = this._createGridNode(cookie); | |
| 175 parentNode.appendChild(cookieNode); | |
| 176 if (selectedCookie && selectedCookie.name() === cookie.name() && sel
ectedCookie.domain() === cookie.domain() && selectedCookie.path() === cookie.pat
h()) | |
| 177 cookieNode.select(); | |
| 178 } | |
| 179 }, | |
| 180 | |
| 181 _totalSize: function(cookies) | |
| 182 { | |
| 183 var totalSize = 0; | |
| 184 for (var i = 0; cookies && i < cookies.length; ++i) | |
| 185 totalSize += cookies[i].size(); | |
| 186 return totalSize; | |
| 187 }, | |
| 188 | |
| 189 /** | |
| 190 * @param {!Array.<!WebInspector.Cookie>} cookies | |
| 191 */ | |
| 192 _sortCookies: function(cookies) | |
| 193 { | |
| 194 var sortDirection = this._dataGrid.isSortOrderAscending() ? 1 : -1; | |
| 195 | |
| 196 function compareTo(getter, cookie1, cookie2) | |
| 197 { | |
| 198 return sortDirection * (getter.apply(cookie1) + "").compareTo(getter
.apply(cookie2) + ""); | |
| 199 } | |
| 200 | |
| 201 function numberCompare(getter, cookie1, cookie2) | |
| 202 { | |
| 203 return sortDirection * (getter.apply(cookie1) - getter.apply(cookie2
)); | |
| 204 } | |
| 205 | |
| 206 function expiresCompare(cookie1, cookie2) | |
| 207 { | |
| 208 if (cookie1.session() !== cookie2.session()) | |
| 209 return sortDirection * (cookie1.session() ? 1 : -1); | |
| 210 | |
| 211 if (cookie1.session()) | |
| 212 return 0; | |
| 213 | |
| 214 if (cookie1.maxAge() && cookie2.maxAge()) | |
| 215 return sortDirection * (cookie1.maxAge() - cookie2.maxAge()); | |
| 216 if (cookie1.expires() && cookie2.expires()) | |
| 217 return sortDirection * (cookie1.expires() - cookie2.expires()); | |
| 218 return sortDirection * (cookie1.expires() ? 1 : -1); | |
| 219 } | |
| 220 | |
| 221 var comparator; | |
| 222 switch (this._dataGrid.sortColumnId()) { | |
| 223 case "name": comparator = compareTo.bind(null, WebInspector.Cookie.proto
type.name); break; | |
| 224 case "value": comparator = compareTo.bind(null, WebInspector.Cookie.prot
otype.value); break; | |
| 225 case "domain": comparator = compareTo.bind(null, WebInspector.Cookie.pro
totype.domain); break; | |
| 226 case "path": comparator = compareTo.bind(null, WebInspector.Cookie.proto
type.path); break; | |
| 227 case "expires": comparator = expiresCompare; break; | |
| 228 case "size": comparator = numberCompare.bind(null, WebInspector.Cookie.p
rototype.size); break; | |
| 229 case "httpOnly": comparator = compareTo.bind(null, WebInspector.Cookie.p
rototype.httpOnly); break; | |
| 230 case "secure": comparator = compareTo.bind(null, WebInspector.Cookie.pro
totype.secure); break; | |
| 231 case "sameSite": comparator = compareTo.bind(null, WebInspector.Cookie.p
rototype.sameSite); break; | |
| 232 default: compareTo.bind(null, WebInspector.Cookie.prototype.name); | |
| 233 } | |
| 234 | |
| 235 cookies.sort(comparator); | |
| 236 }, | |
| 237 | |
| 238 /** | |
| 239 * @param {!WebInspector.Cookie} cookie | |
| 240 * @return {!WebInspector.DataGridNode} | |
| 241 */ | |
| 242 _createGridNode: function(cookie) | |
| 243 { | |
| 244 var data = {}; | |
| 245 data.name = cookie.name(); | |
| 246 data.value = cookie.value(); | |
| 247 if (cookie.type() === WebInspector.Cookie.Type.Request) { | |
| 248 data.domain = WebInspector.UIString("N/A"); | |
| 249 data.path = WebInspector.UIString("N/A"); | |
| 250 data.expires = WebInspector.UIString("N/A"); | |
| 251 } else { | |
| 252 data.domain = cookie.domain() || ""; | |
| 253 data.path = cookie.path() || ""; | |
| 254 if (cookie.maxAge()) | |
| 255 data.expires = Number.secondsToString(parseInt(cookie.maxAge(),
10)); | |
| 256 else if (cookie.expires()) | |
| 257 data.expires = new Date(cookie.expires()).toISOString(); | |
| 258 else | |
| 259 data.expires = WebInspector.UIString("Session"); | |
| 260 } | |
| 261 data.size = cookie.size(); | |
| 262 const checkmark = "\u2713"; | |
| 263 data.httpOnly = (cookie.httpOnly() ? checkmark : ""); | |
| 264 data.secure = (cookie.secure() ? checkmark : ""); | |
| 265 data.sameSite = cookie.sameSite() || ""; | |
| 266 | |
| 267 var node = new WebInspector.DataGridNode(data); | |
| 268 node.cookie = cookie; | |
| 269 node.selectable = true; | |
| 270 return node; | |
| 271 }, | |
| 272 | |
| 273 _onDeleteCookie: function(node) | |
| 274 { | |
| 275 var cookie = node.cookie; | |
| 276 var neighbour = node.traverseNextNode() || node.traversePreviousNode(); | |
| 277 if (neighbour) | |
| 278 this._nextSelectedCookie = neighbour.cookie; | |
| 279 cookie.remove(); | |
| 280 this._refresh(); | |
| 281 }, | |
| 282 | |
| 283 _refresh: function() | |
| 284 { | |
| 285 if (this._refreshCallback) | |
| 286 this._refreshCallback(); | |
| 287 }, | |
| 288 | |
| 289 __proto__: WebInspector.VBox.prototype | |
| 290 }; | |
| OLD | NEW |