1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// Heavily inspired by Dave Townsend's post:
// Playing with windows in restartless (bootstrapped) extensions
// http://www.oxymoronical.com/blog/2011/01/Playing-with-windows-in-restartless-bootstrapped-extensions
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
var WindowListener = {
setupBrowserUI: function(domWindow) {
var doc = domWindow.document;
domWindow.kerberosauth_listener = kerberosauth_listener(domWindow);
doc.addEventListener('kerberos-auth-config', domWindow.kerberosauth_listener, false, true);
},
tearDownBrowserUI: function(domWindow) {
var doc = domWindow.document;
doc.removeEventListener('kerberos-auth-config', domWindow.kerberosauth_listener);
delete domWindow.kerberosauth_listener;
},
// nsIWindowMediatorListener functions
onOpenWindow: function(xulWindow) {
// A new window has opened
var domWindow = xulWindow.QueryInterface(Ci.nsIInterfaceRequestor).
getInterface(Ci.nsIDOMWindowInternal);
// Wait for it to finish loading
domWindow.addEventListener("load", function listener() {
domWindow.removeEventListener("load", listener, false);
// If this is a browser window then setup its UI
if (domWindow.document.documentElement.getAttribute("windowtype") === "navigator:browser") {
WindowListener.setupBrowserUI(domWindow);
}
}, false);
},
onCloseWindow: function(xulWindow) {
},
onWindowTitleChange: function(xulWindow, newTitle) {
}
};
function startup(data, reason) {
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
Cu['import']("chrome://kerberosauth/content/kerberosauth.js");
// Get the list of browser windows already open
var windows = wm.getEnumerator("navigator:browser");
while (windows.hasMoreElements()) {
var domWindow = windows.getNext().QueryInterface(Ci.nsIDOMWindow);
WindowListener.setupBrowserUI(domWindow);
}
// Wait for any new browser windows to open
wm.addListener(WindowListener);
}
function shutdown(data, reason) {
// When the application is shutting down we normally don't have to clean
// up any UI changes made
if (reason == APP_SHUTDOWN)
return;
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
getService(Ci.nsIWindowMediator);
// Get the list of browser windows already open
var windows = wm.getEnumerator("navigator:browser");
while (windows.hasMoreElements()) {
var domWindow = windows.getNext().QueryInterface(Ci.nsIDOMWindow);
WindowListener.tearDownBrowserUI(domWindow);
}
// Stop listening for any new browser windows to open
wm.removeListener(WindowListener);
Cu.unload("chrome://kerberosauth/content/kerberosauth.js");
}
function install() {}
function uninstall() {}
|