1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 ChromeUtils.defineESModuleGetters(lazy, {
8 GeckoViewTabUtil: "resource://gre/modules/GeckoViewTestUtils.sys.mjs",
10 windowManager: "chrome://remote/content/shared/WindowManager.sys.mjs",
13 // GeckoView shim for Desktop's gBrowser
14 export class MobileTabBrowser {
20 return [this.window.tab];
24 return this.window.tab;
27 set selectedTab(tab) {
28 if (tab != this.selectedTab) {
29 throw new Error("GeckoView only supports a single tab");
32 // Synthesize a custom TabSelect event to indicate that a tab has been
33 // selected even when we don't change it.
34 const event = this.window.CustomEvent("TabSelect", {
38 previousTab: this.selectedTab,
41 this.window.document.dispatchEvent(event);
44 get selectedBrowser() {
45 return this.selectedTab.linkedBrowser;
49 this.window.addEventListener(...arguments);
55 * @param {string} uriString
56 * The URI string to load within the newly opened tab.
58 * @returns {Promise<Tab>}
61 * Throws an error if the tab cannot be created.
64 return lazy.GeckoViewTabUtil.createNewTab(uriString);
67 getTabForBrowser(browser) {
68 if (browser != this.selectedBrowser) {
69 throw new Error("GeckoView only supports a single tab");
72 return this.selectedTab;
75 removeEventListener() {
76 this.window.removeEventListener(...arguments);
80 if (tab != this.selectedTab) {
81 throw new Error("GeckoView only supports a single tab");
84 return lazy.windowManager.closeWindow(this.window);