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

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

Issue 570503002: Compile chrome://settings, part 6 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@H_options_errors_4
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 /** 13 /**
14 * @constructor 14 * @constructor
15 */ 15 */
16 function OncData(data) { 16 function OncData(data) {
17 this.data_ = data; 17 this.data_ = data;
18 } 18 }
19 19
20 OncData.prototype = { 20 OncData.prototype = {
21 21
22 /** 22 /**
23 * Returns either a managed property dictionary or an unmanaged value. 23 * Returns either a managed property dictionary or an unmanaged value.
24 * @param {string} key The property key. 24 * @param {string} key The property key.
25 * @return {*} The property value or dictionary if it exists, otherwise 25 * @return {(Object|string|undefined)} The property value or dictionary if
26 * undefined. 26 * it exists, otherwise undefined.
27 */ 27 */
28 getManagedProperty: function(key) { 28 getManagedProperty: function(key) {
29 var data = this.data_; 29 var data = this.data_;
30 while (true) { 30 while (true) {
31 var index = key.indexOf('.'); 31 var index = key.indexOf('.');
32 if (index < 0) 32 if (index < 0)
33 break; 33 break;
34 var keyComponent = key.substr(0, index); 34 var keyComponent = key.substr(0, index);
35 if (!(keyComponent in data)) 35 if (!(keyComponent in data))
36 return undefined; 36 return undefined;
37 data = data[keyComponent]; 37 data = data[keyComponent];
38 key = key.substr(index + 1); 38 key = key.substr(index + 1);
39 } 39 }
40 return data[key]; 40 return data[key];
41 }, 41 },
42 42
43 /** 43 /**
44 * Sets the value of a property. Currently only supports unmanaged 44 * Sets the value of a property. Currently only supports unmanaged
45 * properties. 45 * properties.
46 * @param {string} key The property key. 46 * @param {string} key The property key.
47 * @param {string} value The property value to set. 47 * @param {Object} value The property value to set.
48 */ 48 */
49 setManagedProperty: function(key, value) { 49 setManagedProperty: function(key, value) {
50 var data = this.data_; 50 var data = this.data_;
51 while (true) { 51 while (true) {
52 var index = key.indexOf('.'); 52 var index = key.indexOf('.');
53 if (index < 0) 53 if (index < 0)
54 break; 54 break;
55 var keyComponent = key.substr(0, index); 55 var keyComponent = key.substr(0, index);
56 if (!(keyComponent in data)) 56 if (!(keyComponent in data))
57 data[keyComponent] = {}; 57 data[keyComponent] = {};
(...skipping 11 matching lines...) Expand all
69 // For now, just update the active value. TODO(stevenjb): Eventually we 69 // For now, just update the active value. TODO(stevenjb): Eventually we
70 // should update the 'UserSetting' and 'Effective' properties correctly 70 // should update the 'UserSetting' and 'Effective' properties correctly
71 // and send that back to Chrome. 71 // and send that back to Chrome.
72 data[key]['Active'] = value; 72 data[key]['Active'] = value;
73 } 73 }
74 }, 74 },
75 75
76 /** 76 /**
77 * Gets the active value of a property. 77 * Gets the active value of a property.
78 * @param {string} key The property key. 78 * @param {string} key The property key.
79 * @return {*} The property value or undefined. 79 * @return {(Object|Array|string|undefined)} The property value or
Dan Beam 2014/09/12 03:25:20 @typedef
Vitaly Pavlenko 2014/09/12 19:16:23 Done.
80 * undefined.
80 */ 81 */
81 getActiveValue: function(key) { 82 getActiveValue: function(key) {
82 var property = this.getManagedProperty(key); 83 var property = this.getManagedProperty(key);
83 if (Array.isArray(property) || typeof property != 'object') 84 if (Array.isArray(property) || typeof property != 'object')
84 return property; 85 return property;
85 // Otherwise get the Active value (default behavior). 86 // Otherwise get the Active value (default behavior).
86 if ('Active' in property) 87 if ('Active' in property)
87 return property['Active']; 88 return property['Active'];
88 // If no Active value is defined, return the effective value if present. 89 // If no Active value is defined, return the effective value if present.
89 var effective = this.getEffectiveValueFromProperty_(property); 90 var effective = this.getEffectiveValueFromProperty_(
91 /** @type {Object} */(property));
90 if (effective != undefined) 92 if (effective != undefined)
91 return effective; 93 return effective;
92 // Otherwise this is an Object but not a Managed one. 94 // Otherwise this is an Object but not a Managed one.
93 return property; 95 return property;
94 }, 96 },
95 97
96 /** 98 /**
97 * Gets the translated ONC value from the result of getActiveValue() using 99 * Gets the translated ONC value from the result of getActiveValue() using
98 * loadTimeData. If no translation exists, returns the untranslated value. 100 * loadTimeData. If no translation exists, returns the untranslated value.
99 * @param {string} key The property key. 101 * @param {string} key The property key.
100 * @return {*} The translation if available or the value if not. 102 * @return {(Object|Array|string|undefined)} The translation if available or
103 * the value if not.
101 */ 104 */
102 getTranslatedValue: function(key) { 105 getTranslatedValue: function(key) {
103 var value = this.getActiveValue(key); 106 var value = this.getActiveValue(key);
104 if (typeof value != 'string') 107 if (typeof value != 'string')
105 return value; 108 return value;
106 var oncString = 'Onc' + key + value; 109 var oncString = 'Onc' + key + value;
107 // Handle special cases 110 // Handle special cases
108 if (key == 'Name' && this.getActiveValue('Type') == 'Ethernet') 111 if (key == 'Name' && this.getActiveValue('Type') == 'Ethernet')
109 return loadTimeData.getString('ethernetName'); 112 return loadTimeData.getString('ethernetName');
110 if (key == 'VPN.Type' && value == 'L2TP-IPsec') { 113 if (key == 'VPN.Type' && value == 'L2TP-IPsec') {
111 var auth = this.getActiveValue('VPN.IPsec.AuthenticationType'); 114 var auth = this.getActiveValue('VPN.IPsec.AuthenticationType');
112 if (auth != undefined) 115 if (auth != undefined)
113 oncString += auth; 116 oncString += auth;
114 } 117 }
115 oncString = oncString.replace(/\./g, '-'); 118 oncString = oncString.replace(/\./g, '-');
116 if (loadTimeData.valueExists(oncString)) 119 if (loadTimeData.valueExists(oncString))
117 return loadTimeData.getString(oncString); 120 return loadTimeData.getString(oncString);
118 return value; 121 return value;
119 }, 122 },
120 123
121 /** 124 /**
122 * Gets the recommended value of a property. 125 * Gets the recommended value of a property.
123 * @param {string} key The property key. 126 * @param {string} key The property key.
124 * @return {*} The property value or undefined. 127 * @return {(Object|Array|string|undefined)} The property value or
128 * undefined.
125 */ 129 */
126 getRecommendedValue: function(key) { 130 getRecommendedValue: function(key) {
127 var property = this.getManagedProperty(key); 131 var property = this.getManagedProperty(key);
128 if (Array.isArray(property) || typeof property != 'object') 132 if (Array.isArray(property) || typeof property != 'object')
129 return undefined; 133 return undefined;
130 if (property['UserEditable']) 134 if (property['UserEditable'])
131 return property['UserPolicy']; 135 return property['UserPolicy'];
132 if (property['DeviceEditable']) 136 if (property['DeviceEditable'])
133 return property['DevicePolicy']; 137 return property['DevicePolicy'];
134 // No value recommended by policy. 138 // No value recommended by policy.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 updateData: function(update) { 173 updateData: function(update) {
170 for (var prop in update) { 174 for (var prop in update) {
171 if (prop in this.data_) 175 if (prop in this.data_)
172 this.data_[prop] = update[prop]; 176 this.data_[prop] = update[prop];
173 } 177 }
174 }, 178 },
175 179
176 /** 180 /**
177 * Get the effective value from a Managed property ONC dictionary. 181 * Get the effective value from a Managed property ONC dictionary.
178 * @param {Object} property The managed property ONC dictionary. 182 * @param {Object} property The managed property ONC dictionary.
179 * @return {*} The effective value or undefined. 183 * @return {(Object|Array|string|undefined)} The effective value or
184 * undefined.
180 * @private 185 * @private
181 */ 186 */
182 getEffectiveValueFromProperty_: function(property) { 187 getEffectiveValueFromProperty_: function(property) {
183 if ('Effective' in property) { 188 if ('Effective' in property) {
184 var effective = property.Effective; 189 var effective = property.Effective;
185 if (effective in property) 190 if (effective in property)
186 return property[effective]; 191 return property[effective];
187 } 192 }
188 return undefined; 193 return undefined;
189 } 194 }
190 }; 195 };
191 196
192 return { 197 return {
193 OncData: OncData 198 OncData: OncData
194 }; 199 };
195 }); 200 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698