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.
7 * 'cr-settings-internet-detail' is the settings subpage containing details
10 * @group Chrome Settings Elements
11 * @element cr-settings-internet-detail
15 /** @const */ var CARRIER_VERIZON
= 'Verizon Wireless';
18 is
: 'cr-settings-internet-detail-page',
28 value
: 'internet-detail',
41 * Whether the page is a subpage.
49 * Title for the page header and navigation menu.
54 return loadTimeData
.getString('internetDetailPageTitle');
59 * Reflects the selected settings page. We use this to extract guid from
60 * window.location.href when this page is navigated to. This is a
61 * workaround for a bug in the 1.0 version of more-routing where
62 * selected-params='{{params}}' is not correctly setting params in
63 * settings_main.html. TODO(stevenjb): Remove once more-routing is fixed.
68 observer
: 'selectedPageChanged_'
72 * Name of the 'core-icon' to show. TODO(stevenjb): Update this with the
73 * icon for the active internet connection.
77 value
: 'settings-ethernet',
82 * The network GUID to display details for.
87 observer
: 'guidChanged_',
91 * The current state for the network matching |guid|.
92 * @type {?CrOnc.NetworkStateProperties}
97 observer
: 'networkStateChanged_'
101 * The network AutoConnect state.
106 observer
: 'autoConnectChanged_'
110 * The network preferred state.
115 observer
: 'preferNetworkChanged_'
119 * The network IP Address.
127 * Object providing network type values for data binding.
134 CELLULAR
: CrOnc
.Type
.CELLULAR
,
135 ETHERNET
: CrOnc
.Type
.ETHERNET
,
137 WIFI
: CrOnc
.Type
.WIFI
,
138 WIMAX
: CrOnc
.Type
.WIMAX
,
145 * Listener function for chrome.networkingPrivate.onNetworksChanged event.
146 * @type {?function(!Array<string>)}
149 networksChangedListener_
: null,
152 attached: function() {
153 this.networksChangedListener_
= this.onNetworksChangedEvent_
.bind(this);
154 chrome
.networkingPrivate
.onNetworksChanged
.addListener(
155 this.networksChangedListener_
);
159 detached: function() {
160 chrome
.networkingPrivate
.onNetworksChanged
.removeListener(
161 this.networksChangedListener_
);
165 * Polymer guid changed method.
167 guidChanged_: function() {
170 this.getNetworkDetails_();
174 * Polymer guid changed method. TODO(stevenjb): Remove, see TODO above.
176 selectedPageChanged_: function() {
177 if ((this.selectedPage
&& this.selectedPage
.PAGE_ID
) != this.PAGE_ID
)
179 var href
= window
.location
.href
;
180 var idx
= href
.lastIndexOf('/');
181 var guid
= href
.slice(idx
+ 1);
186 * Polymer networkState changed method.
188 networkStateChanged_: function() {
189 if (!this.networkState
)
192 // Update autoConnect if it has changed. Default value is false.
194 CrOnc
.getActiveTypeValue(this.networkState
, 'AutoConnect') || false;
195 if (autoConnect
!= this.autoConnect
)
196 this.autoConnect
= autoConnect
;
198 // Update preferNetwork if it has changed. Default value is false.
199 var preferNetwork
= this.networkState
.Priority
> 0;
200 if (preferNetwork
!= this.preferNetwork
)
201 this.preferNetwork
= preferNetwork
;
203 // Set the IPAddress property to the IPV4 Address.
204 var ipv4
= CrOnc
.getIPConfigForType(this.networkState
, CrOnc
.IPType
.IPV4
);
205 this.IPAddress
= (ipv4
&& ipv4
.IPAddress
) || '';
209 * Polymer autoConnect changed method.
211 autoConnectChanged_: function() {
212 if (!this.networkState
|| !this.guid
)
214 var onc
= {Type
: this.networkState
.Type
};
215 CrOnc
.setTypeProperty(onc
, 'AutoConnect', this.autoConnect
);
216 this.setNetworkProperties_(onc
);
220 * Polymer preferNetwork changed method.
222 preferNetworkChanged_: function() {
223 if (!this.networkState
|| !this.guid
)
225 var priority
= this.preferNetwork
? 1 : 0;
226 this.setNetworkProperties_(
227 {Type
: this.networkState
.Type
, Priority
: priority
});
231 * networkingPrivate.onNetworksChanged event callback.
232 * @param {!Array<string>} networkIds The list of changed network GUIDs.
235 onNetworksChangedEvent_: function(networkIds
) {
236 if (networkIds
.indexOf(this.guid
) != -1)
237 this.getNetworkDetails_();
241 * Calls networkingPrivate.getProperties for this.guid.
244 getNetworkDetails_: function() {
247 chrome
.networkingPrivate
.getProperties(
248 this.guid
, this.getPropertiesCallback_
.bind(this));
252 * networkingPrivate.getProperties callback.
253 * @param {!CrOnc.NetworkStateProperties} state The network state properties.
256 getPropertiesCallback_: function(state
) {
257 this.networkState
= state
;
259 // If state becomes null (i.e. the network is no longer visible), close
261 MoreRouting
.navigateTo('internet');
266 * @param {!chrome.networkingPrivate.NetworkConfigProperties} onc The ONC
267 * network properties.
270 setNetworkProperties_: function(onc
) {
273 chrome
.networkingPrivate
.setProperties(this.guid
, onc
, function() {
274 if (chrome
.runtime
.lastError
) {
275 // An error typically indicates invalid input; request the properties
276 // to update any invalid fields.
277 this.getNetworkDetails_();
283 * @param {?CrOnc.NetworkStateProperties} state The network state properties.
284 * @return {string} The text to display for the network name.
287 getStateName_: function(state
) {
288 return (state
&& state
.Name
) || '';
292 * @param {?CrOnc.NetworkStateProperties} state The network state properties.
293 * @return {string} The text to display for the network name.
296 getStateClass_: function(state
) {
297 return this.isConnectedState_(state
) ? 'connected' : '';
301 * @param {?CrOnc.NetworkStateProperties} state The network state properties.
302 * @return {string} The text to display for the network connection state.
305 getStateText_: function(state
) {
306 // TODO(stevenjb): Localize.
307 return (state
&& state
.ConnectionState
) || '';
311 * @param {?CrOnc.NetworkStateProperties} state The network state properties.
312 * @return {boolean} True if the state is connected.
315 isConnectedState_: function(state
) {
316 return state
&& state
.ConnectionState
== CrOnc
.ConnectionState
.CONNECTED
;
320 * @param {?CrOnc.NetworkStateProperties} state The network state properties.
321 * @return {boolean} Whether or not to show the 'Connect' button.
324 showConnect_: function(state
) {
325 return state
&& state
.Type
!= CrOnc
.Type
.ETHERNET
&&
326 state
.ConnectionState
== CrOnc
.ConnectionState
.NOT_CONNECTED
;
330 * @param {?CrOnc.NetworkStateProperties} state The network state properties.
331 * @return {boolean} Whether or not to show the 'Activate' buttonb.
334 showActivate_: function(state
) {
335 if (!state
|| state
.Type
!= CrOnc
.Type
.CELLULAR
)
337 var activation
= state
.Cellular
.ActivationState
;
338 return activation
== CrOnc
.ActivationState
.NOT_ACTIVATED
||
339 activation
== CrOnc
.ActivationState
.PARTIALLY_ACTIVATED
;
343 * @param {?CrOnc.NetworkStateProperties} state The network state properties.
344 * @return {boolean} Whether or not to show the 'View Account' button.
347 showViewAccount_: function(state
) {
348 // Show either the 'Activate' or the 'View Account' button.
349 if (this.showActivate_())
352 if (!state
|| state
.Type
!= CrOnc
.Type
.CELLULAR
|| !state
.Cellular
)
354 var cellular
= state
.Cellular
;
356 // Only show if online payment URL is provided or the carrier is Verizon.
357 if (cellular
.Carrier
!= CARRIER_VERIZON
) {
358 var paymentUrl
= cellular
.PaymentPortal
&& cellular
.PaymentPortal
.Url
;
363 // Only show for connected networks or LTE networks with a valid MDN.
364 if (!this.isConnectedState_(state
)) {
365 var technology
= cellular
.NetworkTechnology
;
366 if (technology
!= CrOnc
.NetworkTechnology
.LTE
&&
367 technology
!= CrOnc
.NetworkTechnology
.LTEAdvanced
) {
378 * @return {boolean} Whether or not to enable the network connect button.
381 enableConnect_: function(state
) {
382 if (!state
|| !this.showConnect_(state
))
384 if (state
.Type
== CrOnc
.Type
.CELLULAR
&& CrOnc
.isSimLocked(state
))
386 // TODO(stevenjb): For VPN, check connected state of any network.
391 * @param {?CrOnc.NetworkStateProperties} state The network state properties.
392 * @return {boolean} Whether or not to show the 'Disconnect' button.
395 showDisconnect_: function(state
) {
396 return state
&& state
.Type
!= CrOnc
.Type
.ETHERNET
&&
397 state
.ConnectionState
!= CrOnc
.ConnectionState
.NOT_CONNECTED
;
401 * Callback when the Connect button is clicked.
404 onConnectClicked_: function() {
405 chrome
.networkingPrivate
.startConnect(this.guid
);
409 * Callback when the Disconnect button is clicked.
412 onDisconnectClicked_: function() {
413 chrome
.networkingPrivate
.startDisconnect(this.guid
);
417 * Callback when the Activate button is clicked.
420 onActivateClicked_: function() {
421 chrome
.networkingPrivate
.startActivate(this.guid
);
425 * Callback when the View Account button is clicked.
428 onViewAccountClicked_: function() {
429 // startActivate() will show the account page for activated networks.
430 chrome
.networkingPrivate
.startActivate(this.guid
);
434 * Event triggered for elements associated with network properties.
435 * @param {!{detail: { field: string, value: Object}}} event
438 onNetworkPropertyChange_: function(event
) {
439 var field
= event
.detail
.field
;
440 var value
= event
.detail
.value
;
441 if (field
== 'APN') {
442 this.setNetworkProperties_({Cellular
: {APN
: value
}});
445 if (field
== 'SIMLockStatus') {
446 this.setNetworkProperties_({Cellular
: {SIMLockStatus
: value
}});
452 * Event triggered when the IP Config or NameServers element changes.
453 * @param {!{detail: {field: string,
454 * value: string|CrOnc.IPConfigProperties}}} event
455 * The network-ip-config or network-nameservers change event.
458 onIPConfigChange_: function(event
) {
459 if (!this.networkState
)
462 var field
= event
.detail
.field
;
463 var value
= event
.detail
.value
;
465 // Set just the IP Config properties that need to change.
467 if (field
== 'IPAddressConfigType') {
468 if (onc
.IPAddressConfigType
== value
)
470 onc
.IPAddressConfigType
= value
;
471 } else if (field
== 'NameServersConfigType') {
472 if (onc
.NameServersConfigType
== value
)
474 onc
.NameServersConfigType
= value
;
475 } else if (field
== 'StaticIPConfig') {
476 if (onc
.IPAddressConfigType
== CrOnc
.IPConfigType
.STATIC
&&
477 onc
.StaticIPConfig
) {
479 for (var key
in value
) {
480 if (onc
.StaticIPConfig
[key
] != value
[key
]) {
488 onc
.IPAddressConfigType
= CrOnc
.IPConfigType
.STATIC
;
489 onc
.StaticIPConfig
= onc
.StaticIPConfig
|| {};
491 onc
.StaticIPConfig
[key
] = value
[key
];
492 } else if (field
== 'NameServers') {
493 if (onc
.NameServersConfigType
== CrOnc
.IPConfigType
.STATIC
&&
494 onc
.StaticIPConfig
&& onc
.StaticIPConfig
.NameServers
== value
) {
497 onc
.NameServersConfigType
= CrOnc
.IPConfigType
.STATIC
;
498 onc
.StaticIPConfig
= onc
.StaticIPConfig
|| {};
499 onc
.StaticIPConfig
.NameServers
= value
;
501 console
.error('Unexpected change field: ' + field
);
504 // setValidStaticIPConfig will fill in any other properties from
505 // networkState. This is necessary since we update IP Address and
506 // NameServers independently.
507 CrOnc
.setValidStaticIPConfig(onc
, this.networkState
);
508 this.setNetworkProperties_(onc
);
512 * Event triggered when the Proxy configuration element changes.
513 * @param {!{detail: {field: string, value: CrOnc.ProxySettings}}} event
514 * The network-proxy change event.
517 onProxyChange_: function(event
) {
518 var field
= event
.detail
.field
;
519 var value
= event
.detail
.value
;
520 if (field
!= 'ProxySettings')
522 this.setNetworkProperties_({ProxySettings
: value
});
526 * @param {?CrOnc.NetworkStateProperties} state The network state properties.
527 * @return {boolean} True if the shared message should be shown.
530 showShared_: function(state
) {
532 (state
.Source
== 'Device' || state
.Source
== 'DevicePolicy');
536 * @param {?CrOnc.NetworkStateProperties} state The network state properties.
537 * @return {boolean} True if the AutoConnect checkbox should be shown.
540 showAutoConnect_: function(state
) {
541 return state
&& state
.Type
!= CrOnc
.Type
.ETHERNET
;
545 * @param {?CrOnc.NetworkStateProperties} state The network state properties.
546 * @return {boolean} True if the prefer network checkbox should be shown.
549 showPreferNetwork_: function(state
) {
550 return state
&& state
.Type
!= CrOnc
.Type
.ETHERNET
;
554 * @param {?CrOnc.NetworkStateProperties} state The network state properties.
555 * @return {!Array<string>} The fields to display in the info section.
558 getInfoFields_: function(state
) {
559 /** @type {!Array<string>} */ var fields
= [];
563 if (state
.Type
== CrOnc
.Type
.CELLULAR
) {
564 fields
.push('Cellular.ActivationState',
565 'Cellular.RoamingState',
566 'RestrictedConnectivity',
567 'Cellular.ServingOperator.Name');
569 if (state
.Type
== CrOnc
.Type
.VPN
) {
570 fields
.push('VPN.Host', 'VPN.Type');
571 if (state
.VPN
.Type
== 'OpenVPN')
572 fields
.push('VPN.OpenVPN.Username');
573 else if (state
.VPN
.Type
== 'L2TP-IPsec')
574 fields
.push('VPN.L2TP.Username');
575 // TODO(stevenjb): ThirdPartyVPN
577 if (state
.Type
== CrOnc
.Type
.WIFI
)
578 fields
.push('RestrictedConnectivity');
579 if (state
.Type
== CrOnc
.Type
.WIMAX
) {
580 fields
.push('RestrictedConnectivity', 'WiMAX.EAP.Identity');
586 * @param {?CrOnc.NetworkStateProperties} state The network state properties.
587 * @return {!Array<string>} The fields to display in the Advanced section.
590 getAdvancedFields_: function(state
) {
591 /** @type {!Array<string>} */ var fields
= [];
594 fields
.push('MacAddress');
595 if (state
.Type
== CrOnc
.Type
.CELLULAR
) {
596 fields
.push('Cellular.Carrier',
598 'Cellular.NetworkTechnology',
599 'Cellular.ServingOperator.Code');
601 if (state
.Type
== CrOnc
.Type
.WIFI
) {
602 fields
.push('WiFi.SSID',
605 'WiFi.SignalStrength',
608 if (state
.Type
== CrOnc
.Type
.WIMAX
)
609 fields
.push('WiFi.SignalStrength');
614 * @param {?CrOnc.NetworkStateProperties} state The network state properties.
615 * @return {!Array<string>} The fields to display in the device section.
618 getDeviceFields_: function(state
) {
619 /** @type {!Array<string>} */ var fields
= [];
622 if (state
.Type
== CrOnc
.Type
.CELLULAR
) {
623 fields
.push('Cellular.HomeProvider.Name',
624 'Cellular.HomeProvider.Country',
625 'Cellular.HomeProvider.Code',
626 'Cellular.Manufacturer',
628 'Cellular.FirmwareRevision',
629 'Cellular.HardwareRevision',
637 'Cellular.PRLVersion');
643 * @param {?CrOnc.NetworkStateProperties} state The network state properties.
644 * @return {boolean} True if there are any advanced fields to display.
647 hasAdvancedOrDeviceFields_: function(state
) {
648 return this.getAdvancedFields_(state
).length
> 0 || this.hasDeviceFields_();
652 * @param {?CrOnc.NetworkStateProperties} state The network state properties.
653 * @return {boolean} True if there are any device fields to display.
656 hasDeviceFields_: function(state
) {
657 var fields
= this.getDeviceFields_(state
);
658 return fields
.length
> 0;
662 * @param {?CrOnc.NetworkStateProperties} state The network state properties.
663 * @return {boolean} True if the network section should be shown.
666 hasNetworkSection_: function(state
) {
667 return state
&& state
.Type
!= CrOnc
.Type
.VPN
;
671 * @param {?CrOnc.NetworkStateProperties} state The network state properties.
672 * @param {string} type The network type.
673 * @return {boolean} True if the network type matches 'type'.
676 isType_: function(state
, type
) {
677 return state
&& state
.Type
== type
;
681 * @param {?CrOnc.NetworkStateProperties} state The network state properties.
682 * @return {boolean} True if the Cellular SIM section should be shown.
685 showCellularSim_: function(state
) {
686 return state
&& state
.Type
== 'Cellular' && state
.Cellular
&&
687 state
.Cellular
.Family
== 'GSM';