1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
* The contents of this file are subject to the Mozilla Public License Version
5
* 1.1 (the "License"); you may not use this file except in compliance with
6
* the License. You may obtain a copy of the License at
7
* http://www.mozilla.org/MPL/
9
* Software distributed under the License is distributed on an "AS IS" basis,
10
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
* for the specific language governing rights and limitations under the
14
* The Original Code is Mozilla Kill All.
16
* The Initial Developer of the Original Code is
17
* Netscape Communications Corp.
18
* Portions created by the Initial Developer are Copyright (C) 2002
19
* the Initial Developer. All Rights Reserved.
22
* Bill Law <law@netscape.com>
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the MPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the MPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
38
/* This file implements the nsICmdLineHandler interface. See nsICmdLineHandler.idl
39
* at http://lxr.mozilla.org/seamonkey/source/xpfe/appshell/public/nsICmdLineHandler.idl.
41
* This component handles the startup command line argument of the form:
43
* by closing all windows and shutting down turbo mode.
45
* The module is registered under the contractid
46
* "@mozilla.org/commandlinehandler/general-startup;1?type=killAll"
48
* The implementation consists of a JavaScript "class" named nsKillAll,
50
* - a JS constructor function
51
* - a prototype providing all the interface methods and implementation stuff
53
* In addition, this file implements an nsIModule object that registers the
54
* nsKillAll component.
59
function nsKillAll() {
62
nsKillAll.prototype = {
64
// nsICmdLineHandler interface
65
get commandLineArgument() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
66
get prefNameForStartup() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
68
get chromeUrlForTask() {
70
// turn off server mode
72
var wasMozillaAlreadyRunning = false;
73
var appShellService = Components.classes["@mozilla.org/appshell/appShellService;1"]
74
.getService(Components.interfaces.nsIAppShellService);
75
var nativeAppSupport = {isServerMode: false};
77
nativeAppSupport = appShellService.nativeAppSupport;
81
var originalServerMode = false;
82
if (nativeAppSupport.isServerMode) {
83
originalServerMode = true;
84
wasMozillaAlreadyRunning = true;
85
nativeAppSupport.isServerMode = false;
88
// stop all applications
90
var gObserverService = Components.classes["@mozilla.org/observer-service;1"]
91
.getService(Components.interfaces.nsIObserverService);
92
if (gObserverService) {
94
gObserverService.notifyObservers(null, "quit-application", null);
96
// dump("no observer found \n");
100
// close down all windows
103
Components.classes['@mozilla.org/appshell/window-mediator;1']
104
.getService(Components.interfaces.nsIWindowMediator);
105
var enumerator = windowManager.getEnumerator(null);
106
while(enumerator.hasMoreElements()) {
107
wasMozillaAlreadyRunning = true;
108
var domWindow = enumerator.getNext();
109
if (("tryToClose" in domWindow) && !domWindow.tryToClose()) {
110
// user pressed cancel in response to dialog for closing an unsaved window
111
nativeAppSupport.isServerMode = originalServerMode
112
// Return NS_ERROR_ABORT to inform caller of the "cancel."
113
throw Components.results.NS_ERROR_ABORT;
118
// exit without opening a new window
120
if (wasMozillaAlreadyRunning) {
121
// Need to exit appshell in this case.
122
appShellService.quit(Components.interfaces.nsIAppShellService.eAttemptQuit);
125
// We throw NS_ERROR_NOT_AVAILABLE which will be interpreted by the caller
126
// to mean that the command line handler is indicating that this should be a
127
// silent command and not cause any windows to open.
128
throw Components.results.NS_ERROR_NOT_AVAILABLE;
131
get helpText() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
132
get handlesArgs() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
133
get defaultArgs() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
134
get openWindowWithArgs() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
136
// nsISupports interface
138
// This "class" supports nsICmdLineHandler and nsISupports.
139
QueryInterface: function (iid) {
140
if (!iid.equals(Components.interfaces.nsICmdLineHandler) &&
141
!iid.equals(Components.interfaces.nsISupports)) {
142
throw Components.results.NS_ERROR_NO_INTERFACE;
147
// This Component's module implementation. All the code below is used to get this
148
// component registered and accessible via XPCOM.
150
// registerSelf: Register this component.
151
registerSelf: function (compMgr, fileSpec, location, type) {
152
var compReg = compMgr.QueryInterface( Components.interfaces.nsIComponentRegistrar );
153
compReg.registerFactoryLocation( this.cid,
154
"Kill All Component",
161
// getClassObject: Return this component's factory object.
162
getClassObject: function (compMgr, cid, iid) {
163
if (!cid.equals(this.cid))
164
throw Components.results.NS_ERROR_NO_INTERFACE;
166
if (!iid.equals(Components.interfaces.nsIFactory))
167
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
172
/* CID for this class */
173
cid: Components.ID("{F1F25940-4C8F-11d6-A651-0010A401EB10}"),
175
/* Contract ID for this class */
176
contractId: "@mozilla.org/commandlinehandler/general-startup;1?type=killAll",
180
// createInstance: Return a new nsKillAll object.
181
createInstance: function (outer, iid) {
183
throw Components.results.NS_ERROR_NO_AGGREGATION;
185
return (new nsKillAll()).QueryInterface(iid);
189
// canUnload: n/a (returns true)
190
canUnload: function(compMgr) {
196
// NSGetModule: Return the nsIModule object.
197
function NSGetModule(compMgr, fileSpec) {
198
return nsKillAll.prototype.module;