summaryrefslogtreecommitdiffstats
path: root/devtools/server/content-globals.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /devtools/server/content-globals.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/server/content-globals.js')
-rw-r--r--devtools/server/content-globals.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/devtools/server/content-globals.js b/devtools/server/content-globals.js
new file mode 100644
index 000000000..2c59552e7
--- /dev/null
+++ b/devtools/server/content-globals.js
@@ -0,0 +1,47 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const { Ci } = require("chrome");
+const Services = require("Services");
+
+var globalsCache = {};
+
+exports.addContentGlobal = function (options) {
+ if (!options || !options.global || !options["inner-window-id"]) {
+ throw Error("Invalid arguments");
+ }
+ let cache = getGlobalCache(options["inner-window-id"]);
+ cache.push(options.global);
+ return undefined;
+};
+
+exports.getContentGlobals = function (options) {
+ if (!options || !options["inner-window-id"]) {
+ throw Error("Invalid arguments");
+ }
+ return Array.slice(globalsCache[options["inner-window-id"]] || []);
+};
+
+exports.removeContentGlobal = function (options) {
+ if (!options || !options.global || !options["inner-window-id"]) {
+ throw Error("Invalid arguments");
+ }
+ let cache = getGlobalCache(options["inner-window-id"]);
+ let index = cache.indexOf(options.global);
+ cache.splice(index, 1);
+ return undefined;
+};
+
+function getGlobalCache(aInnerWindowID) {
+ return globalsCache[aInnerWindowID] = globalsCache[aInnerWindowID] || [];
+}
+
+// when the window is destroyed, eliminate the associated globals cache
+if (!isWorker) {
+ Services.obs.addObserver(function observer(subject, topic, data) {
+ let id = subject.QueryInterface(Ci.nsISupportsPRUint64).data;
+ delete globalsCache[id];
+ }, "inner-window-destroyed", false);
+}