Commit 52fbcbfa authored by Arthur Edelstein's avatar Arthur Edelstein Committed by Georg Koppen
Browse files

Bug 20373: Prevent redundant dialogs opening

parent 7f16ada7
......@@ -9,6 +9,7 @@
let { LoadContextInfo } = Cu.import('resource://gre/modules/LoadContextInfo.jsm');
let { Services } = Cu.import("resource://gre/modules/Services.jsm");
let { showDialog } = Cu.import("resource://torbutton/modules/utils.js");
const k_tb_last_browser_version_pref = "extensions.torbutton.lastBrowserVersion";
const k_tb_browser_update_needed_pref = "extensions.torbutton.updateNeeded";
......@@ -824,9 +825,7 @@ function torbutton_on_abouttor_load(aDoc) {
label: button_label,
accessKey: 'S',
popup: null,
callback: function() {
window.openDialog("chrome://torbutton/content/preferences.xul",
"torbutton-preferences","chrome");}
callback: torbutton_open_prefs_dialog,
}];
let priority = box.PRIORITY_INFO_LOW;
......@@ -2127,14 +2126,15 @@ function torbutton_check_protections()
// Bug 1506 P2: I think cookie protections is a neat feature.
function torbutton_open_cookie_dialog() {
window.openDialog('chrome://torbutton/content/torcookiedialog.xul','Cookie Protections',
'centerscreen,chrome,dialog,modal,resizable');
showDialog(window, 'chrome://torbutton/content/torcookiedialog.xul',
'Cookie Protections', 'centerscreen,chrome,dialog,modal,resizable');
}
// Bug 1506 P2/P3: Prefs are handled differently on android, I guess?
function torbutton_open_prefs_dialog() {
window.openDialog("chrome://torbutton/content/preferences.xul","torbutton-preferences","centerscreen, chrome");
torbutton_log(2, 'opened preferences window');
showDialog(window, "chrome://torbutton/content/preferences.xul",
"torbutton-preferences","centerscreen, chrome");
torbutton_log(2, 'opened preferences window');
}
// Bug 1506 P0: Support code for checking Firefox versions. Not needed.
......
......@@ -52,5 +52,27 @@ var getEnv = function (name) {
return env.exists(name) ? env.get(name) : undefined;
};
// ## Windows
// __dialogsByName__.
// Map of window names to dialogs.
let dialogsByName = {};
// __showDialog(parent, url, name, features, arg1, arg2, ...)__.
// Like window.openDialog, but if the window is already
// open, just focuses it instead of opening a new one.
var showDialog = function (parent, url, name, features) {
let existingDialog = dialogsByName[name];
if (existingDialog && !existingDialog.closed) {
existingDialog.focus();
return existingDialog;
} else {
let newDialog = parent.openDialog.apply(parent,
Array.slice(arguments, 1));
dialogsByName[name] = newDialog;
return newDialog;
}
};
// Export utility functions for external use.
let EXPORTED_SYMBOLS = ["bindPrefAndInit", "getPrefValue", "getEnv"];
let EXPORTED_SYMBOLS = ["bindPrefAndInit", "getPrefValue", "getEnv", "showDialog"];
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment