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