| OLD | NEW |
| (Empty) |
| 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 */ | |
| 8 function onLoad() { | |
| 9 NetExportView.getInstance(); | |
| 10 } | |
| 11 | |
| 12 document.addEventListener('DOMContentLoaded', onLoad); | |
| 13 | |
| 14 /** | |
| 15 * This class handles the presentation of our profiler view. Used as a | |
| 16 * singleton. | |
| 17 */ | |
| 18 var 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 | |
| 28 /** | |
| 29 * @constructor | |
| 30 */ | |
| 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); | |
| 35 | |
| 36 window.setInterval(function() { chrome.send('getExportNetLogInfo'); }, | |
| 37 POLL_INTERVAL_MS); | |
| 38 | |
| 39 chrome.send('getExportNetLogInfo'); | |
| 40 } | |
| 41 | |
| 42 cr.addSingletonGetter(NetExportView); | |
| 43 | |
| 44 NetExportView.prototype = { | |
| 45 /** | |
| 46 * Starts saving NetLog data to a file. | |
| 47 */ | |
| 48 onStartData_: function() { | |
| 49 var logMode = | |
| 50 document.querySelector('input[name="log-mode"]:checked').value; | |
| 51 chrome.send('startNetLog', [logMode]); | |
| 52 }, | |
| 53 | |
| 54 /** | |
| 55 * Stops saving NetLog data to a file. | |
| 56 */ | |
| 57 onStopData_: function() { | |
| 58 chrome.send('stopNetLog'); | |
| 59 }, | |
| 60 | |
| 61 /** | |
| 62 * Sends NetLog data via email from browser. | |
| 63 */ | |
| 64 onSendData_: function() { | |
| 65 chrome.send('sendNetLog'); | |
| 66 }, | |
| 67 | |
| 68 /** | |
| 69 * Updates the UI to reflect the current state. Displays the path name of | |
| 70 * the file where NetLog data is collected. | |
| 71 */ | |
| 72 onExportNetLogInfoChanged: function(exportNetLogInfo) { | |
| 73 if (exportNetLogInfo.file) { | |
| 74 var message = ''; | |
| 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; | |
| 81 } else { | |
| 82 $('export-view-file-path-text').textContent = ''; | |
| 83 } | |
| 84 | |
| 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; | |
| 89 } | |
| 90 | |
| 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; | |
| 100 | |
| 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; | |
| 109 } | |
| 110 } | |
| 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.'; | |
| 119 } | |
| 120 } | |
| 121 }; | |
| 122 | |
| 123 return NetExportView; | |
| 124 })(); | |
| OLD | NEW |