OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /** |
| 6 * This view displays a summary of the state of each QUIC session, and |
| 7 * has links to display them in the events tab. |
| 8 */ |
| 9 var QuicView = (function() { |
| 10 'use strict'; |
| 11 |
| 12 // We inherit from DivView. |
| 13 var superClass = DivView; |
| 14 |
| 15 /** |
| 16 * @constructor |
| 17 */ |
| 18 function QuicView() { |
| 19 assertFirstConstructorCall(QuicView); |
| 20 |
| 21 // Call superclass's constructor. |
| 22 superClass.call(this, QuicView.MAIN_BOX_ID); |
| 23 |
| 24 g_browser.addQuicInfoObserver(this, true); |
| 25 |
| 26 this.quicEnabledSpan_ = $(QuicView.ENABLED_SPAN_ID); |
| 27 this.quicForcePortSpan_ = $(QuicView.FORCE_PORT_SPAN_ID); |
| 28 |
| 29 this.quicSessionNoneSpan_ = $(QuicView.SESSION_NONE_SPAN_ID); |
| 30 this.quicSessionLinkSpan_ = $(QuicView.SESSION_LINK_SPAN_ID); |
| 31 this.quicSessionDiv_ = $(QuicView.SESSION_DIV_ID); |
| 32 } |
| 33 |
| 34 // ID for special HTML element in category_tabs.html |
| 35 QuicView.TAB_HANDLE_ID = 'tab-handle-quic'; |
| 36 |
| 37 // IDs for special HTML elements in quic_view.html |
| 38 QuicView.MAIN_BOX_ID = 'quic-view-tab-content'; |
| 39 QuicView.ENABLED_SPAN_ID = 'quic-view-enabled-span'; |
| 40 QuicView.FORCE_PORT_SPAN_ID = 'quic-view-force-port-span'; |
| 41 QuicView.SESSION_NONE_SPAN_ID = 'quic-view-session-none-span'; |
| 42 QuicView.SESSION_LINK_SPAN_ID = 'quic-view-session-link-span'; |
| 43 QuicView.SESSION_DIV_ID = 'quic-view-session-div'; |
| 44 |
| 45 cr.addSingletonGetter(QuicView); |
| 46 |
| 47 QuicView.prototype = { |
| 48 // Inherit the superclass's methods. |
| 49 __proto__: superClass.prototype, |
| 50 |
| 51 onLoadLogFinish: function(data) { |
| 52 return this.onQuicInfoChanged(data.quicInfo); |
| 53 }, |
| 54 |
| 55 /** |
| 56 * If there are any sessions, display a single table with |
| 57 * information on each QUIC session. Otherwise, displays "None". |
| 58 */ |
| 59 onQuicInfoChanged: function(quicInfo) { |
| 60 this.quicSessionDiv_.innerHTML = ''; |
| 61 |
| 62 var hasNoSession = |
| 63 (!quicInfo || !quicInfo.sessions || quicInfo.sessions.length == 0); |
| 64 setNodeDisplay(this.quicSessionNoneSpan_, hasNoSession); |
| 65 setNodeDisplay(this.quicSessionLinkSpan_, !hasNoSession); |
| 66 |
| 67 // Only want to be hide the tab if there's no data. In the case of having |
| 68 // data but no sessions, still show the tab. |
| 69 if (!quicInfo) |
| 70 return false; |
| 71 |
| 72 this.quicEnabledSpan_.textContent = quicInfo.quic_enabled; |
| 73 this.quicForcePortSpan_.textContent = |
| 74 quicInfo.origin_port_to_force_quic_on; |
| 75 |
| 76 if (!hasNoSession) { |
| 77 var tablePrinter = createSessionTablePrinter(quicInfo.sessions); |
| 78 tablePrinter.toHTML(this.quicSessionDiv_, 'styled-table'); |
| 79 } |
| 80 |
| 81 return true; |
| 82 }, |
| 83 }; |
| 84 |
| 85 /** |
| 86 * Creates a table printer to print out the state of list of QUIC sessions. |
| 87 */ |
| 88 function createSessionTablePrinter(quicSessions) { |
| 89 var tablePrinter = new TablePrinter(); |
| 90 |
| 91 tablePrinter.addHeaderCell('Host'); |
| 92 tablePrinter.addHeaderCell('Peer address'); |
| 93 tablePrinter.addHeaderCell('GUID'); |
| 94 tablePrinter.addHeaderCell('Active streams'); |
| 95 |
| 96 for (var i = 0; i < quicSessions.length; i++) { |
| 97 var session = quicSessions[i]; |
| 98 tablePrinter.addRow(); |
| 99 |
| 100 var host = session.host_port_pair; |
| 101 if (session.aliases) |
| 102 host += ' ' + session.aliases.join(' '); |
| 103 tablePrinter.addCell(host); |
| 104 |
| 105 tablePrinter.addCell(session.peer_address); |
| 106 tablePrinter.addCell(session.guid); |
| 107 tablePrinter.addCell(session.open_streams); |
| 108 } |
| 109 return tablePrinter; |
| 110 } |
| 111 |
| 112 return QuicView; |
| 113 })(); |
OLD | NEW |