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

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: '' 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,103 @@
+// 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';
+
+ // We inherit from DivView.
+ var superClass = DivView;
+
+ var fileContent;
+ var passcode = '';
+ function importONCFile() {
+ g_browser.importONCFile(fileContent, passcode);
+ }
+
+ function setPasscode(value) {
+ passcode = value;
+ if (passcode) {
+ importONCFile();
+ }
+ }
+
+ function promptForPasscode() {
+ $(CrosView.PASSWORD_ID).hidden = false;
+ $(CrosView.PASSWORD_INPUT_ID).focus();
+ $(CrosView.PASSWORD_INPUT_ID).select();
+ }
+
+ 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();
+ }
+ }
+
+ 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) {
mmenke 2011/12/02 15:07:55 You might want to check for read errors here, and
achuithb 2011/12/02 19:49:10 Handling read errors is not trivial (probably need
+ setFileContent(this.result);
+ };
+ reader.readAsText(file);
+ }, false);
+
+ $(CrosView.PASSWORD_INPUT_ID).addEventListener('change', function(event) {
+ setPasscode(this.value);
+ }, false);
+ }
+
+ function reset() {
+ fileContent = undefined;
+ passcode = '';
+ $(CrosView.PASSWORD_ID).hidden = true;
+ }
+
+ /**
+ * @constructor
+ */
+ function CrosView() {
+ assertFirstConstructorCall(CrosView);
+
+ // Call superclass's constructor.
+ superClass.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.PASSWORD_ID = 'chromeos-view-password-div';
+ CrosView.PASSWORD_INPUT_ID = 'chromeos-view-onc-password';
+ CrosView.PARSE_STATUS_ID = 'chromeos-view-parse-status';
+
+ cr.addSingletonGetter(CrosView);
+
+ CrosView.prototype = {
+ // Inherit the superclass's methods.
+ __proto__: superClass.prototype,
+
+ onONCFileParse: function(status) {
+ var parseStatus = $(CrosView.PARSE_STATUS_ID);
+ parseStatus.hidden = false;
+ parseStatus.textContent = status;
+ reset();
+ }
+ };
+
+ 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