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

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

Issue 604373006: Compile chrome://settings, part 9: yet another final battle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@K_blockers_from_bookmarks
Patch Set: describe supressions Created 6 years, 2 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 10
11 cr.exportPath('cr.onc'); 11 cr.exportPath('cr.onc');
12 12
13 /**
14 * @typedef {(Object|Array|string|number|undefined)}
15 */
16 cr.onc.OncValue;
17
18 cr.define('cr.onc', function() { 13 cr.define('cr.onc', function() {
19 'use strict'; 14 'use strict';
20 15
21 /** 16 /**
22 * @constructor 17 * @constructor
23 */ 18 */
24 function OncData(data) { 19 function OncData(data) {
25 this.data_ = data; 20 this.data_ = data;
26 } 21 }
27 22
28 OncData.prototype = { 23 OncData.prototype = {
29 24
30 /** 25 /**
31 * Returns either a managed property dictionary or an unmanaged value. 26 * Returns either a managed property dictionary or an unmanaged value.
32 * @param {string} key The property key. 27 * @param {string} key The property key.
33 * @return {cr.onc.OncValue} The property value or dictionary if it exists, 28 * @return {?} The property value or dictionary if it exists, otherwise
34 * otherwise undefined. 29 * undefined.
35 */ 30 */
36 getManagedProperty: function(key) { 31 getManagedProperty: function(key) {
37 var data = this.data_; 32 var data = this.data_;
38 while (true) { 33 while (true) {
39 var index = key.indexOf('.'); 34 var index = key.indexOf('.');
40 if (index < 0) 35 if (index < 0)
41 break; 36 break;
42 var keyComponent = key.substr(0, index); 37 var keyComponent = key.substr(0, index);
43 if (!(keyComponent in data)) 38 if (!(keyComponent in data))
44 return undefined; 39 return undefined;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // For now, just update the active value. TODO(stevenjb): Eventually we 72 // For now, just update the active value. TODO(stevenjb): Eventually we
78 // should update the 'UserSetting' and 'Effective' properties correctly 73 // should update the 'UserSetting' and 'Effective' properties correctly
79 // and send that back to Chrome. 74 // and send that back to Chrome.
80 data[key]['Active'] = value; 75 data[key]['Active'] = value;
81 } 76 }
82 }, 77 },
83 78
84 /** 79 /**
85 * Gets the active value of a property. 80 * Gets the active value of a property.
86 * @param {string} key The property key. 81 * @param {string} key The property key.
87 * @return {cr.onc.OncValue} The property value or undefined. 82 * @return {?} The property value or undefined.
88 */ 83 */
89 getActiveValue: function(key) { 84 getActiveValue: function(key) {
90 var property = this.getManagedProperty(key); 85 var property = this.getManagedProperty(key);
91 if (Array.isArray(property) || typeof property != 'object') 86 if (Array.isArray(property) || typeof property != 'object')
92 return property; 87 return property;
93 // Otherwise get the Active value (default behavior). 88 // Otherwise get the Active value (default behavior).
94 if ('Active' in property) 89 if ('Active' in property)
95 return property['Active']; 90 return property['Active'];
96 // If no Active value is defined, return the effective value if present. 91 // If no Active value is defined, return the effective value if present.
97 var effective = this.getEffectiveValueFromProperty_( 92 var effective = this.getEffectiveValueFromProperty_(
98 /** @type {Object} */(property)); 93 /** @type {Object} */(property));
99 if (effective != undefined) 94 if (effective != undefined)
100 return effective; 95 return effective;
101 // Otherwise this is an Object but not a Managed one. 96 // Otherwise this is an Object but not a Managed one.
102 return property; 97 return property;
103 }, 98 },
104 99
105 /** 100 /**
106 * Gets the translated ONC value from the result of getActiveValue() using 101 * Gets the translated ONC value from the result of getActiveValue() using
107 * loadTimeData. If no translation exists, returns the untranslated value. 102 * loadTimeData. If no translation exists, returns the untranslated value.
108 * @param {string} key The property key. 103 * @param {string} key The property key.
109 * @return {cr.onc.OncValue} The translation if available or the value if 104 * @return {?} The translation if available or the value if not.
110 * not.
111 */ 105 */
112 getTranslatedValue: function(key) { 106 getTranslatedValue: function(key) {
113 var value = this.getActiveValue(key); 107 var value = this.getActiveValue(key);
114 if (typeof value != 'string') 108 if (typeof value != 'string')
115 return value; 109 return value;
116 var oncString = 'Onc' + key + value; 110 var oncString = 'Onc' + key + value;
117 // Handle special cases 111 // Handle special cases
118 if (key == 'Name' && this.getActiveValue('Type') == 'Ethernet') 112 if (key == 'Name' && this.getActiveValue('Type') == 'Ethernet')
119 return loadTimeData.getString('ethernetName'); 113 return loadTimeData.getString('ethernetName');
120 if (key == 'VPN.Type' && value == 'L2TP-IPsec') { 114 if (key == 'VPN.Type' && value == 'L2TP-IPsec') {
121 var auth = this.getActiveValue('VPN.IPsec.AuthenticationType'); 115 var auth = this.getActiveValue('VPN.IPsec.AuthenticationType');
122 if (auth != undefined) 116 if (auth != undefined)
123 oncString += auth; 117 oncString += auth;
124 } 118 }
125 oncString = oncString.replace(/\./g, '-'); 119 oncString = oncString.replace(/\./g, '-');
126 if (loadTimeData.valueExists(oncString)) 120 if (loadTimeData.valueExists(oncString))
127 return loadTimeData.getString(oncString); 121 return loadTimeData.getString(oncString);
128 return value; 122 return value;
129 }, 123 },
130 124
131 /** 125 /**
132 * Gets the recommended value of a property. 126 * Gets the recommended value of a property.
133 * @param {string} key The property key. 127 * @param {string} key The property key.
134 * @return {cr.onc.OncValue} The property value or undefined. 128 * @return {?} The property value or undefined.
135 */ 129 */
136 getRecommendedValue: function(key) { 130 getRecommendedValue: function(key) {
137 var property = this.getManagedProperty(key); 131 var property = this.getManagedProperty(key);
138 if (Array.isArray(property) || typeof property != 'object') 132 if (Array.isArray(property) || typeof property != 'object')
139 return undefined; 133 return undefined;
140 if (property['UserEditable']) 134 if (property['UserEditable'])
141 return property['UserPolicy']; 135 return property['UserPolicy'];
142 if (property['DeviceEditable']) 136 if (property['DeviceEditable'])
143 return property['DevicePolicy']; 137 return property['DevicePolicy'];
144 // No value recommended by policy. 138 // No value recommended by policy.
(...skipping 21 matching lines...) Expand all
166 var security = this.getActiveValue('WiFi.Security'); 160 var security = this.getActiveValue('WiFi.Security');
167 if (security == undefined) 161 if (security == undefined)
168 return 'None'; 162 return 'None';
169 assert(typeof security == 'string'); 163 assert(typeof security == 'string');
170 return security; 164 return security;
171 }, 165 },
172 166
173 /** 167 /**
174 * Get the effective value from a Managed property ONC dictionary. 168 * Get the effective value from a Managed property ONC dictionary.
175 * @param {Object} property The managed property ONC dictionary. 169 * @param {Object} property The managed property ONC dictionary.
176 * @return {cr.onc.OncValue} The effective value or undefined. 170 * @return {?} The effective value or undefined.
177 * @private 171 * @private
178 */ 172 */
179 getEffectiveValueFromProperty_: function(property) { 173 getEffectiveValueFromProperty_: function(property) {
180 if ('Effective' in property) { 174 if ('Effective' in property) {
181 var effective = property.Effective; 175 var effective = property.Effective;
182 if (effective in property) 176 if (effective in property)
183 return property[effective]; 177 return property[effective];
184 } 178 }
185 return undefined; 179 return undefined;
186 } 180 }
187 }; 181 };
188 182
189 return { 183 return {
190 OncData: OncData 184 OncData: OncData
191 }; 185 };
192 }); 186 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/chromeos/network_list.js ('k') | chrome/browser/resources/options/compiled_resources.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698