 Chromium Code Reviews
 Chromium Code Reviews Issue 1017443002:
  Allow users to add third-party VPNs from the settings page  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@f_3_460428_update_details_dialog
    
  
    Issue 1017443002:
  Allow users to add third-party VPNs from the settings page  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@f_3_460428_update_details_dialog| 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 A singleton that keeps track of the VPN providers enabled in | 6 * @fileoverview A singleton that keeps track of the VPN providers enabled in | 
| 7 * the primary user's profile. | 7 * the primary user's profile. | 
| 8 */ | 8 */ | 
| 9 | 9 | 
| 10 cr.define('options', function() { | 10 cr.define('options', function() { | 
| 11 // ID used for the built-in OpenVPN/L2TP VPN provider. This must be kept in | 11 // ID used for the built-in OpenVPN/L2TP VPN provider. This must be kept in | 
| 12 // sync with | 12 // sync with | 
| 13 //chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc. | 13 //chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc. | 
| 14 /** @const */ var BuiltInVPNProviderID = 'built-in'; | 14 /** @const */ var BuiltInVPNProviderID = 'built-in'; | 
| 15 | 15 | 
| 16 /** | 16 /** | 
| 17 * @constructor | 17 * @constructor | 
| 18 */ | 18 */ | 
| 19 function VPNProviders() { | 19 function VPNProviders() { | 
| 20 } | 20 } | 
| 21 | 21 | 
| 22 cr.addSingletonGetter(VPNProviders); | 22 cr.addSingletonGetter(VPNProviders); | 
| 23 | 23 | 
| 24 VPNProviders.prototype = { | 24 VPNProviders.prototype = { | 
| 25 /** | 25 /** | 
| 26 * The VPN providers enabled in the primary user's profile. This is a | 26 * The VPN providers enabled in the primary user's profile. This is a | 
| 27 * mapping from provider ID to provider name. For third-party VPN providers, | 27 * mapping from provider ID to provider name. For third-party VPN providers, | 
| 28 * the provider ID is an extension ID. For the built-in OpenVPN/L2TP | 28 * the provider ID is an extension ID. For the built-in OpenVPN/L2TP | 
| 29 * provider, the ID is 'built-in'. | 29 * provider, the ID is 'built-in'. | 
| 30 * @type {Object<string, string>} | 30 * @type {!Object<string, string>} | 
| 31 * @private | 31 * @private | 
| 32 */ | 32 */ | 
| 33 providers_: {}, | 33 providers_: {}, | 
| 34 | 34 | 
| 35 /** | 35 /** | 
| 36 * Observers who will be notified when the list of VPN providers changes. | |
| 37 * @type {!Array<!options.VPNProviders.Observer>} | |
| 38 */ | |
| 39 observers_: [], | |
| 40 | |
| 41 /** | |
| 42 * The VPN providers enabled in the primary user's profile. | |
| 43 * @type {!Object<string, string>} | |
| 44 */ | |
| 45 get providers() { | |
| 
michaelpg
2015/03/17 19:28:16
Why do we need these get/setters?
 
bartfab (slow)
2015/03/18 21:27:15
I had to convert |providers_| from a simple member
 | |
| 46 return this.providers_; | |
| 47 }, | |
| 48 set providers(providers) { | |
| 49 this.providers_ = providers; | |
| 50 for (var i = 0; i < this.observers_.length; ++i) | |
| 51 this.observers_[i].onVPNProvidersChanged(); | |
| 52 }, | |
| 53 | |
| 54 /** | |
| 55 * Adds an observer to be notified when the list of VPN providers changes. | |
| 56 * @param {!options.VPNProviders.Observer} observer The observer to add. | |
| 57 */ | |
| 58 addObserver: function(observer) { | |
| 59 this.observers_.push(observer); | |
| 60 }, | |
| 61 | |
| 62 /** | |
| 36 * Determines whether |provider_id| belongs to a third-party VPN provider. | 63 * Determines whether |provider_id| belongs to a third-party VPN provider. | 
| 37 * @param {string} provider_id The VPN provider ID. | 64 * @param {string} provider_id The VPN provider ID. | 
| 38 * @return {boolean} True if the ID belongs to a third-party VPN provider. | 65 * @return {boolean} True if the ID belongs to a third-party VPN provider. | 
| 39 * @private | 66 * @private | 
| 40 */ | 67 */ | 
| 41 isThirdPartyProvider_(provider_id) { | 68 isThirdPartyProvider_(provider_id) { | 
| 42 return provider_id != BuiltInVPNProviderID; | 69 return provider_id != BuiltInVPNProviderID; | 
| 43 }, | 70 }, | 
| 44 | 71 | 
| 45 /** | 72 /** | 
| (...skipping 10 matching lines...) Expand all Loading... | |
| 56 !(provider_id in this.providers_)) { | 83 !(provider_id in this.providers_)) { | 
| 57 return network_name; | 84 return network_name; | 
| 58 } | 85 } | 
| 59 return loadTimeData.getStringF('vpnNameTemplate', | 86 return loadTimeData.getStringF('vpnNameTemplate', | 
| 60 this.providers_[provider_id], | 87 this.providers_[provider_id], | 
| 61 network_name); | 88 network_name); | 
| 62 }, | 89 }, | 
| 63 }; | 90 }; | 
| 64 | 91 | 
| 65 /** | 92 /** | 
| 93 * Adds an observer to be notified when the list of VPN providers changes. | |
| 94 * @param {!options.VPNProviders.Observer} observer The observer to add. | |
| 95 */ | |
| 96 VPNProviders.addObserver = function(observer) { | |
| 97 VPNProviders.getInstance().addObserver(observer); | |
| 98 }; | |
| 99 | |
| 100 /** | |
| 66 * Returns the list of VPN providers enabled in the primary user's profile. | 101 * Returns the list of VPN providers enabled in the primary user's profile. | 
| 67 * @return {Object<string, string>} A mapping from VPN provider ID to name. | 102 * @return {Object<string, string>} A mapping from VPN provider ID to name. | 
| 68 */ | 103 */ | 
| 69 VPNProviders.getProviders = function() { | 104 VPNProviders.getProviders = function() { | 
| 70 return VPNProviders.getInstance().providers_; | 105 return VPNProviders.getInstance().providers; | 
| 71 }; | 106 }; | 
| 72 | 107 | 
| 73 /** | 108 /** | 
| 74 * Replaces the list of VPN providers enabled in the primary user's profile. | 109 * Replaces the list of VPN providers enabled in the primary user's profile. | 
| 75 * @param {Object<string, string>} providers A mapping from VPN provider ID | 110 * @param {Object<string, string>} providers A mapping from VPN provider ID | 
| 76 * to name. | 111 * to name. | 
| 77 */ | 112 */ | 
| 78 VPNProviders.setProviders = function(providers) { | 113 VPNProviders.setProviders = function(providers) { | 
| 79 VPNProviders.getInstance().providers_ = providers; | 114 VPNProviders.getInstance().providers = providers; | 
| 80 }; | 115 }; | 
| 81 | 116 | 
| 82 /** | 117 /** | 
| 83 * Determines whether |provider_id| belongs to a third-party VPN provider. | 118 * Determines whether |provider_id| belongs to a third-party VPN provider. | 
| 84 * @param {string} provider_id The VPN provider ID. | 119 * @param {string} provider_id The VPN provider ID. | 
| 85 * @return {boolean} True if the ID belongs to a third-party VPN provider. | 120 * @return {boolean} True if the ID belongs to a third-party VPN provider. | 
| 86 */ | 121 */ | 
| 87 VPNProviders.isThirdPartyProvider = function(provider_id) { | 122 VPNProviders.isThirdPartyProvider = function(provider_id) { | 
| 88 return VPNProviders.getInstance().isThirdPartyProvider_(provider_id); | 123 return VPNProviders.getInstance().isThirdPartyProvider_(provider_id); | 
| 89 }; | 124 }; | 
| 90 | 125 | 
| 91 /** | 126 /** | 
| 92 * Formats a network name for display purposes. If the network belongs to a | 127 * Formats a network name for display purposes. If the network belongs to a | 
| 93 * third-party VPN provider, the provider name is added to the network name. | 128 * third-party VPN provider, the provider name is added to the network name. | 
| 94 * @param {string} provider_id The VPN provider ID for this network. | 129 * @param {string} provider_id The VPN provider ID for this network. | 
| 95 * @param {string} network_name The network name. | 130 * @param {string} network_name The network name. | 
| 96 * @return {string} The resulting display name. | 131 * @return {string} The resulting display name. | 
| 97 */ | 132 */ | 
| 98 VPNProviders.formatNetworkName = function(provider_id, network_name) { | 133 VPNProviders.formatNetworkName = function(provider_id, network_name) { | 
| 99 return VPNProviders.getInstance().formatNetworkName_(provider_id, | 134 return VPNProviders.getInstance().formatNetworkName_(provider_id, | 
| 100 network_name); | 135 network_name); | 
| 101 }; | 136 }; | 
| 102 | 137 | 
| 138 /** | |
| 139 * An observer of VPNProviders. | |
| 140 * @interface | |
| 141 */ | |
| 142 VPNProviders.Observer = function() {}; | |
| 143 | |
| 144 VPNProviders.Observer.prototype = { | |
| 145 /** | |
| 146 * Called when the list of VPN providers changes. | |
| 147 */ | |
| 148 onVPNProvidersChanged: function() {}, | |
| 149 }; | |
| 150 | |
| 103 // Export | 151 // Export | 
| 104 return { | 152 return { | 
| 105 VPNProviders: VPNProviders | 153 VPNProviders: VPNProviders | 
| 106 }; | 154 }; | 
| 107 }); | 155 }); | 
| OLD | NEW |