summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/resources/net_internals/spdy_view.js
blob: b997122eaa5c7c9e2e7ebf3e97e413135ba2d3a3 (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
// 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);
  }

  SpdyView.TAB_ID = 'tab-handle-spdy';
  SpdyView.TAB_NAME = 'SPDY';
  SpdyView.TAB_HASH = '#spdy';

  // IDs for special HTML elements in spdy_view.html
  SpdyView.MAIN_BOX_ID = 'spdy-view-tab-content';
  SpdyView.STATUS_ID = 'spdy-view-status';
  SpdyView.SESSION_INFO_ID = 'spdy-view-session-info';
  SpdyView.ALTERNATE_PROTOCOL_MAPPINGS_ID =
      'spdy-view-alternate-protocol-mappings';

  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| contains any sessions, displays a single table with
     * information on each SPDY session.  Otherwise, displays "None".
     */
    onSpdySessionInfoChanged: function(spdySessionInfo) {
      if (!spdySessionInfo)
        return false;
      var input = new JsEvalContext({ spdySessionInfo: spdySessionInfo });
      jstProcess(input, $(SpdyView.SESSION_INFO_ID));
      return true;
    },

    /**
     * Displays information on the global SPDY status.
     */
    onSpdyStatusChanged: function(spdyStatus) {
      if (!spdyStatus)
        return false;
      var input = new JsEvalContext(spdyStatus);
      jstProcess(input, $(SpdyView.STATUS_ID));
      return true;
    },

    /**
     * Displays information on the SPDY alternate protocol mappings.
     */
    onSpdyAlternateProtocolMappingsChanged: function(
        spdyAlternateProtocolMappings) {
      if (!spdyAlternateProtocolMappings)
        return false;
      var input = new JsEvalContext(
          {spdyAlternateProtocolMappings: spdyAlternateProtocolMappings});
      jstProcess(input, $(SpdyView.ALTERNATE_PROTOCOL_MAPPINGS_ID));
      return true;
    }
  };

  return SpdyView;
})();