1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/addon-sdk/source/lib/sdk/addon-page.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,73 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 +'use strict'; 1.8 + 1.9 +module.metadata = { 1.10 + 'stability': 'deprecated' 1.11 +}; 1.12 + 1.13 +const { WindowTracker } = require('./deprecated/window-utils'); 1.14 +const { isXULBrowser } = require('./window/utils'); 1.15 +const { add, remove } = require('./util/array'); 1.16 +const { getTabs, closeTab, getURI } = require('./tabs/utils'); 1.17 +const { data } = require('./self'); 1.18 +const { ns } = require("./core/namespace"); 1.19 + 1.20 +const addonURL = data.url('index.html'); 1.21 + 1.22 +const windows = ns(); 1.23 + 1.24 +require("./util/deprecate").deprecateUsage( 1.25 + "The addon-page module is deprecated." + 1.26 + "In the new Firefox UI design all pages will include navigational elements;" + 1.27 + "once the new design ships, using the addon-page module will not have any effect." 1.28 +); 1.29 + 1.30 +WindowTracker({ 1.31 + onTrack: function onTrack(window) { 1.32 + if (!isXULBrowser(window) || windows(window).hideChromeForLocation) 1.33 + return; 1.34 + 1.35 + let { XULBrowserWindow } = window; 1.36 + let { hideChromeForLocation } = XULBrowserWindow; 1.37 + 1.38 + windows(window).hideChromeForLocation = hideChromeForLocation; 1.39 + 1.40 + // Augmenting the behavior of `hideChromeForLocation` method, as 1.41 + // suggested by https://developer.mozilla.org/en-US/docs/Hiding_browser_chrome 1.42 + XULBrowserWindow.hideChromeForLocation = function(url) { 1.43 + return isAddonURL(url) || hideChromeForLocation.call(this, url); 1.44 + } 1.45 + }, 1.46 + 1.47 + onUntrack: function onUntrack(window) { 1.48 + if (isXULBrowser(window)) 1.49 + getTabs(window).filter(tabFilter).forEach(untrackTab.bind(null, window)); 1.50 + } 1.51 +}); 1.52 + 1.53 +function isAddonURL(url) { 1.54 + if (url.indexOf(addonURL) === 0) { 1.55 + let rest = url.substr(addonURL.length); 1.56 + return ((rest.length === 0) || (['#','?'].indexOf(rest.charAt(0)) > -1)); 1.57 + } 1.58 + return false; 1.59 +} 1.60 + 1.61 +function tabFilter(tab) { 1.62 + return isAddonURL(getURI(tab)); 1.63 +} 1.64 + 1.65 +function untrackTab(window, tab) { 1.66 + // Note: `onUntrack` will be called for all windows on add-on unloads, 1.67 + // so we want to clean them up from these URLs. 1.68 + let { hideChromeForLocation } = windows(window); 1.69 + 1.70 + if (hideChromeForLocation) { 1.71 + window.XULBrowserWindow.hideChromeForLocation = hideChromeForLocation.bind(window.XULBrowserWindow); 1.72 + windows(window).hideChromeForLocation = null; 1.73 + } 1.74 + 1.75 + closeTab(tab); 1.76 +}