OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 ONC network configuration support class. Wraps a dictionary | 6 * @fileoverview ONC network configuration support class. Wraps a dictionary |
7 * object containing ONC managed or unmanaged dictionaries. Also provides | 7 * object containing ONC managed or unmanaged dictionaries. Also provides |
8 * special accessors for ONC properties. See cr-onc-types for ONC types, | 8 * special accessors for ONC properties. Used by consumers of the |
9 * e.g. CrOnc.NetworkConfigType. Used by consumers of the | |
10 * chrome.networkingPrivate API. See components/onc/docs/onc_spec.html. | 9 * chrome.networkingPrivate API. See components/onc/docs/onc_spec.html. |
11 */ | 10 */ |
12 Polymer('cr-onc-data', { | 11 Polymer('cr-onc-data', { |
13 publish: { | 12 publish: { |
14 /** | 13 /** |
15 * ONC configuration property dictionary, e.g. the result of a | 14 * ONC configuration property dictionary, e.g. the result of a |
16 * chrome.networkingPrivate.getProperties() call. | 15 * chrome.networkingPrivate.getProperties() call. |
17 * | 16 * |
18 * @attribute data | 17 * @attribute data |
19 * @type CrOnc.NetworkConfigType | 18 * @type chrome.networkingPrivate.NetworkStateProperties |
20 * @default null | 19 * @default null |
21 */ | 20 */ |
22 data: null, | 21 data: null, |
23 }, | 22 }, |
24 | 23 |
25 /** @override */ | 24 /** @override */ |
26 created: function() { | 25 created: function() { |
27 this.data = /** @type {CrOnc.NetworkConfigType} */({}); | 26 this.data = |
27 /** @type {chrome.networkingPrivate.NetworkStateProperties} */({}); | |
28 }, | 28 }, |
29 | 29 |
30 /** @return {boolean} True if the network is connected. */ | 30 /** @return {boolean} True if the network is connected. */ |
31 connected: function() { | 31 connected: function() { |
32 return this.data.ConnectionState == CrOnc.ConnectionState.CONNECTED; | 32 return this.data.ConnectionState == |
33 chrome.networkingPrivate.ConnectionStateType.Connected; | |
michaelpg
2015/03/31 19:18:46
4 spaces 33, 39
| |
33 }, | 34 }, |
34 | 35 |
35 /** @return {boolean} True if the network is connecting. */ | 36 /** @return {boolean} True if the network is connecting. */ |
36 connecting: function() { | 37 connecting: function() { |
37 return this.data.ConnectionState == CrOnc.ConnectionState.CONNECTING; | 38 return this.data.ConnectionState == |
39 chrome.networkingPrivate.ConnectionStateType.Connecting; | |
38 }, | 40 }, |
39 | 41 |
40 /** @return {number} The signal strength of the network. */ | 42 /** @return {number} The signal strength of the network. */ |
41 getStrength: function() { | 43 getStrength: function() { |
42 var type = this.data.Type; | 44 var type = this.data.Type; |
43 var strength = 0; | 45 var strength = 0; |
44 if (type == 'WiFi') | 46 if (type == 'WiFi') |
45 strength = this.data.WiFi ? this.data.WiFi.SignalStrength : 0; | 47 strength = this.data.WiFi ? this.data.WiFi.SignalStrength : 0; |
46 else if (type == 'Cellular') | 48 else if (type == 'Cellular') |
47 strength = this.data.Cellular ? this.data.Cellular.SignalStrength : 0; | 49 strength = this.data.Cellular ? this.data.Cellular.SignalStrength : 0; |
48 else if (type == 'WiMAX') | 50 else if (type == 'WiMAX') |
49 strength = this.data.WiMAX ? this.data.WiMAX.SignalStrength : 0; | 51 strength = this.data.WiMAX ? this.data.WiMAX.SignalStrength : 0; |
50 return strength; | 52 return strength; |
51 }, | 53 }, |
52 | 54 |
53 /** @return {CrOnc.Security} The ONC security type. */ | 55 /** @return {DOMString} The ONC security type. */ |
54 getWiFiSecurity: function() { | 56 getWiFiSecurity: function() { |
55 return (this.data.WiFi && this.data.WiFi.Security) ? | 57 return (this.data.WiFi && this.data.WiFi.Security) ? |
56 this.data.WiFi.Security : CrOnc.Security.NONE; | 58 this.data.WiFi.Security : 'None'; |
57 }, | 59 }, |
58 | 60 |
59 /** @return {CrOnc.RoamingState} The ONC roaming state. */ | 61 /** @return {DOMString} The ONC roaming state. */ |
60 getCellularRoamingState: function() { | 62 getCellularRoamingState: function() { |
61 return (this.data.Cellular && this.data.Cellular.RoamingState) ? | 63 return (this.data.Cellular && this.data.Cellular.RoamingState) ? |
62 this.data.Cellular.RoamingState : CrOnc.RoamingState.UNKNOWN; | 64 this.data.Cellular.RoamingState : 'Unknown'; |
63 }, | 65 }, |
64 | 66 |
65 /** @return {CrOnc.NetworkTechnology} The ONC network technology. */ | 67 /** @return {DOMString} The ONC network technology. */ |
66 getCellularTechnology: function() { | 68 getCellularTechnology: function() { |
67 return (this.data.Cellular && this.data.Cellular.NetworkTechnology) ? | 69 return (this.data.Cellular && this.data.Cellular.NetworkTechnology) ? |
68 this.data.Cellular.NetworkTechnology : CrOnc.NetworkTechnology.UNKNOWN; | 70 this.data.Cellular.NetworkTechnology : 'Unknown'; |
69 } | 71 } |
70 }); | 72 }); |
71 | 73 |
72 // Temporary constructor method. TODO(stevenjb): Replace with proper | 74 // Temporary constructor method. TODO(stevenjb): Replace with proper |
73 // construction after switching to Polymer 0.8. | 75 // construction after switching to Polymer 0.8. |
74 | 76 |
75 var CrOncDataElement = {}; | 77 var CrOncDataElement = {}; |
76 | 78 |
77 /** | 79 /** |
78 * Helper method to create and return a typed cr-onc-data Polymer element. | 80 * Helper method to create and return a typed cr-onc-data Polymer element. |
79 * Sets the data property of the element to |state|. | 81 * Sets the data property of the element to |state|. |
80 * | 82 * |
81 * @param {!CrOnc.NetworkConfigType} state The network state properties. | 83 * @param {!chrome.networkingPrivate.NetworkStateProperties} state The network |
84 * state properties. | |
82 * @return {!CrOncDataElement} A cr-onc-data element. | 85 * @return {!CrOncDataElement} A cr-onc-data element. |
83 */ | 86 */ |
84 CrOncDataElement.create = function(state) { | 87 CrOncDataElement.create = function(state) { |
85 var oncData = /** @type {!CrOncDataElement} */ ( | 88 var oncData = /** @type {!CrOncDataElement} */ ( |
86 document.createElement('cr-onc-data')); | 89 document.createElement('cr-onc-data')); |
87 oncData.data = state; | 90 oncData.data = state; |
88 return oncData; | 91 return oncData; |
89 }; | 92 }; |
OLD | NEW |