michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: 'use strict'; michael@0: michael@0: module.metadata = { michael@0: 'stability': 'deprecated' michael@0: }; michael@0: michael@0: const { WindowTracker } = require('./deprecated/window-utils'); michael@0: const { isXULBrowser } = require('./window/utils'); michael@0: const { add, remove } = require('./util/array'); michael@0: const { getTabs, closeTab, getURI } = require('./tabs/utils'); michael@0: const { data } = require('./self'); michael@0: const { ns } = require("./core/namespace"); michael@0: michael@0: const addonURL = data.url('index.html'); michael@0: michael@0: const windows = ns(); michael@0: michael@0: require("./util/deprecate").deprecateUsage( michael@0: "The addon-page module is deprecated." + michael@0: "In the new Firefox UI design all pages will include navigational elements;" + michael@0: "once the new design ships, using the addon-page module will not have any effect." michael@0: ); michael@0: michael@0: WindowTracker({ michael@0: onTrack: function onTrack(window) { michael@0: if (!isXULBrowser(window) || windows(window).hideChromeForLocation) michael@0: return; michael@0: michael@0: let { XULBrowserWindow } = window; michael@0: let { hideChromeForLocation } = XULBrowserWindow; michael@0: michael@0: windows(window).hideChromeForLocation = hideChromeForLocation; michael@0: michael@0: // Augmenting the behavior of `hideChromeForLocation` method, as michael@0: // suggested by https://developer.mozilla.org/en-US/docs/Hiding_browser_chrome michael@0: XULBrowserWindow.hideChromeForLocation = function(url) { michael@0: return isAddonURL(url) || hideChromeForLocation.call(this, url); michael@0: } michael@0: }, michael@0: michael@0: onUntrack: function onUntrack(window) { michael@0: if (isXULBrowser(window)) michael@0: getTabs(window).filter(tabFilter).forEach(untrackTab.bind(null, window)); michael@0: } michael@0: }); michael@0: michael@0: function isAddonURL(url) { michael@0: if (url.indexOf(addonURL) === 0) { michael@0: let rest = url.substr(addonURL.length); michael@0: return ((rest.length === 0) || (['#','?'].indexOf(rest.charAt(0)) > -1)); michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: function tabFilter(tab) { michael@0: return isAddonURL(getURI(tab)); michael@0: } michael@0: michael@0: function untrackTab(window, tab) { michael@0: // Note: `onUntrack` will be called for all windows on add-on unloads, michael@0: // so we want to clean them up from these URLs. michael@0: let { hideChromeForLocation } = windows(window); michael@0: michael@0: if (hideChromeForLocation) { michael@0: window.XULBrowserWindow.hideChromeForLocation = hideChromeForLocation.bind(window.XULBrowserWindow); michael@0: windows(window).hideChromeForLocation = null; michael@0: } michael@0: michael@0: closeTab(tab); michael@0: }