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. 4 5/** 6 * Main entry point called once the page has loaded. 7 */ 8function onLoad() { 9 NetExportView.getInstance(); 10} 11 12document.addEventListener('DOMContentLoaded', onLoad); 13 14/** 15 * This class handles the presentation of our profiler view. Used as a 16 * singleton. 17 */ 18var NetExportView = (function() { 19 'use strict'; 20 21 /** 22 * Delay in milliseconds between updates of certain browser information. 23 */ 24 /** @const */ var POLL_INTERVAL_MS = 5000; 25 26 // -------------------------------------------------------------------------- 27 // Important IDs in the HTML document 28 // -------------------------------------------------------------------------- 29 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'; 34 35 // -------------------------------------------------------------------------- 36 37 /** 38 * @constructor 39 */ 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); 44 45 window.setInterval(function() { chrome.send('getExportNetLogInfo'); }, 46 POLL_INTERVAL_MS); 47 48 chrome.send('getExportNetLogInfo'); 49 } 50 51 cr.addSingletonGetter(NetExportView); 52 53 NetExportView.prototype = { 54 /** 55 * Starts saving NetLog data to a file. 56 */ 57 onStartData_: function() { 58 chrome.send('startNetLog'); 59 }, 60 61 /** 62 * Stops saving NetLog data to a file. 63 */ 64 onStopData_: function() { 65 chrome.send('stopNetLog'); 66 }, 67 68 /** 69 * Sends NetLog data via email from browser. 70 */ 71 onSendData_: function() { 72 chrome.send('sendNetLog'); 73 }, 74 75 /** 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. 79 */ 80 onExportNetLogInfoChanged: function(exportNetLogInfo) { 81 if (exportNetLogInfo.file) { 82 var message = ''; 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; 88 } else { 89 $(FILE_PATH_TEXT_ID).textContent = ''; 90 } 91 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.'; 105 } 106 } 107 }; 108 109 return NetExportView; 110})(); 111