cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chrome / browser / resources / net_internals / chromeos_view.js
blobf71bb3d188115d815fb38ac49d27fed87c7586e4
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.
5 /**
6 * This view displays information on ChromeOS specific features.
7 */
8 var CrosView = (function() {
9 'use strict';
11 var fileContent;
12 var passcode = '';
14 /**
15 * Clear file input div
17 * @private
19 function clearFileInput_() {
20 $(CrosView.IMPORT_DIV_ID).innerHTML = $(CrosView.IMPORT_DIV_ID).innerHTML;
21 $(CrosView.IMPORT_ONC_ID).addEventListener('change',
22 handleFileChangeEvent_,
23 false);
26 /**
27 * Send file contents and passcode to C++ cros network library.
29 * @private
31 function importONCFile_() {
32 clearParseStatus_();
33 if (fileContent)
34 g_browser.importONCFile(fileContent, passcode);
35 else
36 setParseStatus_('ONC file parse failed: cannot read file');
37 clearFileInput_();
40 /**
41 * Set the passcode var, and trigger onc import.
43 * @param {string} value The passcode value.
44 * @private
46 function setPasscode_(value) {
47 passcode = value;
48 if (passcode)
49 importONCFile_();
52 /**
53 * Unhide the passcode prompt input field and give it focus.
55 * @private
57 function promptForPasscode_() {
58 $(CrosView.PASSCODE_ID).hidden = false;
59 $(CrosView.PASSCODE_INPUT_ID).focus();
60 $(CrosView.PASSCODE_INPUT_ID).select();
63 /**
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.
67 * @private
68 * @param {string} text contents of selected file.
70 function setFileContent_(result) {
71 fileContent = result;
72 // Parse the JSON to get at the top level "Type" property.
73 var jsonObject;
74 // Ignore any parse errors: they'll get handled in the C++ import code.
75 try {
76 jsonObject = JSON.parse(fileContent);
77 } catch (error) {}
78 // Check if file is encrypted.
79 if (jsonObject &&
80 jsonObject.hasOwnProperty('Type') &&
81 jsonObject.Type == 'EncryptedConfiguration') {
82 promptForPasscode_();
83 } else {
84 importONCFile_();
88 /**
89 * Clear ONC file parse status. Clears and hides the parse status div.
91 * @private
93 function clearParseStatus_(error) {
94 var parseStatus = $(CrosView.PARSE_STATUS_ID);
95 parseStatus.hidden = true;
96 parseStatus.textContent = '';
99 /**
100 * Set ONC file parse status.
102 * @private
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';
109 reset_();
113 * Set storing debug logs status.
115 * @private
117 function setStoreDebugLogsStatus_(status) {
118 $(CrosView.STORE_DEBUG_LOGS_STATUS_ID).innerText = status;
122 * Set status for current debug mode.
124 * @private
126 function setNetworkDebugModeStatus_(status) {
127 $(CrosView.DEBUG_STATUS_ID).innerText = status;
131 * An event listener for the file selection field.
133 * @private
135 function handleFileChangeEvent_(event) {
136 clearParseStatus_();
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.
150 * @private
152 function addEventListeners_() {
153 $(CrosView.IMPORT_ONC_ID).addEventListener('change',
154 handleFileChangeEvent_,
155 false);
157 $(CrosView.PASSCODE_INPUT_ID).addEventListener('change', function(event) {
158 setPasscode_(this.value);
159 }, false);
161 $(CrosView.STORE_DEBUG_LOGS_ID).addEventListener('click', function(event) {
162 $(CrosView.STORE_DEBUG_LOGS_STATUS_ID).innerText = '';
163 g_browser.storeDebugLogs();
164 }, false);
166 $(CrosView.DEBUG_WIFI_ID).addEventListener('click', function(event) {
167 setNetworkDebugMode_('wifi');
168 }, false);
169 $(CrosView.DEBUG_ETHERNET_ID).addEventListener('click', function(event) {
170 setNetworkDebugMode_('ethernet');
171 }, false);
172 $(CrosView.DEBUG_CELLULAR_ID).addEventListener('click', function(event) {
173 setNetworkDebugMode_('cellular');
174 }, false);
175 $(CrosView.DEBUG_WIMAX_ID).addEventListener('click', function(event) {
176 setNetworkDebugMode_('wimax');
177 }, false);
178 $(CrosView.DEBUG_NONE_ID).addEventListener('click', function(event) {
179 setNetworkDebugMode_('none');
180 }, false);
184 * Reset fileContent and passcode vars.
186 * @private
188 function reset_() {
189 fileContent = undefined;
190 passcode = '';
191 $(CrosView.PASSCODE_ID).hidden = true;
195 * Enables or disables debug mode for a specified subsystem.
197 * @private
199 function setNetworkDebugMode_(subsystem) {
200 $(CrosView.DEBUG_STATUS_ID).innerText = '';
201 g_browser.setNetworkDebugMode(subsystem);
205 * @constructor
206 * @extends {DivView}
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_,
250 return CrosView;
251 })();