comparison components/tp-cmdline.js @ 196:dd0018bc27de

Copy the pageloader from CVS and into a bundle format (single chrome.manifest).
author Benjamin Smedberg <benjamin@smedbergs.us>
date Wed, 21 Jul 2010 15:57:39 -0400
parents
children 31249cbe4f19
comparison
equal deleted inserted replaced
-1:000000000000 196:dd0018bc27de
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
55 function PageLoaderCmdLineHandler() {}
56 PageLoaderCmdLineHandler.prototype =
57 {
58 /* nsISupports */
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 */
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 {
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 function NSGetFactory(cid) {
142 if (!cid.equals(TP_CMDLINE_CLSID))
143 throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
144
145 return PageLoaderCmdLineFactory;
146 }
147
148 var PageLoaderCmdLineModule =
149 {
150 registerSelf : function(compMgr, fileSpec, location, type)
151 {
152 compMgr = compMgr.QueryInterface(nsIComponentRegistrar);
153
154 compMgr.registerFactoryLocation(TP_CMDLINE_CLSID,
155 "PageLoader CommandLine Service",
156 TP_CMDLINE_CONTRACTID,
157 fileSpec,
158 location,
159 type);
160
161 var catman = Components.classes[CATMAN_CONTRACTID].getService(nsICategoryManager);
162 catman.addCategoryEntry("command-line-handler",
163 "m-tp",
164 TP_CMDLINE_CONTRACTID, true, true);
165 },
166
167 unregisterSelf : function(compMgr, fileSpec, location)
168 {
169 compMgr = compMgr.QueryInterface(nsIComponentRegistrar);
170
171 compMgr.unregisterFactoryLocation(TP_CMDLINE_CLSID, fileSpec);
172 catman = Components.classes[CATMAN_CONTRACTID].getService(nsICategoryManager);
173 catman.deleteCategoryEntry("command-line-handler",
174 "m-tp", true);
175 },
176
177 getClassObject : function(compMgr, cid, iid)
178 {
179 return NSGetFactory(cid);
180 },
181
182 canUnload : function(compMgr)
183 {
184 return true;
185 }
186 };
187
188
189 function NSGetModule(compMgr, fileSpec) {
190 return PageLoaderCmdLineModule;
191 }