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 // --------------------------------------------------------------------------
27 // Important IDs in the HTML document
28 // --------------------------------------------------------------------------
30 /** @const */ var START_DATA_BUTTON_ID = 'export-view-start-data';
31 /** @const */ var STOP_DATA_BUTTON_ID = 'export-view-stop-data';
32 /** @const */ var SEND_DATA_BUTTON_ID = 'export-view-send-data';
33 /** @const */ var FILE_PATH_TEXT_ID = 'export-view-file-path-text';
35 // --------------------------------------------------------------------------
40 function NetExportView() {
41 $(START_DATA_BUTTON_ID).onclick = this.onStartData_.bind(this);
42 $(STOP_DATA_BUTTON_ID).onclick = this.onStopData_.bind(this);
43 $(SEND_DATA_BUTTON_ID).onclick = this.onSendData_.bind(this);
45 window.setInterval(function() { chrome.send('getExportNetLogInfo'); },
48 chrome.send('getExportNetLogInfo');
51 cr.addSingletonGetter(NetExportView);
53 NetExportView.prototype = {
55 * Starts saving NetLog data to a file.
57 onStartData_: function() {
58 chrome.send('startNetLog');
62 * Stops saving NetLog data to a file.
64 onStopData_: function() {
65 chrome.send('stopNetLog');
69 * Sends NetLog data via email from browser.
71 onSendData_: function() {
72 chrome.send('sendNetLog');
76 * Enable or disable START_DATA_BUTTON_ID, STOP_DATA_BUTTON_ID and
77 * SEND_DATA_BUTTON_ID buttons. Displays the path name of the file where
78 * NetLog data is collected.
80 onExportNetLogInfoChanged: function(exportNetLogInfo) {
81 if (exportNetLogInfo.file) {
83 if (exportNetLogInfo.state == 'ALLOW_STOP')
84 message = 'NetLog data is collected in: ';
85 else if (exportNetLogInfo.state == 'ALLOW_START_SEND')
86 message = 'NetLog data to send is in: ';
87 $(FILE_PATH_TEXT_ID).textContent = message + exportNetLogInfo.file;
89 $(FILE_PATH_TEXT_ID).textContent = '';
92 $(START_DATA_BUTTON_ID).disabled = true;
93 $(STOP_DATA_BUTTON_ID).disabled = true;
94 $(SEND_DATA_BUTTON_ID).disabled = true;
95 if (exportNetLogInfo.state == 'ALLOW_START') {
96 $(START_DATA_BUTTON_ID).disabled = false;
97 } else if (exportNetLogInfo.state == 'ALLOW_STOP') {
98 $(STOP_DATA_BUTTON_ID).disabled = false;
99 } else if (exportNetLogInfo.state == 'ALLOW_START_SEND') {
100 $(START_DATA_BUTTON_ID).disabled = false;
101 $(SEND_DATA_BUTTON_ID).disabled = false;
102 } else if (exportNetLogInfo.state == 'UNINITIALIZED') {
103 $(FILE_PATH_TEXT_ID).textContent =
104 'Unable to initialize NetLog data file.';
109 return NetExportView;