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

Side by Side Diff: chrome/browser/resources/settings/internet_page/internet_subpage.js

Issue 2913323003: Settings: Network: Merge Tether networks into Mobile subpage (Closed)
Patch Set: Fix browser_tests Created 3 years, 6 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 * @fileoverview Polymer element for displaying information about WiFi, 6 * @fileoverview Polymer element for displaying information about WiFi,
7 * WiMAX, or virtual networks. 7 * WiMAX, or virtual networks.
8 */ 8 */
9 9
10 Polymer({ 10 Polymer({
11 is: 'settings-internet-subpage', 11 is: 'settings-internet-subpage',
12 12
13 behaviors: [ 13 behaviors: [
14 CrPolicyNetworkBehavior, 14 CrPolicyNetworkBehavior,
15 settings.RouteObserverBehavior, 15 settings.RouteObserverBehavior,
16 I18nBehavior, 16 I18nBehavior,
17 ], 17 ],
18 18
19 properties: { 19 properties: {
20 /** 20 /**
21 * Highest priority connected network or null. Provided by 21 * Highest priority connected network or null. Provided by
22 * settings-internet-page (but set in network-summary). 22 * settings-internet-page (but set in network-summary).
23 * @type {?CrOnc.NetworkStateProperties|undefined} 23 * @type {?CrOnc.NetworkStateProperties|undefined}
24 */ 24 */
25 defaultNetwork: Object, 25 defaultNetwork: Object,
26 26
27 /** 27 /**
28 * Device state for the network type. 28 * Device state for the network type. Note: when both Cellular and Tether
29 * are available this will always be set to the Cellular device state and
30 * |tetherDeviceState| will be set to the Tether device state.
29 * @type {!CrOnc.DeviceStateProperties|undefined} 31 * @type {!CrOnc.DeviceStateProperties|undefined}
30 */ 32 */
31 deviceState: Object, 33 deviceState: Object,
32 34
35 /**
36 * If both Cellular and Tether technologies exist, we combine the subpages
37 * and set this to the device state for Tether.
38 * @type {!CrOnc.DeviceStateProperties|undefined}
39 */
40 tetherDeviceState: Object,
41
33 /** @type {!chrome.networkingPrivate.GlobalPolicy|undefined} */ 42 /** @type {!chrome.networkingPrivate.GlobalPolicy|undefined} */
34 globalPolicy: Object, 43 globalPolicy: Object,
35 44
36 /** 45 /**
37 * List of third party VPN providers. 46 * List of third party VPN providers.
38 * @type 47 * @type
39 * {!Array<!chrome.networkingPrivate.ThirdPartyVPNProperties>|undefined} 48 * {!Array<!chrome.networkingPrivate.ThirdPartyVPNProperties>|undefined}
40 */ 49 */
41 thirdPartyVpnProviders: Array, 50 thirdPartyVpnProviders: Array,
42 51
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 173
165 /** @private */ 174 /** @private */
166 getNetworkStateList_: function() { 175 getNetworkStateList_: function() {
167 if (!this.deviceState) 176 if (!this.deviceState)
168 return; 177 return;
169 var filter = { 178 var filter = {
170 networkType: this.deviceState.Type, 179 networkType: this.deviceState.Type,
171 visible: true, 180 visible: true,
172 configured: false 181 configured: false
173 }; 182 };
174 this.networkingPrivate.getNetworks(filter, function(networkStates) { 183 this.networkingPrivate.getNetworks(filter, this.onGetNetworks_.bind(this));
175 if (!this.deviceState) 184 },
176 return; 185
177 if (this.deviceState.Type != CrOnc.Type.VPN) { 186 /**
178 this.networkStateList_ = networkStates; 187 * @param {!Array<!CrOnc.NetworkStateProperties>} networkStates
179 return; 188 * @private
180 } 189 */
181 // For VPNs, separate out third party VPNs. 190 onGetNetworks_: function(networkStates) {
182 var networkStateList = []; 191 if (!this.deviceState)
192 return; // Edge case when device states change before this callback.
193
194 // For the Cellular/Mobile subpage, request Tether networks if available.
195 if (this.deviceState.Type == CrOnc.Type.CELLULAR &&
196 this.tetherDeviceState) {
197 var filter = {
198 networkType: CrOnc.Type.TETHER,
199 visible: true,
200 configured: false
201 };
202 this.networkingPrivate.getNetworks(filter, function(tetherNetworkStates) {
203 this.networkStateList_ = networkStates.concat(tetherNetworkStates);
204 }.bind(this));
205 return;
206 }
207
208 // For VPNs, separate out third party VPNs.
209 if (this.deviceState.Type == CrOnc.Type.VPN) {
210 var builtinNetworkStates = [];
183 var thirdPartyVpns = {}; 211 var thirdPartyVpns = {};
184 for (var i = 0; i < networkStates.length; ++i) { 212 for (var i = 0; i < networkStates.length; ++i) {
185 var state = networkStates[i]; 213 var state = networkStates[i];
186 var providerType = state.VPN && state.VPN.ThirdPartyVPN && 214 var providerType = state.VPN && state.VPN.ThirdPartyVPN &&
187 state.VPN.ThirdPartyVPN.ProviderName; 215 state.VPN.ThirdPartyVPN.ProviderName;
188 if (providerType) { 216 if (providerType) {
189 thirdPartyVpns[providerType] = thirdPartyVpns[providerType] || []; 217 thirdPartyVpns[providerType] = thirdPartyVpns[providerType] || [];
190 thirdPartyVpns[providerType].push(state); 218 thirdPartyVpns[providerType].push(state);
191 } else { 219 } else {
192 networkStateList.push(state); 220 builtinNetworkStates.push(state);
193 } 221 }
222 networkStates = builtinNetworkStates;
223 this.thirdPartyVpns_ = thirdPartyVpns;
194 } 224 }
195 this.networkStateList_ = networkStateList; 225 }
196 this.thirdPartyVpns_ = thirdPartyVpns; 226
197 }.bind(this)); 227 this.networkStateList_ = networkStates;
198 }, 228 },
199 229
200 /** 230 /**
201 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState 231 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState
202 * @return {boolean} Whether or not the device state is enabled. 232 * @return {boolean} Whether or not the device state is enabled.
203 * @private 233 * @private
204 */ 234 */
205 deviceIsEnabled_: function(deviceState) { 235 deviceIsEnabled_: function(deviceState) {
206 return !!deviceState && deviceState.State == CrOnc.DeviceState.ENABLED; 236 return !!deviceState && deviceState.State == CrOnc.DeviceState.ENABLED;
207 }, 237 },
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 /** 269 /**
240 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState 270 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState
241 * @return {string} 271 * @return {string}
242 * @private 272 * @private
243 */ 273 */
244 getToggleA11yString_: function(deviceState) { 274 getToggleA11yString_: function(deviceState) {
245 if (!this.enableToggleIsVisible_(deviceState)) 275 if (!this.enableToggleIsVisible_(deviceState))
246 return ''; 276 return '';
247 switch (deviceState.Type) { 277 switch (deviceState.Type) {
248 case CrOnc.Type.TETHER: 278 case CrOnc.Type.TETHER:
249 return this.i18n('internetToggleTetherA11yLabel');
250 case CrOnc.Type.CELLULAR: 279 case CrOnc.Type.CELLULAR:
251 return this.i18n('internetToggleMobileA11yLabel'); 280 return this.i18n('internetToggleMobileA11yLabel');
252 case CrOnc.Type.WI_FI: 281 case CrOnc.Type.WI_FI:
253 return this.i18n('internetToggleWiFiA11yLabel'); 282 return this.i18n('internetToggleWiFiA11yLabel');
254 case CrOnc.Type.WI_MAX: 283 case CrOnc.Type.WI_MAX:
255 return this.i18n('internetToggleWiMAXA11yLabel'); 284 return this.i18n('internetToggleWiMAXA11yLabel');
256 } 285 }
257 assertNotReached(); 286 assertNotReached();
258 return ''; 287 return '';
259 }, 288 },
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 } 427 }
399 if (state.Type == CrOnc.Type.VPN && 428 if (state.Type == CrOnc.Type.VPN &&
400 (!defaultNetwork || 429 (!defaultNetwork ||
401 defaultNetwork.ConnectionState != CrOnc.ConnectionState.CONNECTED)) { 430 defaultNetwork.ConnectionState != CrOnc.ConnectionState.CONNECTED)) {
402 return false; 431 return false;
403 } 432 }
404 return true; 433 return true;
405 }, 434 },
406 435
407 /** 436 /**
437 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState
438 * @param {!CrOnc.DeviceStateProperties|undefined} tetherDeviceState
439 * @return {boolean}
440 * @private
441 */
442 tetherToggleIsVisible_: function(deviceState, tetherDeviceState) {
443 return !!deviceState && deviceState.Type == CrOnc.Type.CELLULAR &&
444 !!tetherDeviceState;
445 },
446
447 /**
448 * @param {!CrOnc.DeviceStateProperties|undefined} deviceState
449 * @param {!CrOnc.DeviceStateProperties|undefined} tetherDeviceState
450 * @return {boolean}
451 * @private
452 */
453 tetherToggleIsEnabled_: function(deviceState, tetherDeviceState) {
454 return this.tetherToggleIsVisible_(deviceState, tetherDeviceState) &&
455 this.enableToggleIsEnabled_(tetherDeviceState) &&
456 tetherDeviceState.State != CrOnc.DeviceState.UNINITIALIZED;
457 },
458
459 /**
460 * @param {!Event} event
461 * @private
462 */
463 onTetherEnabledTap_: function(event) {
464 this.fire('device-enabled-toggled', {
465 enabled: !this.deviceIsEnabled_(this.tetherDeviceState),
466 type: CrOnc.Type.TETHER,
467 });
468 event.stopPropagation();
469 },
470
471 /**
408 * @param {*} lhs 472 * @param {*} lhs
409 * @param {*} rhs 473 * @param {*} rhs
410 * @return {boolean} 474 * @return {boolean}
411 */ 475 */
412 isEqual_: function(lhs, rhs) { 476 isEqual_: function(lhs, rhs) {
413 return lhs === rhs; 477 return lhs === rhs;
414 }, 478 },
415 }); 479 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698