Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/components_lazy/CookiesTable.js

Issue 2493373002: DevTools: rename WebInspector into modules. (Closed)
Patch Set: for bots Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 WebInspector.CookiesTable = class extends WebInspector.VBox { 34 Components.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<!WebInspector.DataGrid.ColumnDescriptor>} */ ([ 46 var columns = /** @type {!Array<!UI.DataGrid.ColumnDescriptor>} */ ([
47 { 47 {
48 id: 'name', 48 id: 'name',
49 title: WebInspector.UIString('Name'), 49 title: Common.UIString('Name'),
50 sortable: true, 50 sortable: true,
51 disclosure: expandable, 51 disclosure: expandable,
52 sort: WebInspector.DataGrid.Order.Ascending, 52 sort: UI.DataGrid.Order.Ascending,
53 longText: true, 53 longText: true,
54 weight: 24 54 weight: 24
55 }, 55 },
56 {id: 'value', title: WebInspector.UIString('Value'), sortable: true, longT ext: true, weight: 34}, 56 {id: 'value', title: Common.UIString('Value'), sortable: true, longText: t rue, weight: 34},
57 {id: 'domain', title: WebInspector.UIString('Domain'), sortable: true, wei ght: 7}, 57 {id: 'domain', title: Common.UIString('Domain'), sortable: true, weight: 7 },
58 {id: 'path', title: WebInspector.UIString('Path'), sortable: true, weight: 7}, 58 {id: 'path', title: Common.UIString('Path'), sortable: true, weight: 7},
59 {id: 'expires', title: WebInspector.UIString('Expires / Max-Age'), sortabl e: true, weight: 7}, { 59 {id: 'expires', title: Common.UIString('Expires / Max-Age'), sortable: tru e, weight: 7}, {
60 id: 'size', 60 id: 'size',
61 title: WebInspector.UIString('Size'), 61 title: Common.UIString('Size'),
62 sortable: true, 62 sortable: true,
63 align: WebInspector.DataGrid.Align.Right, 63 align: UI.DataGrid.Align.Right,
64 weight: 7 64 weight: 7
65 }, 65 },
66 { 66 {
67 id: 'httpOnly', 67 id: 'httpOnly',
68 title: WebInspector.UIString('HTTP'), 68 title: Common.UIString('HTTP'),
69 sortable: true, 69 sortable: true,
70 align: WebInspector.DataGrid.Align.Center, 70 align: UI.DataGrid.Align.Center,
71 weight: 7 71 weight: 7
72 }, 72 },
73 { 73 {
74 id: 'secure', 74 id: 'secure',
75 title: WebInspector.UIString('Secure'), 75 title: Common.UIString('Secure'),
76 sortable: true, 76 sortable: true,
77 align: WebInspector.DataGrid.Align.Center, 77 align: UI.DataGrid.Align.Center,
78 weight: 7 78 weight: 7
79 }, 79 },
80 { 80 {
81 id: 'sameSite', 81 id: 'sameSite',
82 title: WebInspector.UIString('SameSite'), 82 title: Common.UIString('SameSite'),
83 sortable: true, 83 sortable: true,
84 align: WebInspector.DataGrid.Align.Center, 84 align: UI.DataGrid.Align.Center,
85 weight: 7 85 weight: 7
86 } 86 }
87 ]); 87 ]);
88 88
89 if (readOnly) { 89 if (readOnly) {
90 this._dataGrid = new WebInspector.DataGrid(columns); 90 this._dataGrid = new UI.DataGrid(columns);
91 } else { 91 } else {
92 this._dataGrid = new WebInspector.DataGrid(columns, undefined, this._onDel eteCookie.bind(this), refreshCallback); 92 this._dataGrid = new UI.DataGrid(columns, undefined, this._onDeleteCookie. bind(this), refreshCallback);
93 this._dataGrid.setRowContextMenuCallback(this._onRowContextMenu.bind(this) ); 93 this._dataGrid.setRowContextMenuCallback(this._onRowContextMenu.bind(this) );
94 } 94 }
95 95
96 this._dataGrid.setName('cookiesTable'); 96 this._dataGrid.setName('cookiesTable');
97 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SortingChanged, this._rebuildTable, this); 97 this._dataGrid.addEventListener(UI.DataGrid.Events.SortingChanged, this._reb uildTable, this);
98 98
99 if (selectedCallback) 99 if (selectedCallback)
100 this._dataGrid.addEventListener(WebInspector.DataGrid.Events.SelectedNode, selectedCallback, this); 100 this._dataGrid.addEventListener(UI.DataGrid.Events.SelectedNode, selectedC allback, this);
101 101
102 this._nextSelectedCookie = /** @type {?WebInspector.Cookie} */ (null); 102 this._nextSelectedCookie = /** @type {?SDK.Cookie} */ (null);
103 103
104 this._dataGrid.asWidget().show(this.element); 104 this._dataGrid.asWidget().show(this.element);
105 this._data = []; 105 this._data = [];
106 } 106 }
107 107
108 /** 108 /**
109 * @param {?string} domain 109 * @param {?string} domain
110 */ 110 */
111 _clearAndRefresh(domain) { 111 _clearAndRefresh(domain) {
112 this.clear(domain); 112 this.clear(domain);
113 this._refresh(); 113 this._refresh();
114 } 114 }
115 115
116 /** 116 /**
117 * @param {!WebInspector.ContextMenu} contextMenu 117 * @param {!UI.ContextMenu} contextMenu
118 * @param {!WebInspector.DataGridNode} node 118 * @param {!UI.DataGridNode} node
119 */ 119 */
120 _onRowContextMenu(contextMenu, node) { 120 _onRowContextMenu(contextMenu, node) {
121 if (node === this._dataGrid.creationNode) 121 if (node === this._dataGrid.creationNode)
122 return; 122 return;
123 var domain = node.cookie.domain(); 123 var domain = node.cookie.domain();
124 if (domain) 124 if (domain)
125 contextMenu.appendItem( 125 contextMenu.appendItem(
126 WebInspector.UIString.capitalize('Clear ^all from "%s"', domain), this ._clearAndRefresh.bind(this, domain)); 126 Common.UIString.capitalize('Clear ^all from "%s"', domain), this._clea rAndRefresh.bind(this, domain));
127 contextMenu.appendItem(WebInspector.UIString.capitalize('Clear ^all'), this. _clearAndRefresh.bind(this, null)); 127 contextMenu.appendItem(Common.UIString.capitalize('Clear ^all'), this._clear AndRefresh.bind(this, null));
128 } 128 }
129 129
130 /** 130 /**
131 * @param {!Array.<!WebInspector.Cookie>} cookies 131 * @param {!Array.<!SDK.Cookie>} cookies
132 */ 132 */
133 setCookies(cookies) { 133 setCookies(cookies) {
134 this.setCookieFolders([{cookies: cookies}]); 134 this.setCookieFolders([{cookies: cookies}]);
135 } 135 }
136 136
137 /** 137 /**
138 * @param {!Array.<!{folderName: ?string, cookies: !Array.<!WebInspector.Cooki e>}>} cookieFolders 138 * @param {!Array.<!{folderName: ?string, cookies: !Array.<!SDK.Cookie>}>} coo kieFolders
139 */ 139 */
140 setCookieFolders(cookieFolders) { 140 setCookieFolders(cookieFolders) {
141 this._data = cookieFolders; 141 this._data = cookieFolders;
142 this._rebuildTable(); 142 this._rebuildTable();
143 } 143 }
144 144
145 /** 145 /**
146 * @return {?WebInspector.Cookie} 146 * @return {?SDK.Cookie}
147 */ 147 */
148 selectedCookie() { 148 selectedCookie() {
149 var node = this._dataGrid.selectedNode; 149 var node = this._dataGrid.selectedNode;
150 return node ? node.cookie : null; 150 return node ? node.cookie : null;
151 } 151 }
152 152
153 /** 153 /**
154 * @param {?string=} domain 154 * @param {?string=} domain
155 */ 155 */
156 clear(domain) { 156 clear(domain) {
(...skipping 17 matching lines...) Expand all
174 name: item.folderName, 174 name: item.folderName,
175 value: '', 175 value: '',
176 domain: '', 176 domain: '',
177 path: '', 177 path: '',
178 expires: '', 178 expires: '',
179 size: this._totalSize(item.cookies), 179 size: this._totalSize(item.cookies),
180 httpOnly: '', 180 httpOnly: '',
181 secure: '', 181 secure: '',
182 sameSite: '' 182 sameSite: ''
183 }; 183 };
184 var groupNode = new WebInspector.DataGridNode(groupData); 184 var groupNode = new UI.DataGridNode(groupData);
185 groupNode.selectable = true; 185 groupNode.selectable = true;
186 this._dataGrid.rootNode().appendChild(groupNode); 186 this._dataGrid.rootNode().appendChild(groupNode);
187 groupNode.element().classList.add('row-group'); 187 groupNode.element().classList.add('row-group');
188 this._populateNode(groupNode, item.cookies, selectedCookie); 188 this._populateNode(groupNode, item.cookies, selectedCookie);
189 groupNode.expand(); 189 groupNode.expand();
190 } else 190 } else
191 this._populateNode(this._dataGrid.rootNode(), item.cookies, selectedCook ie); 191 this._populateNode(this._dataGrid.rootNode(), item.cookies, selectedCook ie);
192 } 192 }
193 } 193 }
194 194
195 /** 195 /**
196 * @param {!WebInspector.DataGridNode} parentNode 196 * @param {!UI.DataGridNode} parentNode
197 * @param {?Array.<!WebInspector.Cookie>} cookies 197 * @param {?Array.<!SDK.Cookie>} cookies
198 * @param {?WebInspector.Cookie} selectedCookie 198 * @param {?SDK.Cookie} selectedCookie
199 */ 199 */
200 _populateNode(parentNode, cookies, selectedCookie) { 200 _populateNode(parentNode, cookies, selectedCookie) {
201 parentNode.removeChildren(); 201 parentNode.removeChildren();
202 if (!cookies) 202 if (!cookies)
203 return; 203 return;
204 204
205 this._sortCookies(cookies); 205 this._sortCookies(cookies);
206 for (var i = 0; i < cookies.length; ++i) { 206 for (var i = 0; i < cookies.length; ++i) {
207 var cookie = cookies[i]; 207 var cookie = cookies[i];
208 var cookieNode = this._createGridNode(cookie); 208 var cookieNode = this._createGridNode(cookie);
209 parentNode.appendChild(cookieNode); 209 parentNode.appendChild(cookieNode);
210 if (selectedCookie && selectedCookie.name() === cookie.name() && selectedC ookie.domain() === cookie.domain() && 210 if (selectedCookie && selectedCookie.name() === cookie.name() && selectedC ookie.domain() === cookie.domain() &&
211 selectedCookie.path() === cookie.path()) 211 selectedCookie.path() === cookie.path())
212 cookieNode.select(); 212 cookieNode.select();
213 } 213 }
214 } 214 }
215 215
216 _totalSize(cookies) { 216 _totalSize(cookies) {
217 var totalSize = 0; 217 var totalSize = 0;
218 for (var i = 0; cookies && i < cookies.length; ++i) 218 for (var i = 0; cookies && i < cookies.length; ++i)
219 totalSize += cookies[i].size(); 219 totalSize += cookies[i].size();
220 return totalSize; 220 return totalSize;
221 } 221 }
222 222
223 /** 223 /**
224 * @param {!Array.<!WebInspector.Cookie>} cookies 224 * @param {!Array.<!SDK.Cookie>} cookies
225 */ 225 */
226 _sortCookies(cookies) { 226 _sortCookies(cookies) {
227 var sortDirection = this._dataGrid.isSortOrderAscending() ? 1 : -1; 227 var sortDirection = this._dataGrid.isSortOrderAscending() ? 1 : -1;
228 228
229 /** 229 /**
230 * @param {string} property 230 * @param {string} property
231 * @param {!WebInspector.Cookie} cookie1 231 * @param {!SDK.Cookie} cookie1
232 * @param {!WebInspector.Cookie} cookie2 232 * @param {!SDK.Cookie} cookie2
233 */ 233 */
234 function compareTo(property, cookie1, cookie2) { 234 function compareTo(property, cookie1, cookie2) {
235 return sortDirection * 235 return sortDirection *
236 (String(cookie1[property] || cookie1['name'])).compareTo(String(cookie 2[property] || cookie2['name'])); 236 (String(cookie1[property] || cookie1['name'])).compareTo(String(cookie 2[property] || cookie2['name']));
237 } 237 }
238 238
239 /** 239 /**
240 * @param {!WebInspector.Cookie} cookie1 240 * @param {!SDK.Cookie} cookie1
241 * @param {!WebInspector.Cookie} cookie2 241 * @param {!SDK.Cookie} cookie2
242 */ 242 */
243 function numberCompare(cookie1, cookie2) { 243 function numberCompare(cookie1, cookie2) {
244 return sortDirection * (cookie1.size() - cookie2.size()); 244 return sortDirection * (cookie1.size() - cookie2.size());
245 } 245 }
246 246
247 /** 247 /**
248 * @param {!WebInspector.Cookie} cookie1 248 * @param {!SDK.Cookie} cookie1
249 * @param {!WebInspector.Cookie} cookie2 249 * @param {!SDK.Cookie} cookie2
250 */ 250 */
251 function expiresCompare(cookie1, cookie2) { 251 function expiresCompare(cookie1, cookie2) {
252 if (cookie1.session() !== cookie2.session()) 252 if (cookie1.session() !== cookie2.session())
253 return sortDirection * (cookie1.session() ? 1 : -1); 253 return sortDirection * (cookie1.session() ? 1 : -1);
254 254
255 if (cookie1.session()) 255 if (cookie1.session())
256 return 0; 256 return 0;
257 257
258 if (cookie1.maxAge() && cookie2.maxAge()) 258 if (cookie1.maxAge() && cookie2.maxAge())
259 return sortDirection * (cookie1.maxAge() - cookie2.maxAge()); 259 return sortDirection * (cookie1.maxAge() - cookie2.maxAge());
260 if (cookie1.expires() && cookie2.expires()) 260 if (cookie1.expires() && cookie2.expires())
261 return sortDirection * (cookie1.expires() - cookie2.expires()); 261 return sortDirection * (cookie1.expires() - cookie2.expires());
262 return sortDirection * (cookie1.expires() ? 1 : -1); 262 return sortDirection * (cookie1.expires() ? 1 : -1);
263 } 263 }
264 264
265 var comparator; 265 var comparator;
266 var columnId = this._dataGrid.sortColumnId() || 'name'; 266 var columnId = this._dataGrid.sortColumnId() || 'name';
267 if (columnId === 'expires') 267 if (columnId === 'expires')
268 comparator = expiresCompare; 268 comparator = expiresCompare;
269 else if (columnId === 'size') 269 else if (columnId === 'size')
270 comparator = numberCompare; 270 comparator = numberCompare;
271 else 271 else
272 comparator = compareTo.bind(null, columnId); 272 comparator = compareTo.bind(null, columnId);
273 cookies.sort(comparator); 273 cookies.sort(comparator);
274 } 274 }
275 275
276 /** 276 /**
277 * @param {!WebInspector.Cookie} cookie 277 * @param {!SDK.Cookie} cookie
278 * @return {!WebInspector.DataGridNode} 278 * @return {!UI.DataGridNode}
279 */ 279 */
280 _createGridNode(cookie) { 280 _createGridNode(cookie) {
281 var data = {}; 281 var data = {};
282 data.name = cookie.name(); 282 data.name = cookie.name();
283 data.value = cookie.value(); 283 data.value = cookie.value();
284 if (cookie.type() === WebInspector.Cookie.Type.Request) { 284 if (cookie.type() === SDK.Cookie.Type.Request) {
285 data.domain = WebInspector.UIString('N/A'); 285 data.domain = Common.UIString('N/A');
286 data.path = WebInspector.UIString('N/A'); 286 data.path = Common.UIString('N/A');
287 data.expires = WebInspector.UIString('N/A'); 287 data.expires = Common.UIString('N/A');
288 } else { 288 } else {
289 data.domain = cookie.domain() || ''; 289 data.domain = cookie.domain() || '';
290 data.path = cookie.path() || ''; 290 data.path = cookie.path() || '';
291 if (cookie.maxAge()) 291 if (cookie.maxAge())
292 data.expires = Number.secondsToString(parseInt(cookie.maxAge(), 10)); 292 data.expires = Number.secondsToString(parseInt(cookie.maxAge(), 10));
293 else if (cookie.expires()) 293 else if (cookie.expires())
294 data.expires = new Date(cookie.expires()).toISOString(); 294 data.expires = new Date(cookie.expires()).toISOString();
295 else 295 else
296 data.expires = WebInspector.UIString('Session'); 296 data.expires = Common.UIString('Session');
297 } 297 }
298 data.size = cookie.size(); 298 data.size = cookie.size();
299 const checkmark = '\u2713'; 299 const checkmark = '\u2713';
300 data.httpOnly = (cookie.httpOnly() ? checkmark : ''); 300 data.httpOnly = (cookie.httpOnly() ? checkmark : '');
301 data.secure = (cookie.secure() ? checkmark : ''); 301 data.secure = (cookie.secure() ? checkmark : '');
302 data.sameSite = cookie.sameSite() || ''; 302 data.sameSite = cookie.sameSite() || '';
303 303
304 var node = new WebInspector.DataGridNode(data); 304 var node = new UI.DataGridNode(data);
305 node.cookie = cookie; 305 node.cookie = cookie;
306 node.selectable = true; 306 node.selectable = true;
307 return node; 307 return node;
308 } 308 }
309 309
310 _onDeleteCookie(node) { 310 _onDeleteCookie(node) {
311 var cookie = node.cookie; 311 var cookie = node.cookie;
312 var neighbour = node.traverseNextNode() || node.traversePreviousNode(); 312 var neighbour = node.traverseNextNode() || node.traversePreviousNode();
313 if (neighbour) 313 if (neighbour)
314 this._nextSelectedCookie = neighbour.cookie; 314 this._nextSelectedCookie = neighbour.cookie;
315 cookie.remove(); 315 cookie.remove();
316 this._refresh(); 316 this._refresh();
317 } 317 }
318 318
319 _refresh() { 319 _refresh() {
320 if (this._refreshCallback) 320 if (this._refreshCallback)
321 this._refreshCallback(); 321 this._refreshCallback();
322 } 322 }
323 }; 323 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698