Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4467)

Unified Diff: chrome/browser/resources/net_internals/chromeos_view.js

Issue 8741009: ONC import option to chromeos tab in chrome://net-internals (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: move status text to js Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/net_internals/chromeos_view.js
===================================================================
--- chrome/browser/resources/net_internals/chromeos_view.js (revision 0)
+++ chrome/browser/resources/net_internals/chromeos_view.js (revision 0)
@@ -0,0 +1,135 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * This view displays information on ChromeOS specific features.
+ */
+var CrosView = (function() {
+ 'use strict';
+
+ var fileContent;
+ var passcode = '';
+
+ /**
+ * Send file contents and passcode to C++ cros network library.
+ */
+ function importONCFile() {
+ 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
+ g_browser.importONCFile(fileContent, passcode);
+ } else {
+ setParseStatus(false);
+ }
+ }
+
+ /**
+ * Set the passcode var, and trigger onc import.
+ *
+ * @param {string} passcode
+ */
+ function setPasscode(value) {
+ passcode = value;
+ if (passcode)
+ importONCFile();
+ }
+
+ /**
+ * Unhide the passcode prompt input field and give it focus.
+ */
+ function promptForPasscode() {
+ $(CrosView.PASSCODE_ID).hidden = false;
+ $(CrosView.PASSCODE_INPUT_ID).focus();
+ $(CrosView.PASSCODE_INPUT_ID).select();
+ }
+
+ /**
+ * Set the fileContent var, and trigger onc import if the file appears to
+ * not be encrypted, or prompt for passcode if the file is encrypted.
+ *
+ * @param {string} text contents of selected file.
+ */
+ function setFileContent(result) {
+ fileContent = result;
+ // Check if file is encrypted.
+ if (fileContent.search(/begin pgp message/i) == -1) {
+ // Not encrypted, don't need passcode.
+ importONCFile();
+ } else {
+ promptForPasscode();
+ }
+ }
+
+ /**
+ * Set ONC file parse status.
+ *
+ */
+ function setParseStatus(success) {
+ var parseStatus = $(CrosView.PARSE_STATUS_ID);
+ parseStatus.hidden = false;
+ parseStatus.textContent = status ?
+ "ONC file successfully parsed" : "ONC file parse failed";
+ reset();
+ }
+
+ /**
+ * Add event listeners for the file selection and passcode input fields.
+ */
+ function addEventListeners() {
+ $(CrosView.IMPORT_ONC_ID).addEventListener('change', function(event) {
+ $(CrosView.PARSE_STATUS_ID).hidden = true;
+ var file = event.target.files[0];
+ var reader = new FileReader();
+ reader.onloadend = function(e) {
+ setFileContent(this.result);
+ };
+ reader.readAsText(file);
+ }, false);
+
+ $(CrosView.PASSCODE_INPUT_ID).addEventListener('change', function(event) {
+ setPasscode(this.value);
+ }, false);
+ }
+
+ /**
+ * Reset fileContent and passcode vars.
+ */
+ function reset() {
+ fileContent = undefined;
+ passcode = '';
+ $(CrosView.PASSCODE_ID).hidden = true;
+ }
+
+ /**
+ * @constructor
+ * @extends {DivView}
+ */
+ function CrosView() {
+ assertFirstConstructorCall(CrosView);
+
+ // Call superclass's constructor.
+ DivView.call(this, CrosView.MAIN_BOX_ID);
+
+ g_browser.addCrosONCFileParseObserver(this);
+ addEventListeners();
+ }
+
+ // ID for special HTML element in category_tabs.html
+ CrosView.TAB_HANDLE_ID = 'tab-handle-chromeos';
+
+ CrosView.MAIN_BOX_ID = 'chromeos-view-tab-content';
+ CrosView.IMPORT_ONC_ID = 'chromeos-view-import-onc';
+ CrosView.PASSCODE_ID = 'chromeos-view-password-div';
+ CrosView.PASSCODE_INPUT_ID = 'chromeos-view-onc-password';
+ CrosView.PARSE_STATUS_ID = 'chromeos-view-parse-status';
+
+ cr.addSingletonGetter(CrosView);
+
+ CrosView.prototype = {
+ // Inherit from DivView.
+ __proto__: DivView.prototype,
+
+ onONCFileParse: setParseStatus,
+ };
+
+ return CrosView;
+})();
Property changes on: chrome/browser/resources/net_internals/chromeos_view.js
___________________________________________________________________
Added: svn:eol-style
+ LF

Powered by Google App Engine
This is Rietveld 408576698