summaryrefslogtreecommitdiffstats
path: root/addon-sdk/source/lib/sdk/windows/fennec.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 /addon-sdk/source/lib/sdk/windows/fennec.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 'addon-sdk/source/lib/sdk/windows/fennec.js')
-rw-r--r--addon-sdk/source/lib/sdk/windows/fennec.js83
1 files changed, 83 insertions, 0 deletions
diff --git a/addon-sdk/source/lib/sdk/windows/fennec.js b/addon-sdk/source/lib/sdk/windows/fennec.js
new file mode 100644
index 000000000..3c3b6c313
--- /dev/null
+++ b/addon-sdk/source/lib/sdk/windows/fennec.js
@@ -0,0 +1,83 @@
+/* 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 { Class } = require('../core/heritage');
+const { BrowserWindow } = require('../window/browser');
+const { WindowTracker } = require('../deprecated/window-utils');
+const { isBrowser, getMostRecentBrowserWindow } = require('../window/utils');
+const { windowNS } = require('../window/namespace');
+const { on, off, once, emit } = require('../event/core');
+const { method } = require('../lang/functional');
+const { EventTarget } = require('../event/target');
+const { List, addListItem } = require('../util/list');
+
+const ERR_FENNEC_MSG = 'This method is not yet supported by Fennec, consider using require("sdk/tabs") instead';
+
+// NOTE: On Fennec there is only one window.
+
+var BrowserWindows = Class({
+ implements: [ List ],
+ extends: EventTarget,
+ initialize: function() {
+ List.prototype.initialize.apply(this);
+ },
+ get activeWindow() {
+ let window = getMostRecentBrowserWindow();
+ return window ? getBrowserWindow({window: window}) : null;
+ },
+ open: function open(options) {
+ throw new Error(ERR_FENNEC_MSG);
+ return null;
+ }
+});
+const browserWindows = exports.browserWindows = BrowserWindows();
+
+
+/**
+ * Gets a `BrowserWindow` for the given `chromeWindow` if previously
+ * registered, `null` otherwise.
+ */
+function getRegisteredWindow(chromeWindow) {
+ for (let window of browserWindows) {
+ if (chromeWindow === windowNS(window).window)
+ return window;
+ }
+
+ return null;
+}
+
+/**
+ * Gets a `BrowserWindow` for the provided window options obj
+ * @params {Object} options
+ * Options that are passed to the the `BrowserWindow`
+ * @returns {BrowserWindow}
+ */
+function getBrowserWindow(options) {
+ let window = null;
+
+ // if we have a BrowserWindow already then use it
+ if ('window' in options)
+ window = getRegisteredWindow(options.window);
+ if (window)
+ return window;
+
+ // we don't have a BrowserWindow yet, so create one
+ window = BrowserWindow(options);
+ addListItem(browserWindows, window);
+ return window;
+}
+
+WindowTracker({
+ onTrack: function onTrack(chromeWindow) {
+ if (!isBrowser(chromeWindow)) return;
+ let window = getBrowserWindow({ window: chromeWindow });
+ emit(browserWindows, 'open', window);
+ },
+ onUntrack: function onUntrack(chromeWindow) {
+ if (!isBrowser(chromeWindow)) return;
+ let window = getBrowserWindow({ window: chromeWindow });
+ emit(browserWindows, 'close', window);
+ }
+});