Chromium Code Reviews| Index: chrome/browser/resources/options/chromeos/vpn_providers.js |
| diff --git a/chrome/browser/resources/options/chromeos/vpn_providers.js b/chrome/browser/resources/options/chromeos/vpn_providers.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ba056ecbead732267ee5f27f990762a0c6a43d3d |
| --- /dev/null |
| +++ b/chrome/browser/resources/options/chromeos/vpn_providers.js |
| @@ -0,0 +1,102 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +/** |
| + * @fileoverview A singleton that keeps track of the VPN providers enabled in |
| + * the primary user's profile. |
| + */ |
| + |
| +cr.define('options', function() { |
| + /** |
| + * @constructor |
| + */ |
| + function VPNProviders() { |
| + } |
| + |
| + cr.addSingletonGetter(VPNProviders); |
| + |
| + VPNProviders.prototype = { |
| + /** |
| + * The VPN providers enabled in the primary user's profile. This is a |
| + * mapping from provider ID to provider name. For third-party VPN providers, |
| + * the provider ID is an extension ID. For the built-in OpenVPN/L2TP |
| + * provider, the ID is 'built-in'. |
| + * @type {Object.<string, string>} |
|
michaelpg
2015/03/16 05:45:20
nit (25,62,70): dot (.) no longer required for arr
bartfab (slow)
2015/03/16 10:04:51
Done.
|
| + * @private |
| + */ |
| + providers_: {}, |
| + |
| + /** |
| + * Determines whether |provider_id| belongs to a third-party VPN provider. |
| + * @param {string} provider_id The VPN provider ID. |
| + * @return {boolean} True if the ID belongs to a third-party VPN provider. |
| + * @private |
| + */ |
| + isThirdPartyProvider_(provider_id) { |
| + return provider_id != 'built-in'; |
| + }, |
| + |
| + /** |
| + * Formats a network name for display purposes. If the network belongs to |
| + * a third-party VPN provider, the provider name is added to the network |
| + * name. |
| + * @param {string} provider_id The VPN provider ID for this network. |
| + * @param {string} network_name The network name. |
| + * @return {string} The resulting display name. |
| + * @private |
| + */ |
| + formatNetworkName_(provider_id, network_name) { |
| + if (!this.isThirdPartyProvider_(provider_id) || |
| + !(provider_id in this.providers_)) { |
| + return network_name; |
| + } |
| + return loadTimeData.getStringF('vpnNameTemplate', |
| + this.providers_[provider_id], |
| + network_name); |
| + }, |
| + }; |
| + |
| + /** |
| + * Returns the list of VPN providers enabled in the primary user's profile. |
| + * @return {Object.<string, string>} A mapping from VPN provider ID to name. |
| + */ |
| + VPNProviders.getProviders = function() { |
| + return VPNProviders.getInstance().providers_; |
| + }; |
| + |
| + /** |
| + * Replaces the list of VPN providers enabled in the primary user's profile. |
| + * @param {Object.<string, string>} providers A mapping from VPN provider ID |
| + * to name. |
| + */ |
| + VPNProviders.setProviders = function(providers) { |
| + VPNProviders.getInstance().providers_ = providers; |
| + }; |
| + |
| + /** |
| + * Determines whether |provider_id| belongs to a third-party VPN provider. |
| + * @param {string} provider_id The VPN provider ID. |
| + * @return {boolean} True if the ID belongs to a third-party VPN provider. |
| + */ |
| + VPNProviders.isThirdPartyProvider = function(provider_id) { |
| + return VPNProviders.getInstance().isThirdPartyProvider_(provider_id); |
| + }; |
| + |
| + /** |
| + * Formats a network name for display purposes. If the network belongs to a |
| + * third-party VPN provider, the provider name is added to the network name. |
| + * @param {string} provider_id The VPN provider ID for this network. |
| + * @param {string} network_name The network name. |
| + * @return {string} The resulting display name. |
| + */ |
| + VPNProviders.formatNetworkName = function(provider_id, network_name) { |
| + return VPNProviders.getInstance().formatNetworkName_(provider_id, |
| + network_name); |
| + }; |
| + |
| + // Export |
| + return { |
| + VPNProviders: VPNProviders |
| + }; |
| +}); |