| 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 cr.define('options.network', function() { | 5 cr.define('options.network', function() { |
| 6 var ArrayDataModel = cr.ui.ArrayDataModel; | 6 var ArrayDataModel = cr.ui.ArrayDataModel; |
| 7 var List = cr.ui.List; | 7 var List = cr.ui.List; |
| 8 var ListItem = cr.ui.ListItem; | 8 var ListItem = cr.ui.ListItem; |
| 9 var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; | 9 var ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; |
| 10 var Menu = cr.ui.Menu; | 10 var Menu = cr.ui.Menu; |
| (...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 discardOnClose = true; | 613 discardOnClose = true; |
| 614 } | 614 } |
| 615 } | 615 } |
| 616 oldMenu.data = {discardOnClose: discardOnClose}; | 616 oldMenu.data = {discardOnClose: discardOnClose}; |
| 617 return true; | 617 return true; |
| 618 }, | 618 }, |
| 619 | 619 |
| 620 /** | 620 /** |
| 621 * Extracts a mapping of network names to menu element and position. | 621 * Extracts a mapping of network names to menu element and position. |
| 622 * @param {!Element} menu The menu to process. | 622 * @param {!Element} menu The menu to process. |
| 623 * @return {Object.<string, Element>} Network mapping. | 623 * @return {Object.<string, {index: number, button: Element}>} |
| 624 * Network mapping. |
| 624 * @private | 625 * @private |
| 625 */ | 626 */ |
| 626 extractNetworkConnectButtons_: function(menu) { | 627 extractNetworkConnectButtons_: function(menu) { |
| 627 var group = menu.getElementsByClassName('network-menu-group')[0]; | 628 var group = menu.getElementsByClassName('network-menu-group')[0]; |
| 628 var networkButtons = {}; | 629 var networkButtons = {}; |
| 629 if (!group) | 630 if (!group) |
| 630 return networkButtons; | 631 return networkButtons; |
| 631 var buttons = group.getElementsByClassName('network-menu-item'); | 632 var buttons = group.getElementsByClassName('network-menu-item'); |
| 632 for (var i = 0; i < buttons.length; i++) { | 633 for (var i = 0; i < buttons.length; i++) { |
| 633 var label = buttons[i].data.label; | 634 var label = buttons[i].data.label; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 else if (this.data.iconType) | 690 else if (this.data.iconType) |
| 690 this.iconType = this.data.iconType; | 691 this.iconType = this.data.iconType; |
| 691 if (this.data.policyManaged) | 692 if (this.data.policyManaged) |
| 692 this.showManagedNetworkIndicator(); | 693 this.showManagedNetworkIndicator(); |
| 693 }, | 694 }, |
| 694 }; | 695 }; |
| 695 | 696 |
| 696 /** | 697 /** |
| 697 * Adds a command to a menu for modifying network settings. | 698 * Adds a command to a menu for modifying network settings. |
| 698 * @param {!Element} menu Parent menu. | 699 * @param {!Element} menu Parent menu. |
| 699 * @param {!Object} data Description of the network. | 700 * @param {Object} data Description of the network. |
| 700 * @param {!string} label Display name for the menu item. | 701 * @param {!string} label Display name for the menu item. |
| 701 * @param {?(string|!Function)} command Callback function or name | 702 * @param {?(string|!Function)} command Callback function or name |
| 702 * of the command for |networkCommand|. | 703 * of the command for |networkCommand|. |
| 703 * @param {string=} opt_iconURL Optional URL to an icon for the menu item. | 704 * @param {string=} opt_iconURL Optional URL to an icon for the menu item. |
| 704 * @return {!Element} The created menu item. | 705 * @return {!Element} The created menu item. |
| 705 * @private | 706 * @private |
| 706 */ | 707 */ |
| 707 function createCallback_(menu, data, label, command, opt_iconURL) { | 708 function createCallback_(menu, data, label, command, opt_iconURL) { |
| 708 var button = menu.ownerDocument.createElement('div'); | 709 var button = menu.ownerDocument.createElement('div'); |
| 709 button.className = 'network-menu-item'; | 710 button.className = 'network-menu-item'; |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 * Sets the default icon to use for each network type if disconnected. | 931 * Sets the default icon to use for each network type if disconnected. |
| 931 * @param {!Object.<string, string>} data Mapping of network type to icon | 932 * @param {!Object.<string, string>} data Mapping of network type to icon |
| 932 * data url. | 933 * data url. |
| 933 */ | 934 */ |
| 934 NetworkList.setDefaultNetworkIcons = function(data) { | 935 NetworkList.setDefaultNetworkIcons = function(data) { |
| 935 defaultIcons_ = Object.create(data); | 936 defaultIcons_ = Object.create(data); |
| 936 }; | 937 }; |
| 937 | 938 |
| 938 /** | 939 /** |
| 939 * Chrome callback for updating network controls. | 940 * Chrome callback for updating network controls. |
| 940 * @param {Object} data Description of available network devices and their | 941 * @param {{wiredList: Array, wirelessList: Array, vpnList: Array, |
| 941 * corresponding state. | 942 * rememberedList: Array, wifiAvailable: boolean, wifiEnabled: boolean, |
| 943 * wimaxAvailable: boolean, wimaxEnabled: boolean, |
| 944 * cellularAvailable: boolean, cellularEnabled: boolean, |
| 945 * cellularSupportsScan: boolean}} data Description of available network |
| 946 * devices and their corresponding state. |
| 942 */ | 947 */ |
| 943 NetworkList.refreshNetworkData = function(data) { | 948 NetworkList.refreshNetworkData = function(data) { |
| 944 var networkList = $('network-list'); | 949 var networkList = $('network-list'); |
| 945 networkList.startBatchUpdates(); | 950 networkList.startBatchUpdates(); |
| 946 cellularAvailable_ = data.cellularAvailable; | 951 cellularAvailable_ = data.cellularAvailable; |
| 947 cellularEnabled_ = data.cellularEnabled; | 952 cellularEnabled_ = data.cellularEnabled; |
| 948 cellularSupportsScan_ = data.cellularSupportsScan; | 953 cellularSupportsScan_ = data.cellularSupportsScan; |
| 949 wimaxAvailable_ = data.wimaxAvailable; | 954 wimaxAvailable_ = data.wimaxAvailable; |
| 950 wimaxEnabled_ = data.wimaxEnabled; | 955 wimaxEnabled_ = data.wimaxEnabled; |
| 951 | 956 |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1113 menu.hidden = true; | 1118 menu.hidden = true; |
| 1114 if (menu.data && menu.data.discardOnClose) | 1119 if (menu.data && menu.data.discardOnClose) |
| 1115 menu.parentNode.removeChild(menu); | 1120 menu.parentNode.removeChild(menu); |
| 1116 activeMenu_ = null; | 1121 activeMenu_ = null; |
| 1117 } | 1122 } |
| 1118 } | 1123 } |
| 1119 | 1124 |
| 1120 /** | 1125 /** |
| 1121 * Fetches the active connection. | 1126 * Fetches the active connection. |
| 1122 * @param {Array.<Object>} networkList List of networks. | 1127 * @param {Array.<Object>} networkList List of networks. |
| 1123 * @return {boolean} True if connected or connecting to a network. | 1128 * @return {Object} |
| 1124 * @private | 1129 * @private |
| 1125 */ | 1130 */ |
| 1126 function getConnection_(networkList) { | 1131 function getConnection_(networkList) { |
| 1127 if (!networkList) | 1132 if (!networkList) |
| 1128 return null; | 1133 return null; |
| 1129 for (var i = 0; i < networkList.length; i++) { | 1134 for (var i = 0; i < networkList.length; i++) { |
| 1130 var entry = networkList[i]; | 1135 var entry = networkList[i]; |
| 1131 if (entry.ConnectionState == 'Connected' || | 1136 if (entry.ConnectionState == 'Connected' || |
| 1132 entry.ConnectionState == 'Connecting') | 1137 entry.ConnectionState == 'Connecting') |
| 1133 return entry; | 1138 return entry; |
| 1134 } | 1139 } |
| 1135 return null; | 1140 return null; |
| 1136 } | 1141 } |
| 1137 | 1142 |
| 1138 /** | 1143 /** |
| 1139 * Create a callback function that adds a new connection of the given type. | 1144 * Create a callback function that adds a new connection of the given type. |
| 1140 * @param {string} type An ONC network type | 1145 * @param {string} type An ONC network type |
| 1141 * @return {function()} The created callback. | 1146 * @return {function()} The created callback. |
| 1142 * @private | 1147 * @private |
| 1143 */ | 1148 */ |
| 1144 function createAddConnectionCallback_(type) { | 1149 function createAddConnectionCallback_(type) { |
| 1145 return function() { | 1150 return function() { |
| 1146 chrome.send('networkCommand', [type, '', 'add']); | 1151 chrome.send('networkCommand', [type, '', 'add']); |
| 1147 }; | 1152 }; |
| 1148 } | 1153 } |
| 1149 | 1154 |
| 1150 /** | 1155 /** |
| 1151 * Whether the Network list is disabled. Only used for display purpose. | 1156 * Whether the Network list is disabled. Only used for display purpose. |
| 1152 * @type {boolean} | |
| 1153 */ | 1157 */ |
| 1154 cr.defineProperty(NetworkList, 'disabled', cr.PropertyKind.BOOL_ATTR); | 1158 cr.defineProperty(NetworkList, 'disabled', cr.PropertyKind.BOOL_ATTR); |
| 1155 | 1159 |
| 1156 // Export | 1160 // Export |
| 1157 return { | 1161 return { |
| 1158 NetworkList: NetworkList | 1162 NetworkList: NetworkList |
| 1159 }; | 1163 }; |
| 1160 }); | 1164 }); |
| OLD | NEW |