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 | const ObservableObject = require("devtools/shared/observable-object"); |
michael@0 | 6 | const {Connection} = require("devtools/client/connection-manager"); |
michael@0 | 7 | |
michael@0 | 8 | const _knownConnectionStores = new WeakMap(); |
michael@0 | 9 | |
michael@0 | 10 | let ConnectionStore; |
michael@0 | 11 | |
michael@0 | 12 | module.exports = ConnectionStore = function(connection) { |
michael@0 | 13 | // If we already know about this connection, |
michael@0 | 14 | // let's re-use the existing store. |
michael@0 | 15 | if (_knownConnectionStores.has(connection)) { |
michael@0 | 16 | return _knownConnectionStores.get(connection); |
michael@0 | 17 | } |
michael@0 | 18 | _knownConnectionStores.set(connection, this); |
michael@0 | 19 | |
michael@0 | 20 | ObservableObject.call(this, {status:null,host:null,port:null}); |
michael@0 | 21 | |
michael@0 | 22 | this.destroy = this.destroy.bind(this); |
michael@0 | 23 | this._feedStore = this._feedStore.bind(this); |
michael@0 | 24 | |
michael@0 | 25 | this._connection = connection; |
michael@0 | 26 | this._connection.once(Connection.Events.DESTROYED, this.destroy); |
michael@0 | 27 | this._connection.on(Connection.Events.STATUS_CHANGED, this._feedStore); |
michael@0 | 28 | this._connection.on(Connection.Events.PORT_CHANGED, this._feedStore); |
michael@0 | 29 | this._connection.on(Connection.Events.HOST_CHANGED, this._feedStore); |
michael@0 | 30 | this._feedStore(); |
michael@0 | 31 | return this; |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | ConnectionStore.prototype = { |
michael@0 | 35 | destroy: function() { |
michael@0 | 36 | if (this._connection) { |
michael@0 | 37 | // While this.destroy is bound using .once() above, that event may not |
michael@0 | 38 | // have occurred when the ConnectionStore client calls destroy, so we |
michael@0 | 39 | // manually remove it here. |
michael@0 | 40 | this._connection.off(Connection.Events.DESTROYED, this.destroy); |
michael@0 | 41 | this._connection.off(Connection.Events.STATUS_CHANGED, this._feedStore); |
michael@0 | 42 | this._connection.off(Connection.Events.PORT_CHANGED, this._feedStore); |
michael@0 | 43 | this._connection.off(Connection.Events.HOST_CHANGED, this._feedStore); |
michael@0 | 44 | _knownConnectionStores.delete(this._connection); |
michael@0 | 45 | this._connection = null; |
michael@0 | 46 | } |
michael@0 | 47 | }, |
michael@0 | 48 | |
michael@0 | 49 | _feedStore: function() { |
michael@0 | 50 | this.object.status = this._connection.status; |
michael@0 | 51 | this.object.host = this._connection.host; |
michael@0 | 52 | this.object.port = this._connection.port; |
michael@0 | 53 | } |
michael@0 | 54 | } |