Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(886)

Side by Side Diff: chrome/browser/resources/options/chromeos/onc_data.js

Issue 547703004: Some JS cleanup, including proper ownership of ONC properties. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue_279351_internet_options_8b
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 ONC Data support class. Wraps a dictionary object containing 6 * @fileoverview ONC Data support class. Wraps a dictionary object containing
7 * ONC managed or unmanaged dictionaries. Supports nested dictionaries, 7 * ONC managed or unmanaged dictionaries. Supports nested dictionaries,
8 * e.g. data.getManagedProperty('VPN.Type'). 8 * e.g. data.getManagedProperty('VPN.Type').
9 */ 9 */
10 cr.define('cr.onc', function() { 10 cr.define('cr.onc', function() {
11 'use strict'; 11 'use strict';
12 12
13 function OncData(data) { 13 function OncData(data) {
14 this.data_ = data; 14 this.data_ = data;
15 // For convenience set 'type' to the active 'Type' value.
16 this.type = this.getActiveValue('Type');
17 } 15 }
18 16
19 OncData.prototype = { 17 OncData.prototype = {
20 18
21 /** 19 /**
22 * Returns either a managed property dictionary or an unmanaged value. 20 * Returns either a managed property dictionary or an unmanaged value.
23 * @param {string} key The property key. 21 * @param {string} key The property key.
24 * @return {*} The property value or dictionary if it exists, otherwise 22 * @return {*} The property value or dictionary if it exists, otherwise
25 * undefined. 23 * undefined.
26 */ 24 */
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 * loadTimeData. If no translation exists, returns the untranslated value. 95 * loadTimeData. If no translation exists, returns the untranslated value.
98 * @param {string} key The property key. 96 * @param {string} key The property key.
99 * @return {*} The translation if available or the value if not. 97 * @return {*} The translation if available or the value if not.
100 */ 98 */
101 getTranslatedValue: function(key) { 99 getTranslatedValue: function(key) {
102 var value = this.getActiveValue(key); 100 var value = this.getActiveValue(key);
103 if (typeof value != 'string') 101 if (typeof value != 'string')
104 return value; 102 return value;
105 var oncString = 'Onc' + key + value; 103 var oncString = 'Onc' + key + value;
106 // Handle special cases 104 // Handle special cases
107 if (key == 'Name' && this.type == 'Ethernet') 105 if (key == 'Name' && this.getActiveValue('Type') == 'Ethernet')
108 return loadTimeData.getString('ethernetName'); 106 return loadTimeData.getString('ethernetName');
109 if (key == 'VPN.Type' && value == 'L2TP-IPsec') { 107 if (key == 'VPN.Type' && value == 'L2TP-IPsec') {
110 var auth = this.getActiveValue('VPN.IPsec.AuthenticationType'); 108 var auth = this.getActiveValue('VPN.IPsec.AuthenticationType');
111 if (auth != undefined) 109 if (auth != undefined)
112 oncString += auth; 110 oncString += auth;
113 } 111 }
114 oncString = oncString.replace(/\./g, '-'); 112 oncString = oncString.replace(/\./g, '-');
115 if (loadTimeData.valueExists(oncString)) 113 if (loadTimeData.valueExists(oncString))
116 return loadTimeData.getString(oncString); 114 return loadTimeData.getString(oncString);
117 return value; 115 return value;
(...skipping 10 matching lines...) Expand all
128 return undefined; 126 return undefined;
129 if (property['UserEditable']) 127 if (property['UserEditable'])
130 return property['UserPolicy']; 128 return property['UserPolicy'];
131 if (property['DeviceEditable']) 129 if (property['DeviceEditable'])
132 return property['DevicePolicy']; 130 return property['DevicePolicy'];
133 // No value recommended by policy. 131 // No value recommended by policy.
134 return undefined; 132 return undefined;
135 }, 133 },
136 134
137 /** 135 /**
136 * Updates the properties of |data_| from the properties in |update|.
pneubeck (no reviews) 2014/09/08 09:18:00 not sure whether that has the intended effect. IIU
stevenjb 2014/09/08 19:43:12 Eventually this should go away, we really shouldn'
137 * @param {object} update Dictionary containing the updated properties.
138 */
139 updateData: function(update) {
140 for (var prop in update) {
141 if (prop in this.data_)
142 this.data_[prop] = update[prop];
143 }
144 },
145
146 /**
138 * Get the effective value from a Managed property ONC dictionary. 147 * Get the effective value from a Managed property ONC dictionary.
139 * @param {object} property The managed property ONC dictionary. 148 * @param {object} property The managed property ONC dictionary.
140 * @return {*} The effective value or undefined. 149 * @return {*} The effective value or undefined.
141 * @private 150 * @private
142 */ 151 */
143 getEffectiveValueFromProperty_: function(property) { 152 getEffectiveValueFromProperty_: function(property) {
144 if ('Effective' in property) { 153 if ('Effective' in property) {
145 var effective = property.Effective; 154 var effective = property.Effective;
146 if (effective in property) 155 if (effective in property)
147 return property[effective]; 156 return property[effective];
148 } 157 }
149 return undefined; 158 return undefined;
150 } 159 }
151 }; 160 };
152 161
153 return { 162 return {
154 OncData: OncData 163 OncData: OncData
155 }; 164 };
156 }); 165 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698