forked from simplesamlphp/SAML-tracer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.js
146 lines (121 loc) · 4.88 KB
/
bootstrap.js
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// This bootstrap.js file is based upon the template available here:
// https://developer.mozilla.org/en-US/Add-ons/Firefox_for_Android/Initialization_and_Cleanup#template_code
// The onOpenWindow event handler was slightly modified to be compatible with standard Firefox.
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cu = Components.utils;
Cu.import("resource:///modules/CustomizableUI.jsm");
Cu.import('resource://gre/modules/Services.jsm');
var css_uri = Services.io.newURI("chrome://samltrace/skin/button.css", null, null);
var strings = Services.strings.createBundle('chrome://samltrace/locale/samltrace.properties');
var tracerWindow = null;
function showTracerWindow() {
if (tracerWindow != null) {
// Window already opened -- just give it focus.
tracerWindow.focus();
return;
}
tracerWindow = Services.ww.openWindow(null, "chrome://samltrace/content/TraceWindow.xul", "global:samltrace", "chrome,centerscreen", null);
tracerWindow.addEventListener('close', function() {
tracerWindow = null;
});
}
function loadIntoWindow(window) {
if (!window)
return;
// Add our style sheet
window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).loadSheet(css_uri, 1);
// Add an entry to the tools menu.
let menuToolsPopup = window.document.getElementById('menu_ToolsPopup');
if (menuToolsPopup) {
let mi = window.document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'menuitem');
mi.setAttribute('label', strings.GetStringFromName('samltrace.open.label'));
mi.setAttribute('id', 'samltrace-menu-open');
mi.addEventListener('command', showTracerWindow);
menuToolsPopup.appendChild(mi);
}
// Add it to the web developer menu.
let menuWebDevPopup = window.document.getElementById('appmenu_webDeveloper_popup');
if (menuWebDevPopup) {
let mi = window.document.createElementNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'menuitem');
mi.setAttribute('label', strings.GetStringFromName('samltrace.open.label'));
mi.setAttribute('id', 'samltrace-appmenu-open');
mi.addEventListener('command', showTracerWindow);
let errConsole = window.document.getElementById("appmenu_errorConsole");
if (errConsole && errConsole.parentNode == menuWebDevPopup) {
/* Insert it before the error console, if it is in the menu. */
menuWebDevPopup.insertBefore(mi, errConsole);
} else {
/* No error console -- just append it to the end. */
menuWebDevPopup.appendChild(mi);
}
}
}
function unloadFromWindow(window) {
if (!window)
return;
// Clean up menu entries.
let toolsOpen = window.document.getElementById('samltrace-menu-open');
if (toolsOpen) {
toolsOpen.parentNode.removeChild(toolsOpen);
}
let appMenuOpen = window.document.getElementById('samltrace-appmenu-open');
if (appMenuOpen) {
appMenuOpen.parentNode.removeChild(appMenuOpen);
}
// Remove our style sheet
window.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils).removeSheet(css_uri, 1);
}
var windowListener = {
onOpenWindow: function(aWindow) {
// Wait for the window to finish loading
let domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindow);
domWindow.addEventListener("load", function onLoad() {
domWindow.removeEventListener("load", onLoad, false);
loadIntoWindow(domWindow);
}, false);
},
onCloseWindow: function(aWindow) {},
onWindowTitleChange: function(aWindow, aTitle) {}
};
function startup(aData, aReason) {
// Load into any existing windows
let windows = Services.wm.getEnumerator("navigator:browser");
while (windows.hasMoreElements()) {
let domWindow = windows.getNext().QueryInterface(Ci.nsIDOMWindow);
loadIntoWindow(domWindow);
}
// Load into any new windows
Services.wm.addListener(windowListener);
// Add button to panel.
CustomizableUI.createWidget({
id: "samltrace-showtracer",
defaultArea: CustomizableUI.AREA_PANEL,
removable: true,
label: strings.GetStringFromName('samltrace.open.label'),
onCommand: showTracerWindow
});
}
function shutdown(aData, aReason) {
// When the application is shutting down we normally don't have to clean
// up any UI changes made
if (aReason == APP_SHUTDOWN) {
return;
}
// Close the SAML tracer window if it is open.
if (tracerWindow != null) {
tracerWindow.close();
tracerWindow = null;
}
// Stop listening for new windows
Services.wm.removeListener(windowListener);
// Unload from any existing windows
let windows = Services.wm.getEnumerator("navigator:browser");
while (windows.hasMoreElements()) {
let domWindow = windows.getNext().QueryInterface(Ci.nsIDOMWindow);
unloadFromWindow(domWindow);
}
CustomizableUI.destroyWidget("samltrace-showtracer");
}
function install(aData, aReason) {}
function uninstall(aData, aReason) {}