Home | History | Annotate | Download | only in netlog_viewer
      1 // Copyright 2014 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 information related to SDCH.
      7  *
      8  * Shows loaded dictionaries, blacklisted domains and SDCH errors.
      9  */
     10 var SdchView = (function() {
     11   'use strict';
     12 
     13   // We inherit from DivView.
     14   var superClass = DivView;
     15 
     16   /**
     17    * @constructor
     18    */
     19   function SdchView() {
     20     assertFirstConstructorCall(SdchView);
     21 
     22     // Call superclass's constructor.
     23     superClass.call(this, SdchView.MAIN_BOX_ID);
     24 
     25     // Register to receive changes to the SDCH info.
     26     g_browser.addSdchInfoObserver(this, false);
     27   }
     28 
     29   SdchView.TAB_ID = 'tab-handle-sdch';
     30   SdchView.TAB_NAME = 'SDCH';
     31   SdchView.TAB_HASH = '#sdch';
     32 
     33   // IDs for special HTML elements in sdch_view.html
     34   SdchView.MAIN_BOX_ID = 'sdch-view-tab-content';
     35   SdchView.SDCH_ENABLED_SPAN_ID = 'sdch-view-sdch-enabled';
     36   SdchView.SECURE_SCHEME_SUPPORT_SPAN_ID = 'sdch-view-secure-scheme-support';
     37   SdchView.BLACKLIST_TBODY_ID = 'sdch-view-blacklist-tbody';
     38   SdchView.NUM_DICTIONARIES_LOADED_ID = 'sdch-view-num-dictionaries-loaded';
     39   SdchView.DICTIONARIES_TBODY_ID = 'sdch-view-dictionaries-tbody';
     40 
     41   cr.addSingletonGetter(SdchView);
     42 
     43   SdchView.prototype = {
     44     // Inherit the superclass's methods.
     45     __proto__: superClass.prototype,
     46 
     47     onLoadLogFinish: function(data) {
     48       return this.onSdchInfoChanged(data.sdchInfo);
     49     },
     50 
     51     onSdchInfoChanged: function(sdchInfo) {
     52       if (!sdchInfo || typeof(sdchInfo.sdch_enabled) === 'undefined')
     53         return false;
     54 
     55       $(SdchView.SDCH_ENABLED_SPAN_ID).textContent =
     56           !!sdchInfo.sdch_enabled;
     57 
     58       $(SdchView.NUM_DICTIONARIES_LOADED_ID).textContent =
     59           sdchInfo.dictionaries.length;
     60 
     61       var tbodyDictionaries = $(SdchView.DICTIONARIES_TBODY_ID);
     62       tbodyDictionaries.innerHTML = '';
     63 
     64       // Fill in the dictionaries table.
     65       for (var i = 0; i < sdchInfo.dictionaries.length; ++i) {
     66         var d = sdchInfo.dictionaries[i];
     67         var tr = addNode(tbodyDictionaries, 'tr');
     68 
     69         addNodeWithText(tr, 'td', d.domain);
     70         addNodeWithText(tr, 'td', d.path);
     71         addNodeWithText(tr, 'td',
     72             d.ports ? d.ports.join(', ') : '');
     73         addNodeWithText(tr, 'td', d.server_hash);
     74         addNodeWithText(tr, 'td', d.client_hash);
     75         addNodeWithText(tr, 'td', d.url);
     76       }
     77 
     78       var tbodyBlacklist = $(SdchView.BLACKLIST_TBODY_ID);
     79       tbodyBlacklist.innerHTML = '';
     80 
     81       // Fill in the blacklisted table.
     82       for (var i = 0; i < sdchInfo.blacklisted.length; ++i) {
     83         var b = sdchInfo.blacklisted[i];
     84         var tr = addNode(tbodyBlacklist, 'tr');
     85 
     86         addNodeWithText(tr, 'td', d.domain);
     87         addNodeWithText(tr, 'td', d.sdchProblemCodeToString(reason));
     88         addNodeWithText(tr, 'td', d.tries);
     89       }
     90 
     91       return true;
     92     },
     93   };
     94 
     95   return SdchView;
     96 })();
     97 
     98