OLD | NEW |
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 * @typedef {{ | 6 * @typedef {{ |
7 * ConnectionState: string, | 7 * ConnectionState: string, |
8 * iconURL: string, | 8 * iconURL: string, |
9 * policyManaged: boolean, | 9 * policyManaged: boolean, |
10 * servicePath: string | 10 * servicePath: string |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 | 103 |
104 /** | 104 /** |
105 * Indicates if mobile data roaming is enabled. | 105 * Indicates if mobile data roaming is enabled. |
106 * @type {boolean} | 106 * @type {boolean} |
107 * @private | 107 * @private |
108 */ | 108 */ |
109 var enableDataRoaming_ = false; | 109 var enableDataRoaming_ = false; |
110 | 110 |
111 /** | 111 /** |
112 * Icon to use when not connected to a particular type of network. | 112 * Icon to use when not connected to a particular type of network. |
113 * @type {!Object.<string, string>} Mapping of network type to icon data url. | 113 * @type {!Object<string, string>} Mapping of network type to icon data url. |
114 * @private | 114 * @private |
115 */ | 115 */ |
116 var defaultIcons_ = {}; | 116 var defaultIcons_ = {}; |
117 | 117 |
118 /** | 118 /** |
119 * Returns the display name for 'network'. | 119 * Returns the display name for 'network'. |
120 * @param {Object} data The network data dictionary. | 120 * @param {Object} data The network data dictionary. |
121 */ | 121 */ |
122 function getNetworkName(data) { | 122 function getNetworkName(data) { |
123 if (data.Type == 'Ethernet') | 123 if (data.Type == 'Ethernet') |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 NetworkListItem.decorate = function(el) { | 165 NetworkListItem.decorate = function(el) { |
166 el.__proto__ = NetworkListItem.prototype; | 166 el.__proto__ = NetworkListItem.prototype; |
167 el.decorate(); | 167 el.decorate(); |
168 }; | 168 }; |
169 | 169 |
170 NetworkListItem.prototype = { | 170 NetworkListItem.prototype = { |
171 __proto__: ListItem.prototype, | 171 __proto__: ListItem.prototype, |
172 | 172 |
173 /** | 173 /** |
174 * Description of the network group or control. | 174 * Description of the network group or control. |
175 * @type {Object.<string,Object>} | 175 * @type {Object<string,Object>} |
176 * @private | 176 * @private |
177 */ | 177 */ |
178 data_: null, | 178 data_: null, |
179 | 179 |
180 /** | 180 /** |
181 * Element for the control's subtitle. | 181 * Element for the control's subtitle. |
182 * @type {?Element} | 182 * @type {?Element} |
183 * @private | 183 * @private |
184 */ | 184 */ |
185 subtitle_: null, | 185 subtitle_: null, |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 if (rescan) { | 406 if (rescan) { |
407 // TODO(stevenjb): chrome.networkingPrivate.requestNetworkScan | 407 // TODO(stevenjb): chrome.networkingPrivate.requestNetworkScan |
408 chrome.send('requestNetworkScan'); | 408 chrome.send('requestNetworkScan'); |
409 } | 409 } |
410 } | 410 } |
411 }; | 411 }; |
412 | 412 |
413 /** | 413 /** |
414 * Creates a control for selecting or configuring a network connection based | 414 * Creates a control for selecting or configuring a network connection based |
415 * on the type of connection (e.g. wifi versus vpn). | 415 * on the type of connection (e.g. wifi versus vpn). |
416 * @param {{key: string, networkList: Array.<NetworkInfo>}} data Description | 416 * @param {{key: string, networkList: Array<NetworkInfo>}} data Description |
417 * of the network. | 417 * of the network. |
418 * @constructor | 418 * @constructor |
419 * @extends {NetworkMenuItem} | 419 * @extends {NetworkMenuItem} |
420 */ | 420 */ |
421 function NetworkSelectorItem(data) { | 421 function NetworkSelectorItem(data) { |
422 var el = new NetworkMenuItem(data); | 422 var el = new NetworkMenuItem(data); |
423 el.__proto__ = NetworkSelectorItem.prototype; | 423 el.__proto__ = NetworkSelectorItem.prototype; |
424 el.decorate(); | 424 el.decorate(); |
425 return el; | 425 return el; |
426 } | 426 } |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 discardOnClose = true; | 680 discardOnClose = true; |
681 } | 681 } |
682 } | 682 } |
683 oldMenu.data = {discardOnClose: discardOnClose}; | 683 oldMenu.data = {discardOnClose: discardOnClose}; |
684 return true; | 684 return true; |
685 }, | 685 }, |
686 | 686 |
687 /** | 687 /** |
688 * Extracts a mapping of network names to menu element and position. | 688 * Extracts a mapping of network names to menu element and position. |
689 * @param {!Element} menu The menu to process. | 689 * @param {!Element} menu The menu to process. |
690 * @return {Object.<string, ?{index: number, button: Element}>} | 690 * @return {Object<string, ?{index: number, button: Element}>} |
691 * Network mapping. | 691 * Network mapping. |
692 * @private | 692 * @private |
693 */ | 693 */ |
694 extractNetworkConnectButtons_: function(menu) { | 694 extractNetworkConnectButtons_: function(menu) { |
695 var group = menu.getElementsByClassName('network-menu-group')[0]; | 695 var group = menu.getElementsByClassName('network-menu-group')[0]; |
696 var networkButtons = {}; | 696 var networkButtons = {}; |
697 if (!group) | 697 if (!group) |
698 return networkButtons; | 698 return networkButtons; |
699 var buttons = group.getElementsByClassName('network-menu-item'); | 699 var buttons = group.getElementsByClassName('network-menu-item'); |
700 for (var i = 0; i < buttons.length; i++) { | 700 for (var i = 0; i < buttons.length; i++) { |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 for (var i = 0; i < size; i++) { | 901 for (var i = 0; i < size; i++) { |
902 var entry = this.dataModel.item(i); | 902 var entry = this.dataModel.item(i); |
903 if (entry.key == key) | 903 if (entry.key == key) |
904 return i; | 904 return i; |
905 } | 905 } |
906 return undefined; | 906 return undefined; |
907 }, | 907 }, |
908 | 908 |
909 /** | 909 /** |
910 * Updates a network control. | 910 * Updates a network control. |
911 * @param {Object.<string,string>} data Description of the entry. | 911 * @param {Object<string,string>} data Description of the entry. |
912 */ | 912 */ |
913 update: function(data) { | 913 update: function(data) { |
914 this.startBatchUpdates(); | 914 this.startBatchUpdates(); |
915 var index = this.indexOf(data.key); | 915 var index = this.indexOf(data.key); |
916 if (index == undefined) { | 916 if (index == undefined) { |
917 // Find reference position for adding the element. We cannot hide | 917 // Find reference position for adding the element. We cannot hide |
918 // individual list elements, thus we need to conditionally add or | 918 // individual list elements, thus we need to conditionally add or |
919 // remove elements and cannot rely on any element having a fixed index. | 919 // remove elements and cannot rely on any element having a fixed index. |
920 for (var i = 0; i < Constants.NETWORK_ORDER.length; i++) { | 920 for (var i = 0; i < Constants.NETWORK_ORDER.length; i++) { |
921 if (data.key == Constants.NETWORK_ORDER[i]) { | 921 if (data.key == Constants.NETWORK_ORDER[i]) { |
(...skipping 27 matching lines...) Expand all Loading... |
949 this.endBatchUpdates(); | 949 this.endBatchUpdates(); |
950 }, | 950 }, |
951 | 951 |
952 /** | 952 /** |
953 * @override | 953 * @override |
954 * @param {Object} entry | 954 * @param {Object} entry |
955 */ | 955 */ |
956 createItem: function(entry) { | 956 createItem: function(entry) { |
957 if (entry.networkList) | 957 if (entry.networkList) |
958 return new NetworkSelectorItem( | 958 return new NetworkSelectorItem( |
959 /** @type {{key: string, networkList: Array.<NetworkInfo>}} */( | 959 /** @type {{key: string, networkList: Array<NetworkInfo>}} */( |
960 entry)); | 960 entry)); |
961 if (entry.command) | 961 if (entry.command) |
962 return new NetworkButtonItem( | 962 return new NetworkButtonItem( |
963 /** @type {{key: string, subtitle: string, command: Function}} */( | 963 /** @type {{key: string, subtitle: string, command: Function}} */( |
964 entry)); | 964 entry)); |
965 if (entry.menu) | 965 if (entry.menu) |
966 return new NetworkMenuItem(entry); | 966 return new NetworkMenuItem(entry); |
967 assertNotReached(); | 967 assertNotReached(); |
968 }, | 968 }, |
969 | 969 |
(...skipping 18 matching lines...) Expand all Loading... |
988 var entry = this.dataModel.item(index); | 988 var entry = this.dataModel.item(index); |
989 entry.iconType = active ? 'control-active' : | 989 entry.iconType = active ? 'control-active' : |
990 'control-inactive'; | 990 'control-inactive'; |
991 this.update(entry); | 991 this.update(entry); |
992 } | 992 } |
993 } | 993 } |
994 }; | 994 }; |
995 | 995 |
996 /** | 996 /** |
997 * Sets the default icon to use for each network type if disconnected. | 997 * Sets the default icon to use for each network type if disconnected. |
998 * @param {!Object.<string, string>} data Mapping of network type to icon | 998 * @param {!Object<string, string>} data Mapping of network type to icon |
999 * data url. | 999 * data url. |
1000 */ | 1000 */ |
1001 NetworkList.setDefaultNetworkIcons = function(data) { | 1001 NetworkList.setDefaultNetworkIcons = function(data) { |
1002 defaultIcons_ = Object.create(data); | 1002 defaultIcons_ = Object.create(data); |
1003 }; | 1003 }; |
1004 | 1004 |
1005 /** | 1005 /** |
1006 * Chrome callback for updating network controls. | 1006 * Chrome callback for updating network controls. |
1007 * @param {{cellularAvailable: boolean, | 1007 * @param {{cellularAvailable: boolean, |
1008 * cellularEnabled: boolean, | 1008 * cellularEnabled: boolean, |
1009 * cellularSimAbsent: boolean, | 1009 * cellularSimAbsent: boolean, |
1010 * cellularSimLockType: string, | 1010 * cellularSimLockType: string, |
1011 * cellularSupportsScan: boolean, | 1011 * cellularSupportsScan: boolean, |
1012 * rememberedList: Array.<NetworkInfo>, | 1012 * rememberedList: Array<NetworkInfo>, |
1013 * vpnList: Array.<NetworkInfo>, | 1013 * vpnList: Array<NetworkInfo>, |
1014 * wifiAvailable: boolean, | 1014 * wifiAvailable: boolean, |
1015 * wifiEnabled: boolean, | 1015 * wifiEnabled: boolean, |
1016 * wimaxAvailable: boolean, | 1016 * wimaxAvailable: boolean, |
1017 * wimaxEnabled: boolean, | 1017 * wimaxEnabled: boolean, |
1018 * wiredList: Array.<NetworkInfo>, | 1018 * wiredList: Array<NetworkInfo>, |
1019 * wirelessList: Array.<NetworkInfo>}} data Description of available | 1019 * wirelessList: Array<NetworkInfo>}} data Description of available |
1020 * network devices and their corresponding state. | 1020 * network devices and their corresponding state. |
1021 */ | 1021 */ |
1022 NetworkList.refreshNetworkData = function(data) { | 1022 NetworkList.refreshNetworkData = function(data) { |
1023 var networkList = $('network-list'); | 1023 var networkList = $('network-list'); |
1024 networkList.startBatchUpdates(); | 1024 networkList.startBatchUpdates(); |
1025 cellularAvailable_ = data.cellularAvailable; | 1025 cellularAvailable_ = data.cellularAvailable; |
1026 cellularEnabled_ = data.cellularEnabled; | 1026 cellularEnabled_ = data.cellularEnabled; |
1027 cellularSupportsScan_ = data.cellularSupportsScan; | 1027 cellularSupportsScan_ = data.cellularSupportsScan; |
1028 cellularSimAbsent_ = data.cellularSimAbsent; | 1028 cellularSimAbsent_ = data.cellularSimAbsent; |
1029 cellularSimLockType_ = data.cellularSimLockType; | 1029 cellularSimLockType_ = data.cellularSimLockType; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 var menu = $(activeMenu_); | 1202 var menu = $(activeMenu_); |
1203 menu.hidden = true; | 1203 menu.hidden = true; |
1204 if (menu.data && menu.data.discardOnClose) | 1204 if (menu.data && menu.data.discardOnClose) |
1205 menu.parentNode.removeChild(menu); | 1205 menu.parentNode.removeChild(menu); |
1206 activeMenu_ = null; | 1206 activeMenu_ = null; |
1207 } | 1207 } |
1208 } | 1208 } |
1209 | 1209 |
1210 /** | 1210 /** |
1211 * Fetches the active connection. | 1211 * Fetches the active connection. |
1212 * @param {Array.<Object>} networkList List of networks. | 1212 * @param {Array<Object>} networkList List of networks. |
1213 * @return {Object} | 1213 * @return {Object} |
1214 * @private | 1214 * @private |
1215 */ | 1215 */ |
1216 function getConnection_(networkList) { | 1216 function getConnection_(networkList) { |
1217 if (!networkList) | 1217 if (!networkList) |
1218 return null; | 1218 return null; |
1219 for (var i = 0; i < networkList.length; i++) { | 1219 for (var i = 0; i < networkList.length; i++) { |
1220 var entry = networkList[i]; | 1220 var entry = networkList[i]; |
1221 if (entry.ConnectionState == 'Connected' || | 1221 if (entry.ConnectionState == 'Connected' || |
1222 entry.ConnectionState == 'Connecting') | 1222 entry.ConnectionState == 'Connecting') |
(...skipping 21 matching lines...) Expand all Loading... |
1244 /** | 1244 /** |
1245 * Whether the Network list is disabled. Only used for display purpose. | 1245 * Whether the Network list is disabled. Only used for display purpose. |
1246 */ | 1246 */ |
1247 cr.defineProperty(NetworkList, 'disabled', cr.PropertyKind.BOOL_ATTR); | 1247 cr.defineProperty(NetworkList, 'disabled', cr.PropertyKind.BOOL_ATTR); |
1248 | 1248 |
1249 // Export | 1249 // Export |
1250 return { | 1250 return { |
1251 NetworkList: NetworkList | 1251 NetworkList: NetworkList |
1252 }; | 1252 }; |
1253 }); | 1253 }); |
OLD | NEW |