Home | History | Annotate | Download | only in net_internals
      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  * The status view at the top of the page when in capturing mode.
      7  */
      8 var CaptureStatusView = (function() {
      9   'use strict';
     10 
     11   // We inherit from DivView.
     12   var superClass = DivView;
     13 
     14   function CaptureStatusView() {
     15     superClass.call(this, CaptureStatusView.MAIN_BOX_ID);
     16 
     17     this.getDropdown_().onchange = this.onSelectAction_.bind(this);
     18     this.getDropdown_().selectedIndex = -1;
     19 
     20     this.capturedEventsCountBox_ =
     21         $(CaptureStatusView.CAPTURED_EVENTS_COUNT_ID);
     22     this.updateEventCounts_();
     23 
     24     EventsTracker.getInstance().addLogEntryObserver(this);
     25   }
     26 
     27   // IDs for special HTML elements in status_view.html
     28   CaptureStatusView.MAIN_BOX_ID = 'capture-status-view';
     29   CaptureStatusView.ACTIONS_DROPDOWN_ID = 'capture-status-view-actions';
     30   CaptureStatusView.CAPTURED_EVENTS_COUNT_ID =
     31       'capture-status-view-captured-events-count';
     32 
     33   CaptureStatusView.prototype = {
     34     // Inherit the superclass's methods.
     35     __proto__: superClass.prototype,
     36 
     37     /**
     38      * Called whenever new log entries have been received.
     39      */
     40     onReceivedLogEntries: function(logEntries) {
     41       this.updateEventCounts_();
     42     },
     43 
     44     /**
     45      * Called whenever all log events are deleted.
     46      */
     47     onAllLogEntriesDeleted: function() {
     48       this.updateEventCounts_();
     49     },
     50 
     51     /**
     52      * Updates the counters showing how many events have been captured.
     53      */
     54     updateEventCounts_: function() {
     55       this.capturedEventsCountBox_.textContent =
     56           EventsTracker.getInstance().getNumCapturedEvents();
     57     },
     58 
     59     getDropdown_: function() {
     60       return $(CaptureStatusView.ACTIONS_DROPDOWN_ID);
     61     },
     62 
     63     onSelectAction_: function() {
     64       var dropdown = this.getDropdown_();
     65       var action = dropdown.value;
     66       dropdown.selectedIndex = -1;
     67 
     68       if (action == 'stop') {
     69         $(CaptureView.STOP_BUTTON_ID).click();
     70       } else if (action == 'reset') {
     71         $(CaptureView.RESET_BUTTON_ID).click();
     72       } else if (action == 'clear-cache') {
     73         g_browser.sendClearAllCache();
     74       } else if (action == 'flush-sockets') {
     75         g_browser.sendFlushSocketPools();
     76       } else if (action == 'switch-time-format') {
     77         var tracker = SourceTracker.getInstance();
     78         tracker.setUseRelativeTimes(!tracker.getUseRelativeTimes());
     79       } else {
     80         throw Error('Unrecognized action: ' + action);
     81       }
     82     },
     83   };
     84 
     85   return CaptureStatusView;
     86 })();
     87