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