helpers.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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/. */
  4. 'use strict';
  5. module.metadata = {
  6. 'stability': 'unstable'
  7. };
  8. // NOTE: This file should only export Tab instances
  9. const { getTabForContentWindow, getTabForBrowser: getRawTabForBrowser } = require('./utils');
  10. const { Tab } = require('./tab');
  11. const { rawTabNS } = require('./namespace');
  12. function getTabForWindow(win) {
  13. let tab = getTabForContentWindow(win);
  14. // We were unable to find the related tab!
  15. if (!tab)
  16. return null;
  17. return getTabForRawTab(tab) || Tab({ tab: tab });
  18. }
  19. exports.getTabForWindow = getTabForWindow;
  20. // only works on fennec atm
  21. function getTabForRawTab(rawTab) {
  22. let tab = rawTabNS(rawTab).tab;
  23. if (tab) {
  24. return tab;
  25. }
  26. return null;
  27. }
  28. exports.getTabForRawTab = getTabForRawTab;
  29. function getTabForBrowser(browser) {
  30. return getTabForRawTab(getRawTabForBrowser(browser));
  31. }
  32. exports.getTabForBrowser = getTabForBrowser;