michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: "use strict"; michael@0: michael@0: this.EXPORTED_SYMBOLS = ["gDevToolsExtensions"]; michael@0: michael@0: Components.utils.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: let globalsCache = {}; michael@0: michael@0: this.gDevToolsExtensions = { michael@0: addContentGlobal: function(options) { michael@0: if (!options || !options.global || !options['inner-window-id']) { michael@0: throw Error('Invalid arguments'); michael@0: } michael@0: let cache = getGlobalCache(options['inner-window-id']); michael@0: cache.push(options.global); michael@0: return undefined; michael@0: }, michael@0: getContentGlobals: function(options) { michael@0: if (!options || !options['inner-window-id']) { michael@0: throw Error('Invalid arguments'); michael@0: } michael@0: return Array.slice(globalsCache[options['inner-window-id']] || []); michael@0: }, michael@0: removeContentGlobal: function(options) { michael@0: if (!options || !options.global || !options['inner-window-id']) { michael@0: throw Error('Invalid arguments'); michael@0: } michael@0: let cache = getGlobalCache(options['inner-window-id']); michael@0: let index = cache.indexOf(options.global); michael@0: cache.splice(index, 1); michael@0: return undefined; michael@0: } michael@0: }; michael@0: michael@0: function getGlobalCache(aInnerWindowID) { michael@0: return globalsCache[aInnerWindowID] = globalsCache[aInnerWindowID] || []; michael@0: } michael@0: michael@0: // when the window is destroyed, eliminate the associated globals cache michael@0: Services.obs.addObserver(function observer(subject, topic, data) { michael@0: let id = subject.QueryInterface(Components.interfaces.nsISupportsPRUint64).data; michael@0: delete globalsCache[id]; michael@0: }, 'inner-window-destroyed', false);