remote/shared/MobileTabBrowser.jsm
author Mozilla Releng Treescript <release+treescript@mozilla.org>
Sun, 07 Aug 2022 07:00:20 +0000
changeset 626346 44a5d0f480929c4a3850e68f2701a907439f8c57
parent 604612 bec07511dd3c63f84370eceb7d32e78de67da513
permissions -rw-r--r--
no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD ia -> 13b119f6b22fd39552b8ca6d8365d0fdfee076fd uk -> 04dd614d47732b72ee99dd913df676bb70d1cd60

/* 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";

var EXPORTED_SYMBOLS = ["MobileTabBrowser"];

// GeckoView shim for Desktop's gBrowser
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);
  }

  removeEventListener() {
    this.window.removeEventListener(...arguments);
  }
}