OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * This view displays information on ChromeOS specific features. | 6 * This view displays information on ChromeOS specific features. |
7 */ | 7 */ |
8 var CrosView = (function() { | 8 var CrosView = (function() { |
9 'use strict'; | 9 'use strict'; |
10 | 10 |
11 var fileContent; | 11 var fileContent; |
12 var passcode = ''; | 12 var passcode = ''; |
13 | 13 |
14 /** | 14 /** |
15 * Clear file input div | 15 * Clear file input div |
16 * | 16 * |
17 * @private | 17 * @private |
18 */ | 18 */ |
19 function clearFileInput_() { | 19 function clearFileInput_() { |
20 $(CrosView.IMPORT_DIV_ID).innerHTML = $(CrosView.IMPORT_DIV_ID).innerHTML; | 20 $(CrosView.IMPORT_DIV_ID).innerHTML = $(CrosView.IMPORT_DIV_ID).innerHTML; |
21 $(CrosView.IMPORT_ONC_ID).addEventListener('change', | 21 $(CrosView.IMPORT_ONC_ID) |
22 handleFileChangeEvent_, | 22 .addEventListener('change', handleFileChangeEvent_, false); |
23 false); | |
24 } | 23 } |
25 | 24 |
26 /** | 25 /** |
27 * Send file contents and passcode to C++ cros network library. | 26 * Send file contents and passcode to C++ cros network library. |
28 * | 27 * |
29 * @private | 28 * @private |
30 */ | 29 */ |
31 function importONCFile_() { | 30 function importONCFile_() { |
32 clearParseStatus_(); | 31 clearParseStatus_(); |
33 if (fileContent) | 32 if (fileContent) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 * @private | 66 * @private |
68 * @param {string} text contents of selected file. | 67 * @param {string} text contents of selected file. |
69 */ | 68 */ |
70 function setFileContent_(result) { | 69 function setFileContent_(result) { |
71 fileContent = result; | 70 fileContent = result; |
72 // Parse the JSON to get at the top level "Type" property. | 71 // Parse the JSON to get at the top level "Type" property. |
73 var jsonObject; | 72 var jsonObject; |
74 // Ignore any parse errors: they'll get handled in the C++ import code. | 73 // Ignore any parse errors: they'll get handled in the C++ import code. |
75 try { | 74 try { |
76 jsonObject = JSON.parse(fileContent); | 75 jsonObject = JSON.parse(fileContent); |
77 } catch (error) {} | 76 } catch (error) { |
| 77 } |
78 // Check if file is encrypted. | 78 // Check if file is encrypted. |
79 if (jsonObject && | 79 if (jsonObject && jsonObject.hasOwnProperty('Type') && |
80 jsonObject.hasOwnProperty('Type') && | |
81 jsonObject.Type == 'EncryptedConfiguration') { | 80 jsonObject.Type == 'EncryptedConfiguration') { |
82 promptForPasscode_(); | 81 promptForPasscode_(); |
83 } else { | 82 } else { |
84 importONCFile_(); | 83 importONCFile_(); |
85 } | 84 } |
86 } | 85 } |
87 | 86 |
88 /** | 87 /** |
89 * Clear ONC file parse status. Clears and hides the parse status div. | 88 * Clear ONC file parse status. Clears and hides the parse status div. |
90 * | 89 * |
91 * @private | 90 * @private |
92 */ | 91 */ |
93 function clearParseStatus_(error) { | 92 function clearParseStatus_(error) { |
94 var parseStatus = $(CrosView.PARSE_STATUS_ID); | 93 var parseStatus = $(CrosView.PARSE_STATUS_ID); |
95 parseStatus.hidden = true; | 94 parseStatus.hidden = true; |
96 parseStatus.textContent = ''; | 95 parseStatus.textContent = ''; |
97 } | 96 } |
98 | 97 |
99 /** | 98 /** |
100 * Set ONC file parse status. | 99 * Set ONC file parse status. |
101 * | 100 * |
102 * @private | 101 * @private |
103 */ | 102 */ |
104 function setParseStatus_(error) { | 103 function setParseStatus_(error) { |
105 var parseStatus = $(CrosView.PARSE_STATUS_ID); | 104 var parseStatus = $(CrosView.PARSE_STATUS_ID); |
106 parseStatus.hidden = false; | 105 parseStatus.hidden = false; |
107 parseStatus.textContent = error ? | 106 parseStatus.textContent = error ? 'ONC file parse failed: ' + error : |
108 'ONC file parse failed: ' + error : 'ONC file successfully parsed'; | 107 'ONC file successfully parsed'; |
109 reset_(); | 108 reset_(); |
110 } | 109 } |
111 | 110 |
112 /** | 111 /** |
113 * Set storing debug logs status. | 112 * Set storing debug logs status. |
114 * | 113 * |
115 * @private | 114 * @private |
116 */ | 115 */ |
117 function setStoreDebugLogsStatus_(status) { | 116 function setStoreDebugLogsStatus_(status) { |
118 $(CrosView.STORE_DEBUG_LOGS_STATUS_ID).innerText = status; | 117 $(CrosView.STORE_DEBUG_LOGS_STATUS_ID).innerText = status; |
(...skipping 24 matching lines...) Expand all Loading... |
143 } | 142 } |
144 | 143 |
145 /** | 144 /** |
146 * Add event listeners for the file selection, passcode input | 145 * Add event listeners for the file selection, passcode input |
147 * fields, for the button for debug logs storing and for buttons | 146 * fields, for the button for debug logs storing and for buttons |
148 * for debug mode selection. | 147 * for debug mode selection. |
149 * | 148 * |
150 * @private | 149 * @private |
151 */ | 150 */ |
152 function addEventListeners_() { | 151 function addEventListeners_() { |
153 $(CrosView.IMPORT_ONC_ID).addEventListener('change', | 152 $(CrosView.IMPORT_ONC_ID) |
154 handleFileChangeEvent_, | 153 .addEventListener('change', handleFileChangeEvent_, false); |
155 false); | |
156 | 154 |
157 $(CrosView.PASSCODE_INPUT_ID).addEventListener('change', function(event) { | 155 $(CrosView.PASSCODE_INPUT_ID).addEventListener('change', function(event) { |
158 setPasscode_(this.value); | 156 setPasscode_(this.value); |
159 }, false); | 157 }, false); |
160 | 158 |
161 $(CrosView.STORE_DEBUG_LOGS_ID).addEventListener('click', function(event) { | 159 $(CrosView.STORE_DEBUG_LOGS_ID).addEventListener('click', function(event) { |
162 $(CrosView.STORE_DEBUG_LOGS_STATUS_ID).innerText = ''; | 160 $(CrosView.STORE_DEBUG_LOGS_STATUS_ID).innerText = ''; |
163 g_browser.storeDebugLogs(); | 161 g_browser.storeDebugLogs(); |
164 }, false); | 162 }, false); |
165 | 163 |
166 $(CrosView.DEBUG_WIFI_ID).addEventListener('click', function(event) { | 164 $(CrosView.DEBUG_WIFI_ID).addEventListener('click', function(event) { |
167 setNetworkDebugMode_('wifi'); | 165 setNetworkDebugMode_('wifi'); |
168 }, false); | 166 }, false); |
169 $(CrosView.DEBUG_ETHERNET_ID).addEventListener('click', function(event) { | 167 $(CrosView.DEBUG_ETHERNET_ID).addEventListener('click', function(event) { |
170 setNetworkDebugMode_('ethernet'); | 168 setNetworkDebugMode_('ethernet'); |
171 }, false); | 169 }, false); |
172 $(CrosView.DEBUG_CELLULAR_ID).addEventListener('click', function(event) { | 170 $(CrosView.DEBUG_CELLULAR_ID).addEventListener('click', function(event) { |
173 setNetworkDebugMode_('cellular'); | 171 setNetworkDebugMode_('cellular'); |
174 }, false); | 172 }, false); |
175 $(CrosView.DEBUG_WIMAX_ID).addEventListener('click', function(event) { | 173 $(CrosView.DEBUG_WIMAX_ID).addEventListener('click', function(event) { |
176 setNetworkDebugMode_('wimax'); | 174 setNetworkDebugMode_('wimax'); |
177 }, false); | 175 }, false); |
178 $(CrosView.DEBUG_NONE_ID).addEventListener('click', function(event) { | 176 $(CrosView.DEBUG_NONE_ID).addEventListener('click', function(event) { |
179 setNetworkDebugMode_('none'); | 177 setNetworkDebugMode_('none'); |
180 }, false); | 178 }, false); |
181 } | 179 } |
182 | 180 |
183 /** | 181 /** |
184 * Reset fileContent and passcode vars. | 182 * Reset fileContent and passcode vars. |
185 * | 183 * |
186 * @private | 184 * @private |
187 */ | 185 */ |
188 function reset_() { | 186 function reset_() { |
189 fileContent = undefined; | 187 fileContent = undefined; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 // Inherit from DivView. | 240 // Inherit from DivView. |
243 __proto__: DivView.prototype, | 241 __proto__: DivView.prototype, |
244 | 242 |
245 onONCFileParse: setParseStatus_, | 243 onONCFileParse: setParseStatus_, |
246 onStoreDebugLogs: setStoreDebugLogsStatus_, | 244 onStoreDebugLogs: setStoreDebugLogsStatus_, |
247 onSetNetworkDebugMode: setNetworkDebugModeStatus_, | 245 onSetNetworkDebugMode: setNetworkDebugModeStatus_, |
248 }; | 246 }; |
249 | 247 |
250 return CrosView; | 248 return CrosView; |
251 })(); | 249 })(); |
OLD | NEW |