From c079cb29dc7f8376d3a1b02aff7c8301ee6632e5 Mon Sep 17 00:00:00 2001 From: Thomas Berezansky Date: Wed, 10 Aug 2011 21:02:51 -0400 Subject: [PATCH] Add openDialog to window class Uses window.openDialog instead of window.open. https://developer.mozilla.org/en/DOM/window.openDialog Signed-off-by: Thomas Berezansky Signed-off-by: Jason Etheridge --- .../chrome/content/util/window.js | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/Open-ILS/xul/staff_client/chrome/content/util/window.js b/Open-ILS/xul/staff_client/chrome/content/util/window.js index fc1c19aca8..dbacd795fc 100644 --- a/Open-ILS/xul/staff_client/chrome/content/util/window.js +++ b/Open-ILS/xul/staff_client/chrome/content/util/window.js @@ -59,6 +59,33 @@ util.window.prototype = { return w; }, + 'SafeWindowOpenDialog' : function (url,title,features) { + var w; + + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesRead"); + netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite"); + netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); + netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite"); + + const CI = Components.interfaces; + const PB = Components.classes["@mozilla.org/preferences-service;1"].getService(CI.nsIPrefBranch); + + var blocked = false; + try { + // pref 'dom.disable_open_during_load' is the main popup blocker preference + blocked = PB.getBoolPref("dom.disable_open_during_load"); + if(blocked) PB.setBoolPref("dom.disable_open_during_load",false); + w = this.win.openDialog.apply(this.win,arguments); + } catch(E) { + this.error.sdump('D_ERROR','window.SafeWindowOpen: ' + E + '\n'); + throw(E); + } + if(blocked) PB.setBoolPref("dom.disable_open_during_load",true); + + return w; + }, + 'open' : function(url,title,features,my_xulG) { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); var key; @@ -108,6 +135,59 @@ util.window.prototype = { ); */ return w; + }, + + 'openDialog' : function(url,title,features,my_xulG) { + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + var key; + if (!title) title = '_blank'; + if (!features) features = 'chrome'; // Note that this is a default for openDialog anyway + var outArgs = Array.prototype.slice.call(arguments); + outArgs.splice(3,1); // Remove my_xulG + this.error.sdump('D_WIN', 'opening ' + url + ', ' + title + ', ' + features + ' from ' + this.win + '\n'); + var data; + if (features.match(/modal/) && my_xulG) { + JSAN.use('OpenILS.data'); data = new OpenILS.data(); data.init({'via':'stash'}); + if (typeof data.modal_xulG_stack == 'undefined') data.modal_xulG_stack = {}; + /* FIXME - not a perfect key.. could imagine two top-level windows both opening modal windows */ + key = url; + if (typeof xulG == 'object') { + if (typeof xulG.url_prefix == 'function') { + key = key.replace( xulG.url_prefix('/'), '/' ); + } + } else if (typeof url_prefix == 'function') { + key = key.replace( url_prefix('/'), '/' ); + } + if (typeof data.modal_xulG_stack[key] == 'undefined') data.modal_xulG_stack[key] = []; + data.modal_xulG_stack[key].push( my_xulG ); + data.stash('modal_xulG_stack'); + this.error.sdump('D_WIN','modal key = ' + key); + } + var w = this.SafeWindowOpenDialog.apply(this, outArgs); + if (features.match(/modal/) && my_xulG) { + data.init({'via':'stash'}); + var x = data.modal_xulG_stack[key].pop(); + data.stash('modal_xulG_stack'); + w.focus(); + return x; + } else { + if (my_xulG) { + if (get_contentWindow(w)) { + get_contentWindow(w).xulG = my_xulG; + } else { + w.xulG = my_xulG; + } + } + } + /* + setTimeout( + function() { + try { w.title = title; } catch(E) { dump('**'+E+'\n'); } + try { w.document.title = title; } catch(E) { dump('**'+E+'\n'); } + }, 0 + ); + */ + return w; } } -- 2.43.2