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.
6 * The status view at the top of the page when in capturing mode.
8 var CaptureStatusView = (function() {
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);
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,
38 * Called whenever new log entries have been received.
40 onReceivedLogEntries: function(logEntries) {
41 this.updateEventCounts_();
45 * Called whenever all log events are deleted.
47 onAllLogEntriesDeleted: function() {
48 this.updateEventCounts_();
52 * Updates the counters showing how many events have been captured.
54 updateEventCounts_: function() {
55 this.capturedEventsCountBox_.textContent =
56 EventsTracker.getInstance().getNumCapturedEvents();
59 getDropdown_: function() {
60 return $(CaptureStatusView.ACTIONS_DROPDOWN_ID);
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();
77 throw Error('Unrecognized action: ' + action);
82 return CaptureStatusView;