mobile/android/modules/geckoview/GeckoViewTab.jsm
author Mike Conley <mconley@mozilla.com>
Tue, 06 Nov 2018 04:35:00 +0000
changeset 501108 410f4e7ae2feb52dc23db8892829e1b767477849
parent 489335 7d9cc6236b1f4f08f4a748c720c80d1e1325390a
child 504452 412a0c8ee8c479e0b29e2ca9540c7c7a20876168
permissions -rw-r--r--
Bug 1498233 - Stub out getBrowserForOuterWindowID for GeckoViewTab. r=jchen a=jcristau GeckoViewTab stubs out gBrowser on the root window for WebExtension compatibility. LoginManagerParent also looks for gBrowser on windows that are handling username and password form fills, and expects it to implement getBrowserForOuterWindowID. This patch makes the stub implement getBrowserForOuterWindowID, which just returns the lone GeckoViewTab browser. Differential Revision: https://phabricator.services.mozilla.com/D10750

/* 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 = ["GeckoViewTab"];

ChromeUtils.import("resource://gre/modules/GeckoViewModule.jsm");

// Based on the "Tab" prototype from mobile/android/chrome/content/browser.js
class Tab {
  constructor(id, browser) {
    this.id = id;
    this.browser = browser;
  }

  getActive() {
    return this.browser.docShellIsActive;
  }
}

// Stub BrowserApp implementation for WebExtensions support.
class GeckoViewTab extends GeckoViewModule {
  onInit() {
    let tab = new Tab(0, this.browser);

    this.window.gBrowser = this.window.BrowserApp = {
      selectedBrowser: this.browser,
      tabs: [tab],
      selectedTab: tab,

      getTabForId: function(aId) {
        return this.selectedTab;
      },

      getTabForBrowser: function(aBrowser) {
        return this.selectedTab;
      },

      getTabForWindow: function(aWindow) {
        return this.selectedTab;
      },

      getTabForDocument: function(aDocument) {
        return this.selectedTab;
      },

      getBrowserForOuterWindowID: function(aID) {
        return this.browser;
      },
    };
  }
}