1 // Copyright (c) 2013 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 * Main entry point called once the page has loaded.
9 NetExportView.getInstance();
12 document.addEventListener('DOMContentLoaded', onLoad);
15 * This class handles the presentation of our profiler view. Used as a
18 var NetExportView = (function() {
22 * Delay in milliseconds between updates of certain browser information.
24 /** @const */ var POLL_INTERVAL_MS = 5000;
26 // --------------------------------------------------------------------------
31 function NetExportView() {
32 $('export-view-start-data').onclick = this.onStartData_.bind(this);
33 $('export-view-stop-data').onclick = this.onStopData_.bind(this);
34 $('export-view-send-data').onclick = this.onSendData_.bind(this);
36 window.setInterval(function() { chrome.send('getExportNetLogInfo'); },
39 chrome.send('getExportNetLogInfo');
42 cr.addSingletonGetter(NetExportView);
44 NetExportView.prototype = {
46 * Starts saving NetLog data to a file.
48 onStartData_: function() {
50 document.querySelector('input[name="log-mode"]:checked').value;
51 chrome.send('startNetLog', [logMode]);
55 * Stops saving NetLog data to a file.
57 onStopData_: function() {
58 chrome.send('stopNetLog');
62 * Sends NetLog data via email from browser.
64 onSendData_: function() {
65 chrome.send('sendNetLog');
69 * Updates the UI to reflect the current state. Displays the path name of
70 * the file where NetLog data is collected.
72 onExportNetLogInfoChanged: function(exportNetLogInfo) {
73 if (exportNetLogInfo.file) {
75 if (exportNetLogInfo.state == 'LOGGING')
76 message = 'NetLog data is collected in: ';
77 else if (exportNetLogInfo.logType != 'NONE')
78 message = 'NetLog data to send is in: ';
79 $('export-view-file-path-text').textContent =
80 message + exportNetLogInfo.file;
82 $('export-view-file-path-text').textContent = '';
85 // Disable all controls. Useable controls are enabled below.
86 var controls = document.querySelectorAll('button, input');
87 for (var i = 0; i < controls.length; ++i) {
88 controls[i].disabled = true;
91 $('export-view-deletes-log-text').hidden = true;
92 $('export-view-private-data-text').hidden = true;
93 $('export-view-send-old-log-text').hidden = true;
94 if (exportNetLogInfo.state == 'NOT_LOGGING') {
95 // Allow making a new log.
96 $('export-view-strip-private-data-button').disabled = false;
97 $('export-view-include-private-data-button').disabled = false;
98 $('export-view-log-bytes-button').disabled = false;
99 $('export-view-start-data').disabled = false;
101 // If there's an existing log, allow sending it.
102 if (exportNetLogInfo.logType != 'NONE') {
103 $('export-view-deletes-log-text').hidden = false;
104 $('export-view-send-data').disabled = false;
105 if (exportNetLogInfo.logType == 'UNKNOWN') {
106 $('export-view-send-old-log-text').hidden = false;
107 } else if (exportNetLogInfo.logType == 'NORMAL') {
108 $('export-view-private-data-text').hidden = false;
111 } else if (exportNetLogInfo.state == 'LOGGING') {
112 // Only possible to stop logging. Radio buttons reflects current state.
113 document.querySelector('input[name="log-mode"][value="' +
114 exportNetLogInfo.logType + '"]').checked = true;
115 $('export-view-stop-data').disabled = false;
116 } else if (exportNetLogInfo.state == 'UNINITIALIZED') {
117 $('export-view-file-path-text').textContent =
118 'Unable to initialize NetLog data file.';
123 return NetExportView;