Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
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 | this.EXPORTED_SYMBOLS = ["gDevToolsExtensions"]; |
michael@0 | 7 | |
michael@0 | 8 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 9 | |
michael@0 | 10 | let globalsCache = {}; |
michael@0 | 11 | |
michael@0 | 12 | this.gDevToolsExtensions = { |
michael@0 | 13 | addContentGlobal: function(options) { |
michael@0 | 14 | if (!options || !options.global || !options['inner-window-id']) { |
michael@0 | 15 | throw Error('Invalid arguments'); |
michael@0 | 16 | } |
michael@0 | 17 | let cache = getGlobalCache(options['inner-window-id']); |
michael@0 | 18 | cache.push(options.global); |
michael@0 | 19 | return undefined; |
michael@0 | 20 | }, |
michael@0 | 21 | getContentGlobals: function(options) { |
michael@0 | 22 | if (!options || !options['inner-window-id']) { |
michael@0 | 23 | throw Error('Invalid arguments'); |
michael@0 | 24 | } |
michael@0 | 25 | return Array.slice(globalsCache[options['inner-window-id']] || []); |
michael@0 | 26 | }, |
michael@0 | 27 | removeContentGlobal: function(options) { |
michael@0 | 28 | if (!options || !options.global || !options['inner-window-id']) { |
michael@0 | 29 | throw Error('Invalid arguments'); |
michael@0 | 30 | } |
michael@0 | 31 | let cache = getGlobalCache(options['inner-window-id']); |
michael@0 | 32 | let index = cache.indexOf(options.global); |
michael@0 | 33 | cache.splice(index, 1); |
michael@0 | 34 | return undefined; |
michael@0 | 35 | } |
michael@0 | 36 | }; |
michael@0 | 37 | |
michael@0 | 38 | function getGlobalCache(aInnerWindowID) { |
michael@0 | 39 | return globalsCache[aInnerWindowID] = globalsCache[aInnerWindowID] || []; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | // when the window is destroyed, eliminate the associated globals cache |
michael@0 | 43 | Services.obs.addObserver(function observer(subject, topic, data) { |
michael@0 | 44 | let id = subject.QueryInterface(Components.interfaces.nsISupportsPRUint64).data; |
michael@0 | 45 | delete globalsCache[id]; |
michael@0 | 46 | }, 'inner-window-destroyed', false); |