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 file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 ChromeUtils.defineLazyGetter(lazy, "l10n", () => {
8 return new Localization(
9 ["browser/tabbrowser.ftl", "branding/brand.ftl"],
15 * Utility functions that can be used when opening multiple tabs, that can be
16 * called without any tabbrowser instance.
18 export const OpenInTabsUtils = {
20 * Gives the user a chance to cancel loading lots of tabs at once.
22 confirmOpenInTabs(numTabsToOpen, aWindow) {
23 const WARN_ON_OPEN_PREF = "browser.tabs.warnOnOpen";
24 const MAX_OPNE_PREF = "browser.tabs.maxOpenBeforeWarn";
25 if (!Services.prefs.getBoolPref(WARN_ON_OPEN_PREF)) {
28 if (numTabsToOpen < Services.prefs.getIntPref(MAX_OPNE_PREF)) {
32 // default to true: if it were false, we wouldn't get this far
33 let warnOnOpen = { value: true };
35 const [title, message, button, checkbox] = lazy.l10n.formatMessagesSync([
36 { id: "tabbrowser-confirm-open-multiple-tabs-title" },
38 id: "tabbrowser-confirm-open-multiple-tabs-message",
39 args: { tabCount: numTabsToOpen },
41 { id: "tabbrowser-confirm-open-multiple-tabs-button" },
42 { id: "tabbrowser-confirm-open-multiple-tabs-checkbox" },
45 let buttonPressed = Services.prompt.confirmEx(
49 Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_0 +
50 Services.prompt.BUTTON_TITLE_CANCEL * Services.prompt.BUTTON_POS_1,
58 let reallyOpen = buttonPressed == 0;
59 // don't set the pref unless they press OK and it's false
60 if (reallyOpen && !warnOnOpen.value) {
61 Services.prefs.setBoolPref(WARN_ON_OPEN_PREF, false);
68 * Async version of confirmOpenInTabs.
70 promiseConfirmOpenInTabs(numTabsToOpen, aWindow) {
71 return new Promise(resolve => {
72 Services.tm.dispatchToMainThread(() => {
73 resolve(this.confirmOpenInTabs(numTabsToOpen, aWindow));