| 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 * |
| 11 * Example: | 11 * Example: |
| 12 * | 12 * |
| 13 * <cr-settings-prefs id="prefs"></cr-settings-prefs> | 13 * <cr-settings-prefs id="prefs"></cr-settings-prefs> |
| 14 * <cr-settings-a11y-page prefs="{{this.$.prefs}}"></cr-settings-a11y-page> | 14 * <cr-settings-a11y-page prefs="{{this.$.prefs}}"></cr-settings-a11y-page> |
| 15 * | 15 * |
| 16 * @group Chrome Settings Elements | 16 * @group Chrome Settings Elements |
| 17 * @element cr-settings-a11y-page | 17 * @element cr-settings-a11y-page |
| 18 */ | 18 */ |
| 19 (function() { | 19 (function() { |
| 20 'use strict'; | 20 'use strict'; |
| 21 | 21 |
| 22 Polymer({ | 22 Polymer({ |
| 23 is: 'cr-settings-prefs', | 23 is: 'cr-settings-prefs', |
| 24 | 24 |
| 25 properties: { | 25 properties: { |
| 26 /** | 26 /** |
| 27 * Object containing all preferences. | 27 * Object containing all preferences. |
| 28 */ | 28 */ |
| 29 settings: { | 29 prefStore: { |
| 30 type: Object, | 30 type: Object, |
| 31 value: function() { return {}; }, | 31 value: function() { return {}; }, |
| 32 notify: true, | 32 notify: true, |
| 33 }, | 33 }, |
| 34 }, | 34 }, |
| 35 | 35 |
| 36 /** @override */ | 36 /** @override */ |
| 37 created: function() { | 37 created: function() { |
| 38 CrSettingsPrefs.isInitialized = false; | 38 CrSettingsPrefs.isInitialized = false; |
| 39 | 39 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 67 | 67 |
| 68 /** | 68 /** |
| 69 * Updates the settings model with the given prefs. | 69 * Updates the settings model with the given prefs. |
| 70 * @param {!Array<!chrome.settingsPrivate.PrefObject>} prefs | 70 * @param {!Array<!chrome.settingsPrivate.PrefObject>} prefs |
| 71 * @param {boolean} shouldObserve Whether to add an ObjectObserver for each | 71 * @param {boolean} shouldObserve Whether to add an ObjectObserver for each |
| 72 * of the prefs. | 72 * of the prefs. |
| 73 * @private | 73 * @private |
| 74 */ | 74 */ |
| 75 updatePrefs_: function(prefs, shouldObserve) { | 75 updatePrefs_: function(prefs, shouldObserve) { |
| 76 prefs.forEach(function(prefObj) { | 76 prefs.forEach(function(prefObj) { |
| 77 let root = this.settings; | 77 let root = this.prefStore; |
| 78 let tokens = prefObj.key.split('.'); | 78 let tokens = prefObj.key.split('.'); |
| 79 | 79 |
| 80 assert(tokens.length > 0); | 80 assert(tokens.length > 0); |
| 81 | 81 |
| 82 for (let i = 0; i < tokens.length; i++) { | 82 for (let i = 0; i < tokens.length; i++) { |
| 83 let token = tokens[i]; | 83 let token = tokens[i]; |
| 84 | 84 |
| 85 if (!root.hasOwnProperty(token)) { | 85 if (!root.hasOwnProperty(token)) { |
| 86 let path = 'settings.' + tokens.slice(0, i + 1).join('.'); | 86 let path = 'prefStore.' + tokens.slice(0, i + 1).join('.'); |
| 87 this.setPathValue(path, {}); | 87 this.setPathValue(path, {}); |
| 88 } | 88 } |
| 89 root = root[token]; | 89 root = root[token]; |
| 90 } | 90 } |
| 91 | 91 |
| 92 // NOTE: Do this copy rather than just a re-assignment, so that the | 92 // NOTE: Do this copy rather than just a re-assignment, so that the |
| 93 // ObjectObserver fires. | 93 // ObjectObserver fires. |
| 94 for (let objKey in prefObj) { | 94 for (let objKey in prefObj) { |
| 95 let path = 'settings.' + prefObj.key + '.' + objKey; | 95 let path = 'prefStore.' + prefObj.key + '.' + objKey; |
| 96 this.setPathValue(path, prefObj[objKey]); | 96 this.setPathValue(path, prefObj[objKey]); |
| 97 } | 97 } |
| 98 | 98 |
| 99 if (shouldObserve) { | 99 if (shouldObserve) { |
| 100 let keyObserver = new ObjectObserver(root); | 100 let keyObserver = new ObjectObserver(root); |
| 101 keyObserver.open( | 101 keyObserver.open( |
| 102 this.propertyChangeCallback_.bind(this, prefObj.key)); | 102 this.propertyChangeCallback_.bind(this, prefObj.key)); |
| 103 } | 103 } |
| 104 }, this); | 104 }, this); |
| 105 }, | 105 }, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 127 | 127 |
| 128 chrome.settingsPrivate.setPref( | 128 chrome.settingsPrivate.setPref( |
| 129 propertyPath, | 129 propertyPath, |
| 130 newValue, | 130 newValue, |
| 131 /* pageId */ '', | 131 /* pageId */ '', |
| 132 /* callback */ function() {}); | 132 /* callback */ function() {}); |
| 133 } | 133 } |
| 134 }, | 134 }, |
| 135 }); | 135 }); |
| 136 })(); | 136 })(); |
| OLD | NEW |