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 * This view displays controls for capturing network events.
8 var CaptureView = (function() {
11 // We inherit from DivView.
12 var superClass = DivView;
17 function CaptureView() {
18 assertFirstConstructorCall(CaptureView);
20 // Call superclass's constructor.
21 superClass.call(this, CaptureView.MAIN_BOX_ID);
23 var byteLoggingCheckbox = $(CaptureView.BYTE_LOGGING_CHECKBOX_ID);
24 byteLoggingCheckbox.onclick = this.onSetByteLogging_.bind(this);
26 $(CaptureView.LIMIT_CHECKBOX_ID).onclick = this.onChangeLimit_.bind(this);
28 $(CaptureView.STOP_BUTTON_ID).onclick =
29 this.onStopButtonClicked_.bind(this);
30 $(CaptureView.RESET_BUTTON_ID).onclick =
31 this.onResetButtonClicked_.bind(this);
33 if (byteLoggingCheckbox.checked) {
34 // The code to display a warning on ExportView relies on bytelogging
35 // being off by default. If this ever changes, the code will need to
37 throw 'Not expecting byte logging to be enabled!';
40 new MouseOverHelp(CaptureView.LIMIT_HELP_ID,
41 CaptureView.LIMIT_HELP_HOVER_ID);
43 new MouseOverHelp(CaptureView.BYTE_LOGGING_HELP_ID,
44 CaptureView.BYTE_LOGGING_HELP_HOVER_ID);
46 this.onChangeLimit_();
49 CaptureView.TAB_ID = 'tab-handle-capture';
50 CaptureView.TAB_NAME = 'Capture';
51 CaptureView.TAB_HASH = '#capture';
53 // IDs for special HTML elements in capture_view.html
54 CaptureView.MAIN_BOX_ID = 'capture-view-tab-content';
55 CaptureView.BYTE_LOGGING_CHECKBOX_ID = 'capture-view-byte-logging-checkbox';
56 CaptureView.LIMIT_CHECKBOX_ID = 'capture-view-limit-checkbox';
57 CaptureView.LIMIT_HELP_ID = 'capture-view-limit-help';
58 CaptureView.LIMIT_HELP_HOVER_ID = 'capture-view-limit-help-hover';
59 CaptureView.BYTE_LOGGING_HELP_ID = 'capture-view-byte-logging-help';
60 CaptureView.BYTE_LOGGING_HELP_HOVER_ID =
61 'capture-view-byte-logging-help-hover';
62 CaptureView.STOP_BUTTON_ID = 'capture-view-stop-button';
63 CaptureView.RESET_BUTTON_ID = 'capture-view-reset-button';
65 cr.addSingletonGetter(CaptureView);
67 CaptureView.prototype = {
68 // Inherit the superclass's methods.
69 __proto__: superClass.prototype,
72 * Called when a log file is loaded, after clearing the old log entries and
73 * loading the new ones. Returns false to indicate the view should
76 onLoadLogFinish: function(data) {
81 * Depending on the value of the checkbox, enables or disables logging of
82 * actual bytes transferred.
84 onSetByteLogging_: function() {
85 var byteLoggingCheckbox = $(CaptureView.BYTE_LOGGING_CHECKBOX_ID);
87 if (byteLoggingCheckbox.checked) {
88 g_browser.setLogLevel(LogLevelType.LOG_ALL);
90 // Once we enable byte logging, all bets are off on what gets captured.
91 // Have the export view warn that the "strip cookies" option is
92 // ineffective from this point on.
94 // In theory we could clear this warning after unchecking the box and
95 // then deleting all the events which had been captured. We don't
96 // currently do that; if you want the warning to go away, will need to
98 ExportView.getInstance().showPrivacyWarning();
100 g_browser.setLogLevel(LogLevelType.LOG_ALL_BUT_BYTES);
104 onChangeLimit_: function() {
105 var limitCheckbox = $(CaptureView.LIMIT_CHECKBOX_ID);
107 // Default to unlimited.
108 var softLimit = Infinity;
109 var hardLimit = Infinity;
111 if (limitCheckbox.checked) {
112 // The chosen limits are kind of arbitrary. I based it off the
113 // following observation:
114 // A user-submitted log file which spanned a 7 hour time period
115 // comprised 778,235 events and required 128MB of JSON.
117 // That feels too big. Assuming it was representative, then scaling
118 // by a factor of 4 should translate into a 32MB log file and cover
119 // close to 2 hours of events, which feels better.
121 // A large gap is left between the hardLimit and softLimit to avoid
122 // resetting the events often.
127 EventsTracker.getInstance().setLimits(softLimit, hardLimit);
130 onStopButtonClicked_: function() {
131 MainView.getInstance().switchToViewOnlyMode();
134 onResetButtonClicked_: function() {
135 EventsTracker.getInstance().deleteAllLogEntries();