1 dump('entering util/window.js\n');
3 if (typeof util == 'undefined') util = {};
4 util.window = function () {
5 JSAN.use('util.error'); this.error = new util.error(); this.win = window;
9 util.window.prototype = {
11 // list of open window references, used for debugging in shell
14 // list of Top Level menu interface window references
17 // list of documents for debugging. BROKEN
20 // Windows need unique names. This number helps.
21 'window_name_increment' : function() {
22 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
23 if (typeof data.window_name_increment == 'undefined') {
24 data.window_name_increment = 1;
26 data.window_name_increment++;
28 data.stash('window_name_increment');
29 return data.window_name_increment;
32 // This number gets put into the title bar for Top Level menu interface windows
33 'appshell_name_increment' : function() {
34 JSAN.use('OpenILS.data'); var data = new OpenILS.data(); data.init({'via':'stash'});
35 if (typeof data.appshell_name_increment == 'undefined') {
36 data.appshell_name_increment = 1;
38 data.appshell_name_increment++;
40 data.stash('appshell_name_increment');
41 return data.appshell_name_increment;
44 // From: Bryan White on netscape.public.mozilla.xpfe, Oct 13, 2004
45 // Message-ID: <ckjh7a$18q1@ripley.netscape.com>
46 // Modified by Jason for Evergreen
47 'SafeWindowOpen' : function (url,title,features) {
50 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
51 netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesRead");
52 netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite");
53 netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
54 netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserWrite");
56 const CI = Components.interfaces;
57 const PB = Components.classes["@mozilla.org/preferences-service;1"].getService(CI.nsIPrefBranch);
61 // pref 'dom.disable_open_during_load' is the main popup blocker preference
62 blocked = PB.getBoolPref("dom.disable_open_during_load");
63 if(blocked) PB.setBoolPref("dom.disable_open_during_load",false);
64 w = this.win.open(url,title,features);
66 this.error.sdump('D_ERROR','window.SafeWindowOpen: ' + E + '\n');
69 if(blocked) PB.setBoolPref("dom.disable_open_during_load",true);
74 'open' : function(url,title,features,my_xulG) {
75 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
77 if (!title) title = 'anon' + this.window_name_increment();
78 if (!features) features = 'chrome';
79 this.error.sdump('D_WIN', 'opening ' + url + ', ' + title + ', ' + features + ' from ' + this.win + '\n');
81 if (features.match(/modal/) && my_xulG) {
82 JSAN.use('OpenILS.data'); data = new OpenILS.data(); data.init({'via':'stash'});
83 if (typeof data.modal_xulG_stack == 'undefined') data.modal_xulG_stack = {};
84 /* FIXME - not a perfect key.. could imagine two top-level windows both opening modal windows */
86 if (typeof xulG == 'object') if (typeof xulG.url_prefix == 'function') {
87 key = key.replace( xulG.url_prefix('/'), '/' );
89 if (typeof data.modal_xulG_stack[key] == 'undefined') data.modal_xulG_stack[key] = [];
90 data.modal_xulG_stack[key].push( my_xulG );
91 data.stash('modal_xulG_stack');
92 this.error.sdump('D_WIN','modal key = ' + key);
94 var w = this.SafeWindowOpen(url,title,features);
95 if (features.match(/modal/) && my_xulG) {
96 var x = data.modal_xulG_stack[key].pop();
97 data.stash('modal_xulG_stack');
101 if (w.contentWindow) {
102 w.contentWindow.xulG = my_xulG;
111 try { w.title = title; } catch(E) { dump('**'+E+'\n'); }
112 try { w.document.title = title; } catch(E) { dump('**'+E+'\n'); }
120 dump('exiting util/window.js\n');