| 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   /** |  11   /** | 
|  12    * @constructor |  12    * @constructor | 
|  13    */ |  13    */ | 
|  14   function VPNProviders() { |  14   function VPNProviders() { | 
|  15   } |  15   } | 
|  16  |  16  | 
|  17   cr.addSingletonGetter(VPNProviders); |  17   cr.addSingletonGetter(VPNProviders); | 
|  18  |  18  | 
|  19   VPNProviders.prototype = { |  19   VPNProviders.prototype = { | 
|  20     /** |  20     /** | 
|  21      * The VPN providers enabled in the primary user's profile. Each provider |  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. |  22      * has a name. Third-party VPN providers additionally have an extension ID. | 
|  23      * @type {!Array<{name: string, extensionID: ?string>}} |  23      * @type {!Array<{name: string, extensionID: ?string}>} | 
|  24      * @private |  24      * @private | 
|  25      */ |  25      */ | 
|  26     providers_: [], |  26     providers_: [], | 
|  27  |  27  | 
|  28     /** |  28     /** | 
|  29      * Formats a network name for display purposes. If the network belongs to |  29      * Formats a network name for display purposes. If the network belongs to | 
|  30      * a third-party VPN provider, the provider name is added to the network |  30      * a third-party VPN provider, the provider name is added to the network | 
|  31      * name. |  31      * name. | 
|  32      * @param {cr.onc.OncData} onc ONC data describing this network. |  32      * @param {cr.onc.OncData} onc ONC data describing this network. | 
|  33      * @return {string} The resulting display name. |  33      * @return {string} The resulting display name. | 
|  34      * @private |  34      * @private | 
|  35      */ |  35      */ | 
|  36     formatNetworkName_(onc) { |  36     formatNetworkName_: function(onc) { | 
|  37       var networkName = onc.getTranslatedValue('Name'); |  37       var networkName = onc.getTranslatedValue('Name'); | 
|  38       if (onc.getActiveValue('VPN.Type') != 'ThirdPartyVPN') |  38       if (onc.getActiveValue('VPN.Type') != 'ThirdPartyVPN') | 
|  39         return networkName; |  39         return networkName; | 
|  40       var extensionID = onc.getActiveValue('VPN.ThirdPartyVPN.ExtensionID'); |  40       var extensionID = onc.getActiveValue('VPN.ThirdPartyVPN.ExtensionID'); | 
|  41       for (var i = 0; i < this.providers_.length; ++i) { |  41       for (var i = 0; i < this.providers_.length; ++i) { | 
|  42         if (extensionID == this.providers_[i].extensionID) { |  42         if (extensionID == this.providers_[i].extensionID) { | 
|  43           return loadTimeData.getStringF('vpnNameTemplate', |  43           return loadTimeData.getStringF('vpnNameTemplate', | 
|  44                                          this.providers_[i].name, |  44                                          this.providers_[i].name, | 
|  45                                          networkName); |  45                                          networkName); | 
|  46         } |  46         } | 
|  47       } |  47       } | 
|  48       return networkName; |  48       return networkName; | 
|  49     }, |  49     }, | 
|  50   }; |  50   }; | 
|  51  |  51  | 
|  52   /** |  52   /** | 
|  53    * Returns the list of VPN providers enabled in the primary user's profile. |  53    * Returns the list of VPN providers enabled in the primary user's profile. | 
|  54    * @return {!Array<{name: string, extensionID: ?string>}} The list of VPN |  54    * @return {!Array<{name: string, extensionID: ?string}>} The list of VPN | 
|  55    *     providers enabled in the primary user's profile. |  55    *     providers enabled in the primary user's profile. | 
|  56    */ |  56    */ | 
|  57   VPNProviders.getProviders = function() { |  57   VPNProviders.getProviders = function() { | 
|  58     return VPNProviders.getInstance().providers_; |  58     return VPNProviders.getInstance().providers_; | 
|  59   }; |  59   }; | 
|  60  |  60  | 
|  61   /** |  61   /** | 
|  62    * Replaces the list of VPN providers enabled in the primary user's profile. |  62    * Replaces the list of VPN providers enabled in the primary user's profile. | 
|  63    * @param {!Array<{name: string, extensionID: ?string>}} providers The list |  63    * @param {!Array<{name: string, extensionID: ?string}>} providers The list | 
|  64    *     of VPN providers enabled in the primary user's profile. |  64    *     of VPN providers enabled in the primary user's profile. | 
|  65    */ |  65    */ | 
|  66   VPNProviders.setProviders = function(providers) { |  66   VPNProviders.setProviders = function(providers) { | 
|  67     VPNProviders.getInstance().providers_ = providers; |  67     VPNProviders.getInstance().providers_ = providers; | 
|  68   }; |  68   }; | 
|  69  |  69  | 
|  70   /** |  70   /** | 
|  71    * Formats a network name for display purposes. If the network belongs to a |  71    * Formats a network name for display purposes. If the network belongs to a | 
|  72    * third-party VPN provider, the provider name is added to the network name. |  72    * third-party VPN provider, the provider name is added to the network name. | 
|  73    * @param {cr.onc.OncData} onc ONC data describing this network. |  73    * @param {cr.onc.OncData} onc ONC data describing this network. | 
|  74    * @return {string} The resulting display name. |  74    * @return {string} The resulting display name. | 
|  75    */ |  75    */ | 
|  76   VPNProviders.formatNetworkName = function(onc) { |  76   VPNProviders.formatNetworkName = function(onc) { | 
|  77     return VPNProviders.getInstance().formatNetworkName_(onc); |  77     return VPNProviders.getInstance().formatNetworkName_(onc); | 
|  78   }; |  78   }; | 
|  79  |  79  | 
|  80   // Export |  80   // Export | 
|  81   return { |  81   return { | 
|  82     VPNProviders: VPNProviders |  82     VPNProviders: VPNProviders | 
|  83   }; |  83   }; | 
|  84 }); |  84 }); | 
| OLD | NEW |