- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / net_internals / spdy_view.js
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.
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 var SpdyView = (function() {
10   'use strict';
11
12   // We inherit from DivView.
13   var superClass = DivView;
14
15   /**
16    * @constructor
17    */
18   function SpdyView() {
19     assertFirstConstructorCall(SpdyView);
20
21     // Call superclass's constructor.
22     superClass.call(this, SpdyView.MAIN_BOX_ID);
23
24     g_browser.addSpdySessionInfoObserver(this, true);
25     g_browser.addSpdyStatusObserver(this, true);
26     g_browser.addSpdyAlternateProtocolMappingsObserver(this, true);
27   }
28
29   SpdyView.TAB_ID = 'tab-handle-spdy';
30   SpdyView.TAB_NAME = 'SPDY';
31   SpdyView.TAB_HASH = '#spdy';
32
33   // IDs for special HTML elements in spdy_view.html
34   SpdyView.MAIN_BOX_ID = 'spdy-view-tab-content';
35   SpdyView.STATUS_ID = 'spdy-view-status';
36   SpdyView.SESSION_INFO_ID = 'spdy-view-session-info';
37   SpdyView.ALTERNATE_PROTOCOL_MAPPINGS_ID =
38       'spdy-view-alternate-protocol-mappings';
39
40   cr.addSingletonGetter(SpdyView);
41
42   SpdyView.prototype = {
43     // Inherit the superclass's methods.
44     __proto__: superClass.prototype,
45
46     onLoadLogFinish: function(data) {
47       return this.onSpdySessionInfoChanged(data.spdySessionInfo) &&
48              this.onSpdyStatusChanged(data.spdyStatus) &&
49              this.onSpdyAlternateProtocolMappingsChanged(
50                  data.spdyAlternateProtocolMappings);
51     },
52
53     /**
54      * If |spdySessionInfo| contains any sessions, displays a single table with
55      * information on each SPDY session.  Otherwise, displays "None".
56      */
57     onSpdySessionInfoChanged: function(spdySessionInfo) {
58       if (!spdySessionInfo)
59         return false;
60       var input = new JsEvalContext({ spdySessionInfo: spdySessionInfo });
61       jstProcess(input, $(SpdyView.SESSION_INFO_ID));
62       return true;
63     },
64
65     /**
66      * Displays information on the global SPDY status.
67      */
68     onSpdyStatusChanged: function(spdyStatus) {
69       if (!spdyStatus)
70         return false;
71       var input = new JsEvalContext(spdyStatus);
72       jstProcess(input, $(SpdyView.STATUS_ID));
73       return true;
74     },
75
76     /**
77      * Displays information on the SPDY alternate protocol mappings.
78      */
79     onSpdyAlternateProtocolMappingsChanged: function(
80         spdyAlternateProtocolMappings) {
81       if (!spdyAlternateProtocolMappings)
82         return false;
83       var input = new JsEvalContext(
84           {spdyAlternateProtocolMappings: spdyAlternateProtocolMappings});
85       jstProcess(input, $(SpdyView.ALTERNATE_PROTOCOL_MAPPINGS_ID));
86       return true;
87     }
88   };
89
90   return SpdyView;
91 })();