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 | 6 * @fileoverview |
7 * 'cr-settings-prefs' is an element which serves as a model for | 7 * 'cr-settings-prefs' is an element which serves as a model for |
8 * interaction with settings which are stored in Chrome's | 8 * interaction with settings which are stored in Chrome's |
9 * Preferences. | 9 * Preferences. |
10 * | 10 * |
(...skipping 16 matching lines...) Expand all Loading... |
27 */ | 27 */ |
28 settings: null, | 28 settings: null, |
29 }, | 29 }, |
30 | 30 |
31 /** @override */ | 31 /** @override */ |
32 created: function() { | 32 created: function() { |
33 'use strict'; | 33 'use strict'; |
34 | 34 |
35 this.settings = {}; | 35 this.settings = {}; |
36 this.initializeA11y_(); | 36 this.initializeA11y_(); |
| 37 this.initializeDownloads_(); |
37 var observer = new ObjectObserver(this.settings); | 38 var observer = new ObjectObserver(this.settings); |
38 observer.open(this.propertyChangeCallback_.bind(this, 'settings')); | 39 observer.open(this.propertyChangeCallback_.bind(this, 'settings')); |
39 | 40 |
40 // For all Object properties of settings, create an ObjectObserver. | 41 // For all Object properties of settings, create an ObjectObserver. |
41 for (let key in this.settings) { | 42 for (let key in this.settings) { |
42 if (typeof this.settings[key] == 'object') { | 43 if (typeof this.settings[key] == 'object') { |
43 let keyObserver = new ObjectObserver(this.settings[key]); | 44 let keyObserver = new ObjectObserver(this.settings[key]); |
44 keyObserver.open( | 45 keyObserver.open( |
45 this.propertyChangeCallback_.bind(this, 'settings.' + key)); | 46 this.propertyChangeCallback_.bind(this, 'settings.' + key)); |
46 } | 47 } |
(...skipping 22 matching lines...) Expand all Loading... |
69 }; | 70 }; |
70 | 71 |
71 // ChromeVox is enbaled/disabled via the 'settings.accessibility' boolean | 72 // ChromeVox is enbaled/disabled via the 'settings.accessibility' boolean |
72 // pref. | 73 // pref. |
73 this.settings.accessibility = false; | 74 this.settings.accessibility = false; |
74 | 75 |
75 // TODO(jlklein): Actually pull the data out of prefs and initialize. | 76 // TODO(jlklein): Actually pull the data out of prefs and initialize. |
76 }, | 77 }, |
77 | 78 |
78 /** | 79 /** |
| 80 * Initializes some defaults for the downloads settings. |
| 81 * @private |
| 82 */ |
| 83 initializeDownloads_: function() { |
| 84 this.settings.download = { |
| 85 downloadLocation: '', |
| 86 promptForDownload: false, |
| 87 }; |
| 88 }, |
| 89 |
| 90 /** |
79 * @param {string} propertyPath The path before the property names. | 91 * @param {string} propertyPath The path before the property names. |
80 * @param {!Array<string>} added An array of keys which were added. | 92 * @param {!Array<string>} added An array of keys which were added. |
81 * @param {!Array<string>} removed An array of keys which were removed. | 93 * @param {!Array<string>} removed An array of keys which were removed. |
82 * @param {!Array<string>} changed An array of keys of properties whose | 94 * @param {!Array<string>} changed An array of keys of properties whose |
83 * values changed. | 95 * values changed. |
84 * @param {function(string) : *} getOldValueFn A function which takes a | 96 * @param {function(string) : *} getOldValueFn A function which takes a |
85 * property name and returns the old value for that property. | 97 * property name and returns the old value for that property. |
86 * @private | 98 * @private |
87 */ | 99 */ |
88 propertyChangeCallback_: function( | 100 propertyChangeCallback_: function( |
89 propertyPath, added, removed, changed, getOldValueFn) { | 101 propertyPath, added, removed, changed, getOldValueFn) { |
90 Object.keys(changed).forEach(function(property) { | 102 Object.keys(changed).forEach(function(property) { |
91 console.log( | 103 console.log( |
92 `${propertyPath}.${property}`, | 104 `${propertyPath}.${property}`, |
93 `old : ${getOldValueFn(property)}`, | 105 `old : ${getOldValueFn(property)}`, |
94 `newValue : ${changed[property]}`); | 106 `newValue : ${changed[property]}`); |
95 | 107 |
96 // TODO(jlklein): Actually set the changed property back to prefs. | 108 // TODO(jlklein): Actually set the changed property back to prefs. |
97 }); | 109 }); |
98 }, | 110 }, |
99 }); | 111 }); |
OLD | NEW |