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 this.EXPORTED_SYMBOLS = ["OpenInTabsUtils"];
9 const { XPCOMUtils } = ChromeUtils.import(
10 "resource://gre/modules/XPCOMUtils.jsm"
12 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
14 XPCOMUtils.defineLazyGetter(this, "bundle", function() {
15 return Services.strings.createBundle(
16 "chrome://browser/locale/tabbrowser.properties"
21 * Utility functions that can be used when opening multiple tabs, that can be
22 * called without any tabbrowser instance.
24 this.OpenInTabsUtils = {
26 return bundle.GetStringFromName(key);
29 getFormattedString(key, params) {
30 return bundle.formatStringFromName(key, params);
34 * Gives the user a chance to cancel loading lots of tabs at once.
36 confirmOpenInTabs(numTabsToOpen, aWindow) {
37 const WARN_ON_OPEN_PREF = "browser.tabs.warnOnOpen";
38 const MAX_OPNE_PREF = "browser.tabs.maxOpenBeforeWarn";
39 if (!Services.prefs.getBoolPref(WARN_ON_OPEN_PREF)) {
42 if (numTabsToOpen < Services.prefs.getIntPref(MAX_OPNE_PREF)) {
46 // default to true: if it were false, we wouldn't get this far
47 let warnOnOpen = { value: true };
49 const messageKey = "tabs.openWarningMultipleBranded";
50 const openKey = "tabs.openButtonMultiple";
51 const BRANDING_BUNDLE_URI = "chrome://branding/locale/brand.properties";
52 let brandShortName = Services.strings
53 .createBundle(BRANDING_BUNDLE_URI)
54 .GetStringFromName("brandShortName");
56 let buttonPressed = Services.prompt.confirmEx(
58 this.getString("tabs.openWarningTitle"),
59 this.getFormattedString(messageKey, [numTabsToOpen, brandShortName]),
60 Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_0 +
61 Services.prompt.BUTTON_TITLE_CANCEL * Services.prompt.BUTTON_POS_1,
62 this.getString(openKey),
65 this.getFormattedString("tabs.openWarningPromptMeBranded", [
71 let reallyOpen = buttonPressed == 0;
72 // don't set the pref unless they press OK and it's false
73 if (reallyOpen && !warnOnOpen.value) {
74 Services.prefs.setBoolPref(WARN_ON_OPEN_PREF, false);
81 * Async version of confirmOpenInTabs.
83 promiseConfirmOpenInTabs(numTabsToOpen, aWindow) {
84 return new Promise(resolve => {
85 Services.tm.dispatchToMainThread(() => {
86 resolve(this.confirmOpenInTabs(numTabsToOpen, aWindow));