|
1 /* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 const {Cc, Ci, Cu, Cr} = require("chrome"); |
|
8 |
|
9 Cu.import("resource://gre/modules/Services.jsm"); |
|
10 Cu.import("resource://gre/modules/devtools/event-emitter.js"); |
|
11 |
|
12 exports.PREF_ORIG_SOURCES = "devtools.styleeditor.source-maps-enabled"; |
|
13 |
|
14 /** |
|
15 * A PreferenceObserver observes a pref branch for pref changes. |
|
16 * It emits an event for each preference change. |
|
17 */ |
|
18 function PrefObserver(branchName) { |
|
19 this.branchName = branchName; |
|
20 this.branch = Services.prefs.getBranch(branchName); |
|
21 this.branch.addObserver("", this, false); |
|
22 |
|
23 EventEmitter.decorate(this); |
|
24 } |
|
25 |
|
26 exports.PrefObserver = PrefObserver; |
|
27 |
|
28 PrefObserver.prototype = { |
|
29 observe: function(subject, topic, data) { |
|
30 if (topic == "nsPref:changed") { |
|
31 this.emit(this.branchName + data); |
|
32 } |
|
33 }, |
|
34 |
|
35 destroy: function() { |
|
36 if (this.branch) { |
|
37 this.branch.removeObserver('', this); |
|
38 } |
|
39 } |
|
40 }; |