Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: chrome/browser/resources/options/chromeos/network_list.js

Issue 1057613006: Use networkingPrivate.getDeviceState in Internet Settings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 'VPN', 56 'VPN',
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
pneubeck (no reviews) 2015/04/15 08:13:06 nit: remove empty line
stevenjb 2015/04/16 17:07:44 Done.
66 /** 67 /**
67 * Indicates if cellular networks are available. 68 * The state of the cellular device or undefined if not available.
68 * @type {boolean} 69 * @type {string|undefined}
69 * @private 70 * @private
70 */ 71 */
71 var cellularAvailable_ = false; 72 var cellularState_ = undefined;
72
73 /**
74 * Indicates if cellular networks are enabled.
75 * @type {boolean}
76 * @private
77 */
78 var cellularEnabled_ = false;
79 73
80 /** 74 /**
81 * Indicates if cellular device supports network scanning. 75 * Indicates if cellular device supports network scanning.
82 * @type {boolean} 76 * @type {boolean}
83 * @private 77 * @private
84 */ 78 */
85 var cellularSupportsScan_ = false; 79 var cellularSupportsScan_ = false;
86 80
87 /** 81 /**
88 * Indicates the current SIM lock type of the cellular device. 82 * Indicates the current SIM lock type of the cellular device.
89 * @type {string} 83 * @type {string}
90 * @private 84 * @private
91 */ 85 */
92 var cellularSimLockType_ = ''; 86 var cellularSimLockType_ = '';
93 87
94 /** 88 /**
95 * Indicates whether the SIM card is absent on the cellular device. 89 * Indicates whether the SIM card is absent on the cellular device.
96 * @type {boolean} 90 * @type {boolean}
97 * @private 91 * @private
98 */ 92 */
99 var cellularSimAbsent_ = false; 93 var cellularSimAbsent_ = false;
100 94
101 /** 95 /**
102 * Indicates if WiMAX networks are available. 96 * The state of the WiFi device or undefined if not available.
103 * @type {boolean} 97 * @type {string|undefined}
104 * @private 98 * @private
105 */ 99 */
106 var wimaxAvailable_ = false; 100 var wifiState_ = undefined;
107 101
108 /** 102 /**
109 * Indicates if WiMAX networks are enabled. 103 * The state of the WiMAX device or undefined if not available.
110 * @type {boolean} 104 * @type {string|undefined}
111 * @private 105 * @private
112 */ 106 */
113 var wimaxEnabled_ = false; 107 var wimaxState_ = undefined;
114 108
115 /** 109 /**
116 * Indicates if mobile data roaming is enabled. 110 * Indicates if mobile data roaming is enabled.
117 * @type {boolean} 111 * @type {boolean}
118 * @private 112 * @private
119 */ 113 */
120 var enableDataRoaming_ = false; 114 var enableDataRoaming_ = false;
121 115
122 /** 116 /**
117 * List of wired networks.
118 * @type {Array<!NetworkInfo>}
119 * @private
120 */
121 var wiredList_ = [];
122
123 /**
124 * List of WiFi, Cellular, and WiMAX networks.
125 * @type {Array<!NetworkInfo>}
126 * @private
127 */
128 var wirelessList_ = [];
129
130 /**
131 * List of VPN networks.
132 * @type {Array<!NetworkInfo>}
133 * @private
134 */
135 var vpnList_ = [];
136
137 /**
138 * List of remembered (favorite) networks.
139 * @type {Array<!NetworkInfo>}
140 * @private
141 */
142 var rememberedList_ = [];
143
144 /**
123 * Returns the display name for 'network'. 145 * Returns the display name for 'network'.
124 * @param {Object} data The network data dictionary. 146 * @param {Object} data The network data dictionary.
125 */ 147 */
126 function getNetworkName(data) { 148 function getNetworkName(data) {
127 if (data.Type == 'Ethernet') 149 if (data.Type == 'Ethernet')
128 return loadTimeData.getString('ethernetName'); 150 return loadTimeData.getString('ethernetName');
129 if (data.Type == 'VPN') 151 if (data.Type == 'VPN')
130 return options.VPNProviders.formatNetworkName(new cr.onc.OncData(data)); 152 return options.VPNProviders.formatNetworkName(new cr.onc.OncData(data));
131 return data.Name; 153 return data.Name;
132 } 154 }
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 menu.hidden = true; 527 menu.hidden = true;
506 Menu.decorate(menu); 528 Menu.decorate(menu);
507 var addendum = []; 529 var addendum = [];
508 if (this.data_.key == 'WiFi') { 530 if (this.data_.key == 'WiFi') {
509 addendum.push({ 531 addendum.push({
510 label: loadTimeData.getString('joinOtherNetwork'), 532 label: loadTimeData.getString('joinOtherNetwork'),
511 command: createAddNonVPNConnectionCallback_('WiFi'), 533 command: createAddNonVPNConnectionCallback_('WiFi'),
512 data: {} 534 data: {}
513 }); 535 });
514 } else if (this.data_.key == 'Cellular') { 536 } else if (this.data_.key == 'Cellular') {
515 if (cellularEnabled_ && cellularSupportsScan_) { 537 if (cellularState_ == 'Enabled' && cellularSupportsScan_) {
516 addendum.push({ 538 addendum.push({
517 label: loadTimeData.getString('otherCellularNetworks'), 539 label: loadTimeData.getString('otherCellularNetworks'),
518 command: createAddNonVPNConnectionCallback_('Cellular'), 540 command: createAddNonVPNConnectionCallback_('Cellular'),
519 addClass: ['other-cellulars'], 541 addClass: ['other-cellulars'],
520 data: {} 542 data: {}
521 }); 543 });
522 } 544 }
523 545
524 var label = enableDataRoaming_ ? 'disableDataRoaming' : 546 var label = enableDataRoaming_ ? 'disableDataRoaming' :
525 'enableDataRoaming'; 547 'enableDataRoaming';
(...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 if (index != undefined) { 1043 if (index != undefined) {
1022 var entry = this.dataModel.item(index); 1044 var entry = this.dataModel.item(index);
1023 entry.iconType = active ? 'control-active' : 'control-inactive'; 1045 entry.iconType = active ? 'control-active' : 'control-inactive';
1024 this.update(entry); 1046 this.update(entry);
1025 } 1047 }
1026 } 1048 }
1027 }; 1049 };
1028 1050
1029 /** 1051 /**
1030 * Chrome callback for updating network controls. 1052 * Chrome callback for updating network controls.
1031 * @param {{cellularAvailable: boolean, 1053 * @param {{cellularSimAbsent: boolean,
1032 * cellularEnabled: boolean,
1033 * cellularSimAbsent: boolean,
1034 * cellularSimLockType: string, 1054 * cellularSimLockType: string,
1035 * cellularSupportsScan: boolean, 1055 * cellularSupportsScan: boolean,
1036 * rememberedList: Array<NetworkInfo>, 1056 * rememberedList: Array<NetworkInfo>,
1037 * vpnList: Array<NetworkInfo>, 1057 * vpnList: Array<NetworkInfo>,
1038 * wifiAvailable: boolean,
1039 * wifiEnabled: boolean,
1040 * wimaxAvailable: boolean,
1041 * wimaxEnabled: boolean,
1042 * wiredList: Array<NetworkInfo>, 1058 * wiredList: Array<NetworkInfo>,
1043 * wirelessList: Array<NetworkInfo>}} data Description of available 1059 * wirelessList: Array<NetworkInfo>}} data Description of available
1044 * network devices and their corresponding state. 1060 * network devices and their corresponding state.
1045 */ 1061 */
1046 NetworkList.refreshNetworkData = function(data) { 1062 NetworkList.refreshNetworkData = function(data) {
1047 var networkList = $('network-list');
1048 networkList.startBatchUpdates();
1049 cellularAvailable_ = data.cellularAvailable;
1050 cellularEnabled_ = data.cellularEnabled;
1051 cellularSupportsScan_ = data.cellularSupportsScan; 1063 cellularSupportsScan_ = data.cellularSupportsScan;
1052 cellularSimAbsent_ = data.cellularSimAbsent; 1064 cellularSimAbsent_ = data.cellularSimAbsent;
1053 cellularSimLockType_ = data.cellularSimLockType; 1065 cellularSimLockType_ = data.cellularSimLockType;
1054 wimaxAvailable_ = data.wimaxAvailable; 1066 wiredList_ = data.wiredList;
1055 wimaxEnabled_ = data.wimaxEnabled; 1067 wirelessList_ = data.wirelessList;
1068 vpnList_ = data.vpnList;
1069 rememberedList_ = data.rememberedList;
1070
1071 // Request device states.
1072 chrome.networkingPrivate.getDeviceStates(
1073 NetworkList.onGetDeviceStates.bind(this));
1074 };
1075
1076 /**
1077 * Callback from getDeviceStates. Updates network controls.
1078 * @param {Array<{State: string, Type: string}>} deviceStates The result
1079 * from getDeviceStates.
1080 */
1081 NetworkList.onGetDeviceStates = function(deviceStates) {
1082 var networkList = $('network-list');
1083 networkList.startBatchUpdates();
1084
1085 cellularState_ = undefined;
1086 wifiState_ = undefined;
1087 wimaxState_ = undefined;
1088 for (var i = 0; i < deviceStates.length; ++i) {
1089 var device = deviceStates[i];
1090 var type = device.Type;
pneubeck (no reviews) 2015/04/15 08:13:05 nit: to make it more generic / less code, you coul
stevenjb 2015/04/16 17:07:44 I decided against that since it is an incomplete l
1091 var state = device.State;
1092 if (type == 'Cellular')
1093 cellularState_ = cellularState_ || state;
1094 else if (type == 'WiFi')
1095 wifiState_ = wifiState_ || state;
1096 else if (type == 'WiMAX')
1097 wimaxState_ = wimaxState_ || state;
1098 }
1056 1099
1057 // Only show Ethernet control if connected. 1100 // Only show Ethernet control if connected.
1058 var ethernetConnection = getConnection_(data.wiredList); 1101 var ethernetConnection = getConnection_(wiredList_);
1059 if (ethernetConnection) { 1102 if (ethernetConnection) {
1060 var type = String('Ethernet'); 1103 var type = String('Ethernet');
1061 var ethernetOptions = showDetails.bind(null, ethernetConnection.GUID); 1104 var ethernetOptions = showDetails.bind(null, ethernetConnection.GUID);
1062 networkList.update( 1105 networkList.update(
1063 { key: 'Ethernet', 1106 { key: 'Ethernet',
1064 subtitle: loadTimeData.getString('OncConnectionStateConnected'), 1107 subtitle: loadTimeData.getString('OncConnectionStateConnected'),
1065 iconData: ethernetConnection, 1108 iconData: ethernetConnection,
1066 command: ethernetOptions, 1109 command: ethernetOptions,
1067 policyManaged: ethernetConnection.policyManaged } 1110 policyManaged: ethernetConnection.policyManaged }
1068 ); 1111 );
1069 } else { 1112 } else {
1070 networkList.deleteItem('Ethernet'); 1113 networkList.deleteItem('Ethernet');
1071 } 1114 }
1072 1115
1073 if (data.wifiEnabled) 1116 if (wifiState_ == 'Enabled')
1074 loadData_('WiFi', data.wirelessList, data.rememberedList); 1117 loadData_('WiFi', wirelessList_, rememberedList_);
1075 else 1118 else
1076 addEnableNetworkButton_('WiFi'); 1119 addEnableNetworkButton_('WiFi');
1077 1120
1078 // Only show cellular control if available. 1121 // Only show cellular control if available.
1079 if (data.cellularAvailable) { 1122 if (cellularState_) {
1080 if (data.cellularEnabled) 1123 if (cellularState_ == 'Enabled')
1081 loadData_('Cellular', data.wirelessList, data.rememberedList); 1124 loadData_('Cellular', wirelessList_, rememberedList_);
1082 else 1125 else
1083 addEnableNetworkButton_('Cellular'); 1126 addEnableNetworkButton_('Cellular');
1084 } else { 1127 } else {
1085 networkList.deleteItem('Cellular'); 1128 networkList.deleteItem('Cellular');
1086 } 1129 }
1087 1130
1088 // Only show wimax control if available. Uses cellular icons. 1131 // Only show wimax control if available. Uses cellular icons.
1089 if (data.wimaxAvailable) { 1132 if (wimaxState_) {
1090 if (data.wimaxEnabled) 1133 if (wimaxState_ == 'Enabled')
1091 loadData_('WiMAX', data.wirelessList, data.rememberedList); 1134 loadData_('WiMAX', wirelessList_, rememberedList_);
1092 else 1135 else
1093 addEnableNetworkButton_('WiMAX'); 1136 addEnableNetworkButton_('WiMAX');
1094 } else { 1137 } else {
1095 networkList.deleteItem('WiMAX'); 1138 networkList.deleteItem('WiMAX');
1096 } 1139 }
1097 1140
1098 // Only show VPN control if there is at least one VPN configured. 1141 // Only show VPN control if there is at least one VPN configured.
1099 if (data.vpnList.length > 0) 1142 if (vpnList_.length > 0)
1100 loadData_('VPN', data.vpnList, data.rememberedList); 1143 loadData_('VPN', vpnList_, rememberedList_);
1101 else 1144 else
1102 networkList.deleteItem('VPN'); 1145 networkList.deleteItem('VPN');
1103 networkList.endBatchUpdates(); 1146 networkList.endBatchUpdates();
1104 }; 1147 };
1105 1148
1106 /** 1149 /**
1107 * Replaces a network menu with a button for enabling the network type. 1150 * Replaces a network menu with a button for enabling the network type.
1108 * @param {string} type The type of network (WiFi, Cellular or Wimax). 1151 * @param {string} type The type of network (WiFi, Cellular or Wimax).
1109 * @private 1152 * @private
1110 */ 1153 */
1111 function addEnableNetworkButton_(type) { 1154 function addEnableNetworkButton_(type) {
1112 var subtitle = loadTimeData.getString('networkDisabled'); 1155 var subtitle = loadTimeData.getString('networkDisabled');
1113 var enableNetwork = function() { 1156 var enableNetwork = function() {
1114 if (type == 'WiFi') 1157 if (type == 'WiFi')
1115 sendChromeMetricsAction('Options_NetworkWifiToggle'); 1158 sendChromeMetricsAction('Options_NetworkWifiToggle');
1116 if (type == 'Cellular') { 1159 if (type == 'Cellular') {
1117 if (cellularSimLockType_) { 1160 if (cellularSimLockType_) {
1118 chrome.send('simOperation', ['unlock']); 1161 chrome.send('simOperation', ['unlock']);
1119 return; 1162 return;
1120 } else if (cellularEnabled_ && cellularSimAbsent_) { 1163 } else if (cellularState_ == 'Enabled' && cellularSimAbsent_) {
1121 chrome.send('simOperation', ['configure']); 1164 chrome.send('simOperation', ['configure']);
1122 return; 1165 return;
1123 } 1166 }
1124 } 1167 }
1125 chrome.networkingPrivate.enableNetworkType(type); 1168 chrome.networkingPrivate.enableNetworkType(type);
1126 }; 1169 };
1127 $('network-list').update({key: type, 1170 $('network-list').update({key: type,
1128 subtitle: subtitle, 1171 subtitle: subtitle,
1129 iconType: type, 1172 iconType: type,
1130 command: enableNetwork}); 1173 command: enableNetwork});
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 /** 1347 /**
1305 * Whether the Network list is disabled. Only used for display purpose. 1348 * Whether the Network list is disabled. Only used for display purpose.
1306 */ 1349 */
1307 cr.defineProperty(NetworkList, 'disabled', cr.PropertyKind.BOOL_ATTR); 1350 cr.defineProperty(NetworkList, 'disabled', cr.PropertyKind.BOOL_ATTR);
1308 1351
1309 // Export 1352 // Export
1310 return { 1353 return {
1311 NetworkList: NetworkList 1354 NetworkList: NetworkList
1312 }; 1355 };
1313 }); 1356 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698