2015-06-19 15:52:44 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-01-17 18:50:18 +00:00
|
|
|
|
2018-01-29 23:20:18 +00:00
|
|
|
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
|
2010-06-22 16:59:15 +00:00
|
|
|
|
2018-01-29 23:20:18 +00:00
|
|
|
ChromeUtils.defineModuleGetter(this, "HeadlessShell",
|
|
|
|
"resource:///modules/HeadlessShell.jsm");
|
|
|
|
ChromeUtils.defineModuleGetter(this, "LaterRun",
|
|
|
|
"resource:///modules/LaterRun.jsm");
|
|
|
|
ChromeUtils.defineModuleGetter(this, "PrivateBrowsingUtils",
|
|
|
|
"resource://gre/modules/PrivateBrowsingUtils.jsm");
|
|
|
|
ChromeUtils.defineModuleGetter(this, "RecentWindow",
|
|
|
|
"resource:///modules/RecentWindow.jsm");
|
|
|
|
ChromeUtils.defineModuleGetter(this, "ShellService",
|
|
|
|
"resource:///modules/ShellService.jsm");
|
2015-06-19 15:52:44 +00:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "WindowsUIUtils",
|
|
|
|
"@mozilla.org/windows-ui-utils;1", "nsIWindowsUIUtils");
|
2018-01-29 23:20:18 +00:00
|
|
|
ChromeUtils.defineModuleGetter(this, "UpdatePing",
|
|
|
|
"resource://gre/modules/UpdatePing.jsm");
|
2012-11-12 17:26:53 +00:00
|
|
|
|
2005-08-26 19:56:55 +00:00
|
|
|
function shouldLoadURI(aURI) {
|
|
|
|
if (aURI && !aURI.schemeIs("chrome"))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
dump("*** Preventing external load of chrome: URI into browser window\n");
|
2014-10-24 00:35:27 +00:00
|
|
|
dump(" Use --chrome <uri> instead\n");
|
2005-08-26 19:56:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function resolveURIInternal(aCmdLine, aArgument) {
|
2005-08-08 13:03:17 +00:00
|
|
|
var uri = aCmdLine.resolveURI(aArgument);
|
2016-02-15 18:19:39 +00:00
|
|
|
var uriFixup = Services.uriFixup;
|
2005-08-08 13:03:17 +00:00
|
|
|
|
2018-04-03 13:44:05 +00:00
|
|
|
if (!(uri instanceof Ci.nsIFileURL)) {
|
2016-02-15 18:19:39 +00:00
|
|
|
return uriFixup.createFixupURI(aArgument,
|
|
|
|
uriFixup.FIXUP_FLAG_FIX_SCHEME_TYPOS);
|
2005-08-08 13:03:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (uri.file.exists())
|
|
|
|
return uri;
|
2016-12-31 02:47:25 +00:00
|
|
|
} catch (e) {
|
2018-02-28 17:51:33 +00:00
|
|
|
Cu.reportError(e);
|
2005-08-08 13:03:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// We have interpreted the argument as a relative file URI, but the file
|
|
|
|
// doesn't exist. Try URI fixup heuristics: see bug 290782.
|
2016-02-03 22:22:33 +00:00
|
|
|
|
2005-08-08 13:03:17 +00:00
|
|
|
try {
|
2016-02-15 18:19:39 +00:00
|
|
|
uri = uriFixup.createFixupURI(aArgument, 0);
|
2016-12-31 02:47:25 +00:00
|
|
|
} catch (e) {
|
2018-02-28 17:51:33 +00:00
|
|
|
Cu.reportError(e);
|
2005-08-08 13:03:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
|
2012-11-12 17:26:53 +00:00
|
|
|
var gFirstWindow = false;
|
|
|
|
|
2007-03-26 14:22:14 +00:00
|
|
|
const OVERRIDE_NONE = 0;
|
|
|
|
const OVERRIDE_NEW_PROFILE = 1;
|
|
|
|
const OVERRIDE_NEW_MSTONE = 2;
|
2010-08-26 10:19:37 +00:00
|
|
|
const OVERRIDE_NEW_BUILD_ID = 3;
|
2007-03-26 14:22:14 +00:00
|
|
|
/**
|
|
|
|
* Determines whether a home page override is needed.
|
|
|
|
* Returns:
|
|
|
|
* OVERRIDE_NEW_PROFILE if this is the first run with a new profile.
|
|
|
|
* OVERRIDE_NEW_MSTONE if this is the first run with a build with a different
|
|
|
|
* Gecko milestone (i.e. right after an upgrade).
|
2010-08-26 10:19:37 +00:00
|
|
|
* OVERRIDE_NEW_BUILD_ID if this is the first run with a new build ID of the
|
|
|
|
* same Gecko milestone (i.e. after a nightly upgrade).
|
2007-03-26 14:22:14 +00:00
|
|
|
* OVERRIDE_NONE otherwise.
|
|
|
|
*/
|
2005-01-17 18:50:18 +00:00
|
|
|
function needHomepageOverride(prefb) {
|
2017-03-07 14:29:48 +00:00
|
|
|
var savedmstone = prefb.getCharPref("browser.startup.homepage_override.mstone", "");
|
2005-01-17 18:50:18 +00:00
|
|
|
|
2006-09-20 23:10:07 +00:00
|
|
|
if (savedmstone == "ignore")
|
2007-03-26 14:22:14 +00:00
|
|
|
return OVERRIDE_NONE;
|
2006-09-20 23:10:07 +00:00
|
|
|
|
2012-02-21 03:26:51 +00:00
|
|
|
var mstone = Services.appinfo.platformVersion;
|
2005-01-17 18:50:18 +00:00
|
|
|
|
2017-03-07 14:29:48 +00:00
|
|
|
var savedBuildID = prefb.getCharPref("browser.startup.homepage_override.buildID", "");
|
2010-08-26 10:19:37 +00:00
|
|
|
|
2012-02-21 03:26:51 +00:00
|
|
|
var buildID = Services.appinfo.platformBuildID;
|
2010-08-26 10:19:37 +00:00
|
|
|
|
2006-07-05 14:04:36 +00:00
|
|
|
if (mstone != savedmstone) {
|
2008-11-06 03:17:27 +00:00
|
|
|
// Bug 462254. Previous releases had a default pref to suppress the EULA
|
|
|
|
// agreement if the platform's installer had already shown one. Now with
|
|
|
|
// about:rights we've removed the EULA stuff and default pref, but we need
|
|
|
|
// a way to make existing profiles retain the default that we removed.
|
|
|
|
if (savedmstone)
|
|
|
|
prefb.setBoolPref("browser.rights.3.shown", true);
|
2016-02-03 22:22:33 +00:00
|
|
|
|
2006-01-21 20:12:47 +00:00
|
|
|
prefb.setCharPref("browser.startup.homepage_override.mstone", mstone);
|
2010-08-26 10:19:37 +00:00
|
|
|
prefb.setCharPref("browser.startup.homepage_override.buildID", buildID);
|
2007-03-26 14:22:14 +00:00
|
|
|
return (savedmstone ? OVERRIDE_NEW_MSTONE : OVERRIDE_NEW_PROFILE);
|
2006-07-05 14:04:36 +00:00
|
|
|
}
|
2005-01-17 18:50:18 +00:00
|
|
|
|
2010-08-26 10:19:37 +00:00
|
|
|
if (buildID != savedBuildID) {
|
|
|
|
prefb.setCharPref("browser.startup.homepage_override.buildID", buildID);
|
|
|
|
return OVERRIDE_NEW_BUILD_ID;
|
|
|
|
}
|
|
|
|
|
2007-03-26 14:22:14 +00:00
|
|
|
return OVERRIDE_NONE;
|
2005-01-17 18:50:18 +00:00
|
|
|
}
|
|
|
|
|
2010-04-07 02:49:23 +00:00
|
|
|
/**
|
|
|
|
* Gets the override page for the first run after the application has been
|
|
|
|
* updated.
|
|
|
|
* @param defaultOverridePage
|
|
|
|
* The default override page.
|
|
|
|
* @return The override page.
|
|
|
|
*/
|
|
|
|
function getPostUpdateOverridePage(defaultOverridePage) {
|
2018-02-28 17:51:33 +00:00
|
|
|
var um = Cc["@mozilla.org/updates/update-manager;1"]
|
|
|
|
.getService(Ci.nsIUpdateManager);
|
2017-08-18 19:06:10 +00:00
|
|
|
// The active update should be present when this code is called. If for
|
|
|
|
// whatever reason it isn't fallback to the latest update in the update
|
|
|
|
// history.
|
|
|
|
if (um.activeUpdate) {
|
|
|
|
var update = um.activeUpdate
|
2018-02-28 17:51:33 +00:00
|
|
|
.QueryInterface(Ci.nsIPropertyBag);
|
2017-08-18 19:06:10 +00:00
|
|
|
} else {
|
|
|
|
// If the updates.xml file is deleted then getUpdateAt will throw.
|
|
|
|
try {
|
|
|
|
update = um.getUpdateAt(0)
|
2018-02-28 17:51:33 +00:00
|
|
|
.QueryInterface(Ci.nsIPropertyBag);
|
2017-08-18 19:06:10 +00:00
|
|
|
} catch (e) {
|
2018-02-28 17:51:33 +00:00
|
|
|
Cu.reportError("Unable to find update: " + e);
|
2017-08-18 19:06:10 +00:00
|
|
|
return defaultOverridePage;
|
|
|
|
}
|
2010-04-07 02:49:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let actions = update.getProperty("actions");
|
|
|
|
// When the update doesn't specify actions fallback to the original behavior
|
|
|
|
// of displaying the default override page.
|
|
|
|
if (!actions)
|
|
|
|
return defaultOverridePage;
|
|
|
|
|
|
|
|
// The existence of silent or the non-existence of showURL in the actions both
|
|
|
|
// mean that an override page should not be displayed.
|
2018-02-01 19:45:22 +00:00
|
|
|
if (actions.includes("silent") || !actions.includes("showURL"))
|
2010-04-07 02:49:23 +00:00
|
|
|
return "";
|
|
|
|
|
|
|
|
return update.getProperty("openURL") || defaultOverridePage;
|
|
|
|
}
|
|
|
|
|
2018-03-30 12:03:46 +00:00
|
|
|
/**
|
|
|
|
* Open a browser window. If this is the initial launch, this function will
|
|
|
|
* attempt to use the navigator:blank window opened by nsBrowserGlue.js during
|
|
|
|
* early startup.
|
|
|
|
*
|
|
|
|
* @param cmdLine
|
|
|
|
* The nsICommandLine object given to nsICommandLineHandler's handle
|
|
|
|
* method.
|
|
|
|
* Used to check if we are processing the command line for the initial launch.
|
|
|
|
* @param urlOrUrlList (optional)
|
|
|
|
* When omitted, the browser window will be opened with the default
|
|
|
|
* arguments, which will usually load the homepage.
|
|
|
|
* This can be a JS array of urls provided as strings, each url will be
|
|
|
|
* loaded in a tab. postData will be ignored in this case.
|
|
|
|
* This can be a single url to load in the new window, provided as a string.
|
|
|
|
* postData will be used in this case if provided.
|
|
|
|
* @param postData (optional)
|
|
|
|
* An nsIInputStream object to use as POST data when loading the provided
|
|
|
|
* url, or null.
|
|
|
|
* @param forcePrivate (optional)
|
|
|
|
* Boolean. If set to true, the new window will be a private browsing one.
|
|
|
|
*/
|
|
|
|
function openBrowserWindow(cmdLine, urlOrUrlList, postData = null,
|
|
|
|
forcePrivate = false) {
|
|
|
|
let chromeURL = Services.prefs.getCharPref("browser.chromeURL");
|
2008-07-03 20:30:24 +00:00
|
|
|
|
2018-03-30 12:03:46 +00:00
|
|
|
let args;
|
|
|
|
if (!urlOrUrlList) {
|
2008-07-03 20:30:24 +00:00
|
|
|
// Just pass in the defaultArgs directly
|
2018-03-30 12:03:46 +00:00
|
|
|
args = [gBrowserContentHandler.defaultArgs];
|
|
|
|
} else if (Array.isArray(urlOrUrlList)) {
|
|
|
|
// Passing an nsIArray for the url disables the "|"-splitting behavior.
|
|
|
|
let uriArray = Cc["@mozilla.org/array;1"]
|
|
|
|
.createInstance(Ci.nsIMutableArray);
|
|
|
|
urlOrUrlList.forEach(function(uri) {
|
2018-02-28 17:51:33 +00:00
|
|
|
var sstring = Cc["@mozilla.org/supports-string;1"]
|
2018-04-03 13:44:05 +00:00
|
|
|
.createInstance(Ci.nsISupportsString);
|
2008-07-03 20:30:24 +00:00
|
|
|
sstring.data = uri;
|
2017-04-14 19:51:39 +00:00
|
|
|
uriArray.appendElement(sstring);
|
2008-07-03 20:30:24 +00:00
|
|
|
});
|
2018-03-30 12:03:46 +00:00
|
|
|
args = [uriArray];
|
2008-07-03 20:30:24 +00:00
|
|
|
} else {
|
2018-03-30 12:03:46 +00:00
|
|
|
// Always pass at least 3 arguments to avoid the "|"-splitting behavior,
|
|
|
|
// ie. avoid the loadOneOrMoreURIs function.
|
|
|
|
args = [urlOrUrlList,
|
|
|
|
null, // charset
|
|
|
|
null, // referer
|
|
|
|
postData];
|
2005-01-17 18:50:18 +00:00
|
|
|
}
|
2008-07-03 20:30:24 +00:00
|
|
|
|
2018-04-03 13:44:05 +00:00
|
|
|
if (cmdLine.state == Ci.nsICommandLine.STATE_INITIAL_LAUNCH) {
|
2018-03-30 12:03:46 +00:00
|
|
|
let win = Services.wm.getMostRecentWindow("navigator:blank");
|
|
|
|
if (win) {
|
|
|
|
// Remove the windowtype of our blank window so that we don't close it
|
|
|
|
// later on when seeing cmdLine.preventDefault is true.
|
|
|
|
win.document.documentElement.removeAttribute("windowtype");
|
|
|
|
|
|
|
|
if (forcePrivate) {
|
|
|
|
// This causes a "Only internal code is allowed to set the
|
|
|
|
// usePrivateBrowsing attribute" warning in the Browser Console.
|
|
|
|
// Still better than having a white window that flickers.
|
|
|
|
win.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsILoadContext)
|
|
|
|
.usePrivateBrowsing = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
win.location = chromeURL;
|
|
|
|
win.arguments = args; // <-- needs to be a plain JS array here.
|
2008-07-03 20:30:24 +00:00
|
|
|
|
2018-03-30 12:03:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We can't provide arguments to openWindow as a JS array.
|
|
|
|
if (!urlOrUrlList) {
|
|
|
|
// If we have a single string guaranteed to not contain '|' we can simply
|
|
|
|
// wrap it in an nsISupportsString object.
|
|
|
|
let [url] = args;
|
|
|
|
args = Cc["@mozilla.org/supports-string;1"]
|
2018-04-03 13:44:05 +00:00
|
|
|
.createInstance(Ci.nsISupportsString);
|
2018-03-30 12:03:46 +00:00
|
|
|
args.data = url;
|
|
|
|
} else {
|
|
|
|
// Otherwise, pass an nsIArray.
|
|
|
|
if (args.length > 1) {
|
|
|
|
let string = Cc["@mozilla.org/supports-string;1"]
|
|
|
|
.createInstance(Ci.nsISupportsString);
|
|
|
|
string.data = args[0];
|
|
|
|
args[0] = string;
|
|
|
|
}
|
|
|
|
let array = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
|
|
|
|
args.forEach(a => { array.appendElement(a); });
|
|
|
|
args = array;
|
|
|
|
}
|
|
|
|
|
|
|
|
let features = "chrome,dialog=no,all" + gBrowserContentHandler.getFeatures(cmdLine);
|
|
|
|
if (forcePrivate)
|
|
|
|
features += ",private";
|
|
|
|
|
|
|
|
Services.ww.openWindow(null, chromeURL, "_blank", features, args);
|
2005-01-17 18:50:18 +00:00
|
|
|
}
|
|
|
|
|
2018-03-30 12:03:46 +00:00
|
|
|
function openPreferences(cmdLine, extraArgs) {
|
2017-05-09 14:43:48 +00:00
|
|
|
if (extraArgs && extraArgs.origin) {
|
|
|
|
Services.telemetry.getHistogramById("FX_PREFERENCES_OPENED_VIA").add(extraArgs.origin);
|
|
|
|
} else {
|
|
|
|
Services.telemetry.getHistogramById("FX_PREFERENCES_OPENED_VIA").add("other");
|
|
|
|
}
|
2018-03-30 12:03:46 +00:00
|
|
|
openBrowserWindow(cmdLine, "about:preferences");
|
2005-01-17 18:50:18 +00:00
|
|
|
}
|
|
|
|
|
2018-04-03 13:44:05 +00:00
|
|
|
function doSearch(searchTerm, cmdLine) {
|
|
|
|
var engine = Services.search.defaultEngine;
|
2015-08-26 17:28:13 +00:00
|
|
|
var countId = (engine.identifier || ("other-" + engine.name)) + ".system";
|
|
|
|
var count = Services.telemetry.getKeyedHistogramById("SEARCH_COUNTS");
|
|
|
|
count.add(countId);
|
|
|
|
|
|
|
|
var submission = engine.getSubmission(searchTerm, null, "system");
|
2006-06-28 04:06:10 +00:00
|
|
|
|
|
|
|
// XXXbsmedberg: use handURIToExistingBrowser to obey tabbed-browsing
|
|
|
|
// preferences, but need nsIBrowserDOMWindow extensions
|
2018-03-30 12:03:46 +00:00
|
|
|
openBrowserWindow(cmdLine, submission.uri.spec, submission.postData);
|
2006-06-28 04:06:10 +00:00
|
|
|
}
|
|
|
|
|
2010-06-24 15:56:28 +00:00
|
|
|
function nsBrowserContentHandler() {
|
2010-06-22 16:59:15 +00:00
|
|
|
}
|
|
|
|
nsBrowserContentHandler.prototype = {
|
|
|
|
classID: Components.ID("{5d0ce354-df01-421a-83fb-7ead0990c24e}"),
|
|
|
|
|
|
|
|
_xpcom_factory: {
|
|
|
|
createInstance: function bch_factory_ci(outer, iid) {
|
|
|
|
if (outer)
|
2018-02-28 17:51:33 +00:00
|
|
|
throw Cr.NS_ERROR_NO_AGGREGATION;
|
2010-06-22 16:59:15 +00:00
|
|
|
return gBrowserContentHandler.QueryInterface(iid);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2005-01-17 18:50:18 +00:00
|
|
|
/* nsISupports */
|
2018-04-03 13:44:05 +00:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler,
|
|
|
|
Ci.nsIBrowserHandler,
|
|
|
|
Ci.nsIContentHandler,
|
|
|
|
Ci.nsICommandLineValidator]),
|
2005-01-17 18:50:18 +00:00
|
|
|
|
|
|
|
/* nsICommandLineHandler */
|
2017-03-21 18:29:43 +00:00
|
|
|
handle: function bch_handle(cmdLine) {
|
2005-01-17 18:50:18 +00:00
|
|
|
if (cmdLine.handleFlag("browser", false)) {
|
2018-03-30 12:03:46 +00:00
|
|
|
openBrowserWindow(cmdLine);
|
2005-01-17 18:50:18 +00:00
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
}
|
|
|
|
|
2015-03-10 08:25:19 +00:00
|
|
|
// In the past, when an instance was not already running, the -remote
|
|
|
|
// option returned an error code. Any script or application invoking the
|
|
|
|
// -remote option is expected to be handling this case, otherwise they
|
|
|
|
// wouldn't be doing anything when there is no Firefox already running.
|
|
|
|
// Making the -remote option always return an error code makes those
|
|
|
|
// scripts or applications handle the situation as if Firefox was not
|
|
|
|
// already running.
|
|
|
|
if (cmdLine.handleFlag("remote", true)) {
|
2018-04-03 13:44:05 +00:00
|
|
|
throw Cr.NS_ERROR_ABORT;
|
2015-03-10 08:25:19 +00:00
|
|
|
}
|
|
|
|
|
2005-08-15 14:01:10 +00:00
|
|
|
var uriparam;
|
2005-01-17 18:50:18 +00:00
|
|
|
try {
|
2005-03-27 21:28:34 +00:00
|
|
|
while ((uriparam = cmdLine.handleFlagWithParam("new-window", false))) {
|
2016-01-19 22:03:11 +00:00
|
|
|
let uri = resolveURIInternal(cmdLine, uriparam);
|
2005-08-26 19:56:55 +00:00
|
|
|
if (!shouldLoadURI(uri))
|
|
|
|
continue;
|
2018-03-30 12:03:46 +00:00
|
|
|
openBrowserWindow(cmdLine, uri.spec);
|
2005-01-17 18:50:18 +00:00
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
}
|
2016-12-31 02:47:25 +00:00
|
|
|
} catch (e) {
|
2018-02-28 17:51:33 +00:00
|
|
|
Cu.reportError(e);
|
2005-01-17 18:50:18 +00:00
|
|
|
}
|
|
|
|
|
2005-08-15 14:01:10 +00:00
|
|
|
try {
|
|
|
|
while ((uriparam = cmdLine.handleFlagWithParam("new-tab", false))) {
|
2016-01-19 22:03:11 +00:00
|
|
|
let uri = resolveURIInternal(cmdLine, uriparam);
|
2018-04-03 13:44:05 +00:00
|
|
|
handURIToExistingBrowser(uri, Ci.nsIBrowserDOMWindow.OPEN_NEWTAB,
|
|
|
|
cmdLine, false,
|
2017-07-05 19:58:21 +00:00
|
|
|
Services.scriptSecurityManager.getSystemPrincipal());
|
2005-08-15 14:01:10 +00:00
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
}
|
2016-12-31 02:47:25 +00:00
|
|
|
} catch (e) {
|
2018-02-28 17:51:33 +00:00
|
|
|
Cu.reportError(e);
|
2005-08-15 14:01:10 +00:00
|
|
|
}
|
|
|
|
|
2005-01-17 18:50:18 +00:00
|
|
|
var chromeParam = cmdLine.handleFlagWithParam("chrome", false);
|
|
|
|
if (chromeParam) {
|
2005-05-05 02:17:23 +00:00
|
|
|
|
2013-11-05 12:21:28 +00:00
|
|
|
// Handle old preference dialog URLs.
|
|
|
|
if (chromeParam == "chrome://browser/content/pref/pref.xul" ||
|
2015-09-02 16:12:55 +00:00
|
|
|
chromeParam == "chrome://browser/content/preferences/preferences.xul") {
|
2018-03-30 12:03:46 +00:00
|
|
|
openPreferences(cmdLine, {origin: "commandLineLegacy"});
|
2007-09-18 00:54:03 +00:00
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
} else try {
|
2016-01-19 22:03:11 +00:00
|
|
|
let resolvedURI = resolveURIInternal(cmdLine, chromeParam);
|
|
|
|
let isLocal = uri => {
|
2015-07-03 16:16:19 +00:00
|
|
|
let localSchemes = new Set(["chrome", "file", "resource"]);
|
2018-02-28 17:51:33 +00:00
|
|
|
if (uri instanceof Ci.nsINestedURI) {
|
|
|
|
uri = uri.QueryInterface(Ci.nsINestedURI).innerMostURI;
|
2015-06-25 20:25:56 +00:00
|
|
|
}
|
|
|
|
return localSchemes.has(uri.scheme);
|
|
|
|
};
|
2016-01-19 22:03:11 +00:00
|
|
|
if (isLocal(resolvedURI)) {
|
2015-07-03 15:00:21 +00:00
|
|
|
// If the URI is local, we are sure it won't wrongly inherit chrome privs
|
2018-03-01 16:20:38 +00:00
|
|
|
let features = "chrome,dialog=no,all" + this.getFeatures(cmdLine);
|
2018-03-30 12:03:46 +00:00
|
|
|
Services.ww.openWindow(null, resolvedURI.spec, "_blank", features, null);
|
2015-07-03 15:00:21 +00:00
|
|
|
cmdLine.preventDefault = true;
|
2015-06-25 20:25:56 +00:00
|
|
|
} else {
|
|
|
|
dump("*** Preventing load of web URI as chrome\n");
|
|
|
|
dump(" If you're trying to load a webpage, do not pass --chrome.\n");
|
2007-09-18 00:54:03 +00:00
|
|
|
}
|
2016-12-31 02:47:25 +00:00
|
|
|
} catch (e) {
|
2018-02-28 17:51:33 +00:00
|
|
|
Cu.reportError(e);
|
2005-05-05 02:17:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cmdLine.handleFlag("preferences", false)) {
|
2018-03-30 12:03:46 +00:00
|
|
|
openPreferences(cmdLine, {origin: "commandLineLegacy"});
|
2005-01-17 18:50:18 +00:00
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
}
|
2006-02-02 17:26:57 +00:00
|
|
|
if (cmdLine.handleFlag("silent", false))
|
|
|
|
cmdLine.preventDefault = true;
|
2014-01-17 06:29:00 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
var privateWindowParam = cmdLine.handleFlagWithParam("private-window", false);
|
|
|
|
if (privateWindowParam) {
|
2018-03-01 16:20:38 +00:00
|
|
|
let forcePrivate = true;
|
|
|
|
let resolvedURI;
|
|
|
|
if (!PrivateBrowsingUtils.enabled) {
|
|
|
|
// Load about:privatebrowsing in a normal tab, which will display an error indicating
|
|
|
|
// access to private browsing has been disabled.
|
|
|
|
forcePrivate = false;
|
|
|
|
resolvedURI = Services.io.newURI("about:privatebrowsing");
|
|
|
|
} else {
|
|
|
|
resolvedURI = resolveURIInternal(cmdLine, privateWindowParam);
|
|
|
|
}
|
2018-04-03 13:44:05 +00:00
|
|
|
handURIToExistingBrowser(resolvedURI, Ci.nsIBrowserDOMWindow.OPEN_NEWTAB,
|
|
|
|
cmdLine, forcePrivate,
|
2017-07-05 19:58:21 +00:00
|
|
|
Services.scriptSecurityManager.getSystemPrincipal());
|
2018-03-09 21:30:33 +00:00
|
|
|
cmdLine.preventDefault = true;
|
2014-01-17 06:29:00 +00:00
|
|
|
}
|
2016-01-19 22:03:11 +00:00
|
|
|
} catch (e) {
|
2018-02-28 17:51:33 +00:00
|
|
|
if (e.result != Cr.NS_ERROR_INVALID_ARG) {
|
2016-01-19 22:03:11 +00:00
|
|
|
throw e;
|
|
|
|
}
|
2014-01-17 06:29:00 +00:00
|
|
|
// NS_ERROR_INVALID_ARG is thrown when flag exists, but has no param.
|
|
|
|
if (cmdLine.handleFlag("private-window", false)) {
|
2018-03-30 12:03:46 +00:00
|
|
|
openBrowserWindow(cmdLine, "about:privatebrowsing", null,
|
|
|
|
PrivateBrowsingUtils.enabled);
|
2014-01-17 06:29:00 +00:00
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
}
|
2012-11-21 01:31:35 +00:00
|
|
|
}
|
2006-06-28 04:06:10 +00:00
|
|
|
|
|
|
|
var searchParam = cmdLine.handleFlagWithParam("search", false);
|
|
|
|
if (searchParam) {
|
|
|
|
doSearch(searchParam, cmdLine);
|
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
}
|
|
|
|
|
2012-11-12 17:26:53 +00:00
|
|
|
// The global PB Service consumes this flag, so only eat it in per-window
|
|
|
|
// PB builds.
|
2018-03-01 16:20:38 +00:00
|
|
|
if (cmdLine.handleFlag("private", false) && PrivateBrowsingUtils.enabled) {
|
2012-11-12 17:26:53 +00:00
|
|
|
PrivateBrowsingUtils.enterTemporaryAutoStartMode();
|
|
|
|
}
|
|
|
|
|
2009-02-02 17:49:56 +00:00
|
|
|
var fileParam = cmdLine.handleFlagWithParam("file", false);
|
|
|
|
if (fileParam) {
|
|
|
|
var file = cmdLine.resolveFile(fileParam);
|
2016-02-15 18:19:39 +00:00
|
|
|
var fileURI = Services.io.newFileURI(file);
|
2018-03-30 12:03:46 +00:00
|
|
|
openBrowserWindow(cmdLine, fileURI.spec);
|
2009-02-02 17:49:56 +00:00
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
}
|
|
|
|
|
2016-12-31 02:47:25 +00:00
|
|
|
if (AppConstants.platform == "win") {
|
2015-06-19 15:52:44 +00:00
|
|
|
// Handle "? searchterm" for Windows Vista start menu integration
|
|
|
|
for (var i = cmdLine.length - 1; i >= 0; --i) {
|
|
|
|
var param = cmdLine.getArgument(i);
|
|
|
|
if (param.match(/^\? /)) {
|
|
|
|
cmdLine.removeArguments(i, i);
|
|
|
|
cmdLine.preventDefault = true;
|
2006-06-28 04:06:10 +00:00
|
|
|
|
2015-06-19 15:52:44 +00:00
|
|
|
searchParam = param.substr(2);
|
|
|
|
doSearch(searchParam, cmdLine);
|
|
|
|
}
|
2006-06-28 04:06:10 +00:00
|
|
|
}
|
|
|
|
}
|
2005-01-17 18:50:18 +00:00
|
|
|
},
|
|
|
|
|
2015-06-19 15:52:44 +00:00
|
|
|
get helpInfo() {
|
|
|
|
let info =
|
|
|
|
" --browser Open a browser window.\n" +
|
|
|
|
" --new-window <url> Open <url> in a new window.\n" +
|
|
|
|
" --new-tab <url> Open <url> in a new tab.\n" +
|
|
|
|
" --private-window <url> Open <url> in a new private window.\n";
|
|
|
|
if (AppConstants.platform == "win") {
|
|
|
|
info += " --preferences Open Options dialog.\n";
|
|
|
|
} else {
|
|
|
|
info += " --preferences Open Preferences dialog.\n";
|
|
|
|
}
|
2017-11-06 18:42:32 +00:00
|
|
|
info += " --screenshot [<path>] Save screenshot to <path> or in working directory.\n";
|
|
|
|
info += " --window-size width[,height] Width and optionally height of screenshot.\n";
|
2015-06-19 15:52:44 +00:00
|
|
|
info += " --search <term> Search <term> with your default search engine.\n";
|
|
|
|
return info;
|
|
|
|
},
|
2005-01-17 18:50:18 +00:00
|
|
|
|
|
|
|
/* nsIBrowserHandler */
|
|
|
|
|
2005-04-10 23:32:51 +00:00
|
|
|
get defaultArgs() {
|
2016-02-15 18:19:39 +00:00
|
|
|
var prefb = Services.prefs;
|
2005-04-10 23:32:51 +00:00
|
|
|
|
2012-11-12 17:26:53 +00:00
|
|
|
if (!gFirstWindow) {
|
|
|
|
gFirstWindow = true;
|
|
|
|
if (PrivateBrowsingUtils.isInTemporaryAutoStartMode) {
|
|
|
|
return "about:privatebrowsing";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-15 20:44:18 +00:00
|
|
|
var override;
|
2007-03-26 14:22:14 +00:00
|
|
|
var overridePage = "";
|
2015-10-15 20:44:18 +00:00
|
|
|
var additionalPage = "";
|
2013-11-19 19:57:46 +00:00
|
|
|
var willRestoreSession = false;
|
2006-07-05 14:04:36 +00:00
|
|
|
try {
|
2012-03-28 16:56:56 +00:00
|
|
|
// Read the old value of homepage_override.mstone before
|
|
|
|
// needHomepageOverride updates it, so that we can later add it to the
|
|
|
|
// URL if we do end up showing an overridePage. This makes it possible
|
|
|
|
// to have the overridePage's content vary depending on the version we're
|
|
|
|
// upgrading from.
|
2017-03-07 14:29:48 +00:00
|
|
|
let old_mstone = Services.prefs.getCharPref("browser.startup.homepage_override.mstone", "unknown");
|
2017-08-21 09:50:59 +00:00
|
|
|
let old_buildId = Services.prefs.getCharPref("browser.startup.homepage_override.buildID", "unknown");
|
2015-10-15 20:44:18 +00:00
|
|
|
override = needHomepageOverride(prefb);
|
2010-08-26 10:19:37 +00:00
|
|
|
if (override != OVERRIDE_NONE) {
|
|
|
|
switch (override) {
|
|
|
|
case OVERRIDE_NEW_PROFILE:
|
|
|
|
// New profile.
|
2010-11-08 14:03:42 +00:00
|
|
|
overridePage = Services.urlFormatter.formatURLPref("startup.homepage_welcome_url");
|
2015-10-15 20:44:18 +00:00
|
|
|
additionalPage = Services.urlFormatter.formatURLPref("startup.homepage_welcome_url.additional");
|
2016-01-19 15:47:19 +00:00
|
|
|
// Turn on 'later run' pages for new profiles.
|
|
|
|
LaterRun.enabled = true;
|
2010-08-26 10:19:37 +00:00
|
|
|
break;
|
|
|
|
case OVERRIDE_NEW_MSTONE:
|
2013-11-19 19:57:46 +00:00
|
|
|
// Check whether we will restore a session. If we will, we assume
|
|
|
|
// that this is an "update" session. This does not take crashes
|
|
|
|
// into account because that requires waiting for the session file
|
|
|
|
// to be read. If a crash occurs after updating, before restarting,
|
|
|
|
// we may open the startPage in addition to restoring the session.
|
2018-02-28 17:51:33 +00:00
|
|
|
var ss = Cc["@mozilla.org/browser/sessionstartup;1"]
|
|
|
|
.getService(Ci.nsISessionStartup);
|
2013-11-19 19:57:46 +00:00
|
|
|
willRestoreSession = ss.isAutomaticRestoreEnabled();
|
|
|
|
|
2010-11-08 14:03:42 +00:00
|
|
|
overridePage = Services.urlFormatter.formatURLPref("startup.homepage_override_url");
|
2017-08-21 09:50:59 +00:00
|
|
|
if (prefb.prefHasUserValue("app.update.postupdate")) {
|
2010-08-26 10:19:37 +00:00
|
|
|
overridePage = getPostUpdateOverridePage(overridePage);
|
2017-08-21 09:50:59 +00:00
|
|
|
// Send the update ping to signal that the update was successful.
|
|
|
|
UpdatePing.handleUpdateSuccess(old_mstone, old_buildId);
|
|
|
|
}
|
2012-03-28 16:56:56 +00:00
|
|
|
|
|
|
|
overridePage = overridePage.replace("%OLD_VERSION%", old_mstone);
|
2010-08-26 10:19:37 +00:00
|
|
|
break;
|
2017-08-21 09:50:59 +00:00
|
|
|
case OVERRIDE_NEW_BUILD_ID:
|
|
|
|
if (prefb.prefHasUserValue("app.update.postupdate")) {
|
|
|
|
// Send the update ping to signal that the update was successful.
|
|
|
|
UpdatePing.handleUpdateSuccess(old_mstone, old_buildId);
|
|
|
|
}
|
|
|
|
break;
|
2010-08-26 10:19:37 +00:00
|
|
|
}
|
2010-04-07 02:49:23 +00:00
|
|
|
}
|
2007-03-26 14:22:14 +00:00
|
|
|
} catch (ex) {}
|
2005-04-10 23:32:51 +00:00
|
|
|
|
2007-03-26 14:22:14 +00:00
|
|
|
// formatURLPref might return "about:blank" if getting the pref fails
|
|
|
|
if (overridePage == "about:blank")
|
|
|
|
overridePage = "";
|
2006-12-07 21:28:32 +00:00
|
|
|
|
2016-01-19 15:47:19 +00:00
|
|
|
if (!additionalPage) {
|
|
|
|
additionalPage = LaterRun.getURL() || "";
|
2015-07-17 22:02:05 +00:00
|
|
|
}
|
|
|
|
|
2015-10-15 20:44:18 +00:00
|
|
|
if (additionalPage && additionalPage != "about:blank") {
|
|
|
|
if (overridePage) {
|
|
|
|
overridePage += "|" + additionalPage;
|
|
|
|
} else {
|
|
|
|
overridePage = additionalPage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-26 21:20:28 +00:00
|
|
|
var startPage = "";
|
2005-04-10 23:32:51 +00:00
|
|
|
try {
|
|
|
|
var choice = prefb.getIntPref("browser.startup.page");
|
2008-03-29 06:47:04 +00:00
|
|
|
if (choice == 1 || choice == 3)
|
2007-03-26 14:22:14 +00:00
|
|
|
startPage = this.startPage;
|
2007-03-26 21:20:28 +00:00
|
|
|
} catch (e) {
|
2018-02-28 17:51:33 +00:00
|
|
|
Cu.reportError(e);
|
2007-03-26 21:20:28 +00:00
|
|
|
}
|
2005-04-10 23:32:51 +00:00
|
|
|
|
2007-03-26 14:22:14 +00:00
|
|
|
if (startPage == "about:blank")
|
|
|
|
startPage = "";
|
2006-07-05 14:04:36 +00:00
|
|
|
|
2016-12-15 15:40:50 +00:00
|
|
|
let skipStartPage = override == OVERRIDE_NEW_PROFILE &&
|
|
|
|
prefb.getBoolPref("browser.startup.firstrunSkipsHomepage");
|
|
|
|
// Only show the startPage if we're not restoring an update session and are
|
|
|
|
// not set to skip the start page on this profile
|
|
|
|
if (overridePage && startPage && !willRestoreSession && !skipStartPage)
|
2007-03-26 14:22:14 +00:00
|
|
|
return overridePage + "|" + startPage;
|
2006-07-05 14:04:36 +00:00
|
|
|
|
2007-03-26 14:22:14 +00:00
|
|
|
return overridePage || startPage || "about:blank";
|
2005-04-10 23:32:51 +00:00
|
|
|
},
|
|
|
|
|
2005-01-17 18:50:18 +00:00
|
|
|
get startPage() {
|
2011-10-03 23:28:13 +00:00
|
|
|
var uri = Services.prefs.getComplexValue("browser.startup.homepage",
|
2018-04-03 13:44:05 +00:00
|
|
|
Ci.nsIPrefLocalizedString).data;
|
2005-08-25 05:28:37 +00:00
|
|
|
if (!uri) {
|
2011-10-03 23:28:13 +00:00
|
|
|
Services.prefs.clearUserPref("browser.startup.homepage");
|
|
|
|
uri = Services.prefs.getComplexValue("browser.startup.homepage",
|
2018-04-03 13:44:05 +00:00
|
|
|
Ci.nsIPrefLocalizedString).data;
|
2005-01-17 18:50:18 +00:00
|
|
|
}
|
|
|
|
return uri;
|
|
|
|
},
|
|
|
|
|
2017-03-21 18:29:43 +00:00
|
|
|
mFeatures: null,
|
2005-01-17 18:50:18 +00:00
|
|
|
|
2017-03-21 18:29:43 +00:00
|
|
|
getFeatures: function bch_features(cmdLine) {
|
2005-01-17 18:50:18 +00:00
|
|
|
if (this.mFeatures === null) {
|
|
|
|
this.mFeatures = "";
|
|
|
|
|
|
|
|
try {
|
|
|
|
var width = cmdLine.handleFlagWithParam("width", false);
|
|
|
|
var height = cmdLine.handleFlagWithParam("height", false);
|
|
|
|
|
|
|
|
if (width)
|
|
|
|
this.mFeatures += ",width=" + width;
|
|
|
|
if (height)
|
|
|
|
this.mFeatures += ",height=" + height;
|
2016-12-31 02:47:25 +00:00
|
|
|
} catch (e) {
|
2005-01-17 18:50:18 +00:00
|
|
|
}
|
2012-11-12 17:26:53 +00:00
|
|
|
|
|
|
|
// The global PB Service consumes this flag, so only eat it in per-window
|
|
|
|
// PB builds.
|
|
|
|
if (PrivateBrowsingUtils.isInTemporaryAutoStartMode) {
|
2017-05-04 16:42:27 +00:00
|
|
|
this.mFeatures += ",private";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Services.prefs.getBoolPref("browser.suppress_first_window_animation") &&
|
|
|
|
!Services.wm.getMostRecentWindow("navigator:browser")) {
|
|
|
|
this.mFeatures += ",suppressanimation";
|
2012-11-12 17:26:53 +00:00
|
|
|
}
|
2005-01-17 18:50:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.mFeatures;
|
|
|
|
},
|
|
|
|
|
|
|
|
/* nsIContentHandler */
|
|
|
|
|
2017-03-21 18:29:43 +00:00
|
|
|
handleContent: function bch_handleContent(contentType, context, request) {
|
2018-04-03 13:44:05 +00:00
|
|
|
const NS_ERROR_WONT_HANDLE_CONTENT = 0x805d0001;
|
|
|
|
|
2005-02-19 01:36:59 +00:00
|
|
|
try {
|
2018-02-28 17:51:33 +00:00
|
|
|
var webNavInfo = Cc["@mozilla.org/webnavigation-info;1"]
|
2018-04-03 13:44:05 +00:00
|
|
|
.getService(Ci.nsIWebNavigationInfo);
|
2005-02-27 18:33:27 +00:00
|
|
|
if (!webNavInfo.isTypeSupported(contentType, null)) {
|
|
|
|
throw NS_ERROR_WONT_HANDLE_CONTENT;
|
|
|
|
}
|
2005-02-19 01:36:59 +00:00
|
|
|
} catch (e) {
|
|
|
|
throw NS_ERROR_WONT_HANDLE_CONTENT;
|
|
|
|
}
|
|
|
|
|
2018-04-03 13:44:05 +00:00
|
|
|
request.QueryInterface(Ci.nsIChannel);
|
|
|
|
handURIToExistingBrowser(request.URI, Ci.nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW,
|
|
|
|
null, false, request.loadInfo.triggeringPrincipal);
|
|
|
|
request.cancel(Cr.NS_BINDING_ABORTED);
|
2005-01-17 18:50:18 +00:00
|
|
|
},
|
|
|
|
|
2007-07-11 05:59:56 +00:00
|
|
|
/* nsICommandLineValidator */
|
2017-03-21 18:29:43 +00:00
|
|
|
validate: function bch_validate(cmdLine) {
|
2007-07-11 05:59:56 +00:00
|
|
|
// Other handlers may use osint so only handle the osint flag if the url
|
|
|
|
// flag is also present and the command line is valid.
|
|
|
|
var osintFlagIdx = cmdLine.findFlag("osint", false);
|
|
|
|
var urlFlagIdx = cmdLine.findFlag("url", false);
|
|
|
|
if (urlFlagIdx > -1 && (osintFlagIdx > -1 ||
|
2018-04-03 13:44:05 +00:00
|
|
|
cmdLine.state == Ci.nsICommandLine.STATE_REMOTE_EXPLICIT)) {
|
2007-07-11 05:59:56 +00:00
|
|
|
var urlParam = cmdLine.getArgument(urlFlagIdx + 1);
|
2018-01-17 11:14:37 +00:00
|
|
|
if (cmdLine.length != urlFlagIdx + 2 || /firefoxurl:/i.test(urlParam))
|
2018-04-03 13:44:05 +00:00
|
|
|
throw Cr.NS_ERROR_ABORT;
|
2015-06-18 23:16:52 +00:00
|
|
|
var isDefault = false;
|
|
|
|
try {
|
|
|
|
var url = Services.urlFormatter.formatURLPref("app.support.baseURL") +
|
|
|
|
"win10-default-browser";
|
|
|
|
if (urlParam == url) {
|
2016-01-15 17:35:15 +00:00
|
|
|
isDefault = ShellService.isDefaultBrowser(false, false);
|
2015-06-18 23:16:52 +00:00
|
|
|
}
|
|
|
|
} catch (ex) {}
|
|
|
|
if (isDefault) {
|
|
|
|
// Firefox is already the default HTTP handler.
|
|
|
|
// We don't have to show the instruction page.
|
2018-04-03 13:44:05 +00:00
|
|
|
throw Cr.NS_ERROR_ABORT;
|
2015-06-18 23:16:52 +00:00
|
|
|
}
|
2017-10-15 18:50:30 +00:00
|
|
|
cmdLine.handleFlag("osint", false);
|
2007-07-11 05:59:56 +00:00
|
|
|
}
|
|
|
|
},
|
2005-01-17 18:50:18 +00:00
|
|
|
};
|
2010-06-22 16:59:15 +00:00
|
|
|
var gBrowserContentHandler = new nsBrowserContentHandler();
|
2005-01-17 18:50:18 +00:00
|
|
|
|
2017-07-05 19:58:21 +00:00
|
|
|
function handURIToExistingBrowser(uri, location, cmdLine, forcePrivate, triggeringPrincipal) {
|
2005-08-26 19:56:55 +00:00
|
|
|
if (!shouldLoadURI(uri))
|
|
|
|
return;
|
|
|
|
|
2014-01-17 06:29:00 +00:00
|
|
|
// Unless using a private window is forced, open external links in private
|
|
|
|
// windows only if we're in perma-private mode.
|
|
|
|
var allowPrivate = forcePrivate || PrivateBrowsingUtils.permanentPrivateBrowsing;
|
2013-02-26 23:15:57 +00:00
|
|
|
var navWin = RecentWindow.getMostRecentBrowserWindow({private: allowPrivate});
|
2005-04-04 19:08:55 +00:00
|
|
|
if (!navWin) {
|
|
|
|
// if we couldn't load it in an existing window, open a new one
|
2018-03-30 12:03:46 +00:00
|
|
|
openBrowserWindow(cmdLine, uri.spec, null, forcePrivate);
|
2005-04-04 19:08:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-03 13:44:05 +00:00
|
|
|
var navNav = navWin.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation);
|
|
|
|
var rootItem = navNav.QueryInterface(Ci.nsIDocShellTreeItem).rootTreeItem;
|
|
|
|
var rootWin = rootItem.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindow);
|
|
|
|
var bwin = rootWin.QueryInterface(Ci.nsIDOMChromeWindow).browserDOMWindow;
|
2005-04-04 19:08:55 +00:00
|
|
|
bwin.openURI(uri, null, location,
|
2018-04-03 13:44:05 +00:00
|
|
|
Ci.nsIBrowserDOMWindow.OPEN_EXTERNAL, triggeringPrincipal);
|
2005-04-04 19:08:55 +00:00
|
|
|
}
|
|
|
|
|
2010-06-24 15:56:28 +00:00
|
|
|
function nsDefaultCommandLineHandler() {
|
2010-06-22 16:59:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDefaultCommandLineHandler.prototype = {
|
|
|
|
classID: Components.ID("{47cd0651-b1be-4a0f-b5c4-10e5a573ef71}"),
|
2005-04-04 19:08:55 +00:00
|
|
|
|
2005-01-17 18:50:18 +00:00
|
|
|
/* nsISupports */
|
2017-03-21 18:29:43 +00:00
|
|
|
QueryInterface: function dch_QI(iid) {
|
2018-04-03 13:44:05 +00:00
|
|
|
if (!iid.equals(Ci.nsISupports) &&
|
|
|
|
!iid.equals(Ci.nsICommandLineHandler))
|
2018-02-28 17:51:33 +00:00
|
|
|
throw Cr.NS_ERROR_NO_INTERFACE;
|
2005-01-17 18:50:18 +00:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2007-02-14 00:04:30 +00:00
|
|
|
_haveProfile: false,
|
2007-01-30 05:14:50 +00:00
|
|
|
|
2005-01-17 18:50:18 +00:00
|
|
|
/* nsICommandLineHandler */
|
2017-03-21 18:29:43 +00:00
|
|
|
handle: function dch_handle(cmdLine) {
|
2005-01-17 18:50:18 +00:00
|
|
|
var urilist = [];
|
|
|
|
|
2015-06-19 15:52:44 +00:00
|
|
|
if (AppConstants.platform == "win") {
|
|
|
|
// 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 flags 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.
|
|
|
|
if (!this._haveProfile) {
|
|
|
|
try {
|
|
|
|
// This will throw when a profile has not been selected.
|
2018-02-28 17:51:33 +00:00
|
|
|
Services.dirsvc.get("ProfD", Ci.nsIFile);
|
2015-06-19 15:52:44 +00:00
|
|
|
this._haveProfile = true;
|
2016-12-31 02:47:25 +00:00
|
|
|
} catch (e) {
|
2016-08-04 04:55:07 +00:00
|
|
|
while ((ar = cmdLine.handleFlagWithParam("url", false)));
|
2015-06-19 15:52:44 +00:00
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
}
|
2007-02-14 00:04:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-17 18:50:18 +00:00
|
|
|
try {
|
|
|
|
var ar;
|
2005-03-27 21:28:34 +00:00
|
|
|
while ((ar = cmdLine.handleFlagWithParam("url", false))) {
|
2007-02-13 01:14:48 +00:00
|
|
|
var uri = resolveURIInternal(cmdLine, ar);
|
2012-03-26 19:45:29 +00:00
|
|
|
urilist.push(uri);
|
2005-01-17 18:50:18 +00:00
|
|
|
}
|
2016-12-31 02:47:25 +00:00
|
|
|
} catch (e) {
|
2018-02-28 17:51:33 +00:00
|
|
|
Cu.reportError(e);
|
2005-01-17 18:50:18 +00:00
|
|
|
}
|
|
|
|
|
2017-09-12 23:55:27 +00:00
|
|
|
if (cmdLine.findFlag("screenshot", true) != -1) {
|
|
|
|
HeadlessShell.handleCmdLineArgs(cmdLine, urilist.filter(shouldLoadURI).map(u => u.spec));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-05 13:47:17 +00:00
|
|
|
for (let i = 0; i < cmdLine.length; ++i) {
|
2005-01-17 18:50:18 +00:00
|
|
|
var curarg = cmdLine.getArgument(i);
|
|
|
|
if (curarg.match(/^-/)) {
|
2018-02-28 17:51:33 +00:00
|
|
|
Cu.reportError("Warning: unrecognized command line flag " + curarg + "\n");
|
2005-01-17 18:50:18 +00:00
|
|
|
// To emulate the pre-nsICommandLine behavior, we ignore
|
|
|
|
// the argument after an unrecognized flag.
|
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
try {
|
2005-08-08 13:03:17 +00:00
|
|
|
urilist.push(resolveURIInternal(cmdLine, curarg));
|
2016-12-31 02:47:25 +00:00
|
|
|
} catch (e) {
|
2018-02-28 17:51:33 +00:00
|
|
|
Cu.reportError("Error opening URI '" + curarg + "' from the command line: " + e + "\n");
|
2005-01-17 18:50:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (urilist.length) {
|
2018-04-03 13:44:05 +00:00
|
|
|
if (cmdLine.state != Ci.nsICommandLine.STATE_INITIAL_LAUNCH &&
|
2005-01-17 18:50:18 +00:00
|
|
|
urilist.length == 1) {
|
|
|
|
// Try to find an existing window and load our URI into the
|
|
|
|
// current tab, new tab, or new window as prefs determine.
|
|
|
|
try {
|
2018-04-03 13:44:05 +00:00
|
|
|
handURIToExistingBrowser(urilist[0], Ci.nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW,
|
|
|
|
cmdLine, false,
|
2017-07-05 19:58:21 +00:00
|
|
|
Services.scriptSecurityManager.getSystemPrincipal());
|
2005-01-17 18:50:18 +00:00
|
|
|
return;
|
2016-12-31 02:47:25 +00:00
|
|
|
} catch (e) {
|
2005-01-17 18:50:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-23 09:36:21 +00:00
|
|
|
var URLlist = urilist.filter(shouldLoadURI).map(u => u.spec);
|
2008-07-03 20:30:24 +00:00
|
|
|
if (URLlist.length) {
|
2018-03-30 12:03:46 +00:00
|
|
|
openBrowserWindow(cmdLine, URLlist);
|
2005-08-26 19:56:55 +00:00
|
|
|
}
|
2005-01-17 18:50:18 +00:00
|
|
|
|
2016-12-31 02:47:25 +00:00
|
|
|
} else if (!cmdLine.preventDefault) {
|
2015-06-19 15:52:44 +00:00
|
|
|
if (AppConstants.isPlatformAndVersionAtLeast("win", "10") &&
|
2018-04-03 13:44:05 +00:00
|
|
|
cmdLine.state != Ci.nsICommandLine.STATE_INITIAL_LAUNCH &&
|
2015-06-19 15:52:44 +00:00
|
|
|
WindowsUIUtils.inTabletMode) {
|
|
|
|
// In windows 10 tablet mode, do not create a new window, but reuse the existing one.
|
|
|
|
let win = RecentWindow.getMostRecentBrowserWindow();
|
|
|
|
if (win) {
|
|
|
|
win.focus();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-03-30 12:03:46 +00:00
|
|
|
openBrowserWindow(cmdLine);
|
2018-02-10 14:07:48 +00:00
|
|
|
} else {
|
|
|
|
// Need a better solution in the future to avoid opening the blank window
|
|
|
|
// when command line parameters say we are not going to show a browser
|
|
|
|
// window, but for now the blank window getting closed quickly (and
|
|
|
|
// causing only a slight flicker) is better than leaving it open.
|
|
|
|
let win = Services.wm.getMostRecentWindow("navigator:blank");
|
|
|
|
if (win)
|
|
|
|
win.close();
|
2005-01-17 18:50:18 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-03-21 18:29:43 +00:00
|
|
|
helpInfo: "",
|
2005-01-17 18:50:18 +00:00
|
|
|
};
|
|
|
|
|
2010-06-22 16:59:15 +00:00
|
|
|
var components = [nsBrowserContentHandler, nsDefaultCommandLineHandler];
|
2012-10-31 16:13:28 +00:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
|