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
.TIP_ANCHOR_ID
).onclick
=
29 this.toggleCommandLineTip_
.bind(this, CaptureView
.TIP_DIV_ID
);
31 if (byteLoggingCheckbox
.checked
) {
32 // The code to display a warning on ExportView relies on bytelogging
33 // being off by default. If this ever changes, the code will need to
35 throw 'Not expecting byte logging to be enabled!';
38 this.onChangeLimit_();
41 // ID for special HTML element in category_tabs.html
42 CaptureView
.TAB_HANDLE_ID
= 'tab-handle-capture';
44 // IDs for special HTML elements in capture_view.html
45 CaptureView
.MAIN_BOX_ID
= 'capture-view-tab-content';
46 CaptureView
.BYTE_LOGGING_CHECKBOX_ID
= 'capture-view-byte-logging-checkbox';
47 CaptureView
.LIMIT_CHECKBOX_ID
= 'capture-view-limit-checkbox';
48 CaptureView
.TIP_ANCHOR_ID
= 'capture-view-tip-anchor';
49 CaptureView
.TIP_DIV_ID
= 'capture-view-tip-div';
51 cr
.addSingletonGetter(CaptureView
);
53 CaptureView
.prototype = {
54 // Inherit the superclass's methods.
55 __proto__
: superClass
.prototype,
58 * Toggles the visilibity on the command-line tip.
60 toggleCommandLineTip_: function(divId
) {
62 var isVisible
= n
.style
.display
!= 'none';
63 setNodeDisplay(n
, !isVisible
);
64 return false; // Prevent default handling of the click.
68 * Called when a log file is loaded, after clearing the old log entries and
69 * loading the new ones. Returns false to indicate the view should
72 onLoadLogFinish: function(data
) {
77 * Depending on the value of the checkbox, enables or disables logging of
78 * actual bytes transferred.
80 onSetByteLogging_: function() {
81 var byteLoggingCheckbox
= $(CaptureView
.BYTE_LOGGING_CHECKBOX_ID
);
83 if (byteLoggingCheckbox
.checked
) {
84 g_browser
.setLogLevel(LogLevelType
.LOG_ALL
);
86 // Once we enable byte logging, all bets are off on what gets captured.
87 // Have the export view warn that the "strip cookies" option is
88 // ineffective from this point on.
90 // In theory we could clear this warning after unchecking the box and
91 // then deleting all the events which had been captured. We don't
92 // currently do that; if you want the warning to go away, will need to
94 ExportView
.getInstance().showPrivacyWarning();
96 g_browser
.setLogLevel(LogLevelType
.LOG_ALL_BUT_BYTES
);
100 onChangeLimit_: function() {
101 var limitCheckbox
= $(CaptureView
.LIMIT_CHECKBOX_ID
);
103 // Default to unlimited.
104 var softLimit
= Infinity
;
105 var hardLimit
= Infinity
;
107 if (limitCheckbox
.checked
) {
108 // The chosen limits are kind of arbitrary. I based it off the
109 // following observation:
110 // A user-submitted log file which spanned a 7 hour time period
111 // comprised 778,235 events and required 128MB of JSON.
113 // That feels too big. Assuming it was representative, then scaling
114 // by a factor of 4 should translate into a 32MB log file and cover
115 // close to 2 hours of events, which feels better.
117 // A large gap is left between the hardLimit and softLimit to avoid
118 // resetting the events often.
123 EventsTracker
.getInstance().setLimits(softLimit
, hardLimit
);