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') {
87 if (typeof xulG.url_prefix == 'function') {
88 key = key.replace( xulG.url_prefix('/'), '/' );
90 } else if (typeof url_prefix == 'function') {
91 key = key.replace( url_prefix('/'), '/' );
93 if (typeof data.modal_xulG_stack[key] == 'undefined') data.modal_xulG_stack[key] = [];
94 data.modal_xulG_stack[key].push( my_xulG );
95 data.stash('modal_xulG_stack');
96 this.error.sdump('D_WIN','modal key = ' + key);
98 var w = this.SafeWindowOpen(url,title,features);
99 if (features.match(/modal/) && my_xulG) {
100 data.init({'via':'stash'});
101 var x = data.modal_xulG_stack[key].pop();
102 data.stash('modal_xulG_stack');
106 if (get_contentWindow(w)) {
107 get_contentWindow(w).xulG = my_xulG;
116 try { w.title = title; } catch(E) { dump('**'+E+'\n'); }
117 try { w.document.title = title; } catch(E) { dump('**'+E+'\n'); }
125 dump('exiting util/window.js\n');