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

Side by Side Diff: chrome/browser/resources/options/preferences.js

Issue 2835009: Split options page code/html into its own set of files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/resources/options/pref_ui.js ('k') | tools/grit/grit/format/html_inline.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 ///////////////////////////////////////////////////////////////////////////////
6 // Preferences class:
7
8 /**
9 * Preferences class manages access to Chrome profile preferences.
10 * @constructor
11 */
12 function Preferences() {
13 }
14
15 /**
16 * Gets Preferences object instance.
17 * @return Preferences singleton instance.
18 * @type Preferences
19 */
20 Preferences.getInstance = function() {
21 if (Preferences.instance_)
22 return Preferences.instance_;
23 Preferences.instance_ = new Preferences();
24 return Preferences.instance_;
25 };
26
27 /**
28 * Extracts preference value.
29 * @param {Object} dict Map of preference values passed to fetchPrefs callback.
30 * @param {string} name Preference name.
31 * @return preference value.
32 */
33 Preferences.getPref = function (dict, name) {
34 var parts = name.split('.');
35 var cur = dict;
36 for (var part; part = parts.shift(); ) {
37 if (cur[part]) {
38 cur = cur[part];
39 } else {
40 return null;
41 }
42 }
43 return cur;
44 };
45
46 /**
47 * Sets value of a boolean preference.
48 * and signals its changed value.
49 * @param {string} name Preference name.
50 * @param {boolean} value New preference value.
51 */
52 Preferences.setBooleanPref = function (name, value) {
53 chrome.send('setBooleanPref', [name, value ? 'true' : 'false']);
54 };
55
56 /**
57 * Sets value of an integer preference.
58 * and signals its changed value.
59 * @param {string} name Preference name.
60 * @param {number} value New preference value.
61 */
62 Preferences.setIntegerPref = function(name, value) {
63 chrome.send('setIntegerPref', [name, String(value)]);
64 };
65
66 /**
67 * Sets value of a string preference.
68 * and signals its changed value.
69 * @param {string} name Preference name.
70 * @param {string} value New preference value.
71 */
72 Preferences.setStringPref = function(name, value) {
73 chrome.send('setStringPref', [name, value]);
74 };
75
76 Preferences.prototype = {
77 __proto__: cr.EventTarget.prototype,
78
79 // Map of registered preferences.
80 registeredPreferences_: {},
81
82 /**
83 * Adds an event listener to the target.
84 * @param {string} type The name of the event.
85 * @param {!Function|{handleEvent:Function}} handler The handler for the
86 * event. This is called when the event is dispatched.
87 */
88 addEventListener: function(type, handler) {
89 cr.EventTarget.prototype.addEventListener.call(this, type, handler);
90 this.registeredPreferences_[type] = true;
91 },
92
93 /**
94 * Initializes preference reading and change notifications.
95 */
96 initialize: function() {
97 var params1 = ['Preferences.prefsFetchedCallback'];
98 var params2 = ['Preferences.prefsChangedCallback'];
99 for (var prefName in this.registeredPreferences_) {
100 params1.push(prefName);
101 params2.push(prefName);
102 }
103 chrome.send('fetchPrefs', params1);
104 chrome.send('observePrefs', params2);
105 },
106
107 /**
108 * Helper function for flattening of dictionary passed via fetchPrefs
109 * callback.
110 * @param {string} prefix Preference name prefix.
111 * @param {object} dict Map with preference values.
112 */
113 flattenMapAndDispatchEvent_: function(prefix, dict) {
114 for (var prefName in dict) {
115 if (typeof dict[prefName] == 'object') {
116 this.flattenMapAndDispatchEvent_(prefix + prefName + '.',
117 dict[prefName]);
118 } else {
119 var event = new cr.Event(prefix + prefName);
120 event.value = dict[prefName];
121 this.dispatchEvent(event);
122 }
123 }
124 }
125 };
126
127 /**
128 * Callback for fetchPrefs method.
129 * @param {object} dict Map of fetched property values.
130 */
131 Preferences.prefsFetchedCallback = function(dict) {
132 Preferences.getInstance().flattenMapAndDispatchEvent_('', dict);
133 };
134
135 /**
136 * Callback for observePrefs method.
137 * @param {array} notification An array defining changed preference values.
138 * notification[0] contains name of the change preference while its new value
139 * is stored in notification[1].
140 */
141 Preferences.prefsChangedCallback = function(notification) {
142 var event = new cr.Event(notification[0]);
143 event.value = notification[1];
144 Preferences.getInstance().dispatchEvent(event);
145 };
146
147
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/pref_ui.js ('k') | tools/grit/grit/format/html_inline.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698