2015-06-19 18:52:44 +03: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 21:50:18 +03:00
|
|
|
|
2015-07-07 04:11:05 +03:00
|
|
|
Components.utils.importGlobalProperties(["URLSearchParams"]);
|
|
|
|
|
2010-06-22 20:59:15 +04:00
|
|
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
2010-08-26 14:19:37 +04:00
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
2015-06-19 18:52:44 +03:00
|
|
|
Components.utils.import("resource://gre/modules/AppConstants.jsm");
|
2010-06-22 20:59:15 +04:00
|
|
|
|
2012-11-12 21:26:53 +04:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils",
|
|
|
|
"resource://gre/modules/PrivateBrowsingUtils.jsm");
|
2013-01-11 08:25:56 +04:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "RecentWindow",
|
2013-03-18 19:46:17 +04:00
|
|
|
"resource:///modules/RecentWindow.jsm");
|
2015-06-19 18:52:44 +03:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "WindowsUIUtils",
|
|
|
|
"@mozilla.org/windows-ui-utils;1", "nsIWindowsUIUtils");
|
2012-11-12 21:26:53 +04:00
|
|
|
|
2005-01-17 21:50:18 +03:00
|
|
|
const nsISupports = Components.interfaces.nsISupports;
|
|
|
|
|
|
|
|
const nsIBrowserDOMWindow = Components.interfaces.nsIBrowserDOMWindow;
|
|
|
|
const nsIBrowserHandler = Components.interfaces.nsIBrowserHandler;
|
|
|
|
const nsIBrowserHistory = Components.interfaces.nsIBrowserHistory;
|
|
|
|
const nsIChannel = Components.interfaces.nsIChannel;
|
|
|
|
const nsICommandLine = Components.interfaces.nsICommandLine;
|
|
|
|
const nsICommandLineHandler = Components.interfaces.nsICommandLineHandler;
|
|
|
|
const nsIContentHandler = Components.interfaces.nsIContentHandler;
|
|
|
|
const nsIDocShellTreeItem = Components.interfaces.nsIDocShellTreeItem;
|
|
|
|
const nsIDOMChromeWindow = Components.interfaces.nsIDOMChromeWindow;
|
|
|
|
const nsIDOMWindow = Components.interfaces.nsIDOMWindow;
|
2005-08-08 17:03:17 +04:00
|
|
|
const nsIFileURL = Components.interfaces.nsIFileURL;
|
2005-01-17 21:50:18 +03:00
|
|
|
const nsIInterfaceRequestor = Components.interfaces.nsIInterfaceRequestor;
|
2007-09-18 04:54:03 +04:00
|
|
|
const nsINetUtil = Components.interfaces.nsINetUtil;
|
2005-01-17 21:50:18 +03:00
|
|
|
const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
|
|
|
|
const nsIPrefLocalizedString = Components.interfaces.nsIPrefLocalizedString;
|
|
|
|
const nsISupportsString = Components.interfaces.nsISupportsString;
|
2005-08-08 17:03:17 +04:00
|
|
|
const nsIURIFixup = Components.interfaces.nsIURIFixup;
|
2005-01-17 21:50:18 +03:00
|
|
|
const nsIWebNavigation = Components.interfaces.nsIWebNavigation;
|
|
|
|
const nsIWindowMediator = Components.interfaces.nsIWindowMediator;
|
|
|
|
const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher;
|
2005-02-27 21:33:27 +03:00
|
|
|
const nsIWebNavigationInfo = Components.interfaces.nsIWebNavigationInfo;
|
2006-06-28 08:06:10 +04:00
|
|
|
const nsIBrowserSearchService = Components.interfaces.nsIBrowserSearchService;
|
2007-07-11 09:59:56 +04:00
|
|
|
const nsICommandLineValidator = Components.interfaces.nsICommandLineValidator;
|
2005-01-17 21:50:18 +03:00
|
|
|
|
2008-09-10 08:33:27 +04:00
|
|
|
const NS_BINDING_ABORTED = Components.results.NS_BINDING_ABORTED;
|
2005-02-19 04:36:59 +03:00
|
|
|
const NS_ERROR_WONT_HANDLE_CONTENT = 0x805d0001;
|
2005-04-04 23:08:55 +04:00
|
|
|
const NS_ERROR_ABORT = Components.results.NS_ERROR_ABORT;
|
2005-01-17 21:50:18 +03:00
|
|
|
|
2005-08-26 23:56:55 +04: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 04:35:27 +04:00
|
|
|
dump(" Use --chrome <uri> instead\n");
|
2005-08-26 23:56:55 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function resolveURIInternal(aCmdLine, aArgument) {
|
2005-08-08 17:03:17 +04:00
|
|
|
var uri = aCmdLine.resolveURI(aArgument);
|
2014-01-13 00:02:27 +04:00
|
|
|
var urifixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
|
|
|
|
.getService(nsIURIFixup);
|
2005-08-08 17:03:17 +04:00
|
|
|
|
|
|
|
if (!(uri instanceof nsIFileURL)) {
|
2014-01-13 00:02:27 +04:00
|
|
|
return urifixup.createFixupURI(aArgument,
|
|
|
|
urifixup.FIXUP_FLAG_FIX_SCHEME_TYPOS);
|
2005-08-08 17:03:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (uri.file.exists())
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
Components.utils.reportError(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have interpreted the argument as a relative file URI, but the file
|
|
|
|
// doesn't exist. Try URI fixup heuristics: see bug 290782.
|
|
|
|
|
|
|
|
try {
|
|
|
|
uri = urifixup.createFixupURI(aArgument, 0);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
Components.utils.reportError(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return uri;
|
|
|
|
}
|
|
|
|
|
2012-11-12 21:26:53 +04:00
|
|
|
var gFirstWindow = false;
|
|
|
|
|
2007-03-26 18:22:14 +04:00
|
|
|
const OVERRIDE_NONE = 0;
|
|
|
|
const OVERRIDE_NEW_PROFILE = 1;
|
|
|
|
const OVERRIDE_NEW_MSTONE = 2;
|
2010-08-26 14:19:37 +04:00
|
|
|
const OVERRIDE_NEW_BUILD_ID = 3;
|
2007-03-26 18:22:14 +04: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 14:19:37 +04: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 18:22:14 +04:00
|
|
|
* OVERRIDE_NONE otherwise.
|
|
|
|
*/
|
2005-01-17 21:50:18 +03:00
|
|
|
function needHomepageOverride(prefb) {
|
2006-01-21 23:12:47 +03:00
|
|
|
var savedmstone = null;
|
2005-01-17 21:50:18 +03:00
|
|
|
try {
|
|
|
|
savedmstone = prefb.getCharPref("browser.startup.homepage_override.mstone");
|
2006-01-21 23:12:47 +03:00
|
|
|
} catch (e) {}
|
2005-01-17 21:50:18 +03:00
|
|
|
|
2006-09-21 03:10:07 +04:00
|
|
|
if (savedmstone == "ignore")
|
2007-03-26 18:22:14 +04:00
|
|
|
return OVERRIDE_NONE;
|
2006-09-21 03:10:07 +04:00
|
|
|
|
2012-02-21 07:26:51 +04:00
|
|
|
var mstone = Services.appinfo.platformVersion;
|
2005-01-17 21:50:18 +03:00
|
|
|
|
2010-08-26 14:19:37 +04:00
|
|
|
var savedBuildID = null;
|
|
|
|
try {
|
|
|
|
savedBuildID = prefb.getCharPref("browser.startup.homepage_override.buildID");
|
|
|
|
} catch (e) {}
|
|
|
|
|
2012-02-21 07:26:51 +04:00
|
|
|
var buildID = Services.appinfo.platformBuildID;
|
2010-08-26 14:19:37 +04:00
|
|
|
|
2006-07-05 18:04:36 +04:00
|
|
|
if (mstone != savedmstone) {
|
2008-11-06 06:17:27 +03: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);
|
|
|
|
|
2006-01-21 23:12:47 +03:00
|
|
|
prefb.setCharPref("browser.startup.homepage_override.mstone", mstone);
|
2010-08-26 14:19:37 +04:00
|
|
|
prefb.setCharPref("browser.startup.homepage_override.buildID", buildID);
|
2007-03-26 18:22:14 +04:00
|
|
|
return (savedmstone ? OVERRIDE_NEW_MSTONE : OVERRIDE_NEW_PROFILE);
|
2006-07-05 18:04:36 +04:00
|
|
|
}
|
2005-01-17 21:50:18 +03:00
|
|
|
|
2010-08-26 14:19:37 +04:00
|
|
|
if (buildID != savedBuildID) {
|
|
|
|
prefb.setCharPref("browser.startup.homepage_override.buildID", buildID);
|
|
|
|
return OVERRIDE_NEW_BUILD_ID;
|
|
|
|
}
|
|
|
|
|
2007-03-26 18:22:14 +04:00
|
|
|
return OVERRIDE_NONE;
|
2005-01-17 21:50:18 +03:00
|
|
|
}
|
|
|
|
|
2010-04-07 06:49:23 +04: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) {
|
|
|
|
var um = Components.classes["@mozilla.org/updates/update-manager;1"]
|
|
|
|
.getService(Components.interfaces.nsIUpdateManager);
|
|
|
|
try {
|
|
|
|
// If the updates.xml file is deleted then getUpdateAt will throw.
|
|
|
|
var update = um.getUpdateAt(0)
|
|
|
|
.QueryInterface(Components.interfaces.nsIPropertyBag);
|
|
|
|
} catch (e) {
|
|
|
|
// This should never happen.
|
|
|
|
Components.utils.reportError("Unable to find update: " + e);
|
|
|
|
return defaultOverridePage;
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
if (actions.indexOf("silent") != -1 || actions.indexOf("showURL") == -1)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
return update.getProperty("openURL") || defaultOverridePage;
|
|
|
|
}
|
|
|
|
|
2008-07-04 00:30:24 +04:00
|
|
|
// Flag used to indicate that the arguments to openWindow can be passed directly.
|
|
|
|
const NO_EXTERNAL_URIS = 1;
|
|
|
|
|
|
|
|
function openWindow(parent, url, target, features, args, noExternalArgs) {
|
2005-01-17 21:50:18 +03:00
|
|
|
var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
|
|
|
|
.getService(nsIWindowWatcher);
|
|
|
|
|
2008-07-04 00:30:24 +04:00
|
|
|
if (noExternalArgs == NO_EXTERNAL_URIS) {
|
|
|
|
// Just pass in the defaultArgs directly
|
|
|
|
var argstring;
|
|
|
|
if (args) {
|
|
|
|
argstring = Components.classes["@mozilla.org/supports-string;1"]
|
2005-01-17 21:50:18 +03:00
|
|
|
.createInstance(nsISupportsString);
|
2008-07-04 00:30:24 +04:00
|
|
|
argstring.data = args;
|
|
|
|
}
|
|
|
|
|
|
|
|
return wwatch.openWindow(parent, url, target, features, argstring);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pass an array to avoid the browser "|"-splitting behavior.
|
|
|
|
var argArray = Components.classes["@mozilla.org/supports-array;1"]
|
|
|
|
.createInstance(Components.interfaces.nsISupportsArray);
|
|
|
|
|
|
|
|
// add args to the arguments array
|
|
|
|
var stringArgs = null;
|
|
|
|
if (args instanceof Array) // array
|
|
|
|
stringArgs = args;
|
|
|
|
else if (args) // string
|
|
|
|
stringArgs = [args];
|
|
|
|
|
|
|
|
if (stringArgs) {
|
|
|
|
// put the URIs into argArray
|
|
|
|
var uriArray = Components.classes["@mozilla.org/supports-array;1"]
|
|
|
|
.createInstance(Components.interfaces.nsISupportsArray);
|
|
|
|
stringArgs.forEach(function (uri) {
|
|
|
|
var sstring = Components.classes["@mozilla.org/supports-string;1"]
|
|
|
|
.createInstance(nsISupportsString);
|
|
|
|
sstring.data = uri;
|
|
|
|
uriArray.AppendElement(sstring);
|
|
|
|
});
|
|
|
|
argArray.AppendElement(uriArray);
|
|
|
|
} else {
|
|
|
|
argArray.AppendElement(null);
|
2005-01-17 21:50:18 +03:00
|
|
|
}
|
2008-07-04 00:30:24 +04:00
|
|
|
|
|
|
|
// Pass these as null to ensure that we always trigger the "single URL"
|
2012-06-15 23:09:48 +04:00
|
|
|
// behavior in browser.js's gBrowserInit.onLoad (which handles the window
|
2008-07-04 00:30:24 +04:00
|
|
|
// arguments)
|
|
|
|
argArray.AppendElement(null); // charset
|
|
|
|
argArray.AppendElement(null); // referer
|
|
|
|
argArray.AppendElement(null); // postData
|
|
|
|
argArray.AppendElement(null); // allowThirdPartyFixup
|
|
|
|
|
|
|
|
return wwatch.openWindow(parent, url, target, features, argArray);
|
2005-01-17 21:50:18 +03:00
|
|
|
}
|
|
|
|
|
2005-05-05 06:17:23 +04:00
|
|
|
function openPreferences() {
|
2012-05-09 06:31:51 +04:00
|
|
|
if (Services.prefs.getBoolPref("browser.preferences.inContent")) {
|
|
|
|
var sa = Components.classes["@mozilla.org/supports-array;1"]
|
|
|
|
.createInstance(Components.interfaces.nsISupportsArray);
|
|
|
|
|
|
|
|
var wuri = Components.classes["@mozilla.org/supports-string;1"]
|
|
|
|
.createInstance(Components.interfaces.nsISupportsString);
|
|
|
|
wuri.data = "about:preferences";
|
|
|
|
|
|
|
|
sa.AppendElement(wuri);
|
2005-05-05 06:17:23 +04:00
|
|
|
|
2012-05-09 06:31:51 +04:00
|
|
|
var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
|
|
|
|
.getService(nsIWindowWatcher);
|
|
|
|
|
|
|
|
wwatch.openWindow(null, gBrowserContentHandler.chromeURL,
|
|
|
|
"_blank",
|
|
|
|
"chrome,dialog=no,all",
|
|
|
|
sa);
|
2005-05-05 06:17:23 +04:00
|
|
|
} else {
|
2012-05-09 06:31:51 +04:00
|
|
|
var features = "chrome,titlebar,toolbar,centerscreen,dialog=no";
|
|
|
|
var url = "chrome://browser/content/preferences/preferences.xul";
|
|
|
|
|
|
|
|
var win = getMostRecentWindow("Browser:Preferences");
|
|
|
|
if (win) {
|
|
|
|
win.focus();
|
|
|
|
} else {
|
|
|
|
openWindow(null, url, "_blank", features);
|
|
|
|
}
|
2005-05-05 06:17:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-17 21:50:18 +03:00
|
|
|
function getMostRecentWindow(aType) {
|
|
|
|
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
|
|
|
.getService(nsIWindowMediator);
|
|
|
|
return wm.getMostRecentWindow(aType);
|
|
|
|
}
|
|
|
|
|
2006-06-28 08:06:10 +04:00
|
|
|
function doSearch(searchTerm, cmdLine) {
|
|
|
|
var ss = Components.classes["@mozilla.org/browser/search-service;1"]
|
|
|
|
.getService(nsIBrowserSearchService);
|
|
|
|
|
2010-06-16 20:54:29 +04:00
|
|
|
var submission = ss.defaultEngine.getSubmission(searchTerm);
|
2006-06-28 08:06:10 +04:00
|
|
|
|
|
|
|
// fill our nsISupportsArray with uri-as-wstring, null, null, postData
|
|
|
|
var sa = Components.classes["@mozilla.org/supports-array;1"]
|
|
|
|
.createInstance(Components.interfaces.nsISupportsArray);
|
|
|
|
|
|
|
|
var wuri = Components.classes["@mozilla.org/supports-string;1"]
|
|
|
|
.createInstance(Components.interfaces.nsISupportsString);
|
|
|
|
wuri.data = submission.uri.spec;
|
|
|
|
|
|
|
|
sa.AppendElement(wuri);
|
|
|
|
sa.AppendElement(null);
|
|
|
|
sa.AppendElement(null);
|
|
|
|
sa.AppendElement(submission.postData);
|
|
|
|
|
|
|
|
// XXXbsmedberg: use handURIToExistingBrowser to obey tabbed-browsing
|
|
|
|
// preferences, but need nsIBrowserDOMWindow extensions
|
|
|
|
|
|
|
|
var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
|
|
|
|
.getService(nsIWindowWatcher);
|
|
|
|
|
2010-06-22 20:59:15 +04:00
|
|
|
return wwatch.openWindow(null, gBrowserContentHandler.chromeURL,
|
2006-06-28 08:06:10 +04:00
|
|
|
"_blank",
|
|
|
|
"chrome,dialog=no,all" +
|
2010-06-22 20:59:15 +04:00
|
|
|
gBrowserContentHandler.getFeatures(cmdLine),
|
2006-06-28 08:06:10 +04:00
|
|
|
sa);
|
|
|
|
}
|
|
|
|
|
2010-06-24 19:56:28 +04:00
|
|
|
function nsBrowserContentHandler() {
|
2010-06-22 20:59:15 +04:00
|
|
|
}
|
|
|
|
nsBrowserContentHandler.prototype = {
|
|
|
|
classID: Components.ID("{5d0ce354-df01-421a-83fb-7ead0990c24e}"),
|
|
|
|
|
|
|
|
_xpcom_factory: {
|
|
|
|
createInstance: function bch_factory_ci(outer, iid) {
|
|
|
|
if (outer)
|
|
|
|
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
|
|
|
return gBrowserContentHandler.QueryInterface(iid);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2005-01-17 21:50:18 +03:00
|
|
|
/* helper functions */
|
|
|
|
|
|
|
|
mChromeURL : null,
|
|
|
|
|
|
|
|
get chromeURL() {
|
|
|
|
if (this.mChromeURL) {
|
|
|
|
return this.mChromeURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
var prefb = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(nsIPrefBranch);
|
|
|
|
this.mChromeURL = prefb.getCharPref("browser.chromeURL");
|
2005-05-05 06:17:23 +04:00
|
|
|
|
2005-01-17 21:50:18 +03:00
|
|
|
return this.mChromeURL;
|
|
|
|
},
|
|
|
|
|
|
|
|
/* nsISupports */
|
2010-06-24 19:56:28 +04:00
|
|
|
QueryInterface : XPCOMUtils.generateQI([nsICommandLineHandler,
|
|
|
|
nsIBrowserHandler,
|
|
|
|
nsIContentHandler,
|
|
|
|
nsICommandLineValidator]),
|
2005-01-17 21:50:18 +03:00
|
|
|
|
|
|
|
/* nsICommandLineHandler */
|
|
|
|
handle : function bch_handle(cmdLine) {
|
|
|
|
if (cmdLine.handleFlag("browser", false)) {
|
2008-07-04 00:30:24 +04:00
|
|
|
// Passing defaultArgs, so use NO_EXTERNAL_URIS
|
2005-01-17 21:50:18 +03:00
|
|
|
openWindow(null, this.chromeURL, "_blank",
|
|
|
|
"chrome,dialog=no,all" + this.getFeatures(cmdLine),
|
2008-07-04 00:30:24 +04:00
|
|
|
this.defaultArgs, NO_EXTERNAL_URIS);
|
2005-01-17 21:50:18 +03:00
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
}
|
|
|
|
|
2015-03-10 11:25:19 +03: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)) {
|
|
|
|
throw NS_ERROR_ABORT;
|
|
|
|
}
|
|
|
|
|
2005-08-15 18:01:10 +04:00
|
|
|
var uriparam;
|
2005-01-17 21:50:18 +03:00
|
|
|
try {
|
2005-03-28 01:28:34 +04:00
|
|
|
while ((uriparam = cmdLine.handleFlagWithParam("new-window", false))) {
|
2005-08-08 17:03:17 +04:00
|
|
|
var uri = resolveURIInternal(cmdLine, uriparam);
|
2005-08-26 23:56:55 +04:00
|
|
|
if (!shouldLoadURI(uri))
|
|
|
|
continue;
|
2005-01-17 21:50:18 +03:00
|
|
|
openWindow(null, this.chromeURL, "_blank",
|
|
|
|
"chrome,dialog=no,all" + this.getFeatures(cmdLine),
|
|
|
|
uri.spec);
|
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
2005-08-08 17:03:17 +04:00
|
|
|
Components.utils.reportError(e);
|
2005-01-17 21:50:18 +03:00
|
|
|
}
|
|
|
|
|
2005-08-15 18:01:10 +04:00
|
|
|
try {
|
|
|
|
while ((uriparam = cmdLine.handleFlagWithParam("new-tab", false))) {
|
|
|
|
var uri = resolveURIInternal(cmdLine, uriparam);
|
2006-11-07 06:10:18 +03:00
|
|
|
handURIToExistingBrowser(uri, nsIBrowserDOMWindow.OPEN_NEWTAB, cmdLine);
|
2005-08-15 18:01:10 +04:00
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
Components.utils.reportError(e);
|
|
|
|
}
|
|
|
|
|
2005-01-17 21:50:18 +03:00
|
|
|
var chromeParam = cmdLine.handleFlagWithParam("chrome", false);
|
|
|
|
if (chromeParam) {
|
2005-05-05 06:17:23 +04:00
|
|
|
|
2013-11-05 16:21:28 +04:00
|
|
|
// Handle old preference dialog URLs.
|
|
|
|
if (chromeParam == "chrome://browser/content/pref/pref.xul" ||
|
|
|
|
(Services.prefs.getBoolPref("browser.preferences.inContent") &&
|
|
|
|
chromeParam == "chrome://browser/content/preferences/preferences.xul")) {
|
2005-05-05 06:17:23 +04:00
|
|
|
openPreferences();
|
2007-09-18 04:54:03 +04:00
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
} else try {
|
|
|
|
var uri = resolveURIInternal(cmdLine, chromeParam);
|
2015-06-25 23:25:56 +03:00
|
|
|
let isLocal = (uri) => {
|
2015-07-03 19:16:19 +03:00
|
|
|
let localSchemes = new Set(["chrome", "file", "resource"]);
|
2015-06-25 23:25:56 +03:00
|
|
|
if (uri instanceof Components.interfaces.nsINestedURI) {
|
|
|
|
uri = uri.QueryInterface(Components.interfaces.nsINestedURI).innerMostURI;
|
|
|
|
}
|
|
|
|
return localSchemes.has(uri.scheme);
|
|
|
|
};
|
|
|
|
if (isLocal(uri)) {
|
2015-07-03 18:00:21 +03:00
|
|
|
// If the URI is local, we are sure it won't wrongly inherit chrome privs
|
2015-06-25 23:25:56 +03:00
|
|
|
var features = "chrome,dialog=no,all" + this.getFeatures(cmdLine);
|
2015-07-03 18:00:21 +03:00
|
|
|
openWindow(null, uri.spec, "_blank", features);
|
|
|
|
cmdLine.preventDefault = true;
|
2015-06-25 23:25:56 +03: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 04:54:03 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
Components.utils.reportError(e);
|
2005-05-05 06:17:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cmdLine.handleFlag("preferences", false)) {
|
|
|
|
openPreferences();
|
2005-01-17 21:50:18 +03:00
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
}
|
2006-02-02 20:26:57 +03:00
|
|
|
if (cmdLine.handleFlag("silent", false))
|
|
|
|
cmdLine.preventDefault = true;
|
2014-01-17 10:29:00 +04:00
|
|
|
|
|
|
|
try {
|
|
|
|
var privateWindowParam = cmdLine.handleFlagWithParam("private-window", false);
|
|
|
|
if (privateWindowParam) {
|
|
|
|
var uri = resolveURIInternal(cmdLine, privateWindowParam);
|
|
|
|
handURIToExistingBrowser(uri, nsIBrowserDOMWindow.OPEN_NEWTAB, cmdLine, true);
|
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
}
|
|
|
|
} catch (e if e.result == Components.results.NS_ERROR_INVALID_ARG) {
|
|
|
|
// NS_ERROR_INVALID_ARG is thrown when flag exists, but has no param.
|
|
|
|
if (cmdLine.handleFlag("private-window", false)) {
|
|
|
|
openWindow(null, this.chromeURL, "_blank",
|
|
|
|
"chrome,dialog=no,private,all" + this.getFeatures(cmdLine),
|
|
|
|
"about:privatebrowsing");
|
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
}
|
2012-11-21 05:31:35 +04:00
|
|
|
}
|
2006-06-28 08:06:10 +04:00
|
|
|
|
|
|
|
var searchParam = cmdLine.handleFlagWithParam("search", false);
|
|
|
|
if (searchParam) {
|
|
|
|
doSearch(searchParam, cmdLine);
|
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
}
|
|
|
|
|
2012-11-12 21:26:53 +04:00
|
|
|
// The global PB Service consumes this flag, so only eat it in per-window
|
|
|
|
// PB builds.
|
|
|
|
if (cmdLine.handleFlag("private", false)) {
|
|
|
|
PrivateBrowsingUtils.enterTemporaryAutoStartMode();
|
|
|
|
}
|
|
|
|
|
2009-02-02 20:49:56 +03:00
|
|
|
var fileParam = cmdLine.handleFlagWithParam("file", false);
|
|
|
|
if (fileParam) {
|
|
|
|
var file = cmdLine.resolveFile(fileParam);
|
|
|
|
var ios = Components.classes["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIIOService);
|
|
|
|
var uri = ios.newFileURI(file);
|
|
|
|
openWindow(null, this.chromeURL, "_blank",
|
|
|
|
"chrome,dialog=no,all" + this.getFeatures(cmdLine),
|
|
|
|
uri.spec);
|
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
}
|
|
|
|
|
2015-06-19 18:52:44 +03:00
|
|
|
if (AppConstants.platform == "win") {
|
|
|
|
// 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 08:06:10 +04:00
|
|
|
|
2015-06-19 18:52:44 +03:00
|
|
|
searchParam = param.substr(2);
|
|
|
|
doSearch(searchParam, cmdLine);
|
|
|
|
}
|
2006-06-28 08:06:10 +04:00
|
|
|
}
|
|
|
|
}
|
2005-01-17 21:50:18 +03:00
|
|
|
},
|
|
|
|
|
2015-06-19 18:52:44 +03: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";
|
|
|
|
}
|
|
|
|
info += " --search <term> Search <term> with your default search engine.\n";
|
|
|
|
return info;
|
|
|
|
},
|
2005-01-17 21:50:18 +03:00
|
|
|
|
|
|
|
/* nsIBrowserHandler */
|
|
|
|
|
2005-04-11 03:32:51 +04:00
|
|
|
get defaultArgs() {
|
|
|
|
var prefb = Components.classes["@mozilla.org/preferences-service;1"]
|
|
|
|
.getService(nsIPrefBranch);
|
|
|
|
|
2012-11-12 21:26:53 +04:00
|
|
|
if (!gFirstWindow) {
|
|
|
|
gFirstWindow = true;
|
|
|
|
if (PrivateBrowsingUtils.isInTemporaryAutoStartMode) {
|
|
|
|
return "about:privatebrowsing";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-26 18:22:14 +04:00
|
|
|
var overridePage = "";
|
2013-11-19 23:57:46 +04:00
|
|
|
var willRestoreSession = false;
|
2006-07-05 18:04:36 +04:00
|
|
|
try {
|
2012-03-28 20:56:56 +04: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.
|
|
|
|
let old_mstone = "unknown";
|
|
|
|
try {
|
|
|
|
old_mstone = Services.prefs.getCharPref("browser.startup.homepage_override.mstone");
|
|
|
|
} catch (ex) {}
|
2010-08-26 14:19:37 +04:00
|
|
|
let override = needHomepageOverride(prefb);
|
|
|
|
if (override != OVERRIDE_NONE) {
|
|
|
|
switch (override) {
|
|
|
|
case OVERRIDE_NEW_PROFILE:
|
|
|
|
// New profile.
|
2010-11-08 17:03:42 +03:00
|
|
|
overridePage = Services.urlFormatter.formatURLPref("startup.homepage_welcome_url");
|
2010-08-26 14:19:37 +04:00
|
|
|
break;
|
|
|
|
case OVERRIDE_NEW_MSTONE:
|
2013-11-19 23:57:46 +04: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.
|
2010-08-26 14:19:37 +04:00
|
|
|
var ss = Components.classes["@mozilla.org/browser/sessionstartup;1"]
|
|
|
|
.getService(Components.interfaces.nsISessionStartup);
|
2013-11-19 23:57:46 +04:00
|
|
|
willRestoreSession = ss.isAutomaticRestoreEnabled();
|
|
|
|
|
2010-11-08 17:03:42 +03:00
|
|
|
overridePage = Services.urlFormatter.formatURLPref("startup.homepage_override_url");
|
2010-08-26 14:19:37 +04:00
|
|
|
if (prefb.prefHasUserValue("app.update.postupdate"))
|
|
|
|
overridePage = getPostUpdateOverridePage(overridePage);
|
2012-03-28 20:56:56 +04:00
|
|
|
|
|
|
|
overridePage = overridePage.replace("%OLD_VERSION%", old_mstone);
|
2010-08-26 14:19:37 +04:00
|
|
|
break;
|
|
|
|
}
|
2010-04-07 06:49:23 +04:00
|
|
|
}
|
2007-03-26 18:22:14 +04:00
|
|
|
} catch (ex) {}
|
2005-04-11 03:32:51 +04:00
|
|
|
|
2007-03-26 18:22:14 +04:00
|
|
|
// formatURLPref might return "about:blank" if getting the pref fails
|
|
|
|
if (overridePage == "about:blank")
|
|
|
|
overridePage = "";
|
2006-12-08 00:28:32 +03:00
|
|
|
|
2007-03-27 01:20:28 +04:00
|
|
|
var startPage = "";
|
2005-04-11 03:32:51 +04:00
|
|
|
try {
|
|
|
|
var choice = prefb.getIntPref("browser.startup.page");
|
2008-03-29 09:47:04 +03:00
|
|
|
if (choice == 1 || choice == 3)
|
2007-03-26 18:22:14 +04:00
|
|
|
startPage = this.startPage;
|
2007-03-27 01:20:28 +04:00
|
|
|
} catch (e) {
|
|
|
|
Components.utils.reportError(e);
|
|
|
|
}
|
2005-04-11 03:32:51 +04:00
|
|
|
|
2007-03-26 18:22:14 +04:00
|
|
|
if (startPage == "about:blank")
|
|
|
|
startPage = "";
|
2006-07-05 18:04:36 +04:00
|
|
|
|
2007-03-26 18:22:14 +04:00
|
|
|
// Only show the startPage if we're not restoring an update session.
|
2013-11-19 23:57:46 +04:00
|
|
|
if (overridePage && startPage && !willRestoreSession)
|
2007-03-26 18:22:14 +04:00
|
|
|
return overridePage + "|" + startPage;
|
2006-07-05 18:04:36 +04:00
|
|
|
|
2007-03-26 18:22:14 +04:00
|
|
|
return overridePage || startPage || "about:blank";
|
2005-04-11 03:32:51 +04:00
|
|
|
},
|
|
|
|
|
2005-01-17 21:50:18 +03:00
|
|
|
get startPage() {
|
2011-10-04 03:28:13 +04:00
|
|
|
var uri = Services.prefs.getComplexValue("browser.startup.homepage",
|
|
|
|
nsIPrefLocalizedString).data;
|
2005-08-25 09:28:37 +04:00
|
|
|
if (!uri) {
|
2011-10-04 03:28:13 +04:00
|
|
|
Services.prefs.clearUserPref("browser.startup.homepage");
|
|
|
|
uri = Services.prefs.getComplexValue("browser.startup.homepage",
|
|
|
|
nsIPrefLocalizedString).data;
|
2005-01-17 21:50:18 +03:00
|
|
|
}
|
|
|
|
return uri;
|
|
|
|
},
|
|
|
|
|
|
|
|
mFeatures : null,
|
|
|
|
|
|
|
|
getFeatures : function bch_features(cmdLine) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
}
|
2012-11-12 21:26:53 +04:00
|
|
|
|
|
|
|
// The global PB Service consumes this flag, so only eat it in per-window
|
|
|
|
// PB builds.
|
|
|
|
if (PrivateBrowsingUtils.isInTemporaryAutoStartMode) {
|
|
|
|
this.mFeatures = ",private";
|
|
|
|
}
|
2005-01-17 21:50:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.mFeatures;
|
|
|
|
},
|
|
|
|
|
|
|
|
/* nsIContentHandler */
|
|
|
|
|
|
|
|
handleContent : function bch_handleContent(contentType, context, request) {
|
2005-02-19 04:36:59 +03:00
|
|
|
try {
|
2005-02-27 21:33:27 +03:00
|
|
|
var webNavInfo = Components.classes["@mozilla.org/webnavigation-info;1"]
|
|
|
|
.getService(nsIWebNavigationInfo);
|
|
|
|
if (!webNavInfo.isTypeSupported(contentType, null)) {
|
|
|
|
throw NS_ERROR_WONT_HANDLE_CONTENT;
|
|
|
|
}
|
2005-02-19 04:36:59 +03:00
|
|
|
} catch (e) {
|
|
|
|
throw NS_ERROR_WONT_HANDLE_CONTENT;
|
|
|
|
}
|
|
|
|
|
2005-01-17 21:50:18 +03:00
|
|
|
request.QueryInterface(nsIChannel);
|
2007-07-19 22:14:05 +04:00
|
|
|
handURIToExistingBrowser(request.URI,
|
|
|
|
nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW, null);
|
2005-01-17 21:50:18 +03:00
|
|
|
request.cancel(NS_BINDING_ABORTED);
|
|
|
|
},
|
|
|
|
|
2007-07-11 09:59:56 +04:00
|
|
|
/* nsICommandLineValidator */
|
|
|
|
validate : function bch_validate(cmdLine) {
|
|
|
|
// 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 ||
|
|
|
|
cmdLine.state == nsICommandLine.STATE_REMOTE_EXPLICIT)) {
|
|
|
|
var urlParam = cmdLine.getArgument(urlFlagIdx + 1);
|
|
|
|
if (cmdLine.length != urlFlagIdx + 2 || /firefoxurl:/.test(urlParam))
|
|
|
|
throw NS_ERROR_ABORT;
|
2015-06-19 02:16:52 +03:00
|
|
|
var isDefault = false;
|
|
|
|
try {
|
|
|
|
var url = Services.urlFormatter.formatURLPref("app.support.baseURL") +
|
|
|
|
"win10-default-browser";
|
|
|
|
if (urlParam == url) {
|
|
|
|
var shellSvc = Components.classes["@mozilla.org/browser/shell-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIShellService);
|
|
|
|
isDefault = shellSvc.isDefaultBrowser(false, false);
|
|
|
|
}
|
|
|
|
} catch (ex) {}
|
|
|
|
if (isDefault) {
|
|
|
|
// Firefox is already the default HTTP handler.
|
|
|
|
// We don't have to show the instruction page.
|
|
|
|
throw NS_ERROR_ABORT;
|
|
|
|
}
|
2007-07-11 09:59:56 +04:00
|
|
|
cmdLine.handleFlag("osint", false)
|
|
|
|
}
|
|
|
|
},
|
2005-01-17 21:50:18 +03:00
|
|
|
};
|
2010-06-22 20:59:15 +04:00
|
|
|
var gBrowserContentHandler = new nsBrowserContentHandler();
|
2005-01-17 21:50:18 +03:00
|
|
|
|
2014-01-17 10:29:00 +04:00
|
|
|
function handURIToExistingBrowser(uri, location, cmdLine, forcePrivate)
|
2005-04-04 23:08:55 +04:00
|
|
|
{
|
2005-08-26 23:56:55 +04:00
|
|
|
if (!shouldLoadURI(uri))
|
|
|
|
return;
|
|
|
|
|
2014-01-17 10:29:00 +04: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-27 03:15:57 +04:00
|
|
|
var navWin = RecentWindow.getMostRecentBrowserWindow({private: allowPrivate});
|
2005-04-04 23:08:55 +04:00
|
|
|
if (!navWin) {
|
|
|
|
// if we couldn't load it in an existing window, open a new one
|
2014-01-17 10:29:00 +04:00
|
|
|
var features = "chrome,dialog=no,all" + gBrowserContentHandler.getFeatures(cmdLine);
|
|
|
|
if (forcePrivate) {
|
|
|
|
features += ",private";
|
|
|
|
}
|
|
|
|
openWindow(null, gBrowserContentHandler.chromeURL, "_blank", features, uri.spec);
|
2005-04-04 23:08:55 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var navNav = navWin.QueryInterface(nsIInterfaceRequestor)
|
|
|
|
.getInterface(nsIWebNavigation);
|
|
|
|
var rootItem = navNav.QueryInterface(nsIDocShellTreeItem).rootTreeItem;
|
|
|
|
var rootWin = rootItem.QueryInterface(nsIInterfaceRequestor)
|
|
|
|
.getInterface(nsIDOMWindow);
|
|
|
|
var bwin = rootWin.QueryInterface(nsIDOMChromeWindow).browserDOMWindow;
|
|
|
|
bwin.openURI(uri, null, location,
|
|
|
|
nsIBrowserDOMWindow.OPEN_EXTERNAL);
|
|
|
|
}
|
|
|
|
|
2010-06-24 19:56:28 +04:00
|
|
|
function nsDefaultCommandLineHandler() {
|
2010-06-22 20:59:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDefaultCommandLineHandler.prototype = {
|
|
|
|
classID: Components.ID("{47cd0651-b1be-4a0f-b5c4-10e5a573ef71}"),
|
2005-04-04 23:08:55 +04:00
|
|
|
|
2005-01-17 21:50:18 +03:00
|
|
|
/* nsISupports */
|
|
|
|
QueryInterface : function dch_QI(iid) {
|
|
|
|
if (!iid.equals(nsISupports) &&
|
2010-06-22 20:59:15 +04:00
|
|
|
!iid.equals(nsICommandLineHandler))
|
2006-12-06 04:12:06 +03:00
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
2005-01-17 21:50:18 +03:00
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2007-02-14 03:04:30 +03:00
|
|
|
_haveProfile: false,
|
2007-01-30 08:14:50 +03:00
|
|
|
|
2005-01-17 21:50:18 +03:00
|
|
|
/* nsICommandLineHandler */
|
|
|
|
handle : function dch_handle(cmdLine) {
|
|
|
|
var urilist = [];
|
|
|
|
|
2015-06-19 18:52:44 +03: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.
|
|
|
|
var fl = Components.classes["@mozilla.org/file/directory_service;1"]
|
|
|
|
.getService(Components.interfaces.nsIProperties);
|
|
|
|
var dir = fl.get("ProfD", Components.interfaces.nsILocalFile);
|
|
|
|
this._haveProfile = true;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
while ((ar = cmdLine.handleFlagWithParam("url", false))) { }
|
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
}
|
2007-02-14 03:04:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-07 04:11:05 +03:00
|
|
|
let redirectWinSearch = false;
|
|
|
|
if (AppConstants.isPlatformAndVersionAtLeast("win", "10")) {
|
|
|
|
redirectWinSearch = Services.prefs.getBoolPref("browser.search.redirectWindowsSearch");
|
|
|
|
}
|
|
|
|
|
2005-01-17 21:50:18 +03:00
|
|
|
try {
|
|
|
|
var ar;
|
2005-03-28 01:28:34 +04:00
|
|
|
while ((ar = cmdLine.handleFlagWithParam("url", false))) {
|
2007-02-13 04:14:48 +03:00
|
|
|
var uri = resolveURIInternal(cmdLine, ar);
|
2015-07-07 04:11:05 +03:00
|
|
|
|
|
|
|
// Searches in the Windows 10 task bar searchbox simply open the default browser
|
|
|
|
// with a URL for a search on Bing. Here we extract the search term and use the
|
|
|
|
// user's default search engine instead.
|
2015-07-17 03:29:32 +03:00
|
|
|
var uriScheme = "", uriHost = "", uriPath = "";
|
|
|
|
try {
|
|
|
|
uriScheme = uri.scheme;
|
|
|
|
uriHost = uri.host;
|
|
|
|
uriPath = uri.path;
|
|
|
|
} catch(e) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Most Windows searches are "https://www.bing.com/search...", but bug
|
|
|
|
// 1182308 reports a Chinese edition of Windows 10 using
|
|
|
|
// "http://cn.bing.com/search...", so be a bit flexible in what we match.
|
|
|
|
if (redirectWinSearch &&
|
|
|
|
(uriScheme == "http" || uriScheme == "https") &&
|
|
|
|
uriHost.endsWith(".bing.com") && uriPath.startsWith("/search")) {
|
2015-07-07 04:11:05 +03:00
|
|
|
try {
|
|
|
|
var url = uri.QueryInterface(Components.interfaces.nsIURL);
|
|
|
|
var params = new URLSearchParams(url.query);
|
|
|
|
// We don't want to rewrite all Bing URLs coming from external apps. Look
|
|
|
|
// for the magic URL parm that's present in searches from the task bar.
|
2015-07-17 23:24:25 +03:00
|
|
|
// (Typed searches use "form=WNSGPH", Cortana voice searches use "FORM=WNSBOX"
|
|
|
|
// for direct results, or "FORM=WNSFC2" for "see more results on
|
|
|
|
// Bing.com")
|
2015-07-07 04:11:05 +03:00
|
|
|
var formParam = params.get("form");
|
|
|
|
if (!formParam) {
|
|
|
|
formParam = params.get("FORM");
|
|
|
|
}
|
2015-07-17 23:24:25 +03:00
|
|
|
if (formParam == "WNSGPH" || formParam == "WNSBOX" || formParam == "WNSFC2") {
|
2015-07-07 04:11:05 +03:00
|
|
|
var term = params.get("q");
|
|
|
|
var ss = Components.classes["@mozilla.org/browser/search-service;1"]
|
|
|
|
.getService(nsIBrowserSearchService);
|
|
|
|
var submission = ss.defaultEngine.getSubmission(term, null, "searchbar");
|
|
|
|
uri = submission.uri;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
Components.utils.reportError("Couldn't redirect Windows search: " + e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-26 23:45:29 +04:00
|
|
|
urilist.push(uri);
|
2005-01-17 21:50:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
2005-08-08 17:03:17 +04:00
|
|
|
Components.utils.reportError(e);
|
2005-01-17 21:50:18 +03:00
|
|
|
}
|
|
|
|
|
2014-08-05 17:47:17 +04:00
|
|
|
for (let i = 0; i < cmdLine.length; ++i) {
|
2005-01-17 21:50:18 +03:00
|
|
|
var curarg = cmdLine.getArgument(i);
|
|
|
|
if (curarg.match(/^-/)) {
|
2005-08-08 17:03:17 +04:00
|
|
|
Components.utils.reportError("Warning: unrecognized command line flag " + curarg + "\n");
|
2005-01-17 21:50:18 +03:00
|
|
|
// To emulate the pre-nsICommandLine behavior, we ignore
|
|
|
|
// the argument after an unrecognized flag.
|
|
|
|
++i;
|
|
|
|
} else {
|
|
|
|
try {
|
2005-08-08 17:03:17 +04:00
|
|
|
urilist.push(resolveURIInternal(cmdLine, curarg));
|
2005-08-26 23:56:55 +04:00
|
|
|
}
|
2005-01-17 21:50:18 +03:00
|
|
|
catch (e) {
|
2005-08-08 17:03:17 +04:00
|
|
|
Components.utils.reportError("Error opening URI '" + curarg + "' from the command line: " + e + "\n");
|
2005-01-17 21:50:18 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (urilist.length) {
|
|
|
|
if (cmdLine.state != nsICommandLine.STATE_INITIAL_LAUNCH &&
|
|
|
|
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 {
|
2006-11-07 06:10:18 +03:00
|
|
|
handURIToExistingBrowser(urilist[0], nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW, cmdLine);
|
2005-01-17 21:50:18 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-04 00:30:24 +04:00
|
|
|
var URLlist = urilist.filter(shouldLoadURI).map(function (u) u.spec);
|
|
|
|
if (URLlist.length) {
|
2010-06-22 20:59:15 +04:00
|
|
|
openWindow(null, gBrowserContentHandler.chromeURL, "_blank",
|
|
|
|
"chrome,dialog=no,all" + gBrowserContentHandler.getFeatures(cmdLine),
|
2008-07-04 00:30:24 +04:00
|
|
|
URLlist);
|
2005-08-26 23:56:55 +04:00
|
|
|
}
|
2005-01-17 21:50:18 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
else if (!cmdLine.preventDefault) {
|
2015-06-19 18:52:44 +03:00
|
|
|
if (AppConstants.isPlatformAndVersionAtLeast("win", "10") &&
|
|
|
|
cmdLine.state != nsICommandLine.STATE_INITIAL_LAUNCH &&
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2008-07-04 00:30:24 +04:00
|
|
|
// Passing defaultArgs, so use NO_EXTERNAL_URIS
|
2010-06-22 20:59:15 +04:00
|
|
|
openWindow(null, gBrowserContentHandler.chromeURL, "_blank",
|
|
|
|
"chrome,dialog=no,all" + gBrowserContentHandler.getFeatures(cmdLine),
|
|
|
|
gBrowserContentHandler.defaultArgs, NO_EXTERNAL_URIS);
|
2005-01-17 21:50:18 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-08-18 21:47:57 +04:00
|
|
|
helpInfo : "",
|
2005-01-17 21:50:18 +03:00
|
|
|
};
|
|
|
|
|
2010-06-22 20:59:15 +04:00
|
|
|
var components = [nsBrowserContentHandler, nsDefaultCommandLineHandler];
|
2012-10-31 20:13:28 +04:00
|
|
|
this.NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
|