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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 } | 142 } |
143 | 143 |
144 /** | 144 /** |
145 * @param {string} action An action to send to coreOptionsUserMetricsAction. | 145 * @param {string} action An action to send to coreOptionsUserMetricsAction. |
146 */ | 146 */ |
147 function sendChromeMetricsAction(action) { | 147 function sendChromeMetricsAction(action) { |
148 chrome.send('coreOptionsUserMetricsAction', [action]); | 148 chrome.send('coreOptionsUserMetricsAction', [action]); |
149 } | 149 } |
150 | 150 |
151 /** | 151 /** |
| 152 * @param {string} servicePath The network service path. |
| 153 */ |
| 154 function showDetails(servicePath) { |
| 155 // TODO(stevenjb): chrome.networkingPrivate.getManagedProperties |
| 156 // (Note: we will need to provide DetailsInternetPage.initializeDetailsPage |
| 157 // as the callback). |
| 158 chrome.send('getManagedProperties', [servicePath]); |
| 159 } |
| 160 |
| 161 /** |
152 * Decorate an element as a NetworkListItem. | 162 * Decorate an element as a NetworkListItem. |
153 * @param {!Element} el The element to decorate. | 163 * @param {!Element} el The element to decorate. |
154 */ | 164 */ |
155 NetworkListItem.decorate = function(el) { | 165 NetworkListItem.decorate = function(el) { |
156 el.__proto__ = NetworkListItem.prototype; | 166 el.__proto__ = NetworkListItem.prototype; |
157 el.decorate(); | 167 el.decorate(); |
158 }; | 168 }; |
159 | 169 |
160 NetworkListItem.prototype = { | 170 NetworkListItem.prototype = { |
161 __proto__: ListItem.prototype, | 171 __proto__: ListItem.prototype, |
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 return networkButtons; | 704 return networkButtons; |
695 }, | 705 }, |
696 | 706 |
697 /** | 707 /** |
698 * Adds a menu item for showing network details. | 708 * Adds a menu item for showing network details. |
699 * @param {!Element} parent The parent element. | 709 * @param {!Element} parent The parent element. |
700 * @param {Object} data Description of the network. | 710 * @param {Object} data Description of the network. |
701 * @private | 711 * @private |
702 */ | 712 */ |
703 createNetworkOptionsCallback_: function(parent, data) { | 713 createNetworkOptionsCallback_: function(parent, data) { |
| 714 var servicePath = data.servicePath; |
704 var menuItem = createCallback_(parent, | 715 var menuItem = createCallback_(parent, |
705 data, | 716 data, |
706 getNetworkName(data), | 717 getNetworkName(data), |
707 'showDetails', | 718 showDetails.bind(null, servicePath), |
708 data.iconURL); | 719 data.iconURL); |
709 if (data.policyManaged) | 720 if (data.policyManaged) |
710 menuItem.appendChild(new ManagedNetworkIndicator()); | 721 menuItem.appendChild(new ManagedNetworkIndicator()); |
711 if (data.ConnectionState == 'Connected' || | 722 if (data.ConnectionState == 'Connected' || |
712 data.ConnectionState == 'Connecting') { | 723 data.ConnectionState == 'Connecting') { |
713 var label = menuItem.getElementsByClassName( | 724 var label = menuItem.getElementsByClassName( |
714 'network-menu-item-label')[0]; | 725 'network-menu-item-label')[0]; |
715 label.classList.add('active-network'); | 726 label.classList.add('active-network'); |
716 } | 727 } |
717 } | 728 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 if (this.data.policyManaged) | 760 if (this.data.policyManaged) |
750 this.showManagedNetworkIndicator(); | 761 this.showManagedNetworkIndicator(); |
751 }, | 762 }, |
752 }; | 763 }; |
753 | 764 |
754 /** | 765 /** |
755 * Adds a command to a menu for modifying network settings. | 766 * Adds a command to a menu for modifying network settings. |
756 * @param {!Element} menu Parent menu. | 767 * @param {!Element} menu Parent menu. |
757 * @param {Object} data Description of the network. | 768 * @param {Object} data Description of the network. |
758 * @param {!string} label Display name for the menu item. | 769 * @param {!string} label Display name for the menu item. |
759 * @param {?(string|!Function)} command Callback function or name | 770 * @param {!Function} command Callback function. |
760 * of the command for |networkCommand|. | |
761 * @param {string=} opt_iconURL Optional URL to an icon for the menu item. | 771 * @param {string=} opt_iconURL Optional URL to an icon for the menu item. |
762 * @return {!Element} The created menu item. | 772 * @return {!Element} The created menu item. |
763 * @private | 773 * @private |
764 */ | 774 */ |
765 function createCallback_(menu, data, label, command, opt_iconURL) { | 775 function createCallback_(menu, data, label, command, opt_iconURL) { |
766 var button = menu.ownerDocument.createElement('div'); | 776 var button = menu.ownerDocument.createElement('div'); |
767 button.className = 'network-menu-item'; | 777 button.className = 'network-menu-item'; |
768 | 778 |
769 var buttonIcon = menu.ownerDocument.createElement('div'); | 779 var buttonIcon = menu.ownerDocument.createElement('div'); |
770 buttonIcon.className = 'network-menu-item-icon'; | 780 buttonIcon.className = 'network-menu-item-icon'; |
771 button.appendChild(buttonIcon); | 781 button.appendChild(buttonIcon); |
772 if (opt_iconURL) | 782 if (opt_iconURL) |
773 buttonIcon.style.backgroundImage = url(opt_iconURL); | 783 buttonIcon.style.backgroundImage = url(opt_iconURL); |
774 | 784 |
775 var buttonLabel = menu.ownerDocument.createElement('span'); | 785 var buttonLabel = menu.ownerDocument.createElement('span'); |
776 buttonLabel.className = 'network-menu-item-label'; | 786 buttonLabel.className = 'network-menu-item-label'; |
777 buttonLabel.textContent = label; | 787 buttonLabel.textContent = label; |
778 button.appendChild(buttonLabel); | 788 button.appendChild(buttonLabel); |
779 var callback = null; | 789 var callback = null; |
780 if (typeof command == 'string') { | 790 if (command != null) { |
781 var type = data.Type; | |
782 var path = data.servicePath; | |
783 callback = function() { | |
784 chrome.send('networkCommand', [type, path, command]); | |
785 closeMenu_(); | |
786 }; | |
787 } else if (command != null) { | |
788 if (data) { | 791 if (data) { |
789 callback = function() { | 792 callback = function() { |
790 (/** @type {Function} */(command))(data); | 793 (/** @type {Function} */(command))(data); |
791 closeMenu_(); | 794 closeMenu_(); |
792 }; | 795 }; |
793 } else { | 796 } else { |
794 callback = function() { | 797 callback = function() { |
795 (/** @type {Function} */(command))(); | 798 (/** @type {Function} */(command))(); |
796 closeMenu_(); | 799 closeMenu_(); |
797 }; | 800 }; |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1026 cellularSimLockType_ = data.cellularSimLockType; | 1029 cellularSimLockType_ = data.cellularSimLockType; |
1027 wimaxAvailable_ = data.wimaxAvailable; | 1030 wimaxAvailable_ = data.wimaxAvailable; |
1028 wimaxEnabled_ = data.wimaxEnabled; | 1031 wimaxEnabled_ = data.wimaxEnabled; |
1029 | 1032 |
1030 // Only show Ethernet control if connected. | 1033 // Only show Ethernet control if connected. |
1031 var ethernetConnection = getConnection_(data.wiredList); | 1034 var ethernetConnection = getConnection_(data.wiredList); |
1032 if (ethernetConnection) { | 1035 if (ethernetConnection) { |
1033 var type = String('Ethernet'); | 1036 var type = String('Ethernet'); |
1034 var path = ethernetConnection.servicePath; | 1037 var path = ethernetConnection.servicePath; |
1035 var ethernetOptions = function() { | 1038 var ethernetOptions = function() { |
1036 chrome.send('networkCommand', [type, path, 'showDetails']); | 1039 showDetails(path); |
1037 }; | 1040 }; |
1038 networkList.update( | 1041 networkList.update( |
1039 { key: 'Ethernet', | 1042 { key: 'Ethernet', |
1040 subtitle: loadTimeData.getString('OncConnectionStateConnected'), | 1043 subtitle: loadTimeData.getString('OncConnectionStateConnected'), |
1041 iconURL: ethernetConnection.iconURL, | 1044 iconURL: ethernetConnection.iconURL, |
1042 command: ethernetOptions, | 1045 command: ethernetOptions, |
1043 policyManaged: ethernetConnection.policyManaged } | 1046 policyManaged: ethernetConnection.policyManaged } |
1044 ); | 1047 ); |
1045 } else { | 1048 } else { |
1046 networkList.deleteItem('Ethernet'); | 1049 networkList.deleteItem('Ethernet'); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 * @param {string} type An ONC network type | 1230 * @param {string} type An ONC network type |
1228 * @return {function()} The created callback. | 1231 * @return {function()} The created callback. |
1229 * @private | 1232 * @private |
1230 */ | 1233 */ |
1231 function createAddConnectionCallback_(type) { | 1234 function createAddConnectionCallback_(type) { |
1232 return function() { | 1235 return function() { |
1233 if (type == 'WiFi') | 1236 if (type == 'WiFi') |
1234 sendChromeMetricsAction('Options_NetworkJoinOtherWifi'); | 1237 sendChromeMetricsAction('Options_NetworkJoinOtherWifi'); |
1235 else if (type == 'VPN') | 1238 else if (type == 'VPN') |
1236 sendChromeMetricsAction('Options_NetworkJoinOtherVPN'); | 1239 sendChromeMetricsAction('Options_NetworkJoinOtherVPN'); |
1237 chrome.send('networkCommand', [type, '', 'add']); | 1240 chrome.send('addConnection', [type]); |
1238 }; | 1241 }; |
1239 } | 1242 } |
1240 | 1243 |
1241 /** | 1244 /** |
1242 * Whether the Network list is disabled. Only used for display purpose. | 1245 * Whether the Network list is disabled. Only used for display purpose. |
1243 */ | 1246 */ |
1244 cr.defineProperty(NetworkList, 'disabled', cr.PropertyKind.BOOL_ATTR); | 1247 cr.defineProperty(NetworkList, 'disabled', cr.PropertyKind.BOOL_ATTR); |
1245 | 1248 |
1246 // Export | 1249 // Export |
1247 return { | 1250 return { |
1248 NetworkList: NetworkList | 1251 NetworkList: NetworkList |
1249 }; | 1252 }; |
1250 }); | 1253 }); |
OLD | NEW |