[tbb-commits] [torbutton/master] Bug 20373: Prevent redundant dialogs opening
gk at torproject.org
gk at torproject.org
Mon Oct 17 07:12:46 UTC 2016
commit 52fbcbfa9df65d56dce5b1654c4d56012b3ff6a9
Author: Arthur Edelstein <arthuredelstein at gmail.com>
Date: Sat Oct 15 19:59:16 2016 -0700
Bug 20373: Prevent redundant dialogs opening
---
src/chrome/content/torbutton.js | 14 +++++++-------
src/modules/utils.js | 24 +++++++++++++++++++++++-
2 files changed, 30 insertions(+), 8 deletions(-)
diff --git a/src/chrome/content/torbutton.js b/src/chrome/content/torbutton.js
index 0f1046a..fa4009a 100644
--- a/src/chrome/content/torbutton.js
+++ b/src/chrome/content/torbutton.js
@@ -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.
diff --git a/src/modules/utils.js b/src/modules/utils.js
index eb0746b..514ef51 100644
--- a/src/modules/utils.js
+++ b/src/modules/utils.js
@@ -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"];
More information about the tbb-commits
mailing list