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 |
(...skipping 13 matching lines...) Expand all Loading... |
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 | 30 |
31 /** | 31 /** |
32 * @unrestricted | 32 * @unrestricted |
33 */ | 33 */ |
34 Components.CookiesTable = class extends UI.VBox { | 34 CookieTable.CookiesTable = class extends UI.VBox { |
35 /** | 35 /** |
36 * @param {boolean} expandable | 36 * @param {boolean} expandable |
37 * @param {function()=} refreshCallback | 37 * @param {function()=} refreshCallback |
38 * @param {function()=} selectedCallback | 38 * @param {function()=} selectedCallback |
39 */ | 39 */ |
40 constructor(expandable, refreshCallback, selectedCallback) { | 40 constructor(expandable, refreshCallback, selectedCallback) { |
41 super(); | 41 super(); |
42 | 42 |
43 var readOnly = expandable; | 43 var readOnly = expandable; |
44 this._refreshCallback = refreshCallback; | 44 this._refreshCallback = refreshCallback; |
45 | 45 |
46 var columns = /** @type {!Array<!UI.DataGrid.ColumnDescriptor>} */ ([ | 46 var columns = /** @type {!Array<!DataGrid.DataGrid.ColumnDescriptor>} */ ([ |
47 { | 47 { |
48 id: 'name', | 48 id: 'name', |
49 title: Common.UIString('Name'), | 49 title: Common.UIString('Name'), |
50 sortable: true, | 50 sortable: true, |
51 disclosure: expandable, | 51 disclosure: expandable, |
52 sort: UI.DataGrid.Order.Ascending, | 52 sort: DataGrid.DataGrid.Order.Ascending, |
53 longText: true, | 53 longText: true, |
54 weight: 24 | 54 weight: 24 |
55 }, | 55 }, |
56 {id: 'value', title: Common.UIString('Value'), sortable: true, longText: t
rue, weight: 34}, | 56 {id: 'value', title: Common.UIString('Value'), sortable: true, longText: t
rue, weight: 34}, |
57 {id: 'domain', title: Common.UIString('Domain'), sortable: true, weight: 7
}, | 57 {id: 'domain', title: Common.UIString('Domain'), sortable: true, weight: 7
}, |
58 {id: 'path', title: Common.UIString('Path'), sortable: true, weight: 7}, | 58 {id: 'path', title: Common.UIString('Path'), sortable: true, weight: 7}, |
59 {id: 'expires', title: Common.UIString('Expires / Max-Age'), sortable: tru
e, weight: 7}, | 59 {id: 'expires', title: Common.UIString('Expires / Max-Age'), sortable: tru
e, weight: 7}, |
60 {id: 'size', title: Common.UIString('Size'), sortable: true, align: UI.Dat
aGrid.Align.Right, weight: 7}, | 60 {id: 'size', title: Common.UIString('Size'), sortable: true, align: DataGr
id.DataGrid.Align.Right, weight: 7}, { |
61 {id: 'httpOnly', title: Common.UIString('HTTP'), sortable: true, align: UI
.DataGrid.Align.Center, weight: 7}, | 61 id: 'httpOnly', |
62 {id: 'secure', title: Common.UIString('Secure'), sortable: true, align: UI
.DataGrid.Align.Center, weight: 7}, { | 62 title: Common.UIString('HTTP'), |
| 63 sortable: true, |
| 64 align: DataGrid.DataGrid.Align.Center, |
| 65 weight: 7 |
| 66 }, |
| 67 { |
| 68 id: 'secure', |
| 69 title: Common.UIString('Secure'), |
| 70 sortable: true, |
| 71 align: DataGrid.DataGrid.Align.Center, |
| 72 weight: 7 |
| 73 }, |
| 74 { |
63 id: 'sameSite', | 75 id: 'sameSite', |
64 title: Common.UIString('SameSite'), | 76 title: Common.UIString('SameSite'), |
65 sortable: true, | 77 sortable: true, |
66 align: UI.DataGrid.Align.Center, | 78 align: DataGrid.DataGrid.Align.Center, |
67 weight: 7 | 79 weight: 7 |
68 } | 80 } |
69 ]); | 81 ]); |
70 | 82 |
71 if (readOnly) { | 83 if (readOnly) { |
72 this._dataGrid = new UI.DataGrid(columns); | 84 this._dataGrid = new DataGrid.DataGrid(columns); |
73 } else { | 85 } else { |
74 this._dataGrid = new UI.DataGrid(columns, undefined, this._onDeleteCookie.
bind(this), refreshCallback); | 86 this._dataGrid = new DataGrid.DataGrid(columns, undefined, this._onDeleteC
ookie.bind(this), refreshCallback); |
75 this._dataGrid.setRowContextMenuCallback(this._onRowContextMenu.bind(this)
); | 87 this._dataGrid.setRowContextMenuCallback(this._onRowContextMenu.bind(this)
); |
76 } | 88 } |
77 | 89 |
78 this._dataGrid.setName('cookiesTable'); | 90 this._dataGrid.setName('cookiesTable'); |
79 this._dataGrid.addEventListener(UI.DataGrid.Events.SortingChanged, this._reb
uildTable, this); | 91 this._dataGrid.addEventListener(DataGrid.DataGrid.Events.SortingChanged, thi
s._rebuildTable, this); |
80 | 92 |
81 if (selectedCallback) | 93 if (selectedCallback) |
82 this._dataGrid.addEventListener(UI.DataGrid.Events.SelectedNode, selectedC
allback, this); | 94 this._dataGrid.addEventListener(DataGrid.DataGrid.Events.SelectedNode, sel
ectedCallback, this); |
83 | 95 |
84 this._nextSelectedCookie = /** @type {?SDK.Cookie} */ (null); | 96 this._nextSelectedCookie = /** @type {?SDK.Cookie} */ (null); |
85 | 97 |
86 this._dataGrid.asWidget().show(this.element); | 98 this._dataGrid.asWidget().show(this.element); |
87 this._data = []; | 99 this._data = []; |
88 } | 100 } |
89 | 101 |
90 /** | 102 /** |
91 * @param {?string} domain | 103 * @param {?string} domain |
92 */ | 104 */ |
93 _clearAndRefresh(domain) { | 105 _clearAndRefresh(domain) { |
94 this.clear(domain); | 106 this.clear(domain); |
95 this._refresh(); | 107 this._refresh(); |
96 } | 108 } |
97 | 109 |
98 /** | 110 /** |
99 * @param {!UI.ContextMenu} contextMenu | 111 * @param {!UI.ContextMenu} contextMenu |
100 * @param {!UI.DataGridNode} node | 112 * @param {!DataGrid.DataGridNode} node |
101 */ | 113 */ |
102 _onRowContextMenu(contextMenu, node) { | 114 _onRowContextMenu(contextMenu, node) { |
103 if (node === this._dataGrid.creationNode) | 115 if (node === this._dataGrid.creationNode) |
104 return; | 116 return; |
105 var domain = node.cookie.domain(); | 117 var domain = node.cookie.domain(); |
106 if (domain) { | 118 if (domain) { |
107 contextMenu.appendItem( | 119 contextMenu.appendItem( |
108 Common.UIString.capitalize('Clear ^all from "%s"', domain), this._clea
rAndRefresh.bind(this, domain)); | 120 Common.UIString.capitalize('Clear ^all from "%s"', domain), this._clea
rAndRefresh.bind(this, domain)); |
109 } | 121 } |
110 contextMenu.appendItem(Common.UIString.capitalize('Clear ^all'), this._clear
AndRefresh.bind(this, null)); | 122 contextMenu.appendItem(Common.UIString.capitalize('Clear ^all'), this._clear
AndRefresh.bind(this, null)); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 name: item.folderName, | 169 name: item.folderName, |
158 value: '', | 170 value: '', |
159 domain: '', | 171 domain: '', |
160 path: '', | 172 path: '', |
161 expires: '', | 173 expires: '', |
162 size: this._totalSize(item.cookies), | 174 size: this._totalSize(item.cookies), |
163 httpOnly: '', | 175 httpOnly: '', |
164 secure: '', | 176 secure: '', |
165 sameSite: '' | 177 sameSite: '' |
166 }; | 178 }; |
167 var groupNode = new UI.DataGridNode(groupData); | 179 var groupNode = new DataGrid.DataGridNode(groupData); |
168 groupNode.selectable = true; | 180 groupNode.selectable = true; |
169 this._dataGrid.rootNode().appendChild(groupNode); | 181 this._dataGrid.rootNode().appendChild(groupNode); |
170 groupNode.element().classList.add('row-group'); | 182 groupNode.element().classList.add('row-group'); |
171 this._populateNode(groupNode, item.cookies, selectedCookie); | 183 this._populateNode(groupNode, item.cookies, selectedCookie); |
172 groupNode.expand(); | 184 groupNode.expand(); |
173 } else { | 185 } else { |
174 this._populateNode(this._dataGrid.rootNode(), item.cookies, selectedCook
ie); | 186 this._populateNode(this._dataGrid.rootNode(), item.cookies, selectedCook
ie); |
175 } | 187 } |
176 } | 188 } |
177 } | 189 } |
178 | 190 |
179 /** | 191 /** |
180 * @param {!UI.DataGridNode} parentNode | 192 * @param {!DataGrid.DataGridNode} parentNode |
181 * @param {?Array.<!SDK.Cookie>} cookies | 193 * @param {?Array.<!SDK.Cookie>} cookies |
182 * @param {?SDK.Cookie} selectedCookie | 194 * @param {?SDK.Cookie} selectedCookie |
183 */ | 195 */ |
184 _populateNode(parentNode, cookies, selectedCookie) { | 196 _populateNode(parentNode, cookies, selectedCookie) { |
185 parentNode.removeChildren(); | 197 parentNode.removeChildren(); |
186 if (!cookies) | 198 if (!cookies) |
187 return; | 199 return; |
188 | 200 |
189 this._sortCookies(cookies); | 201 this._sortCookies(cookies); |
190 for (var i = 0; i < cookies.length; ++i) { | 202 for (var i = 0; i < cookies.length; ++i) { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 comparator = expiresCompare; | 272 comparator = expiresCompare; |
261 else if (columnId === 'size') | 273 else if (columnId === 'size') |
262 comparator = numberCompare; | 274 comparator = numberCompare; |
263 else | 275 else |
264 comparator = compareTo.bind(null, columnId); | 276 comparator = compareTo.bind(null, columnId); |
265 cookies.sort(comparator); | 277 cookies.sort(comparator); |
266 } | 278 } |
267 | 279 |
268 /** | 280 /** |
269 * @param {!SDK.Cookie} cookie | 281 * @param {!SDK.Cookie} cookie |
270 * @return {!UI.DataGridNode} | 282 * @return {!DataGrid.DataGridNode} |
271 */ | 283 */ |
272 _createGridNode(cookie) { | 284 _createGridNode(cookie) { |
273 var data = {}; | 285 var data = {}; |
274 data.name = cookie.name(); | 286 data.name = cookie.name(); |
275 data.value = cookie.value(); | 287 data.value = cookie.value(); |
276 if (cookie.type() === SDK.Cookie.Type.Request) { | 288 if (cookie.type() === SDK.Cookie.Type.Request) { |
277 data.domain = Common.UIString('N/A'); | 289 data.domain = Common.UIString('N/A'); |
278 data.path = Common.UIString('N/A'); | 290 data.path = Common.UIString('N/A'); |
279 data.expires = Common.UIString('N/A'); | 291 data.expires = Common.UIString('N/A'); |
280 } else { | 292 } else { |
281 data.domain = cookie.domain() || ''; | 293 data.domain = cookie.domain() || ''; |
282 data.path = cookie.path() || ''; | 294 data.path = cookie.path() || ''; |
283 if (cookie.maxAge()) | 295 if (cookie.maxAge()) |
284 data.expires = Number.secondsToString(parseInt(cookie.maxAge(), 10)); | 296 data.expires = Number.secondsToString(parseInt(cookie.maxAge(), 10)); |
285 else if (cookie.expires()) | 297 else if (cookie.expires()) |
286 data.expires = new Date(cookie.expires()).toISOString(); | 298 data.expires = new Date(cookie.expires()).toISOString(); |
287 else | 299 else |
288 data.expires = Common.UIString('Session'); | 300 data.expires = Common.UIString('Session'); |
289 } | 301 } |
290 data.size = cookie.size(); | 302 data.size = cookie.size(); |
291 const checkmark = '\u2713'; | 303 const checkmark = '\u2713'; |
292 data.httpOnly = (cookie.httpOnly() ? checkmark : ''); | 304 data.httpOnly = (cookie.httpOnly() ? checkmark : ''); |
293 data.secure = (cookie.secure() ? checkmark : ''); | 305 data.secure = (cookie.secure() ? checkmark : ''); |
294 data.sameSite = cookie.sameSite() || ''; | 306 data.sameSite = cookie.sameSite() || ''; |
295 | 307 |
296 var node = new UI.DataGridNode(data); | 308 var node = new DataGrid.DataGridNode(data); |
297 node.cookie = cookie; | 309 node.cookie = cookie; |
298 node.selectable = true; | 310 node.selectable = true; |
299 return node; | 311 return node; |
300 } | 312 } |
301 | 313 |
302 _onDeleteCookie(node) { | 314 _onDeleteCookie(node) { |
303 var cookie = node.cookie; | 315 var cookie = node.cookie; |
304 var neighbour = node.traverseNextNode() || node.traversePreviousNode(); | 316 var neighbour = node.traverseNextNode() || node.traversePreviousNode(); |
305 if (neighbour) | 317 if (neighbour) |
306 this._nextSelectedCookie = neighbour.cookie; | 318 this._nextSelectedCookie = neighbour.cookie; |
307 cookie.remove(); | 319 cookie.remove(); |
308 this._refresh(); | 320 this._refresh(); |
309 } | 321 } |
310 | 322 |
311 _refresh() { | 323 _refresh() { |
312 if (this._refreshCallback) | 324 if (this._refreshCallback) |
313 this._refreshCallback(); | 325 this._refreshCallback(); |
314 } | 326 } |
315 }; | 327 }; |
OLD | NEW |