addon-sdk/source/lib/sdk/window/browser.js

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

mercurial