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 DOM Inspector.
16 * The Initial Developer of the Original Code is
17 * Christopher A. Aillon <christopher@aillon.com>.
18 * Portions created by the Initial Developer are Copyright (C) 2003
19 * the Initial Developer. All Rights Reserved.
22 * Christopher A. Aillon <christopher@aillon.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 // NOTE: this file implements both the seamonkey nsICmdLineHandler and
39 // the toolkit nsICommandLineHandler, using runtime detection.
41 const INSPECTOR_CMDLINE_CONTRACTID = "@mozilla.org/commandlinehandler/general-startup;1?type=inspector";
42 const INSPECTOR_CMDLINE_CLSID = Components.ID('{38293526-6b13-4d4f-a075-71939435b408}');
43 const CATMAN_CONTRACTID = "@mozilla.org/categorymanager;1";
44 const nsISupports = Components.interfaces.nsISupports;
46 const nsICategoryManager = Components.interfaces.nsICategoryManager;
47 const nsICmdLineHandler = Components.interfaces.nsICmdLineHandler;
48 const nsICommandLine = Components.interfaces.nsICommandLine;
49 const nsICommandLineHandler = Components.interfaces.nsICommandLineHandler;
50 const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar;
51 const nsISupportsString = Components.interfaces.nsISupportsString;
52 const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher;
54 function InspectorCmdLineHandler() {}
55 InspectorCmdLineHandler.prototype =
58 QueryInterface : function handler_QI(iid) {
59 if (iid.equals(nsISupports))
62 if (nsICmdLineHandler && iid.equals(nsICmdLineHandler))
65 if (nsICommandLineHandler && iid.equals(nsICommandLineHandler))
68 throw Components.results.NS_ERROR_NO_INTERFACE;
71 /* nsICmdLineHandler */
72 commandLineArgument : "-inspector",
73 prefNameForStartup : "general.startup.inspector",
74 chromeUrlForTask : "chrome://inspector/content/inspector.xul",
75 helpText : "Start with the DOM Inspector.",
78 openWindowWithArgs : true,
80 /* nsICommandLineHandler */
81 handle : function handler_handle(cmdLine) {
82 var args = Components.classes["@mozilla.org/supports-string;1"]
83 .createInstance(nsISupportsString);
85 var uristr = cmdLine.handleFlagWithParam("inspector", false);
89 args.data = cmdLine.resolveURI(uristr).spec;
96 cmdLine.handleFlag("inspector", true);
99 var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
100 .getService(nsIWindowWatcher);
101 wwatch.openWindow(null, "chrome://inspector/content/", "_blank",
102 "chrome,dialog=no,all", args);
103 cmdLine.preventDefault = true;
106 helpInfo : " -inspector <url> Open the DOM inspector.\n"
110 var InspectorCmdLineFactory =
112 createInstance : function(outer, iid)
115 throw Components.results.NS_ERROR_NO_AGGREGATION;
118 return new InspectorCmdLineHandler().QueryInterface(iid);
123 var InspectorCmdLineModule =
125 registerSelf : function(compMgr, fileSpec, location, type)
127 compMgr = compMgr.QueryInterface(nsIComponentRegistrar);
129 compMgr.registerFactoryLocation(INSPECTOR_CMDLINE_CLSID,
130 "DOM Inspector CommandLine Service",
131 INSPECTOR_CMDLINE_CONTRACTID,
136 var catman = Components.classes[CATMAN_CONTRACTID].getService(nsICategoryManager);
137 catman.addCategoryEntry("command-line-argument-handlers",
138 "inspector command line handler",
139 INSPECTOR_CMDLINE_CONTRACTID, true, true);
140 catman.addCategoryEntry("command-line-handler",
142 INSPECTOR_CMDLINE_CONTRACTID, true, true);
145 unregisterSelf : function(compMgr, fileSpec, location)
147 compMgr = compMgr.QueryInterface(nsIComponentRegistrar);
149 compMgr.unregisterFactoryLocation(INSPECTOR_CMDLINE_CLSID, fileSpec);
150 catman = Components.classes[CATMAN_CONTRACTID].getService(nsICategoryManager);
151 catman.deleteCategoryEntry("command-line-argument-handlers",
152 "inspector command line handler", true);
153 catman.deleteCategoryEntry("command-line-handler",
154 "m-inspector", true);
157 getClassObject : function(compMgr, cid, iid)
159 if (cid.equals(INSPECTOR_CMDLINE_CLSID)) {
160 return InspectorCmdLineFactory;
163 if (!iid.equals(Components.interfaces.nsIFactory)) {
164 throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
167 throw Components.results.NS_ERROR_NO_INTERFACE;
170 canUnload : function(compMgr)
177 function NSGetModule(compMgr, fileSpec) {
178 return InspectorCmdLineModule;