summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorachuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-05 01:34:34 +0000
committerachuith@chromium.org <achuith@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-05 01:34:34 +0000
commit34c6ef8c58c3df0d124439919f2a9034c5471978 (patch)
tree5d65b3d5bc2381832a3cd383075dee93cff6fb8f
parent7714cb32c8694e3798a5be3aa7fdcdf924080ac5 (diff)
downloadchromium_src-34c6ef8c58c3df0d124439919f2a9034c5471978.zip
chromium_src-34c6ef8c58c3df0d124439919f2a9034c5471978.tar.gz
chromium_src-34c6ef8c58c3df0d124439919f2a9034c5471978.tar.bz2
ONC import option to chromeos tab in chrome://net-internals
Add chromeos tab to chrome://net-internals. Move ONC file import input field to chromeos tab, from network options. Support for encrypted onc files. Fix net_internals browser test. BUG=chromium-os:23472,chromium-os:19397 TEST=Go to chrome://net-internals, click on chromeos tab. Should be able to import an onc file from there. If the file is encrypted, should be prompted for a passcode. Review URL: http://codereview.chromium.org/8741009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112952 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/resources/net_internals/browser_bridge.js42
-rw-r--r--chrome/browser/resources/net_internals/category_tabs.html1
-rw-r--r--chrome/browser/resources/net_internals/chromeos_view.css10
-rw-r--r--chrome/browser/resources/net_internals/chromeos_view.html12
-rw-r--r--chrome/browser/resources/net_internals/chromeos_view.js145
-rw-r--r--chrome/browser/resources/net_internals/index.html2
-rw-r--r--chrome/browser/resources/net_internals/index.js1
-rw-r--r--chrome/browser/resources/net_internals/main.css5
-rw-r--r--chrome/browser/resources/net_internals/main.js2
-rw-r--r--chrome/browser/ui/webui/net_internals_ui.cc21
-rw-r--r--chrome/test/data/webui/net_internals/log_util.js3
-rw-r--r--chrome/test/data/webui/net_internals/main.js3
-rw-r--r--chrome/test/data/webui/net_internals/net_internals_test.js3
13 files changed, 234 insertions, 16 deletions
diff --git a/chrome/browser/resources/net_internals/browser_bridge.js b/chrome/browser/resources/net_internals/browser_bridge.js
index fa13d48..6a2d308 100644
--- a/chrome/browser/resources/net_internals/browser_bridge.js
+++ b/chrome/browser/resources/net_internals/browser_bridge.js
@@ -25,6 +25,7 @@ var BrowserBridge = (function() {
this.hstsObservers_ = [];
this.httpThrottlingObservers_ = [];
this.constantsObservers_ = [];
+ this.crosONCFileParseObservers_ = [];
this.pollableDataHelpers_ = {};
this.pollableDataHelpers_.proxySettings =
@@ -224,6 +225,10 @@ var BrowserBridge = (function() {
this.send('getSystemLog', [log_key, cellId]);
},
+ importONCFile: function(fileContent, passcode) {
+ this.send('importONCFile', [fileContent, passcode]);
+ },
+
//--------------------------------------------------------------------------
// Messages received from the browser.
//--------------------------------------------------------------------------
@@ -236,7 +241,7 @@ var BrowserBridge = (function() {
},
receivedConstants: function(constants) {
- for (var i = 0; i < this.constantsObservers_.length; ++i)
+ for (var i = 0; i < this.constantsObservers_.length; i++)
this.constantsObservers_[i].onReceivedConstants(constants);
},
@@ -283,40 +288,45 @@ var BrowserBridge = (function() {
},
receivedStartConnectionTestSuite: function() {
- for (var i = 0; i < this.connectionTestsObservers_.length; ++i)
+ for (var i = 0; i < this.connectionTestsObservers_.length; i++)
this.connectionTestsObservers_[i].onStartedConnectionTestSuite();
},
receivedStartConnectionTestExperiment: function(experiment) {
- for (var i = 0; i < this.connectionTestsObservers_.length; ++i) {
+ for (var i = 0; i < this.connectionTestsObservers_.length; i++) {
this.connectionTestsObservers_[i].onStartedConnectionTestExperiment(
experiment);
}
},
receivedCompletedConnectionTestExperiment: function(info) {
- for (var i = 0; i < this.connectionTestsObservers_.length; ++i) {
+ for (var i = 0; i < this.connectionTestsObservers_.length; i++) {
this.connectionTestsObservers_[i].onCompletedConnectionTestExperiment(
info.experiment, info.result);
}
},
receivedCompletedConnectionTestSuite: function() {
- for (var i = 0; i < this.connectionTestsObservers_.length; ++i)
+ for (var i = 0; i < this.connectionTestsObservers_.length; i++)
this.connectionTestsObservers_[i].onCompletedConnectionTestSuite();
},
receivedHSTSResult: function(info) {
- for (var i = 0; i < this.hstsObservers_.length; ++i)
+ for (var i = 0; i < this.hstsObservers_.length; i++)
this.hstsObservers_[i].onHSTSQueryResult(info);
},
+ receivedONCFileParse: function(status) {
+ for (var i = 0; i < this.crosONCFileParseObservers_.length; i++)
+ this.crosONCFileParseObservers_[i].onONCFileParse(status);
+ },
+
receivedHttpCacheInfo: function(info) {
this.pollableDataHelpers_.httpCacheInfo.update(info);
},
receivedHttpThrottlingEnabledPrefChanged: function(enabled) {
- for (var i = 0; i < this.httpThrottlingObservers_.length; ++i) {
+ for (var i = 0; i < this.httpThrottlingObservers_.length; i++) {
this.httpThrottlingObservers_[i].onHttpThrottlingEnabledPrefChanged(
enabled);
}
@@ -485,6 +495,16 @@ var BrowserBridge = (function() {
},
/**
+ * Adds a listener for ONC file parse status. The observer will be called
+ * back with:
+ *
+ * observer.onONCFileParse(status);
+ */
+ addCrosONCFileParseObserver: function(observer) {
+ this.crosONCFileParseObservers_.push(observer);
+ },
+
+ /**
* Adds a listener for HTTP throttling-related events. |observer| will be
* called back when HTTP throttling is enabled/disabled, through:
*
@@ -558,7 +578,7 @@ var BrowserBridge = (function() {
},
isObserver: function(object) {
- for (var i = 0; i < this.observerInfos_.length; ++i) {
+ for (var i = 0; i < this.observerInfos_.length; i++) {
if (this.observerInfos_[i].observer === object)
return true;
}
@@ -574,7 +594,7 @@ var BrowserBridge = (function() {
},
removeObserver: function(observer) {
- for (var i = 0; i < this.observerInfos_.length; ++i) {
+ for (var i = 0; i < this.observerInfos_.length; i++) {
if (this.observerInfos_[i].observer === observer) {
this.observerInfos_.splice(i, 1);
return;
@@ -600,7 +620,7 @@ var BrowserBridge = (function() {
}
// Notify the observers of the change, as needed.
- for (var i = 0; i < this.observerInfos_.length; ++i) {
+ for (var i = 0; i < this.observerInfos_.length; i++) {
var observerInfo = this.observerInfos_[i];
if (changed || !observerInfo.hasReceivedData ||
!observerInfo.ignoreWhenUnchanged) {
@@ -615,7 +635,7 @@ var BrowserBridge = (function() {
* (i.e. is visible).
*/
hasActiveObserver: function() {
- for (var i = 0; i < this.observerInfos_.length; ++i) {
+ for (var i = 0; i < this.observerInfos_.length; i++) {
if (this.observerInfos_[i].observer.isActive())
return true;
}
diff --git a/chrome/browser/resources/net_internals/category_tabs.html b/chrome/browser/resources/net_internals/category_tabs.html
index 037811e..e617a20 100644
--- a/chrome/browser/resources/net_internals/category_tabs.html
+++ b/chrome/browser/resources/net_internals/category_tabs.html
@@ -18,6 +18,7 @@
<!-- Tab is only shown on ChromeOS -->
<a href="#logs" id=tab-handle-logs style="display: none;">Logs</a>
<a href="#prerender" id=tab-handle-prerender>Prerender</a>
+ <a href="#chromeos" id=tab-handle-chromeos>ChromeOS</a>
</div>
<!-- Splitter Box: This is a handle to resize the vertical divider -->
diff --git a/chrome/browser/resources/net_internals/chromeos_view.css b/chrome/browser/resources/net_internals/chromeos_view.css
new file mode 100644
index 0000000..c96293f
--- /dev/null
+++ b/chrome/browser/resources/net_internals/chromeos_view.css
@@ -0,0 +1,10 @@
+/*
+ * 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.
+ * */
+
+#chromeos-view-password-div,
+#chromeos-view-parse-status {
+ margin-top: 20px;
+}
diff --git a/chrome/browser/resources/net_internals/chromeos_view.html b/chrome/browser/resources/net_internals/chromeos_view.html
new file mode 100644
index 0000000..b985ee2
--- /dev/null
+++ b/chrome/browser/resources/net_internals/chromeos_view.html
@@ -0,0 +1,12 @@
+<div id="chromeos-view-tab-content">
+ <h3>Import ONC file</h3>
+ <input type="file" id="chromeos-view-import-onc">
+ <div id="chromeos-view-password-div" hidden>
+ This onc file appears to be encrypted. Please provide the decryption key:
+ <div>
+ <input type="password" id="chromeos-view-onc-password">
+ </div>
+ </div>
+ <div id="chromeos-view-parse-status" hidden>
+ </div>
+</div>
diff --git a/chrome/browser/resources/net_internals/chromeos_view.js b/chrome/browser/resources/net_internals/chromeos_view.js
new file mode 100644
index 0000000..c20f806
--- /dev/null
+++ b/chrome/browser/resources/net_internals/chromeos_view.js
@@ -0,0 +1,145 @@
+// 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.
+ *
+ * @private
+ */
+ function importONCFile_() {
+ if (fileContent)
+ g_browser.importONCFile(fileContent, passcode);
+ else
+ setParseStatus_(false);
+ }
+
+ /**
+ * Set the passcode var, and trigger onc import.
+ *
+ * @private
+ * @param {string} passcode
+ */
+ function setPasscode_(value) {
+ passcode = value;
+ if (passcode)
+ importONCFile_();
+ }
+
+ /**
+ * Unhide the passcode prompt input field and give it focus.
+ *
+ * @private
+ */
+ 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.
+ *
+ * @private
+ * @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.
+ *
+ * @private
+ */
+ 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.
+ *
+ * @private
+ */
+ 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.
+ *
+ * @private
+ */
+ 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;
+})();
diff --git a/chrome/browser/resources/net_internals/index.html b/chrome/browser/resources/net_internals/index.html
index 605e993..a1944bf 100644
--- a/chrome/browser/resources/net_internals/index.html
+++ b/chrome/browser/resources/net_internals/index.html
@@ -11,6 +11,7 @@ found in the LICENSE file.
<link rel="stylesheet" href="timeline_view.css">
<link rel="stylesheet" href="logs_view.css">
<link rel="stylesheet" href="tab_switcher_view.css">
+ <link rel="stylesheet" href="chromeos_view.css">
<script src="chrome://resources/js/util.js"></script>
<script src="chrome://resources/js/cr.js"></script>
<script src="chrome://net-internals/index.js"></script>
@@ -46,6 +47,7 @@ found in the LICENSE file.
<include src="events_view.html"/>
<include src="timeline_view.html"/>
<include src="logs_view.html"/>
+ <include src="chromeos_view.html"/>
<script src="chrome://resources/js/i18n_template.js"></script>
<script src="chrome://resources/js/i18n_process.js"></script>
diff --git a/chrome/browser/resources/net_internals/index.js b/chrome/browser/resources/net_internals/index.js
index 936f044..b67f9fa 100644
--- a/chrome/browser/resources/net_internals/index.js
+++ b/chrome/browser/resources/net_internals/index.js
@@ -38,6 +38,7 @@
<include src="http_throttling_view.js"/>
<include src="logs_view.js"/>
<include src="prerender_view.js"/>
+<include src="chromeos_view.js"/>
document.addEventListener('DOMContentLoaded', function() {
MainView.getInstance(); // from main.js
diff --git a/chrome/browser/resources/net_internals/main.css b/chrome/browser/resources/net_internals/main.css
index 230c50e..3b7c2ed 100644
--- a/chrome/browser/resources/net_internals/main.css
+++ b/chrome/browser/resources/net_internals/main.css
@@ -57,8 +57,9 @@ body {
#test-view-tab-content,
#hsts-view-tab-content,
#http-throttling-view-tab-content,
+#logs-view-tab-content,
#prerender-view-tab-content,
-#logs-view-tab-content {
+#chromeos-view-tab-content {
overflow: auto;
padding: 10px;
}
@@ -67,7 +68,7 @@ body {
* Styles for TABLE that uses a thin collapsed border.
*/
table.styledTable {
- border-collapse:collapse;
+ border-collapse: collapse;
}
table.styledTable,
diff --git a/chrome/browser/resources/net_internals/main.js b/chrome/browser/resources/net_internals/main.js
index e1334e2..f5b39ae 100644
--- a/chrome/browser/resources/net_internals/main.js
+++ b/chrome/browser/resources/net_internals/main.js
@@ -102,6 +102,8 @@ var MainView = (function() {
false, cr.isChromeOS);
tabs.addTab(PrerenderView.TAB_HANDLE_ID, PrerenderView.getInstance(),
false, true);
+ tabs.addTab(CrosView.TAB_HANDLE_ID, CrosView.getInstance(),
+ false, cr.isChromeOS);
// Build a map from the anchor name of each tab handle to its "tab ID".
// We will consider navigations to the #hash as a switch tab request.
diff --git a/chrome/browser/ui/webui/net_internals_ui.cc b/chrome/browser/ui/webui/net_internals_ui.cc
index b587873..8660432 100644
--- a/chrome/browser/ui/webui/net_internals_ui.cc
+++ b/chrome/browser/ui/webui/net_internals_ui.cc
@@ -66,6 +66,7 @@
#ifdef OS_CHROMEOS
#include "chrome/browser/chromeos/cros/cros_library.h"
+#include "chrome/browser/chromeos/cros/network_library.h"
#include "chrome/browser/chromeos/system/syslogs_provider.h"
#endif
#ifdef OS_WIN
@@ -180,6 +181,7 @@ class NetInternalsMessageHandler
#ifdef OS_CHROMEOS
void OnRefreshSystemLogs(const ListValue* list);
void OnGetSystemLog(const ListValue* list);
+ void OnImportONCFile(const ListValue* list);
#endif
private:
@@ -560,6 +562,10 @@ void NetInternalsMessageHandler::RegisterMessages() {
"getSystemLog",
base::Bind(&NetInternalsMessageHandler::OnGetSystemLog,
base::Unretained(this)));
+ web_ui_->RegisterMessageCallback(
+ "importONCFile",
+ base::Bind(&NetInternalsMessageHandler::OnImportONCFile,
+ base::Unretained(this)));
#endif
}
@@ -1279,6 +1285,21 @@ void NetInternalsMessageHandler::OnGetSystemLog(const ListValue* list) {
DCHECK(syslogs_getter_.get());
syslogs_getter_->RequestSystemLog(list);
}
+
+void NetInternalsMessageHandler::OnImportONCFile(const ListValue* list) {
+ std::string onc_blob;
+ std::string passcode;
+ if (list->GetSize() != 2 ||
+ !list->GetString(0, &onc_blob) ||
+ !list->GetString(1, &passcode)) {
+ NOTREACHED();
+ }
+
+ const bool success = chromeos::CrosLibrary::Get()->GetNetworkLibrary()->
+ LoadOncNetworks(onc_blob, passcode);
+ SendJavascriptCommand("receivedONCFileParse",
+ Value::CreateBooleanValue(success));
+}
#endif
void NetInternalsMessageHandler::IOThreadImpl::OnSetLogLevel(
diff --git a/chrome/test/data/webui/net_internals/log_util.js b/chrome/test/data/webui/net_internals/log_util.js
index ccc367b..70816ca 100644
--- a/chrome/test/data/webui/net_internals/log_util.js
+++ b/chrome/test/data/webui/net_internals/log_util.js
@@ -29,7 +29,8 @@ netInternalsTest.test('netInternalsExportImportDump', function() {
tests: false,
hsts: false,
logs: false,
- prerender: true
+ prerender: true,
+ chromeos: false
};
netInternalsTest.checkTabHandleVisibility(tabVisibilityState, false);
diff --git a/chrome/test/data/webui/net_internals/main.js b/chrome/test/data/webui/net_internals/main.js
index be35eb7..e88779e 100644
--- a/chrome/test/data/webui/net_internals/main.js
+++ b/chrome/test/data/webui/net_internals/main.js
@@ -30,7 +30,8 @@ netInternalsTest.test('netInternalsTourTabs', function() {
tests: true,
hsts: true,
logs: cr.isChromeOS,
- prerender: true
+ prerender: true,
+ chromeos: cr.isChromeOS
};
netInternalsTest.checkTabHandleVisibility(tabVisibilityState, true);
diff --git a/chrome/test/data/webui/net_internals/net_internals_test.js b/chrome/test/data/webui/net_internals/net_internals_test.js
index fc4f587..1b86a6e 100644
--- a/chrome/test/data/webui/net_internals/net_internals_test.js
+++ b/chrome/test/data/webui/net_internals/net_internals_test.js
@@ -45,7 +45,8 @@ var netInternalsTest = (function() {
tests: TestView.TAB_HANDLE_ID,
hsts: HSTSView.TAB_HANDLE_ID,
logs: LogsView.TAB_HANDLE_ID,
- prerender: PrerenderView.TAB_HANDLE_ID
+ prerender: PrerenderView.TAB_HANDLE_ID,
+ chromeos: CrosView.TAB_HANDLE_ID
};
/**