|
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 module.metadata = { |
|
7 'stability': 'deprecated' |
|
8 }; |
|
9 |
|
10 const { WindowTracker } = require('./deprecated/window-utils'); |
|
11 const { isXULBrowser } = require('./window/utils'); |
|
12 const { add, remove } = require('./util/array'); |
|
13 const { getTabs, closeTab, getURI } = require('./tabs/utils'); |
|
14 const { data } = require('./self'); |
|
15 const { ns } = require("./core/namespace"); |
|
16 |
|
17 const addonURL = data.url('index.html'); |
|
18 |
|
19 const windows = ns(); |
|
20 |
|
21 require("./util/deprecate").deprecateUsage( |
|
22 "The addon-page module is deprecated." + |
|
23 "In the new Firefox UI design all pages will include navigational elements;" + |
|
24 "once the new design ships, using the addon-page module will not have any effect." |
|
25 ); |
|
26 |
|
27 WindowTracker({ |
|
28 onTrack: function onTrack(window) { |
|
29 if (!isXULBrowser(window) || windows(window).hideChromeForLocation) |
|
30 return; |
|
31 |
|
32 let { XULBrowserWindow } = window; |
|
33 let { hideChromeForLocation } = XULBrowserWindow; |
|
34 |
|
35 windows(window).hideChromeForLocation = hideChromeForLocation; |
|
36 |
|
37 // Augmenting the behavior of `hideChromeForLocation` method, as |
|
38 // suggested by https://developer.mozilla.org/en-US/docs/Hiding_browser_chrome |
|
39 XULBrowserWindow.hideChromeForLocation = function(url) { |
|
40 return isAddonURL(url) || hideChromeForLocation.call(this, url); |
|
41 } |
|
42 }, |
|
43 |
|
44 onUntrack: function onUntrack(window) { |
|
45 if (isXULBrowser(window)) |
|
46 getTabs(window).filter(tabFilter).forEach(untrackTab.bind(null, window)); |
|
47 } |
|
48 }); |
|
49 |
|
50 function isAddonURL(url) { |
|
51 if (url.indexOf(addonURL) === 0) { |
|
52 let rest = url.substr(addonURL.length); |
|
53 return ((rest.length === 0) || (['#','?'].indexOf(rest.charAt(0)) > -1)); |
|
54 } |
|
55 return false; |
|
56 } |
|
57 |
|
58 function tabFilter(tab) { |
|
59 return isAddonURL(getURI(tab)); |
|
60 } |
|
61 |
|
62 function untrackTab(window, tab) { |
|
63 // Note: `onUntrack` will be called for all windows on add-on unloads, |
|
64 // so we want to clean them up from these URLs. |
|
65 let { hideChromeForLocation } = windows(window); |
|
66 |
|
67 if (hideChromeForLocation) { |
|
68 window.XULBrowserWindow.hideChromeForLocation = hideChromeForLocation.bind(window.XULBrowserWindow); |
|
69 windows(window).hideChromeForLocation = null; |
|
70 } |
|
71 |
|
72 closeTab(tab); |
|
73 } |