Bug 1869043 add a main thread record of track audio outputs r=padenot
[gecko.git] / remote / shared / MobileTabBrowser.sys.mjs
blobb61a1f9a9bca3bd39c8d38240e5f96e0a4175e75
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/. */
5 const lazy = {};
7 ChromeUtils.defineESModuleGetters(lazy, {
8   GeckoViewTabUtil: "resource://gre/modules/GeckoViewTestUtils.sys.mjs",
10   windowManager: "chrome://remote/content/shared/WindowManager.sys.mjs",
11 });
13 // GeckoView shim for Desktop's gBrowser
14 export class MobileTabBrowser {
15   constructor(window) {
16     this.window = window;
17   }
19   get tabs() {
20     return [this.window.tab];
21   }
23   get selectedTab() {
24     return this.window.tab;
25   }
27   set selectedTab(tab) {
28     if (tab != this.selectedTab) {
29       throw new Error("GeckoView only supports a single tab");
30     }
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", {
35       bubbles: true,
36       cancelable: false,
37       detail: {
38         previousTab: this.selectedTab,
39       },
40     });
41     this.window.document.dispatchEvent(event);
42   }
44   get selectedBrowser() {
45     return this.selectedTab.linkedBrowser;
46   }
48   addEventListener() {
49     this.window.addEventListener(...arguments);
50   }
52   /**
53    * Create a new tab.
54    *
55    * @param {string} uriString
56    *     The URI string to load within the newly opened tab.
57    *
58    * @returns {Promise<Tab>}
59    *     The created tab.
60    * @throws {Error}
61    *     Throws an error if the tab cannot be created.
62    */
63   addTab(uriString) {
64     return lazy.GeckoViewTabUtil.createNewTab(uriString);
65   }
67   getTabForBrowser(browser) {
68     if (browser != this.selectedBrowser) {
69       throw new Error("GeckoView only supports a single tab");
70     }
72     return this.selectedTab;
73   }
75   removeEventListener() {
76     this.window.removeEventListener(...arguments);
77   }
79   removeTab(tab) {
80     if (tab != this.selectedTab) {
81       throw new Error("GeckoView only supports a single tab");
82     }
84     return lazy.windowManager.closeWindow(this.window);
85   }