summaryrefslogtreecommitdiffstats
path: root/chrome/browser/resources/net_internals/spdy_view.js
blob: cf5ddbf6d77ae7ca4a497903d1a2adfcd2df8bd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
 * This view displays a summary of the state of each SPDY sessions, and
 * has links to display them in the events tab.
 */
var SpdyView = (function() {
  'use strict';

  // We inherit from DivView.
  var superClass = DivView;

  /**
   * @constructor
   */
  function SpdyView() {
    assertFirstConstructorCall(SpdyView);

    // Call superclass's constructor.
    superClass.call(this, SpdyView.MAIN_BOX_ID);

    g_browser.addSpdySessionInfoObserver(this, true);
    g_browser.addSpdyStatusObserver(this, true);
    g_browser.addSpdyAlternateProtocolMappingsObserver(this, true);

    this.spdyEnabledSpan_ = $(SpdyView.ENABLED_SPAN_ID);
    this.spdyUseAlternateProtocolSpan_ =
        $(SpdyView.USE_ALTERNATE_PROTOCOL_SPAN_ID);
    this.spdyForceAlwaysSpan_ = $(SpdyView.FORCE_ALWAYS_SPAN_ID);
    this.spdyForceOverSslSpan_ = $(SpdyView.FORCE_OVER_SSL_SPAN_ID);
    this.spdyNextProtocolsSpan_ = $(SpdyView.NEXT_PROTOCOLS_SPAN_ID);

    this.spdyAlternateProtocolMappingsDiv_ =
        $(SpdyView.ALTERNATE_PROTOCOL_MAPPINGS_DIV_ID);
    this.spdySessionNoneSpan_ = $(SpdyView.SESSION_NONE_SPAN_ID);
    this.spdySessionLinkSpan_ = $(SpdyView.SESSION_LINK_SPAN_ID);
    this.spdySessionDiv_ = $(SpdyView.SESSION_DIV_ID);
  }

  // ID for special HTML element in category_tabs.html
  SpdyView.TAB_HANDLE_ID = 'tab-handle-spdy';

  // IDs for special HTML elements in spdy_view.html
  SpdyView.MAIN_BOX_ID = 'spdy-view-tab-content';
  SpdyView.ENABLED_SPAN_ID = 'spdy-view-enabled-span';
  SpdyView.USE_ALTERNATE_PROTOCOL_SPAN_ID =
      'spdy-view-alternate-protocol-span';
  SpdyView.FORCE_ALWAYS_SPAN_ID = 'spdy-view-force-always-span';
  SpdyView.FORCE_OVER_SSL_SPAN_ID = 'spdy-view-force-over-ssl-span';
  SpdyView.NEXT_PROTOCOLS_SPAN_ID = 'spdy-view-next-protocols-span';
  SpdyView.ALTERNATE_PROTOCOL_MAPPINGS_DIV_ID =
      'spdy-view-alternate-protocol-mappings-div';
  SpdyView.SESSION_NONE_SPAN_ID = 'spdy-view-session-none-span';
  SpdyView.SESSION_LINK_SPAN_ID = 'spdy-view-session-link-span';
  SpdyView.SESSION_DIV_ID = 'spdy-view-session-div';

  cr.addSingletonGetter(SpdyView);

  SpdyView.prototype = {
    // Inherit the superclass's methods.
    __proto__: superClass.prototype,

    onLoadLogFinish: function(data) {
      return this.onSpdySessionInfoChanged(data.spdySessionInfo) &&
             this.onSpdyStatusChanged(data.spdyStatus) &&
             this.onSpdyAlternateProtocolMappingsChanged(
                 data.spdyAlternateProtocolMappings);
    },

    /**
     * If |spdySessionInfo| there are any sessions, display a single table with
     * information on each SPDY session.  Otherwise, displays "None".
     */
    onSpdySessionInfoChanged: function(spdySessionInfo) {
      this.spdySessionDiv_.innerHTML = '';

      var hasNoSession =
          (spdySessionInfo == null || spdySessionInfo.length == 0);
      setNodeDisplay(this.spdySessionNoneSpan_, hasNoSession);
      setNodeDisplay(this.spdySessionLinkSpan_, !hasNoSession);

      // Only want to be hide the tab if there's no data.  In the case of having
      // data but no sessions, still show the tab.
      if (!spdySessionInfo)
        return false;

      if (!hasNoSession) {
        var tablePrinter = createSessionTablePrinter(spdySessionInfo);
        tablePrinter.toHTML(this.spdySessionDiv_, 'styled-table');
      }

      return true;
    },

    /**
     * Displays information on the global SPDY status.
     */
    onSpdyStatusChanged: function(spdyStatus) {
      this.spdyEnabledSpan_.textContent = spdyStatus.spdy_enabled;
      this.spdyUseAlternateProtocolSpan_.textContent =
          spdyStatus.use_alternate_protocols;
      this.spdyForceAlwaysSpan_.textContent = spdyStatus.force_spdy_always;
      this.spdyForceOverSslSpan_.textContent = spdyStatus.force_spdy_over_ssl;
      this.spdyNextProtocolsSpan_.textContent = spdyStatus.next_protos;

      return true;
    },

    /**
     * If |spdyAlternateProtocolMappings| is not empty, displays a single table
     * with information on each alternate protocol enabled server.  Otherwise,
     * displays "None".
     */
    onSpdyAlternateProtocolMappingsChanged:
        function(spdyAlternateProtocolMappings) {

      this.spdyAlternateProtocolMappingsDiv_.innerHTML = '';

      if (spdyAlternateProtocolMappings != null &&
          spdyAlternateProtocolMappings.length > 0) {
        var tabPrinter = createAlternateProtocolMappingsTablePrinter(
                spdyAlternateProtocolMappings);
        tabPrinter.toHTML(
            this.spdyAlternateProtocolMappingsDiv_, 'styled-table');
      } else {
        this.spdyAlternateProtocolMappingsDiv_.innerHTML = 'None';
      }
      return true;
    }
  };

  /**
   * Creates a table printer to print out the state of list of SPDY sessions.
   */
  function createSessionTablePrinter(spdySessions) {
    var tablePrinter = new TablePrinter();
    tablePrinter.addHeaderCell('Host');
    tablePrinter.addHeaderCell('Proxy');
    tablePrinter.addHeaderCell('ID');
    tablePrinter.addHeaderCell('Protocol Negotiatied');
    tablePrinter.addHeaderCell('Active streams');
    tablePrinter.addHeaderCell('Unclaimed pushed');
    tablePrinter.addHeaderCell('Max');
    tablePrinter.addHeaderCell('Initiated');
    tablePrinter.addHeaderCell('Pushed');
    tablePrinter.addHeaderCell('Pushed and claimed');
    tablePrinter.addHeaderCell('Abandoned');
    tablePrinter.addHeaderCell('Received frames');
    tablePrinter.addHeaderCell('Secure');
    tablePrinter.addHeaderCell('Sent settings');
    tablePrinter.addHeaderCell('Received settings');
    tablePrinter.addHeaderCell('Error');

    for (var i = 0; i < spdySessions.length; i++) {
      var session = spdySessions[i];
      tablePrinter.addRow();

      tablePrinter.addCell(session.host_port_pair);
      tablePrinter.addCell(session.proxy);

      var idCell = tablePrinter.addCell(session.source_id);
      idCell.link = '#events&q=id:' + session.source_id;

      tablePrinter.addCell(session.protocol_negotiated);
      tablePrinter.addCell(session.active_streams);
      tablePrinter.addCell(session.unclaimed_pushed_streams);
      tablePrinter.addCell(session.max_concurrent_streams);
      tablePrinter.addCell(session.streams_initiated_count);
      tablePrinter.addCell(session.streams_pushed_count);
      tablePrinter.addCell(session.streams_pushed_and_claimed_count);
      tablePrinter.addCell(session.streams_abandoned_count);
      tablePrinter.addCell(session.frames_received);
      tablePrinter.addCell(session.is_secure);
      tablePrinter.addCell(session.sent_settings);
      tablePrinter.addCell(session.received_settings);
      tablePrinter.addCell(session.error);
    }
    return tablePrinter;
  }

  /**
   * Creates a table printer to print out the list of alternate protocol
   * mappings.
   */
  function createAlternateProtocolMappingsTablePrinter(
      spdyAlternateProtocolMappings) {
    var tablePrinter = new TablePrinter();
    tablePrinter.addHeaderCell('Host');
    tablePrinter.addHeaderCell('Alternate Protocol');

    for (var i = 0; i < spdyAlternateProtocolMappings.length; i++) {
      var entry = spdyAlternateProtocolMappings[i];
      tablePrinter.addRow();

      tablePrinter.addCell(entry.host_port_pair);
      tablePrinter.addCell(entry.alternate_protocol);
    }
    return tablePrinter;
  }

  return SpdyView;
})();