Home | History | Annotate | Download | only in net_internals
      1 // Copyright (c) 2010 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 SPDY sessions, and
      7  * has links to display them in the events tab.
      8  *
      9  * @constructor
     10  */
     11 function SpdyView(mainBoxId, spdyEnabledSpanId,
     12                   spdyUseAlternateProtocolSpanId,
     13                   spdyForceAlwaysSpanId, spdyForceOverSslSpanId,
     14                   spdyNextProtocolsSpanId, spdyAlternateProtocolMappingsDivId,
     15                   spdySessionNoneSpanId, spdySessionLinkSpanId,
     16                   spdySessionDivId) {
     17   DivView.call(this, mainBoxId);
     18   g_browser.addSpdySessionInfoObserver(this);
     19   g_browser.addSpdyStatusObserver(this);
     20   g_browser.addSpdyAlternateProtocolMappingsObserver(this);
     21 
     22   this.spdyEnabledSpan_ = document.getElementById(spdyEnabledSpanId);
     23   this.spdyUseAlternateProtocolSpan_ =
     24       document.getElementById(spdyUseAlternateProtocolSpanId);
     25   this.spdyForceAlwaysSpan_ = document.getElementById(spdyForceAlwaysSpanId);
     26   this.spdyForceOverSslSpan_ = document.getElementById(spdyForceOverSslSpanId);
     27   this.spdyNextProtocolsSpan_ =
     28       document.getElementById(spdyNextProtocolsSpanId);
     29 
     30   this.spdyAlternateProtocolMappingsDiv_ =
     31       document.getElementById(spdyAlternateProtocolMappingsDivId);
     32   this.spdySessionNoneSpan_ = document.getElementById(spdySessionNoneSpanId);
     33   this.spdySessionLinkSpan_ = document.getElementById(spdySessionLinkSpanId);
     34   this.spdySessionDiv_ = document.getElementById(spdySessionDivId);
     35 }
     36 
     37 inherits(SpdyView, DivView);
     38 
     39 /**
     40  * If |spdySessionInfo| is not null, displays a single table with information
     41  * on each SPDY session.  Otherwise, displays "None".
     42  */
     43 SpdyView.prototype.onSpdySessionInfoChanged = function(spdySessionInfo) {
     44   this.spdySessionDiv_.innerHTML = '';
     45 
     46   var hasNoSession = (spdySessionInfo == null || spdySessionInfo.length == 0);
     47   setNodeDisplay(this.spdySessionNoneSpan_, hasNoSession);
     48   setNodeDisplay(this.spdySessionLinkSpan_, !hasNoSession);
     49 
     50   if (hasNoSession)
     51     return;
     52 
     53   var tablePrinter = SpdyView.createSessionTablePrinter(spdySessionInfo);
     54   tablePrinter.toHTML(this.spdySessionDiv_, 'styledTable');
     55 
     56 };
     57 
     58 /**
     59  * Displays information on the global SPDY status.
     60  */
     61 SpdyView.prototype.onSpdyStatusChanged = function(spdyStatus) {
     62   this.spdyEnabledSpan_.innerText = spdyStatus.spdy_enabled;
     63   this.spdyUseAlternateProtocolSpan_.innerText =
     64       spdyStatus.use_alternate_protocols;
     65   this.spdyForceAlwaysSpan_.innerText = spdyStatus.force_spdy_always;
     66   this.spdyForceOverSslSpan_.innerText = spdyStatus.force_spdy_over_ssl;
     67   this.spdyNextProtocolsSpan_.innerText = spdyStatus.next_protos;
     68 }
     69 
     70 /**
     71  * If |spdyAlternateProtocolMappings| is not empty, displays a single table
     72  * with information on each alternate protocol enabled server.  Otherwise,
     73  * displays "None".
     74  */
     75 SpdyView.prototype.onSpdyAlternateProtocolMappingsChanged =
     76     function(spdyAlternateProtocolMappings) {
     77 
     78   this.spdyAlternateProtocolMappingsDiv_.innerHTML = '';
     79 
     80   if (spdyAlternateProtocolMappings != null &&
     81       spdyAlternateProtocolMappings.length > 0) {
     82     var tabPrinter = SpdyView.createAlternateProtocolMappingsTablePrinter(
     83             spdyAlternateProtocolMappings);
     84     tabPrinter.toHTML(this.spdyAlternateProtocolMappingsDiv_, 'styledTable');
     85   } else {
     86     this.spdyAlternateProtocolMappingsDiv_.innerHTML = 'None';
     87   }
     88 };
     89 
     90 /**
     91  * Creates a table printer to print out the state of list of SPDY sessions.
     92  */
     93 SpdyView.createSessionTablePrinter = function(spdySessions) {
     94   var tablePrinter = new TablePrinter();
     95   tablePrinter.addHeaderCell('Host');
     96   tablePrinter.addHeaderCell('Proxy');
     97   tablePrinter.addHeaderCell('ID');
     98   tablePrinter.addHeaderCell('Active streams');
     99   tablePrinter.addHeaderCell('Unclaimed pushed');
    100   tablePrinter.addHeaderCell('Max');
    101   tablePrinter.addHeaderCell('Initiated');
    102   tablePrinter.addHeaderCell('Pushed');
    103   tablePrinter.addHeaderCell('Pushed and claimed');
    104   tablePrinter.addHeaderCell('Abandoned');
    105   tablePrinter.addHeaderCell('Received frames');
    106   tablePrinter.addHeaderCell('Secure');
    107   tablePrinter.addHeaderCell('Sent settings');
    108   tablePrinter.addHeaderCell('Received settings');
    109   tablePrinter.addHeaderCell('Error');
    110 
    111   for (var i = 0; i < spdySessions.length; i++) {
    112     var session = spdySessions[i];
    113     tablePrinter.addRow();
    114 
    115     tablePrinter.addCell(session.host_port_pair);
    116     tablePrinter.addCell(session.proxy);
    117 
    118     var idCell = tablePrinter.addCell(session.source_id);
    119     idCell.link = '#events&q=id:' + session.source_id;
    120 
    121     tablePrinter.addCell(session.active_streams);
    122     tablePrinter.addCell(session.unclaimed_pushed_streams);
    123     tablePrinter.addCell(session.max_concurrent_streams);
    124     tablePrinter.addCell(session.streams_initiated_count);
    125     tablePrinter.addCell(session.streams_pushed_count);
    126     tablePrinter.addCell(session.streams_pushed_and_claimed_count);
    127     tablePrinter.addCell(session.streams_abandoned_count);
    128     tablePrinter.addCell(session.frames_received);
    129     tablePrinter.addCell(session.is_secure);
    130     tablePrinter.addCell(session.sent_settings);
    131     tablePrinter.addCell(session.received_settings);
    132     tablePrinter.addCell(session.error);
    133   }
    134   return tablePrinter;
    135 };
    136 
    137 
    138 /**
    139  * Creates a table printer to print out the list of alternate protocol
    140  * mappings.
    141  */
    142 SpdyView.createAlternateProtocolMappingsTablePrinter =
    143     function(spdyAlternateProtocolMappings) {
    144   var tablePrinter = new TablePrinter();
    145   tablePrinter.addHeaderCell('Host');
    146   tablePrinter.addHeaderCell('Alternate Protocol');
    147 
    148   for (var i = 0; i < spdyAlternateProtocolMappings.length; i++) {
    149     var entry = spdyAlternateProtocolMappings[i];
    150     tablePrinter.addRow();
    151 
    152     tablePrinter.addCell(entry.host_port_pair);
    153     tablePrinter.addCell(entry.alternate_protocol);
    154   }
    155   return tablePrinter;
    156 };
    157 
    158