|
1 <script> |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 /* |
|
7 From mozilla/toolkit/content |
|
8 These files did not have a license |
|
9 */ |
|
10 |
|
11 function quitHook() |
|
12 { |
|
13 var xhr = new XMLHttpRequest(); |
|
14 xhr.open("GET", "http://" + location.host + "/server/shutdown", true); |
|
15 xhr.onreadystatechange = function (event) |
|
16 { |
|
17 if (xhr.readyState == 4) |
|
18 goQuitApplication(); |
|
19 }; |
|
20 xhr.send(null); |
|
21 } |
|
22 |
|
23 function canQuitApplication() |
|
24 { |
|
25 var os = Components.classes["@mozilla.org/observer-service;1"] |
|
26 .getService(Components.interfaces.nsIObserverService); |
|
27 if (!os) |
|
28 { |
|
29 return true; |
|
30 } |
|
31 |
|
32 try |
|
33 { |
|
34 var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"] |
|
35 .createInstance(Components.interfaces.nsISupportsPRBool); |
|
36 os.notifyObservers(cancelQuit, "quit-application-requested", null); |
|
37 |
|
38 // Something aborted the quit process. |
|
39 if (cancelQuit.data) |
|
40 { |
|
41 return false; |
|
42 } |
|
43 } |
|
44 catch (ex) |
|
45 { |
|
46 } |
|
47 os.notifyObservers(null, "quit-application-granted", null); |
|
48 return true; |
|
49 } |
|
50 |
|
51 function goQuitApplication() |
|
52 { |
|
53 const privs = 'UniversalXPConnect'; |
|
54 |
|
55 try |
|
56 { |
|
57 netscape.security.PrivilegeManager.enablePrivilege(privs); |
|
58 } |
|
59 catch(ex) |
|
60 { |
|
61 throw('goQuitApplication: privilege failure ' + ex); |
|
62 } |
|
63 |
|
64 if (!canQuitApplication()) |
|
65 { |
|
66 return false; |
|
67 } |
|
68 |
|
69 const kAppStartup = '@mozilla.org/toolkit/app-startup;1'; |
|
70 const kAppShell = '@mozilla.org/appshell/appShellService;1'; |
|
71 var appService; |
|
72 var forceQuit; |
|
73 |
|
74 if (kAppStartup in Components.classes) |
|
75 { |
|
76 appService = Components.classes[kAppStartup]. |
|
77 getService(Components.interfaces.nsIAppStartup); |
|
78 forceQuit = Components.interfaces.nsIAppStartup.eForceQuit; |
|
79 |
|
80 } |
|
81 else if (kAppShell in Components.classes) |
|
82 { |
|
83 appService = Components.classes[kAppShell]. |
|
84 getService(Components.interfaces.nsIAppShellService); |
|
85 forceQuit = Components.interfaces.nsIAppShellService.eForceQuit; |
|
86 } |
|
87 else |
|
88 { |
|
89 throw 'goQuitApplication: no AppStartup/appShell'; |
|
90 } |
|
91 |
|
92 var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(); |
|
93 |
|
94 var windowManagerInterface = windowManager. |
|
95 QueryInterface(Components.interfaces.nsIWindowMediator); |
|
96 |
|
97 var enumerator = windowManagerInterface.getEnumerator(null); |
|
98 |
|
99 while (enumerator.hasMoreElements()) |
|
100 { |
|
101 var domWindow = enumerator.getNext(); |
|
102 if (("tryToClose" in domWindow) && !domWindow.tryToClose()) |
|
103 { |
|
104 return false; |
|
105 } |
|
106 domWindow.close(); |
|
107 } |
|
108 |
|
109 try |
|
110 { |
|
111 appService.quit(forceQuit); |
|
112 } |
|
113 catch(ex) |
|
114 { |
|
115 throw('goQuitApplication: ' + ex); |
|
116 } |
|
117 |
|
118 return true; |
|
119 } |
|
120 |
|
121 // bloat test driver for TestGtkEmbed |
|
122 // |
|
123 // set |user_pref("dom.allow_scripts_to_close_windows", true);| to |
|
124 // allow this to close the window when the loop is done. |
|
125 // |
|
126 // "ftp://ftp.mozilla.org", // not supported for TestGtkEmbed |
|
127 // |
|
128 |
|
129 var list = |
|
130 [ |
|
131 "sample.html", |
|
132 "forms.html", |
|
133 "grid.html", |
|
134 "forms.html", |
|
135 "elements.html" |
|
136 ]; |
|
137 var interval = 5000; // 15000 |
|
138 var idx = 0; |
|
139 var w; |
|
140 |
|
141 window.onload = function () { |
|
142 w = window.open("about:blank"); |
|
143 window.setTimeout(loadURL, interval); |
|
144 }; |
|
145 function loadURL () { |
|
146 w.location.href = list[idx++]; |
|
147 if (idx < list.length) { |
|
148 window.setTimeout(loadURL, interval); |
|
149 } else { |
|
150 if (navigator.platform.indexOf('Mac') != -1) { |
|
151 goQuitApplication(); |
|
152 } else { |
|
153 window.setTimeout("w.close();", interval); |
|
154 window.setTimeout("window.close();", interval*2); |
|
155 } |
|
156 } |
|
157 } |
|
158 var i; |
|
159 |
|
160 for(i=0; i < list.length;i++) { |
|
161 document.write(list[i]); |
|
162 document.write("<br>"); |
|
163 } |
|
164 </script> |