From 3af66c6e0d3bedc2b5dc8698495473f39445d920 Mon Sep 17 00:00:00 2001 From: "sspitzer%mozilla.org" Date: Fri, 9 Jun 2006 07:53:12 +0000 Subject: [PATCH] fix for bug #333734. protect (warn) against opening too many tabs at once. r=ben, UI and strings r=beltzner --- .../components/places/content/controller.js | 50 +++++++++++++++++++ browser/components/preferences/tabs.xul | 4 ++ .../chrome/browser/places/places.properties | 5 ++ .../en-US/chrome/browser/preferences/tabs.dtd | 4 ++ modules/libpref/src/init/all.js | 2 + 5 files changed, 65 insertions(+) diff --git a/browser/components/places/content/controller.js b/browser/components/places/content/controller.js index f48aea85183a..ebe3c4d584f2 100755 --- a/browser/components/places/content/controller.js +++ b/browser/components/places/content/controller.js @@ -1327,6 +1327,56 @@ var PlacesController = { * See: https://bugzilla.mozilla.org/show_bug.cgi?id=331908 */ openLinksInTabs: function PC_openLinksInTabs() { + var pref = + Components.classes["@mozilla.org/preferences-service;1"]. + getService(Components.interfaces.nsIPrefBranch); + + const kWarnOnOpenPref = "browser.tabs.warnOnOpen"; + if (pref.getBoolPref(kWarnOnOpenPref)) + { + var reallyOpen = true; + + // determine how many tabs we are attempting to open + var node = this._activeView.selectedNode; + asFolder(node); + var wasOpen = node.containerOpen; + node.containerOpen = true; + var tabsToOpen = node.childCount; + node.containerOpen = wasOpen; + + if (tabsToOpen >= pref.getIntPref("browser.tabs.maxOpenBeforeWarn")) + { + var promptService = + Components.classes["@mozilla.org/embedcomp/prompt-service;1"]. + getService(Components.interfaces.nsIPromptService); + + // default to true: if it were false, we wouldn't get this far + var warnOnOpen = { value: true }; + + var messageKey = "tabs.openWarningMultiple"; + var openKey = "tabs.openButtonMultiple"; + var strings = document.getElementById("placeBundle"); + + var buttonPressed = promptService.confirmEx(window, + strings.getString("tabs.openWarningTitle"), + strings.getFormattedString(messageKey, [tabsToOpen]), + (promptService.BUTTON_TITLE_IS_STRING * promptService.BUTTON_POS_0) + + (promptService.BUTTON_TITLE_CANCEL * promptService.BUTTON_POS_1), + strings.getString(openKey), + null, null, + strings.getString("tabs.openWarningPromptMe"), + warnOnOpen); + + reallyOpen = (buttonPressed == 0); + // don't set the pref unless they press OK and it's false + if (reallyOpen && !warnOnOpen.value) + pref.setBoolPref(kWarnOnOpen, false); + } + + if (!reallyOpen) + return; + } + var node = this._activeView.selectedNode; if (this._activeView.hasSingleSelection && this.nodeIsFolder(node)) { // Check prefs to see whether to open over existing tabs. diff --git a/browser/components/preferences/tabs.xul b/browser/components/preferences/tabs.xul index 7144d3eb3f16..099a09aa84fb 100644 --- a/browser/components/preferences/tabs.xul +++ b/browser/components/preferences/tabs.xul @@ -55,6 +55,7 @@ +