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.
6 * This view displays information on ChromeOS specific features.
8 var CrosView
= (function() {
15 * Clear file input div
19 function clearFileInput_() {
20 $(CrosView
.IMPORT_DIV_ID
).innerHTML
= $(CrosView
.IMPORT_DIV_ID
).innerHTML
;
21 $(CrosView
.IMPORT_ONC_ID
).addEventListener('change',
22 handleFileChangeEvent_
,
27 * Send file contents and passcode to C++ cros network library.
31 function importONCFile_() {
34 g_browser
.importONCFile(fileContent
, passcode
);
36 setParseStatus_('ONC file parse failed: cannot read file');
41 * Set the passcode var, and trigger onc import.
43 * @param {string} value The passcode value.
46 function setPasscode_(value
) {
53 * Unhide the passcode prompt input field and give it focus.
57 function promptForPasscode_() {
58 $(CrosView
.PASSCODE_ID
).hidden
= false;
59 $(CrosView
.PASSCODE_INPUT_ID
).focus();
60 $(CrosView
.PASSCODE_INPUT_ID
).select();
64 * Set the fileContent var, and trigger onc import if the file appears to
65 * not be encrypted, or prompt for passcode if the file is encrypted.
68 * @param {string} text contents of selected file.
70 function setFileContent_(result
) {
72 // Parse the JSON to get at the top level "Type" property.
74 // Ignore any parse errors: they'll get handled in the C++ import code.
76 jsonObject
= JSON
.parse(fileContent
);
78 // Check if file is encrypted.
80 jsonObject
.hasOwnProperty('Type') &&
81 jsonObject
.Type
== 'EncryptedConfiguration') {
89 * Clear ONC file parse status. Clears and hides the parse status div.
93 function clearParseStatus_(error
) {
94 var parseStatus
= $(CrosView
.PARSE_STATUS_ID
);
95 parseStatus
.hidden
= true;
96 parseStatus
.textContent
= '';
100 * Set ONC file parse status.
104 function setParseStatus_(error
) {
105 var parseStatus
= $(CrosView
.PARSE_STATUS_ID
);
106 parseStatus
.hidden
= false;
107 parseStatus
.textContent
= error
?
108 'ONC file parse failed: ' + error
: 'ONC file successfully parsed';
113 * Set storing debug logs status.
117 function setStoreDebugLogsStatus_(status
) {
118 $(CrosView
.STORE_DEBUG_LOGS_STATUS_ID
).innerText
= status
;
122 * Set status for current debug mode.
126 function setNetworkDebugModeStatus_(status
) {
127 $(CrosView
.DEBUG_STATUS_ID
).innerText
= status
;
131 * An event listener for the file selection field.
135 function handleFileChangeEvent_(event
) {
137 var file
= event
.target
.files
[0];
138 var reader
= new FileReader();
139 reader
.onloadend = function(e
) {
140 setFileContent_(reader
.result
);
142 reader
.readAsText(file
);
146 * Add event listeners for the file selection, passcode input
147 * fields, for the button for debug logs storing and for buttons
148 * for debug mode selection.
152 function addEventListeners_() {
153 $(CrosView
.IMPORT_ONC_ID
).addEventListener('change',
154 handleFileChangeEvent_
,
157 $(CrosView
.PASSCODE_INPUT_ID
).addEventListener('change', function(event
) {
158 setPasscode_(this.value
);
161 $(CrosView
.STORE_DEBUG_LOGS_ID
).addEventListener('click', function(event
) {
162 $(CrosView
.STORE_DEBUG_LOGS_STATUS_ID
).innerText
= '';
163 g_browser
.storeDebugLogs();
166 $(CrosView
.DEBUG_WIFI_ID
).addEventListener('click', function(event
) {
167 setNetworkDebugMode_('wifi');
169 $(CrosView
.DEBUG_ETHERNET_ID
).addEventListener('click', function(event
) {
170 setNetworkDebugMode_('ethernet');
172 $(CrosView
.DEBUG_CELLULAR_ID
).addEventListener('click', function(event
) {
173 setNetworkDebugMode_('cellular');
175 $(CrosView
.DEBUG_WIMAX_ID
).addEventListener('click', function(event
) {
176 setNetworkDebugMode_('wimax');
178 $(CrosView
.DEBUG_NONE_ID
).addEventListener('click', function(event
) {
179 setNetworkDebugMode_('none');
184 * Reset fileContent and passcode vars.
189 fileContent
= undefined;
191 $(CrosView
.PASSCODE_ID
).hidden
= true;
195 * Enables or disables debug mode for a specified subsystem.
199 function setNetworkDebugMode_(subsystem
) {
200 $(CrosView
.DEBUG_STATUS_ID
).innerText
= '';
201 g_browser
.setNetworkDebugMode(subsystem
);
208 function CrosView() {
209 assertFirstConstructorCall(CrosView
);
211 // Call superclass's constructor.
212 DivView
.call(this, CrosView
.MAIN_BOX_ID
);
214 g_browser
.addCrosONCFileParseObserver(this);
215 g_browser
.addStoreDebugLogsObserver(this);
216 g_browser
.addSetNetworkDebugModeObserver(this);
217 addEventListeners_();
220 CrosView
.TAB_ID
= 'tab-handle-chromeos';
221 CrosView
.TAB_NAME
= 'ChromeOS';
222 CrosView
.TAB_HASH
= '#chromeos';
224 CrosView
.MAIN_BOX_ID
= 'chromeos-view-tab-content';
225 CrosView
.IMPORT_DIV_ID
= 'chromeos-view-import-div';
226 CrosView
.IMPORT_ONC_ID
= 'chromeos-view-import-onc';
227 CrosView
.PASSCODE_ID
= 'chromeos-view-password-div';
228 CrosView
.PASSCODE_INPUT_ID
= 'chromeos-view-onc-password';
229 CrosView
.PARSE_STATUS_ID
= 'chromeos-view-parse-status';
230 CrosView
.STORE_DEBUG_LOGS_ID
= 'chromeos-view-store-debug-logs';
231 CrosView
.STORE_DEBUG_LOGS_STATUS_ID
= 'chromeos-view-store-debug-logs-status';
232 CrosView
.DEBUG_WIFI_ID
= 'chromeos-view-network-debugging-wifi';
233 CrosView
.DEBUG_ETHERNET_ID
= 'chromeos-view-network-debugging-ethernet';
234 CrosView
.DEBUG_CELLULAR_ID
= 'chromeos-view-network-debugging-cellular';
235 CrosView
.DEBUG_WIMAX_ID
= 'chromeos-view-network-debugging-wimax';
236 CrosView
.DEBUG_NONE_ID
= 'chromeos-view-network-debugging-none';
237 CrosView
.DEBUG_STATUS_ID
= 'chromeos-view-network-debugging-status';
239 cr
.addSingletonGetter(CrosView
);
241 CrosView
.prototype = {
242 // Inherit from DivView.
243 __proto__
: DivView
.prototype,
245 onONCFileParse
: setParseStatus_
,
246 onStoreDebugLogs
: setStoreDebugLogsStatus_
,
247 onSetNetworkDebugMode
: setNetworkDebugModeStatus_
,