No dual_mode on Win10+ shortcuts.
[chromium-blink-merge.git] / chrome / browser / resources / options / chromeos / vpn_providers.js
blob06da41b5339940a846dcf01029334353b6eca1f3
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
3 // found in the LICENSE file.
5 /**
6 * @fileoverview A singleton that keeps track of the VPN providers enabled in
7 * the primary user's profile.
8 */
10 cr.define('options', function() {
11 /**
12 * @constructor
14 function VPNProviders() {
17 cr.addSingletonGetter(VPNProviders);
19 VPNProviders.prototype = {
20 /**
21 * The VPN providers enabled in the primary user's profile. Each provider
22 * has a name. Third-party VPN providers additionally have an extension ID.
23 * @type {!Array<{name: string, extensionID: ?string}>}
24 * @private
26 providers_: [],
28 /**
29 * Observers who will be called when the list of VPN providers changes.
30 * @type {!Array<!function()>}
32 observers_: [],
34 /**
35 * The VPN providers enabled in the primary user's profile.
36 * @type {!Array<{name: string, extensionID: ?string}>}
38 get providers() {
39 return this.providers_;
41 set providers(providers) {
42 this.providers_ = providers;
43 for (var i = 0; i < this.observers_.length; ++i)
44 this.observers_[i]();
47 /**
48 * Adds an observer to be called when the list of VPN providers changes.
49 * @param {!function()} observer The observer to add.
50 * @private
52 addObserver_: function(observer) {
53 this.observers_.push(observer);
56 /**
57 * Formats a network name for display purposes. If the network belongs to
58 * a third-party VPN provider, the provider name is added to the network
59 * name.
60 * @param {cr.onc.OncData} onc ONC data describing this network.
61 * @return {string} The resulting display name.
62 * @private
64 formatNetworkName_: function(onc) {
65 var networkName = onc.getTranslatedValue('Name');
66 if (onc.getActiveValue('VPN.Type') != 'ThirdPartyVPN')
67 return networkName;
68 var extensionID = onc.getActiveValue('VPN.ThirdPartyVPN.ExtensionID');
69 for (var i = 0; i < this.providers_.length; ++i) {
70 if (extensionID == this.providers_[i].extensionID) {
71 return loadTimeData.getStringF('vpnNameTemplate',
72 this.providers_[i].name,
73 networkName);
76 return networkName;
80 /**
81 * Adds an observer to be called when the list of VPN providers changes. Note
82 * that an observer may in turn call setProviders() but should be careful not
83 * to get stuck in an infinite loop as every change to the list of VPN
84 * providers will cause the observers to be called again.
85 * @param {!function()} observer The observer to add.
87 VPNProviders.addObserver = function(observer) {
88 VPNProviders.getInstance().addObserver_(observer);
91 /**
92 * Returns the list of VPN providers enabled in the primary user's profile.
93 * @return {!Array<{name: string, extensionID: ?string}>} The list of VPN
94 * providers enabled in the primary user's profile.
96 VPNProviders.getProviders = function() {
97 return VPNProviders.getInstance().providers;
101 * Replaces the list of VPN providers enabled in the primary user's profile.
102 * @param {!Array<{name: string, extensionID: ?string}>} providers The list
103 * of VPN providers enabled in the primary user's profile.
105 VPNProviders.setProviders = function(providers) {
106 VPNProviders.getInstance().providers = providers;
110 * Formats a network name for display purposes. If the network belongs to a
111 * third-party VPN provider, the provider name is added to the network name.
112 * @param {cr.onc.OncData} onc ONC data describing this network.
113 * @return {string} The resulting display name.
115 VPNProviders.formatNetworkName = function(onc) {
116 return VPNProviders.getInstance().formatNetworkName_(onc);
119 // Export
120 return {
121 VPNProviders: VPNProviders