Chromium Code Reviews
|
| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 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 * This view displays information on ChromeOS specific features. | |
| 7 */ | |
| 8 var CrosView = (function() { | |
| 9 'use strict'; | |
| 10 | |
| 11 var fileContent; | |
| 12 var passcode = ''; | |
| 13 | |
| 14 /** | |
| 15 * Send file contents and passcode to C++ cros network library. | |
| 16 */ | |
| 17 function importONCFile() { | |
| 18 if (fileContent) { | |
|
James Hawkins
2011/12/04 18:13:07
No braces for single-line logic blocks.
achuithb
2011/12/04 21:56:42
In C++, you need braces for single line blocks wit
James Hawkins
2011/12/04 22:11:54
From the C++ style guide:
"In general, curly brac
achuithb
2011/12/07 18:49:28
Ah, thanks for the explanation. Yes, I was indeed
| |
| 19 g_browser.importONCFile(fileContent, passcode); | |
| 20 } else { | |
| 21 setParseStatus(false); | |
| 22 } | |
| 23 } | |
| 24 | |
| 25 /** | |
| 26 * Set the passcode var, and trigger onc import. | |
| 27 * | |
| 28 * @param {string} passcode | |
| 29 */ | |
| 30 function setPasscode(value) { | |
| 31 passcode = value; | |
| 32 if (passcode) | |
| 33 importONCFile(); | |
| 34 } | |
| 35 | |
| 36 /** | |
| 37 * Unhide the passcode prompt input field and give it focus. | |
| 38 */ | |
| 39 function promptForPasscode() { | |
| 40 $(CrosView.PASSCODE_ID).hidden = false; | |
| 41 $(CrosView.PASSCODE_INPUT_ID).focus(); | |
| 42 $(CrosView.PASSCODE_INPUT_ID).select(); | |
| 43 } | |
| 44 | |
| 45 /** | |
| 46 * Set the fileContent var, and trigger onc import if the file appears to | |
| 47 * not be encrypted, or prompt for passcode if the file is encrypted. | |
| 48 * | |
| 49 * @param {string} text contents of selected file. | |
| 50 */ | |
| 51 function setFileContent(result) { | |
| 52 fileContent = result; | |
| 53 // Check if file is encrypted. | |
| 54 if (fileContent.search(/begin pgp message/i) == -1) { | |
| 55 // Not encrypted, don't need passcode. | |
| 56 importONCFile(); | |
| 57 } else { | |
| 58 promptForPasscode(); | |
| 59 } | |
| 60 } | |
| 61 | |
| 62 /** | |
| 63 * Set ONC file parse status. | |
| 64 * | |
| 65 */ | |
| 66 function setParseStatus(success) { | |
| 67 var parseStatus = $(CrosView.PARSE_STATUS_ID); | |
| 68 parseStatus.hidden = false; | |
| 69 parseStatus.textContent = status ? | |
| 70 "ONC file successfully parsed" : "ONC file parse failed"; | |
| 71 reset(); | |
| 72 } | |
| 73 | |
| 74 /** | |
| 75 * Add event listeners for the file selection and passcode input fields. | |
| 76 */ | |
| 77 function addEventListeners() { | |
| 78 $(CrosView.IMPORT_ONC_ID).addEventListener('change', function(event) { | |
| 79 $(CrosView.PARSE_STATUS_ID).hidden = true; | |
| 80 var file = event.target.files[0]; | |
| 81 var reader = new FileReader(); | |
| 82 reader.onloadend = function(e) { | |
| 83 setFileContent(this.result); | |
| 84 }; | |
| 85 reader.readAsText(file); | |
| 86 }, false); | |
| 87 | |
| 88 $(CrosView.PASSCODE_INPUT_ID).addEventListener('change', function(event) { | |
| 89 setPasscode(this.value); | |
| 90 }, false); | |
| 91 } | |
| 92 | |
| 93 /** | |
| 94 * Reset fileContent and passcode vars. | |
| 95 */ | |
| 96 function reset() { | |
| 97 fileContent = undefined; | |
| 98 passcode = ''; | |
| 99 $(CrosView.PASSCODE_ID).hidden = true; | |
| 100 } | |
| 101 | |
| 102 /** | |
| 103 * @constructor | |
| 104 * @extends {DivView} | |
| 105 */ | |
| 106 function CrosView() { | |
| 107 assertFirstConstructorCall(CrosView); | |
| 108 | |
| 109 // Call superclass's constructor. | |
| 110 DivView.call(this, CrosView.MAIN_BOX_ID); | |
| 111 | |
| 112 g_browser.addCrosONCFileParseObserver(this); | |
| 113 addEventListeners(); | |
| 114 } | |
| 115 | |
| 116 // ID for special HTML element in category_tabs.html | |
| 117 CrosView.TAB_HANDLE_ID = 'tab-handle-chromeos'; | |
| 118 | |
| 119 CrosView.MAIN_BOX_ID = 'chromeos-view-tab-content'; | |
| 120 CrosView.IMPORT_ONC_ID = 'chromeos-view-import-onc'; | |
| 121 CrosView.PASSCODE_ID = 'chromeos-view-password-div'; | |
| 122 CrosView.PASSCODE_INPUT_ID = 'chromeos-view-onc-password'; | |
| 123 CrosView.PARSE_STATUS_ID = 'chromeos-view-parse-status'; | |
| 124 | |
| 125 cr.addSingletonGetter(CrosView); | |
| 126 | |
| 127 CrosView.prototype = { | |
| 128 // Inherit from DivView. | |
| 129 __proto__: DivView.prototype, | |
| 130 | |
| 131 onONCFileParse: setParseStatus, | |
| 132 }; | |
| 133 | |
| 134 return CrosView; | |
| 135 })(); | |
| OLD | NEW |