Updated drag and drop thumbnails.
[chromium-blink-merge.git] / chrome / browser / resources / net_internals / capture_view.js
blobb79c71d23f32a6c2bfa0e0df2b537201c8201a24
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 * This view displays controls for capturing network events.
7 */
8 var CaptureView = (function() {
9 'use strict';
11 // We inherit from DivView.
12 var superClass = DivView;
14 /**
15 * @constructor
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
34 // be updated.
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,
57 /**
58 * Toggles the visilibity on the command-line tip.
60 toggleCommandLineTip_: function(divId) {
61 var n = $(divId);
62 var isVisible = n.style.display != 'none';
63 setNodeDisplay(n, !isVisible);
64 return false; // Prevent default handling of the click.
67 /**
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
70 * be hidden.
72 onLoadLogFinish: function(data) {
73 return false;
76 /**
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
93 // reload.
94 ExportView.getInstance().showPrivacyWarning();
95 } else {
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.
119 hardLimit = 300000;
120 softLimit = 150000;
123 EventsTracker.getInstance().setLimits(softLimit, hardLimit);
127 return CaptureView;
128 })();