browser.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. const { Class } = require('../core/heritage');
  6. const { windowNS } = require('./namespace');
  7. const { on, off, once } = require('../event/core');
  8. const { method } = require('../lang/functional');
  9. const { getWindowTitle } = require('./utils');
  10. const unload = require('../system/unload');
  11. const { isWindowPrivate } = require('../window/utils');
  12. const { EventTarget } = require('../event/target');
  13. const { getOwnerWindow: getPBOwnerWindow } = require('../private-browsing/window/utils');
  14. const { viewFor } = require('../view/core');
  15. const { deprecateUsage } = require('../util/deprecate');
  16. const ERR_FENNEC_MSG = 'This method is not yet supported by Fennec, consider using require("sdk/tabs") instead';
  17. const BrowserWindow = Class({
  18. initialize: function initialize(options) {
  19. EventTarget.prototype.initialize.call(this, options);
  20. windowNS(this).window = options.window;
  21. },
  22. activate: function activate() {
  23. // TODO
  24. return null;
  25. },
  26. close: function() {
  27. throw new Error(ERR_FENNEC_MSG);
  28. return null;
  29. },
  30. get title() getWindowTitle(windowNS(this).window),
  31. // NOTE: Fennec only has one window, which is assumed below
  32. // TODO: remove assumption below
  33. // NOTE: tabs requires windows
  34. get tabs() require('../tabs'),
  35. get activeTab() require('../tabs').activeTab,
  36. on: method(on),
  37. removeListener: method(off),
  38. once: method(once),
  39. get isPrivateBrowsing() {
  40. deprecateUsage('`browserWindow.isPrivateBrowsing` is deprecated, please ' +
  41. 'consider using ' +
  42. '`require("sdk/private-browsing").isPrivate(browserWindow)` ' +
  43. 'instead.');
  44. return isWindowPrivate(windowNS(this).window);
  45. }
  46. });
  47. exports.BrowserWindow = BrowserWindow;
  48. const getWindowView = window => windowNS(window).window;
  49. getPBOwnerWindow.define(BrowserWindow, getWindowView);
  50. viewFor.define(BrowserWindow, getWindowView);