Updated drag and drop thumbnails.
[chromium-blink-merge.git] / chrome / browser / resources / net_internals / spdy_view.js
blob399af7d9735cc2bfd98503a6145e147486cd1196
1 // Copyright (c) 2012 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.
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 var SpdyView = (function() {
10 'use strict';
12 // We inherit from DivView.
13 var superClass = DivView;
15 /**
16 * @constructor
18 function SpdyView() {
19 assertFirstConstructorCall(SpdyView);
21 // Call superclass's constructor.
22 superClass.call(this, SpdyView.MAIN_BOX_ID);
24 g_browser.addSpdySessionInfoObserver(this, true);
25 g_browser.addSpdyStatusObserver(this, true);
26 g_browser.addSpdyAlternateProtocolMappingsObserver(this, true);
28 this.spdyEnabledSpan_ = $(SpdyView.ENABLED_SPAN_ID);
29 this.spdyUseAlternateProtocolSpan_ =
30 $(SpdyView.USE_ALTERNATE_PROTOCOL_SPAN_ID);
31 this.spdyForceAlwaysSpan_ = $(SpdyView.FORCE_ALWAYS_SPAN_ID);
32 this.spdyForceOverSslSpan_ = $(SpdyView.FORCE_OVER_SSL_SPAN_ID);
33 this.spdyNextProtocolsSpan_ = $(SpdyView.NEXT_PROTOCOLS_SPAN_ID);
35 this.spdyAlternateProtocolMappingsDiv_ =
36 $(SpdyView.ALTERNATE_PROTOCOL_MAPPINGS_DIV_ID);
37 this.spdySessionNoneSpan_ = $(SpdyView.SESSION_NONE_SPAN_ID);
38 this.spdySessionLinkSpan_ = $(SpdyView.SESSION_LINK_SPAN_ID);
39 this.spdySessionDiv_ = $(SpdyView.SESSION_DIV_ID);
42 // ID for special HTML element in category_tabs.html
43 SpdyView.TAB_HANDLE_ID = 'tab-handle-spdy';
45 // IDs for special HTML elements in spdy_view.html
46 SpdyView.MAIN_BOX_ID = 'spdy-view-tab-content';
47 SpdyView.ENABLED_SPAN_ID = 'spdy-view-enabled-span';
48 SpdyView.USE_ALTERNATE_PROTOCOL_SPAN_ID =
49 'spdy-view-alternate-protocol-span';
50 SpdyView.FORCE_ALWAYS_SPAN_ID = 'spdy-view-force-always-span';
51 SpdyView.FORCE_OVER_SSL_SPAN_ID = 'spdy-view-force-over-ssl-span';
52 SpdyView.NEXT_PROTOCOLS_SPAN_ID = 'spdy-view-next-protocols-span';
53 SpdyView.ALTERNATE_PROTOCOL_MAPPINGS_DIV_ID =
54 'spdy-view-alternate-protocol-mappings-div';
55 SpdyView.SESSION_NONE_SPAN_ID = 'spdy-view-session-none-span';
56 SpdyView.SESSION_LINK_SPAN_ID = 'spdy-view-session-link-span';
57 SpdyView.SESSION_DIV_ID = 'spdy-view-session-div';
59 cr.addSingletonGetter(SpdyView);
61 SpdyView.prototype = {
62 // Inherit the superclass's methods.
63 __proto__: superClass.prototype,
65 onLoadLogFinish: function(data) {
66 return this.onSpdySessionInfoChanged(data.spdySessionInfo) &&
67 this.onSpdyStatusChanged(data.spdyStatus) &&
68 this.onSpdyAlternateProtocolMappingsChanged(
69 data.spdyAlternateProtocolMappings);
72 /**
73 * If |spdySessionInfo| there are any sessions, display a single table with
74 * information on each SPDY session. Otherwise, displays "None".
76 onSpdySessionInfoChanged: function(spdySessionInfo) {
77 this.spdySessionDiv_.innerHTML = '';
79 var hasNoSession =
80 (spdySessionInfo == null || spdySessionInfo.length == 0);
81 setNodeDisplay(this.spdySessionNoneSpan_, hasNoSession);
82 setNodeDisplay(this.spdySessionLinkSpan_, !hasNoSession);
84 // Only want to be hide the tab if there's no data. In the case of having
85 // data but no sessions, still show the tab.
86 if (!spdySessionInfo)
87 return false;
89 if (!hasNoSession) {
90 var tablePrinter = createSessionTablePrinter(spdySessionInfo);
91 tablePrinter.toHTML(this.spdySessionDiv_, 'styled-table');
94 return true;
97 /**
98 * Displays information on the global SPDY status.
100 onSpdyStatusChanged: function(spdyStatus) {
101 this.spdyEnabledSpan_.textContent = spdyStatus.spdy_enabled;
102 this.spdyUseAlternateProtocolSpan_.textContent =
103 spdyStatus.use_alternate_protocols;
104 this.spdyForceAlwaysSpan_.textContent = spdyStatus.force_spdy_always;
105 this.spdyForceOverSslSpan_.textContent = spdyStatus.force_spdy_over_ssl;
106 this.spdyNextProtocolsSpan_.textContent = spdyStatus.next_protos;
108 return true;
112 * If |spdyAlternateProtocolMappings| is not empty, displays a single table
113 * with information on each alternate protocol enabled server. Otherwise,
114 * displays "None".
116 onSpdyAlternateProtocolMappingsChanged:
117 function(spdyAlternateProtocolMappings) {
119 this.spdyAlternateProtocolMappingsDiv_.innerHTML = '';
121 if (spdyAlternateProtocolMappings != null &&
122 spdyAlternateProtocolMappings.length > 0) {
123 var tabPrinter = createAlternateProtocolMappingsTablePrinter(
124 spdyAlternateProtocolMappings);
125 tabPrinter.toHTML(
126 this.spdyAlternateProtocolMappingsDiv_, 'styled-table');
127 } else {
128 this.spdyAlternateProtocolMappingsDiv_.innerHTML = 'None';
130 return true;
135 * Creates a table printer to print out the state of list of SPDY sessions.
137 function createSessionTablePrinter(spdySessions) {
138 var tablePrinter = new TablePrinter();
139 tablePrinter.addHeaderCell('Host');
140 tablePrinter.addHeaderCell('Proxy');
141 tablePrinter.addHeaderCell('ID');
142 tablePrinter.addHeaderCell('Protocol Negotiatied');
143 tablePrinter.addHeaderCell('Active streams');
144 tablePrinter.addHeaderCell('Unclaimed pushed');
145 tablePrinter.addHeaderCell('Max');
146 tablePrinter.addHeaderCell('Initiated');
147 tablePrinter.addHeaderCell('Pushed');
148 tablePrinter.addHeaderCell('Pushed and claimed');
149 tablePrinter.addHeaderCell('Abandoned');
150 tablePrinter.addHeaderCell('Received frames');
151 tablePrinter.addHeaderCell('Secure');
152 tablePrinter.addHeaderCell('Sent settings');
153 tablePrinter.addHeaderCell('Received settings');
154 tablePrinter.addHeaderCell('Error');
156 for (var i = 0; i < spdySessions.length; i++) {
157 var session = spdySessions[i];
158 tablePrinter.addRow();
160 var host = session.host_port_pair;
161 if (session.aliases)
162 host += ' ' + session.aliases.join(' ');
163 tablePrinter.addCell(host);
164 tablePrinter.addCell(session.proxy);
166 var idCell = tablePrinter.addCell(session.source_id);
167 idCell.link = '#events&q=id:' + session.source_id;
169 tablePrinter.addCell(session.protocol_negotiated);
170 tablePrinter.addCell(session.active_streams);
171 tablePrinter.addCell(session.unclaimed_pushed_streams);
172 tablePrinter.addCell(session.max_concurrent_streams);
173 tablePrinter.addCell(session.streams_initiated_count);
174 tablePrinter.addCell(session.streams_pushed_count);
175 tablePrinter.addCell(session.streams_pushed_and_claimed_count);
176 tablePrinter.addCell(session.streams_abandoned_count);
177 tablePrinter.addCell(session.frames_received);
178 tablePrinter.addCell(session.is_secure);
179 tablePrinter.addCell(session.sent_settings);
180 tablePrinter.addCell(session.received_settings);
181 tablePrinter.addCell(session.error);
183 return tablePrinter;
187 * Creates a table printer to print out the list of alternate protocol
188 * mappings.
190 function createAlternateProtocolMappingsTablePrinter(
191 spdyAlternateProtocolMappings) {
192 var tablePrinter = new TablePrinter();
193 tablePrinter.addHeaderCell('Host');
194 tablePrinter.addHeaderCell('Alternate Protocol');
196 for (var i = 0; i < spdyAlternateProtocolMappings.length; i++) {
197 var entry = spdyAlternateProtocolMappings[i];
198 tablePrinter.addRow();
200 tablePrinter.addCell(entry.host_port_pair);
201 tablePrinter.addCell(entry.alternate_protocol);
203 return tablePrinter;
206 return SpdyView;
207 })();