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 /** |
| 6 * @typedef {{ |
| 7 * ConnectionState: string, |
| 8 * iconURL: string, |
| 9 * policyManaged: boolean, |
| 10 * servicePath: string |
| 11 * }} |
| 12 * @see chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc |
| 13 */ |
| 14 var NetworkInfo; |
| 15 |
5 cr.define('options.network', function() { | 16 cr.define('options.network', function() { |
6 var ArrayDataModel = cr.ui.ArrayDataModel; | 17 var ArrayDataModel = cr.ui.ArrayDataModel; |
7 var List = cr.ui.List; | 18 var List = cr.ui.List; |
8 var ListItem = cr.ui.ListItem; | 19 var ListItem = cr.ui.ListItem; |
9 var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; | 20 var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; |
10 var Menu = cr.ui.Menu; | 21 var Menu = cr.ui.Menu; |
11 var MenuItem = cr.ui.MenuItem; | 22 var MenuItem = cr.ui.MenuItem; |
12 var ControlledSettingIndicator = options.ControlledSettingIndicator; | 23 var ControlledSettingIndicator = options.ControlledSettingIndicator; |
13 | 24 |
14 /** | 25 /** |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 if (rescan) { | 396 if (rescan) { |
386 // TODO(stevenjb): chrome.networkingPrivate.requestNetworkScan | 397 // TODO(stevenjb): chrome.networkingPrivate.requestNetworkScan |
387 chrome.send('requestNetworkScan'); | 398 chrome.send('requestNetworkScan'); |
388 } | 399 } |
389 } | 400 } |
390 }; | 401 }; |
391 | 402 |
392 /** | 403 /** |
393 * Creates a control for selecting or configuring a network connection based | 404 * Creates a control for selecting or configuring a network connection based |
394 * on the type of connection (e.g. wifi versus vpn). | 405 * on the type of connection (e.g. wifi versus vpn). |
395 * @param {{key: string, networkList: Array.<Object>}} data Description of the | 406 * @param {{key: string, networkList: Array.<NetworkInfo>}} data Description |
396 * network. | 407 * of the network. |
397 * @constructor | 408 * @constructor |
398 * @extends {NetworkMenuItem} | 409 * @extends {NetworkMenuItem} |
399 */ | 410 */ |
400 function NetworkSelectorItem(data) { | 411 function NetworkSelectorItem(data) { |
401 var el = new NetworkMenuItem(data); | 412 var el = new NetworkMenuItem(data); |
402 el.__proto__ = NetworkSelectorItem.prototype; | 413 el.__proto__ = NetworkSelectorItem.prototype; |
403 el.decorate(); | 414 el.decorate(); |
404 return el; | 415 return el; |
405 } | 416 } |
406 | 417 |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 discardOnClose = true; | 658 discardOnClose = true; |
648 } | 659 } |
649 } | 660 } |
650 oldMenu.data = {discardOnClose: discardOnClose}; | 661 oldMenu.data = {discardOnClose: discardOnClose}; |
651 return true; | 662 return true; |
652 }, | 663 }, |
653 | 664 |
654 /** | 665 /** |
655 * Extracts a mapping of network names to menu element and position. | 666 * Extracts a mapping of network names to menu element and position. |
656 * @param {!Element} menu The menu to process. | 667 * @param {!Element} menu The menu to process. |
657 * @return {Object.<string, {index: number, button: Element}>} | 668 * @return {Object.<string, ?{index: number, button: Element}>} |
658 * Network mapping. | 669 * Network mapping. |
659 * @private | 670 * @private |
660 */ | 671 */ |
661 extractNetworkConnectButtons_: function(menu) { | 672 extractNetworkConnectButtons_: function(menu) { |
662 var group = menu.getElementsByClassName('network-menu-group')[0]; | 673 var group = menu.getElementsByClassName('network-menu-group')[0]; |
663 var networkButtons = {}; | 674 var networkButtons = {}; |
664 if (!group) | 675 if (!group) |
665 return networkButtons; | 676 return networkButtons; |
666 var buttons = group.getElementsByClassName('network-menu-item'); | 677 var buttons = group.getElementsByClassName('network-menu-item'); |
667 for (var i = 0; i < buttons.length; i++) { | 678 for (var i = 0; i < buttons.length; i++) { |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 this.dataModel.splice(referenceIndex + 1, 0, data); | 927 this.dataModel.splice(referenceIndex + 1, 0, data); |
917 } | 928 } |
918 } else { | 929 } else { |
919 var entry = this.dataModel.item(index); | 930 var entry = this.dataModel.item(index); |
920 data.sortIndex = entry.sortIndex; | 931 data.sortIndex = entry.sortIndex; |
921 this.dataModel.splice(index, 1, data); | 932 this.dataModel.splice(index, 1, data); |
922 } | 933 } |
923 this.endBatchUpdates(); | 934 this.endBatchUpdates(); |
924 }, | 935 }, |
925 | 936 |
926 /** @override */ | 937 /** |
| 938 * @override |
| 939 * @param {Object} entry |
| 940 */ |
927 createItem: function(entry) { | 941 createItem: function(entry) { |
928 if (entry.networkList) | 942 if (entry.networkList) |
929 return new NetworkSelectorItem(entry); | 943 return new NetworkSelectorItem( |
| 944 /** @type {{key: string, networkList: Array.<NetworkInfo>}} */( |
| 945 entry)); |
930 if (entry.command) | 946 if (entry.command) |
931 return new NetworkButtonItem(entry); | 947 return new NetworkButtonItem( |
| 948 /** @type {{key: string, subtitle: string, command: Function}} */( |
| 949 entry)); |
932 if (entry.menu) | 950 if (entry.menu) |
933 return new NetworkMenuItem(entry); | 951 return new NetworkMenuItem(entry); |
934 return undefined; | 952 return undefined; |
935 }, | 953 }, |
936 | 954 |
937 /** | 955 /** |
938 * Deletes an element from the list. | 956 * Deletes an element from the list. |
939 * @param {string} key Unique identifier for the element. | 957 * @param {string} key Unique identifier for the element. |
940 */ | 958 */ |
941 deleteItem: function(key) { | 959 deleteItem: function(key) { |
(...skipping 22 matching lines...) Expand all Loading... |
964 * Sets the default icon to use for each network type if disconnected. | 982 * Sets the default icon to use for each network type if disconnected. |
965 * @param {!Object.<string, string>} data Mapping of network type to icon | 983 * @param {!Object.<string, string>} data Mapping of network type to icon |
966 * data url. | 984 * data url. |
967 */ | 985 */ |
968 NetworkList.setDefaultNetworkIcons = function(data) { | 986 NetworkList.setDefaultNetworkIcons = function(data) { |
969 defaultIcons_ = Object.create(data); | 987 defaultIcons_ = Object.create(data); |
970 }; | 988 }; |
971 | 989 |
972 /** | 990 /** |
973 * Chrome callback for updating network controls. | 991 * Chrome callback for updating network controls. |
974 * @param {{wiredList: Array, wirelessList: Array, vpnList: Array, | 992 * @param {{wiredList: Array.<NetworkInfo>, wirelessList: Array.<NetworkInfo>, |
975 * rememberedList: Array, wifiAvailable: boolean, wifiEnabled: boolean, | 993 * vpnList: Array.<NetworkInfo>, rememberedList: Array.<NetworkInfo>, |
976 * wimaxAvailable: boolean, wimaxEnabled: boolean, | 994 * wifiAvailable: boolean, wifiEnabled: boolean, wimaxAvailable: boolean, |
977 * cellularAvailable: boolean, cellularEnabled: boolean, | 995 * wimaxEnabled: boolean, cellularAvailable: boolean, |
978 * cellularSupportsScan: boolean}} data Description of available network | 996 * cellularEnabled: boolean, cellularSupportsScan: boolean}} data |
979 * devices and their corresponding state. | 997 * Description of available network devices and their corresponding state. |
980 */ | 998 */ |
981 NetworkList.refreshNetworkData = function(data) { | 999 NetworkList.refreshNetworkData = function(data) { |
982 var networkList = $('network-list'); | 1000 var networkList = $('network-list'); |
983 networkList.startBatchUpdates(); | 1001 networkList.startBatchUpdates(); |
984 cellularAvailable_ = data.cellularAvailable; | 1002 cellularAvailable_ = data.cellularAvailable; |
985 cellularEnabled_ = data.cellularEnabled; | 1003 cellularEnabled_ = data.cellularEnabled; |
986 cellularSupportsScan_ = data.cellularSupportsScan; | 1004 cellularSupportsScan_ = data.cellularSupportsScan; |
987 cellularSimAbsent_ = data.cellularSimAbsent; | 1005 cellularSimAbsent_ = data.cellularSimAbsent; |
988 cellularSimLockType_ = data.cellularSimLockType; | 1006 cellularSimLockType_ = data.cellularSimLockType; |
989 wimaxAvailable_ = data.wimaxAvailable; | 1007 wimaxAvailable_ = data.wimaxAvailable; |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 /** | 1221 /** |
1204 * Whether the Network list is disabled. Only used for display purpose. | 1222 * Whether the Network list is disabled. Only used for display purpose. |
1205 */ | 1223 */ |
1206 cr.defineProperty(NetworkList, 'disabled', cr.PropertyKind.BOOL_ATTR); | 1224 cr.defineProperty(NetworkList, 'disabled', cr.PropertyKind.BOOL_ATTR); |
1207 | 1225 |
1208 // Export | 1226 // Export |
1209 return { | 1227 return { |
1210 NetworkList: NetworkList | 1228 NetworkList: NetworkList |
1211 }; | 1229 }; |
1212 }); | 1230 }); |
OLD | NEW |