Chromium Code Reviews| 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 * Object to communicate between the renderer and the browser. | |
| 7 * @type {!BrowserBridge} | |
| 8 */ | |
| 9 var g_exportBrowserBridge = null; | |
| 10 | |
| 11 /** | |
| 12 * Main entry point called once the page has loaded. | |
| 13 */ | |
| 14 function onLoad() { | |
| 15 g_exportBrowserBridge = new BrowserBridge(); | |
| 16 MainView.getInstance(); | |
| 17 } | |
| 18 | |
| 19 document.addEventListener('DOMContentLoaded', onLoad); | |
| 20 | |
| 21 | |
| 22 /** | |
| 23 * This class provides a "bridge" for communicating between the javascript and | |
| 24 * the browser. | |
| 25 */ | |
| 26 var BrowserBridge = (function() { | |
| 27 'use strict'; | |
| 28 | |
| 29 /** | |
| 30 * Delay in milliseconds between updates of certain browser information. | |
| 31 */ | |
| 32 var POLL_INTERVAL_MS = 5000; | |
| 33 | |
| 34 /** | |
| 35 * @constructor | |
| 36 */ | |
| 37 function BrowserBridge() { | |
| 38 } | |
| 39 | |
| 40 BrowserBridge.prototype = { | |
| 41 | |
| 42 //-------------------------------------------------------------------------- | |
| 43 // Messages sent to the browser | |
| 44 //-------------------------------------------------------------------------- | |
| 45 | |
| 46 setPollInterval: function() { | |
| 47 window.setInterval(this.sendGetExportNetLogInfo.bind(this), | |
| 48 POLL_INTERVAL_MS); | |
| 49 }, | |
| 50 | |
| 51 sendGetExportNetLogInfo: function() { | |
| 52 chrome.send('getExportNetLogInfo'); | |
| 53 }, | |
| 54 | |
| 55 sendStartNetLog: function() { | |
| 56 chrome.send('startNetLog'); | |
| 57 }, | |
| 58 | |
| 59 sendStopNetLog: function() { | |
| 60 chrome.send('stopNetLog'); | |
| 61 }, | |
| 62 | |
| 63 sendSendNetLog: function() { | |
| 64 chrome.send('sendNetLog'); | |
|
James Hawkins
2013/01/29 22:48:34
Just inline chrome.send instead of using this brid
ramant (doing other things)
2013/01/30 02:35:42
Done.
| |
| 65 }, | |
| 66 | |
| 67 //-------------------------------------------------------------------------- | |
| 68 // Messages received from the browser. | |
| 69 //-------------------------------------------------------------------------- | |
| 70 | |
| 71 receivedData: function(data) { | |
| 72 MainView.getInstance().onExportNetLogInfoChanged(data); | |
| 73 } | |
| 74 }; | |
| 75 | |
| 76 return BrowserBridge; | |
| 77 })(); | |
| 78 | |
| 79 /** | |
| 80 * This class handles the presentation of our profiler view. Used as a | |
| 81 * singleton. | |
| 82 */ | |
| 83 var MainView = (function() { | |
| 84 'use strict'; | |
| 85 | |
| 86 // -------------------------------------------------------------------------- | |
| 87 // Important IDs in the HTML document | |
| 88 // -------------------------------------------------------------------------- | |
| 89 | |
| 90 var START_DATA_BUTTON_ID = 'export-view-start-data'; | |
| 91 var STOP_DATA_BUTTON_ID = 'export-view-stop-data'; | |
| 92 var SEND_DATA_BUTTON_ID = 'export-view-send-data'; | |
| 93 var FILE_PATH_TEXT_ID = 'export-view-file-path-text'; | |
| 94 | |
| 95 // -------------------------------------------------------------------------- | |
| 96 | |
| 97 /** | |
| 98 * @constructor | |
| 99 */ | |
| 100 function MainView() { | |
| 101 $(START_DATA_BUTTON_ID).onclick = this.onStartData_.bind(this); | |
| 102 $(STOP_DATA_BUTTON_ID).onclick = this.onStopData_.bind(this); | |
| 103 $(SEND_DATA_BUTTON_ID).onclick = this.onSendData_.bind(this); | |
| 104 | |
| 105 g_exportBrowserBridge.setPollInterval(); | |
| 106 | |
| 107 g_exportBrowserBridge.sendGetExportNetLogInfo(); | |
| 108 } | |
| 109 | |
| 110 cr.addSingletonGetter(MainView); | |
| 111 | |
| 112 MainView.prototype = { | |
| 113 /** | |
| 114 * Starts saving NetLog data to a file. | |
| 115 */ | |
| 116 onStartData_: function() { | |
| 117 g_exportBrowserBridge.sendStartNetLog(); | |
| 118 }, | |
| 119 | |
| 120 /** | |
| 121 * Stops saving NetLog data to a file. | |
| 122 */ | |
| 123 onStopData_: function() { | |
| 124 g_exportBrowserBridge.sendStopNetLog(); | |
| 125 }, | |
| 126 | |
| 127 /** | |
| 128 * Sends NetLog data via email from browser. | |
| 129 */ | |
| 130 onSendData_: function() { | |
| 131 g_exportBrowserBridge.sendSendNetLog(); | |
| 132 }, | |
| 133 | |
| 134 onExportNetLogInfoChanged: function(exportNetLogInfo) { | |
| 135 if (exportNetLogInfo.file) { | |
| 136 var message = ''; | |
| 137 if (exportNetLogInfo.state == 'ALLOW_STOP') { | |
| 138 message = 'NetLog data is collected in: '; | |
|
James Hawkins
2013/01/29 22:48:34
nit: No braces on single-line blocks.
ramant (doing other things)
2013/01/30 02:35:42
Done.
| |
| 139 } else if (exportNetLogInfo.state == 'ALLOW_START_SEND') { | |
| 140 message = 'NetLog data to send is in: '; | |
| 141 } | |
| 142 $(FILE_PATH_TEXT_ID).textContent = message + exportNetLogInfo.file; | |
| 143 } else { | |
| 144 $(FILE_PATH_TEXT_ID).textContent = ''; | |
| 145 } | |
| 146 | |
| 147 $(START_DATA_BUTTON_ID).disabled = true; | |
| 148 $(STOP_DATA_BUTTON_ID).disabled = true; | |
| 149 $(SEND_DATA_BUTTON_ID).disabled = true; | |
| 150 if (exportNetLogInfo.state == 'ALLOW_START') { | |
| 151 $(START_DATA_BUTTON_ID).disabled = false; | |
| 152 } else if (exportNetLogInfo.state == 'ALLOW_STOP') { | |
| 153 $(STOP_DATA_BUTTON_ID).disabled = false; | |
| 154 } else if (exportNetLogInfo.state == 'ALLOW_START_SEND') { | |
| 155 $(START_DATA_BUTTON_ID).disabled = false; | |
| 156 $(SEND_DATA_BUTTON_ID).disabled = false; | |
| 157 } else if (exportNetLogInfo.state == 'UNINITIALIZED') { | |
| 158 $(FILE_PATH_TEXT_ID).textContent = | |
| 159 'Unable to initialize NetLog data file.'; | |
| 160 } | |
| 161 } | |
| 162 }; | |
| 163 | |
| 164 return MainView; | |
| 165 })(); | |
| OLD | NEW |