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 /** | 5 /** |
6 * This partially describes the network list entries passed to | 6 * This partially describes the network list entries passed to |
7 * refreshNetworkData. The contents of those lists actually match | 7 * refreshNetworkData. The contents of those lists actually match |
8 * CrOnc.NetworkConfigType with the addition of the policyManaged property. | 8 * CrOnc.NetworkConfigType with the addition of the policyManaged property. |
9 * TODO(stevenjb): Use networkingPrivate.getNetworks. | 9 * TODO(stevenjb): Use networkingPrivate.getNetworks. |
10 * @typedef {{ | 10 * @typedef {{ |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 'addConnection']; | 57 'addConnection']; |
58 | 58 |
59 /** | 59 /** |
60 * ID of the menu that is currently visible. | 60 * ID of the menu that is currently visible. |
61 * @type {?string} | 61 * @type {?string} |
62 * @private | 62 * @private |
63 */ | 63 */ |
64 var activeMenu_ = null; | 64 var activeMenu_ = null; |
65 | 65 |
66 /** | 66 /** |
67 * Indicates if cellular networks are available. | 67 * The state of the cellular device or undefined if not available. |
68 * @type {boolean} | 68 * @type {string|undefined} |
69 * @private | 69 * @private |
70 */ | 70 */ |
71 var cellularAvailable_ = false; | 71 var cellularState_ = undefined; |
72 | |
73 /** | |
74 * Indicates if cellular networks are enabled. | |
75 * @type {boolean} | |
76 * @private | |
77 */ | |
78 var cellularEnabled_ = false; | |
79 | 72 |
80 /** | 73 /** |
81 * Indicates if cellular device supports network scanning. | 74 * Indicates if cellular device supports network scanning. |
82 * @type {boolean} | 75 * @type {boolean} |
83 * @private | 76 * @private |
84 */ | 77 */ |
85 var cellularSupportsScan_ = false; | 78 var cellularSupportsScan_ = false; |
86 | 79 |
87 /** | 80 /** |
88 * Indicates the current SIM lock type of the cellular device. | 81 * Indicates the current SIM lock type of the cellular device. |
89 * @type {string} | 82 * @type {string} |
90 * @private | 83 * @private |
91 */ | 84 */ |
92 var cellularSimLockType_ = ''; | 85 var cellularSimLockType_ = ''; |
93 | 86 |
94 /** | 87 /** |
95 * Indicates whether the SIM card is absent on the cellular device. | 88 * Indicates whether the SIM card is absent on the cellular device. |
96 * @type {boolean} | 89 * @type {boolean} |
97 * @private | 90 * @private |
98 */ | 91 */ |
99 var cellularSimAbsent_ = false; | 92 var cellularSimAbsent_ = false; |
100 | 93 |
101 /** | 94 /** |
102 * Indicates if WiMAX networks are available. | 95 * The state of the WiFi device or undefined if not available. |
103 * @type {boolean} | 96 * @type {string|undefined} |
104 * @private | 97 * @private |
105 */ | 98 */ |
106 var wimaxAvailable_ = false; | 99 var wifiState_ = undefined; |
107 | 100 |
108 /** | 101 /** |
109 * Indicates if WiMAX networks are enabled. | 102 * The state of the WiMAX device or undefined if not available. |
110 * @type {boolean} | 103 * @type {string|undefined} |
111 * @private | 104 * @private |
112 */ | 105 */ |
113 var wimaxEnabled_ = false; | 106 var wimaxState_ = undefined; |
114 | 107 |
115 /** | 108 /** |
116 * Indicates if mobile data roaming is enabled. | 109 * Indicates if mobile data roaming is enabled. |
117 * @type {boolean} | 110 * @type {boolean} |
118 * @private | 111 * @private |
119 */ | 112 */ |
120 var enableDataRoaming_ = false; | 113 var enableDataRoaming_ = false; |
121 | 114 |
122 /** | 115 /** |
| 116 * List of wired networks. |
| 117 * @type {Array<!NetworkInfo>} |
| 118 * @private |
| 119 */ |
| 120 var wiredList_ = []; |
| 121 |
| 122 /** |
| 123 * List of WiFi, Cellular, and WiMAX networks. |
| 124 * @type {Array<!NetworkInfo>} |
| 125 * @private |
| 126 */ |
| 127 var wirelessList_ = []; |
| 128 |
| 129 /** |
| 130 * List of VPN networks. |
| 131 * @type {Array<!NetworkInfo>} |
| 132 * @private |
| 133 */ |
| 134 var vpnList_ = []; |
| 135 |
| 136 /** |
| 137 * List of remembered (favorite) networks. |
| 138 * @type {Array<!NetworkInfo>} |
| 139 * @private |
| 140 */ |
| 141 var rememberedList_ = []; |
| 142 |
| 143 /** |
123 * Returns the display name for 'network'. | 144 * Returns the display name for 'network'. |
124 * @param {Object} data The network data dictionary. | 145 * @param {Object} data The network data dictionary. |
125 */ | 146 */ |
126 function getNetworkName(data) { | 147 function getNetworkName(data) { |
127 if (data.Type == 'Ethernet') | 148 if (data.Type == 'Ethernet') |
128 return loadTimeData.getString('ethernetName'); | 149 return loadTimeData.getString('ethernetName'); |
129 if (data.Type == 'VPN') | 150 if (data.Type == 'VPN') |
130 return options.VPNProviders.formatNetworkName(new cr.onc.OncData(data)); | 151 return options.VPNProviders.formatNetworkName(new cr.onc.OncData(data)); |
131 return data.Name; | 152 return data.Name; |
132 } | 153 } |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 menu.hidden = true; | 526 menu.hidden = true; |
506 Menu.decorate(menu); | 527 Menu.decorate(menu); |
507 var addendum = []; | 528 var addendum = []; |
508 if (this.data_.key == 'WiFi') { | 529 if (this.data_.key == 'WiFi') { |
509 addendum.push({ | 530 addendum.push({ |
510 label: loadTimeData.getString('joinOtherNetwork'), | 531 label: loadTimeData.getString('joinOtherNetwork'), |
511 command: createAddNonVPNConnectionCallback_('WiFi'), | 532 command: createAddNonVPNConnectionCallback_('WiFi'), |
512 data: {} | 533 data: {} |
513 }); | 534 }); |
514 } else if (this.data_.key == 'Cellular') { | 535 } else if (this.data_.key == 'Cellular') { |
515 if (cellularEnabled_ && cellularSupportsScan_) { | 536 if (cellularState_ == 'Enabled' && cellularSupportsScan_) { |
516 addendum.push({ | 537 addendum.push({ |
517 label: loadTimeData.getString('otherCellularNetworks'), | 538 label: loadTimeData.getString('otherCellularNetworks'), |
518 command: createAddNonVPNConnectionCallback_('Cellular'), | 539 command: createAddNonVPNConnectionCallback_('Cellular'), |
519 addClass: ['other-cellulars'], | 540 addClass: ['other-cellulars'], |
520 data: {} | 541 data: {} |
521 }); | 542 }); |
522 } | 543 } |
523 | 544 |
524 var label = enableDataRoaming_ ? 'disableDataRoaming' : | 545 var label = enableDataRoaming_ ? 'disableDataRoaming' : |
525 'enableDataRoaming'; | 546 'enableDataRoaming'; |
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1021 if (index != undefined) { | 1042 if (index != undefined) { |
1022 var entry = this.dataModel.item(index); | 1043 var entry = this.dataModel.item(index); |
1023 entry.iconType = active ? 'control-active' : 'control-inactive'; | 1044 entry.iconType = active ? 'control-active' : 'control-inactive'; |
1024 this.update(entry); | 1045 this.update(entry); |
1025 } | 1046 } |
1026 } | 1047 } |
1027 }; | 1048 }; |
1028 | 1049 |
1029 /** | 1050 /** |
1030 * Chrome callback for updating network controls. | 1051 * Chrome callback for updating network controls. |
1031 * @param {{cellularAvailable: boolean, | 1052 * @param {{cellularSimAbsent: boolean, |
1032 * cellularEnabled: boolean, | |
1033 * cellularSimAbsent: boolean, | |
1034 * cellularSimLockType: string, | 1053 * cellularSimLockType: string, |
1035 * cellularSupportsScan: boolean, | 1054 * cellularSupportsScan: boolean, |
1036 * rememberedList: Array<NetworkInfo>, | 1055 * rememberedList: Array<NetworkInfo>, |
1037 * vpnList: Array<NetworkInfo>, | 1056 * vpnList: Array<NetworkInfo>, |
1038 * wifiAvailable: boolean, | |
1039 * wifiEnabled: boolean, | |
1040 * wimaxAvailable: boolean, | |
1041 * wimaxEnabled: boolean, | |
1042 * wiredList: Array<NetworkInfo>, | 1057 * wiredList: Array<NetworkInfo>, |
1043 * wirelessList: Array<NetworkInfo>}} data Description of available | 1058 * wirelessList: Array<NetworkInfo>}} data Description of available |
1044 * network devices and their corresponding state. | 1059 * network devices and their corresponding state. |
1045 */ | 1060 */ |
1046 NetworkList.refreshNetworkData = function(data) { | 1061 NetworkList.refreshNetworkData = function(data) { |
1047 var networkList = $('network-list'); | |
1048 networkList.startBatchUpdates(); | |
1049 cellularAvailable_ = data.cellularAvailable; | |
1050 cellularEnabled_ = data.cellularEnabled; | |
1051 cellularSupportsScan_ = data.cellularSupportsScan; | 1062 cellularSupportsScan_ = data.cellularSupportsScan; |
1052 cellularSimAbsent_ = data.cellularSimAbsent; | 1063 cellularSimAbsent_ = data.cellularSimAbsent; |
1053 cellularSimLockType_ = data.cellularSimLockType; | 1064 cellularSimLockType_ = data.cellularSimLockType; |
1054 wimaxAvailable_ = data.wimaxAvailable; | 1065 wiredList_ = data.wiredList; |
1055 wimaxEnabled_ = data.wimaxEnabled; | 1066 wirelessList_ = data.wirelessList; |
| 1067 vpnList_ = data.vpnList; |
| 1068 rememberedList_ = data.rememberedList; |
| 1069 |
| 1070 // Request device states. |
| 1071 chrome.networkingPrivate.getDeviceStates( |
| 1072 NetworkList.onGetDeviceStates.bind(this)); |
| 1073 }; |
| 1074 |
| 1075 /** |
| 1076 * Callback from getDeviceStates. Updates network controls. |
| 1077 * @param {Array<{State: string, Type: string}>} deviceStates The result |
| 1078 * from getDeviceStates. |
| 1079 */ |
| 1080 NetworkList.onGetDeviceStates = function(deviceStates) { |
| 1081 var networkList = $('network-list'); |
| 1082 networkList.startBatchUpdates(); |
| 1083 |
| 1084 cellularState_ = undefined; |
| 1085 wifiState_ = undefined; |
| 1086 wimaxState_ = undefined; |
| 1087 for (var i = 0; i < deviceStates.length; ++i) { |
| 1088 var device = deviceStates[i]; |
| 1089 var type = device.Type; |
| 1090 var state = device.State; |
| 1091 if (type == 'Cellular') |
| 1092 cellularState_ = cellularState_ || state; |
| 1093 else if (type == 'WiFi') |
| 1094 wifiState_ = wifiState_ || state; |
| 1095 else if (type == 'WiMAX') |
| 1096 wimaxState_ = wimaxState_ || state; |
| 1097 } |
1056 | 1098 |
1057 // Only show Ethernet control if connected. | 1099 // Only show Ethernet control if connected. |
1058 var ethernetConnection = getConnection_(data.wiredList); | 1100 var ethernetConnection = getConnection_(wiredList_); |
1059 if (ethernetConnection) { | 1101 if (ethernetConnection) { |
1060 var type = String('Ethernet'); | 1102 var type = String('Ethernet'); |
1061 var ethernetOptions = showDetails.bind(null, ethernetConnection.GUID); | 1103 var ethernetOptions = showDetails.bind(null, ethernetConnection.GUID); |
1062 networkList.update( | 1104 networkList.update( |
1063 { key: 'Ethernet', | 1105 { key: 'Ethernet', |
1064 subtitle: loadTimeData.getString('OncConnectionStateConnected'), | 1106 subtitle: loadTimeData.getString('OncConnectionStateConnected'), |
1065 iconData: ethernetConnection, | 1107 iconData: ethernetConnection, |
1066 command: ethernetOptions, | 1108 command: ethernetOptions, |
1067 policyManaged: ethernetConnection.policyManaged } | 1109 policyManaged: ethernetConnection.policyManaged } |
1068 ); | 1110 ); |
1069 } else { | 1111 } else { |
1070 networkList.deleteItem('Ethernet'); | 1112 networkList.deleteItem('Ethernet'); |
1071 } | 1113 } |
1072 | 1114 |
1073 if (data.wifiEnabled) | 1115 if (wifiState_ == 'Enabled') |
1074 loadData_('WiFi', data.wirelessList, data.rememberedList); | 1116 loadData_('WiFi', wirelessList_, rememberedList_); |
1075 else | 1117 else |
1076 addEnableNetworkButton_('WiFi'); | 1118 addEnableNetworkButton_('WiFi'); |
1077 | 1119 |
1078 // Only show cellular control if available. | 1120 // Only show cellular control if available. |
1079 if (data.cellularAvailable) { | 1121 if (cellularState_) { |
1080 if (data.cellularEnabled) | 1122 if (cellularState_ == 'Enabled') |
1081 loadData_('Cellular', data.wirelessList, data.rememberedList); | 1123 loadData_('Cellular', wirelessList_, rememberedList_); |
1082 else | 1124 else |
1083 addEnableNetworkButton_('Cellular'); | 1125 addEnableNetworkButton_('Cellular'); |
1084 } else { | 1126 } else { |
1085 networkList.deleteItem('Cellular'); | 1127 networkList.deleteItem('Cellular'); |
1086 } | 1128 } |
1087 | 1129 |
1088 // Only show wimax control if available. Uses cellular icons. | 1130 // Only show wimax control if available. Uses cellular icons. |
1089 if (data.wimaxAvailable) { | 1131 if (wimaxState_) { |
1090 if (data.wimaxEnabled) | 1132 if (wimaxState_ == 'Enabled') |
1091 loadData_('WiMAX', data.wirelessList, data.rememberedList); | 1133 loadData_('WiMAX', wirelessList_, rememberedList_); |
1092 else | 1134 else |
1093 addEnableNetworkButton_('WiMAX'); | 1135 addEnableNetworkButton_('WiMAX'); |
1094 } else { | 1136 } else { |
1095 networkList.deleteItem('WiMAX'); | 1137 networkList.deleteItem('WiMAX'); |
1096 } | 1138 } |
1097 | 1139 |
1098 // Only show VPN control if there is at least one VPN configured. | 1140 // Only show VPN control if there is at least one VPN configured. |
1099 if (data.vpnList.length > 0) | 1141 if (vpnList_.length > 0) |
1100 loadData_('VPN', data.vpnList, data.rememberedList); | 1142 loadData_('VPN', vpnList_, rememberedList_); |
1101 else | 1143 else |
1102 networkList.deleteItem('VPN'); | 1144 networkList.deleteItem('VPN'); |
1103 networkList.endBatchUpdates(); | 1145 networkList.endBatchUpdates(); |
1104 }; | 1146 }; |
1105 | 1147 |
1106 /** | 1148 /** |
1107 * Replaces a network menu with a button for enabling the network type. | 1149 * Replaces a network menu with a button for enabling the network type. |
1108 * @param {string} type The type of network (WiFi, Cellular or Wimax). | 1150 * @param {string} type The type of network (WiFi, Cellular or Wimax). |
1109 * @private | 1151 * @private |
1110 */ | 1152 */ |
1111 function addEnableNetworkButton_(type) { | 1153 function addEnableNetworkButton_(type) { |
1112 var subtitle = loadTimeData.getString('networkDisabled'); | 1154 var subtitle = loadTimeData.getString('networkDisabled'); |
1113 var enableNetwork = function() { | 1155 var enableNetwork = function() { |
1114 if (type == 'WiFi') | 1156 if (type == 'WiFi') |
1115 sendChromeMetricsAction('Options_NetworkWifiToggle'); | 1157 sendChromeMetricsAction('Options_NetworkWifiToggle'); |
1116 if (type == 'Cellular') { | 1158 if (type == 'Cellular') { |
1117 if (cellularSimLockType_) { | 1159 if (cellularSimLockType_) { |
1118 chrome.send('simOperation', ['unlock']); | 1160 chrome.send('simOperation', ['unlock']); |
1119 return; | 1161 return; |
1120 } else if (cellularEnabled_ && cellularSimAbsent_) { | 1162 } else if (cellularState_ == 'Enabled' && cellularSimAbsent_) { |
1121 chrome.send('simOperation', ['configure']); | 1163 chrome.send('simOperation', ['configure']); |
1122 return; | 1164 return; |
1123 } | 1165 } |
1124 } | 1166 } |
1125 chrome.networkingPrivate.enableNetworkType(type); | 1167 chrome.networkingPrivate.enableNetworkType(type); |
1126 }; | 1168 }; |
1127 $('network-list').update({key: type, | 1169 $('network-list').update({key: type, |
1128 subtitle: subtitle, | 1170 subtitle: subtitle, |
1129 iconType: type, | 1171 iconType: type, |
1130 command: enableNetwork}); | 1172 command: enableNetwork}); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1304 /** | 1346 /** |
1305 * Whether the Network list is disabled. Only used for display purpose. | 1347 * Whether the Network list is disabled. Only used for display purpose. |
1306 */ | 1348 */ |
1307 cr.defineProperty(NetworkList, 'disabled', cr.PropertyKind.BOOL_ATTR); | 1349 cr.defineProperty(NetworkList, 'disabled', cr.PropertyKind.BOOL_ATTR); |
1308 | 1350 |
1309 // Export | 1351 // Export |
1310 return { | 1352 return { |
1311 NetworkList: NetworkList | 1353 NetworkList: NetworkList |
1312 }; | 1354 }; |
1313 }); | 1355 }); |
OLD | NEW |