| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * This view displays controls for capturing network events. | 6 * This view displays controls for capturing network events. |
| 7 * @constructor | |
| 8 */ | 7 */ |
| 9 function CaptureView() { | |
| 10 const mainBoxId = 'capture-view-tab-content'; | |
| 11 const byteLoggingCheckboxId = 'capture-view-byte-logging-checkbox'; | |
| 12 const passivelyCapturedCountId = 'capture-view-passively-captured-count'; | |
| 13 const activelyCapturedCountId = 'capture-view-actively-captured-count'; | |
| 14 const deleteAllId = 'capture-view-delete-all'; | |
| 15 const tipAnchorId = 'capture-view-tip-anchor'; | |
| 16 const tipDivId = 'capture-view-tip-div'; | |
| 17 | 8 |
| 18 DivView.call(this, mainBoxId); | 9 var CaptureView = (function() { |
| 10 // IDs for special HTML elements in capture_view.html |
| 11 const MAIN_BOX_ID = 'capture-view-tab-content'; |
| 12 const BYTE_LOGGING_CHECKBOX_ID = 'capture-view-byte-logging-checkbox'; |
| 13 const PASSIVELY_CAPTURED_COUNT_ID = 'capture-view-passively-captured-count'; |
| 14 const ACTIVELY_CAPTURED_COUNT_ID = 'capture-view-actively-captured-count'; |
| 15 const DELETE_ALL_ID = 'capture-view-delete-all'; |
| 16 const TIP_ANCHOR_ID = 'capture-view-tip-anchor'; |
| 17 const TIP_DIV_ID = 'capture-view-tip-div'; |
| 19 | 18 |
| 20 var byteLoggingCheckbox = $(byteLoggingCheckboxId); | 19 // We inherit from DivView. |
| 21 byteLoggingCheckbox.onclick = | 20 var superClass = DivView; |
| 22 this.onSetByteLogging_.bind(this, byteLoggingCheckbox); | |
| 23 | 21 |
| 24 this.activelyCapturedCountBox_ = $(activelyCapturedCountId); | 22 /** |
| 25 this.passivelyCapturedCountBox_ = $(passivelyCapturedCountId); | 23 * @constructor |
| 26 $(deleteAllId).onclick = g_browser.sourceTracker.deleteAllSourceEntries.bind( | 24 */ |
| 27 g_browser.sourceTracker); | 25 function CaptureView() { |
| 26 // Call superclass's constructor. |
| 27 superClass.call(this, MAIN_BOX_ID); |
| 28 | 28 |
| 29 $(tipAnchorId).onclick = | 29 var byteLoggingCheckbox = $(BYTE_LOGGING_CHECKBOX_ID); |
| 30 this.toggleCommandLineTip_.bind(this, tipDivId); | 30 byteLoggingCheckbox.onclick = |
| 31 this.onSetByteLogging_.bind(this, byteLoggingCheckbox); |
| 31 | 32 |
| 32 this.updateEventCounts_(); | 33 this.activelyCapturedCountBox_ = $(ACTIVELY_CAPTURED_COUNT_ID); |
| 34 this.passivelyCapturedCountBox_ = $(PASSIVELY_CAPTURED_COUNT_ID); |
| 35 $(DELETE_ALL_ID).onclick = |
| 36 g_browser.sourceTracker.deleteAllSourceEntries.bind( |
| 37 g_browser.sourceTracker); |
| 33 | 38 |
| 34 g_browser.sourceTracker.addObserver(this); | 39 $(TIP_ANCHOR_ID).onclick = |
| 35 } | 40 this.toggleCommandLineTip_.bind(this, TIP_DIV_ID); |
| 36 | 41 |
| 37 inherits(CaptureView, DivView); | 42 this.updateEventCounts_(); |
| 38 | 43 |
| 39 /** | 44 g_browser.sourceTracker.addObserver(this); |
| 40 * Called whenever a new event is received. | 45 } |
| 41 */ | |
| 42 CaptureView.prototype.onSourceEntriesUpdated = function(sourceEntries) { | |
| 43 this.updateEventCounts_(); | |
| 44 }; | |
| 45 | 46 |
| 46 /** | 47 cr.addSingletonGetter(CaptureView); |
| 47 * Toggles the visilibity on the command-line tip. | |
| 48 */ | |
| 49 CaptureView.prototype.toggleCommandLineTip_ = function(divId) { | |
| 50 var n = $(divId); | |
| 51 var isVisible = n.style.display != 'none'; | |
| 52 setNodeDisplay(n, !isVisible); | |
| 53 return false; // Prevent default handling of the click. | |
| 54 }; | |
| 55 | 48 |
| 56 /** | 49 CaptureView.prototype = { |
| 57 * Called whenever some log events are deleted. |sourceIds| lists | 50 // Inherit the superclass's methods. |
| 58 * the source IDs of all deleted log entries. | 51 __proto__: superClass.prototype, |
| 59 */ | |
| 60 CaptureView.prototype.onSourceEntriesDeleted = function(sourceIds) { | |
| 61 this.updateEventCounts_(); | |
| 62 }; | |
| 63 | 52 |
| 64 /** | 53 /** |
| 65 * Called whenever all log events are deleted. | 54 * Called whenever a new event is received. |
| 66 */ | 55 */ |
| 67 CaptureView.prototype.onAllSourceEntriesDeleted = function() { | 56 onSourceEntriesUpdated: function(sourceEntries) { |
| 68 this.updateEventCounts_(); | 57 this.updateEventCounts_(); |
| 69 }; | 58 }, |
| 70 | 59 |
| 71 /** | 60 /** |
| 72 * Called when a log file is loaded, after clearing the old log entries and | 61 * Toggles the visilibity on the command-line tip. |
| 73 * loading the new ones. Returns false to indicate the view should | 62 */ |
| 74 * be hidden. | 63 toggleCommandLineTip_: function(divId) { |
| 75 */ | 64 var n = $(divId); |
| 76 CaptureView.prototype.onLoadLogFinish = function(data) { | 65 var isVisible = n.style.display != 'none'; |
| 77 return false; | 66 setNodeDisplay(n, !isVisible); |
| 78 }; | 67 return false; // Prevent default handling of the click. |
| 68 }, |
| 79 | 69 |
| 80 /** | 70 /** |
| 81 * Updates the counters showing how many events have been captured. | 71 * Called whenever some log events are deleted. |sourceIds| lists |
| 82 */ | 72 * the source IDs of all deleted log entries. |
| 83 CaptureView.prototype.updateEventCounts_ = function() { | 73 */ |
| 84 this.activelyCapturedCountBox_.textContent = | 74 onSourceEntriesDeleted: function(sourceIds) { |
| 85 g_browser.sourceTracker.getNumActivelyCapturedEvents(); | 75 this.updateEventCounts_(); |
| 86 this.passivelyCapturedCountBox_.textContent = | 76 }, |
| 87 g_browser.sourceTracker.getNumPassivelyCapturedEvents(); | |
| 88 }; | |
| 89 | 77 |
| 90 /** | 78 /** |
| 91 * Depending on the value of the checkbox, enables or disables logging of | 79 * Called whenever all log events are deleted. |
| 92 * actual bytes transferred. | 80 */ |
| 93 */ | 81 onAllSourceEntriesDeleted: function() { |
| 94 CaptureView.prototype.onSetByteLogging_ = function(byteLoggingCheckbox) { | 82 this.updateEventCounts_(); |
| 95 if (byteLoggingCheckbox.checked) { | 83 }, |
| 96 g_browser.setLogLevel(LogLevelType.LOG_ALL); | |
| 97 } else { | |
| 98 g_browser.setLogLevel(LogLevelType.LOG_ALL_BUT_BYTES); | |
| 99 } | |
| 100 }; | |
| 101 | 84 |
| 85 /** |
| 86 * Called when a log file is loaded, after clearing the old log entries and |
| 87 * loading the new ones. Returns false to indicate the view should |
| 88 * be hidden. |
| 89 */ |
| 90 onLoadLogFinish: function(data) { |
| 91 return false; |
| 92 }, |
| 93 |
| 94 /** |
| 95 * Updates the counters showing how many events have been captured. |
| 96 */ |
| 97 updateEventCounts_: function() { |
| 98 this.activelyCapturedCountBox_.textContent = |
| 99 g_browser.sourceTracker.getNumActivelyCapturedEvents(); |
| 100 this.passivelyCapturedCountBox_.textContent = |
| 101 g_browser.sourceTracker.getNumPassivelyCapturedEvents(); |
| 102 }, |
| 103 |
| 104 /** |
| 105 * Depending on the value of the checkbox, enables or disables logging of |
| 106 * actual bytes transferred. |
| 107 */ |
| 108 onSetByteLogging_: function(byteLoggingCheckbox) { |
| 109 if (byteLoggingCheckbox.checked) { |
| 110 g_browser.setLogLevel(LogLevelType.LOG_ALL); |
| 111 } else { |
| 112 g_browser.setLogLevel(LogLevelType.LOG_ALL_BUT_BYTES); |
| 113 } |
| 114 } |
| 115 }; |
| 116 |
| 117 return CaptureView; |
| 118 })(); |
| OLD | NEW |