addon-sdk/source/lib/sdk/util/registry.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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 "use strict";
michael@0 5
michael@0 6 module.metadata = {
michael@0 7 "stability": "unstable"
michael@0 8 };
michael@0 9
michael@0 10 const { EventEmitter } = require('../deprecated/events');
michael@0 11 const unload = require('../system/unload');
michael@0 12
michael@0 13 const Registry = EventEmitter.compose({
michael@0 14 _registry: null,
michael@0 15 _constructor: null,
michael@0 16 constructor: function Registry(constructor) {
michael@0 17 this._registry = [];
michael@0 18 this._constructor = constructor;
michael@0 19 this.on('error', this._onError = this._onError.bind(this));
michael@0 20 unload.ensure(this, "_destructor");
michael@0 21 },
michael@0 22 _destructor: function _destructor() {
michael@0 23 let _registry = this._registry.slice(0);
michael@0 24 for each (let instance in _registry)
michael@0 25 this._emit('remove', instance);
michael@0 26 this._registry.splice(0);
michael@0 27 },
michael@0 28 _onError: function _onError(e) {
michael@0 29 if (!this._listeners('error').length)
michael@0 30 console.error(e);
michael@0 31 },
michael@0 32 has: function has(instance) {
michael@0 33 let _registry = this._registry;
michael@0 34 return (
michael@0 35 (0 <= _registry.indexOf(instance)) ||
michael@0 36 (instance && instance._public && 0 <= _registry.indexOf(instance._public))
michael@0 37 );
michael@0 38 },
michael@0 39 add: function add(instance) {
michael@0 40 let { _constructor, _registry } = this;
michael@0 41 if (!(instance instanceof _constructor))
michael@0 42 instance = new _constructor(instance);
michael@0 43 if (0 > _registry.indexOf(instance)) {
michael@0 44 _registry.push(instance);
michael@0 45 this._emit('add', instance);
michael@0 46 }
michael@0 47 return instance;
michael@0 48 },
michael@0 49 remove: function remove(instance) {
michael@0 50 let _registry = this._registry;
michael@0 51 let index = _registry.indexOf(instance)
michael@0 52 if (0 <= index) {
michael@0 53 this._emit('remove', instance);
michael@0 54 _registry.splice(index, 1);
michael@0 55 }
michael@0 56 }
michael@0 57 });
michael@0 58 exports.Registry = Registry;
michael@0 59

mercurial