OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // NOTE(stevenjb): This code is in the process of being converted to be | 5 // NOTE(stevenjb): This code is in the process of being converted to be |
6 // compatible with the networkingPrivate extension API: | 6 // compatible with the networkingPrivate extension API: |
7 // * The network property dictionaries are being converted to use ONC values. | 7 // * The network property dictionaries are being converted to use ONC values. |
8 // * chrome.send calls will be replaced with an API object that simulates the | 8 // * chrome.send calls will be replaced with an API object that simulates the |
9 // networkingPrivate API. See network_config.js. | 9 // networkingPrivate API. See network_config.js. |
10 // See crbug.com/279351 for more info. | 10 // See crbug.com/279351 for more info. |
11 | 11 |
12 cr.define('options.internet', function() { | 12 cr.define('options.internet', function() { |
13 var Page = cr.ui.pageManager.Page; | 13 var Page = cr.ui.pageManager.Page; |
14 var PageManager = cr.ui.pageManager.PageManager; | 14 var PageManager = cr.ui.pageManager.PageManager; |
15 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; | 15 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; |
16 /** @const */ var IPAddressField = options.internet.IPAddressField; | 16 /** @const */ var IPAddressField = options.internet.IPAddressField; |
17 | 17 |
18 /** | 18 /** |
19 * Helper function to get the "Active" value of a property from a dictionary | 19 * Gets the value of a property from a dictionary |data| that includes ONC |
20 * that includes ONC managed properties, e.g. getActiveValue(data, 'Name'). | 20 * managed properties, e.g. getManagedValue(data, 'Name'). See notes for |
21 * We use (data, key) instead of getActiveValue(data[key]) so that we can | 21 * getManagedProperty. |
22 * (possibly) add ONC key validation once all properties use ONC. | |
23 * @param {object} data The properties dictionary. | 22 * @param {object} data The properties dictionary. |
24 * @param {string} key The property key. | 23 * @param {string} key The property key. |
24 * @param {string} type (Optional) The type of property to get: | |
25 * 'active' (default) - gets the active value | |
26 * 'translated' - gets the traslated or active value | |
27 * 'recommended' - gets the recommended or active value | |
pneubeck (no reviews)
2014/08/19 16:24:02
why should recommended fallback to the active valu
stevenjb
2014/08/19 18:41:47
That is actually what it does, just the comment is
| |
25 * @return {*} the property value or undefined. | 28 * @return {*} the property value or undefined. |
26 */ | 29 */ |
27 function getActiveValue(data, key) { | 30 function getManagedValue(data, key, type) { |
28 if (!(key in data)) | 31 var property = getManagedProperty(data, key); |
32 if (!property) | |
pneubeck (no reviews)
2014/08/19 16:24:02
be careful about the implicit conversion into bool
stevenjb
2014/08/19 18:41:47
Actually, this check isn't necessary since typeof
| |
29 return undefined; | 33 return undefined; |
30 var property = data[key]; | |
31 if (typeof property != 'object') | 34 if (typeof property != 'object') |
32 return property; | 35 return property; |
36 if (type == 'recommended') | |
37 return getEffectiveValue(property); | |
pneubeck (no reviews)
2014/08/19 16:24:02
this doesn't look like it would return the recomme
stevenjb
2014/08/19 18:41:47
Bah, ugh, right, fixed.
| |
38 if (type == 'translate' && 'Translated' in property) | |
39 return property['Translated']; | |
33 if ('Active' in property) | 40 if ('Active' in property) |
pneubeck (no reviews)
2014/08/19 16:24:02
nit: add a comment before this line saying "Otherw
stevenjb
2014/08/19 18:41:47
Done.
| |
34 return property['Active']; | 41 return property['Active']; |
42 // If no Active value is defined, return the effective (recommended) value. | |
43 return getEffectiveValue(property); | |
44 } | |
45 | |
46 /** | |
47 * Get the effective value from a Managed property ONC dictionary. | |
48 * @param {object} property The managed property ONC dictionary. | |
49 * @return {*} the effective value or undefined. | |
50 */ | |
51 function getEffectiveValue(property) { | |
35 if ('Effective' in property) { | 52 if ('Effective' in property) { |
36 var effective = property.Effective; | 53 var effective = property.Effective; |
37 if (effective in property) | 54 if (effective in property) |
38 return property[effective]; | 55 return property[effective]; |
39 } | 56 } |
40 return undefined; | 57 return undefined; |
41 } | 58 } |
42 | 59 |
43 /** | 60 /** |
44 * Helper function for nested ONC properties, e.g. data[WiFi][Strength]. | 61 * Gets either a managed property dictionary or an unmanaged value from |
45 * @param {object|string} property The property which must ether be | 62 * dictionary |data| that includes ONC managed properties. This supports |
46 * a dictionary object or not be present. | 63 * nested dictionaries, e.g. getManagedProperty(data, 'VPN.Type'). |
64 * @param {object} data The properties dictionary. | |
65 * @param {string} key The property key. | |
47 * @return {*} the property value or undefined. | 66 * @return {*} the property value or undefined. |
pneubeck (no reviews)
2014/08/19 16:24:02
'property value or dictionary if it exists. Otherw
stevenjb
2014/08/19 18:41:47
Done.
| |
48 */ | 67 */ |
49 function getActiveDictionaryValue(data, dict, key) { | 68 function getManagedProperty(data, key) { |
50 if (!(dict in data)) | 69 var index = key.indexOf('.'); |
51 return undefined; | 70 while (index >= 0) { |
52 return getActiveValue(data[dict], key); | 71 var dictKey = key.substr(0, index); |
pneubeck (no reviews)
2014/08/19 16:24:02
optional nit:
dictKey -> keyComponent?
stevenjb
2014/08/19 18:41:47
Sure.
| |
72 data = data[dictKey]; | |
73 if (!data) | |
pneubeck (no reviews)
2014/08/19 16:24:02
again, be careful about implicit conversion into b
stevenjb
2014/08/19 18:41:47
Fixed.
| |
74 return undefined; | |
75 key = key.substr(index + 1); | |
76 index = key.indexOf('.'); | |
pneubeck (no reviews)
2014/08/19 16:24:02
optional nit: could be merged with line 69 by
wh
stevenjb
2014/08/19 18:41:47
Yeah, I'm not a big fan of that pattern, but dupli
| |
77 } | |
78 return data[key]; | |
53 } | 79 } |
54 | 80 |
55 /** | 81 /** |
56 * Helper function to set hidden attribute for elements matching a selector. | 82 * Helper function to set hidden attribute for elements matching a selector. |
57 * @param {string} selector CSS selector for extracting a list of elements. | 83 * @param {string} selector CSS selector for extracting a list of elements. |
58 * @param {bool} hidden New hidden value. | 84 * @param {bool} hidden New hidden value. |
59 */ | 85 */ |
60 function updateHidden(selector, hidden) { | 86 function updateHidden(selector, hidden) { |
61 var elements = cr.doc.querySelectorAll(selector); | 87 var elements = cr.doc.querySelectorAll(selector); |
62 for (var i = 0, el; el = elements[i]; i++) { | 88 for (var i = 0, el; el = elements[i]; i++) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 return loadTimeData.getString('OncStateUnknown'); | 154 return loadTimeData.getString('OncStateUnknown'); |
129 } | 155 } |
130 | 156 |
131 /** | 157 /** |
132 * Returns the display name for the network represented by 'data'. | 158 * Returns the display name for the network represented by 'data'. |
133 * @param {Object} data The network ONC dictionary. | 159 * @param {Object} data The network ONC dictionary. |
134 */ | 160 */ |
135 function getNetworkName(data) { | 161 function getNetworkName(data) { |
136 if (data.type == 'Ethernet') | 162 if (data.type == 'Ethernet') |
137 return loadTimeData.getString('ethernetName'); | 163 return loadTimeData.getString('ethernetName'); |
138 return getActiveValue(data, 'Name'); | 164 return getManagedValue(data, 'Name'); |
139 } | 165 } |
140 | 166 |
141 ///////////////////////////////////////////////////////////////////////////// | 167 ///////////////////////////////////////////////////////////////////////////// |
142 // DetailsInternetPage class: | 168 // DetailsInternetPage class: |
143 | 169 |
144 /** | 170 /** |
145 * Encapsulated handling of ChromeOS internet details overlay page. | 171 * Encapsulated handling of ChromeOS internet details overlay page. |
146 * @constructor | 172 * @constructor |
147 */ | 173 */ |
148 function DetailsInternetPage() { | 174 function DetailsInternetPage() { |
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
901 DetailsInternetPage.updateConnectionButtonVisibilty = function(data) { | 927 DetailsInternetPage.updateConnectionButtonVisibilty = function(data) { |
902 if (data.type == 'Ethernet') { | 928 if (data.type == 'Ethernet') { |
903 // Ethernet can never be connected or disconnected and can always be | 929 // Ethernet can never be connected or disconnected and can always be |
904 // configured (e.g. to set security). | 930 // configured (e.g. to set security). |
905 $('details-internet-login').hidden = true; | 931 $('details-internet-login').hidden = true; |
906 $('details-internet-disconnect').hidden = true; | 932 $('details-internet-disconnect').hidden = true; |
907 $('details-internet-configure').hidden = false; | 933 $('details-internet-configure').hidden = false; |
908 return; | 934 return; |
909 } | 935 } |
910 | 936 |
911 var connectState = getActiveValue(data, 'ConnectionState'); | 937 var connectState = getManagedValue(data, 'ConnectionState'); |
912 if (connectState == 'NotConnected') { | 938 if (connectState == 'NotConnected') { |
913 $('details-internet-login').hidden = false; | 939 $('details-internet-login').hidden = false; |
914 // Connecting to an unconfigured network might trigger certificate | 940 // Connecting to an unconfigured network might trigger certificate |
915 // installation UI. Until that gets handled here, always enable the | 941 // installation UI. Until that gets handled here, always enable the |
916 // Connect button. | 942 // Connect button. |
917 $('details-internet-login').disabled = false; | 943 $('details-internet-login').disabled = false; |
918 $('details-internet-disconnect').hidden = true; | 944 $('details-internet-disconnect').hidden = true; |
919 } else { | 945 } else { |
920 $('details-internet-login').hidden = true; | 946 $('details-internet-login').hidden = true; |
921 $('details-internet-disconnect').hidden = false; | 947 $('details-internet-disconnect').hidden = false; |
922 } | 948 } |
923 | 949 |
924 var connectable = getActiveValue(data, 'Connectable'); | 950 var connectable = getManagedValue(data, 'Connectable'); |
925 if (connectState != 'Connected' && | 951 if (connectState != 'Connected' && |
926 (!connectable || this.hasSecurity || | 952 (!connectable || this.hasSecurity || |
927 (data.type == 'Wimax' || data.type == 'VPN'))) { | 953 (data.type == 'Wimax' || data.type == 'VPN'))) { |
928 $('details-internet-configure').hidden = false; | 954 $('details-internet-configure').hidden = false; |
929 } else { | 955 } else { |
930 $('details-internet-configure').hidden = true; | 956 $('details-internet-configure').hidden = true; |
931 } | 957 } |
932 }; | 958 }; |
933 | 959 |
934 DetailsInternetPage.updateConnectionData = function(update) { | 960 DetailsInternetPage.updateConnectionData = function(update) { |
935 var detailsPage = DetailsInternetPage.getInstance(); | 961 var detailsPage = DetailsInternetPage.getInstance(); |
936 if (!detailsPage.visible) | 962 if (!detailsPage.visible) |
937 return; | 963 return; |
938 | 964 |
939 var data = $('connection-state').data; | 965 var data = $('connection-state').data; |
940 if (!data) | 966 if (!data) |
941 return; | 967 return; |
942 | 968 |
943 if (update.servicePath != data.servicePath) | 969 if (update.servicePath != data.servicePath) |
944 return; | 970 return; |
945 | 971 |
946 // Update our cached data object. | 972 // Update our cached data object. |
947 updateDataObject(data, update); | 973 updateDataObject(data, update); |
948 | 974 |
949 var connectionState = getActiveValue(data, 'ConnectionState'); | 975 var connectionState = getManagedValue(data, 'ConnectionState'); |
950 var connectionStateString = networkOncStateString(connectionState); | 976 var connectionStateString = networkOncStateString(connectionState); |
951 detailsPage.deviceConnected = data.deviceConnected; | 977 detailsPage.deviceConnected = data.deviceConnected; |
952 detailsPage.connected = connectionState == 'Connected'; | 978 detailsPage.connected = connectionState == 'Connected'; |
953 $('connection-state').textContent = connectionStateString; | 979 $('connection-state').textContent = connectionStateString; |
954 | 980 |
955 this.updateConnectionButtonVisibilty(data); | 981 this.updateConnectionButtonVisibilty(data); |
956 | 982 |
957 if (data.type == 'WiFi') { | 983 if (data.type == 'WiFi') { |
958 $('wifi-connection-state').textContent = connectionStateString; | 984 $('wifi-connection-state').textContent = connectionStateString; |
959 } else if (data.type == 'Wimax') { | 985 } else if (data.type == 'Wimax') { |
(...skipping 15 matching lines...) Expand all Loading... | |
975 $('change-pin').hidden = !lockEnabled; | 1001 $('change-pin').hidden = !lockEnabled; |
976 } | 1002 } |
977 } | 1003 } |
978 | 1004 |
979 $('connection-state').data = data; | 1005 $('connection-state').data = data; |
980 }; | 1006 }; |
981 | 1007 |
982 DetailsInternetPage.showDetailedInfo = function(data) { | 1008 DetailsInternetPage.showDetailedInfo = function(data) { |
983 var detailsPage = DetailsInternetPage.getInstance(); | 1009 var detailsPage = DetailsInternetPage.getInstance(); |
984 | 1010 |
985 data.type = getActiveValue(data, 'Type'); // Get Active Type value. | 1011 data.type = getManagedValue(data, 'Type'); // Get Active Type value. |
986 | 1012 |
987 // Populate header | 1013 // Populate header |
988 $('network-details-title').textContent = getNetworkName(data); | 1014 $('network-details-title').textContent = getNetworkName(data); |
989 var connectionState = getActiveValue(data, 'ConnectionState'); | 1015 var connectionState = getManagedValue(data, 'ConnectionState'); |
990 var connectionStateString = networkOncStateString(connectionState); | 1016 var connectionStateString = networkOncStateString(connectionState); |
991 detailsPage.connected = connectionState == 'Connected'; | 1017 detailsPage.connected = connectionState == 'Connected'; |
992 $('network-details-subtitle-status').textContent = connectionStateString; | 1018 $('network-details-subtitle-status').textContent = connectionStateString; |
993 var typeKey = null; | 1019 var typeKey = null; |
994 switch (data.type) { | 1020 switch (data.type) { |
995 case 'Ethernet': | 1021 case 'Ethernet': |
996 typeKey = 'ethernetTitle'; | 1022 typeKey = 'ethernetTitle'; |
997 break; | 1023 break; |
998 case 'WiFi': | 1024 case 'WiFi': |
999 typeKey = 'wifiTitle'; | 1025 typeKey = 'wifiTitle'; |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1123 nameServerModels.push({value: nameServersUser[i] || ''}); | 1149 nameServerModels.push({value: nameServersUser[i] || ''}); |
1124 | 1150 |
1125 $(data.nameServerType + '-dns-radio').checked = true; | 1151 $(data.nameServerType + '-dns-radio').checked = true; |
1126 configureAddressField($('ipconfig-dns1'), nameServerModels[0]); | 1152 configureAddressField($('ipconfig-dns1'), nameServerModels[0]); |
1127 configureAddressField($('ipconfig-dns2'), nameServerModels[1]); | 1153 configureAddressField($('ipconfig-dns2'), nameServerModels[1]); |
1128 configureAddressField($('ipconfig-dns3'), nameServerModels[2]); | 1154 configureAddressField($('ipconfig-dns3'), nameServerModels[2]); |
1129 configureAddressField($('ipconfig-dns4'), nameServerModels[3]); | 1155 configureAddressField($('ipconfig-dns4'), nameServerModels[3]); |
1130 | 1156 |
1131 DetailsInternetPage.updateNameServerDisplay(data.nameServerType); | 1157 DetailsInternetPage.updateNameServerDisplay(data.nameServerType); |
1132 | 1158 |
1133 var macAddress = getActiveValue(data, 'MacAddress'); | 1159 var macAddress = getManagedValue(data, 'MacAddress'); |
1134 if (macAddress) { | 1160 if (macAddress) { |
1135 $('hardware-address').textContent = macAddress; | 1161 $('hardware-address').textContent = macAddress; |
1136 $('hardware-address-row').style.display = 'table-row'; | 1162 $('hardware-address-row').style.display = 'table-row'; |
1137 } else { | 1163 } else { |
1138 // This is most likely a device without a hardware address. | 1164 // This is most likely a device without a hardware address. |
1139 $('hardware-address-row').style.display = 'none'; | 1165 $('hardware-address-row').style.display = 'none'; |
1140 } | 1166 } |
1141 | 1167 |
1142 var setOrHideParent = function(field, property) { | 1168 var setOrHideParent = function(field, property) { |
1143 if (property) { | 1169 if (property) { |
1144 $(field).textContent = property; | 1170 $(field).textContent = property; |
1145 $(field).parentElement.hidden = false; | 1171 $(field).parentElement.hidden = false; |
1146 } else { | 1172 } else { |
1147 $(field).parentElement.hidden = true; | 1173 $(field).parentElement.hidden = true; |
1148 } | 1174 } |
1149 }; | 1175 }; |
1150 | 1176 |
1151 var networkName = getNetworkName(data); | 1177 var networkName = getNetworkName(data); |
1152 | 1178 |
1153 // Signal strength as percentage (for WiFi and Wimax). | 1179 // Signal strength as percentage (for WiFi and Wimax). |
1154 var signalStrength; | 1180 var signalStrength; |
1155 if (data.type == 'WiFi' || data.type == 'Wimax') { | 1181 if (data.type == 'WiFi' || data.type == 'Wimax') { |
1156 signalStrength = | 1182 signalStrength = getManagedValue(data, data.type + '.SignalStrength'); |
1157 getActiveDictionaryValue(data, data.type, 'SignalStrength'); | |
1158 } | 1183 } |
1159 if (!signalStrength) | 1184 if (!signalStrength) |
1160 signalStrength = 0; | 1185 signalStrength = 0; |
1161 var strengthFormat = loadTimeData.getString('inetSignalStrengthFormat'); | 1186 var strengthFormat = loadTimeData.getString('inetSignalStrengthFormat'); |
1162 var strengthString = strengthFormat.replace('$1', signalStrength); | 1187 var strengthString = strengthFormat.replace('$1', signalStrength); |
1163 | 1188 |
1164 detailsPage.type = data.type; | 1189 detailsPage.type = data.type; |
1165 if (data.type == 'WiFi') { | 1190 if (data.type == 'WiFi') { |
1166 assert(data.WiFi, 'WiFi network has no WiFi object' + networkName); | 1191 assert('WiFi' in data, 'WiFi network has no WiFi object' + networkName); |
pneubeck (no reviews)
2014/08/19 16:24:02
good catch!
stevenjb
2014/08/19 18:41:47
Acknowledged.
| |
1167 OptionsPage.showTab($('wifi-network-nav-tab')); | 1192 OptionsPage.showTab($('wifi-network-nav-tab')); |
1168 detailsPage.gsm = false; | 1193 detailsPage.gsm = false; |
1169 detailsPage.shared = data.shared; | 1194 detailsPage.shared = data.shared; |
1170 $('wifi-connection-state').textContent = connectionStateString; | 1195 $('wifi-connection-state').textContent = connectionStateString; |
1171 var ssid = getActiveDictionaryValue(data, 'WiFi', 'SSID'); | 1196 var ssid = getManagedValue(data, 'WiFi.SSID'); |
1172 $('wifi-ssid').textContent = ssid ? ssid : networkName; | 1197 $('wifi-ssid').textContent = ssid ? ssid : networkName; |
1173 setOrHideParent('wifi-bssid', | 1198 setOrHideParent('wifi-bssid', getManagedValue(data, 'WiFi.BSSID')); |
1174 getActiveDictionaryValue(data, 'WiFi', 'BSSID')); | 1199 var security = getManagedValue(data, 'WiFi.Security'); |
1175 var security = getActiveDictionaryValue(data, 'WiFi', 'Security'); | |
1176 if (security == 'None') | 1200 if (security == 'None') |
1177 security = undefined; | 1201 security = undefined; |
1178 setOrHideParent('wifi-security', security); | 1202 setOrHideParent('wifi-security', security); |
1179 // Frequency is in MHz. | 1203 // Frequency is in MHz. |
1180 var frequency = getActiveDictionaryValue(data, 'WiFi', 'Frequency'); | 1204 var frequency = getManagedValue(data, 'WiFi.Frequency'); |
1181 if (!frequency) | 1205 if (!frequency) |
1182 frequency = 0; | 1206 frequency = 0; |
1183 var frequencyFormat = loadTimeData.getString('inetFrequencyFormat'); | 1207 var frequencyFormat = loadTimeData.getString('inetFrequencyFormat'); |
1184 frequencyFormat = frequencyFormat.replace('$1', frequency); | 1208 frequencyFormat = frequencyFormat.replace('$1', frequency); |
1185 $('wifi-frequency').textContent = frequencyFormat; | 1209 $('wifi-frequency').textContent = frequencyFormat; |
1186 $('wifi-signal-strength').textContent = strengthString; | 1210 $('wifi-signal-strength').textContent = strengthString; |
1187 setOrHideParent('wifi-hardware-address', | 1211 setOrHideParent('wifi-hardware-address', |
1188 getActiveValue(data, 'MacAddress')); | 1212 getManagedValue(data, 'MacAddress')); |
1189 detailsPage.showPreferred = data.remembered; | 1213 detailsPage.showPreferred = data.remembered; |
1190 $('prefer-network-wifi').checked = data.preferred.value; | 1214 var priority = getManagedValue(data, 'Priority'); |
1215 $('prefer-network-wifi').checked = priority > 0; | |
1191 $('prefer-network-wifi').disabled = !data.remembered; | 1216 $('prefer-network-wifi').disabled = !data.remembered; |
1192 $('auto-connect-network-wifi').checked = | 1217 $('auto-connect-network-wifi').checked = |
1193 getActiveValue(data, 'AutoConnect'); | 1218 getManagedValue(data, 'AutoConnect'); |
1194 $('auto-connect-network-wifi').disabled = !data.remembered; | 1219 $('auto-connect-network-wifi').disabled = !data.remembered; |
1195 detailsPage.hasSecurity = security != undefined; | 1220 detailsPage.hasSecurity = security != undefined; |
1196 } else if (data.type == 'Wimax') { | 1221 } else if (data.type == 'Wimax') { |
1197 assert(data.Wimax, 'Wimax network has no Wimax object' + networkName); | 1222 assert('Wimax' in data, |
1223 'Wimax network has no Wimax object' + networkName); | |
1198 OptionsPage.showTab($('wimax-network-nav-tab')); | 1224 OptionsPage.showTab($('wimax-network-nav-tab')); |
1199 detailsPage.gsm = false; | 1225 detailsPage.gsm = false; |
1200 detailsPage.shared = data.shared; | 1226 detailsPage.shared = data.shared; |
1201 detailsPage.showPreferred = data.remembered; | 1227 detailsPage.showPreferred = data.remembered; |
1202 $('wimax-connection-state').textContent = connectionStateString; | 1228 $('wimax-connection-state').textContent = connectionStateString; |
1203 $('auto-connect-network-wimax').checked = | 1229 $('auto-connect-network-wimax').checked = |
1204 getActiveValue(data, 'AutoConnect'); | 1230 getManagedValue(data, 'AutoConnect'); |
1205 $('auto-connect-network-wimax').disabled = !data.remembered; | 1231 $('auto-connect-network-wimax').disabled = !data.remembered; |
1206 var identity; | 1232 var identity; |
1207 if (data.Wimax.EAP) | 1233 if (data.Wimax.EAP) |
1208 identity = getActiveValue(data.Wimax.EAP, 'Identity'); | 1234 identity = getManagedValue(data.Wimax.EAP, 'Identity'); |
1209 setOrHideParent('wimax-eap-identity', identity); | 1235 setOrHideParent('wimax-eap-identity', identity); |
1210 $('wimax-signal-strength').textContent = strengthString; | 1236 $('wimax-signal-strength').textContent = strengthString; |
1211 } else if (data.type == 'Cellular') { | 1237 } else if (data.type == 'Cellular') { |
1212 assert(data.Cellular, | 1238 assert('Cellular' in data, |
1213 'Cellular network has no Cellular object' + networkName); | 1239 'Cellular network has no Cellular object' + networkName); |
1214 OptionsPage.showTab($('cellular-conn-nav-tab')); | 1240 OptionsPage.showTab($('cellular-conn-nav-tab')); |
1215 if (data.showCarrierSelect && data.currentCarrierIndex != -1) { | 1241 if (data.showCarrierSelect && data.currentCarrierIndex != -1) { |
1216 var carrierSelector = $('select-carrier'); | 1242 var carrierSelector = $('select-carrier'); |
1217 carrierSelector.onchange = DetailsInternetPage.handleCarrierChanged; | 1243 carrierSelector.onchange = DetailsInternetPage.handleCarrierChanged; |
1218 carrierSelector.options.length = 0; | 1244 carrierSelector.options.length = 0; |
1219 for (var i = 0; i < data.carriers.length; ++i) { | 1245 for (var i = 0; i < data.carriers.length; ++i) { |
1220 var option = document.createElement('option'); | 1246 var option = document.createElement('option'); |
1221 option.textContent = data.carriers[i]; | 1247 option.textContent = data.carriers[i]; |
1222 carrierSelector.add(option); | 1248 carrierSelector.add(option); |
1223 } | 1249 } |
1224 carrierSelector.selectedIndex = data.currentCarrierIndex; | 1250 carrierSelector.selectedIndex = data.currentCarrierIndex; |
1225 } else { | 1251 } else { |
1226 $('service-name').textContent = networkName; | 1252 $('service-name').textContent = networkName; |
1227 } | 1253 } |
1228 | 1254 |
1229 $('network-technology').textContent = | 1255 $('network-technology').textContent = |
1230 getActiveDictionaryValue(data, 'Cellular', 'NetworkTechnology'); | 1256 getManagedValue(data, 'Cellular.NetworkTechnology'); |
pneubeck (no reviews)
2014/08/19 16:24:02
hm. You could have done a
var cellular = getMana
stevenjb
2014/08/19 18:41:47
Yeah, I thought of that, but wanted to limit the c
| |
1231 $('activation-state').textContent = data.activationState; | 1257 $('activation-state').textContent = data.activationState; |
1232 $('roaming-state').textContent = data.roamingState; | 1258 $('roaming-state').textContent = data.roamingState; |
1233 $('restricted-pool').textContent = data.restrictedPool; | 1259 $('restricted-pool').textContent = data.restrictedPool; |
1234 $('error-state').textContent = data.errorMessage; | 1260 $('error-state').textContent = data.errorMessage; |
1235 $('manufacturer').textContent = | 1261 $('manufacturer').textContent = |
1236 getActiveDictionaryValue(data, 'Cellular', 'Manufacturer'); | 1262 getManagedValue(data, 'Cellular.Manufacturer'); |
1237 $('model-id').textContent = | 1263 $('model-id').textContent = getManagedValue(data, 'Cellular.ModelID'); |
1238 getActiveDictionaryValue(data, 'Cellular', 'ModelID'); | |
1239 $('firmware-revision').textContent = | 1264 $('firmware-revision').textContent = |
1240 getActiveDictionaryValue(data, 'Cellular', 'FirmwareRevision'); | 1265 getManagedValue(data, 'Cellular.FirmwareRevision'); |
1241 $('hardware-revision').textContent = | 1266 $('hardware-revision').textContent = |
1242 getActiveDictionaryValue(data, 'Cellular', 'HardwareRevision'); | 1267 getManagedValue(data, 'Cellular.HardwareRevision'); |
1243 $('mdn').textContent = getActiveDictionaryValue(data, 'Cellular', 'MDN'); | 1268 $('mdn').textContent = getManagedValue(data, 'Cellular.MDN'); |
1244 | 1269 |
1245 // Show ServingOperator properties only if available. | 1270 // Show ServingOperator properties only if available. |
1246 if (data.Cellular.ServingOperator) { | 1271 var servingOperatorName = |
1247 $('operator-name').textContent = | 1272 getManagedValue(data, 'Cellular.ServingOperator.Name'); |
1248 getActiveValue(data.Cellular.ServingOperator, 'Name'); | 1273 var servingOperatorCode = |
1249 $('operator-code').textContent = | 1274 getManagedValue(data, 'Cellular.ServingOperator.Code'); |
1250 getActiveValue(data.Cellular.ServingOperator, 'Code'); | 1275 if (servingOperatorName != undefined && |
1276 servingOperatorCode != undefined) { | |
1277 $('operator-name').textContent = servingOperatorName; | |
1278 $('operator-code').textContent = servingOperatorCode; | |
1251 } else { | 1279 } else { |
1252 $('operator-name').parentElement.hidden = true; | 1280 $('operator-name').parentElement.hidden = true; |
1253 $('operator-code').parentElement.hidden = true; | 1281 $('operator-code').parentElement.hidden = true; |
1254 } | 1282 } |
1255 // Make sure that GSM/CDMA specific properties that shouldn't be hidden | 1283 // Make sure that GSM/CDMA specific properties that shouldn't be hidden |
1256 // are visible. | 1284 // are visible. |
1257 updateHidden('#details-internet-page .gsm-only', false); | 1285 updateHidden('#details-internet-page .gsm-only', false); |
1258 updateHidden('#details-internet-page .cdma-only', false); | 1286 updateHidden('#details-internet-page .cdma-only', false); |
1259 | 1287 |
1260 // Show IMEI/ESN/MEID/MIN/PRL only if they are available. | 1288 // Show IMEI/ESN/MEID/MIN/PRL only if they are available. |
1261 setOrHideParent('esn', getActiveDictionaryValue(data, 'Cellular', 'ESN')); | 1289 setOrHideParent('esn', getManagedValue(data, 'Cellular.ESN')); |
1262 setOrHideParent( | 1290 setOrHideParent('imei', getManagedValue(data, 'Cellular.IMEI')); |
1263 'imei', getActiveDictionaryValue(data, 'Cellular', 'IMEI')); | 1291 setOrHideParent('meid', getManagedValue(data, 'Cellular.MEID')); |
1264 setOrHideParent( | 1292 setOrHideParent('min', getManagedValue(data, 'Cellular.MIN')); |
1265 'meid', getActiveDictionaryValue(data, 'Cellular', 'MEID')); | 1293 setOrHideParent('prl-version', |
1266 setOrHideParent('min', getActiveDictionaryValue(data, 'Cellular', 'MIN')); | 1294 getManagedValue(data, 'Cellular.PRLVersion')); |
1267 setOrHideParent( | |
1268 'prl-version', | |
1269 getActiveDictionaryValue(data, 'Cellular', 'PRLVersion')); | |
1270 | 1295 |
1271 var family = getActiveDictionaryValue(data, 'Cellular', 'GSM'); | 1296 var family = getManagedValue(data, 'Cellular.GSM'); |
1272 detailsPage.gsm = family == 'GSM'; | 1297 detailsPage.gsm = family == 'GSM'; |
1273 if (detailsPage.gsm) { | 1298 if (detailsPage.gsm) { |
1274 $('iccid').textContent = | 1299 $('iccid').textContent = getManagedValue(data, 'Cellular.ICCID'); |
1275 getActiveDictionaryValue(data, 'Cellular', 'ICCID'); | 1300 $('imsi').textContent = getManagedValue(data, 'Cellular.IMSI'); |
1276 $('imsi').textContent = | |
1277 getActiveDictionaryValue(data, 'Cellular', 'IMSI'); | |
1278 | 1301 |
1279 var apnSelector = $('select-apn'); | 1302 var apnSelector = $('select-apn'); |
1280 // Clear APN lists, keep only last element that "other". | 1303 // Clear APN lists, keep only last element that "other". |
1281 while (apnSelector.length != 1) | 1304 while (apnSelector.length != 1) |
1282 apnSelector.remove(0); | 1305 apnSelector.remove(0); |
1283 var otherOption = apnSelector[0]; | 1306 var otherOption = apnSelector[0]; |
1284 data.selectedApn = -1; | 1307 data.selectedApn = -1; |
1285 data.userApnIndex = -1; | 1308 data.userApnIndex = -1; |
1286 var apnList = data.providerApnList.value; | 1309 var apnList = data.providerApnList.value; |
1287 for (var i = 0; i < apnList.length; i++) { | 1310 for (var i = 0; i < apnList.length; i++) { |
(...skipping 29 matching lines...) Expand all Loading... | |
1317 } | 1340 } |
1318 apnSelector.selectedIndex = data.selectedApn; | 1341 apnSelector.selectedIndex = data.selectedApn; |
1319 updateHidden('.apn-list-view', false); | 1342 updateHidden('.apn-list-view', false); |
1320 updateHidden('.apn-details-view', true); | 1343 updateHidden('.apn-details-view', true); |
1321 // TODO(stevenjb): Used managed properties for policy controlled value. | 1344 // TODO(stevenjb): Used managed properties for policy controlled value. |
1322 var lockEnabled = data.simCardLockEnabled.value; | 1345 var lockEnabled = data.simCardLockEnabled.value; |
1323 $('sim-card-lock-enabled').checked = lockEnabled; | 1346 $('sim-card-lock-enabled').checked = lockEnabled; |
1324 $('change-pin').hidden = !lockEnabled; | 1347 $('change-pin').hidden = !lockEnabled; |
1325 } | 1348 } |
1326 $('auto-connect-network-cellular').checked = | 1349 $('auto-connect-network-cellular').checked = |
1327 getActiveValue(data, 'AutoConnect'); | 1350 getManagedValue(data, 'AutoConnect'); |
1328 $('auto-connect-network-cellular').disabled = false; | 1351 $('auto-connect-network-cellular').disabled = false; |
1329 | 1352 |
1330 $('buyplan-details').hidden = !data.showBuyButton; | 1353 $('buyplan-details').hidden = !data.showBuyButton; |
1331 $('view-account-details').hidden = !data.showViewAccountButton; | 1354 $('view-account-details').hidden = !data.showViewAccountButton; |
1332 $('activate-details').hidden = !data.showActivateButton; | 1355 $('activate-details').hidden = !data.showActivateButton; |
1333 if (data.showActivateButton) { | 1356 if (data.showActivateButton) { |
1334 $('details-internet-login').hidden = true; | 1357 $('details-internet-login').hidden = true; |
1335 } | 1358 } |
1336 } else if (data.type == 'VPN') { | 1359 } else if (data.type == 'VPN') { |
1337 OptionsPage.showTab($('vpn-nav-tab')); | 1360 OptionsPage.showTab($('vpn-nav-tab')); |
1338 detailsPage.gsm = false; | 1361 detailsPage.gsm = false; |
1339 $('inet-service-name').textContent = networkName; | 1362 $('inet-service-name').textContent = networkName; |
1340 $('inet-provider-type').textContent = data.providerType; | 1363 $('inet-provider-type').textContent = |
1341 $('inet-username').textContent = data.username; | 1364 getManagedValue(data, 'VPN.Type', 'translated'); |
1365 var providerType = getManagedValue(data, 'VPN.Type', 'active'); | |
1366 var providerKey = 'VPN.' + providerType; | |
1367 $('inet-username').textContent = | |
1368 getManagedValue(data, providerKey + '.Username'); | |
1342 var inetServerHostname = $('inet-server-hostname'); | 1369 var inetServerHostname = $('inet-server-hostname'); |
1343 inetServerHostname.value = data.serverHostname.value; | 1370 inetServerHostname.value = getManagedValue(data, 'VPN.Host'); |
1344 inetServerHostname.resetHandler = function() { | 1371 inetServerHostname.resetHandler = function() { |
1345 PageManager.hideBubble(); | 1372 PageManager.hideBubble(); |
1346 inetServerHostname.value = data.serverHostname.recommendedValue; | 1373 inetServerHostname.value = |
1374 getManagedValue(data, 'VPN.Host', 'recommended'); | |
1347 }; | 1375 }; |
1348 $('auto-connect-network-vpn').checked = | 1376 $('auto-connect-network-vpn').checked = |
1349 getActiveValue(data, 'AutoConnect'); | 1377 getManagedValue(data, 'AutoConnect'); |
1350 $('auto-connect-network-vpn').disabled = false; | 1378 $('auto-connect-network-vpn').disabled = false; |
1351 } else { | 1379 } else { |
1352 OptionsPage.showTab($('internet-nav-tab')); | 1380 OptionsPage.showTab($('internet-nav-tab')); |
1353 } | 1381 } |
1354 | 1382 |
1355 // Update controlled option indicators. | 1383 // Update controlled option indicators. |
1356 var indicators = cr.doc.querySelectorAll( | 1384 var indicators = cr.doc.querySelectorAll( |
1357 '#details-internet-page .controlled-setting-indicator'); | 1385 '#details-internet-page .controlled-setting-indicator'); |
1358 for (var i = 0; i < indicators.length; i++) { | 1386 for (var i = 0; i < indicators.length; i++) { |
1359 var attributeName = | 1387 var managed = indicators[i].hasAttribute('managed'); |
1360 indicators[i].hasAttribute('managed') ? 'managed' : 'data'; | 1388 var attributeName = managed ? 'managed' : 'data'; |
1361 var propName = indicators[i].getAttribute(attributeName); | 1389 var propName = indicators[i].getAttribute(attributeName); |
1362 if (!propName || !data[propName]) | 1390 if (!propName) |
1391 continue; | |
1392 var propValue = | |
1393 managed ? getManagedProperty(data, propName) : data[propName]; | |
1394 if (propValue == undefined) | |
pneubeck (no reviews)
2014/08/19 16:24:02
even better catch. boolean conversion seems really
stevenjb
2014/08/19 18:41:47
I still kind of hate JS, but I'm slowly getting us
| |
1363 continue; | 1395 continue; |
1364 var event; | 1396 var event; |
1365 if (attributeName == 'managed') | 1397 if (managed) |
1366 event = detailsPage.createManagedEvent_(propName, data[propName]); | 1398 event = detailsPage.createManagedEvent_(propName, propValue); |
1367 else | 1399 else |
1368 event = detailsPage.createControlledEvent_(propName, data[propName]); | 1400 event = detailsPage.createControlledEvent_(propName, propValue); |
1369 indicators[i].handlePrefChange(event); | 1401 indicators[i].handlePrefChange(event); |
1370 var forElement = $(indicators[i].getAttribute('for')); | 1402 var forElement = $(indicators[i].getAttribute('for')); |
1371 if (forElement) { | 1403 if (forElement) { |
1372 if (event.value.controlledBy == 'policy') | 1404 if (event.value.controlledBy == 'policy') |
1373 forElement.disabled = true; | 1405 forElement.disabled = true; |
1374 if (forElement.resetHandler) | 1406 if (forElement.resetHandler) |
1375 indicators[i].resetHandler = forElement.resetHandler; | 1407 indicators[i].resetHandler = forElement.resetHandler; |
1376 } | 1408 } |
1377 } | 1409 } |
1378 | 1410 |
1379 detailsPage.updateControls(); | 1411 detailsPage.updateControls(); |
1380 | 1412 |
1381 // Don't show page name in address bar and in history to prevent people | 1413 // Don't show page name in address bar and in history to prevent people |
1382 // navigate here by hand and solve issue with page session restore. | 1414 // navigate here by hand and solve issue with page session restore. |
1383 PageManager.showPageByName('detailsInternetPage', false); | 1415 PageManager.showPageByName('detailsInternetPage', false); |
1384 }; | 1416 }; |
1385 | 1417 |
1386 return { | 1418 return { |
1387 DetailsInternetPage: DetailsInternetPage | 1419 DetailsInternetPage: DetailsInternetPage |
1388 }; | 1420 }; |
1389 }); | 1421 }); |
OLD | NEW |