!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 DOM Inspector.
15 *
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.
20 *
21 * Contributor(s):
22 * Christopher A. Aillon <christopher@aillon.com>
23 * L. David Baron, Mozilla Corporation <dbaron@dbaron.org> (modified for reftest)
24 * Vladimir Vukicevic, Mozilla Corporation <dbaron@dbaron.org> (modified for tp)
25 *
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
37 *
38 * ***** END LICENSE BLOCK ***** */
39
40 // This only implements nsICommandLineHandler, since it needs
41 // to handle multiple arguments.
42
43 const TP_CMDLINE_CONTRACTID = "@mozilla.org/commandlinehandler/general-startup;1?type=tp";
44 const TP_CMDLINE_CLSID = Components.ID('{8AF052F5-8EFE-4359-8266-E16498A82E8B}');
45 const CATMAN_CONTRACTID = "@mozilla.org/categorymanager;1";
46 const nsISupports = Components.interfaces.nsISupports;
47
48 const nsICategoryManager = Components.interfaces.nsICategoryManager;
49 const nsICommandLine = Components.interfaces.nsICommandLine;
50 const nsICommandLineHandler = Components.interfaces.nsICommandLineHandler;
51 const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar;
52 const nsISupportsString = Components.interfaces.nsISupportsString;
53 const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher;
54
PageLoaderCmdLineHandler
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
55 function PageLoaderCmdLineHandler() {}
56 PageLoaderCmdLineHandler.prototype =
57 {
58 /* nsISupports */
handler_QI
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
59 QueryInterface : function handler_QI(iid) {
60 if (iid.equals(nsISupports))
61 return this;
62
63 if (nsICommandLineHandler && iid.equals(nsICommandLineHandler))
64 return this;
65
66 throw Components.results.NS_ERROR_NO_INTERFACE;
67 },
68
69 /* nsICommandLineHandler */
handler_handle
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
70 handle : function handler_handle(cmdLine) {
71 var args = {};
72 try {
73 var uristr = cmdLine.handleFlagWithParam("tp", false);
74 if (uristr == null)
75 return;
76 try {
77 args.manifest = cmdLine.resolveURI(uristr).spec;
78 } catch (e) {
79 return;
80 }
81
82 args.numCycles = cmdLine.handleFlagWithParam("tpcycles", false);
83 args.startIndex = cmdLine.handleFlagWithParam("tpstart", false);
84 args.endIndex = cmdLine.handleFlagWithParam("tpend", false);
85 args.filter = cmdLine.handleFlagWithParam("tpfilter", false);
86 args.format = cmdLine.handleFlagWithParam("tpformat", false);
87 args.useBrowserChrome = cmdLine.handleFlag("tpchrome", false);
88 args.doRender = cmdLine.handleFlag("tprender", false);
89 args.width = cmdLine.handleFlagWithParam("tpwidth", false);
90 args.height = cmdLine.handleFlagWithParam("tpheight", false);
91 args.offline = cmdLine.handleFlag("tpoffline", false);
92 args.noisy = cmdLine.handleFlag("tpnoisy", false);
93 args.timeout = cmdLine.handleFlagWithParam("tptimeout", false);
94 args.noForceCC = cmdLine.handleFlag("tpnoforcecc", false);
95 }
96 catch (e) {
97 return;
98 }
99
100 // get our data through xpconnect
101 args.wrappedJSObject = args;
102
103 var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
104 .getService(nsIWindowWatcher);
105 wwatch.openWindow(null, "chrome://pageloader/content/pageloader.xul", "_blank",
106 "chrome,dialog=no,all", args);
107 cmdLine.preventDefault = true;
108 },
109
110 helpInfo :
111 " -tp <file> Run pageload perf tests on given manifest\n" +
112 " -tpfilter str Only include pages from manifest that contain str (regexp)\n" +
113 " -tpcycles n Loop through pages n times\n" +
114 " -tpstart n Start at index n in the manifest\n" +
115 " -tpend n End with index n in the manifest\n" +
116 " -tpformat f1,f2,.. Report format(s) to use\n" +
117 " -tpchrome Test with normal browser chrome\n" +
118 " -tprender Run render-only benchmark for each page\n" +
119 " -tpwidth width Width of window\n" +
120 " -tpheight height Height of window\n" +
121 " -tpoffline Force offline mode\n" +
122 " -tpnoisy Dump the name of the last loaded page to console\n" +
123 " -tptimeout Max amount of time given for a page to load, quit if exceeded\n" +
124 " -tpnoforcecc Don't force cycle collection between each pageload\n"
125
126 };
127
128
129 var PageLoaderCmdLineFactory =
130 {
createInstance
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
131 createInstance : function(outer, iid)
132 {
133 if (outer != null) {
134 throw Components.results.NS_ERROR_NO_AGGREGATION;
135 }
136
137 return new PageLoaderCmdLineHandler().QueryInterface(iid);
138 }
139 };
140
141
142 var PageLoaderCmdLineModule =
143 {
registerSelf
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
144 registerSelf : function(compMgr, fileSpec, location, type)
145 {
146 compMgr = compMgr.QueryInterface(nsIComponentRegistrar);
147
148 compMgr.registerFactoryLocation(TP_CMDLINE_CLSID,
149 "PageLoader CommandLine Service",
150 TP_CMDLINE_CONTRACTID,
151 fileSpec,
152 location,
153 type);
154
155 var catman = Components.classes[CATMAN_CONTRACTID].getService(nsICategoryManager);
156 catman.addCategoryEntry("command-line-handler",
157 "m-tp",
158 TP_CMDLINE_CONTRACTID, true, true);
159 },
160
unregisterSelf
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
161 unregisterSelf : function(compMgr, fileSpec, location)
162 {
163 compMgr = compMgr.QueryInterface(nsIComponentRegistrar);
164
165 compMgr.unregisterFactoryLocation(TP_CMDLINE_CLSID, fileSpec);
166 catman = Components.classes[CATMAN_CONTRACTID].getService(nsICategoryManager);
167 catman.deleteCategoryEntry("command-line-handler",
168 "m-tp", true);
169 },
170
getClassObject
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
171 getClassObject : function(compMgr, cid, iid)
172 {
173 if (cid.equals(TP_CMDLINE_CLSID)) {
174 return PageLoaderCmdLineFactory;
175 }
176
177 if (!iid.equals(Components.interfaces.nsIFactory)) {
178 throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
179 }
180
181 throw Components.results.NS_ERROR_NO_INTERFACE;
182 },
183
canUnload
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
184 canUnload : function(compMgr)
185 {
186 return true;
187 }
188 };
189
190
NSGetModule
(0 calls, 0 incl. v-uS, 0 excl. v-uS)
191 function NSGetModule(compMgr, fileSpec) {
192 return PageLoaderCmdLineModule;
193 }