32 const Cc = Components.classes;
33 const Ci = Components.interfaces;
34 const Cr = Components.results;
35 const Cu = Components.utils;
49 if (/@ 0x/(__LOCATION__)) {
55 var
uri = aCmdLine.resolveURI(aArgument);
57 if (!(uri instanceof Components.interfaces.nsIFileURL)) {
66 if (aURI instanceof Components.interfaces.nsIFileURL)
67 if (aURI.file.exists())
78 var urifixup = Components.classes[
"@mozilla.org/docshell/urifixup;1"]
79 .getService(
Ci.nsIURIFixup);
81 aURI = urifixup.createFixupURI(aURL, 0);
91 if (!aURI || aURI ==
"")
return false;
92 if (aURI && !aURI.schemeIs(
"chrome"))
95 dump(
"*** Preventing external load of chrome URI into browser window (" + aURI.spec +
")\n");
96 dump(
" Use -chrome <uri> instead\n");
104 this.itemHandlers = [];
105 this.itemUriSpecs = [];
106 this.flagHandlers = [];
109 this.
gMM =
Cc[
"@songbirdnest.com/Songbird/Mediacore/Manager;1"].getService(
Ci.sbIMediacoreManager);
110 this.controller =
Cc[
'@songbirdnest.com/Songbird/ApplicationController;1'].getService(
Ci.sbIApplicationController);
115 helpInfo :
" -test [tests] Run tests on the components listed in the\n" +
116 " optional comma-separated list of tests.\n" +
117 " If no tests are passed in ALL tests will be run.\n" +
118 " [url|path] Local path/filename to media items to import and\n" +
119 " play, or URL to load in the browser.\n" +
120 " -register-extensions Registers extensions and then quits.\n" +
121 " -play Start/Resume playback at the current position.\n" +
122 " -stop Stop playback.\n" +
123 " -pause Pause playback.\n" +
124 " -toggle-playback Starts playback, if there is none and pauses it\n" +
125 " if media is currently playing.\n" +
126 " -next Skips to the next item in the sequence.\n" +
127 " -previous Goes back to the previous item in the sequence.\n" +
128 " -mute Mute the volume if it's not yet, else unmute it.\n" +
129 " -volumeup Raise the volume by 10%.\n" +
130 " -volumedown Lower the volume by 10%.\n",
138 handle :
function (cmdLine) {
141 var oldlength = this.itemUriSpecs.length;
143 if (cmdLine.handleFlag(
"register-extensions",
false)) {
144 _debugPrint(
"aborting due to handle of register-extensions");
145 throw Cr.NS_ERROR_ABORT;
149 if(cmdLine.handleFlag(
"play",
false)) {
150 if(this.
gMM.playbackControl)
151 this.
gMM.playbackControl.play();
153 this.controller.playDefault();
154 cmdLine.preventDefault =
true;
156 if(cmdLine.handleFlag(
"stop",
false)) {
157 if(this.
gMM.playbackControl)
158 this.
gMM.playbackControl.stop();
159 cmdLine.preventDefault =
true;
161 if(cmdLine.handleFlag(
"pause",
false)) {
162 if(this.
gMM.playbackControl)
163 this.
gMM.playbackControl.pause();
164 cmdLine.preventDefault =
true;
166 if(cmdLine.handleFlag(
"toggle-playback",
false)) {
167 if(this.
gMM.status.state ==
this.gMM.status.STATUS_PAUSED)
168 this.
gMM.playbackControl.play();
169 if(this.
gMM.status.state !=
this.gMM.status.STATUS_PLAYING)
170 this.controller.playDefault();
172 this.
gMM.playbackControl.pause();
173 cmdLine.preventDefault =
true;
175 if(cmdLine.handleFlag(
"next",
false)) {
176 if(this.
gMM.playbackControl)
177 this.
gMM.playbackControl.next();
178 cmdLine.preventDefault =
true;
180 if(cmdLine.handleFlag(
"previous",
false)) {
181 if(this.
gMM.playbackControl)
182 this.
gMM.playbackControl.previous();
183 cmdLine.preventDefault =
true;
185 if(cmdLine.handleFlag(
"mute",
false)) {
186 this.
gMM.volumeControl.mute = !this.
gMM.volumeControl.mute;
187 cmdLine.preventDefault =
true;
189 if(cmdLine.handleFlag(
"volumeup",
false)) {
190 this.
gMM.volumeControl.volume += 0.1;
191 cmdLine.preventDefault =
true;
193 if(cmdLine.handleFlag(
"volumedown",
false)) {
194 this.
gMM.volumeControl.volume -= 0.1;
195 cmdLine.preventDefault =
true;
200 while ((ar = cmdLine.handleFlagWithParam(
"url",
false))) {
211 .getService(
Ci.nsIObserverService);
220 var emptyParam =
false;
222 tests = cmdLine.handleFlagWithParam(
"test",
false);
232 if (tests !=
null || emptyParam) {
234 cmdLine.preventDefault =
true;
235 var testHarness =
Cc[
"@songbirdnest.com/Songbird/TestHarness;1"].getService(
Ci.sbITestHarness);
239 testHarness.init(tests);
247 var platformStr =
Cc[
"@mozilla.org/system-info;1"]
248 .getService(
Ci.nsIPropertyBag2).getProperty(
"name");
264 if (platformStr ==
"Darwin" ||
265 platformStr ==
"Windows_NT") {
266 var
ww =
Cc[
"@mozilla.org/embedcomp/window-watcher;1"]
267 .getService(
Ci.nsIWindowWatcher);
270 "chrome://songbird/content/xul/unitTestShutdownWin.xul",
271 "shutdownwin",
"chrome",
null);
279 var
os =
Cc[
"@mozilla.org/observer-service;1"].
283 var dummyCancelQuit =
Cc[
"@mozilla.org/supports-PRBool;1"].
285 os.notifyObservers(dummyCancelQuit,
"quit-application-requested",
null);
287 os.notifyObservers(
null,
"quit-application-granted",
null);
289 var appStartup =
Cc[
"@mozilla.org/toolkit/app-startup;1"]
290 .getService(
Ci.nsIAppStartup);
291 appStartup.quit(
Ci.nsIAppStartup.eAttemptQuit);
295 throw Cr.NS_ERROR_ABORT;
300 var
count = cmdLine.length;
308 var curarg = cmdLine.getArgument(
i);
310 Components.utils.reportError(e);
315 if (curarg ==
"")
continue;
316 if (curarg.match(/^-/)) {
323 cmdLine.removeArguments(
i,
i);
327 Components.utils.reportError(
"Error opening URI '" + curarg +
"' from the command line: " + e +
"\n");
332 for (var
uri in urilist) {
334 this.itemUriSpecs.push(urilist[uri].spec);
338 if (this.itemUriSpecs.length > oldlength)
339 this.dispatchItems();
341 this.handleRemainingFlags(cmdLine);
342 this.dispatchFlags();
345 handleURL:
function(aURL) {
346 var
ioService = Components.classes[
"@mozilla.org/network/io-service;1"]
347 .getService(Components.interfaces.nsIIOService);
351 this.itemUriSpecs.push(uri.spec);
352 this.dispatchItems();
356 handleRemainingFlags:
function(cmdLine) {
357 while (cmdLine.length) {
358 var curarg = cmdLine.getArgument(0);
359 if (curarg.match(/^-/)) {
360 var flag = curarg.slice(1);
364 var emptyParam =
false;
366 param = cmdLine.handleFlagWithParam(flag,
false);
373 cmdLine.handleFlag(flag,
false);
377 if (param !=
null || emptyParam) {
379 this.
flags.push([flag, param]);
386 cmdLine.removeArguments(0, 0);
391 addItemHandler:
function (aHandler) {
392 this.itemHandlers.push(aHandler);
394 this.dispatchItemsToHandler(aHandler);
397 removeItemHandler:
function(aHandler) {
398 var index = this.itemHandlers.indexOf(aHandler);
399 if (index != -1) this.itemHandlers.splice(index, 1);
402 dispatchItemsToHandler:
function(aHandler) {
404 var
total = this.itemUriSpecs.length;
405 for (var
i=0;
i < this.itemUriSpecs.length;
i++) {
406 if (aHandler.handleItem(
this.itemUriSpecs[
i], count++, total)) {
407 this.itemUriSpecs.splice(
i--, 1);
412 dispatchItems:
function() {
417 for (var handleridx = this.itemHandlers.length-1; handleridx >= 0; handleridx--) {
418 this.dispatchItemsToHandler(this.itemHandlers[handleridx]);
419 if (this.itemUriSpecs.length == 0)
break;
423 addFlagHandler:
function (aHandler, aFlag) {
424 var
entry = [aHandler, aFlag];
425 this.flagHandlers.push(entry);
427 this.dispatchFlagsToHandler(entry);
430 removeFlagHandler:
function(aHandler, aFlag) {
431 this.flagHandlers = this.flagHandlers.filter(
function(
entry) {
432 return !(
entry[0] == aHandler &&
entry[1] == aFlag);
436 dispatchFlagsToHandler:
function(aHandlerEntry) {
437 var
handler = aHandlerEntry[0];
438 var flag = aHandlerEntry[1];
439 for (var
i=0;
i < this.
flags.length;
i++) {
440 if (this.
flags[
i][0] == flag) {
441 if (handler.handleFlag(
this.flags[
i][0],
this.flags[
i][1])) {
442 this.
flags.splice(
i--, 1);
448 dispatchFlags:
function() {
453 for (var handleridx = this.flagHandlers.length-1; handleridx >= 0; handleridx--) {
454 this.dispatchFlagsToHandler(this.flagHandlers[handleridx]);
455 if (this.
flags.length == 0)
break;
460 if (iid.equals(
Ci.nsICommandLineHandler) ||
461 iid.equals(
Ci.sbICommandLineManager) ||
462 iid.equals(
Ci.nsISupports))
465 throw Cr.NS_ERROR_NO_INTERFACE;
473 registerSelf :
function (compMgr, fileSpec, location, type) {
474 compMgr.QueryInterface(
Ci.nsIComponentRegistrar);
482 var catMan =
Cc[
"@mozilla.org/categorymanager;1"].getService(
Ci.nsICategoryManager);
483 catMan.addCategoryEntry(
"command-line-handler",
492 throw Cr.NS_ERROR_NO_INTERFACE;
494 if (!iid.equals(
Ci.nsIFactory))
495 throw Cr.NS_ERROR_NOT_IMPLEMENTED;
497 return this.mFactory;
503 throw Cr.NS_ERROR_NO_AGGREGATION;
508 unregisterSelf :
function (compMgr, location, type) {
509 compMgr.QueryInterface(
Ci.nsIComponentRegistrar);
512 var catMan =
Cc[
"@mozilla.org/categorymanager;1"].getService(
Ci.nsICategoryManager);
516 canUnload :
function (compMgr) {
521 if ( !iid.equals(
Ci.nsIModule) ||
522 !iid.equals(
Ci.nsISupports) )
523 throw Cr.NS_ERROR_NO_INTERFACE;
function sbCommandLineHandler()
function shouldLoadURI(aURI)
static nsCOMPtr< nsIObserverService > observerService
SafebrowsingApplicationMod prototype registerSelf
const SONGBIRD_CLH_CLASSNAME
sbDeviceFirmwareAutoCheckForUpdate prototype flags
const SONGBIRD_CLH_CONTRACTID
sbOSDControlService prototype QueryInterface
function handle(request, response)
getService(Ci.sbIFaceplateManager)
SafebrowsingApplicationMod prototype getClassObject
function _debugPrint(msg)
function checkUri(aURI, aURL)
function resolveURIInternal(aCmdLine, aArgument)
function NSGetModule(comMgr, fileSpec)
const SONGBIRD_CLH_CATEGORY
_getSelectedPageStyle s i
const sbCommandLineHandlerModule