in suite/browser/nsBrowserContentHandler.js [231:498]
handle: function handle(cmdLine) {
var features = "chrome,all,dialog=no";
try {
var width = cmdLine.handleFlagWithParam("width", false);
if (width != null)
features += ",width=" + width;
} catch (e) {
}
try {
var height = cmdLine.handleFlagWithParam("height", false);
if (height != null)
features += ",height=" + height;
} catch (e) {
}
try {
var remote = cmdLine.handleFlagWithParam("remote", true);
if (/^\s*(\w+)\s*\(\s*([^\s,]+)\s*,?\s*([^\s]*)\s*\)\s*$/.test(remote)) {
switch (RegExp.$1.toLowerCase()) {
case "openurl":
case "openfile":
// openURL(<url>)
// openURL(<url>,new-window)
// openURL(<url>,new-tab)
var uri = resolveURIInternal(cmdLine, RegExp.$2);
var location = nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW;
if (RegExp.$3 == "new-window")
location = nsIBrowserDOMWindow.OPEN_NEWWINDOW;
else if (RegExp.$3 == "new-tab")
location = nsIBrowserDOMWindow.OPEN_NEWTAB;
handURIToExistingBrowser(uri, location, features,
Services.scriptSecurityManager.getSystemPrincipal());
break;
case "mailto":
openWindow(null, "chrome://messenger/content/messengercompose/messengercompose.xul", features, RegExp.$2);
break;
case "xfedocommand":
switch (RegExp.$2.toLowerCase()) {
case "openbrowser":
openWindow(null, getBrowserURL(), features, RegExp.$3 || getURLToLoad());
break;
case "openinbox":
openWindow(null, "chrome://messenger/content", features);
break;
case "composemessage":
openWindow(null, "chrome://messenger/content/messengercompose/messengercompose.xul", features, RegExp.$3);
break;
default:
throw Cr.NS_ERROR_ABORT;
}
break;
default:
// Somebody sent us a remote command we don't know how to process:
// just abort.
throw Cr.NS_ERROR_ABORT;
}
cmdLine.preventDefault = true;
}
} catch (e) {
// If we had a -remote flag but failed to process it, throw
// NS_ERROR_ABORT so that the xremote code knows to return a failure
// back to the handling code.
throw Cr.NS_ERROR_ABORT;
}
try {
var browserParam = cmdLine.handleFlagWithParam("browser", false);
if (browserParam) {
openWindow(null, getBrowserURL(), features, browserParam);
cmdLine.preventDefault = true;
}
} catch (e) {
if (cmdLine.handleFlag("browser", false)) {
openWindow(null, getBrowserURL(), features, getURLToLoad());
cmdLine.preventDefault = true;
}
}
try {
var privateParam = cmdLine.handleFlagWithParam("private", false);
if (privateParam) {
openWindow(null, getBrowserURL(), "private," + features, privateParam);
cmdLine.preventDefault = true;
}
} catch (e) {
if (cmdLine.handleFlag("private", false)) {
openWindow(null, getBrowserURL(), "private," + features, "about:privatebrowsing");
cmdLine.preventDefault = true;
}
}
// If we don't have a profile selected yet (e.g. the Profile Manager is
// displayed) we will crash if we open an url and then select a profile. To
// prevent this handle all url command line flag and set the command line's
// preventDefault to true to prevent the display of the ui. The initial
// command line will be retained when nsAppRunner calls LaunchChild though
// urls launched after the initial launch will be lost.
try {
// This will throw when a profile has not been selected.
Services.dirsvc.get("ProfD", Ci.nsIFile);
} catch (e) {
cmdLine.preventDefault = true;
throw Cr.NS_ERROR_ABORT;
}
try {
var urlParam = cmdLine.handleFlagWithParam("url", false);
if (urlParam) {
if (this._handledURI == urlParam) {
this._handledURI = null;
} else {
if (cmdLine.handleFlag("requestpending", false) &&
cmdLine.state == nsICommandLine.STATE_INITIAL_LAUNCH) {
// A DDE request with the URL will follow and the DDE handling code
// will send it to the commandline handler via
// "mozilla -url http://www.foo.com". Store the URL so we can
// ignore this request later
this._handledURI = urlParam;
}
urlParam = resolveURIInternal(cmdLine, urlParam);
handURIToExistingBrowser(urlParam,
nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW,
features,
Services.scriptSecurityManager.getSystemPrincipal());
}
cmdLine.preventDefault = true;
}
} catch (e) {
}
var param;
try {
while ((param = cmdLine.handleFlagWithParam("new-window", false)) != null) {
var uri = resolveURIInternal(cmdLine, param);
handURIToExistingBrowser(uri,
nsIBrowserDOMWindow.OPEN_NEWWINDOW,
features,
Services.scriptSecurityManager.getSystemPrincipal());
cmdLine.preventDefault = true;
}
} catch (e) {
}
try {
while ((param = cmdLine.handleFlagWithParam("new-tab", false)) != null) {
var uri = resolveURIInternal(cmdLine, param);
handURIToExistingBrowser(uri,
nsIBrowserDOMWindow.OPEN_NEWTAB,
features,
Services.scriptSecurityManager.getSystemPrincipal());
cmdLine.preventDefault = true;
}
} catch (e) {
}
try {
var chromeParam = cmdLine.handleFlagWithParam("chrome", false);
if (chromeParam) {
// only load URIs which do not inherit chrome privs
var uri = resolveURIInternal(cmdLine, chromeParam);
if (!Services.netUtils.URIChainHasFlags(uri, URI_INHERITS_SECURITY_CONTEXT)) {
openWindow(null, uri.spec, features);
cmdLine.preventDefault = true;
}
}
} catch (e) {
}
try {
var fileParam = cmdLine.handleFlagWithParam("file", false);
if (fileParam) {
fileParam = resolveURIInternal(cmdLine, fileParam);
handURIToExistingBrowser(fileParam,
nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW,
features,
Services.scriptSecurityManager.getSystemPrincipal());
cmdLine.preventDefault = true;
}
} catch (e) {
}
var searchParam = cmdLine.handleFlagWithParam("search", false);
if (searchParam) {
doSearch(searchParam, features);
cmdLine.preventDefault = true;
}
if (cmdLine.handleFlag("preferences", false)) {
openPreferences();
cmdLine.preventDefault = true;
}
if (cmdLine.handleFlag("silent", false))
cmdLine.preventDefault = true;
if (!cmdLine.preventDefault && cmdLine.length) {
var arg = cmdLine.getArgument(0);
if (!/^-/.test(arg)) {
try {
arg = resolveURIInternal(cmdLine, arg);
handURIToExistingBrowser(arg,
nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW,
features,
Services.scriptSecurityManager.getSystemPrincipal());
cmdLine.preventDefault = true;
} catch (e) {
}
}
}
if (!cmdLine.preventDefault) {
this.realCmdLine = cmdLine;
var prefBranch = Services.prefs.getBranch("general.startup.");
var startupArray = prefBranch.getChildList("");
for (var i = 0; i < startupArray.length; ++i) {
this.currentArgument = startupArray[i];
var contract = NS_GENERAL_STARTUP_PREFIX + this.currentArgument;
if (contract in Cc) {
// Ignore any exceptions - we can't do anything about them here.
try {
if (prefBranch.getBoolPref(this.currentArgument)) {
var handler = Cc[contract].getService(nsICommandLineHandler);
if (handler.wrappedJSObject)
handler.wrappedJSObject.handle(this);
else
handler.handle(this);
}
} catch (e) {
Cu.reportError(e);
}
}
}
this.realCmdLine = null;
}
if (!cmdLine.preventDefault) {
var homePage = getURLToLoad();
if (!/\n/.test(homePage)) {
try {
let uri = Services.uriFixup.createFixupURI(homePage, 0);
handURIToExistingBrowser(uri, nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW, features);
cmdLine.preventDefault = true;
} catch (e) {
}
}
if (!cmdLine.preventDefault) {
openWindow(null, getBrowserURL(), features, homePage);
cmdLine.preventDefault = true;
}
}
},