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); | |
mmenke
2013/01/17 17:49:43
optional: Could just make the MainView a singleto
mmenke
2013/01/17 17:49:43
nit: Fix indent.
ramant (doing other things)
2013/01/18 04:59:52
Done.
ramant (doing other things)
2013/01/18 04:59:52
Done.
| |
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.startDataButton_ = $(START_DATA_BUTTON_ID); | |
104 this.startDataButton_.onclick = this.onStartData_.bind(this); | |
105 this.stopDataButton_ = $(STOP_DATA_BUTTON_ID); | |
106 this.stopDataButton_.onclick = this.onStopData_.bind(this); | |
107 this.sendDataButton_ = $(SEND_DATA_BUTTON_ID); | |
108 this.sendDataButton_.onclick = this.onSendData_.bind(this); | |
mmenke
2013/01/17 17:49:43
optional: Rather than use member variables, could
ramant (doing other things)
2013/01/18 04:59:52
Done.
| |
109 | |
110 g_exportBrowserBridge.setPollInterval(); | |
111 | |
112 g_exportBrowserBridge.sendGetExportNetLogInfo(); | |
113 } | |
114 | |
115 MainView.prototype = { | |
116 /** | |
117 * Starts saving NetLog data to a file. | |
118 */ | |
119 onStartData_: function() { | |
120 g_exportBrowserBridge.sendStartNetLog(); | |
121 }, | |
122 | |
123 /** | |
124 * Stops saving NetLog data to a file. | |
125 */ | |
126 onStopData_: function() { | |
127 g_exportBrowserBridge.sendStopNetLog(); | |
128 }, | |
129 | |
130 /** | |
131 * Sends NetLog data via email from browser. | |
132 */ | |
133 onSendData_: function() { | |
134 g_exportBrowserBridge.sendSendNetLog(); | |
135 }, | |
136 | |
137 onExportNetLogInfoChanged: function(exportNetLogInfo) { | |
138 if (exportNetLogInfo.file) { | |
139 var message = ''; | |
140 if (exportNetLogInfo.state == 'ALLOW_STOP') { | |
141 message = 'NetLog data is collected in: '; | |
142 } else if (exportNetLogInfo.state == 'ALLOW_START_SEND') { | |
143 message = 'NetLog data to send is in: '; | |
144 } | |
145 $(FILE_PATH_TEXT_ID).textContent = message + exportNetLogInfo.file; | |
146 } else { | |
147 $(FILE_PATH_TEXT_ID).textContent = ''; | |
148 } | |
mmenke
2013/01/17 17:49:43
nit: Suggest a linebreak here.
ramant (doing other things)
2013/01/18 04:59:52
Done.
| |
149 this.startDataButton_.disabled = true; | |
150 this.stopDataButton_.disabled = true; | |
151 this.sendDataButton_.disabled = true; | |
152 if (exportNetLogInfo.state == 'ALLOW_START') { | |
153 this.startDataButton_.disabled = false; | |
154 } else if (exportNetLogInfo.state == 'ALLOW_STOP') { | |
155 this.stopDataButton_.disabled = false; | |
156 } else if (exportNetLogInfo.state == 'ALLOW_START_SEND') { | |
157 this.startDataButton_.disabled = false; | |
158 this.sendDataButton_.disabled = false; | |
159 } | |
160 } | |
161 }; | |
162 | |
163 return MainView; | |
164 })(); | |
OLD | NEW |