1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// mail/base/content/specialTabs.js
/* globals contentTabBaseType, DOMLinkHandler */
var { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);
var { ExtensionParent } = ChromeUtils.importESModule(
"resource://gre/modules/ExtensionParent.sys.mjs"
);
/**
* A tab to show Preferences.
*/
var preferencesTabType = {
__proto__: contentTabBaseType,
name: "preferencesTab",
perTabPanel: "vbox",
lastBrowserId: 0,
bundle: Services.strings.createBundle(
"chrome://messenger/locale/messenger.properties"
),
protoSvc: Cc["@mozilla.org/uriloader/external-protocol-service;1"].getService(
Ci.nsIExternalProtocolService
),
get loadingTabString() {
delete this.loadingTabString;
return (this.loadingTabString = document
.getElementById("bundle_messenger")
.getString("loadingTab"));
},
modes: {
preferencesTab: {
type: "preferencesTab",
},
},
shouldSwitchTo(aArgs) {
if (!this.tab) {
return -1;
}
this.tab.browser.contentWindow.selectPrefPane(
aArgs.paneID,
aArgs.scrollPaneTo,
aArgs.otherArgs
);
return document.getElementById("tabmail").tabInfo.indexOf(this.tab);
},
closeTab() {
this.tab = null;
},
openTab(aTab, aArgs) {
aTab.tabNode.setIcon(
"chrome://messenger/skin/icons/new/compact/settings.svg"
);
// First clone the page and set up the basics.
const clone = document
.getElementById("preferencesTab")
.firstElementChild.cloneNode(true);
clone.setAttribute("id", "preferencesTab" + this.lastBrowserId);
clone.setAttribute("collapsed", false);
aTab.panel.setAttribute("id", "preferencesTabWrapper" + this.lastBrowserId);
aTab.panel.appendChild(clone);
// Start setting up the browser.
aTab.browser = aTab.panel.querySelector("browser");
aTab.browser.setAttribute(
"id",
"preferencesTabBrowser" + this.lastBrowserId
);
aTab.browser.setAttribute("autocompletepopup", "PopupAutoComplete");
aTab.browser.addEventListener("DOMLinkAdded", DOMLinkHandler);
aTab.findbar = document.createXULElement("findbar");
aTab.findbar.setAttribute(
"browserid",
"preferencesTabBrowser" + this.lastBrowserId
);
aTab.panel.appendChild(aTab.findbar);
// Default to reload being disabled.
aTab.reloadEnabled = false;
aTab.url = "about:preferences";
aTab.paneID = aArgs.paneID;
aTab.scrollPaneTo = aArgs.scrollPaneTo;
aTab.otherArgs = aArgs.otherArgs;
// Now set up the listeners.
this._setUpTitleListener(aTab);
this._setUpCloseWindowListener(aTab);
// Wait for full loading of the tab and the automatic selecting of last tab.
// Then run the given onload code.
aTab.browser.addEventListener(
"paneSelected",
function (event) {
aTab.pageLoading = false;
aTab.pageLoaded = true;
if ("onLoad" in aArgs) {
// Let selection of the initial pane complete before selecting another.
// Otherwise we can end up with two panes selected at once.
aTab.browser.contentWindow.setTimeout(() => {
// By now, the tab could already be closed. Check that it isn't.
if (aTab.panel) {
aArgs.onLoad(event, aTab.browser);
}
}, 0);
}
},
{ once: true }
);
// Initialize our unit testing variables.
aTab.pageLoading = true;
aTab.pageLoaded = false;
// Now start loading the content.
aTab.title = this.loadingTabString;
ExtensionParent.apiManager.emit("extension-browser-inserted", aTab.browser);
const params = {
triggeringPrincipal: Services.scriptSecurityManager.getSystemPrincipal(),
postData: aArgs.postData || null,
};
aTab.browser.loadURI(Services.io.newURI("about:preferences"), params);
this.tab = aTab;
this.lastBrowserId++;
},
persistTab(aTab) {
if (aTab.browser.currentURI.spec == "about:blank") {
return null;
}
return {
paneID: aTab.paneID,
scrollPaneTo: aTab.scrollPaneTo,
otherArgs: aTab.otherArgs,
};
},
restoreTab(aTabmail, aPersistedState) {
aTabmail.openTab("preferencesTab", {
paneID: aPersistedState.paneID,
scrollPaneTo: aPersistedState.scrollPaneTo,
otherArgs: aPersistedState.otherArgs,
});
},
};
|