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() {
49 var stripPrivateData = $('export-view-private-data-toggle').checked;
50 chrome.send('startNetLog', [stripPrivateData]);
54 * Stops saving NetLog data to a file.
56 onStopData_: function() {
57 chrome.send('stopNetLog');
61 * Sends NetLog data via email from browser.
63 onSendData_: function() {
64 chrome.send('sendNetLog');
68 * Updates the UI to reflect the current state. Displays the path name of
69 * the file where NetLog data is collected.
71 onExportNetLogInfoChanged: function(exportNetLogInfo) {
72 if (exportNetLogInfo.file) {
74 if (exportNetLogInfo.state == 'LOGGING')
75 message = 'NetLog data is collected in: ';
76 else if (exportNetLogInfo.logType != 'NONE')
77 message = 'NetLog data to send is in: ';
78 $('export-view-file-path-text').textContent =
79 message + exportNetLogInfo.file;
81 $('export-view-file-path-text').textContent = '';
84 $('export-view-private-data-toggle').disabled = true;
85 $('export-view-start-data').disabled = true;
86 $('export-view-deletes-log-text').hidden = true;
87 $('export-view-stop-data').disabled = true;
88 $('export-view-send-data').disabled = true;
89 $('export-view-private-data-text').hidden = true;
90 $('export-view-send-old-log-text').hidden = true;
91 if (exportNetLogInfo.state == 'NOT_LOGGING') {
92 // Allow making a new log.
93 $('export-view-private-data-toggle').disabled = false;
94 $('export-view-start-data').disabled = false;
96 // If there's an existing log, allow sending it.
97 if (exportNetLogInfo.logType != 'NONE') {
98 $('export-view-deletes-log-text').hidden = false;
99 $('export-view-send-data').disabled = false;
100 if (exportNetLogInfo.logType == 'UNKNOWN') {
101 $('export-view-send-old-log-text').hidden = false;
102 } else if (exportNetLogInfo.logType == 'NORMAL') {
103 $('export-view-private-data-text').hidden = false;
106 } else if (exportNetLogInfo.state == 'LOGGING') {
107 // Only possible to stop logging. Checkbox reflects current state.
108 $('export-view-private-data-toggle').checked =
109 (exportNetLogInfo.logType == 'STRIP_PRIVATE_DATA');
110 $('export-view-stop-data').disabled = false;
111 } else if (exportNetLogInfo.state == 'UNINITIALIZED') {
112 $('export-view-file-path-text').textContent =
113 'Unable to initialize NetLog data file.';
118 return NetExportView;