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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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 // We inherit from DivView.
12 var superClass = DivView;
13
14 var fileContent;
15 var passcode = '';
16 function importONCFile() {
17 g_browser.importONCFile(fileContent, passcode);
18 }
19
20 function setPasscode(value) {
21 passcode = value;
22 if (passcode) {
23 importONCFile();
24 }
25 }
26
27 function promptForPasscode() {
28 $(CrosView.PASSWORD_ID).hidden = false;
29 $(CrosView.PASSWORD_INPUT_ID).focus();
30 $(CrosView.PASSWORD_INPUT_ID).select();
31 }
32
33 function setFileContent(result) {
34 fileContent = result;
35 // Check if file is encrypted.
36 if (fileContent.search(/begin pgp message/i) == -1) {
37 // Not encrypted, don't need passcode.
38 importONCFile();
39 } else {
40 promptForPasscode();
41 }
42 }
43
44 function addEventListeners() {
45 $(CrosView.IMPORT_ONC_ID).addEventListener('change', function(event) {
46 $(CrosView.PARSE_STATUS_ID).hidden = true;
47 var file = event.target.files[0];
48 var reader = new FileReader();
49 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
50 setFileContent(this.result);
51 };
52 reader.readAsText(file);
53 }, false);
54
55 $(CrosView.PASSWORD_INPUT_ID).addEventListener('change', function(event) {
56 setPasscode(this.value);
57 }, false);
58 }
59
60 function reset() {
61 fileContent = undefined;
62 passcode = '';
63 $(CrosView.PASSWORD_ID).hidden = true;
64 }
65
66 /**
67 * @constructor
68 */
69 function CrosView() {
70 assertFirstConstructorCall(CrosView);
71
72 // Call superclass's constructor.
73 superClass.call(this, CrosView.MAIN_BOX_ID);
74
75 g_browser.addCrosONCFileParseObserver(this);
76 addEventListeners();
77 }
78
79 // ID for special HTML element in category_tabs.html
80 CrosView.TAB_HANDLE_ID = 'tab-handle-chromeos';
81
82 CrosView.MAIN_BOX_ID = 'chromeos-view-tab-content';
83 CrosView.IMPORT_ONC_ID = 'chromeos-view-import-onc';
84 CrosView.PASSWORD_ID = 'chromeos-view-password-div';
85 CrosView.PASSWORD_INPUT_ID = 'chromeos-view-onc-password';
86 CrosView.PARSE_STATUS_ID = 'chromeos-view-parse-status';
87
88 cr.addSingletonGetter(CrosView);
89
90 CrosView.prototype = {
91 // Inherit the superclass's methods.
92 __proto__: superClass.prototype,
93
94 onONCFileParse: function(status) {
95 var parseStatus = $(CrosView.PARSE_STATUS_ID);
96 parseStatus.hidden = false;
97 parseStatus.textContent = status;
98 reset();
99 }
100 };
101
102 return CrosView;
103 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698