Commit f6329b4e authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

Network UI: Support Device State

This shows the list of Shill devices in chrome://network

Bug: none
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Icf7fdce83722a3a84b82baee28b35bd5b40ad4c0
Reviewed-on: https://chromium-review.googlesource.com/656377Reviewed-by: default avatarToni Barzic <tbarzic@chromium.org>
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501347}
parent a7ca6493
......@@ -4863,12 +4863,18 @@ All users must sign out to continue.
<message name="IDS_NETWORK_UI_GLOBAL_POLICY" desc="Label for global policy properties">
Global Policy:
</message>
<message name="IDS_NETWORK_UI_NETWORK_LISTS" desc="Label for network lists section">
Network (Service) and Device properties
</message>
<message name="IDS_NETWORK_UI_VISIBLE_NETWORKS" desc="Label for list of visible networks">
Visible Networks:
</message>
<message name="IDS_NETWORK_UI_FAVORITE_NETWORKS" desc="Label for list of favorite networks">
Favorite Networks:
</message>
<message name="IDS_NETWORK_UI_DEVICES" desc="Label for list of network devices, e.g. wifi or cellular">
Devices:
</message>
<message name="IDS_DEVICE_LOG_LINK_TEXT" desc="Message preceeding link to chrome://device-log">
For network logs, see: <ph name="DEVICE_LOG_LINK">&lt;a href="chrome://device-log"&gt;chrome://device-log&lt;/a&gt;</ph>
......
......@@ -26,6 +26,10 @@ paper-button[raised].colored {
border-collapse: collapse;
}
.state-table tr {
min-width: 800px;
}
.state-table tr td {
border: 1px solid rgb(220, 220, 220);
font-size: 13px;
......@@ -50,6 +54,7 @@ paper-button[raised].colored {
}
.state-table-expanded-cell {
min-width: 400px;
white-space: pre-wrap;
}
......
......@@ -21,10 +21,10 @@
<div i18n-content="autoRefreshText"></div>
<span i18n-values=".innerHTML:deviceLogLinkText"></span>
<h3 i18n-content="globalPolicyLabel"></h3>
<h2 i18n-content="globalPolicyLabel"></h2>
<div id="global-policy"></div>
<h3>CrNetworkSelect</h3>
<h2>CrNetworkSelect</h2>
<div id="select-div">
<cr-network-select handle-network-item-selected>
</cr-network-select>
......@@ -35,7 +35,8 @@
</paper-button>
</div>
<h3 i18n-content="visibleNetworksLabel"></h3>
<h2 i18n-content="networkListsLabel"></h2>
<div i18n-content="clickToExpandText"></div>
<div>
<span i18n-content="propertyFormatText"></span>
......@@ -47,12 +48,22 @@
</select>
</div>
<h3 i18n-content="devicesLabel"></h3>
<table id="device-state-table" class="state-table">
<tr class="state-table-header">
<td></td>
<td></td>
<td>Type</td>
<td>State</td>
</tr>
</table>
<h3 i18n-content="visibleNetworksLabel"></h3>
<table id="network-state-table" class="state-table">
<tr class="state-table-header">
<td></td>
<td></td>
<td>GUID</td>
<td>Path</td>
<td>Name</td>
<td>Type</td>
<td>State</td>
......@@ -73,7 +84,6 @@
<td></td>
<td></td>
<td>GUID</td>
<td>Path</td>
<td>Name</td>
<td>Type</td>
<td>Profile</td>
......
......@@ -10,6 +10,7 @@
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "chrome/browser/chromeos/options/network_config_view.h"
#include "chrome/browser/extensions/tab_helper.h"
......@@ -19,8 +20,10 @@
#include "chrome/grit/generated_resources.h"
#include "chromeos/network/device_state.h"
#include "chromeos/network/network_configuration_handler.h"
#include "chromeos/network/network_device_handler.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "chromeos/network/onc/onc_utils.h"
#include "components/device_event_log/device_event_log.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
......@@ -33,6 +36,9 @@ namespace chromeos {
namespace {
constexpr char kGetNetworkProperties[] = "getShillNetworkProperties";
constexpr char kGetDeviceProperties[] = "getShillDeviceProperties";
bool GetServicePathFromGuid(const std::string& guid,
std::string* service_path) {
const NetworkState* network =
......@@ -77,65 +83,120 @@ class NetworkConfigMessageHandler : public content::WebUIMessageHandler {
// WebUIMessageHandler implementation.
void RegisterMessages() override {
web_ui()->RegisterMessageCallback(
"getShillProperties",
base::Bind(&NetworkConfigMessageHandler::GetShillProperties,
kGetNetworkProperties,
base::Bind(&NetworkConfigMessageHandler::GetShillNetworkProperties,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"addNetwork",
base::Bind(&NetworkConfigMessageHandler::AddNetwork,
kGetDeviceProperties,
base::Bind(&NetworkConfigMessageHandler::GetShillDeviceProperties,
base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"addNetwork", base::Bind(&NetworkConfigMessageHandler::AddNetwork,
base::Unretained(this)));
}
private:
void GetShillProperties(const base::ListValue* arg_list) {
void GetShillNetworkProperties(const base::ListValue* arg_list) {
std::string guid;
if (!arg_list->GetString(0, &guid)) {
NOTREACHED();
ErrorCallback(guid, "Missing GUID in arg list", nullptr);
return;
}
std::string service_path;
if (!GetServicePathFromGuid(guid, &service_path)) {
ErrorCallback(guid, "Error.InvalidNetworkGuid", nullptr);
ErrorCallback(guid, kGetNetworkProperties, "Error.InvalidNetworkGuid",
nullptr);
return;
}
NetworkHandler::Get()->network_configuration_handler()->GetShillProperties(
service_path,
base::Bind(&NetworkConfigMessageHandler::GetShillPropertiesSuccess,
weak_ptr_factory_.GetWeakPtr()),
base::Bind(
&NetworkConfigMessageHandler::GetShillNetworkPropertiesSuccess,
weak_ptr_factory_.GetWeakPtr()),
base::Bind(&NetworkConfigMessageHandler::ErrorCallback,
weak_ptr_factory_.GetWeakPtr(), guid));
weak_ptr_factory_.GetWeakPtr(), guid,
kGetNetworkProperties));
}
void GetShillPropertiesSuccess(
void GetShillNetworkPropertiesSuccess(
const std::string& service_path,
const base::DictionaryValue& dictionary) const {
const base::DictionaryValue& dictionary) {
std::unique_ptr<base::DictionaryValue> dictionary_copy(
dictionary.DeepCopy());
// Set the 'ServicePath' property for debugging.
dictionary_copy->SetKey("ServicePath", base::Value(service_path));
// Set the 'service_path' property for debugging.
dictionary_copy->SetKey("service_path", base::Value(service_path));
// Set the device properties for debugging.
SetDeviceProperties(dictionary_copy.get());
base::ListValue return_arg_list;
return_arg_list.Append(std::move(dictionary_copy));
web_ui()->CallJavascriptFunctionUnsafe("NetworkUI.getShillPropertiesResult",
return_arg_list);
AllowJavascript();
CallJavascriptFunction(
base::StringPrintf("NetworkUI.%sResult", kGetNetworkProperties),
return_arg_list);
}
void GetShillDeviceProperties(const base::ListValue* arg_list) {
std::string type;
if (!arg_list->GetString(0, &type)) {
NOTREACHED();
return;
}
const DeviceState* device =
NetworkHandler::Get()->network_state_handler()->GetDeviceStateByType(
onc::NetworkTypePatternFromOncType(type));
if (!device) {
ErrorCallback(type, kGetDeviceProperties, "Error.InvalidDeviceType",
nullptr);
return;
}
NetworkHandler::Get()->network_device_handler()->GetDeviceProperties(
device->path(),
base::Bind(
&NetworkConfigMessageHandler::GetShillDevicePropertiesSuccess,
weak_ptr_factory_.GetWeakPtr()),
base::Bind(&NetworkConfigMessageHandler::ErrorCallback,
weak_ptr_factory_.GetWeakPtr(), type, kGetDeviceProperties));
}
void GetShillDevicePropertiesSuccess(
const std::string& device_path,
const base::DictionaryValue& dictionary) {
std::unique_ptr<base::DictionaryValue> dictionary_copy(
dictionary.DeepCopy());
// Set the 'device_path' property for debugging.
dictionary_copy->SetKey("device_path", base::Value(device_path));
base::ListValue return_arg_list;
return_arg_list.Append(std::move(dictionary_copy));
AllowJavascript();
CallJavascriptFunction(
base::StringPrintf("NetworkUI.%sResult", kGetDeviceProperties),
return_arg_list);
}
void ErrorCallback(
const std::string& guid,
const std::string& error_name,
std::unique_ptr<base::DictionaryValue> /* error_data */) const {
NET_LOG(ERROR) << "Shill Error: " << error_name << " guid=" << guid;
void ErrorCallback(const std::string& guid_or_type,
const std::string& function_name,
const std::string& error_name,
std::unique_ptr<base::DictionaryValue> /* error_data */) {
NET_LOG(ERROR) << "Shill Error: " << error_name << " id=" << guid_or_type;
base::ListValue return_arg_list;
std::unique_ptr<base::DictionaryValue> dictionary;
dictionary->SetKey(shill::kGuidProperty, base::Value(guid));
std::string key = function_name == kGetDeviceProperties
? shill::kTypeProperty
: shill::kGuidProperty;
dictionary->SetKey(key, base::Value(guid_or_type));
dictionary->SetKey("ShillError", base::Value(error_name));
return_arg_list.Append(std::move(dictionary));
web_ui()->CallJavascriptFunctionUnsafe("NetworkUI.getShillPropertiesResult",
return_arg_list);
AllowJavascript();
CallJavascriptFunction(
base::StringPrintf("NetworkUI.%sResult", function_name.c_str()),
return_arg_list);
}
void AddNetwork(const base::ListValue* args) {
......@@ -190,12 +251,17 @@ void NetworkUI::GetLocalizedStrings(base::DictionaryValue* localized_strings) {
localized_strings->SetString(
"globalPolicyLabel",
l10n_util::GetStringUTF16(IDS_NETWORK_UI_GLOBAL_POLICY));
localized_strings->SetString(
"networkListsLabel",
l10n_util::GetStringUTF16(IDS_NETWORK_UI_NETWORK_LISTS));
localized_strings->SetString(
"visibleNetworksLabel",
l10n_util::GetStringUTF16(IDS_NETWORK_UI_VISIBLE_NETWORKS));
localized_strings->SetString(
"favoriteNetworksLabel",
l10n_util::GetStringUTF16(IDS_NETWORK_UI_FAVORITE_NETWORKS));
localized_strings->SetString(
"devicesLabel", l10n_util::GetStringUTF16(IDS_NETWORK_UI_DEVICES));
}
NetworkUI::NetworkUI(content::WebUI* web_ui)
......@@ -223,7 +289,6 @@ NetworkUI::NetworkUI(content::WebUI* web_ui)
html);
}
NetworkUI::~NetworkUI() {
}
NetworkUI::~NetworkUI() {}
} // namespace chromeos
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