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

Use mojo in network-ip-config and network-nameservers

Bug: 853953
Change-Id: I67129d3d0c68f750b4d907f8d37c8ef052dd9324
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1758591
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690250}
parent 7f11eed1
...@@ -145,7 +145,7 @@ ...@@ -145,7 +145,7 @@
<!-- IP Config --> <!-- IP Config -->
<div class="section single-column"> <div class="section single-column">
<network-ip-config editable on-ip-change="onIPConfigChange_" <network-ip-config editable on-ip-change="onIPConfigChange_"
network-properties="[[networkProperties]]"> managed-properties="[[managedProperties_]]">
</network-ip-config> </network-ip-config>
</div> </div>
...@@ -153,7 +153,7 @@ ...@@ -153,7 +153,7 @@
<div class="section single-column"> <div class="section single-column">
<network-nameservers editable <network-nameservers editable
on-nameservers-change="onIPConfigChange_" on-nameservers-change="onIPConfigChange_"
network-properties="[[networkProperties]]"> managed-properties="[[managedProperties_]]">
</network-nameservers> </network-nameservers>
</div> </div>
</template> </template>
......
...@@ -501,89 +501,21 @@ Polymer({ ...@@ -501,89 +501,21 @@ Polymer({
/** /**
* Event triggered when the IP Config or NameServers element changes. * Event triggered when the IP Config or NameServers element changes.
* TODO(stevenjb): Move this logic down to network_ip_config.js and
* network_nameservers.js and remove it from here and internet_detail_page.js.
* @param {!CustomEvent<!{ * @param {!CustomEvent<!{
* field: string, * field: string,
* value: (string|!CrOnc.IPConfigProperties|!Array<string>) * value: (string|!mojom.IPConfigProperties|!Array<string>)
* }>} event The network-ip-config or network-nameservers change event. * }>} event The network-ip-config or network-nameservers change event.
* @private * @private
*/ */
onIPConfigChange_: function(event) { onIPConfigChange_: function(event) {
if (!this.networkProperties) { if (!this.managedProperties_) {
return; return;
} }
const field = event.detail.field; const config = OncMojo.getUpdatedIPConfigProperties(
const value = event.detail.value; this.managedProperties_, event.detail.field, event.detail.value);
// Get an empty ONC dictionary and set just the IP Config properties that if (config) {
// need to change. this.setMojoNetworkProperties_(config);
const onc = this.getEmptyNetworkProperties_();
const ipConfigType =
/** @type {chrome.networkingPrivate.IPConfigType|undefined} */ (
CrOnc.getActiveValue(this.networkProperties.IPAddressConfigType));
if (field == 'IPAddressConfigType') {
const newIpConfigType =
/** @type {chrome.networkingPrivate.IPConfigType} */ (value);
if (newIpConfigType == ipConfigType) {
return;
}
onc.IPAddressConfigType = newIpConfigType;
} else if (field == 'NameServersConfigType') {
const nsConfigType =
/** @type {chrome.networkingPrivate.IPConfigType|undefined} */ (
CrOnc.getActiveValue(
this.networkProperties.NameServersConfigType));
const newNsConfigType =
/** @type {chrome.networkingPrivate.IPConfigType} */ (value);
if (newNsConfigType == nsConfigType) {
return;
}
onc.NameServersConfigType = newNsConfigType;
} else if (field == 'StaticIPConfig') {
if (ipConfigType == CrOnc.IPConfigType.STATIC) {
const staticIpConfig = this.networkProperties.StaticIPConfig;
const ipConfigValue = /** @type {!Object} */ (value);
if (staticIpConfig &&
this.allPropertiesMatch_(staticIpConfig, ipConfigValue)) {
return;
}
}
onc.IPAddressConfigType = CrOnc.IPConfigType.STATIC;
if (!onc.StaticIPConfig) {
onc.StaticIPConfig =
/** @type {!chrome.networkingPrivate.IPConfigProperties} */ ({});
}
// Only copy Static IP properties.
const keysToCopy = ['Type', 'IPAddress', 'RoutingPrefix', 'Gateway'];
for (let i = 0; i < keysToCopy.length; ++i) {
const key = keysToCopy[i];
if (key in value) {
onc.StaticIPConfig[key] = value[key];
}
}
} else if (field == 'NameServers') {
// If a StaticIPConfig property is specified and its NameServers value
// matches the new value, no need to set anything.
const nameServers = /** @type {!Array<string>} */ (value);
if (onc.NameServersConfigType == CrOnc.IPConfigType.STATIC &&
onc.StaticIPConfig && onc.StaticIPConfig.NameServers == nameServers) {
return;
}
onc.NameServersConfigType = CrOnc.IPConfigType.STATIC;
if (!onc.StaticIPConfig) {
onc.StaticIPConfig =
/** @type {!chrome.networkingPrivate.IPConfigProperties} */ ({});
}
onc.StaticIPConfig.NameServers = nameServers;
} else {
console.error('Unexpected change field: ' + field);
return;
} }
// setValidStaticIPConfig will fill in any other properties from
// networkProperties. This is necessary since we update IP Address and
// NameServers independently.
CrOnc.setValidStaticIPConfig(onc, this.networkProperties);
this.setNetworkProperties_(onc);
}, },
/** /**
...@@ -645,19 +577,5 @@ Polymer({ ...@@ -645,19 +577,5 @@ Polymer({
fields.push('MacAddress'); fields.push('MacAddress');
return fields; return fields;
}, },
/**
* @param {!Object} curValue
* @param {!Object} newValue
* @return {boolean} True if all properties set in |newValue| are equal to
* the corresponding properties in |curValue|. Note: Not all properties
* of |curValue| need to be specified in |newValue| for this to return
* true.
* @private
*/
allPropertiesMatch_: function(curValue, newValue) {
return Object.getOwnPropertyNames(newValue).every(
key => newValue[key] == curValue[key]);
}
}); });
})(); })();
...@@ -312,10 +312,10 @@ ...@@ -312,10 +312,10 @@
<template is="dom-if" <template is="dom-if"
if="[[isRememberedOrConnected_(managedProperties_)]]"> if="[[isRememberedOrConnected_(managedProperties_)]]">
<network-ip-config on-ip-change="onIPConfigChange_" <network-ip-config on-ip-change="onIPConfigChange_"
network-properties="[[networkProperties_]]"> managed-properties="[[managedProperties_]]">
</network-ip-config> </network-ip-config>
<network-nameservers on-nameservers-change="onIPConfigChange_" <network-nameservers on-nameservers-change="onIPConfigChange_"
network-properties="[[networkProperties_]]"> managed-properties="[[managedProperties_]]">
</network-nameservers> </network-nameservers>
</template> </template>
</div> </div>
......
...@@ -1196,85 +1196,19 @@ Polymer({ ...@@ -1196,85 +1196,19 @@ Polymer({
* Event triggered when the IP Config or NameServers element changes. * Event triggered when the IP Config or NameServers element changes.
* @param {!CustomEvent<!{ * @param {!CustomEvent<!{
* field: string, * field: string,
* value: (string|!CrOnc.IPConfigProperties| !Array<string>) * value: (string|!mojom.IPConfigProperties|!Array<string>)
* }>} event The network-ip-config or network-nameservers change event. * }>} event The network-ip-config or network-nameservers change event.
* @private * @private
*/ */
onIPConfigChange_: function(event) { onIPConfigChange_: function(event) {
if (!this.networkProperties_) { if (!this.managedProperties_) {
return; return;
} }
const field = event.detail.field; const config = OncMojo.getUpdatedIPConfigProperties(
const value = event.detail.value; this.managedProperties_, event.detail.field, event.detail.value);
// Get an empty ONC dictionary and set just the IP Config properties that if (config) {
// need to change. this.setMojoNetworkProperties_(config);
const onc = this.getEmptyNetworkProperties_();
const ipConfigType =
/** @type {chrome.networkingPrivate.IPConfigType|undefined} */ (
CrOnc.getActiveValue(this.networkProperties_.IPAddressConfigType));
if (field == 'IPAddressConfigType') {
const newIpConfigType =
/** @type {chrome.networkingPrivate.IPConfigType} */ (value);
if (newIpConfigType == ipConfigType) {
return;
}
onc.IPAddressConfigType = newIpConfigType;
} else if (field == 'NameServersConfigType') {
const nsConfigType =
/** @type {chrome.networkingPrivate.IPConfigType|undefined} */ (
CrOnc.getActiveValue(
this.networkProperties_.NameServersConfigType));
const newNsConfigType =
/** @type {chrome.networkingPrivate.IPConfigType} */ (value);
if (newNsConfigType == nsConfigType) {
return;
}
onc.NameServersConfigType = newNsConfigType;
} else if (field == 'StaticIPConfig') {
if (ipConfigType == CrOnc.IPConfigType.STATIC) {
const staticIpConfig = this.networkProperties_.StaticIPConfig;
const ipConfigValue = /** @type {!Object} */ (value);
if (staticIpConfig &&
this.allPropertiesMatch_(staticIpConfig, ipConfigValue)) {
return;
}
}
onc.IPAddressConfigType = CrOnc.IPConfigType.STATIC;
if (!onc.StaticIPConfig) {
onc.StaticIPConfig =
/** @type {!chrome.networkingPrivate.IPConfigProperties} */ ({});
}
// Only copy Static IP properties.
const keysToCopy = ['Type', 'IPAddress', 'RoutingPrefix', 'Gateway'];
for (let i = 0; i < keysToCopy.length; ++i) {
const key = keysToCopy[i];
if (key in value) {
onc.StaticIPConfig[key] = value[key];
}
}
} else if (field == 'NameServers') {
// If a StaticIPConfig property is specified and its NameServers value
// matches the new value, no need to set anything.
const nameServers = /** @type {!Array<string>} */ (value);
if (onc.NameServersConfigType == CrOnc.IPConfigType.STATIC &&
onc.StaticIPConfig && onc.StaticIPConfig.NameServers == nameServers) {
return;
}
onc.NameServersConfigType = CrOnc.IPConfigType.STATIC;
if (!onc.StaticIPConfig) {
onc.StaticIPConfig =
/** @type {!chrome.networkingPrivate.IPConfigProperties} */ ({});
}
onc.StaticIPConfig.NameServers = nameServers;
} else {
console.error('Unexpected change field: ' + field);
return;
} }
// setValidStaticIPConfig will fill in any other properties from
// networkProperties. This is necessary since we update IP Address and
// NameServers independently.
CrOnc.setValidStaticIPConfig(onc, this.networkProperties_);
this.setNetworkProperties_(onc);
}, },
/** /**
......
...@@ -55,9 +55,6 @@ suite('CrPolicyNetworkBehavior', function() { ...@@ -55,9 +55,6 @@ suite('CrPolicyNetworkBehavior', function() {
assertTrue(testBehavior.isEditable(properties.a)); assertTrue(testBehavior.isEditable(properties.a));
assertFalse(testBehavior.isNetworkPolicyEnforced(properties.a)); assertFalse(testBehavior.isNetworkPolicyEnforced(properties.a));
assertTrue(testBehavior.isNetworkPolicyRecommended(properties.a)); assertTrue(testBehavior.isNetworkPolicyRecommended(properties.a));
assertEquals(
CrPolicyIndicatorType.USER_POLICY,
testBehavior.getPolicyIndicatorType_(properties, 'a'));
}); });
test('device_recommended', function() { test('device_recommended', function() {
...@@ -76,9 +73,6 @@ suite('CrPolicyNetworkBehavior', function() { ...@@ -76,9 +73,6 @@ suite('CrPolicyNetworkBehavior', function() {
assertTrue(testBehavior.isEditable(properties.a)); assertTrue(testBehavior.isEditable(properties.a));
assertFalse(testBehavior.isNetworkPolicyEnforced(properties.a)); assertFalse(testBehavior.isNetworkPolicyEnforced(properties.a));
assertTrue(testBehavior.isNetworkPolicyRecommended(properties.a)); assertTrue(testBehavior.isNetworkPolicyRecommended(properties.a));
assertEquals(
CrPolicyIndicatorType.DEVICE_POLICY,
testBehavior.getPolicyIndicatorType_(properties, 'a'));
}); });
test('user_enforced', function() { test('user_enforced', function() {
...@@ -96,9 +90,6 @@ suite('CrPolicyNetworkBehavior', function() { ...@@ -96,9 +90,6 @@ suite('CrPolicyNetworkBehavior', function() {
assertFalse(testBehavior.isEditable(properties.a)); assertFalse(testBehavior.isEditable(properties.a));
assertTrue(testBehavior.isNetworkPolicyEnforced(properties.a)); assertTrue(testBehavior.isNetworkPolicyEnforced(properties.a));
assertFalse(testBehavior.isNetworkPolicyRecommended(properties.a)); assertFalse(testBehavior.isNetworkPolicyRecommended(properties.a));
assertEquals(
CrPolicyIndicatorType.USER_POLICY,
testBehavior.getPolicyIndicatorType_(properties, 'a'));
}); });
test('device_enforced', function() { test('device_enforced', function() {
...@@ -116,9 +107,6 @@ suite('CrPolicyNetworkBehavior', function() { ...@@ -116,9 +107,6 @@ suite('CrPolicyNetworkBehavior', function() {
assertFalse(testBehavior.isEditable(properties.a)); assertFalse(testBehavior.isEditable(properties.a));
assertTrue(testBehavior.isNetworkPolicyEnforced(properties.a)); assertTrue(testBehavior.isNetworkPolicyEnforced(properties.a));
assertFalse(testBehavior.isNetworkPolicyRecommended(properties.a)); assertFalse(testBehavior.isNetworkPolicyRecommended(properties.a));
assertEquals(
CrPolicyIndicatorType.DEVICE_POLICY,
testBehavior.getPolicyIndicatorType_(properties, 'a'));
}); });
test('extension_controlled', function() { test('extension_controlled', function() {
...@@ -136,11 +124,5 @@ suite('CrPolicyNetworkBehavior', function() { ...@@ -136,11 +124,5 @@ suite('CrPolicyNetworkBehavior', function() {
assertFalse(testBehavior.isEditable(properties.a)); assertFalse(testBehavior.isEditable(properties.a));
assertFalse(testBehavior.isNetworkPolicyEnforced(properties.a)); assertFalse(testBehavior.isNetworkPolicyEnforced(properties.a));
assertFalse(testBehavior.isNetworkPolicyRecommended(properties.a)); assertFalse(testBehavior.isNetworkPolicyRecommended(properties.a));
// TODO(stevenjb): We should probably show the correct indicator for
// extension controlled properties; fix this in the mojo code.
assertEquals(
CrPolicyIndicatorType.NONE,
testBehavior.getPolicyIndicatorType_(properties, 'a'));
}); });
}); });
...@@ -1546,6 +1546,8 @@ void CrosNetworkConfig::SetProperties(const std::string& guid, ...@@ -1546,6 +1546,8 @@ void CrosNetworkConfig::SetProperties(const std::string& guid,
SetString(::onc::ipconfig::kType, ip_config.type, &ip_config_dict); SetString(::onc::ipconfig::kType, ip_config.type, &ip_config_dict);
SetString(::onc::ipconfig::kWebProxyAutoDiscoveryUrl, SetString(::onc::ipconfig::kWebProxyAutoDiscoveryUrl,
ip_config.web_proxy_auto_discovery_url, &ip_config_dict); ip_config.web_proxy_auto_discovery_url, &ip_config_dict);
onc.SetKey(::onc::network_config::kStaticIPConfig,
std::move(ip_config_dict));
} }
if (!type_dict.DictEmpty()) { if (!type_dict.DictEmpty()) {
std::string type = network_util::TranslateShillTypeToONC(network->type()); std::string type = network_util::TranslateShillTypeToONC(network->type());
......
...@@ -98,13 +98,16 @@ js_library("network_ip_config") { ...@@ -98,13 +98,16 @@ js_library("network_ip_config") {
deps = [ deps = [
"//ui/webui/resources/cr_elements/chromeos/network:cr_onc_types", "//ui/webui/resources/cr_elements/chromeos/network:cr_onc_types",
"//ui/webui/resources/js:i18n_behavior", "//ui/webui/resources/js:i18n_behavior",
"//ui/webui/resources/js/chromeos:onc_mojo",
] ]
} }
js_library("network_nameservers") { js_library("network_nameservers") {
deps = [ deps = [
"//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_mojo",
"//ui/webui/resources/js:i18n_behavior", "//ui/webui/resources/js:i18n_behavior",
"//ui/webui/resources/js/chromeos:onc_mojo",
] ]
} }
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
<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/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/policy/cr_policy_network_behavior.html"> <link rel="import" href="chrome://resources/cr_elements/policy/cr_policy_network_behavior_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="network_property_list.html"> <link rel="import" href="network_property_list_mojo.html">
<link rel="import" href="network_shared_css.html"> <link rel="import" href="network_shared_css.html">
<dom-module id="network-ip-config"> <dom-module id="network-ip-config">
...@@ -19,23 +19,23 @@ ...@@ -19,23 +19,23 @@
<div id="autoIPConfigLabel" class="start"> <div id="autoIPConfigLabel" class="start">
[[i18n('networkIPConfigAuto')]] [[i18n('networkIPConfigAuto')]]
</div> </div>
<cr-policy-indicator indicator-type="[[getPolicyIndicatorType_( <cr-policy-indicator indicator-type="[[getPolicyIndicatorType(
networkProperties, 'IPAddressConfigType')]]"> managedProperties.ipAddressConfigType)]]">
</cr-policy-indicator> </cr-policy-indicator>
<cr-toggle checked="{{automatic_}}" <cr-toggle checked="{{automatic_}}"
disabled="[[!canChangeIPConfigType_(networkProperties)]]" disabled="[[!canChangeIPConfigType_(managedProperties)]]"
on-change="onAutomaticChange_" on-change="onAutomaticChange_"
aria-labelledby="autoIPConfigLabel"> aria-labelledby="autoIPConfigLabel">
</cr-toggle> </cr-toggle>
</div> </div>
<template is="dom-if" if="[[hasIpConfigFields_(ipConfig_)]]"> <template is="dom-if" if="[[hasIpConfigFields_(ipConfig_)]]">
<div class="property-box single-column indented stretch"> <div class="property-box single-column indented stretch">
<network-property-list fields="[[ipConfigFields_]]" <network-property-list-mojo fields="[[ipConfigFields_]]"
property-dict="[[ipConfig_]]" property-dict="[[ipConfig_]]"
edit-field-types="[[getIPEditFields_(automatic_, edit-field-types="[[getIPEditFields_(automatic_,
networkProperties)]]" managedProperties)]]"
on-property-change="onIPChange_"> on-property-change="onIPChange_">
</network-property-list> </network-property-list-mojo>
</div> </div>
</template> </template>
</template> </template>
......
...@@ -6,20 +6,19 @@ ...@@ -6,20 +6,19 @@
* @fileoverview Polymer element for displaying the IP Config properties for * @fileoverview Polymer element for displaying the IP Config properties for
* a network state. * a network state.
*/ */
(function() {
'use strict';
Polymer({ Polymer({
is: 'network-ip-config', is: 'network-ip-config',
behaviors: [I18nBehavior, CrPolicyNetworkBehavior], behaviors: [I18nBehavior, CrPolicyNetworkBehaviorMojo],
properties: { properties: {
/** /** @private {!chromeos.networkConfig.mojom.ManagedProperties|undefined} */
* The network properties dictionary containing the IP Config properties to managedProperties: {
* display and modify.
* @type {!CrOnc.NetworkProperties|undefined}
*/
networkProperties: {
type: Object, type: Object,
observer: 'networkPropertiesChanged_', observer: 'managedPropertiesChanged_',
}, },
/** /**
...@@ -32,11 +31,10 @@ Polymer({ ...@@ -32,11 +31,10 @@ Polymer({
}, },
/** /**
* The currently visible IP Config property dictionary. The 'RoutingPrefix' * The currently visible IP Config property dictionary.
* property is a human-readable mask instead of a prefix length.
* @private {{ * @private {{
* ipv4: (!CrOnc.IPConfigUIProperties|undefined), * ipv4: (OncMojo.IPConfigUIProperties|undefined),
* ipv6: (!CrOnc.IPConfigUIProperties|undefined) * ipv6: (OncMojo.IPConfigUIProperties|undefined)
* }|undefined} * }|undefined}
*/ */
ipConfig_: Object, ipConfig_: Object,
...@@ -49,10 +47,10 @@ Polymer({ ...@@ -49,10 +47,10 @@ Polymer({
type: Array, type: Array,
value: function() { value: function() {
return [ return [
'ipv4.IPAddress', 'ipv4.ipAddress',
'ipv4.RoutingPrefix', 'ipv4.routingPrefix',
'ipv4.Gateway', 'ipv4.gateway',
'ipv6.IPAddress', 'ipv6.ipAddress',
]; ];
}, },
readOnly: true readOnly: true
...@@ -61,39 +59,38 @@ Polymer({ ...@@ -61,39 +59,38 @@ Polymer({
/** /**
* Saved static IP configuration properties when switching to 'automatic'. * Saved static IP configuration properties when switching to 'automatic'.
* @private {!CrOnc.IPConfigUIProperties|undefined} * @private {!OncMojo.IPConfigUIProperties|undefined}
*/ */
savedStaticIp_: undefined, savedStaticIp_: undefined,
/** /** @private */
* Polymer networkProperties changed method. managedPropertiesChanged_: function(newValue, oldValue) {
*/ if (!this.managedProperties) {
networkPropertiesChanged_: function(newValue, oldValue) {
if (!this.networkProperties) {
return; return;
} }
const properties = this.networkProperties; const properties = this.managedProperties;
if (newValue.GUID != (oldValue && oldValue.GUID)) { if (newValue.guid != (oldValue && oldValue.guid)) {
this.savedStaticIp_ = undefined; this.savedStaticIp_ = undefined;
} }
// Update the 'automatic' property. // Update the 'automatic' property.
if (properties.IPAddressConfigType) { if (properties.ipAddressConfigType) {
const ipConfigType = CrOnc.getActiveValue(properties.IPAddressConfigType); const ipConfigType =
this.automatic_ = (ipConfigType != CrOnc.IPConfigType.STATIC); OncMojo.getActiveValue(properties.ipAddressConfigType);
this.automatic_ = ipConfigType != 'Static';
} }
if (properties.IPConfigs || properties.StaticIPConfig) { if (properties.ipConfigs || properties.staticIpConfig) {
// Update the 'ipConfig' property. // Update the 'ipConfig' property.
const ipv4 = this.getIPConfigUIProperties_( const ipv4 = this.getIPConfigUIProperties_(
CrOnc.getIPConfigForType(properties, CrOnc.IPType.IPV4)); OncMojo.getIPConfigForType(properties, 'IPv4'));
let ipv6 = this.getIPConfigUIProperties_( let ipv6 = this.getIPConfigUIProperties_(
CrOnc.getIPConfigForType(properties, CrOnc.IPType.IPV6)); OncMojo.getIPConfigForType(properties, 'IPv6'));
if (properties.ConnectionState == CrOnc.ConnectionState.CONNECTED && if (OncMojo.connectionStateIsConnected(properties.connectionState) &&
ipv4 && ipv4.IPAddress) { ipv4 && ipv4.ipAddress) {
ipv6 = ipv6 || {}; ipv6 = ipv6 || {};
ipv6.IPAddress = ipv6.IPAddress || this.i18n('loading'); ipv6.ipAddress = ipv6.ipAddress || this.i18n('loading');
} }
this.ipConfig_ = {ipv4: ipv4, ipv6: ipv6}; this.ipConfig_ = {ipv4: ipv4, ipv6: ipv6};
} else { } else {
...@@ -103,24 +100,23 @@ Polymer({ ...@@ -103,24 +100,23 @@ Polymer({
/** /**
* Checks whether IP address config type can be changed. * Checks whether IP address config type can be changed.
* @param {!CrOnc.NetworkProperties} networkProperties * @param {!chromeos.networkConfig.mojom.ManagedProperties} managedProperties
* @return {boolean} true only if 'IPAddressConfigType' as well as all other * @return {boolean}
* IP address config related fields are editable.
* @private * @private
*/ */
canChangeIPConfigType_: function(networkProperties) { canChangeIPConfigType_: function(managedProperties) {
return !this.isNetworkPolicyPathEnforced( const ipConfigType = managedProperties.ipAddressConfigType;
networkProperties, 'IPAddressConfigType'); return !ipConfigType || !this.isNetworkPolicyEnforced(ipConfigType);
}, },
/** @private */ /** @private */
onAutomaticChange_: function() { onAutomaticChange_: function() {
if (!this.automatic_) { if (!this.automatic_) {
const defaultIpv4 = { const defaultIpv4 = {
Gateway: '192.168.1.1', gateway: '192.168.1.1',
IPAddress: '192.168.1.1', ipAddress: '192.168.1.1',
RoutingPrefix: '255.255.255.0', routingPrefix: '255.255.255.0',
Type: CrOnc.IPType.IPV4, type: 'IPv4',
}; };
// Ensure that there is a valid IPConfig object. Copy any set properties // Ensure that there is a valid IPConfig object. Copy any set properties
// over the default properties to ensure all properties are set. // over the default properties to ensure all properties are set.
...@@ -137,18 +133,19 @@ Polymer({ ...@@ -137,18 +133,19 @@ Polymer({
if (this.ipConfig_) { if (this.ipConfig_) {
this.savedStaticIp_ = this.ipConfig_.ipv4; this.savedStaticIp_ = this.ipConfig_.ipv4;
} }
// Send the change.
this.fire('ip-change', { this.fire('ip-change', {
field: 'IPAddressConfigType', field: 'ipAddressConfigType',
value: CrOnc.IPConfigType.DHCP, value: 'DHCP',
}); });
}, },
/** /**
* @param {!CrOnc.IPConfigProperties|undefined} ipconfig * @param {!chromeos.networkConfig.mojom.IPConfigProperties|undefined}
* @return {!CrOnc.IPConfigUIProperties|undefined} A new IPConfigUIProperties * ipconfig
* object with RoutingPrefix expressed as a string mask instead of a * @return {!OncMojo.IPConfigUIProperties|undefined} A new
* prefix length. Returns undefined if |ipconfig| is not defined. * IPConfigUIProperties object with routingPrefix expressed as a string
* mask instead of a prefix length. Returns undefined if |ipconfig| is not
* defined.
* @private * @private
*/ */
getIPConfigUIProperties_: function(ipconfig) { getIPConfigUIProperties_: function(ipconfig) {
...@@ -158,8 +155,8 @@ Polymer({ ...@@ -158,8 +155,8 @@ Polymer({
const result = {}; const result = {};
for (const key in ipconfig) { for (const key in ipconfig) {
const value = ipconfig[key]; const value = ipconfig[key];
if (key == 'RoutingPrefix') { if (key == 'routingPrefix') {
result.RoutingPrefix = CrOnc.getRoutingPrefixAsNetmask(value); result.routingPrefix = CrOnc.getRoutingPrefixAsNetmask(value);
} else { } else {
result[key] = value; result[key] = value;
} }
...@@ -168,17 +165,18 @@ Polymer({ ...@@ -168,17 +165,18 @@ Polymer({
}, },
/** /**
* @param {!CrOnc.IPConfigUIProperties} ipconfig The IP Config UI properties. * @param {!OncMojo.IPConfigUIProperties} ipconfig
* @return {!CrOnc.IPConfigProperties} A new IPConfigProperties object with * @return {!chromeos.networkConfig.mojom.IPConfigProperties} A new
* RoutingPrefix expressed as a a prefix length. * IPConfigProperties object with RoutingPrefix expressed as a a prefix
* length.
* @private * @private
*/ */
getIPConfigProperties_: function(ipconfig) { getIPConfigProperties_: function(ipconfig) {
const result = {}; const result = {};
for (const key in ipconfig) { for (const key in ipconfig) {
const value = ipconfig[key]; const value = ipconfig[key];
if (key == 'RoutingPrefix') { if (key == 'routingPrefix') {
result.RoutingPrefix = CrOnc.getRoutingPrefixAsLength(value); result.routingPrefix = CrOnc.getRoutingPrefixAsLength(value);
} else { } else {
result[key] = value; result[key] = value;
} }
...@@ -203,17 +201,19 @@ Polymer({ ...@@ -203,17 +201,19 @@ Polymer({
}, },
/** /**
* @param {string} path path to a property inside of |networkProperties| * @param {string} path path to a property inside of |managedProperties|.
* dictionary.
* @return {string|undefined} Edit type to be used in network-property-list * @return {string|undefined} Edit type to be used in network-property-list
* for the given path. * for the given path.
* @private * @private
*/ */
getIPFieldEditType_: function(path) { getIPFieldEditType_: function(path) {
return this.networkProperties && if (!this.managedProperties) {
this.isNetworkPolicyPathEnforced(this.networkProperties, path) ? return undefined;
undefined : }
'String'; const property = /** @type{!OncMojo.ManagedProperty|undefined}*/ (
this.get(path, this.managedProperties));
return (property && this.isNetworkPolicyEnforced(property)) ? undefined :
'String';
}, },
/** /**
...@@ -221,14 +221,14 @@ Polymer({ ...@@ -221,14 +221,14 @@ Polymer({
* @private * @private
*/ */
getIPEditFields_: function() { getIPEditFields_: function() {
if (this.automatic_ || !this.networkProperties) { if (this.automatic_ || !this.managedProperties) {
return {}; return {};
} }
return { return {
'ipv4.IPAddress': this.getIPFieldEditType_('StaticIPConfig.IPAddress'), 'ipv4.ipAddress': this.getIPFieldEditType_('staticIpConfig.ipAddress'),
'ipv4.RoutingPrefix': 'ipv4.routingPrefix':
this.getIPFieldEditType_('StaticIPConfig.RoutingPrefix'), this.getIPFieldEditType_('staticIpConfig.routingPrefix'),
'ipv4.Gateway': this.getIPFieldEditType_('StaticIPConfig.Gateway') 'ipv4.gateway': this.getIPFieldEditType_('staticIpConfig.gateway')
}; };
}, },
...@@ -253,10 +253,11 @@ Polymer({ ...@@ -253,10 +253,11 @@ Polymer({
sendStaticIpConfig_: function() { sendStaticIpConfig_: function() {
// This will also set IPAddressConfigType to STATIC. // This will also set IPAddressConfigType to STATIC.
this.fire('ip-change', { this.fire('ip-change', {
field: 'StaticIPConfig', field: 'staticIpConfig',
value: this.ipConfig_.ipv4 ? value: this.ipConfig_.ipv4 ?
this.getIPConfigProperties_(this.ipConfig_.ipv4) : this.getIPConfigProperties_(this.ipConfig_.ipv4) :
{} {}
}); });
}, },
}); });
})();
<link rel="import" href="chrome://resources/html/polymer.html"> <link rel="import" href="chrome://resources/html/polymer.html">
<link rel="import" href="chrome://resources/cr_elements/chromeos/network/cr_onc_types.html">
<link rel="import" href="chrome://resources/cr_elements/cr_input/cr_input.html"> <link rel="import" href="chrome://resources/cr_elements/cr_input/cr_input.html">
<link rel="import" href="chrome://resources/cr_elements/cr_radio_button/cr_radio_button.html"> <link rel="import" href="chrome://resources/cr_elements/cr_radio_button/cr_radio_button.html">
<link rel="import" href="chrome://resources/cr_elements/cr_radio_group/cr_radio_group.html"> <link rel="import" href="chrome://resources/cr_elements/cr_radio_group/cr_radio_group.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/policy/cr_policy_network_behavior.html"> <link rel="import" href="chrome://resources/cr_elements/policy/cr_policy_network_behavior_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/cr_elements/md_select_css.html"> <link rel="import" href="chrome://resources/cr_elements/md_select_css.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">
...@@ -57,8 +56,8 @@ ...@@ -57,8 +56,8 @@
<div class="start"> <div class="start">
[[i18n('networkNameservers')]] [[i18n('networkNameservers')]]
</div> </div>
<cr-policy-indicator indicator-type="[[getPolicyIndicatorType_( <cr-policy-indicator indicator-type="[[getPolicyIndicatorType(
networkProperties, 'NameServersConfigType')]]"> managedProperties.nameServersConfigType)]]">
</cr-policy-indicator> </cr-policy-indicator>
</div> </div>
<div id="radioGroupDiv"> <div id="radioGroupDiv">
...@@ -106,7 +105,7 @@ ...@@ -106,7 +105,7 @@
<cr-input id="nameserver[[index]]" value="[[item]]" <cr-input id="nameserver[[index]]" value="[[item]]"
on-change="onValueChange_" on-change="onValueChange_"
disabled="[[!canEditCustomNameServers_(nameserversType_, disabled="[[!canEditCustomNameServers_(nameserversType_,
networkProperties)]]"> managedProperties)]]">
</cr-input> </cr-input>
</template> </template>
</div> </div>
......
...@@ -8,17 +8,13 @@ ...@@ -8,17 +8,13 @@
Polymer({ Polymer({
is: 'network-nameservers', is: 'network-nameservers',
behaviors: [I18nBehavior, CrPolicyNetworkBehavior], behaviors: [I18nBehavior, CrPolicyNetworkBehaviorMojo],
properties: { properties: {
/** /** @private {!chromeos.networkConfig.mojom.ManagedProperties|undefined} */
* The network properties dictionary containing the nameserver properties to managedProperties: {
* display and modify.
* @type {!CrOnc.NetworkProperties|undefined}
*/
networkProperties: {
type: Object, type: Object,
observer: 'networkPropertiesChanged_', observer: 'managedPropertiesChanged_',
}, },
/** /**
...@@ -53,7 +49,7 @@ Polymer({ ...@@ -53,7 +49,7 @@ Polymer({
/** @private */ /** @private */
canChangeConfigType_: { canChangeConfigType_: {
type: Boolean, type: Boolean,
computed: 'computeCanChangeConfigType_(networkProperties)', computed: 'computeCanChangeConfigType_(managedProperties)',
} }
}, },
...@@ -109,28 +105,27 @@ Polymer({ ...@@ -109,28 +105,27 @@ Polymer({
}, },
/** @private */ /** @private */
networkPropertiesChanged_: function(newValue, oldValue) { managedPropertiesChanged_: function(newValue, oldValue) {
if (!this.networkProperties) { if (!this.managedProperties) {
return; return;
} }
if (!oldValue || newValue.GUID != oldValue.GUID) { if (!oldValue || newValue.guid != oldValue.guid) {
this.savedNameservers_ = []; this.savedNameservers_ = [];
} }
// Update the 'nameservers' property. // Update the 'nameservers' property.
let nameservers = []; let nameservers = [];
const ipv4 = const ipv4 = OncMojo.getIPConfigForType(this.managedProperties, 'IPv4');
CrOnc.getIPConfigForType(this.networkProperties, CrOnc.IPType.IPV4); if (ipv4 && ipv4.nameServers) {
if (ipv4 && ipv4.NameServers) { nameservers = ipv4.nameServers;
nameservers = ipv4.NameServers;
} }
// Update the 'nameserversType' property. // Update the 'nameserversType' property.
const configType = const configType =
CrOnc.getActiveValue(this.networkProperties.NameServersConfigType); OncMojo.getActiveValue(this.managedProperties.nameServersConfigType);
let type; let type;
if (configType == CrOnc.IPConfigType.STATIC) { if (configType == 'Static') {
if (this.isGoogleNameservers_(nameservers)) { if (this.isGoogleNameservers_(nameservers)) {
type = 'google'; type = 'google';
nameservers = this.GOOGLE_NAMESERVERS; // Use consistent order. nameservers = this.GOOGLE_NAMESERVERS; // Use consistent order.
...@@ -172,30 +167,51 @@ Polymer({ ...@@ -172,30 +167,51 @@ Polymer({
}, },
/** /**
* @param {!CrOnc.NetworkProperties} networkProperties * @param {!chromeos.networkConfig.mojom.ManagedProperties} managedProperties
* @return {boolean} True if the nameservers config type type can be changed. * @return {boolean} True if the nameservers config type type can be changed.
* @private * @private
*/ */
computeCanChangeConfigType_: function(networkProperties) { computeCanChangeConfigType_: function(managedProperties) {
return !this.isNetworkPolicyPathEnforced( if (!managedProperties) {
networkProperties, 'NameServersConfigType') && return false;
!this.isNetworkPolicyPathEnforced( }
networkProperties, 'StaticIPConfig.NameServers'); if (managedProperties.nameServersConfigType &&
this.isNetworkPolicyEnforced(managedProperties.nameServersConfigType)) {
return false;
}
if (managedProperties.staticIpConfig &&
managedProperties.staticIpConfig.nameServers &&
this.isNetworkPolicyEnforced(
managedProperties.staticIpConfig.nameServers)) {
return false;
}
return true;
}, },
/** /**
* @param {string} nameserversType * @param {string} nameserversType
* @param {!CrOnc.NetworkProperties} networkProperties * @param {!chromeos.networkConfig.mojom.ManagedProperties} managedProperties
* @return {boolean} True if the nameservers are editable. * @return {boolean} True if the nameservers are editable.
* @private * @private
*/ */
canEditCustomNameServers_: function(nameserversType, networkProperties) { canEditCustomNameServers_: function(nameserversType, managedProperties) {
return nameserversType == 'custom' && if (!managedProperties) {
!this.isNetworkPolicyEnforced( return false;
networkProperties.NameServersConfigType) && }
(!networkProperties.StaticIPConfig || if (nameserversType != 'custom') {
!this.isNetworkPolicyEnforced( return false;
networkProperties.StaticIPConfig.NameServers)); }
if (managedProperties.nameServersConfigType &&
this.isNetworkPolicyEnforced(managedProperties.nameServersConfigType)) {
return false;
}
if (managedProperties.staticIpConfig &&
managedProperties.staticIpConfig.nameServers &&
this.isNetworkPolicyEnforced(
managedProperties.staticIpConfig.nameServers)) {
return false;
}
return true;
}, },
/** /**
...@@ -266,27 +282,27 @@ Polymer({ ...@@ -266,27 +282,27 @@ Polymer({
this.nameservers_ = nameservers; this.nameservers_ = nameservers;
this.savedNameservers_ = nameservers.slice(); this.savedNameservers_ = nameservers.slice();
this.fire('nameservers-change', { this.fire('nameservers-change', {
field: 'NameServers', field: 'nameServers',
value: nameservers, value: nameservers,
}); });
} else if (type == 'google') { } else if (type == 'google') {
this.nameservers_ = this.GOOGLE_NAMESERVERS; this.nameservers_ = this.GOOGLE_NAMESERVERS;
this.fire('nameservers-change', { this.fire('nameservers-change', {
field: 'NameServers', field: 'nameServers',
value: this.GOOGLE_NAMESERVERS, value: this.GOOGLE_NAMESERVERS,
}); });
} else { // type == automatic } else { // type == automatic
// If not connected, properties will clear. Otherwise they may or may not // If not connected, properties will clear. Otherwise they may or may not
// change so leave them as-is. // change so leave them as-is.
if (this.networkProperties.ConnectionState != if (!OncMojo.connectionStateIsConnected(
CrOnc.ConnectionState.CONNECTED) { this.managedProperties.connectionState)) {
this.nameservers_ = []; this.nameservers_ = [];
} else { } else {
this.nameservers_ = this.clearEmptyNameServers_(this.nameservers_); this.nameservers_ = this.clearEmptyNameServers_(this.nameservers_);
} }
this.fire('nameservers-change', { this.fire('nameservers-change', {
field: 'NameServersConfigType', field: 'nameServersConfigType',
value: CrOnc.IPConfigType.DHCP, value: 'DHCP',
}); });
} }
}, },
......
...@@ -99,8 +99,12 @@ Polymer({ ...@@ -99,8 +99,12 @@ Polymer({
const subKeys = key.split('.'); const subKeys = key.split('.');
subKeys.forEach(subKey => { subKeys.forEach(subKey => {
// Check for exceptions to CamelCase vs camelCase naming conventions. // Check for exceptions to CamelCase vs camelCase naming conventions.
if (subKey == 'apn') { if (subKey == 'ipv4' || subKey == 'ipv6') {
result += subKey + '-';
} else if (subKey == 'apn') {
result += 'APN-'; result += 'APN-';
} else if (subKey == 'ipAddress') {
result += 'IPAddress-';
} else { } else {
result += subKey.charAt(0).toUpperCase() + subKey.slice(1) + '-'; result += subKey.charAt(0).toUpperCase() + subKey.slice(1) + '-';
} }
......
...@@ -85,20 +85,6 @@ CrOnc.ProxyLocation; ...@@ -85,20 +85,6 @@ CrOnc.ProxyLocation;
/** @typedef {chrome.networkingPrivate.ProxySettings} */ /** @typedef {chrome.networkingPrivate.ProxySettings} */
CrOnc.ProxySettings; CrOnc.ProxySettings;
// Modified version of IPConfigProperties to store RoutingPrefix as a
// human-readable string instead of as a number.
/**
* @typedef {{
* Gateway: (string|undefined),
* IPAddress: (string|undefined),
* NameServers: (!Array<string>|undefined),
* RoutingPrefix: (string|undefined),
* Type: (string|undefined),
* WebProxyAutoDiscoveryUrl: (string|undefined)
* }}
*/
CrOnc.IPConfigUIProperties;
/** @typedef {chrome.networkingPrivate.PaymentPortal} */ /** @typedef {chrome.networkingPrivate.PaymentPortal} */
CrOnc.PaymentPortal; CrOnc.PaymentPortal;
...@@ -508,53 +494,6 @@ CrOnc.isSimLocked = function(properties) { ...@@ -508,53 +494,6 @@ CrOnc.isSimLocked = function(properties) {
simLockStatus.LockType == CrOnc.LockType.PUK; simLockStatus.LockType == CrOnc.LockType.PUK;
}; };
/**
* Modifies |config| to include the correct set of properties for configuring
* a network IP Address and NameServer configuration for |state|. Existing
* properties in |config| will be preserved unless invalid.
* @param {!chrome.networkingPrivate.NetworkConfigProperties} config A partial
* ONC configuration.
* @param {CrOnc.NetworkProperties|undefined} properties The ONC properties.
*/
CrOnc.setValidStaticIPConfig = function(config, properties) {
if (!config.IPAddressConfigType) {
const ipConfigType = /** @type {chrome.networkingPrivate.IPConfigType} */ (
CrOnc.getActiveValue(properties.IPAddressConfigType));
config.IPAddressConfigType = ipConfigType || CrOnc.IPConfigType.DHCP;
}
if (!config.NameServersConfigType) {
const nsConfigType = /** @type {chrome.networkingPrivate.IPConfigType} */ (
CrOnc.getActiveValue(properties.NameServersConfigType));
config.NameServersConfigType = nsConfigType || CrOnc.IPConfigType.DHCP;
}
if (config.IPAddressConfigType != CrOnc.IPConfigType.STATIC &&
config.NameServersConfigType != CrOnc.IPConfigType.STATIC) {
if (config.hasOwnProperty('StaticIPConfig')) {
delete config.StaticIPConfig;
}
return;
}
if (!config.hasOwnProperty('StaticIPConfig')) {
config.StaticIPConfig =
/** @type {chrome.networkingPrivate.IPConfigProperties} */ ({});
}
const staticIP = config.StaticIPConfig;
const stateIPConfig = CrOnc.getIPConfigForType(properties, CrOnc.IPType.IPV4);
if (config.IPAddressConfigType == 'Static') {
staticIP.Gateway = staticIP.Gateway || stateIPConfig.Gateway || '';
staticIP.IPAddress = staticIP.IPAddress || stateIPConfig.IPAddress || '';
staticIP.RoutingPrefix =
staticIP.RoutingPrefix || stateIPConfig.RoutingPrefix || 0;
staticIP.Type = staticIP.Type || stateIPConfig.Type || CrOnc.IPType.IPV4;
}
if (config.NameServersConfigType == 'Static') {
staticIP.NameServers =
staticIP.NameServers || stateIPConfig.NameServers || [];
}
};
/** /**
* Sets the value of a property in an ONC dictionary. * Sets the value of a property in an ONC dictionary.
* @param {!chrome.networkingPrivate.NetworkConfigProperties} properties * @param {!chrome.networkingPrivate.NetworkConfigProperties} properties
......
...@@ -216,19 +216,4 @@ const CrPolicyNetworkBehavior = { ...@@ -216,19 +216,4 @@ const CrPolicyNetworkBehavior = {
return this.isNetworkPolicyEnforced( return this.isNetworkPolicyEnforced(
this.getManagedSettingAtPath_(networkProperties, path)); this.getManagedSettingAtPath_(networkProperties, path));
}, },
/**
* Get policy indicator type for the setting at |path|.
* @param {CrOnc.NetworkProperties} networkProperties
* @param {string} path
* @return {CrPolicyIndicatorType}
*/
getPolicyIndicatorType_: function(networkProperties, path) {
if (!this.isNetworkPolicyPathManaged(networkProperties, path)) {
return CrPolicyIndicatorType.NONE;
}
return networkProperties.Source == CrOnc.Source.DEVICE_POLICY ?
CrPolicyIndicatorType.DEVICE_POLICY :
CrPolicyIndicatorType.USER_POLICY;
},
}; };
...@@ -699,7 +699,7 @@ class OncMojo { ...@@ -699,7 +699,7 @@ class OncMojo {
let ipConfig; let ipConfig;
if (ipConfigs) { if (ipConfigs) {
ipConfig = ipConfigs.find(ipconfig => ipconfig.type == desiredType); ipConfig = ipConfigs.find(ipconfig => ipconfig.type == desiredType);
if (ipConfig && desiredType != CrOnc.IPType.IPV4) { if (ipConfig && desiredType != 'IPv4') {
return ipConfig; return ipConfig;
} }
} }
...@@ -738,6 +738,119 @@ class OncMojo { ...@@ -738,6 +738,119 @@ class OncMojo {
return ipConfig; return ipConfig;
} }
/**
* Compares the IP config properties of a new unmanaged dictionary to the
* corresponding IP properties in an existing managed dictionary. Returns true
* if all properties specified in the new dictionary match the values in the
* existing dictionary.
* @param {!chromeos.networkConfig.mojom.ManagedIPConfigProperties}
* staticValue
* @param {!chromeos.networkConfig.mojom.IPConfigProperties} newValue
* @return {boolean} True if all properties set in |newValue| are equal to
* the corresponding properties in |staticValue|.
*/
static ipConfigPropertiesMatch(staticValue, newValue) {
// If the existing type is unset, or the types do not match, return false.
if (!staticValue.type || staticValue.type.activeValue != newValue.type) {
return false;
}
if (newValue.gateway !== undefined &&
(!staticValue.gateway ||
staticValue.gateway.activeValue != newValue.gateway)) {
return false;
}
if (newValue.ipAddress !== undefined &&
(!staticValue.ipAddress ||
staticValue.ipAddress.activeValue != newValue.ipAddress)) {
return false;
}
if (!staticValue.routingPrefix ||
staticValue.routingPrefix.activeValue != newValue.routingPrefix) {
return false;
}
return true;
}
/**
* Extracts existing ip config properties from |managedProperties| and applies
* |newValue| to |field|. Returns a mojom.ConfigProperties object with the
* IP Config related properties set, or null if no changes were applied.
* @param {!chromeos.networkConfig.mojom.ManagedProperties} managedProperties
* @param {string} field
* @param {string|!Array<string>|
* !chromeos.networkConfig.mojom.IPConfigProperties} newValue
* @return {?chromeos.networkConfig.mojom.ConfigProperties}
*/
static getUpdatedIPConfigProperties(managedProperties, field, newValue) {
const mojom = chromeos.networkConfig.mojom;
// Get an empty ONC dictionary and set just the IP Config properties that
// need to change.
let ipConfigType =
OncMojo.getActiveString(managedProperties.ipAddressConfigType) ||
'DHCP';
let nsConfigType =
OncMojo.getActiveString(managedProperties.nameServersConfigType) ||
'DHCP';
let staticIpConfig = OncMojo.getIPConfigForType(managedProperties, 'IPv4');
let nameServers = staticIpConfig ? staticIpConfig.nameServers : undefined;
if (field == 'ipAddressConfigType') {
const newIpConfigType = /** @type {string} */ (newValue);
if (newIpConfigType == ipConfigType) {
return null;
}
ipConfigType = newIpConfigType;
} else if (field == 'nameServersConfigType') {
const newNsConfigType = /** @type {string} */ (newValue);
if (newNsConfigType == nsConfigType) {
return null;
}
nsConfigType = newNsConfigType;
} else if (field == 'staticIpConfig') {
const ipConfigValue =
/** @type {!mojom.IPConfigProperties} */ (newValue);
if (!ipConfigValue.type || !ipConfigValue.ipAddress) {
console.error('Invalid StaticIPConfig: ' + JSON.stringify(newValue));
return null;
}
if (ipConfigType == 'Static' && staticIpConfig &&
OncMojo.ipConfigPropertiesMatch(staticIpConfig, ipConfigValue)) {
return null;
}
ipConfigType = 'Static';
staticIpConfig = ipConfigValue;
} else if (field == 'nameServers') {
const newNameServers = /** @type {!Array<string>} */ (newValue);
if (!newNameServers || !newNameServers.length) {
console.error('Invalid NameServers: ' + JSON.stringify(newValue));
}
if (nsConfigType == 'Static' &&
JSON.stringify(nameServers) == JSON.stringify(newNameServers)) {
return null;
}
nsConfigType = 'Static';
nameServers = newNameServers;
} else {
console.error('Unexpected field: ' + field);
return null;
}
// Set ONC IP config properties to existing values + new values.
const config = {};
config.ipAddressConfigType = ipConfigType;
config.nameServersConfigType = nsConfigType;
if (ipConfigType == 'Static') {
assert(staticIpConfig && staticIpConfig.type && staticIpConfig.ipAddress);
config.staticIpConfig = staticIpConfig;
}
if (nsConfigType == 'Static') {
assert(nameServers && nameServers.length);
config.staticIpConfig = config.staticIpConfig ||
/** @type{!mojom.IPConfigProperties}*/ ({routingPrefix: 0});
config.staticIpConfig.nameServers = nameServers;
}
return config;
}
/** /**
* @param {!chromeos.networkConfig.mojom.ManagedProperties} properties * @param {!chromeos.networkConfig.mojom.ManagedProperties} properties
* @return {chromeos.networkConfig.mojom.ManagedBoolean|undefined} * @return {chromeos.networkConfig.mojom.ManagedBoolean|undefined}
...@@ -832,3 +945,17 @@ OncMojo.ManagedProperty; ...@@ -832,3 +945,17 @@ OncMojo.ManagedProperty;
/** @typedef {chromeos.networkConfig.mojom.ManagedProperties} */ /** @typedef {chromeos.networkConfig.mojom.ManagedProperties} */
OncMojo.ManagedProperties; OncMojo.ManagedProperties;
/**
* Modified version of mojom.IPConfigProperties to store routingPrefix as a
* human-readable string instead of as a number. Used in network_ip_config.js.
* @typedef {{
* gateway: (string|undefined),
* ipAddress: (string|undefined),
* nameServers: (!Array<string>|undefined),
* routingPrefix: (string|undefined),
* type: (string|undefined),
* webProxyAutoDiscoveryUrl: (string|undefined),
* }}
*/
OncMojo.IPConfigUIProperties;
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