Commit 2b49f843 authored by hshi@chromium.org's avatar hshi@chromium.org

diagnostics: Add connectivity section to chrome://diagnostics

BUG=139442
TEST=chrome://diagnostics

Review URL: https://chromiumcodereview.appspot.com/10827148

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150141 0039d316-1c4b-4281-b951-d872f2087c98
parent 331304b6
...@@ -183,7 +183,9 @@ ...@@ -183,7 +183,9 @@
<include name="IDR_CRYPTOHOME_JS" file="resources\chromeos\cryptohome.js" type="BINDATA" /> <include name="IDR_CRYPTOHOME_JS" file="resources\chromeos\cryptohome.js" type="BINDATA" />
<!-- manifest file of ChromeVox accessibility extension --> <!-- manifest file of ChromeVox accessibility extension -->
<include name="IDR_CHROMEVOX_MANIFEST" file="resources\chromeos\access_chromevox\manifest.json" type="BINDATA" /> <include name="IDR_CHROMEVOX_MANIFEST" file="resources\chromeos\access_chromevox\manifest.json" type="BINDATA" />
<include name="IDR_DIAGNOSTICS_MAIN_CSS" file="resources\chromeos\diagnostics\main.css" type="BINDATA" />
<include name="IDR_DIAGNOSTICS_MAIN_HTML" file="resources\chromeos\diagnostics\main.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_DIAGNOSTICS_MAIN_HTML" file="resources\chromeos\diagnostics\main.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_DIAGNOSTICS_MAIN_JS" file="resources\chromeos\diagnostics\main.js" type="BINDATA" />
<include name="IDR_DRIVE_INTERNALS_CSS" file="resources\chromeos\drive_internals.css" type="BINDATA" /> <include name="IDR_DRIVE_INTERNALS_CSS" file="resources\chromeos\drive_internals.css" type="BINDATA" />
<include name="IDR_DRIVE_INTERNALS_HTML" file="resources\chromeos\drive_internals.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_DRIVE_INTERNALS_HTML" file="resources\chromeos\drive_internals.html" flattenhtml="true" type="BINDATA" />
<include name="IDR_DRIVE_INTERNALS_JS" file="resources\chromeos\drive_internals.js" type="BINDATA" /> <include name="IDR_DRIVE_INTERNALS_JS" file="resources\chromeos\drive_internals.js" type="BINDATA" />
......
/* Copyright (c) 2012 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.
*/
body {
font-family: 'Chrome Droid Sans', 'Droid Sans Fallback', sans-serif;
font-size: 75%;
padding: 1em;
}
body header > h1 {
margin: 0;
padding: 21px 0 13px;
}
/* Create a border under the h1 (but before anything that gets appended
* to the end of the header, such as the managed prefs banner). */
body header > h1::after {
-webkit-margin-end: 20px;
background-color: #eee;
content: '';
display: block;
height: 1px;
position: relative;
top: 13px;
}
...@@ -3,10 +3,17 @@ ...@@ -3,10 +3,17 @@
<head> <head>
<title>diagnostics</title> <title>diagnostics</title>
<meta charset="utf-8"> <meta charset="utf-8">
<link rel="stylesheet" href="chrome://resources/css/chrome_shared.css">
<link rel="stylesheet" href="main.css">
<script src="chrome://resources/js/util.js"></script> <script src="chrome://resources/js/util.js"></script>
<script src="chrome://diagnostics/main.js"></script>
</head> </head>
<body> <body>
<h1>Diagnostics</h1> <div class="page">
<p>To be implemented. crbug.com/139442</p> <header>
<h1>Connectivity</h1>
</header>
<div id='connectivity-status'></div>
</div>
</body> </body>
</html> </html>
// Copyright (c) 2012 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.
/**
* Updates the Connectivity Status section.
* @param {String} connStatus Dictionary containing connectivity status.
*/
function updateConnectivityStatus(connStatus) {
var deviceTypes = ['wlan0', 'wwan0', 'eth0', 'eth1'];
var deviceNames = ['Wi-Fi', '3G', 'Ethernet0', 'Ethernet1'];
for (var i = 0; i < deviceTypes.length; i++) {
var deviceName = deviceNames[i];
var nameElement = document.createElement('h2');
nameElement.appendChild(document.createTextNode(deviceName));
$('connectivity-status').appendChild(nameElement);
var deviceType = deviceTypes[i];
var deviceStatus = connStatus[deviceType];
var statusMessage;
if (!deviceStatus) {
statusMessage = 'Device not found.';
} else if (!deviceStatus.flags ||
deviceStatus.flags.indexOf('up') == -1) {
statusMessage = 'Device disabled.';
} else if (!deviceStatus.ipv4) {
statusMessage = 'IPv4 address unavailable.';
} else {
statusMessage = 'IPv4 address: ' + deviceStatus.ipv4.addrs;
}
var statusElement = document.createElement('p');
statusElement.appendChild(document.createTextNode(statusMessage));
$('connectivity-status').appendChild(statusElement);
}
}
document.addEventListener('DOMContentLoaded', function() {
chrome.send('pageLoaded');
});
...@@ -5,10 +5,13 @@ ...@@ -5,10 +5,13 @@
#include "chrome/browser/ui/webui/chromeos/diagnostics/diagnostics_ui.h" #include "chrome/browser/ui/webui/chromeos/diagnostics/diagnostics_ui.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/json/json_reader.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chromeos/dbus/debug_daemon_client.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_message_handler.h" #include "content/public/browser/web_ui_message_handler.h"
...@@ -18,6 +21,9 @@ namespace chromeos { ...@@ -18,6 +21,9 @@ namespace chromeos {
namespace { namespace {
// JS API callback names.
const char kJsApiUpdateConnStatus[] = "updateConnectivityStatus";
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// DiagnosticsHandler // DiagnosticsHandler
...@@ -36,6 +42,12 @@ class DiagnosticsWebUIHandler : public content::WebUIMessageHandler { ...@@ -36,6 +42,12 @@ class DiagnosticsWebUIHandler : public content::WebUIMessageHandler {
// Called when the page is first loaded. // Called when the page is first loaded.
void OnPageLoaded(const base::ListValue* args); void OnPageLoaded(const base::ListValue* args);
// Called when GetNetworkInterfaces() is complete.
// |succeeded|: information was obtained successfully.
// |status|: network interfaces information in json. See
// DebugDaemonClient::GetNetworkInterfaces() for details.
void OnGetNetworkInterfaces(bool succeeded, const std::string& status);
base::WeakPtrFactory<DiagnosticsWebUIHandler> weak_ptr_factory_; base::WeakPtrFactory<DiagnosticsWebUIHandler> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(DiagnosticsWebUIHandler); DISALLOW_COPY_AND_ASSIGN(DiagnosticsWebUIHandler);
}; };
...@@ -48,8 +60,25 @@ void DiagnosticsWebUIHandler::RegisterMessages() { ...@@ -48,8 +60,25 @@ void DiagnosticsWebUIHandler::RegisterMessages() {
} }
void DiagnosticsWebUIHandler::OnPageLoaded(const base::ListValue* args) { void DiagnosticsWebUIHandler::OnPageLoaded(const base::ListValue* args) {
// TODO: invoke debugd methods to retrieve diagnostics information, and chromeos::DebugDaemonClient* debugd_client =
// upon completion call javascript function to update status. chromeos::DBusThreadManager::Get()->GetDebugDaemonClient();
DCHECK(debugd_client);
debugd_client->GetNetworkInterfaces(
base::Bind(&DiagnosticsWebUIHandler::OnGetNetworkInterfaces,
weak_ptr_factory_.GetWeakPtr()));
}
void DiagnosticsWebUIHandler::OnGetNetworkInterfaces(
bool succeeded, const std::string& status) {
if (!succeeded)
return;
scoped_ptr<Value> parsed_value(base::JSONReader::Read(status));
if (parsed_value.get() && parsed_value->IsType(Value::TYPE_DICTIONARY)) {
base::DictionaryValue* result =
static_cast<DictionaryValue*>(parsed_value.get());
web_ui()->CallJavascriptFunction(kJsApiUpdateConnStatus, *result);
}
} }
} // namespace } // namespace
...@@ -63,6 +92,8 @@ DiagnosticsUI::DiagnosticsUI(content::WebUI* web_ui) ...@@ -63,6 +92,8 @@ DiagnosticsUI::DiagnosticsUI(content::WebUI* web_ui)
ChromeWebUIDataSource* source = ChromeWebUIDataSource* source =
new ChromeWebUIDataSource(chrome::kChromeUIDiagnosticsHost); new ChromeWebUIDataSource(chrome::kChromeUIDiagnosticsHost);
source->add_resource_path("main.css", IDR_DIAGNOSTICS_MAIN_CSS);
source->add_resource_path("main.js", IDR_DIAGNOSTICS_MAIN_JS);
source->set_default_resource(IDR_DIAGNOSTICS_MAIN_HTML); source->set_default_resource(IDR_DIAGNOSTICS_MAIN_HTML);
Profile* profile = Profile::FromWebUI(web_ui); Profile* profile = Profile::FromWebUI(web_ui);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment