зеркало из https://github.com/mozilla/gecko-dev.git
Bug 593782 - cleanup command line handling [r=mfinkle, r=fabrice]
This commit is contained in:
Родитель
0c3e14f841
Коммит
38a53eb9bf
|
@ -136,34 +136,6 @@ let Util = {
|
|||
return Math.max(min, Math.min(max, num));
|
||||
},
|
||||
|
||||
/**
|
||||
* Determines whether a home page override is needed.
|
||||
* Returns:
|
||||
* "new profile" if this is the first run with a new profile.
|
||||
* "new version" if this is the first run with a build with a different
|
||||
* Gecko milestone (i.e. right after an upgrade).
|
||||
* "none" otherwise.
|
||||
*/
|
||||
needHomepageOverride: function needHomepageOverride() {
|
||||
let savedmstone = null;
|
||||
try {
|
||||
savedmstone = Services.prefs.getCharPref("browser.startup.homepage_override.mstone");
|
||||
} catch (e) {}
|
||||
|
||||
if (savedmstone == "ignore")
|
||||
return "none";
|
||||
|
||||
#expand let ourmstone = "__MOZ_APP_VERSION__";
|
||||
|
||||
if (ourmstone != savedmstone) {
|
||||
Services.prefs.setCharPref("browser.startup.homepage_override.mstone", ourmstone);
|
||||
|
||||
return (savedmstone ? "new version" : "new profile");
|
||||
}
|
||||
|
||||
return "none";
|
||||
},
|
||||
|
||||
/** Don't display anything in the urlbar for these special URIs. */
|
||||
isURLEmpty: function isURLEmpty(aURL) {
|
||||
return (!aURL || aURL == "about:blank" || aURL == "about:empty" || aURL == "about:home");
|
||||
|
|
|
@ -363,10 +363,6 @@ var Browser = {
|
|||
dump("###########" + e + "\n");
|
||||
}
|
||||
|
||||
let needOverride = Util.needHomepageOverride();
|
||||
if (needOverride == "new profile")
|
||||
this.initNewProfile();
|
||||
|
||||
let container = document.getElementById("tile-container");
|
||||
let bv = this._browserView = new BrowserView(container, Browser.getVisibleRect);
|
||||
|
||||
|
@ -507,45 +503,13 @@ var Browser = {
|
|||
// Make sure we're online before attempting to load
|
||||
Util.forceOnline();
|
||||
|
||||
// Command line arguments/initial homepage
|
||||
let whereURI = this.getHomePage();
|
||||
if (needOverride == "new profile")
|
||||
whereURI = "about:firstrun";
|
||||
// If this is an intial window launch the commandline handler passes us the default
|
||||
// page as an argument
|
||||
let defaultURL = this.getHomePage();
|
||||
if (window.arguments && window.arguments[0])
|
||||
defaultURL = window.arguments[0];
|
||||
|
||||
// If this is an intial window launch (was a nsICommandLine passed via window params)
|
||||
// we execute some logic to load the initial launch page
|
||||
if (window.arguments && window.arguments[0]) {
|
||||
if (window.arguments[0] instanceof Ci.nsICommandLine) {
|
||||
try {
|
||||
var cmdLine = window.arguments[0];
|
||||
|
||||
// Check for and use a single commandline parameter
|
||||
if (cmdLine.length == 1) {
|
||||
// Assume the first arg is a URI if it is not a flag
|
||||
var uri = cmdLine.getArgument(0);
|
||||
if (uri != "" && uri[0] != '-') {
|
||||
whereURI = cmdLine.resolveURI(uri);
|
||||
if (whereURI)
|
||||
whereURI = whereURI.spec;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for the "url" flag
|
||||
var uriFlag = cmdLine.handleFlagWithParam("url", false);
|
||||
if (uriFlag) {
|
||||
whereURI = cmdLine.resolveURI(uriFlag);
|
||||
if (whereURI)
|
||||
whereURI = whereURI.spec;
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
else {
|
||||
// This window could have been opened by nsIBrowserDOMWindow.openURI
|
||||
whereURI = window.arguments[0];
|
||||
}
|
||||
}
|
||||
|
||||
this.addTab(whereURI, true);
|
||||
this.addTab(defaultURL, true);
|
||||
|
||||
// JavaScript Error Console
|
||||
if (Services.prefs.getBoolPref("browser.console.showInPanel")){
|
||||
|
@ -656,9 +620,6 @@ var Browser = {
|
|||
window.controllers.removeController(BrowserUI);
|
||||
},
|
||||
|
||||
initNewProfile: function initNewProfile() {
|
||||
},
|
||||
|
||||
getHomePage: function () {
|
||||
let url = "about:home";
|
||||
try {
|
||||
|
|
|
@ -42,8 +42,14 @@ const Cu = Components.utils;
|
|||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function openWindow(aParent, aURL, aTarget, aFeatures) {
|
||||
return Services.ww.openWindow(aParent, aURL, aTarget, aFeatures, null);
|
||||
function openWindow(aParent, aURL, aTarget, aFeatures, aArgs) {
|
||||
let argString = null;
|
||||
if (aArgs) {
|
||||
argString = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString);
|
||||
argString.data = aArgs;
|
||||
}
|
||||
|
||||
return Services.ww.openWindow(aParent, aURL, aTarget, aFeatures, argString);
|
||||
}
|
||||
|
||||
function resolveURIInternal(aCmdLine, aArgument) {
|
||||
|
@ -71,6 +77,43 @@ function resolveURIInternal(aCmdLine, aArgument) {
|
|||
return uri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a home page override is needed.
|
||||
* Returns:
|
||||
* "new profile" if this is the first run with a new profile.
|
||||
* "new version" if this is the first run with a build with a different
|
||||
* Gecko milestone (i.e. right after an upgrade).
|
||||
* "none" otherwise.
|
||||
*/
|
||||
function needHomepageOverride() {
|
||||
let savedmstone = null;
|
||||
try {
|
||||
savedmstone = Services.prefs.getCharPref("browser.startup.homepage_override.mstone");
|
||||
} catch (e) {}
|
||||
|
||||
if (savedmstone == "ignore")
|
||||
return "none";
|
||||
|
||||
#expand let ourmstone = "__MOZ_APP_VERSION__";
|
||||
|
||||
if (ourmstone != savedmstone) {
|
||||
Services.prefs.setCharPref("browser.startup.homepage_override.mstone", ourmstone);
|
||||
|
||||
return (savedmstone ? "new version" : "new profile");
|
||||
}
|
||||
|
||||
return "none";
|
||||
}
|
||||
|
||||
function getHomePage() {
|
||||
let url = "about:home";
|
||||
try {
|
||||
url = Services.prefs.getComplexValue("browser.startup.homepage", Ci.nsIPrefLocalizedString).data;
|
||||
} catch (e) { }
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
function BrowserCLH() { }
|
||||
|
||||
|
@ -95,12 +138,14 @@ BrowserCLH.prototype = {
|
|||
let chromeParam = aCmdLine.handleFlagWithParam("chrome", false);
|
||||
if (chromeParam) {
|
||||
try {
|
||||
// only load URIs which do not inherit chrome privs
|
||||
// Only load URIs which do not inherit chrome privs
|
||||
let features = "chrome,dialog=no,all";
|
||||
let uri = resolveURIInternal(aCmdLine, chromeParam);
|
||||
let netutil = Cc["@mozilla.org/network/util;1"].getService(Ci.nsINetUtil);
|
||||
if (!netutil.URIChainHasFlags(uri, Ci.nsIHttpProtocolHandler.URI_INHERITS_SECURITY_CONTEXT)) {
|
||||
openWindow(null, uri.spec, "_blank", features);
|
||||
openWindow(null, uri.spec, "_blank", features, null);
|
||||
|
||||
// Stop the normal commandline processing from continuing
|
||||
aCmdLine.preventDefault = true;
|
||||
}
|
||||
}
|
||||
|
@ -109,18 +154,17 @@ BrowserCLH.prototype = {
|
|||
}
|
||||
}
|
||||
|
||||
let win;
|
||||
try {
|
||||
win = Services.wm.getMostRecentWindow("navigator:browser");
|
||||
if (!win)
|
||||
return;
|
||||
// Keep an array of possible URL arguments
|
||||
let uris = [];
|
||||
|
||||
win.focus();
|
||||
aCmdLine.preventDefault = true;
|
||||
} catch (e) { }
|
||||
// Check for the "url" flag
|
||||
let uriFlag = aCmdLine.handleFlagWithParam("url", false);
|
||||
if (uriFlag) {
|
||||
let uri = resolveURIInternal(aCmdLine, uriFlag);
|
||||
if (uri)
|
||||
uris.push(uri);
|
||||
}
|
||||
|
||||
// Assumption: All CLH arguments we've received have been sent remotely,
|
||||
// or we wouldn't already have a window. Therefore: open 'em all!
|
||||
for (let i = 0; i < aCmdLine.length; i++) {
|
||||
let arg = aCmdLine.getArgument(i);
|
||||
if (!arg || arg[0] == '-')
|
||||
|
@ -128,8 +172,46 @@ BrowserCLH.prototype = {
|
|||
|
||||
let uri = resolveURIInternal(aCmdLine, arg);
|
||||
if (uri)
|
||||
win.browserDOMWindow.openURI(uri, null, Ci.nsIBrowserDOMWindow.OPEN_NEWTAB, null);
|
||||
uris.push(uri);
|
||||
}
|
||||
|
||||
// Open the main browser window, if we don't already have one
|
||||
let win;
|
||||
try {
|
||||
win = Services.wm.getMostRecentWindow("navigator:browser");
|
||||
if (!win) {
|
||||
// Default to the saved homepage
|
||||
let defaultURL = getHomePage();
|
||||
|
||||
// Override the default if we have a new profile
|
||||
if (needHomepageOverride() == "new profile")
|
||||
defaultURL = "about:firstrun";
|
||||
|
||||
// Override the default if we have a URL passed on command line
|
||||
if (uris.length > 0) {
|
||||
defaultURL = uris[0].spec;
|
||||
uris = uris.slice(1);
|
||||
}
|
||||
|
||||
win = openWindow(null, "chrome://browser/content/browser.xul", "_blank", "chrome,dialog=no,all", defaultURL);
|
||||
}
|
||||
|
||||
win.focus();
|
||||
|
||||
// Stop the normal commandline processing from continuing. We just opened the main browser window
|
||||
aCmdLine.preventDefault = true;
|
||||
} catch (e) { }
|
||||
|
||||
// Assumption: All remaining command line arguments have been sent remotely (browser is already running)
|
||||
// Action: Open any URLs we find into an existing browser window
|
||||
|
||||
// First, get a browserDOMWindow object
|
||||
while (!win.browserDOMWindow)
|
||||
Services.tm.currentThread.processNextEvent(true);
|
||||
|
||||
// Open any URIs into new tabs
|
||||
for (let i = 0; i < uris.length; i++)
|
||||
win.browserDOMWindow.openURI(uris[i], null, Ci.nsIBrowserDOMWindow.OPEN_NEWTAB, null);
|
||||
},
|
||||
|
||||
// QI
|
||||
|
|
|
@ -52,6 +52,7 @@ XPIDLSRCS = \
|
|||
|
||||
EXTRA_PP_COMPONENTS = \
|
||||
AboutRedirector.js \
|
||||
BrowserCLH.js \
|
||||
DirectoryProvider.js\
|
||||
Sidebar.js \
|
||||
SessionStore.js \
|
||||
|
@ -65,7 +66,6 @@ EXTRA_COMPONENTS = \
|
|||
DownloadManagerUI.js \
|
||||
HelperAppDialog.js \
|
||||
PromptService.js \
|
||||
BrowserCLH.js \
|
||||
ContentDispatchChooser.js \
|
||||
AutoCompleteCache.js \
|
||||
AddonUpdateService.js \
|
||||
|
|
Загрузка…
Ссылка в новой задаче