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

Settings > Internet: Use mojo for DeviceStateProperties

This CL:
* Replaces all uses of CrOnc.DeviceState in Settings UI and related
  cr_elements to OncMojo.DeviceStateProperties.
* Replaces all calls to networkingPrivate.getDeviceStates in Settings
  UI and related cr_elements to CrosNetworkConfig.getDeviceStateList.
* Modifies device related <internet-page> events to use mojo types.

Bug: 853953
Change-Id: I858fc0db3fc8d171b267776644f9a5a90fd266af
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1666840
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#672521}
parent 62d2a3f0
...@@ -100,6 +100,7 @@ js_library("internet_subpage") { ...@@ -100,6 +100,7 @@ js_library("internet_subpage") {
"//ui/webui/resources/cr_elements/policy:cr_policy_network_behavior", "//ui/webui/resources/cr_elements/policy:cr_policy_network_behavior",
"//ui/webui/resources/js:assert", "//ui/webui/resources/js:assert",
"//ui/webui/resources/js:i18n_behavior", "//ui/webui/resources/js:i18n_behavior",
"//ui/webui/resources/js/chromeos:onc_mojo",
] ]
externs_list = [ "$externs_path/networking_private.js" ] externs_list = [ "$externs_path/networking_private.js" ]
extra_sources = [ "$interfaces_path/networking_private_interface.js" ] extra_sources = [ "$interfaces_path/networking_private_interface.js" ]
...@@ -124,6 +125,7 @@ js_library("network_summary") { ...@@ -124,6 +125,7 @@ js_library("network_summary") {
"//ui/webui/resources/cr_elements/chromeos/network:cr_onc_types", "//ui/webui/resources/cr_elements/chromeos/network:cr_onc_types",
"//ui/webui/resources/cr_elements/policy:cr_policy_network_behavior", "//ui/webui/resources/cr_elements/policy:cr_policy_network_behavior",
"//ui/webui/resources/js:assert", "//ui/webui/resources/js:assert",
"//ui/webui/resources/js/chromeos:onc_mojo",
] ]
extra_sources = [ "$interfaces_path/networking_private_interface.js" ] extra_sources = [ "$interfaces_path/networking_private_interface.js" ]
} }
...@@ -134,6 +136,7 @@ js_library("network_summary_item") { ...@@ -134,6 +136,7 @@ js_library("network_summary_item") {
"//ui/webui/resources/cr_elements/policy:cr_policy_network_behavior", "//ui/webui/resources/cr_elements/policy:cr_policy_network_behavior",
"//ui/webui/resources/js:assert", "//ui/webui/resources/js:assert",
"//ui/webui/resources/js:i18n_behavior", "//ui/webui/resources/js:i18n_behavior",
"//ui/webui/resources/js/chromeos:onc_mojo",
] ]
extra_sources = [ "$interfaces_path/networking_private_interface.js" ] extra_sources = [ "$interfaces_path/networking_private_interface.js" ]
} }
......
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
<template is="dom-if" if="[[addConnectionExpanded_]]"> <template is="dom-if" if="[[addConnectionExpanded_]]">
<div class="list-frame vertical-list"> <div class="list-frame vertical-list">
<template is="dom-if" <template is="dom-if"
if="[[deviceIsEnabled_(deviceStates.WiFi)]]"> if="[[deviceIsEnabled_(deviceStates, 'WiFi')]]">
<div actionable class="list-item" on-click="onAddWiFiTap_"> <div actionable class="list-item" on-click="onAddWiFiTap_">
<div class="start settings-box-text"> <div class="start settings-box-text">
$i18n{internetAddWiFi} $i18n{internetAddWiFi}
...@@ -127,7 +127,7 @@ ...@@ -127,7 +127,7 @@
<settings-internet-subpage <settings-internet-subpage
default-network="[[defaultNetwork]]" default-network="[[defaultNetwork]]"
device-state="[[getDeviceState_(subpageType_, deviceStates)]]" device-state="[[getDeviceState_(subpageType_, deviceStates)]]"
tether-device-state="[[get('Tether', deviceStates)]]" tether-device-state="[[getTetherDeviceState_(deviceStates)]]"
global-policy="[[globalPolicy_]]" global-policy="[[globalPolicy_]]"
third-party-vpn-providers="[[thirdPartyVpnProviders_]]" third-party-vpn-providers="[[thirdPartyVpnProviders_]]"
arc-vpn-providers="[[arcVpnProviders_]]" arc-vpn-providers="[[arcVpnProviders_]]"
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
(function() {
const mojom = chromeos.networkConfig.mojom;
/** /**
* @fileoverview * @fileoverview
* 'settings-internet-page' is the settings page containing internet * 'settings-internet-page' is the settings page containing internet
...@@ -33,8 +37,9 @@ Polymer({ ...@@ -33,8 +37,9 @@ Polymer({
}, },
/** /**
* The device state for each network device type. Set by network-summary. * The device state for each network device type, keyed by NetworkType. Set
* @type {!Object<!CrOnc.DeviceStateProperties>|undefined} * by network-summary.
* @type {!Object<!OncMojo.DeviceStateProperties>|undefined}
* @private * @private
*/ */
deviceStates: { deviceStates: {
...@@ -132,12 +137,12 @@ Polymer({ ...@@ -132,12 +137,12 @@ Polymer({
// Element event listeners // Element event listeners
listeners: { listeners: {
'device-enabled-toggled': 'onDeviceEnabledToggled_', 'device-enabled-toggled': 'onDeviceEnabledToggled_', // mojo api
'network-connect': 'onNetworkConnect_', 'network-connect': 'onNetworkConnect_',
'show-config': 'onShowConfig_', 'show-config': 'onShowConfig_',
'show-detail': 'onShowDetail_', 'show-detail': 'onShowDetail_',
'show-known-networks': 'onShowKnownNetworks_', 'show-known-networks': 'onShowKnownNetworks_', // mojo api
'show-networks': 'onShowNetworks_', 'show-networks': 'onShowNetworks_', // mojo api
}, },
// chrome.management listeners // chrome.management listeners
...@@ -277,14 +282,13 @@ Polymer({ ...@@ -277,14 +282,13 @@ Polymer({
* Event triggered by a device state enabled toggle. * Event triggered by a device state enabled toggle.
* @param {!CustomEvent<!{ * @param {!CustomEvent<!{
* enabled: boolean, * enabled: boolean,
* type: chrome.networkingPrivate.NetworkType * type: chromeos.networkConfig.mojom.NetworkType
* }>} event * }>} event
* @private * @private
*/ */
onDeviceEnabledToggled_: function(event) { onDeviceEnabledToggled_: function(event) {
this.networkConfigProxy_.setNetworkTypeEnabledState( this.networkConfigProxy_.setNetworkTypeEnabledState(
OncMojo.getNetworkTypeFromString(event.detail.type), event.detail.type, event.detail.enabled);
event.detail.enabled);
}, },
/** /**
...@@ -338,11 +342,11 @@ Polymer({ ...@@ -338,11 +342,11 @@ Polymer({
}, },
/** /**
* @param {!CustomEvent<!{type: string}>} event * @param {!CustomEvent<chromeos.networkConfig.mojom.NetworkType>} event
* @private * @private
*/ */
onShowNetworks_: function(event) { onShowNetworks_: function(event) {
this.showNetworksSubpage_(event.detail.type); this.showNetworksSubpage_(event.detail);
}, },
/** /**
...@@ -371,37 +375,51 @@ Polymer({ ...@@ -371,37 +375,51 @@ Polymer({
/** /**
* @param {string} subpageType * @param {string} subpageType
* @param {!Object<!CrOnc.DeviceStateProperties>|undefined} deviceStates * @param {!Object<!OncMojo.DeviceStateProperties>|undefined} deviceStates
* @return {!CrOnc.DeviceStateProperties|undefined} * @return {!OncMojo.DeviceStateProperties|undefined}
* @private * @private
*/ */
getDeviceState_: function(subpageType, deviceStates) { getDeviceState_: function(subpageType, deviceStates) {
if (!subpageType) {
return undefined;
}
// If both Tether and Cellular are enabled, use the Cellular device state // If both Tether and Cellular are enabled, use the Cellular device state
// when directly navigating to the Tether page. // when directly navigating to the Tether page.
if (subpageType == CrOnc.Type.TETHER && if (subpageType == CrOnc.Type.TETHER &&
this.deviceStates[CrOnc.Type.CELLULAR]) { this.deviceStates[mojom.NetworkType.kCellular]) {
subpageType = CrOnc.Type.CELLULAR; subpageType = CrOnc.Type.CELLULAR;
} }
return deviceStates[subpageType]; return deviceStates[OncMojo.getNetworkTypeFromString(subpageType)];
},
/**
* @param {!Object<!OncMojo.DeviceStateProperties>|undefined} deviceStates
* @return {!OncMojo.DeviceStateProperties|undefined}
* @private
*/
getTetherDeviceState_: function(deviceStates) {
return deviceStates[mojom.NetworkType.kTether];
}, },
/** /**
* @param {!CrOnc.DeviceStateProperties|undefined} newValue * @param {!OncMojo.DeviceStateProperties|undefined} newValue
* @param {!CrOnc.DeviceStateProperties|undefined} oldValue * @param {!OncMojo.DeviceStateProperties|undefined} oldValue
* @private * @private
*/ */
onDeviceStatesChanged_: function(newValue, oldValue) { onDeviceStatesChanged_: function(newValue, oldValue) {
const wifiDeviceState = this.getDeviceState_(CrOnc.Type.WI_FI, newValue); const wifiDeviceState = this.getDeviceState_(CrOnc.Type.WI_FI, newValue);
let managedNetworkAvailable = false; let managedNetworkAvailable = false;
if (wifiDeviceState) { if (wifiDeviceState) {
managedNetworkAvailable = !!wifiDeviceState.ManagedNetworkAvailable; managedNetworkAvailable = !!wifiDeviceState.managedNetworkAvailable;
} }
if (this.managedNetworkAvailable != managedNetworkAvailable) { if (this.managedNetworkAvailable != managedNetworkAvailable) {
this.managedNetworkAvailable = managedNetworkAvailable; this.managedNetworkAvailable = managedNetworkAvailable;
} }
if (this.detailType_ && !this.deviceStates[this.detailType_]) { if (this.detailType_ &&
!this.deviceStates[OncMojo.getNetworkTypeFromString(
this.detailType_)]) {
// If the device type associated with the current network has been // If the device type associated with the current network has been
// removed (e.g., due to unplugging a Cellular dongle), the details page, // removed (e.g., due to unplugging a Cellular dongle), the details page,
// if visible, displays controls which are no longer functional. If this // if visible, displays controls which are no longer functional. If this
...@@ -414,14 +432,15 @@ Polymer({ ...@@ -414,14 +432,15 @@ Polymer({
}, },
/** /**
* @param {!CustomEvent<!{type: string}>} event * @param {!CustomEvent<chromeos.networkConfig.mojom.NetworkType>} event
* @private * @private
*/ */
onShowKnownNetworks_: function(event) { onShowKnownNetworks_: function(event) {
this.detailType_ = event.detail.type; const oncType = OncMojo.getNetworkTypeString(event.detail);
this.detailType_ = oncType;
this.knownNetworksType_ = oncType;
const params = new URLSearchParams; const params = new URLSearchParams;
params.append('type', event.detail.type); params.append('type', oncType);
this.knownNetworksType_ = event.detail.type;
settings.navigateTo(settings.routes.KNOWN_NETWORKS, params); settings.navigateTo(settings.routes.KNOWN_NETWORKS, params);
}, },
...@@ -448,18 +467,19 @@ Polymer({ ...@@ -448,18 +467,19 @@ Polymer({
/** @private */ /** @private */
onAddArcVpnTap_: function() { onAddArcVpnTap_: function() {
this.showNetworksSubpage_(CrOnc.Type.VPN); this.showNetworksSubpage_(mojom.NetworkType.kVPN);
}, },
/** /**
* @param {string} type * @param {chromeos.networkConfig.mojom.NetworkType} type
* @private * @private
*/ */
showNetworksSubpage_: function(type) { showNetworksSubpage_: function(type) {
this.detailType_ = type; const oncType = OncMojo.getNetworkTypeString(type);
this.detailType_ = oncType;
const params = new URLSearchParams; const params = new URLSearchParams;
params.append('type', type); params.append('type', oncType);
this.subpageType_ = type; this.subpageType_ = oncType;
settings.navigateTo(settings.routes.INTERNET_NETWORKS, params); settings.navigateTo(settings.routes.INTERNET_NETWORKS, params);
}, },
...@@ -559,12 +579,16 @@ Polymer({ ...@@ -559,12 +579,16 @@ Polymer({
}, },
/** /**
* @param {!CrOnc.DeviceStateProperties} deviceState * @param {!Array<!OncMojo.DeviceStateProperties>} deviceStates
* @param {string} type
* @return {boolean} * @return {boolean}
* @private * @private
*/ */
deviceIsEnabled_: function(deviceState) { deviceIsEnabled_: function(deviceStates, type) {
return !!deviceState && deviceState.State == CrOnc.DeviceState.ENABLED; const device = deviceStates[OncMojo.getNetworkTypeFromString(type)];
return !!device &&
device.deviceState ==
chromeos.networkConfig.mojom.DeviceStateType.kEnabled;
}, },
/** /**
...@@ -643,3 +667,4 @@ Polymer({ ...@@ -643,3 +667,4 @@ Polymer({
}); });
}, },
}); });
})();
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<link rel="import" href="chrome://resources/cr_elements/cr_link_row/cr_link_row.html"> <link rel="import" href="chrome://resources/cr_elements/cr_link_row/cr_link_row.html">
<link rel="import" href="chrome://resources/cr_elements/cr_toggle/cr_toggle.html"> <link rel="import" href="chrome://resources/cr_elements/cr_toggle/cr_toggle.html">
<link rel="import" href="chrome://resources/cr_elements/shared_vars_css.html"> <link rel="import" href="chrome://resources/cr_elements/shared_vars_css.html">
<link rel="import" href="chrome://resources/html/chromeos/onc_mojo.html">
<link rel="import" href="chrome://resources/html/i18n_behavior.html"> <link rel="import" href="chrome://resources/html/i18n_behavior.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-flex-layout/iron-flex-layout-classes.html"> <link rel="import" href="chrome://resources/polymer/v1_0/iron-flex-layout/iron-flex-layout-classes.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-icon/iron-icon.html"> <link rel="import" href="chrome://resources/polymer/v1_0/iron-icon/iron-icon.html">
...@@ -111,7 +112,7 @@ ...@@ -111,7 +112,7 @@
<template is="dom-if" if="[[deviceIsEnabled_(deviceState)]]"> <template is="dom-if" if="[[deviceIsEnabled_(deviceState)]]">
<div id="networkListDiv" class="layout vertical flex"> <div id="networkListDiv" class="layout vertical flex">
<!-- VPN only header for built-in VPNs. --> <!-- VPN only header for built-in VPNs. -->
<template is="dom-if" if="[[isEqual_('VPN', deviceState.Type)]]"> <template is="dom-if" if="[[matchesType_('VPN', deviceState)]]">
<div class="vpn-header layout horizontal center"> <div class="vpn-header layout horizontal center">
<div class="flex settings-box-text">$i18n{networkVpnBuiltin}</div> <div class="flex settings-box-text">$i18n{networkVpnBuiltin}</div>
<cr-icon-button class="icon-add-circle" <cr-icon-button class="icon-add-circle"
...@@ -157,7 +158,7 @@ ...@@ -157,7 +158,7 @@
class="no-networks"> class="no-networks">
</div> </div>
<template is="dom-if" if="[[isEqual_('VPN', deviceState.Type)]]"> <template is="dom-if" if="[[matchesType_('VPN', deviceState)]]">
<!-- Third party VPNs. --> <!-- Third party VPNs. -->
<template is="dom-repeat" items="[[thirdPartyVpnProviders]]"> <template is="dom-repeat" items="[[thirdPartyVpnProviders]]">
<div id="[[item.ProviderName]]" <div id="[[item.ProviderName]]"
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<link rel="import" href="chrome://resources/cr_elements/chromeos/network/cr_network_listener_behavior.html"> <link rel="import" href="chrome://resources/cr_elements/chromeos/network/cr_network_listener_behavior.html">
<link rel="import" href="chrome://resources/cr_elements/chromeos/network/cr_onc_types.html"> <link rel="import" href="chrome://resources/cr_elements/chromeos/network/cr_onc_types.html">
<link rel="import" href="chrome://resources/cr_elements/policy/cr_policy_network_behavior.html"> <link rel="import" href="chrome://resources/cr_elements/policy/cr_policy_network_behavior.html">
<link rel="import" href="chrome://resources/html/chromeos/onc_mojo.html">
<link rel="import" href="network_summary_item.html"> <link rel="import" href="network_summary_item.html">
<dom-module id="network-summary"> <dom-module id="network-summary">
...@@ -11,9 +12,9 @@ ...@@ -11,9 +12,9 @@
<template is="dom-repeat" items="[[activeNetworkStates_]]"> <template is="dom-repeat" items="[[activeNetworkStates_]]">
<network-summary-item id="[[item.Type]]" <network-summary-item id="[[item.Type]]"
active-network-state="[[item]]" active-network-state="[[item]]"
device-state="[[get(item.Type, deviceStates)]]" device-state="[[getDeviceState_(item.Type, deviceStates)]]"
network-state-list="[[get(item.Type, networkStateLists_)]]" network-state-list="[[get(item.Type, networkStateLists_)]]"
tether-device-state="[[get('Tether', deviceStates)]]"> tether-device-state="[[getDeviceState_('Tether', deviceStates)]]">
</network-summary-item> </network-summary-item>
</template> </template>
</div> </div>
......
...@@ -7,17 +7,6 @@ ...@@ -7,17 +7,6 @@
* by type: Ethernet, WiFi, Cellular, WiMAX, and VPN. * by type: Ethernet, WiFi, Cellular, WiMAX, and VPN.
*/ */
/**
* @typedef {{
* Ethernet: (!CrOnc.DeviceStateProperties|undefined),
* WiFi: (!CrOnc.DeviceStateProperties|undefined),
* Cellular: (!CrOnc.DeviceStateProperties|undefined),
* WiMAX: (!CrOnc.DeviceStateProperties|undefined),
* VPN: (!CrOnc.DeviceStateProperties|undefined)
* }}
*/
let DeviceStateObject;
/** /**
* @typedef {{ * @typedef {{
* Ethernet: (Array<!CrOnc.NetworkStateProperties>|undefined), * Ethernet: (Array<!CrOnc.NetworkStateProperties>|undefined),
...@@ -58,14 +47,17 @@ Polymer({ ...@@ -58,14 +47,17 @@ Polymer({
* The device state for each network device type. We initialize this to * The device state for each network device type. We initialize this to
* include a disabled WiFi type since WiFi is always present. This reduces * include a disabled WiFi type since WiFi is always present. This reduces
* the amount of visual change on first load. * the amount of visual change on first load.
* @private {!DeviceStateObject} * @private {!Object<!OncMojo.DeviceStateProperties>}
*/ */
deviceStates: { deviceStates: {
type: Object, type: Object,
value: function() { value: function() {
return { const result = {};
WiFi: {Type: CrOnc.Type.WI_FI, State: CrOnc.DeviceState.DISABLED}, result[chromeos.networkConfig.mojom.NetworkType.kWiFi] = {
deviceState: chromeos.networkConfig.mojom.DeviceStateType.kDisabled,
type: chromeos.networkConfig.mojom.NetworkType.kWiFi,
}; };
return result;
}, },
notify: true, notify: true,
}, },
...@@ -94,12 +86,27 @@ Polymer({ ...@@ -94,12 +86,27 @@ Polymer({
}, },
}, },
/**
* This UI will use both the networkingPrivate extension API and the
* networkConfig mojo API until we provide all of the required functionality
* in networkConfig. TODO(stevenjb): Remove use of networkingPrivate api.
* @private {?chromeos.networkConfig.mojom.CrosNetworkConfigProxy}
*/
networkConfigProxy_: null,
/** /**
* Set of GUIDs identifying active networks, one for each type. * Set of GUIDs identifying active networks, one for each type.
* @private {?Set<string>} * @private {?Set<string>}
*/ */
activeNetworkIds_: null, activeNetworkIds_: null,
/** @override */
created: function() {
this.networkConfigProxy_ =
network_config.MojoInterfaceProviderImpl.getInstance()
.getMojoServiceProxy();
},
/** @override */ /** @override */
attached: function() { attached: function() {
this.getNetworkLists_(); this.getNetworkLists_();
...@@ -177,9 +184,9 @@ Polymer({ ...@@ -177,9 +184,9 @@ Polymer({
*/ */
getNetworkLists_: function() { getNetworkLists_: function() {
// First get the device states. // First get the device states.
this.networkingPrivate.getDeviceStates(deviceStates => { this.networkConfigProxy_.getDeviceStateList().then(response => {
// Second get the network states. // Second get the network states.
this.getNetworkStates_(deviceStates); this.getNetworkStates_(response.result);
}); });
}, },
...@@ -187,17 +194,17 @@ Polymer({ ...@@ -187,17 +194,17 @@ Polymer({
* Requests the list of network states from Chrome. Updates * Requests the list of network states from Chrome. Updates
* activeNetworkStates and networkStateLists once the results are returned * activeNetworkStates and networkStateLists once the results are returned
* from Chrome. * from Chrome.
* @param {!Array<!CrOnc.DeviceStateProperties>} deviceStates * @param {!Array<!OncMojo.DeviceStateProperties>} deviceStateList
* @private * @private
*/ */
getNetworkStates_: function(deviceStates) { getNetworkStates_: function(deviceStateList) {
const filter = { const filter = {
networkType: CrOnc.Type.ALL, networkType: CrOnc.Type.ALL,
visible: true, visible: true,
configured: false configured: false
}; };
this.networkingPrivate.getNetworks(filter, networkStates => { this.networkingPrivate.getNetworks(filter, networkStates => {
this.updateNetworkStates_(networkStates, deviceStates); this.updateNetworkStates_(networkStates, deviceStateList);
}); });
}, },
...@@ -205,13 +212,14 @@ Polymer({ ...@@ -205,13 +212,14 @@ Polymer({
* Called after network states are received from getNetworks. * Called after network states are received from getNetworks.
* @param {!Array<!CrOnc.NetworkStateProperties>} networkStates The state * @param {!Array<!CrOnc.NetworkStateProperties>} networkStates The state
* properties for all visible networks. * properties for all visible networks.
* @param {!Array<!CrOnc.DeviceStateProperties>} deviceStates * @param {!Array<!OncMojo.DeviceStateProperties>} deviceStateList
* @private * @private
*/ */
updateNetworkStates_: function(networkStates, deviceStates) { updateNetworkStates_: function(networkStates, deviceStateList) {
const newDeviceStates = /** @type {!DeviceStateObject} */ ({}); const mojom = chromeos.networkConfig.mojom;
for (const state of deviceStates) { const newDeviceStates = {};
newDeviceStates[state.Type] = state; for (const device of deviceStateList) {
newDeviceStates[device.type] = device;
} }
// Clear any current networks. // Clear any current networks.
...@@ -245,9 +253,9 @@ Polymer({ ...@@ -245,9 +253,9 @@ Polymer({
// Create a VPN entry in deviceStates if there are any VPN networks. // Create a VPN entry in deviceStates if there are any VPN networks.
if (newNetworkStateLists.VPN && newNetworkStateLists.VPN.length > 0) { if (newNetworkStateLists.VPN && newNetworkStateLists.VPN.length > 0) {
newDeviceStates.VPN = { newDeviceStates[mojom.NetworkType.kVPN] = {
Type: CrOnc.Type.VPN, type: mojom.NetworkType.kVPN,
State: CrOnc.DeviceState.ENABLED deviceState: chromeos.networkConfig.mojom.DeviceStateType.kEnabled,
}; };
} }
...@@ -256,11 +264,15 @@ Polymer({ ...@@ -256,11 +264,15 @@ Polymer({
const newActiveNetworkStates = []; const newActiveNetworkStates = [];
this.activeNetworkIds_ = new Set; this.activeNetworkIds_ = new Set;
const orderedDeviceTypes = [ const orderedDeviceTypes = [
CrOnc.Type.ETHERNET, CrOnc.Type.WI_FI, CrOnc.Type.CELLULAR, mojom.NetworkType.kEthernet,
CrOnc.Type.TETHER, CrOnc.Type.WI_MAX, CrOnc.Type.VPN mojom.NetworkType.kWiFi,
mojom.NetworkType.kCellular,
mojom.NetworkType.kTether,
mojom.NetworkType.kWiMAX,
mojom.NetworkType.kVPN,
]; ];
for (const type of orderedDeviceTypes) { for (const deviceType of orderedDeviceTypes) {
const device = newDeviceStates[type]; const device = newDeviceStates[deviceType];
if (!device) { if (!device) {
continue; continue;
} // The technology for this device type is unavailable. } // The technology for this device type is unavailable.
...@@ -268,7 +280,8 @@ Polymer({ ...@@ -268,7 +280,8 @@ Polymer({
// If both 'Tether' and 'Cellular' technologies exist, merge the network // If both 'Tether' and 'Cellular' technologies exist, merge the network
// lists and do not add an active network for 'Tether' so that there is // lists and do not add an active network for 'Tether' so that there is
// only one 'Mobile data' section / subpage. // only one 'Mobile data' section / subpage.
if (type == CrOnc.Type.TETHER && newDeviceStates[CrOnc.Type.CELLULAR]) { if (deviceType == mojom.NetworkType.kTether &&
newDeviceStates[mojom.NetworkType.kCellular]) {
newNetworkStateLists[CrOnc.Type.CELLULAR] = newNetworkStateLists[CrOnc.Type.CELLULAR] =
newNetworkStateLists[CrOnc.Type.CELLULAR].concat( newNetworkStateLists[CrOnc.Type.CELLULAR].concat(
newNetworkStateLists[CrOnc.Type.TETHER]); newNetworkStateLists[CrOnc.Type.TETHER]);
...@@ -277,15 +290,16 @@ Polymer({ ...@@ -277,15 +290,16 @@ Polymer({
// Note: The active state for 'Cellular' may be a Tether network if both // Note: The active state for 'Cellular' may be a Tether network if both
// types are enabled but no Cellular network exists (edge case). // types are enabled but no Cellular network exists (edge case).
const state = const networkState = this.getActiveStateForType_(
this.getActiveStateForType_(activeNetworkStatesByType, type); activeNetworkStatesByType, OncMojo.getNetworkTypeString(deviceType));
if (state.Source === undefined && if (networkState.Source === undefined &&
device.State == CrOnc.DeviceState.PROHIBITED) { device.deviceState ==
chromeos.networkConfig.mojom.DeviceStateType.kProhibited) {
// Prohibited technologies are enforced by the device policy. // Prohibited technologies are enforced by the device policy.
state.Source = CrOnc.Source.DEVICE_POLICY; networkState.Source = CrOnc.Source.DEVICE_POLICY;
} }
newActiveNetworkStates.push(state); newActiveNetworkStates.push(networkState);
this.activeNetworkIds_.add(state.GUID); this.activeNetworkIds_.add(networkState.GUID);
} }
this.deviceStates = newDeviceStates; this.deviceStates = newDeviceStates;
...@@ -309,4 +323,13 @@ Polymer({ ...@@ -309,4 +323,13 @@ Polymer({
} }
return activeState || {GUID: '', Type: type}; return activeState || {GUID: '', Type: type};
}, },
/**
* @param {string} type
* @param {!Object<!OncMojo.DeviceStateProperties>} deviceStates
* @return {!OncMojo.DeviceStateProperties|undefined}
*/
getDeviceState_: function(type, deviceStates) {
return this.deviceStates[OncMojo.getNetworkTypeFromString(type)];
},
}); });
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
<link rel="import" href="chrome://resources/cr_elements/cr_toggle/cr_toggle.html"> <link rel="import" href="chrome://resources/cr_elements/cr_toggle/cr_toggle.html">
<link rel="import" href="chrome://resources/cr_elements/policy/cr_policy_indicator.html"> <link rel="import" href="chrome://resources/cr_elements/policy/cr_policy_indicator.html">
<link rel="import" href="chrome://resources/cr_elements/shared_vars_css.html"> <link rel="import" href="chrome://resources/cr_elements/shared_vars_css.html">
<link rel="import" href="chrome://resources/html/chromeos/onc_mojo.html">
<link rel="import" href="chrome://resources/html/i18n_behavior.html"> <link rel="import" href="chrome://resources/html/i18n_behavior.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-collapse/iron-collapse.html"> <link rel="import" href="chrome://resources/polymer/v1_0/iron-collapse/iron-collapse.html">
<link rel="import" href="../settings_page/settings_subpage.html"> <link rel="import" href="../settings_page/settings_subpage.html">
......
...@@ -110,6 +110,7 @@ if (is_chromeos) { ...@@ -110,6 +110,7 @@ if (is_chromeos) {
"..:route", "..:route",
"//ui/webui/resources/cr_elements/chromeos/network:cr_network_listener_behavior", "//ui/webui/resources/cr_elements/chromeos/network:cr_network_listener_behavior",
"//ui/webui/resources/cr_elements/chromeos/network:cr_onc_types", "//ui/webui/resources/cr_elements/chromeos/network:cr_onc_types",
"//ui/webui/resources/js/chromeos:onc_mojo",
] ]
externs_list = [ "$externs_path/networking_private.js" ] externs_list = [ "$externs_path/networking_private.js" ]
extra_sources = [ "$interfaces_path/networking_private_interface.js" ] extra_sources = [ "$interfaces_path/networking_private_interface.js" ]
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<link rel="import" href="chrome://resources/cr_elements/chromeos/network/cr_onc_types.html"> <link rel="import" href="chrome://resources/cr_elements/chromeos/network/cr_onc_types.html">
<link rel="import" href="chrome://resources/cr_elements/chromeos/network/cr_network_icon.html"> <link rel="import" href="chrome://resources/cr_elements/chromeos/network/cr_network_icon.html">
<link rel="import" href="chrome://resources/cr_elements/chromeos/network/cr_network_listener_behavior.html"> <link rel="import" href="chrome://resources/cr_elements/chromeos/network/cr_network_listener_behavior.html">
<link rel="import" href="chrome://resources/html/chromeos/onc_mojo.html">
<link rel="import" href="../i18n_setup.html"> <link rel="import" href="../i18n_setup.html">
<link rel="import" href="../route.html"> <link rel="import" href="../route.html">
<link rel="import" href="../settings_shared_css.html"> <link rel="import" href="../settings_shared_css.html">
......
...@@ -31,7 +31,7 @@ Polymer({ ...@@ -31,7 +31,7 @@ Polymer({
/** /**
* The device state for tethering. * The device state for tethering.
* @private {?CrOnc.DeviceStateProperties|undefined} * @private {?OncMojo.DeviceStateProperties|undefined}
*/ */
deviceState_: Object, deviceState_: Object,
...@@ -65,6 +65,21 @@ Polymer({ ...@@ -65,6 +65,21 @@ Polymer({
}, },
}, },
/**
* This UI will use both the networkingPrivate extension API and the
* networkConfig mojo API until we provide all of the required functionality
* in networkConfig. TODO(stevenjb): Remove use of networkingPrivate api.
* @private {?chromeos.networkConfig.mojom.CrosNetworkConfigProxy}
*/
networkConfigProxy_: null,
/** @override */
created: function() {
this.networkConfigProxy_ =
network_config.MojoInterfaceProviderImpl.getInstance()
.getMojoServiceProxy();
},
/** @override */ /** @override */
attached: function() { attached: function() {
this.updateTetherDeviceState_(); this.updateTetherDeviceState_();
...@@ -112,7 +127,7 @@ Polymer({ ...@@ -112,7 +127,7 @@ Polymer({
}, },
/** /**
* Retrieves device states (CrOnc.DeviceStateProperties) and sets * Retrieves device states (OncMojo.DeviceStateProperties) and sets
* this.deviceState_ to the retrieved Instant Tethering state (or undefined if * this.deviceState_ to the retrieved Instant Tethering state (or undefined if
* there is none) in its callback. Note that the function * there is none) in its callback. Note that the function
* chrome.networkingPrivate.getDevicePolicy() retrieves at most one object per * chrome.networkingPrivate.getDevicePolicy() retrieves at most one object per
...@@ -121,11 +136,18 @@ Polymer({ ...@@ -121,11 +136,18 @@ Polymer({
* @private * @private
*/ */
updateTetherDeviceState_: function() { updateTetherDeviceState_: function() {
this.networkingPrivate_.getDeviceStates(deviceStates => { this.networkConfigProxy_.getDeviceStateList().then(response => {
this.deviceState_ = const kTether = chromeos.networkConfig.mojom.NetworkType.kTether;
deviceStates.find( const deviceStates = response.result;
deviceState => deviceState.Type == CrOnc.Type.TETHER) || const deviceState =
{Type: CrOnc.Type.TETHER, State: CrOnc.DeviceState.DISABLED}; deviceStates.find(deviceState => deviceState.type == kTether);
this.deviceState_ = deviceState || {
deviceState: chromeos.networkConfig.mojom.DeviceStateType.kDisabled,
managedNetworkAvailable: false,
scanning: false,
simAbsent: false,
type: kTether,
};
}); });
}, },
......
...@@ -38,6 +38,22 @@ class FakeNetworkConfig { ...@@ -38,6 +38,22 @@ class FakeNetworkConfig {
this.observers_.push(observer); this.observers_.push(observer);
} }
/**
* @return {!Promise<{result:
* !Array<!chromeos.networkConfig.mojom.DeviceStateProperties>}>}
*/
getDeviceStateList() {
return new Promise(resolve => {
this.extensionApi_.getDeviceStates(devices => {
let result = [];
devices.forEach(device => {
result.push(this.deviceToMojo_(device));
});
resolve({result: result});
});
});
}
/** /**
* @param {!chromeos.networkConfig.mojom.NetworkType} type * @param {!chromeos.networkConfig.mojom.NetworkType} type
* @param {boolean} enabled * @param {boolean} enabled
...@@ -51,4 +67,21 @@ class FakeNetworkConfig { ...@@ -51,4 +67,21 @@ class FakeNetworkConfig {
} }
return Promise.resolve(true); return Promise.resolve(true);
} }
/** @param { !chromeos.networkConfig.mojom.NetworkType } type */
requestNetworkScan(type) {
this.extensionApi_.requestNetworkScan();
}
/**
* @param {!chrome.networkingPrivate.DeviceStateProperties} device
* @return {!chromeos.networkConfig.mojom.DeviceStateProperties}
* @private
*/
deviceToMojo_(device) {
return {
deviceState: OncMojo.getDeviceStateTypeFromString(device.State),
type: OncMojo.getNetworkTypeFromString(device.Type),
};
}
} }
...@@ -27,6 +27,7 @@ if (is_chromeos) { ...@@ -27,6 +27,7 @@ if (is_chromeos) {
deps = [ deps = [
":cr_onc_types", ":cr_onc_types",
"//ui/webui/resources/js:assert", "//ui/webui/resources/js:assert",
"//ui/webui/resources/js/chromeos:onc_mojo",
] ]
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
<link rel="import" href="../../chromeos/network/cr_onc_types.html"> <link rel="import" href="../../chromeos/network/cr_onc_types.html">
<link rel="import" href="../../chromeos/network/network_icons.html"> <link rel="import" href="../../chromeos/network/network_icons.html">
<link rel="import" href="../../hidden_style_css.html"> <link rel="import" href="../../hidden_style_css.html">
<link rel="import" href="../../../html/chromeos/onc_mojo.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-icon/iron-icon.html"> <link rel="import" href="chrome://resources/polymer/v1_0/iron-icon/iron-icon.html">
<dom-module id="cr-network-icon"> <dom-module id="cr-network-icon">
......
...@@ -22,7 +22,7 @@ Polymer({ ...@@ -22,7 +22,7 @@ Polymer({
/** /**
* If set, the device state for the network type. Otherwise it defaults to * If set, the device state for the network type. Otherwise it defaults to
* null rather than undefined so that it does not block computed bindings. * null rather than undefined so that it does not block computed bindings.
* @type {?CrOnc.DeviceStateProperties} * @type {?OncMojo.DeviceStateProperties}
*/ */
deviceState: { deviceState: {
type: Object, type: Object,
...@@ -75,9 +75,10 @@ Polymer({ ...@@ -75,9 +75,10 @@ Polymer({
'cellular-' : 'cellular-' :
'wifi-'; 'wifi-';
if (!this.isListItem && !this.networkState.GUID) { if (!this.isListItem && !this.networkState.GUID) {
const deviceState = this.deviceState; const mojom = chromeos.networkConfig.mojom;
if (!deviceState || deviceState.State == 'Enabled' || const device = this.deviceState;
deviceState.State == 'Enabling') { if (!device || device.deviceState == mojom.DeviceStateType.kEnabled ||
device.deviceState == mojom.DeviceStateType.kEnabling) {
return prefix + 'no-network'; return prefix + 'no-network';
} }
return prefix + 'off'; return prefix + 'off';
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
import("//third_party/closure_compiler/compile_js.gni") import("//third_party/closure_compiler/compile_js.gni")
assert(is_chromeos, "Non-ChromeOS builds cannot depend on //chromeos")
group("closure_compile") { group("closure_compile") {
deps = [ deps = [
":js_resources", ":js_resources",
......
...@@ -102,6 +102,30 @@ class OncMojo { ...@@ -102,6 +102,30 @@ class OncMojo {
return ''; return '';
} }
/**
* @param {string} value
* @return {!chromeos.networkConfig.mojom.DeviceStateType}
*/
static getDeviceStateTypeFromString(value) {
const DeviceStateType = chromeos.networkConfig.mojom.DeviceStateType;
switch (value) {
case 'Uninitialized':
return DeviceStateType.kUninitialized;
case 'Disabled':
return DeviceStateType.kDisabled;
case 'Enabling':
return DeviceStateType.kEnabling;
case 'Enabled':
return DeviceStateType.kEnabled;
case 'Prohibited':
return DeviceStateType.kProhibited;
case 'Unavailable':
return DeviceStateType.kUnavailable;
}
assertNotReached();
return DeviceStateType.kUnavailable;
}
/** /**
* @param {!chromeos.networkConfig.mojom.NetworkType} value * @param {!chromeos.networkConfig.mojom.NetworkType} value
* @return {string} * @return {string}
...@@ -158,7 +182,7 @@ class OncMojo { ...@@ -158,7 +182,7 @@ class OncMojo {
case 'WiMAX': case 'WiMAX':
return NetworkType.kWiMAX; return NetworkType.kWiMAX;
} }
assertNotReached(); assertNotReached('Unexpected value: ' + value);
return NetworkType.kAll; return NetworkType.kAll;
} }
...@@ -246,6 +270,8 @@ class OncMojo { ...@@ -246,6 +270,8 @@ class OncMojo {
} }
} }
// Convenience types for commonly used chromeos.networkConfig.mojom types.
/** @typedef {chromeos.networkConfig.mojom.DeviceStateProperties} */ /** @typedef {chromeos.networkConfig.mojom.DeviceStateProperties} */
OncMojo.DeviceStateProperties; OncMojo.DeviceStateProperties;
......
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