Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | /** |
michael@0 | 6 | * |
michael@0 | 7 | * Some helpers for common operations in the App Manager: |
michael@0 | 8 | * |
michael@0 | 9 | * . mergeStores: merge several store into one. |
michael@0 | 10 | * . l10n: resolves strings from app-manager.properties. |
michael@0 | 11 | * |
michael@0 | 12 | */ |
michael@0 | 13 | |
michael@0 | 14 | let Utils = (function() { |
michael@0 | 15 | const Cu = Components.utils; |
michael@0 | 16 | const {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); |
michael@0 | 17 | const {devtools} = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}); |
michael@0 | 18 | const {require} = devtools; |
michael@0 | 19 | const EventEmitter = require("devtools/toolkit/event-emitter"); |
michael@0 | 20 | |
michael@0 | 21 | |
michael@0 | 22 | function _createSetEventForwarder(key, finalStore) { |
michael@0 | 23 | return function(event, path, value) { |
michael@0 | 24 | finalStore.emit("set", [key].concat(path), value); |
michael@0 | 25 | }; |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function mergeStores(stores) { |
michael@0 | 29 | let finalStore = {object:{}}; |
michael@0 | 30 | |
michael@0 | 31 | EventEmitter.decorate(finalStore); |
michael@0 | 32 | |
michael@0 | 33 | let setEventForwarders = {}; |
michael@0 | 34 | |
michael@0 | 35 | for (let key in stores) { |
michael@0 | 36 | let store = stores[key]; |
michael@0 | 37 | finalStore.object[key] = store.object; |
michael@0 | 38 | setEventForwarders[key] = _createSetEventForwarder(key, finalStore); |
michael@0 | 39 | store.on("set", setEventForwarders[key]); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | finalStore.destroy = () => { |
michael@0 | 43 | for (let key in stores) { |
michael@0 | 44 | let store = stores[key]; |
michael@0 | 45 | store.off("set", setEventForwarders[key]); |
michael@0 | 46 | if (store.destroy) { |
michael@0 | 47 | store.destroy(); |
michael@0 | 48 | } |
michael@0 | 49 | } |
michael@0 | 50 | }; |
michael@0 | 51 | |
michael@0 | 52 | return finalStore; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | |
michael@0 | 56 | let strings = Services.strings.createBundle("chrome://browser/locale/devtools/app-manager.properties"); |
michael@0 | 57 | |
michael@0 | 58 | function l10n (property, args = []) { |
michael@0 | 59 | if (args && args.length > 0) { |
michael@0 | 60 | return strings.formatStringFromName(property, args, args.length); |
michael@0 | 61 | } else { |
michael@0 | 62 | return strings.GetStringFromName(property); |
michael@0 | 63 | } |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | return { |
michael@0 | 67 | mergeStores: mergeStores, |
michael@0 | 68 | l10n: l10n |
michael@0 | 69 | } |
michael@0 | 70 | })(); |