BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / resources / net_internals / capture_status_view.js
blob20e5a9b10f24b92a122d032bc343e412ef8cd2e8
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  * The status view at the top of the page when in capturing mode.
7  */
8 var CaptureStatusView = (function() {
9   'use strict';
11   // We inherit from DivView.
12   var superClass = DivView;
14   function CaptureStatusView() {
15     superClass.call(this, CaptureStatusView.MAIN_BOX_ID);
17     this.getDropdown_().onchange = this.onSelectAction_.bind(this);
18     this.getDropdown_().selectedIndex = -1;
20     this.capturedEventsCountBox_ =
21         $(CaptureStatusView.CAPTURED_EVENTS_COUNT_ID);
22     this.updateEventCounts_();
24     EventsTracker.getInstance().addLogEntryObserver(this);
25   }
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';
33   CaptureStatusView.prototype = {
34     // Inherit the superclass's methods.
35     __proto__: superClass.prototype,
37     /**
38      * Called whenever new log entries have been received.
39      */
40     onReceivedLogEntries: function(logEntries) {
41       this.updateEventCounts_();
42     },
44     /**
45      * Called whenever all log events are deleted.
46      */
47     onAllLogEntriesDeleted: function() {
48       this.updateEventCounts_();
49     },
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     },
59     getDropdown_: function() {
60       return $(CaptureStatusView.ACTIONS_DROPDOWN_ID);
61     },
63     onSelectAction_: function() {
64       var dropdown = this.getDropdown_();
65       var action = dropdown.value;
66       dropdown.selectedIndex = -1;
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   };
85   return CaptureStatusView;
86 })();