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 | 6 * @fileoverview |
7 * 'settings-internet-page' is the settings page containing internet | 7 * 'settings-internet-page' is the settings page containing internet |
8 * settings. | 8 * settings. |
9 */ | 9 */ |
10 Polymer({ | 10 Polymer({ |
11 is: 'settings-internet-page', | 11 is: 'settings-internet-page', |
12 | 12 |
| 13 behaviors: [I18nBehavior], |
| 14 |
13 properties: { | 15 properties: { |
14 /** | 16 /** |
15 * Interface for networkingPrivate calls. May be overriden by tests. | 17 * Interface for networkingPrivate calls. May be overriden by tests. |
16 * @type {NetworkingPrivate} | 18 * @type {NetworkingPrivate} |
17 */ | 19 */ |
18 networkingPrivate: { | 20 networkingPrivate: { |
19 type: Object, | 21 type: Object, |
20 value: chrome.networkingPrivate, | 22 value: chrome.networkingPrivate, |
21 }, | 23 }, |
22 | 24 |
23 /** | 25 /** |
24 * The network type for the known networks subpage. | 26 * The network type for the known networks subpage. |
25 * @private | 27 * @private |
26 */ | 28 */ |
27 knownNetworksType_: String, | 29 knownNetworksType_: String, |
28 | 30 |
29 /** | 31 /** |
30 * Whether the 'Add connection' section is expanded. | 32 * Whether the 'Add connection' section is expanded. |
31 * @private | 33 * @private |
32 */ | 34 */ |
33 addConnectionExpanded_: { | 35 addConnectionExpanded_: { |
34 type: Boolean, | 36 type: Boolean, |
35 value: false, | 37 value: false, |
36 }, | 38 }, |
| 39 |
| 40 /** |
| 41 * List of third party VPN providers. |
| 42 * @type {!Array<!chrome.networkingPrivate.ThirdPartyVPNProperties>} |
| 43 * @private |
| 44 */ |
| 45 thirdPartyVpnProviders_: { |
| 46 type: Array, |
| 47 value: function() { |
| 48 return []; |
| 49 } |
| 50 }, |
| 51 }, |
| 52 |
| 53 /** @override */ |
| 54 attached: function() { |
| 55 chrome.management.onInstalled.addListener( |
| 56 this.onExtensionAdded_.bind(this)); |
| 57 chrome.management.onEnabled.addListener(this.onExtensionAdded_.bind(this)); |
| 58 chrome.management.onUninstalled.addListener( |
| 59 this.onExtensionRemoved_.bind(this)); |
| 60 chrome.management.onDisabled.addListener( |
| 61 this.onExtensionDisabled_.bind(this)); |
| 62 |
| 63 chrome.management.getAll(this.onGetAllExtensions_.bind(this)); |
| 64 }, |
| 65 |
| 66 /** @override */ |
| 67 detached: function() { |
| 68 chrome.management.onInstalled.removeListener( |
| 69 this.onExtensionAdded_.bind(this)); |
| 70 chrome.management.onEnabled.removeListener( |
| 71 this.onExtensionAdded_.bind(this)); |
| 72 chrome.management.onUninstalled.removeListener( |
| 73 this.onExtensionRemoved_.bind(this)); |
| 74 chrome.management.onDisabled.removeListener( |
| 75 this.onExtensionDisabled_.bind(this)); |
37 }, | 76 }, |
38 | 77 |
39 /** | 78 /** |
40 * @param {!{detail: !CrOnc.NetworkStateProperties}} event | 79 * @param {!{detail: !CrOnc.NetworkStateProperties}} event |
41 * @private | 80 * @private |
42 */ | 81 */ |
43 onShowDetail_: function(event) { | 82 onShowDetail_: function(event) { |
44 settings.navigateTo( | 83 settings.navigateTo( |
45 settings.Route.NETWORK_DETAIL, | 84 settings.Route.NETWORK_DETAIL, |
46 new URLSearchParams('guid=' + event.detail.GUID)); | 85 new URLSearchParams('guid=' + event.detail.GUID)); |
(...skipping 12 matching lines...) Expand all Loading... |
59 * Event triggered when the 'Add connections' div is tapped. | 98 * Event triggered when the 'Add connections' div is tapped. |
60 * @param {Event} event | 99 * @param {Event} event |
61 * @private | 100 * @private |
62 */ | 101 */ |
63 onExpandAddConnectionsTap_: function(event) { | 102 onExpandAddConnectionsTap_: function(event) { |
64 if (event.target.id == 'expandAddConnections') | 103 if (event.target.id == 'expandAddConnections') |
65 return; | 104 return; |
66 this.addConnectionExpanded_ = !this.addConnectionExpanded_; | 105 this.addConnectionExpanded_ = !this.addConnectionExpanded_; |
67 }, | 106 }, |
68 | 107 |
69 /*** @private */ | 108 /** @private */ |
70 onAddWiFiTap_: function() { | 109 onAddWiFiTap_: function() { |
71 chrome.send('addNetwork', [CrOnc.Type.WI_FI]); | 110 chrome.send('addNetwork', [CrOnc.Type.WI_FI]); |
72 }, | 111 }, |
73 | 112 |
74 /*** @private */ | 113 /** @private */ |
75 onAddVPNTap_: function() { | 114 onAddVPNTap_: function() { |
76 chrome.send('addNetwork', [CrOnc.Type.VPN]); | 115 chrome.send('addNetwork', [CrOnc.Type.VPN]); |
77 }, | 116 }, |
| 117 |
| 118 /** |
| 119 * @param {!{model: |
| 120 * !{item: !chrome.networkingPrivate.ThirdPartyVPNProperties}, |
| 121 * }} event |
| 122 * @private |
| 123 */ |
| 124 onAddThirdPartyVpnTap_: function(event) { |
| 125 let provider = event.model.item; |
| 126 chrome.send('addNetwork', [CrOnc.Type.VPN, provider.ExtensionID]); |
| 127 }, |
| 128 |
| 129 /** |
| 130 * chrome.management.getAll callback. |
| 131 * @param {!Array<!chrome.management.ExtensionInfo>} extensions |
| 132 * @private |
| 133 */ |
| 134 onGetAllExtensions_: function(extensions) { |
| 135 let vpnProviders = []; |
| 136 for (var extension of extensions) |
| 137 this.addVpnProvider_(vpnProviders, extension); |
| 138 this.thirdPartyVpnProviders_ = vpnProviders; |
| 139 }, |
| 140 |
| 141 /** |
| 142 * If |extension| is a third-party VPN provider, add it to |vpnProviders|. |
| 143 * @param {!Array<!chrome.networkingPrivate.ThirdPartyVPNProperties>} |
| 144 * vpnProviders |
| 145 * @param {!chrome.management.ExtensionInfo} extension |
| 146 * @private |
| 147 */ |
| 148 addVpnProvider_: function(vpnProviders, extension) { |
| 149 if (!extension.enabled || |
| 150 extension.permissions.indexOf('vpnProvider') == -1) { |
| 151 return; |
| 152 } |
| 153 if (vpnProviders.find(function(provider) { |
| 154 return provider.ExtensionID == extension.id; |
| 155 })) { |
| 156 return; |
| 157 } |
| 158 var newProvider = { |
| 159 ExtensionID: extension.id, |
| 160 ProviderName: extension.name, |
| 161 }; |
| 162 vpnProviders.push(newProvider); |
| 163 }, |
| 164 |
| 165 /** |
| 166 * chrome.management.onInstalled or onEnabled event. |
| 167 * @param {!chrome.management.ExtensionInfo} extension |
| 168 * @private |
| 169 */ |
| 170 onExtensionAdded_: function(extension) { |
| 171 this.addVpnProvider_(this.thirdPartyVpnProviders_, extension); |
| 172 }, |
| 173 |
| 174 /** |
| 175 * chrome.management.onUninstalled event. |
| 176 * @param {string} extensionId |
| 177 * @private |
| 178 */ |
| 179 onExtensionRemoved_: function(extensionId) { |
| 180 for (var i = 0; i < this.thirdPartyVpnProviders_.length; ++i) { |
| 181 var provider = this.thirdPartyVpnProviders_[i]; |
| 182 if (provider.ExtensionID == extensionId) { |
| 183 this.splice('thirdPartyVpnProviders_', i, 1); |
| 184 break; |
| 185 } |
| 186 } |
| 187 }, |
| 188 |
| 189 /** |
| 190 * chrome.management.onDisabled event. |
| 191 * @param {{id: string}} extension |
| 192 * @private |
| 193 */ |
| 194 onExtensionDisabled_: function(extension) { |
| 195 this.onExtensionRemoved_(extension.id); |
| 196 }, |
| 197 |
| 198 /** |
| 199 * @param {!chrome.networkingPrivate.ThirdPartyVPNProperties} provider |
| 200 * @return {string} |
| 201 */ |
| 202 getAddThirdParrtyVpnLabel_: function(provider) { |
| 203 return this.i18n('internetAddThirdPartyVPN', provider.ProviderName); |
| 204 } |
78 }); | 205 }); |
OLD | NEW |