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

Side by Side Diff: chrome/tools/test/reference_build/chrome_linux/resources/inspector/StoragePanel.js

Issue 177049: On Linux, move the passing of filedescriptors to a dedicated socketpair(). (Closed)
Patch Set: Removed *.d files from reference build Created 11 years, 3 months 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
(Empty)
1 /*
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Joseph Pecoraro
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 WebInspector.StoragePanel = function(database)
31 {
32 WebInspector.Panel.call(this);
33
34 this.sidebarElement = document.createElement("div");
35 this.sidebarElement.id = "storage-sidebar";
36 this.sidebarElement.className = "sidebar";
37 this.element.appendChild(this.sidebarElement);
38
39 this.sidebarResizeElement = document.createElement("div");
40 this.sidebarResizeElement.className = "sidebar-resizer-vertical";
41 this.sidebarResizeElement.addEventListener("mousedown", this._startSidebarDr agging.bind(this), false);
42 this.element.appendChild(this.sidebarResizeElement);
43
44 this.sidebarTreeElement = document.createElement("ol");
45 this.sidebarTreeElement.className = "sidebar-tree";
46 this.sidebarElement.appendChild(this.sidebarTreeElement);
47
48 this.sidebarTree = new TreeOutline(this.sidebarTreeElement);
49
50 this.databasesListTreeElement = new WebInspector.SidebarSectionTreeElement(W ebInspector.UIString("DATABASES"), {}, true);
51 this.sidebarTree.appendChild(this.databasesListTreeElement);
52 this.databasesListTreeElement.expand();
53
54 this.localStorageListTreeElement = new WebInspector.SidebarSectionTreeElemen t(WebInspector.UIString("LOCAL STORAGE"), {}, true);
55 this.sidebarTree.appendChild(this.localStorageListTreeElement);
56 this.localStorageListTreeElement.expand();
57
58 this.sessionStorageListTreeElement = new WebInspector.SidebarSectionTreeElem ent(WebInspector.UIString("SESSION STORAGE"), {}, true);
59 this.sidebarTree.appendChild(this.sessionStorageListTreeElement);
60 this.sessionStorageListTreeElement.expand();
61
62 this.cookieListTreeElement = new WebInspector.SidebarSectionTreeElement(WebI nspector.UIString("COOKIES"), {}, true);
63 this.sidebarTree.appendChild(this.cookieListTreeElement);
64 this.cookieListTreeElement.expand();
65
66 this.storageViews = document.createElement("div");
67 this.storageViews.id = "storage-views";
68 this.element.appendChild(this.storageViews);
69
70 this.storageViewStatusBarItemsContainer = document.createElement("div");
71 this.storageViewStatusBarItemsContainer.id = "storage-view-status-bar-items" ;
72
73 this.reset();
74 }
75
76 WebInspector.StoragePanel.prototype = {
77 toolbarItemClass: "storage",
78
79 get toolbarItemLabel()
80 {
81 return WebInspector.UIString("Storage");
82 },
83
84 get statusBarItems()
85 {
86 return [this.storageViewStatusBarItemsContainer];
87 },
88
89 show: function()
90 {
91 WebInspector.Panel.prototype.show.call(this);
92 this._updateSidebarWidth();
93 this._registerStorageEventListener();
94 this.populateInterface();
95 },
96
97 populateInterface: function()
98 {
99 this.addCookies();
100 },
101
102 reset: function()
103 {
104 if (this._databases) {
105 var databasesLength = this._databases.length;
106 for (var i = 0; i < databasesLength; ++i) {
107 var database = this._databases[i];
108
109 delete database._tableViews;
110 delete database._queryView;
111 }
112 }
113
114 this._databases = [];
115
116 this._unregisterStorageEventListener();
117
118 if (this._domStorage) {
119 var domStorageLength = this._domStorage.length;
120 for (var i = 0; i < domStorageLength; ++i) {
121 var domStorage = this._domStorage[i];
122
123 delete domStorage._domStorageView;
124 }
125 }
126
127 this._domStorage = [];
128
129 delete this.cookieTreeElement;
130 delete this._cookieView;
131
132 this.databasesListTreeElement.removeChildren();
133 this.localStorageListTreeElement.removeChildren();
134 this.sessionStorageListTreeElement.removeChildren();
135 this.cookieListTreeElement.removeChildren();
136 this.storageViews.removeChildren();
137
138 this.storageViewStatusBarItemsContainer.removeChildren();
139 },
140
141 handleKeyEvent: function(event)
142 {
143 this.sidebarTree.handleKeyEvent(event);
144 },
145
146 addDatabase: function(database)
147 {
148 this._databases.push(database);
149
150 var databaseTreeElement = new WebInspector.DatabaseSidebarTreeElement(da tabase);
151 database._databasesTreeElement = databaseTreeElement;
152 this.databasesListTreeElement.appendChild(databaseTreeElement);
153 },
154
155 addDOMStorage: function(domStorage)
156 {
157 this._domStorage.push(domStorage);
158 var domStorageTreeElement = new WebInspector.DOMStorageSidebarTreeElemen t(domStorage, (domStorage.isLocalStorage ? "local-storage" : "session-storage")) ;
159 domStorage._domStorageTreeElement = domStorageTreeElement;
160 if (domStorage.isLocalStorage)
161 this.localStorageListTreeElement.appendChild(domStorageTreeElement);
162 else
163 this.sessionStorageListTreeElement.appendChild(domStorageTreeElement );
164 },
165
166 addCookies: function()
167 {
168 if (!this.cookieTreeElement) {
169 this.cookieTreeElement = new WebInspector.CookieSidebarTreeElement() ;
170 this.cookieListTreeElement.appendChild(this.cookieTreeElement);
171 }
172 },
173
174 selectDatabase: function(db)
175 {
176 var database;
177 for (var i = 0, len = this._databases.length; i < len; ++i) {
178 database = this._databases[i];
179 if ( db === database.database ) {
180 this.showDatabase(database);
181 database._databasesTreeElement.select();
182 return;
183 }
184 }
185 },
186
187 selectDOMStorage: function(s)
188 {
189 var isLocalStorage = (s === InspectorController.inspectedWindow().localS torage);
190 for (var i = 0, len = this._domStorage.length; i < len; ++i) {
191 var storage = this._domStorage[i];
192 if ( isLocalStorage === storage.isLocalStorage ) {
193 this.showDOMStorage(storage);
194 storage._domStorageTreeElement.select();
195 return;
196 }
197 }
198 },
199
200 showDatabase: function(database, tableName)
201 {
202 if (!database)
203 return;
204
205 if (this.visibleView)
206 this.visibleView.hide();
207
208 var view;
209 if (tableName) {
210 if (!("_tableViews" in database))
211 database._tableViews = {};
212 view = database._tableViews[tableName];
213 if (!view) {
214 view = new WebInspector.DatabaseTableView(database, tableName);
215 database._tableViews[tableName] = view;
216 }
217 } else {
218 view = database._queryView;
219 if (!view) {
220 view = new WebInspector.DatabaseQueryView(database);
221 database._queryView = view;
222 }
223 }
224
225 view.show(this.storageViews);
226
227 this.visibleView = view;
228
229 this.storageViewStatusBarItemsContainer.removeChildren();
230 var statusBarItems = view.statusBarItems || [];
231 for (var i = 0; i < statusBarItems.length; ++i)
232 this.storageViewStatusBarItemsContainer.appendChild(statusBarItems[i ]);
233 },
234
235 showDOMStorage: function(domStorage)
236 {
237 if (!domStorage)
238 return;
239
240 if (this.visibleView)
241 this.visibleView.hide();
242
243 var view;
244 view = domStorage._domStorageView;
245 if (!view) {
246 view = new WebInspector.DOMStorageItemsView(domStorage);
247 domStorage._domStorageView = view;
248 }
249
250 view.show(this.storageViews);
251
252 this.visibleView = view;
253
254 this.storageViewStatusBarItemsContainer.removeChildren();
255 var statusBarItems = view.statusBarItems;
256 for (var i = 0; i < statusBarItems.length; ++i)
257 this.storageViewStatusBarItemsContainer.appendChild(statusBarItems[i ]);
258 },
259
260 showCookies: function()
261 {
262 if (this.visibleView)
263 this.visibleView.hide();
264
265 var view = this._cookieView;
266 if (!view) {
267 view = new WebInspector.CookieItemsView();
268 this._cookieView = view;
269 }
270
271 view.show(this.storageViews);
272
273 this.visibleView = view;
274
275 this.storageViewStatusBarItemsContainer.removeChildren();
276 var statusBarItems = view.statusBarItems;
277 for (var i = 0; i < statusBarItems.length; ++i)
278 this.storageViewStatusBarItemsContainer.appendChild(statusBarItems[i ]);
279 },
280
281 closeVisibleView: function()
282 {
283 if (this.visibleView)
284 this.visibleView.hide();
285 delete this.visibleView;
286 },
287
288 updateDatabaseTables: function(database)
289 {
290 if (!database || !database._databasesTreeElement)
291 return;
292
293 database._databasesTreeElement.shouldRefreshChildren = true;
294
295 if (!("_tableViews" in database))
296 return;
297
298 var tableNamesHash = {};
299 var tableNames = database.tableNames;
300 var tableNamesLength = tableNames.length;
301 for (var i = 0; i < tableNamesLength; ++i)
302 tableNamesHash[tableNames[i]] = true;
303
304 for (var tableName in database._tableViews) {
305 if (!(tableName in tableNamesHash)) {
306 if (this.visibleView === database._tableViews[tableName])
307 this.closeVisibleView();
308 delete database._tableViews[tableName];
309 }
310 }
311 },
312
313 dataGridForResult: function(result)
314 {
315 if (!result.rows.length)
316 return null;
317
318 var columns = {};
319
320 var rows = result.rows;
321 for (var columnIdentifier in rows.item(0)) {
322 var column = {};
323 column.width = columnIdentifier.length;
324 column.title = columnIdentifier;
325
326 columns[columnIdentifier] = column;
327 }
328
329 var nodes = [];
330 var length = rows.length;
331 for (var i = 0; i < length; ++i) {
332 var data = {};
333
334 var row = rows.item(i);
335 for (var columnIdentifier in row) {
336 // FIXME: (Bug 19439) We should specially format SQL NULL here
337 // (which is represented by JavaScript null here, and turned
338 // into the string "null" by the String() function).
339 var text = String(row[columnIdentifier]);
340 data[columnIdentifier] = text;
341 if (text.length > columns[columnIdentifier].width)
342 columns[columnIdentifier].width = text.length;
343 }
344
345 var node = new WebInspector.DataGridNode(data, false);
346 node.selectable = false;
347 nodes.push(node);
348 }
349
350 var totalColumnWidths = 0;
351 for (var columnIdentifier in columns)
352 totalColumnWidths += columns[columnIdentifier].width;
353
354 // Calculate the percentage width for the columns.
355 const minimumPrecent = 5;
356 var recoupPercent = 0;
357 for (var columnIdentifier in columns) {
358 var width = columns[columnIdentifier].width;
359 width = Math.round((width / totalColumnWidths) * 100);
360 if (width < minimumPrecent) {
361 recoupPercent += (minimumPrecent - width);
362 width = minimumPrecent;
363 }
364
365 columns[columnIdentifier].width = width;
366 }
367
368 // Enforce the minimum percentage width.
369 while (recoupPercent > 0) {
370 for (var columnIdentifier in columns) {
371 if (columns[columnIdentifier].width > minimumPrecent) {
372 --columns[columnIdentifier].width;
373 --recoupPercent;
374 if (!recoupPercent)
375 break;
376 }
377 }
378 }
379
380 // Change the width property to a string suitable for a style width.
381 for (var columnIdentifier in columns)
382 columns[columnIdentifier].width += "%";
383
384 var dataGrid = new WebInspector.DataGrid(columns);
385 var length = nodes.length;
386 for (var i = 0; i < length; ++i)
387 dataGrid.appendChild(nodes[i]);
388
389 return dataGrid;
390 },
391
392 dataGridForDOMStorage: function(domStorage)
393 {
394 if (!domStorage.length)
395 return null;
396
397 var columns = {};
398 columns[0] = {};
399 columns[1] = {};
400 columns[0].title = WebInspector.UIString("Key");
401 columns[0].width = columns[0].title.length;
402 columns[1].title = WebInspector.UIString("Value");
403 columns[1].width = columns[1].title.length;
404
405 var nodes = [];
406
407 var length = domStorage.length;
408 for (var index = 0; index < domStorage.length; index++) {
409 var data = {};
410
411 var key = String(domStorage.key(index));
412 data[0] = key;
413 if (key.length > columns[0].width)
414 columns[0].width = key.length;
415
416 var value = String(domStorage.getItem(key));
417 data[1] = value;
418 if (value.length > columns[1].width)
419 columns[1].width = value.length;
420 var node = new WebInspector.DataGridNode(data, false);
421 node.selectable = true;
422 nodes.push(node);
423 }
424
425 var totalColumnWidths = columns[0].width + columns[1].width;
426 var width = Math.round((columns[0].width * 100) / totalColumnWidths);
427 const minimumPrecent = 10;
428 if (width < minimumPrecent)
429 width = minimumPrecent;
430 if (width > 100 - minimumPrecent)
431 width = 100 - minimumPrecent;
432 columns[0].width = width;
433 columns[1].width = 100 - width;
434 columns[0].width += "%";
435 columns[1].width += "%";
436
437 var dataGrid = new WebInspector.DOMStorageDataGrid(columns);
438 var length = nodes.length;
439 for (var i = 0; i < length; ++i)
440 dataGrid.appendChild(nodes[i]);
441 dataGrid.addCreationNode(false);
442 if (length > 0)
443 nodes[0].selected = true;
444 return dataGrid;
445 },
446
447 resize: function()
448 {
449 var visibleView = this.visibleView;
450 if (visibleView && "resize" in visibleView)
451 visibleView.resize();
452 },
453
454 _registerStorageEventListener: function()
455 {
456 var inspectedWindow = InspectorController.inspectedWindow();
457 if (!inspectedWindow || !inspectedWindow.document)
458 return;
459
460 this._storageEventListener = InspectorController.wrapCallback(this._stor ageEvent.bind(this));
461 inspectedWindow.addEventListener("storage", this._storageEventListener, true);
462 },
463
464 _unregisterStorageEventListener: function()
465 {
466 if (!this._storageEventListener)
467 return;
468
469 var inspectedWindow = InspectorController.inspectedWindow();
470 if (!inspectedWindow || !inspectedWindow.document)
471 return;
472
473 inspectedWindow.removeEventListener("storage", this._storageEventListene r, true);
474 delete this._storageEventListener;
475 },
476
477 _storageEvent: function(event)
478 {
479 if (!this._domStorage)
480 return;
481
482 var isLocalStorage = (event.storageArea === InspectorController.inspecte dWindow().localStorage);
483 var domStorageLength = this._domStorage.length;
484 for (var i = 0; i < domStorageLength; ++i) {
485 var domStorage = this._domStorage[i];
486 if (isLocalStorage === domStorage.isLocalStorage) {
487 var view = domStorage._domStorageView;
488 if (this.visibleView && view === this.visibleView)
489 domStorage._domStorageView.update();
490 }
491 }
492 },
493
494 _startSidebarDragging: function(event)
495 {
496 WebInspector.elementDragStart(this.sidebarResizeElement, this._sidebarDr agging.bind(this), this._endSidebarDragging.bind(this), event, "col-resize");
497 },
498
499 _sidebarDragging: function(event)
500 {
501 this._updateSidebarWidth(event.pageX);
502
503 event.preventDefault();
504 },
505
506 _endSidebarDragging: function(event)
507 {
508 WebInspector.elementDragEnd(event);
509 },
510
511 _updateSidebarWidth: function(width)
512 {
513 if (this.sidebarElement.offsetWidth <= 0) {
514 // The stylesheet hasn't loaded yet or the window is closed,
515 // so we can't calculate what is need. Return early.
516 return;
517 }
518
519 if (!("_currentSidebarWidth" in this))
520 this._currentSidebarWidth = this.sidebarElement.offsetWidth;
521
522 if (typeof width === "undefined")
523 width = this._currentSidebarWidth;
524
525 width = Number.constrain(width, Preferences.minSidebarWidth, window.inne rWidth / 2);
526
527 this._currentSidebarWidth = width;
528
529 this.sidebarElement.style.width = width + "px";
530 this.storageViews.style.left = width + "px";
531 this.storageViewStatusBarItemsContainer.style.left = width + "px";
532 this.sidebarResizeElement.style.left = (width - 3) + "px";
533
534 var visibleView = this.visibleView;
535 if (visibleView && "resize" in visibleView)
536 visibleView.resize();
537 }
538 }
539
540 WebInspector.StoragePanel.prototype.__proto__ = WebInspector.Panel.prototype;
541
542 WebInspector.DatabaseSidebarTreeElement = function(database)
543 {
544 this.database = database;
545
546 WebInspector.SidebarTreeElement.call(this, "database-sidebar-tree-item", "", "", database, true);
547
548 this.refreshTitles();
549 }
550
551 WebInspector.DatabaseSidebarTreeElement.prototype = {
552 onselect: function()
553 {
554 WebInspector.panels.storage.showDatabase(this.database);
555 },
556
557 oncollapse: function()
558 {
559 // Request a refresh after every collapse so the next
560 // expand will have an updated table list.
561 this.shouldRefreshChildren = true;
562 },
563
564 onpopulate: function()
565 {
566 this.removeChildren();
567
568 var tableNames = this.database.tableNames;
569 var tableNamesLength = tableNames.length;
570 for (var i = 0; i < tableNamesLength; ++i)
571 this.appendChild(new WebInspector.SidebarDatabaseTableTreeElement(th is.database, tableNames[i]));
572 },
573
574 get mainTitle()
575 {
576 return this.database.name;
577 },
578
579 set mainTitle(x)
580 {
581 // Do nothing.
582 },
583
584 get subtitle()
585 {
586 return this.database.displayDomain;
587 },
588
589 set subtitle(x)
590 {
591 // Do nothing.
592 }
593 }
594
595 WebInspector.DatabaseSidebarTreeElement.prototype.__proto__ = WebInspector.Sideb arTreeElement.prototype;
596
597 WebInspector.SidebarDatabaseTableTreeElement = function(database, tableName)
598 {
599 this.database = database;
600 this.tableName = tableName;
601
602 WebInspector.SidebarTreeElement.call(this, "database-table-sidebar-tree-item small", tableName, "", null, false);
603 }
604
605 WebInspector.SidebarDatabaseTableTreeElement.prototype = {
606 onselect: function()
607 {
608 WebInspector.panels.storage.showDatabase(this.database, this.tableName);
609 }
610 }
611
612 WebInspector.SidebarDatabaseTableTreeElement.prototype.__proto__ = WebInspector. SidebarTreeElement.prototype;
613
614 WebInspector.DOMStorageSidebarTreeElement = function(domStorage, className)
615 {
616
617 this.domStorage = domStorage;
618
619 WebInspector.SidebarTreeElement.call(this, "domstorage-sidebar-tree-item " + className, domStorage, "", null, false);
620
621 this.refreshTitles();
622 }
623
624 WebInspector.DOMStorageSidebarTreeElement.prototype = {
625 onselect: function()
626 {
627 WebInspector.panels.storage.showDOMStorage(this.domStorage);
628 },
629
630 get mainTitle()
631 {
632 return this.domStorage.domain;
633 },
634
635 set mainTitle(x)
636 {
637 // Do nothing.
638 },
639
640 get subtitle()
641 {
642 return ""; //this.database.displayDomain;
643 },
644
645 set subtitle(x)
646 {
647 // Do nothing.
648 }
649 }
650
651 WebInspector.DOMStorageSidebarTreeElement.prototype.__proto__ = WebInspector.Sid ebarTreeElement.prototype;
652
653 WebInspector.CookieSidebarTreeElement = function()
654 {
655 WebInspector.SidebarTreeElement.call(this, "cookie-sidebar-tree-item", null, "", null, false);
656
657 this.refreshTitles();
658 }
659
660 WebInspector.CookieSidebarTreeElement.prototype = {
661 onselect: function()
662 {
663 WebInspector.panels.storage.showCookies();
664 },
665
666 get mainTitle()
667 {
668 return WebInspector.UIString("Cookies");
669 },
670
671 set mainTitle(x)
672 {
673 // Do nothing.
674 },
675
676 get subtitle()
677 {
678 return "";
679 },
680
681 set subtitle(x)
682 {
683 // Do nothing.
684 }
685 }
686
687 WebInspector.CookieSidebarTreeElement.prototype.__proto__ = WebInspector.Sidebar TreeElement.prototype;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698