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 Default Browser.
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 making the current executable the "default browser." It accomplishes
44
* that via use of the nsIWindowsHooks interface (see implementation below).
46
* The module is registered under the contractid
47
* "@mozilla.org/commandlinehandler/general-startup;1?type=setDefaultBrowser"
49
* The implementation consists of a JavaScript "class" named nsKillAll,
51
* - a JS constructor function
52
* - a prototype providing all the interface methods and implementation stuff
54
* In addition, this file implements an nsIModule object that registers the
55
* nsSetDefaultBrowser component.
60
function nsSetDefaultBrowser() {
63
nsSetDefaultBrowser.prototype = {
65
// nsICmdLineHandler interface
66
get commandLineArgument() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
67
get prefNameForStartup() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
69
get chromeUrlForTask() {
70
// First, get winhooks service.
71
var winHooks = Components.classes[ "@mozilla.org/winhooks;1" ]
72
.getService( Components.interfaces.nsIWindowsHooks );
74
// Next, extract current settings (these are what the user
75
// had previously checked on the Advanced/System pref panel).
76
var settings = winHooks.settings;
78
// Now, turn on all "default browser" settings.
79
settings.isHandlingHTTP = true;
80
settings.isHandlingHTTPS = true;
81
settings.isHandlingFTP = true;
82
settings.isHandlingHTML = true;
83
settings.isHandlingXHTML = true;
84
settings.isHandlingXML = true;
86
// Finally, apply the (new) settings.
87
winHooks.settings = settings;
89
// Now, get the cmd line service.
90
var cmdLineService = Components.classes[ "@mozilla.org/app-startup/commandLineService;1" ]
91
.getService( Components.interfaces.nsICmdLineService );
93
// See if "-setDefaultBrowser" was specified. The value will be "1" if
94
// -setDefaultBrowser is in the service's list of cmd line arguments, and
95
// null otherwise. -setDefaultBrowser will only be in the service's
96
// arg list if the application was not already running. That's because
97
// if it was already running, then the service reflects the arguments
98
// that were specified when *that* process was started, *not* the ones
99
// passed via IPC from the second instance.
100
var option = cmdLineService.getCmdLineValue( "-setDefaultBrowser" );
102
// Already running, so we don't have to worry about opening
103
// another window, etc.
104
throw Components.results.NS_ERROR_NOT_AVAILABLE;
107
// Return URL for dummy window that will auto-close. We do this rather
108
// than throw NS_ERROR_NOT_AVAILABLE, which *should* work, because it
109
// seems that if we don't open a window, we get a crash when trying to
110
// release this (or some other) JS component during XPCOM shutdown.
111
return "chrome://global/content/dummyWindow.xul";
114
get helpText() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
115
get handlesArgs() { return false; },
116
get defaultArgs() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
117
get openWindowWithArgs() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; },
119
// nsISupports interface
121
// This "class" supports nsICmdLineHandler and nsISupports.
122
QueryInterface: function (iid) {
123
if (iid.equals(Components.interfaces.nsICmdLineHandler) ||
124
iid.equals(Components.interfaces.nsISupports))
127
Components.returnCode = Components.results.NS_ERROR_NO_INTERFACE;
131
// This Component's module implementation. All the code below is used to get this
132
// component registered and accessible via XPCOM.
134
// registerSelf: Register this component.
135
registerSelf: function (compMgr, fileSpec, location, type) {
136
var compReg = compMgr.QueryInterface( Components.interfaces.nsIComponentRegistrar );
137
compReg.registerFactoryLocation( this.cid,
138
"Default Browser Component",
145
// getClassObject: Return this component's factory object.
146
getClassObject: function (compMgr, cid, iid) {
147
if (!cid.equals(this.cid))
148
throw Components.results.NS_ERROR_NO_INTERFACE;
150
if (!iid.equals(Components.interfaces.nsIFactory))
151
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
156
/* CID for this class */
157
cid: Components.ID("{C66E05DC-509C-4972-A1F2-EE5AC34B9800}"),
159
/* Contract ID for this class */
160
contractId: "@mozilla.org/commandlinehandler/general-startup;1?type=setDefaultBrowser",
164
// createInstance: Return a new nsSetDefaultBrowser object.
165
createInstance: function (outer, iid) {
167
throw Components.results.NS_ERROR_NO_AGGREGATION;
169
return (new nsSetDefaultBrowser()).QueryInterface(iid);
173
// canUnload: n/a (returns true)
174
canUnload: function(compMgr) {
180
// NSGetModule: Return the nsIModule object.
181
function NSGetModule(compMgr, fileSpec) {
182
return nsSetDefaultBrowser.prototype.module;