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 * @constructor | |
31 */ | |
32 function BrowserBridge() { | |
33 } | |
34 | |
35 BrowserBridge.prototype = { | |
36 | |
37 //-------------------------------------------------------------------------- | |
38 // Messages received from the browser. | |
39 //-------------------------------------------------------------------------- | |
40 | |
41 receivedData: function(data) { | |
James Hawkins
2013/01/31 18:58:46
Same thing: why do you need a 'bridge'?
ramant (doing other things)
2013/01/31 19:58:26
Called the JS function directly from C++ code.
Do
| |
42 MainView.getInstance().onExportNetLogInfoChanged(data); | |
43 } | |
44 }; | |
45 | |
46 return BrowserBridge; | |
47 })(); | |
48 | |
49 /** | |
50 * This class handles the presentation of our profiler view. Used as a | |
51 * singleton. | |
52 */ | |
53 var MainView = (function() { | |
54 'use strict'; | |
55 | |
56 /** | |
57 * Delay in milliseconds between updates of certain browser information. | |
58 */ | |
59 var POLL_INTERVAL_MS = 5000; | |
60 | |
61 // -------------------------------------------------------------------------- | |
62 // Important IDs in the HTML document | |
63 // -------------------------------------------------------------------------- | |
64 | |
65 var START_DATA_BUTTON_ID = 'export-view-start-data'; | |
James Hawkins
2013/01/31 18:58:46
/** @const */
ramant (doing other things)
2013/01/31 19:58:26
Done.
| |
66 var STOP_DATA_BUTTON_ID = 'export-view-stop-data'; | |
67 var SEND_DATA_BUTTON_ID = 'export-view-send-data'; | |
68 var FILE_PATH_TEXT_ID = 'export-view-file-path-text'; | |
69 | |
70 // -------------------------------------------------------------------------- | |
71 | |
72 /** | |
73 * @constructor | |
74 */ | |
75 function MainView() { | |
76 $(START_DATA_BUTTON_ID).onclick = this.onStartData_.bind(this); | |
77 $(STOP_DATA_BUTTON_ID).onclick = this.onStopData_.bind(this); | |
78 $(SEND_DATA_BUTTON_ID).onclick = this.onSendData_.bind(this); | |
79 | |
80 window.setInterval(function() { chrome.send('getExportNetLogInfo'); }, | |
81 POLL_INTERVAL_MS); | |
82 | |
83 chrome.send('getExportNetLogInfo'); | |
84 } | |
85 | |
86 cr.addSingletonGetter(MainView); | |
87 | |
88 MainView.prototype = { | |
89 /** | |
90 * Starts saving NetLog data to a file. | |
91 */ | |
92 onStartData_: function() { | |
93 chrome.send('startNetLog'); | |
94 }, | |
95 | |
96 /** | |
97 * Stops saving NetLog data to a file. | |
98 */ | |
99 onStopData_: function() { | |
100 chrome.send('stopNetLog'); | |
101 }, | |
102 | |
103 /** | |
104 * Sends NetLog data via email from browser. | |
105 */ | |
106 onSendData_: function() { | |
107 chrome.send('sendNetLog'); | |
108 }, | |
109 | |
110 onExportNetLogInfoChanged: function(exportNetLogInfo) { | |
James Hawkins
2013/01/31 18:58:46
nit: Document method.
ramant (doing other things)
2013/01/31 19:58:26
Done.
| |
111 if (exportNetLogInfo.file) { | |
112 var message = ''; | |
113 if (exportNetLogInfo.state == 'ALLOW_STOP') | |
114 message = 'NetLog data is collected in: '; | |
115 else if (exportNetLogInfo.state == 'ALLOW_START_SEND') | |
116 message = 'NetLog data to send is in: '; | |
117 $(FILE_PATH_TEXT_ID).textContent = message + exportNetLogInfo.file; | |
118 } else { | |
119 $(FILE_PATH_TEXT_ID).textContent = ''; | |
120 } | |
121 | |
122 $(START_DATA_BUTTON_ID).disabled = true; | |
123 $(STOP_DATA_BUTTON_ID).disabled = true; | |
124 $(SEND_DATA_BUTTON_ID).disabled = true; | |
125 if (exportNetLogInfo.state == 'ALLOW_START') { | |
126 $(START_DATA_BUTTON_ID).disabled = false; | |
127 } else if (exportNetLogInfo.state == 'ALLOW_STOP') { | |
128 $(STOP_DATA_BUTTON_ID).disabled = false; | |
129 } else if (exportNetLogInfo.state == 'ALLOW_START_SEND') { | |
130 $(START_DATA_BUTTON_ID).disabled = false; | |
131 $(SEND_DATA_BUTTON_ID).disabled = false; | |
132 } else if (exportNetLogInfo.state == 'UNINITIALIZED') { | |
133 $(FILE_PATH_TEXT_ID).textContent = | |
134 'Unable to initialize NetLog data file.'; | |
135 } | |
136 } | |
137 }; | |
138 | |
139 return MainView; | |
140 })(); | |
OLD | NEW |