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.
6 * @fileoverview ONC network configuration support class. Wraps a dictionary
7 * object containing ONC managed or unmanaged dictionaries. Also provides
8 * special accessors for ONC properties. Used by consumers of the
9 * chrome.networkingPrivate API. See components/onc/docs/onc_spec.html.
11 Polymer('cr-onc-data', {
14 * ONC configuration property dictionary, e.g. the result of a
15 * chrome.networkingPrivate.getProperties() call.
18 * @type {chrome.networkingPrivate.NetworkStateProperties}
27 /** @type {chrome.networkingPrivate.NetworkStateProperties} */({});
30 /** @return {boolean} True if the network is connected. */
31 connected: function() {
32 return this.data.ConnectionState == CrOnc.ConnectionState.CONNECTED;
35 /** @return {boolean} True if the network is connecting. */
36 connecting: function() {
37 return this.data.ConnectionState == CrOnc.ConnectionState.CONNECTING;
40 /** @return {boolean} True if the network is disconnected. */
41 disconnected: function() {
42 return this.data.ConnectionState == CrOnc.ConnectionState.NOT_CONNECTED;
45 /** @return {number} The signal strength of the network. */
46 getStrength: function() {
47 var type = this.data.Type;
50 strength = this.data.WiFi ? this.data.WiFi.SignalStrength : 0;
51 else if (type == 'Cellular')
52 strength = this.data.Cellular ? this.data.Cellular.SignalStrength : 0;
53 else if (type == 'WiMAX')
54 strength = this.data.WiMAX ? this.data.WiMAX.SignalStrength : 0;
58 /** @return {CrOnc.Security} The ONC security type. */
59 getWiFiSecurity: function() {
60 return (this.data.WiFi && this.data.WiFi.Security) ?
61 this.data.WiFi.Security : CrOnc.Security.NONE;
64 /** @return {CrOnc.RoamingState} The ONC roaming state. */
65 getCellularRoamingState: function() {
66 return (this.data.Cellular && this.data.Cellular.RoamingState) ?
67 this.data.Cellular.RoamingState : CrOnc.RoamingState.UNKNOWN;
70 /** @return {CrOnc.NetworkTechnology} The ONC network technology. */
71 getCellularTechnology: function() {
72 return (this.data.Cellular && this.data.Cellular.NetworkTechnology) ?
73 this.data.Cellular.NetworkTechnology : CrOnc.NetworkTechnology.UNKNOWN;
77 // Temporary constructor method. TODO(stevenjb): Replace with proper
78 // construction after switching to Polymer 0.8.
80 var CrOncDataElement = {};
83 * Helper method to create and return a typed cr-onc-data Polymer element.
84 * Sets the data property of the element to |state|.
86 * @param {!chrome.networkingPrivate.NetworkStateProperties} state The network
88 * @return {!CrOncDataElement} A cr-onc-data element.
90 CrOncDataElement.create = function(state) {
91 var oncData = /** @type {!CrOncDataElement} */ (
92 document.createElement('cr-onc-data'));