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

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: Rebase 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|.
137 * Note: this only looks at top level entries, so if a dictionary is
138 * updated the entire dictionary is written over. TODO(stevenjb):
139 * eliminate this function when |data_| contains only ONC entries and
140 * any updates consist of complete ONC dictionaries.
141 * @param {Object} update Dictionary containing the updated properties.
142 */
143 updateData: function(update) {
144 for (var prop in update) {
145 if (prop in this.data_)
146 this.data_[prop] = update[prop];
147 }
148 },
149
150 /**
138 * Get the effective value from a Managed property ONC dictionary. 151 * Get the effective value from a Managed property ONC dictionary.
139 * @param {object} property The managed property ONC dictionary. 152 * @param {object} property The managed property ONC dictionary.
140 * @return {*} The effective value or undefined. 153 * @return {*} The effective value or undefined.
141 * @private 154 * @private
142 */ 155 */
143 getEffectiveValueFromProperty_: function(property) { 156 getEffectiveValueFromProperty_: function(property) {
144 if ('Effective' in property) { 157 if ('Effective' in property) {
145 var effective = property.Effective; 158 var effective = property.Effective;
146 if (effective in property) 159 if (effective in property)
147 return property[effective]; 160 return property[effective];
148 } 161 }
149 return undefined; 162 return undefined;
150 } 163 }
151 }; 164 };
152 165
153 return { 166 return {
154 OncData: OncData 167 OncData: OncData
155 }; 168 };
156 }); 169 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698