!import
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3 *
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/
8 *
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
12 * License.
13 *
14 * The Original Code is Mozilla Seamonkey Composer.
15 *
16 * The Initial Developer of the Original Code is
17 * Benjamin Smedberg <bsmedberg@covad.net>.
18 * Portions created by the Initial Developer are Copyright (C) 2004
19 * the Initial Developer. All Rights Reserved.
20 *
21 * Contributor(s):
22 *
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 2 or later (the "GPL"), or
25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26 * in which case the provisions of the GPL or the LGPL are applicable instead
27 * of those above. If you wish to allow use of your version of this file only
28 * under the terms of either the GPL or the LGPL, and not to allow others to
29 * use your version of this file under the terms of the MPL, indicate your
30 * decision by deleting the provisions above and replace them with the notice
31 * and other provisions required by the GPL or the LGPL. If you do not delete
32 * the provisions above, a recipient may use your version of this file under
33 * the terms of any one of the MPL, the GPL or the LGPL.
34 *
35 * ***** END LICENSE BLOCK ***** */
36
37 const nsICmdLineHandler = Components.interfaces.nsICmdLineHandler;
38 const nsICommandLineHandler = Components.interfaces.nsICommandLineHandler;
39 const nsIFactory = Components.interfaces.nsIFactory;
40 const nsISupports = Components.interfaces.nsISupports;
41 const nsIModule = Components.interfaces.nsIModule;
42 const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar;
43 const nsICategoryManager = Components.interfaces.nsICategoryManager;
44 const nsISupportsString = Components.interfaces.nsISupportsString;
45 const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher;
46
47 const NS_ERROR_FAILURE = Components.results.NS_ERROR_FAILURE;
48 const NS_ERROR_NO_AGGREGATION = Components.results.NS_ERROR_NO_AGGREGATION;
49 const NS_ERROR_NO_INTERFACE = Components.results.NS_ERROR_NO_INTERFACE;
50
nsComposerCmdLineHandler
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
51 function nsComposerCmdLineHandler() {}
52 nsComposerCmdLineHandler.prototype = {
get_wrappedJSObject
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
53 get wrappedJSObject() {
54 return this;
55 },
56
57 /* nsISupports */
58
QueryInterface
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
59 QueryInterface: function(iid) {
60 if (iid.equals(nsISupports))
61 return this;
62
63 if (nsICmdLineHandler && iid.equals(nsICmdLineHandler))
64 return this;
65
66 if (nsICommandLineHandler && iid.equals(nsICommandLineHandler))
67 return this;
68
69 throw NS_ERROR_NO_INTERFACE;
70 },
71
72 /* nsICmdLineHandler */
73 commandLineArgument : "-edit",
74 prefNameForStartup : "general.startup.editor",
75 chromeUrlForTask : "chrome://editor/content/editor.xul",
76 helpText : "Start with editor.",
77 handlesArgs : true,
78 defaultArgs : "about:blank",
79 openWindowWithArgs : true,
80
81 /* nsICommandLineHandler */
handle
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
82 handle : function handle(cmdLine) {
83 var args = Components.classes["@mozilla.org/supports-string;1"]
84 .createInstance(nsISupportsString);
85 try {
86 var uristr = cmdLine.handleFlagWithParam("edit", false);
87 if (uristr == null) {
88 // Try the editor flag (used for general.startup.* prefs)
89 uristr = cmdLine.handleFlagWithParam("editor", false);
90 if (uristr == null)
91 return;
92 }
93
94 try {
95 args.data = cmdLine.resolveURI(uristr).spec;
96 }
97 catch (e) {
98 return;
99 }
100 }
101 catch (e) {
102 // One of the flags is present but no data, so set default arg.
103 args.data = "about:blank";
104 }
105
106 var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
107 .getService(nsIWindowWatcher);
108 wwatch.openWindow(null, "chrome://editor/content", "_blank",
109 "chrome,dialog=no,all", args);
110 cmdLine.preventDefault = true;
111 },
112
113 helpInfo : " -edit <url> Open Composer.\n"
114 };
115
nsComposerCmdLineHandlerFactory
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
116 function nsComposerCmdLineHandlerFactory() {
117 }
118
119 nsComposerCmdLineHandlerFactory.prototype = {
120 /* nsISupports */
121
QueryInterface
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
122 QueryInterface: function(iid) {
123 if (!iid.equals(nsIFactory) &&
124 !iid.equals(nsISupports)) {
125 throw Components.results.NS_ERROR_NO_INTERFACE;
126 }
127 return this;
128 },
129
130 /* nsIFactory */
createInstance
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
131 createInstance: function(outer, iid) {
132 if (outer != null) {
133 throw NS_ERROR_NO_AGGREGATION;
134 }
135
136 return new nsComposerCmdLineHandler().QueryInterface(iid);
137 },
138
lockFactory
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
139 lockFactory: function(lock) {
140 }
141 };
142
143 const nsComposerCmdLineHandler_CID =
144 Components.ID("{f7d8db95-ab5d-4393-a796-9112fe758cfa}");
145
146 const ContractIDPrefix =
147 "@mozilla.org/commandlinehandler/general-startup;1?type=";
148
149 var thisModule = {
150 /* nsISupports */
151
QueryInterface
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
152 QueryInterface: function(iid) {
153 if (!iid.equals(nsIModule) &&
154 !iid.equals(nsISupports)) {
155 throw Components.results.NS_ERROR_NO_INTERFACE;
156 }
157 return this;
158 },
159
160 /* nsIModule */
161
getClassObject
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
162 getClassObject: function (compMgr, cid, iid) {
163 if (!cid.equals(nsComposerCmdLineHandler_CID)) {
164 throw NS_ERROR_FAILURE;
165 }
166
167 if (!iid.equals(nsIFactory)) {
168 throw NS_ERROR_NO_INTERFACE;
169 }
170
171 return new nsComposerCmdLineHandlerFactory();
172 },
173
registerSelf
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
174 registerSelf: function (compMgr, fileSpec, location, type) {
175 var compReg = compMgr.QueryInterface(nsIComponentRegistrar);
176 compReg.registerFactoryLocation(nsComposerCmdLineHandler_CID,
177 "nsComposerCmdLineHandler",
178 ContractIDPrefix + "edit",
179 fileSpec, location, type);
180 compReg.registerFactoryLocation(nsComposerCmdLineHandler_CID,
181 "nsComposerCmdLineHandler",
182 ContractIDPrefix + "editor",
183 fileSpec, location, type);
184
185 var catMan = Components.classes["@mozilla.org/categorymanager;1"].getService(nsICategoryManager);
186 catMan.addCategoryEntry("command-line-argument-handlers",
187 "nsComposerCmdLineHandler",
188 ContractIDPrefix + "edit",
189 true, true);
190 catMan.addCategoryEntry("command-line-handler",
191 "m-edit",
192 ContractIDPrefix + "edit",
193 true, true);
194 },
195
unregisterSelf
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
196 unregisterSelf: function (compMgr, location, type) {
197 var compReg = compMgr.QueryInterface(nsIComponentRegistrar);
198 compReg.unregisterFactoryLocation(nsComposerCmdLineHandler_CID,
199 location);
200
201 var catMan = Components.classes["@mozilla.org/categorymanager;1"].getService(nsICategoryManager);
202 catMan.deleteCategoryEntry("command-line-argument-handlers",
203 "nsComposerCmdLineHandler", true);
204 catMan.deleteCategoryEntry("command-line-handler",
205 "m-edit", true);
206 },
207
canUnload
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
208 canUnload: function (compMgr) {
209 return true;
210 }
211 };
212
NSGetModule
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
213 function NSGetModule(compMgr, fileSpec) {
214 return thisModule;
215 }