Bug 1506173 - use separate pref for warning on quit with sessionstore enabled, r=jaws,flod

Differential Revision: https://phabricator.services.mozilla.com/D13535

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Gijs Kruitbosch 2018-11-30 20:21:59 +00:00
Родитель 5918e7b11c
Коммит db2b40265a
7 изменённых файлов: 112 добавлений и 31 удалений

Просмотреть файл

@ -857,6 +857,9 @@ pref("browser.sessionstore.dom_storage_limit", 2048);
// Amount of failed SessionFile writes until we restart the worker.
pref("browser.sessionstore.max_write_failures", 5);
// Whether to warn the user when quitting, even though their tabs will be restored.
pref("browser.sessionstore.warnOnQuit", false);
// allow META refresh by default
pref("accessibility.blockautorefresh", false);

Просмотреть файл

@ -2661,7 +2661,7 @@ window._gBrowser = {
}
},
warnAboutClosingTabs(tabsToClose, aCloseTabs, aOptionalMessage) {
warnAboutClosingTabs(tabsToClose, aCloseTabs) {
if (tabsToClose <= 1)
return true;
@ -2682,24 +2682,20 @@ window._gBrowser = {
// solve the problem of windows "obscuring" the prompt.
// see bug #350299 for more details
window.focus();
var warningMessage;
if (aOptionalMessage) {
warningMessage = aOptionalMessage;
} else {
warningMessage =
PluralForm.get(tabsToClose, gTabBrowserBundle.GetStringFromName("tabs.closeWarningMultiple"))
.replace("#1", tabsToClose);
}
let warningMessage = gTabBrowserBundle.GetStringFromName("tabs.closeWarningMultiple");
warningMessage = PluralForm.get(tabsToClose, warningMessage).replace("#1", tabsToClose);
let flags = (ps.BUTTON_TITLE_IS_STRING * ps.BUTTON_POS_0) +
(ps.BUTTON_TITLE_CANCEL * ps.BUTTON_POS_1);
let checkboxLabel = aCloseTabs == this.closingTabsEnum.ALL ?
gTabBrowserBundle.GetStringFromName("tabs.closeWarningPromptMe") : null;
var buttonPressed =
ps.confirmEx(window,
gTabBrowserBundle.GetStringFromName("tabs.closeWarningTitle"),
gTabBrowserBundle.GetStringFromName("tabs.closeTitleTabs"),
warningMessage,
(ps.BUTTON_TITLE_IS_STRING * ps.BUTTON_POS_0) +
(ps.BUTTON_TITLE_CANCEL * ps.BUTTON_POS_1),
flags,
gTabBrowserBundle.GetStringFromName("tabs.closeButtonMultiple"),
null, null,
aCloseTabs == this.closingTabsEnum.ALL ?
gTabBrowserBundle.GetStringFromName("tabs.closeWarningPromptMe") : null,
checkboxLabel,
warnOnClose);
var reallyClose = (buttonPressed == 0);

Просмотреть файл

@ -1758,9 +1758,13 @@ BrowserGlue.prototype = {
// There are several cases where we won't show a dialog here:
// 1. There is only 1 tab open in 1 window
// 2. browser.warnOnQuit or browser.warnOnClose == false
// 2. browser.warnOnQuit == false
// 3. The browser is currently in Private Browsing mode
// 4. The browser will be restarted.
// 5. The user has automatic session restore enabled and
// browser.sessionstore.warnOnQuit is not set to true.
// 6. The user doesn't have automatic session restore enabled
// and browser.tabs.warnOnClose is not set to true.
//
// Otherwise, we will show the "closing multiple tabs" dialog.
//
@ -1792,28 +1796,65 @@ BrowserGlue.prototype = {
aQuitType = "quit";
// browser.warnOnQuit is a hidden global boolean to override all quit prompts
// browser.tabs.warnOnClose is the global "warn when closing multiple tabs" pref
if (!Services.prefs.getBoolPref("browser.warnOnQuit") ||
!Services.prefs.getBoolPref("browser.tabs.warnOnClose"))
if (!Services.prefs.getBoolPref("browser.warnOnQuit"))
return;
// If we're going to automatically restore the session, only warn if the user asked for that.
let sessionWillBeRestored = Services.prefs.getIntPref("browser.startup.page") == 3 ||
Services.prefs.getBoolPref("browser.sessionstore.resume_session_once");
// In the sessionWillBeRestored case, we only check the sessionstore-specific pref:
if (sessionWillBeRestored) {
if (!Services.prefs.getBoolPref("browser.sessionstore.warnOnQuit", false)) {
return;
}
// Otherwise, we check browser.tabs.warnOnClose
} else if (!Services.prefs.getBoolPref("browser.tabs.warnOnClose")) {
return;
}
let win = BrowserWindowTracker.getTopWindow();
// warnAboutClosingTabs checks browser.tabs.warnOnClose and returns if it's
// ok to close the window. It doesn't actually close the window.
if (windowcount == 1) {
aCancelQuit.data =
!win.gBrowser.warnAboutClosingTabs(pagecount, win.gBrowser.closingTabsEnum.ALL);
} else {
// More than 1 window. Compose our own message.
let warningMessage;
// More than 1 window. Compose our own message.
if (windowcount > 1) {
let tabSubstring = gTabbrowserBundle.GetStringFromName("tabs.closeWarningMultipleWindowsTabSnippet");
tabSubstring = PluralForm.get(pagecount, tabSubstring).replace(/#1/, pagecount);
let windowString = gTabbrowserBundle.GetStringFromName("tabs.closeWarningMultipleWindows");
let stringID = sessionWillBeRestored ? "tabs.closeWarningMultipleWindowsSessionRestore"
: "tabs.closeWarningMultipleWindows";
let windowString = gTabbrowserBundle.GetStringFromName(stringID);
windowString = PluralForm.get(windowcount, windowString).replace(/#1/, windowcount);
windowString = windowString.replace(/%(?:1\$)?S/i, tabSubstring);
aCancelQuit.data =
!win.gBrowser.warnAboutClosingTabs(pagecount, win.gBrowser.closingTabsEnum.ALL, windowString);
warningMessage = windowString.replace(/%(?:1\$)?S/i, tabSubstring);
} else {
let stringID = sessionWillBeRestored ? "tabs.closeWarningMultipleSessionRestore"
: "tabs.closeWarningMultiple";
warningMessage = gTabbrowserBundle.GetStringFromName(stringID);
warningMessage = PluralForm.get(pagecount, warningMessage).replace("#1", pagecount);
}
let warnOnClose = {value: true};
let titleId = AppConstants.platform == "win" ? "tabs.closeAndQuitTitleTabsWin"
: "tabs.closeAndQuitTitleTabs";
let flags = (Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_0) +
(Services.prompt.BUTTON_TITLE_CANCEL * Services.prompt.BUTTON_POS_1);
// Only display the checkbox in the non-sessionrestore case.
let checkboxLabel = !sessionWillBeRestored ?
gTabbrowserBundle.GetStringFromName("tabs.closeWarningPromptMe") : null;
// buttonPressed will be 0 for closing, 1 for cancel (don't close/quit)
let buttonPressed = Services.prompt.confirmEx(win,
gTabbrowserBundle.GetStringFromName(titleId),
warningMessage, flags,
gTabbrowserBundle.GetStringFromName("tabs.closeButtonMultiple"),
null, null,
checkboxLabel,
warnOnClose);
// If the user has unticked the box, and has confirmed closing, stop showing
// the warning.
if (!sessionWillBeRestored && buttonPressed == 0 && !warnOnClose.value) {
Services.prefs.setBoolPref("browser.tabs.warnOnClose", false);
}
aCancelQuit.data = buttonPressed != 0;
},
_showUpdateNotification: function BG__showUpdateNotification() {

Просмотреть файл

@ -77,6 +77,7 @@ Preferences.addAll([
// Startup
{ id: "browser.startup.page", type: "int" },
{ id: "browser.privatebrowsing.autostart", type: "bool" },
{ id: "browser.sessionstore.warnOnQuit", type: "bool" },
// Downloads
{ id: "browser.download.useDownloadDir", type: "bool" },
@ -735,14 +736,22 @@ var gMainPane = {
let newValue;
let checkbox = document.getElementById("browserRestoreSession");
let warnOnQuitCheckbox = document.getElementById("browserRestoreSessionQuitWarning");
if (pbAutoStartPref.value || startupPref.locked) {
checkbox.setAttribute("disabled", "true");
warnOnQuitCheckbox.setAttribute("disabled", "true");
} else {
checkbox.removeAttribute("disabled");
}
newValue = pbAutoStartPref.value ? false : startupPref.value === this.STARTUP_PREF_RESTORE_SESSION;
if (checkbox.checked !== newValue) {
checkbox.checked = newValue;
let warnOnQuitPref = Preferences.get("browser.sessionstore.warnOnQuit");
if (newValue && !warnOnQuitPref.locked && !pbAutoStartPref.value) {
warnOnQuitCheckbox.removeAttribute("disabled");
} else {
warnOnQuitCheckbox.setAttribute("disabled", "true");
}
}
},
@ -890,14 +899,20 @@ var gMainPane = {
const startupPref = Preferences.get("browser.startup.page");
let newValue;
let warnOnQuitCheckbox = document.getElementById("browserRestoreSessionQuitWarning");
if (value) {
// We need to restore the blank homepage setting in our other pref
if (startupPref.value === this.STARTUP_PREF_BLANK) {
Preferences.get("browser.startup.homepage").value = "about:blank";
}
newValue = this.STARTUP_PREF_RESTORE_SESSION;
let warnOnQuitPref = Preferences.get("browser.sessionstore.warnOnQuit");
if (!warnOnQuitPref.locked) {
warnOnQuitCheckbox.removeAttribute("disabled");
}
} else {
newValue = this.STARTUP_PREF_HOMEPAGE;
warnOnQuitCheckbox.setAttribute("disabled", "true");
}
startupPref.value = newValue;
},

Просмотреть файл

@ -46,6 +46,12 @@
<vbox id="startupPageBox">
<checkbox id="browserRestoreSession"
data-l10n-id="startup-restore-previous-session"/>
<hbox class="indent">
<checkbox id="browserRestoreSessionQuitWarning"
preference="browser.sessionstore.warnOnQuit"
disabled="true"
data-l10n-id="startup-restore-warn-on-quit"/>
</hbox>
</vbox>
#ifdef HAVE_SHELL_SERVICE

Просмотреть файл

@ -162,6 +162,9 @@ startup-restore-previous-session =
.label = Restore previous session
.accesskey = s
startup-restore-warn-on-quit =
.label = Warn you when quitting the browser
disable-extension =
.label = Disable Extension

Просмотреть файл

@ -6,25 +6,42 @@ tabs.emptyTabTitle=New Tab
tabs.emptyPrivateTabTitle=Private Browsing
tabs.closeTab=Close Tab
tabs.close=Close
tabs.closeWarningTitle=Confirm close
tabs.closeTitleTabs=Close tabs?
tabs.closeAndQuitTitleTabs=Quit and close tabs?
tabs.closeAndQuitTitleTabsWin=Exit and close tabs?
# LOCALIZATION NOTE (tabs.closeWarningMultiple):
# Semicolon-separated list of plural forms. See:
# http://developer.mozilla.org/en/docs/Localization_and_Plurals
# The singular form is not considered since this string is used only for
# multiple tabs.
tabs.closeWarningMultiple=;You are about to close #1 tabs. Are you sure you want to continue?
# LOCALIZATION NOTE (tabs.closeWarningMultipleSessionRestore):
# Semicolon-separated list of plural forms. See:
# http://developer.mozilla.org/en/docs/Localization_and_Plurals
# The singular form is not considered since this string is used only for
# multiple tabs.
tabs.closeWarningMultipleSessionRestore=;You are about to close #1 tabs. These tabs will be restored when you restart. Are you sure you want to continue?
tabs.closeButtonMultiple=Close tabs
tabs.closeWarningPromptMe=Warn me when I attempt to close multiple tabs
# LOCALIZATION NOTE (tabs.closeWarningMultipleWindows):
# Semicolon-separated list of plural forms. See:
# http://developer.mozilla.org/en/docs/Localization_and_Plurals
# The singular form is not considered since this string is used only for
# The forms for 0 or 1 items are not considered since this string is used only for
# multiple windows. The %S replacement form will be replaced with the contents
# of tabs.closeWarningMultipleWindowsTabSnippet, which will contain the number
# of tabs in these windows.
# Note that every one of these plural forms must contain one instance of '%S'.
tabs.closeWarningMultipleWindows=;You are about to close #1 windows %S. Are you sure you want to continue?
# LOCALIZATION NOTE (tabs.closeWarningMultipleWindowsSessionRestore):
# Semicolon-separated list of plural forms. See:
# http://developer.mozilla.org/en/docs/Localization_and_Plurals
# The forms for 0 or 1 items are not considered since this string is used only for
# multiple windows. The %S replacement form will be replaced with the contents
# of tabs.closeWarningMultipleWindowsTabSnippet, which will contain the number
# of tabs in these windows.
# Note that every one of these plural forms must contain one instance of '%S'.
tabs.closeWarningMultipleWindowsSessionRestore=;You are about to close #1 windows %S. These tabs will be restored when you restart. Are you sure you want to continue?
# LOCALIZATION NOTE (tabs.closeWarningMultipleWindowsTabSnippet):
# Semicolon-separated list of plural forms. See: