[sql] Remove _HAS_EXCEPTIONS=0 from build info.
[chromium-blink-merge.git] / chrome / browser / resources / settings / internet_page / network_ip_config.js
blobd9ca0bbb44880da179b8e1dbf9af8e91fd8efe1b
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 /**
6 * @fileoverview Polymer element for displaying the IP Config properties for
7 * a network state. TODO(stevenjb): Allow editing of static IP configurations
8 * when 'editable' is true.
9 */
10 Polymer({
11 is: 'network-ip-config',
13 properties: {
14 /**
15 * The current state containing the IP Config properties to display and
16 * modify.
17 * @type {?CrOnc.NetworkStateProperties}
19 networkState: {
20 type: Object,
21 value: null,
22 observer: 'networkStateChanged_'
25 /**
26 * Whether or not the IP Address can be edited.
27 * TODO(stevenjb): Implement editing.
29 editable: {
30 type: Boolean,
31 value: false
34 /**
35 * State of 'Configure IP Addresses Automatically'.
37 automatic: {
38 type: Boolean,
39 value: false,
40 observer: 'automaticChanged_'
43 /**
44 * The currently visible IP Config property dictionary. The 'RoutingPrefix'
45 * property is a human-readable mask instead of a prefix length.
46 * @type {{
47 * ipv4: !CrOnc.IPConfigUIProperties,
48 * ipv6: !CrOnc.IPConfigUIProperties
49 * }}
51 ipConfig: {
52 type: Object,
53 value: function() { return {ipv4: {}, ipv6: {}}; }
56 /**
57 * Array of properties to pass to the property list.
58 * @type {!Array<string>}
60 ipConfigFields_: {
61 type: Array,
62 value: function() {
63 return [
64 'ipv4.IPAddress',
65 'ipv4.RoutingPrefix',
66 'ipv4.Gateway',
67 'ipv6.IPAddress'
70 readOnly: true
74 /**
75 * Saved static IP configuration properties when switching to 'automatic'.
76 * @type {?CrOnc.IPConfigUIProperties}
78 savedStaticIp_: null,
80 /**
81 * Polymer networkState changed method.
83 networkStateChanged_: function(newValue, oldValue) {
84 if (this.networkState === undefined || this.ipConfig === undefined)
85 return;
87 if (newValue.GUID != (oldValue && oldValue.GUID))
88 this.savedStaticIp_ = null;
90 // Update the 'automatic' property.
91 var ipConfigType =
92 CrOnc.getActiveValue(this.networkState, 'IPAddressConfigType');
93 this.automatic = (ipConfigType != CrOnc.IPConfigType.STATIC);
95 // Update the 'ipConfig' property.
96 var ipv4 = CrOnc.getIPConfigForType(this.networkState, CrOnc.IPType.IPV4);
97 var ipv6 = CrOnc.getIPConfigForType(this.networkState, CrOnc.IPType.IPV6);
98 this.ipConfig = {
99 ipv4: this.getIPConfigUIProperties_(ipv4),
100 ipv6: this.getIPConfigUIProperties_(ipv6)
105 * Polymer automatic changed method.
107 automaticChanged_: function() {
108 if (this.automatic === undefined || this.ipConfig === undefined)
109 return;
110 if (this.automatic || !this.savedStaticIp_) {
111 // Save the static IP configuration when switching to automatic.
112 this.savedStaticIp_ = this.ipConfig.ipv4;
113 var configType =
114 this.automatic ? CrOnc.IPConfigType.DHCP : CrOnc.IPConfigType.STATIC;
115 this.fire('ip-change', {
116 field: 'IPAddressConfigType',
117 value: configType
119 } else {
120 // Restore the saved static IP configuration.
121 var ipconfig = {
122 Gateway: this.savedStaticIp_.Gateway,
123 IPAddress: this.savedStaticIp_.IPAddress,
124 RoutingPrefix: this.savedStaticIp_.RoutingPrefix,
125 Type: this.savedStaticIp_.Type
127 this.fire('ip-change', {
128 field: 'StaticIPConfig',
129 value: this.getIPConfigProperties_(ipconfig)
135 * @param {?CrOnc.IPConfigProperties} ipconfig The IP Config properties.
136 * @return {!CrOnc.IPConfigUIProperties} A new IPConfigUIProperties object
137 * with RoutingPrefix expressed as a string mask instead of a prefix
138 * length. Returns an empty object if |ipconfig| is undefined.
139 * @private
141 getIPConfigUIProperties_: function(ipconfig) {
142 var result = {};
143 if (!ipconfig)
144 return result;
145 for (var key in ipconfig) {
146 var value = ipconfig[key];
147 if (key == 'RoutingPrefix')
148 result.RoutingPrefix = CrOnc.getRoutingPrefixAsNetmask(value);
149 else
150 result[key] = value;
152 return result;
156 * @param {!CrOnc.IPConfigUIProperties} ipconfig The IP Config UI properties.
157 * @return {!CrOnc.IPConfigProperties} A new IPConfigProperties object with
158 * RoutingPrefix expressed as a a prefix length.
159 * @private
161 getIPConfigProperties_: function(ipconfig) {
162 var result = {};
163 for (var key in ipconfig) {
164 var value = ipconfig[key];
165 if (key == 'RoutingPrefix')
166 result.RoutingPrefix = CrOnc.getRoutingPrefixAsLength(value);
167 else
168 result[key] = value;
170 return result;
174 * @param {!CrOnc.IPConfigUIProperties} ipConfig The IP Config properties.
175 * @param {boolean} editable The editable property.
176 * @param {boolean} automatic The automatic property.
177 * @return {Object} An object with the edit type for each editable field.
178 * @private
180 getIPEditFields_: function(ipConfig, editable, automatic) {
181 if (!editable || automatic)
182 return {};
183 return {
184 'ipv4.IPAddress': 'String',
185 'ipv4.RoutingPrefix': 'String',
186 'ipv4.Gateway': 'String'
191 * Event triggered when the network property list changes.
192 * @param {!{detail: { field: string, value: string}}} event The
193 * network-property-list change event.
194 * @private
196 onIPChange_: function(event) {
197 var field = event.detail.field;
198 var value = event.detail.value;
199 // Note: |field| includes the 'ipv4.' prefix.
200 this.set('ipConfig.' + field, value);
201 this.fire('ip-change', {
202 field: 'StaticIPConfig',
203 value: this.getIPConfigProperties_(this.ipConfig.ipv4)