summaryrefslogtreecommitdiffstats
path: root/remote/shared/MobileTabBrowser.sys.mjs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /remote/shared/MobileTabBrowser.sys.mjs
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'remote/shared/MobileTabBrowser.sys.mjs')
-rw-r--r--remote/shared/MobileTabBrowser.sys.mjs86
1 files changed, 86 insertions, 0 deletions
diff --git a/remote/shared/MobileTabBrowser.sys.mjs b/remote/shared/MobileTabBrowser.sys.mjs
new file mode 100644
index 0000000000..b61a1f9a9b
--- /dev/null
+++ b/remote/shared/MobileTabBrowser.sys.mjs
@@ -0,0 +1,86 @@
+/* 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/. */
+
+const lazy = {};
+
+ChromeUtils.defineESModuleGetters(lazy, {
+ GeckoViewTabUtil: "resource://gre/modules/GeckoViewTestUtils.sys.mjs",
+
+ windowManager: "chrome://remote/content/shared/WindowManager.sys.mjs",
+});
+
+// GeckoView shim for Desktop's gBrowser
+export class MobileTabBrowser {
+ constructor(window) {
+ this.window = window;
+ }
+
+ get tabs() {
+ return [this.window.tab];
+ }
+
+ get selectedTab() {
+ return this.window.tab;
+ }
+
+ set selectedTab(tab) {
+ if (tab != this.selectedTab) {
+ throw new Error("GeckoView only supports a single tab");
+ }
+
+ // Synthesize a custom TabSelect event to indicate that a tab has been
+ // selected even when we don't change it.
+ const event = this.window.CustomEvent("TabSelect", {
+ bubbles: true,
+ cancelable: false,
+ detail: {
+ previousTab: this.selectedTab,
+ },
+ });
+ this.window.document.dispatchEvent(event);
+ }
+
+ get selectedBrowser() {
+ return this.selectedTab.linkedBrowser;
+ }
+
+ addEventListener() {
+ this.window.addEventListener(...arguments);
+ }
+
+ /**
+ * Create a new tab.
+ *
+ * @param {string} uriString
+ * The URI string to load within the newly opened tab.
+ *
+ * @returns {Promise<Tab>}
+ * The created tab.
+ * @throws {Error}
+ * Throws an error if the tab cannot be created.
+ */
+ addTab(uriString) {
+ return lazy.GeckoViewTabUtil.createNewTab(uriString);
+ }
+
+ getTabForBrowser(browser) {
+ if (browser != this.selectedBrowser) {
+ throw new Error("GeckoView only supports a single tab");
+ }
+
+ return this.selectedTab;
+ }
+
+ removeEventListener() {
+ this.window.removeEventListener(...arguments);
+ }
+
+ removeTab(tab) {
+ if (tab != this.selectedTab) {
+ throw new Error("GeckoView only supports a single tab");
+ }
+
+ return lazy.windowManager.closeWindow(this.window);
+ }
+}