diff --git a/mozilla/allmakefiles.sh b/mozilla/allmakefiles.sh index 036f1eb7615..62728886d51 100755 --- a/mozilla/allmakefiles.sh +++ b/mozilla/allmakefiles.sh @@ -934,6 +934,9 @@ toolkit/components/autocomplete/public/Makefile toolkit/components/autocomplete/src/Makefile toolkit/components/Makefile toolkit/components/build/Makefile +toolkit/components/commandlines/Makefile +toolkit/components/commandlines/public/Makefile +toolkit/components/commandlines/src/Makefile toolkit/components/console/Makefile toolkit/components/downloads/public/Makefile toolkit/components/downloads/Makefile diff --git a/mozilla/browser/base/content/browser.js b/mozilla/browser/base/content/browser.js index 8dfb963fb88..d868654a53e 100644 --- a/mozilla/browser/base/content/browser.js +++ b/mozilla/browser/base/content/browser.js @@ -2543,11 +2543,9 @@ function toOpenWindowByType(inType, uri, features) function OpenBrowserWindow() { var charsetArg = new String(); - var handler = Components.classes['@mozilla.org/commandlinehandler/general-startup;1?type=browser']; - handler = handler.getService(); - handler = handler.QueryInterface(Components.interfaces.nsICmdLineHandler); - var startpage = handler.defaultArgs; - var url = handler.chromeUrlForTask; + var handler = Components.classes["@mozilla.org/browser/clh;1"] + .getService(Components.interfaces.nsIBrowserHandler); + var startpage = handler.startPage; var wintype = document.firstChild.getAttribute('windowtype'); // if and only if the current window is a browser window and it has a document with a character @@ -2559,11 +2557,11 @@ function OpenBrowserWindow() charsetArg = "charset="+DocCharset; //we should "inherit" the charset menu setting in a new window - window.openDialog(url, "_blank", "chrome,all,dialog=no", startpage, charsetArg); + window.openDialog("chrome://browser/content/", "_blank", "chrome,all,dialog=no", startpage, charsetArg); } else // forget about the charset information. { - window.openDialog(url, "_blank", "chrome,all,dialog=no", startpage); + window.openDialog("chrome://browser/content/", "_blank", "chrome,all,dialog=no", startpage); } } diff --git a/mozilla/browser/components/Makefile.in b/mozilla/browser/components/Makefile.in index 94b5e8f8592..2427036e2b8 100644 --- a/mozilla/browser/components/Makefile.in +++ b/mozilla/browser/components/Makefile.in @@ -42,6 +42,17 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk +MODULE = browsercomps +XPIDL_MODULE = browsercompsbase + +XPIDLSRCS = \ + nsIBrowserHandler.idl \ + $(NULL) + +EXTRA_PP_COMPONENTS = \ + nsBrowserContentHandler.js \ + $(NULL) + DIRS = \ bookmarks \ help \ diff --git a/mozilla/browser/components/bookmarks/src/Makefile.in b/mozilla/browser/components/bookmarks/src/Makefile.in index 79dca742208..d09e11690b6 100644 --- a/mozilla/browser/components/bookmarks/src/Makefile.in +++ b/mozilla/browser/components/bookmarks/src/Makefile.in @@ -50,6 +50,7 @@ REQUIRES = xpcom \ caps \ xpconnect \ js \ + browsercomps \ $(NULL) CPPSRCS = nsBookmarksService.cpp \ diff --git a/mozilla/browser/components/bookmarks/src/nsBookmarksService.cpp b/mozilla/browser/components/bookmarks/src/nsBookmarksService.cpp index e5db185c9c2..e9d9428d25f 100644 --- a/mozilla/browser/components/bookmarks/src/nsBookmarksService.cpp +++ b/mozilla/browser/components/bookmarks/src/nsBookmarksService.cpp @@ -51,6 +51,7 @@ #include "nsBookmarksService.h" #include "nsArrayEnumerator.h" #include "nsArray.h" +#include "nsIBrowserHandler.h" #include "nsIDOMWindow.h" #include "nsIObserverService.h" #include "nsIRDFContainer.h" @@ -68,7 +69,6 @@ #include "nsAppDirectoryServiceDefs.h" #include "nsDirectoryServiceDefs.h" #include "nsUnicharUtils.h" -#include "nsICmdLineHandler.h" #include "nsISound.h" #include "nsIPrompt.h" @@ -2427,14 +2427,7 @@ nsBookmarksService::OnStopRequest(nsIRequest* request, nsISupports *ctxt, if (NS_FAILED(rv)) return rv; suppArray->AppendElement(suppString); - nsCOMPtr handler(do_GetService("@mozilla.org/commandlinehandler/general-startup;1?type=browser", &rv)); - if (NS_FAILED(rv)) return rv; - - nsXPIDLCString chromeUrl; - rv = handler->GetChromeUrlForTask(getter_Copies(chromeUrl)); - if (NS_FAILED(rv)) return rv; - - wwatch->OpenWindow(0, chromeUrl, "_blank", "chrome,dialog=no,all", + wwatch->OpenWindow(0, "chrome://browser/content/", "_blank", "chrome,dialog=no,all", suppArray, getter_AddRefs(newWindow)); } } diff --git a/mozilla/browser/components/nsBrowserContentHandler.js b/mozilla/browser/components/nsBrowserContentHandler.js new file mode 100644 index 00000000000..5ca684acf58 --- /dev/null +++ b/mozilla/browser/components/nsBrowserContentHandler.js @@ -0,0 +1,486 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla Firefox browser. + * + * The Initial Developer of the Original Code is + * Benjamin Smedberg + * + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +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; +const nsIFactory = Components.interfaces.nsIFactory; +const nsIHttpProtocolHandler = Components.interfaces.nsIHttpProtocolHandler; +const nsIInterfaceRequestor = Components.interfaces.nsIInterfaceRequestor; +const nsIPrefBranch = Components.interfaces.nsIPrefBranch; +const nsIPrefLocalizedString = Components.interfaces.nsIPrefLocalizedString; +const nsISupportsString = Components.interfaces.nsISupportsString; +const nsIWebNavigation = Components.interfaces.nsIWebNavigation; +const nsIWindowMediator = Components.interfaces.nsIWindowMediator; +const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher; + +const NS_BINDING_ABORTED = 0x80020006; + +function needHomepageOverride(prefb) { + var savedsstone; + try { + savedmstone = prefb.getCharPref("browser.startup.homepage_override.mstone"); + } + catch (e) { + } + + if (savedmstone == "ignore") + return false; + + var mstone = Components.classes["@mozilla.org/network/protocol;1?name=http"] + .getService(nsIHttpProtocolHandler).misc; + + if (mstone == savedmstone) + return false; + + prefb.setCharPref("browser.startup.homepage_override.mstone", mstone); + return true; +} + +function openWindow(parent, url, target, features, args) +{ + var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] + .getService(nsIWindowWatcher); + + var argstring; + if (args) { + argstring = Components.classes["@mozilla.org/supports-string;1"] + .createInstance(nsISupportsString); + argstring.data = args; + } + wwatch.openWindow(parent, url, target, features, argstring); +} + +function getMostRecentWindow(aType) { + var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] + .getService(nsIWindowMediator); + return wm.getMostRecentWindow(aType); +} + +var nsBrowserContentHandler = { + /* helper functions */ + + get defaultArgs() { + var prefb = Components.classes["@mozilla.org/preferences-service;1"] + .getService(nsIPrefBranch); + + if (needHomepageOverride(prefb)) { + try { + return prefb.getComplexValue("startup.homepage_override_url", + nsIPrefLocalizedString).data; + } + catch (e) { + } + } + + try { + var choice = prefb.getIntPref("browser.startup.page"); + if (choice == 1) + return this.startPage; + + if (choice == 2) + return Components.classes["@mozilla.org/browser/global-history;2"] + .getService(nsIBrowserHistory).lastPageVisited; + } + catch (e) { + } + + return "about:blank"; + }, + + 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"); + return this.mChromeURL; + }, + + /* nsISupports */ + QueryInterface : function bch_QI(iid) { + if (!iid.equals(nsISupports) && + !iid.equals(nsICommandLineHandler) && + !iid.equals(nsIBrowserHandler) && + !iid.equals(nsIContentHandler) && + !iid.equals(nsIFactory)) + throw Components.errors.NS_ERROR_NO_INTERFACE; + + return this; + }, + + /* nsICommandLineHandler */ + handle : function bch_handle(cmdLine) { + if (cmdLine.handleFlag("browser", false)) { + openWindow(null, this.chromeURL, "_blank", + "chrome,dialog=no,all" + this.getFeatures(cmdLine), + this.defaultArgs); + cmdLine.preventDefault = true; + } + + try { + var uriparam; + while (uriparam = cmdLine.handleFlagWithParam("new-window", false)) { + var uri = cmdLine.resolveURI(uriparam); + openWindow(null, this.chromeURL, "_blank", + "chrome,dialog=no,all" + this.getFeatures(cmdLine), + uri.spec); + cmdLine.preventDefault = true; + } + } + catch (e) { + dump(e); + // XXXbsmedberg: use console service + } + + var chromeParam = cmdLine.handleFlagWithParam("chrome", false); + if (chromeParam) { + openWindow(null, chromeParam, "_blank", + "chrome,dialog=no,all" + this.getFeatures(cmdLine), null); + cmdLine.preventDefault = true; + } + }, + + helpInfo : " -browser Open a browser window.\n", + + /* nsIBrowserHandler */ + + get startPage() { + var prefb = Components.classes["@mozilla.org/preferences-service;1"] + .getService(nsIPrefBranch); + + var uri = prefb.getComplexValue("browser.startup.homepage", + nsIPrefLocalizedString).data; + var count; + try { + count = prefb.getIntPref("browser.startup.homepage.count"); + } + catch (e) { + return uri; + } + + for (var i = 1; i < count; ++i) { + try { + var page = prefb.getComplexValue("browser.startup.homepage." + i, + nsIPrefLocalizedString).data; + uri += "\n" + page; + } + catch (e) { + } + } + + 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) { + dump(e); // XXXbsmedberg: use console service! + } + } + + return this.mFeatures; + }, + + /* nsIContentHandler */ + + handleContent : function bch_handleContent(contentType, context, request) { + var parentWin; + try { + parentWin = context.getInterface(nsIDOMWindow); + } + catch (e) { + } + + request.QueryInterface(nsIChannel); + + openWindow(parentWin, request.URI, "_blank", null, null); + request.cancel(NS_BINDING_ABORTED); + }, + + /* nsIFactory */ + createInstance: function bch_CI(outer, iid) { + if (outer != null) + throw Components.results.NS_ERROR_NO_AGGREGATION; + + return this.QueryInterface(iid); + }, + + lockFactory : function bch_lock(lock) { + /* no-op */ + } +}; + +const bch_contractID = "@mozilla.org/browser/clh;1"; +const bch_CID = Components.ID("{5d0ce354-df01-421a-83fb-7ead0990c24e}"); +const CONTRACTID_PREFIX = "@mozilla.org/uriloader/content-handler;1?type="; + +var nsDefaultCommandLineHandler = { + /* nsISupports */ + QueryInterface : function dch_QI(iid) { + if (!iid.equals(nsISupports) && + !iid.equals(nsICommandLineHandler) && + !iid.equals(nsIFactory)) + throw Components.errors.NS_ERROR_NO_INTERFACE; + + return this; + }, + + /* nsICommandLineHandler */ + handle : function dch_handle(cmdLine) { + var urilist = []; + + try { + var ar; + while (ar = cmdLine.handleFlagWithParam("url", false)) { + urilist.push(cmdLine.resolveURI(ar)); + } + } + catch (e) { + dump(e); // XXXbsmedberg: use console service + } + + var count = cmdLine.length; + + for (var i = 0; i < count; ++i) { + var curarg = cmdLine.getArgument(i); + if (curarg.match(/^-/)) { + dump("Warning: unrecognized command line flag " + curarg + "\n"); + // XXXbsmedberg: use console service + // To emulate the pre-nsICommandLine behavior, we ignore + // the argument after an unrecognized flag. + ++i; + // xxxbsmedberg: make me use the error service! + } else { + try { + urilist.push(cmdLine.resolveURI(curarg)); + } + catch (e) { + dump ("Error opening URI '" + curarg + "' from the command line: " + e + "\n"); + } + } + } + + if (urilist.length) { + existingWindow: + 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 { + var navWin = getMostRecentWindow("navigator:browser"); + if (!navWin) + break existingWindow; + 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(urilist[0], null, nsIBrowserDOMWindow.OPEN_DEFAULTWINDOW, + nsIBrowserDOMWindow.OPEN_EXTERNAL); + return; + } + catch (e) { + dump("Failed to hand off external URL to extant window: " + e + "\n"); + } + } + + var speclist = []; + for (var uri in urilist) { + speclist.push(urilist[uri].spec); + } + + openWindow(null, nsBrowserContentHandler.chromeURL, "_blank", + "chrome,dialog=no,all" + nsBrowserContentHandler.getFeatures(cmdLine), + speclist.join("|")); + + } + else if (!cmdLine.preventDefault) { + openWindow(null, nsBrowserContentHandler.chromeURL, "_blank", + "chrome,dialog=no,all" + nsBrowserContentHandler.getFeatures(cmdLine), + nsBrowserContentHandler.defaultArgs); + } + }, + + // XXX localize me... how? + helpInfo : "Usage: firefox [-flags] []\n", + + /* nsIFactory */ + createInstance: function dch_CI(outer, iid) { + if (outer != null) + throw Components.results.NS_ERROR_NO_AGGREGATION; + + return this.QueryInterface(iid); + }, + + lockFactory : function dch_lock(lock) { + /* no-op */ + } +}; + +const dch_contractID = "@mozilla.org/browser/final-clh;1"; +const dch_CID = Components.ID("{47cd0651-b1be-4a0f-b5c4-10e5a573ef71}"); + +var Module = { + /* nsISupports */ + QueryInterface: function mod_QI(iid) { + if (iid.equals(Components.interfaces.nsIModule) && + iid.equals(Components.interfaces.nsISupports)) + return this; + + throw Components.results.NS_ERROR_NO_INTERFACE; + }, + + /* nsIModule */ + getClassObject: function mod_getco(compMgr, cid, iid) { + if (cid.equals(bch_CID)) + return nsBrowserContentHandler.QueryInterface(iid); + + if (cid.equals(dch_CID)) + return nsDefaultCommandLineHandler.QueryInterface(iid); + + throw Components.results.NS_ERROR_NO_INTERFACE; + }, + + registerSelf: function mod_regself(compMgr, fileSpec, location, type) { + var compReg = + compMgr.QueryInterface( Components.interfaces.nsIComponentRegistrar ); + + compReg.registerFactoryLocation( bch_CID, + "nsBrowserContentHandler", + bch_contractID, + fileSpec, + location, + type ); + compReg.registerFactoryLocation( dch_CID, + "nsDefaultCommandLineHandler", + dch_contractID, + fileSpec, + location, + type ); + + function registerType(contentType) { + compReg.registerFactoryLocation( bch_CID, + "Browser Cmdline Handler", + CONTRACTID_PREFIX + contentType, + fileSpec, + location, + type ); + } + + registerType("text/html"); + registerType("application/vnd.mozilla.xul+xml"); +#ifdef MOZ_SVG + registerType("image/svg+xml"); +#endif + registerType("text/rdf"); + registerType("text/xml"); + registerType("application/xhtml+xml"); + registerType("text/css"); + registerType("text/plain"); + registerType("image/gif"); + registerType("image/jpeg"); + registerType("image/jpg"); + registerType("image/png"); + registerType("image/bmp"); + registerType("image/x-icon"); + registerType("image/vnd.microsoft.icon"); + registerType("image/x-xbitmap"); + registerType("application/http-index-format"); + + var catMan = Components.classes["@mozilla.org/categorymanager;1"] + .getService(Components.interfaces.nsICategoryManager); + + catMan.addCategoryEntry("command-line-handler", + "m-browser", + bch_contractID, true, true); + catMan.addCategoryEntry("command-line-handler", + "x-default", + dch_contractID, true, true); + }, + + unregisterSelf : function mod_unregself(compMgr, location, type) { + var compReg = compMgr.QueryInterface(nsIComponentRegistrar); + compReg.unregisterFactoryLocation(bch_CID, location); + compReg.unregisterFactoryLocation(dch_CID, location); + + var catMan = Components.classes["@mozilla.org/categorymanager;1"] + .getService(Components.interfaces.nsICategoryManager); + + catMan.deleteCategoryEntry("command-line-handler", + "m-browser", true); + catMan.deleteCategoryEntry("command-line-handler", + "x-default", true); + }, + + canUnload: function(compMgr) { + return true; + } +}; + +// NSGetModule: Return the nsIModule object. +function NSGetModule(compMgr, fileSpec) { + return Module; +} diff --git a/mozilla/browser/components/nsIBrowserHandler.idl b/mozilla/browser/components/nsIBrowserHandler.idl new file mode 100644 index 00000000000..464bae75247 --- /dev/null +++ b/mozilla/browser/components/nsIBrowserHandler.idl @@ -0,0 +1,52 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla Firefox browser. + * + * The Initial Developer of the Original Code is + * Benjamin Smedberg + * + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" + +interface nsICommandLine; + +[scriptable, uuid(8D3F5A9D-118D-4548-A137-CF7718679069)] +interface nsIBrowserHandler : nsISupports +{ + attribute AUTF8String startPage; + + /** + * Extract the width and height specified on the command line, if present. + * @return A feature string with a prepended comma, e.g. ",width=500,height=400" + */ + AUTF8String getFeatures(in nsICommandLine aCmdLine); +}; diff --git a/mozilla/browser/components/shell/src/Makefile.in b/mozilla/browser/components/shell/src/Makefile.in index 04382ada001..922306d9350 100644 --- a/mozilla/browser/components/shell/src/Makefile.in +++ b/mozilla/browser/components/shell/src/Makefile.in @@ -69,6 +69,8 @@ FORCE_STATIC_LIB = 1 include $(topsrcdir)/config/rules.mk +DEFINES += -DMOZ_APP_NAME=\"$(MOZ_APP_NAME)\" + JS_SET_BROWSER_COMPONENT = nsSetDefaultBrowser.js CXXFLAGS += $(TK_CFLAGS) diff --git a/mozilla/browser/components/shell/src/nsGNOMEShellService.cpp b/mozilla/browser/components/shell/src/nsGNOMEShellService.cpp index 454a127c186..7d57dfdabeb 100644 --- a/mozilla/browser/components/shell/src/nsGNOMEShellService.cpp +++ b/mozilla/browser/components/shell/src/nsGNOMEShellService.cpp @@ -38,8 +38,10 @@ #include "nsGNOMEShellService.h" #include "nsShellService.h" #include "nsIServiceManager.h" +#include "nsILocalFile.h" +#include "nsIProperties.h" +#include "nsDirectoryServiceDefs.h" #include "nsIPrefService.h" -#include "nsICmdLineService.h" #include "prenv.h" #include "nsString.h" #include "nsIGConfService.h" @@ -98,6 +100,8 @@ static const char kDesktopColorKey[] = DG_BACKGROUND "/primary_color"; nsresult nsGNOMEShellService::Init() { + nsresult rv; + // GConf and GnomeVFS _must_ be available, or we do not allow // CreateInstance to succeed. @@ -112,39 +116,19 @@ nsGNOMEShellService::Init() // the locale encoding. If it's not set, they use UTF-8. mUseLocaleFilenames = PR_GetEnv("G_BROKEN_FILENAMES") != nsnull; - // Get the path we were launched from. - nsCOMPtr cmdService = - do_GetService("@mozilla.org/appshell/commandLineService;1"); - if (!cmdService) - return NS_ERROR_NOT_AVAILABLE; + nsCOMPtr dirSvc + (do_GetService("@mozilla.org/file/directory_service;1")); + NS_ENSURE_TRUE(dirSvc, NS_ERROR_NOT_AVAILABLE); - nsXPIDLCString programName; - cmdService->GetProgramName(getter_Copies(programName)); + nsCOMPtr appPath; + rv = dirSvc->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsILocalFile), + getter_AddRefs(appPath)); + NS_ENSURE_SUCCESS(rv, rv); - // Make sure we have an absolute pathname. - if (programName[0] != '/') { - // First search PATH if we were just launched as 'firefox-bin'. - // If we were launched as './firefox-bin', this will just return - // the original string. + rv = appPath->AppendNative(NS_LITERAL_CSTRING(MOZ_APP_NAME)); + NS_ENSURE_SUCCESS(rv, rv); - gchar *appPath = g_find_program_in_path(programName.get()); - - // Now resolve it. - char resolvedPath[PATH_MAX] = ""; - if (realpath(appPath, resolvedPath)) { - mAppPath.Assign(resolvedPath); - } - - g_free(appPath); - } else { - mAppPath.Assign(programName); - } - - // strip "-bin" off of the binary name - if (StringEndsWith(mAppPath, NS_LITERAL_CSTRING("-bin"))) - mAppPath.SetLength(mAppPath.Length() - 4); - - return NS_OK; + return appPath->GetNativePath(mAppPath); } NS_IMPL_ISUPPORTS1(nsGNOMEShellService, nsIShellService) diff --git a/mozilla/browser/components/shell/src/nsSetDefaultBrowser.js b/mozilla/browser/components/shell/src/nsSetDefaultBrowser.js index 0f3d36c6b31..b745b943eac 100644 --- a/mozilla/browser/components/shell/src/nsSetDefaultBrowser.js +++ b/mozilla/browser/components/shell/src/nsSetDefaultBrowser.js @@ -35,140 +35,107 @@ * * ***** END LICENSE BLOCK ***** */ -/* This file implements the nsICmdLineHandler interface. See nsICmdLineHandler.idl - * at http://lxr.mozilla.org/seamonkey/source/xpfe/appshell/public/nsICmdLineHandler.idl. +/* This file implements the nsICommandLineHandler interface. * * This component handles the startup command line argument of the form: * -setDefaultBrowser - * by making the current executable the "default browser." It accomplishes - * that via use of the nsIWindowsHooks interface (see implementation below). - * - * The module is registered under the contractid - * "@mozilla.org/commandlinehandler/general-startup;1?type=setDefaultBrowser" - * - * The implementation consists of a JavaScript "class" named nsKillAll, - * comprised of: - * - a JS constructor function - * - a prototype providing all the interface methods and implementation stuff - * - * In addition, this file implements an nsIModule object that registers the - * nsSetDefaultBrowser component. + * by making the current executable the "default browser." */ -/* ctor - */ function nsSetDefaultBrowser() { } nsSetDefaultBrowser.prototype = { + /* nsISupports */ + QueryInterface: function nsSetDefault_QI(iid) { + if (!iid.equals(Components.interfaces.nsICommandLineHandler) && + !iid.equals(Components.interfaces.nsISupports)) + throw Components.results.NS_ERROR_NO_INTERFACE; - // nsICmdLineHandler interface - get commandLineArgument() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; }, - get prefNameForStartup() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; }, + return this; + }, - get chromeUrlForTask() { - // First, get shell service - var shell; - try { - shell = Components.classes["@mozilla.org/browser/shell-service;1"] + /* nsICommandLineHandler */ + handle : function nsSetDefault_handle(cmdline) { + if (cmdline.handleFlag("setDefaultBrowser", false)) { + var shell = Components.classes["@mozilla.org/browser/shell-service;1"] .getService(Components.interfaces.nsIShellService); - } catch(e) { } - if (!shell) - throw Components.results.NS_ERROR_NOT_AVAILABLE; - shell.setDefaultBrowser(true, true); - - // Now, get the cmd line service. - var cmdLineService = Components.classes[ "@mozilla.org/appshell/commandLineService;1" ] - .getService( Components.interfaces.nsICmdLineService ); - - // See if "-setDefaultBrowser" was specified. The value will be "1" if - // -setDefaultBrowser is in the service's list of cmd line arguments, and - // null otherwise. -setDefaultBrowser will only be in the service's - // arg list if the application was not already running. That's because - // if it was already running, then the service reflects the arguments - // that were specified when *that* process was started, *not* the ones - // passed via IPC from the second instance. - var option = cmdLineService.getCmdLineValue( "-setDefaultBrowser" ); - if (!option) { - // Already running, so we don't have to worry about opening - // another window, etc. - throw Components.results.NS_ERROR_NOT_AVAILABLE; - } - - // Return URL for dummy window that will auto-close. We do this rather - // than throw NS_ERROR_NOT_AVAILABLE, which *should* work, because it - // seems that if we don't open a window, we get a crash when trying to - // release this (or some other) JS component during XPCOM shutdown. - return "chrome://global/content/dummyWindow.xul"; - }, - - get helpText() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; }, - get handlesArgs() { return false; }, - get defaultArgs() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; }, - get openWindowWithArgs() { throw Components.results.NS_ERROR_NOT_IMPLEMENTED; }, - - // nsISupports interface - - // This "class" supports nsICmdLineHandler and nsISupports. - QueryInterface: function (iid) { - if (!iid.equals(Components.interfaces.nsICmdLineHandler) && - !iid.equals(Components.interfaces.nsISupports)) { - throw Components.results.NS_ERROR_NO_INTERFACE; - } - return this; - }, - - // This Component's module implementation. All the code below is used to get this - // component registered and accessible via XPCOM. - module: { - // registerSelf: Register this component. - registerSelf: function (compMgr, fileSpec, location, type) { - var compReg = compMgr.QueryInterface( Components.interfaces.nsIComponentRegistrar ); - compReg.registerFactoryLocation( this.cid, - "Default Browser Component", - this.contractId, - fileSpec, - location, - type ); - }, - - // getClassObject: Return this component's factory object. - getClassObject: function (compMgr, cid, iid) { - if (!cid.equals(this.cid)) - throw Components.results.NS_ERROR_NO_INTERFACE; - - if (!iid.equals(Components.interfaces.nsIFactory)) - throw Components.results.NS_ERROR_NOT_IMPLEMENTED; - - return this.factory; - }, - - /* CID for this class */ - cid: Components.ID("{C66E05DC-509C-4972-A1F2-EE5AC34B9800}"), - - /* Contract ID for this class */ - contractId: "@mozilla.org/commandlinehandler/general-startup;1?type=setDefaultBrowser", - - /* factory object */ - factory: { - // createInstance: Return a new nsSetDefaultBrowser object. - createInstance: function (outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; - - return (new nsSetDefaultBrowser()).QueryInterface(iid); - } - }, - - // canUnload: n/a (returns true) - canUnload: function(compMgr) { - return true; - } } + }, + + helpText : " -setDefaultBrowser Set this app as the default browser.\n", +}; + +// This Component's module and factory implementation. + +const contractID = "@mozilla.org/browser/default-browser-clh;1"; +const CID = Components.ID("{F57899D0-4E2C-4ac6-9E29-50C736103B0C}"); + +var ModuleAndFactory = { + /* nsISupports */ + QueryInterface: function nsSetDefault_QI(iid) { + if (!iid.equals(Components.interfaces.nsIModule) && + !iid.equals(Components.interfaces.nsIFactory) && + !iid.equals(Components.interfaces.nsISupports)) + throw Components.results.NS_ERROR_NO_INTERFACE; + + return this; + }, + + /* nsIModule */ + getClassObject: function (compMgr, cid, iid) { + if (!cid.equals(CID)) + throw Components.results.NS_ERROR_NO_INTERFACE; + + return this.QueryInterface(iid); + }, + + registerSelf: function mod_regself(compMgr, fileSpec, location, type) { + var compReg = + compMgr.QueryInterface( Components.interfaces.nsIComponentRegistrar ); + + compReg.registerFactoryLocation( CID, + "Default Browser Cmdline Handler", + contractID, + fileSpec, + location, + type ); + + var catMan = Components.classes["@mozilla.org/categorymanager;1"] + .getService(Components.interfaces.nsICategoryManager); + + catMan.addCategoryEntry("command-line-handler", + "m-setdefaultbrowser", + contractID, true, true); + }, + + unregisterSelf : function mod_unregself(compMgr, location, type) { + var catMan = Components.classes["@mozilla.org/categorymanager;1"] + .getService(Components.interfaces.nsICategoryManager); + + catMan.deleteCategoryEntry("command-line-handler", + "m-setdefaultbrowser", true); + }, + + canUnload: function(compMgr) { + return true; + }, + + /* nsIFactory */ + createInstance: function mod_CI(outer, iid) { + if (outer != null) + throw Components.results.NS_ERROR_NO_AGGREGATION; + + return new nsSetDefaultBrowser().QueryInterface(iid); + }, + + lockFactory : function mod_lock(lock) { + /* no-op */ + } } // NSGetModule: Return the nsIModule object. function NSGetModule(compMgr, fileSpec) { - return nsSetDefaultBrowser.prototype.module; + return ModuleAndFactory; } diff --git a/mozilla/browser/installer/unix/packages-static b/mozilla/browser/installer/unix/packages-static index b8586a07a22..552d603d327 100644 --- a/mozilla/browser/installer/unix/packages-static +++ b/mozilla/browser/installer/unix/packages-static @@ -58,9 +58,11 @@ bin/components/appstartup.xpt bin/components/autocomplete.xpt bin/components/autoconfig.xpt bin/components/bookmarks.xpt +bin/components/browsercompsbase.xpt bin/components/caps.xpt bin/components/chardet.xpt bin/components/commandhandler.xpt +bin/components/commandlines.xpt bin/components/composer.xpt bin/components/content_base.xpt bin/components/content_htmldoc.xpt @@ -169,6 +171,7 @@ bin/components/xuldoc.xpt bin/components/xultmpl.xpt bin/components/shellservice.xpt ; JavaScript components +bin/components/nsBrowserContentHandler.js bin/components/nsSetDefaultBrowser.js bin/components/jsconsole-clhandler.js bin/components/nsCloseAllWindows.js diff --git a/mozilla/browser/installer/windows/packages-static b/mozilla/browser/installer/windows/packages-static index 33406923521..4704f6a4a8d 100644 --- a/mozilla/browser/installer/windows/packages-static +++ b/mozilla/browser/installer/windows/packages-static @@ -59,10 +59,12 @@ bin\components\appstartup.xpt bin\components\autocomplete.xpt bin\components\autoconfig.xpt bin\components\bookmarks.xpt +bin\components\browsercompsbase.xpt bin\components\caps.xpt bin\components\chardet.xpt bin\components\chrome.xpt bin\components\commandhandler.xpt +bin\components\commandlines.xpt bin\components\composer.xpt bin\components\content_base.xpt bin\components\content_html.xpt @@ -179,6 +181,7 @@ bin\components\xulapp.xpt bin\components\xuldoc.xpt bin\components\xultmpl.xpt ; JavaScript components +bin\components\nsBrowserContentHandler.js bin\components\nsSetDefaultBrowser.js bin\components\nsCloseAllWindows.js bin\components\nsDictionary.js diff --git a/mozilla/calendar/resources/content/calendarService.js b/mozilla/calendar/resources/content/calendarService.js index 0679bc3d829..f66c950248e 100644 --- a/mozilla/calendar/resources/content/calendarService.js +++ b/mozilla/calendar/resources/content/calendarService.js @@ -54,12 +54,17 @@ const STANDARDURL_CONTRACTID = "@mozilla.org/network/standard-url;1"; const ASS_CONTRACTID = "@mozilla.org/appshell/appShellService;1"; +const WINDOWWATCHER_CONTRACTID = + "@mozilla.org/embedcomp/window-watcher;1"; /* interafces used in this file */ const nsIWindowMediator = Components.interfaces.nsIWindowMediator; +const nsICommandLineHandler = + Components.interfaces.nsICommandLineHandler; const nsICmdLineHandler = Components.interfaces.nsICmdLineHandler; const nsICategoryManager = Components.interfaces.nsICategoryManager; const nsIContentHandler = Components.interfaces.nsIContentHandler; +const nsIFactory = Components.interfaces.nsIFactory; const nsIProtocolHandler = Components.interfaces.nsIProtocolHandler; const nsIURI = Components.interfaces.nsIURI; const nsIStandardURL = Components.interfaces.nsIStandardURL; @@ -67,31 +72,74 @@ const nsIChannel = Components.interfaces.nsIChannel; const nsIRequest = Components.interfaces.nsIRequest; const nsIAppShellService = Components.interfaces.nsIAppShellService; const nsISupports = Components.interfaces.nsISupports; +const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher; /* Command Line handler service */ function CLineService() {} -CLineService.prototype.commandLineArgument = "-calendar"; -CLineService.prototype.prefNameForStartup = "general.startup.calendar"; -CLineService.prototype.chromeUrlForTask = "chrome://calendar/content"; -CLineService.prototype.helpText = "Start with calendar"; -CLineService.prototype.handlesArgs = false; -CLineService.prototype.defaultArgs = ""; -CLineService.prototype.openWindowWithArgs = true; +CLineService.prototype = { + /* nsISupports */ + QueryInterface : function service_qi(iid) { + if (iid.equals(nsISupports)) + return this; + + if (nsICmdLineHandler && iid.equals(nsICmdLineHandler)) + return this; + + if (nsICommandLineHandler && iid.equals(nsICommandLineHandler)) + return this; + + throw Components.results.NS_ERROR_NO_INTERFACE; + }, + + /* nsICmdLineHandler */ + + commandLineArgument : "-calendar", + prefNameForStartup : "general.startup.calendar", + chromeUrlForTask : "chrome://calendar/content", + helpText : "Start with calendar", + handlesArgs : false, + defaultArgs : "", + openWindowWithArgs : true, + + /* nsICommandLineHandler */ + + handle : function service_handle(cmdLine) { + if (cmdLine.handleFlag("calendar", false)) { + wwatch = Components.classes[WINDOWWATCHER_CONTRACTID] + .getService(nsIWindowWatcher); + wwatch.openWindow(null, "chrome://calendar/content/", + "_blank", "chrome,dialog=no,all", cmdLine); + cmdLine.preventDefault = true; + } + }, + + helpInfo : " -calendar Start with the calendar.\n" +}; /* factory for command line handler service (CLineService) */ -var CLineFactory = new Object(); +var CLineFactory = { + /* nsISupports */ + QueryInterface : function (iid) { + if (iid.equals(nsISupports) || + iid.equals(nsIFactory)) + return this; -CLineFactory.createInstance = -function (outer, iid) { - if (outer != null) - throw Components.results.NS_ERROR_NO_AGGREGATION; + throw Components.results.NS_ERROR_NO_INTERFACE; + }, - if (!iid.equals(nsICmdLineHandler) && !iid.equals(nsISupports)) - throw Components.results.NS_ERROR_INVALID_ARG; + /* nsIFactory */ - return new CLineService(); + createInstance : function (outer, iid) { + if (outer != null) + throw Components.results.NS_ERROR_NO_AGGREGATION; + + return new CLineService.QueryInterface(iid); + }, + + lockFactory : function(lock) { + } } /* text/calendar content handler */ @@ -308,6 +356,8 @@ function (compMgr, fileSpec, location, type) catman.addCategoryEntry("command-line-argument-handlers", "calendar command line handler", CLINE_SERVICE_CONTRACTID, true, true); + catman.addCategoryEntry("command-line-handler", "m-calendar", + CLINE_SERVICE_CONTRACTID, true, true); // dump("*** Registering text/calendar handler.\n"); compMgr.registerFactoryLocation(ICALCNT_HANDLER_CID, @@ -331,18 +381,22 @@ function(compMgr, fileSpec, location) { compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); - compMgr.unregisterFactoryLocation(CLINE_SERVICE_CID, - fileSpec); + compMgr.unregisterFactoryLocation(CLINE_SERVICE_CID, fileSpec); + compMgr.unregisterFactoryLocation(ICALCNT_HANDLER_CID, fileSpec); + compMgr.unregisterFactoryLocation(ICALPROT_HANDLER_CID, fileSpec); + catman = Components.classes["@mozilla.org/categorymanager;1"] .getService(nsICategoryManager); catman.deleteCategoryEntry("command-line-argument-handlers", - CLINE_SERVICE_CONTRACTID, true); + "calendar command line handler", true); + catman.deleteCategoryEntry("command-line-handler", + "m-calendar", true); } CalendarModule.getClassObject = function (compMgr, cid, iid) { if (cid.equals(CLINE_SERVICE_CID)) - return CLineFactory; + return CLineFactory.QueryInterface(iid); if (cid.equals(ICALCNT_HANDLER_CID)) return ICALContentHandlerFactory; @@ -350,11 +404,7 @@ function (compMgr, cid, iid) { if (cid.equals(ICALPROT_HANDLER_CID)) return ICALProtocolHandlerFactory; - if (!iid.equals(Components.interfaces.nsIFactory)) - throw Components.results.NS_ERROR_NOT_IMPLEMENTED; - throw Components.results.NS_ERROR_NO_INTERFACE; - } CalendarModule.canUnload = diff --git a/mozilla/calendar/sunbird/app/nsCalendarApp.cpp b/mozilla/calendar/sunbird/app/nsCalendarApp.cpp index a1d7ce409fc..958a675b82c 100644 --- a/mozilla/calendar/sunbird/app/nsCalendarApp.cpp +++ b/mozilla/calendar/sunbird/app/nsCalendarApp.cpp @@ -21,6 +21,7 @@ * * Contributor(s): * Brian Ryner + * Benjamin Smedberg * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -44,7 +45,6 @@ #include "nsBuildID.h" #include -const int TMP_ARG_MAX=21; static const nsXREAppData kAppData = { "Mozilla", "Sunbird", @@ -58,31 +58,7 @@ static const nsXREAppData kAppData = { int main(int argc, char* argv[]) { - char* temparg[TMP_ARG_MAX+1]; - char **argPtr; - int argCount; - int i; - bool found = false; - for (i=0; i < argc; i++) { - if (!strncmp("-calendar", argv[i], 9)) - found = true; - } - if (!found) { - temparg[0] = argv[0]; - temparg[1] = "-calendar"; - for( i=1; i cmdLineArgs - (do_GetService("@mozilla.org/appshell/commandLineService;1")); - - if (cmdLineArgs) - cmdLineArgs->GetCmdLineValue(UILOCALE_CMD_LINE_ARG, getter_Copies(uiLocale)); - - if (uiLocale) { - useLocalePref = PR_FALSE; - mSelectedLocale = uiLocale; - } - else if (prefs) { + if (prefs) { // check the pref first PRBool matchOS = PR_FALSE; rv = prefs->GetBoolPref(MATCH_OS_LOCALE_PREF, &matchOS); @@ -309,6 +298,7 @@ nsChromeRegistry::Init() // match os locale if (NS_SUCCEEDED(rv) && matchOS) { // compute lang and region code only when needed! + nsCAutoString uiLocale; rv = getUILangCountry(uiLocale); if (NS_SUCCEEDED(rv)) { useLocalePref = PR_FALSE; @@ -2945,6 +2935,21 @@ NS_IMETHODIMP nsChromeRegistry::Observe(nsISupports *aSubject, const char *aTopi rv = LoadProfileDataSource(); } } + else if (!strcmp("command-line-startup", aTopic)) { + nsCOMPtr cmdLine (do_QueryInterface(aSubject)); + if (cmdLine) { + nsAutoString uiLocale; + rv = cmdLine->HandleFlagWithParam(NS_LITERAL_STRING(UILOCALE_CMD_LINE_ARG), + PR_FALSE, uiLocale); + if (NS_SUCCEEDED(rv) && !uiLocale.IsEmpty()) { + CopyUTF16toUTF8(uiLocale, mSelectedLocale); + nsCOMPtr prefs (do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefs) { + prefs->RemoveObserver(SELECTED_LOCALE_PREF, this); + } + } + } + } else if (!strcmp(NS_PREFBRANCH_PREFCHANGE_TOPIC_ID, aTopic)) { nsCOMPtr prefs (do_QueryInterface(aSubject)); NS_ASSERTION(prefs, "Bad observer call!"); diff --git a/mozilla/extensions/inspector/base/js/inspector-cmdline.js b/mozilla/extensions/inspector/base/js/inspector-cmdline.js index 499fa571062..6b4a9c9bde7 100644 --- a/mozilla/extensions/inspector/base/js/inspector-cmdline.js +++ b/mozilla/extensions/inspector/base/js/inspector-cmdline.js @@ -35,26 +35,72 @@ * * ***** END LICENSE BLOCK ***** */ +// NOTE: this file implements both the seamonkey nsICmdLineHandler and +// the toolkit nsICommandLineHandler, using runtime detection. const INSPECTOR_CMDLINE_CONTRACTID = "@mozilla.org/commandlinehandler/general-startup;1?type=inspector"; const INSPECTOR_CMDLINE_CLSID = Components.ID('{38293526-6b13-4d4f-a075-71939435b408}'); const CATMAN_CONTRACTID = "@mozilla.org/categorymanager;1"; const nsISupports = Components.interfaces.nsISupports; + const nsICategoryManager = Components.interfaces.nsICategoryManager; const nsICmdLineHandler = Components.interfaces.nsICmdLineHandler; +const nsICommandLine = Components.interfaces.nsICommandLine; +const nsICommandLineHandler = Components.interfaces.nsICommandLineHandler; const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar; - +const nsISupportsString = Components.interfaces.nsISupportsString; +const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher; function InspectorCmdLineHandler() {} InspectorCmdLineHandler.prototype = { + /* nsISupports */ + QueryInterface : function handler_QI(iid) { + if (iid.equals(nsISupports)) + return this; + + if (nsICmdLineHandler && iid.equals(nsICmdLineHandler)) + return this; + + if (nsICommandLineHandler && iid.equals(nsICommandLineHandler)) + return this; + + throw Components.results.NS_ERROR_NO_INTERFACE; + }, + + /* nsICmdLineHandler */ commandLineArgument : "-inspector", prefNameForStartup : "general.startup.inspector", chromeUrlForTask : "chrome://inspector/content/inspector.xul", helpText : "Start with the DOM Inspector.", handlesArgs : true, defaultArgs : "", - openWindowWithArgs : true + openWindowWithArgs : true, + + /* nsICommandLineHandler */ + handle : function handler_handle(cmdLine) { + var args; + try { + var uristr = cmdLine.handleFlagWithParam("inspect", false); + if (uristr) { + var uri = cmdLine.resolveURI(uristr); + args = Components.classes["@mozilla.org/supports-string;1"] + .createInstance(nsISupportsString); + args.data = uri.spec; + } + } + catch (e) { + } + + if (args || cmdLine.handleFlag("inspector", false)) { + var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] + .getService(nsIWindowWatcher); + wwatch.openWindow(null, "chrome://inspector/content/", "_blank", + "chrome,dialog=no,all", args); + } + }, + + helpInfo : " -inspect Open the URL in the DOM inspector.\n -inspector Open the DOM inspector.\n" }; @@ -66,11 +112,7 @@ var InspectorCmdLineFactory = throw Components.results.NS_ERROR_NO_AGGREGATION; } - if (!iid.equals(nsICmdLineHandler) && !iid.equals(nsISupports)) { - throw Components.results.NS_ERROR_INVALID_ARG; - } - - return new InspectorCmdLineHandler(); + return new InspectorCmdLineHandler().QueryInterface(iid); } }; @@ -92,6 +134,9 @@ var InspectorCmdLineModule = catman.addCategoryEntry("command-line-argument-handlers", "inspector command line handler", INSPECTOR_CMDLINE_CONTRACTID, true, true); + catman.addCategoryEntry("command-line-handler", + "m-inspector", + INSPECTOR_CMDLINE_CONTRACTID, true, true); }, unregisterSelf : function(compMgr, fileSpec, location) @@ -101,7 +146,9 @@ var InspectorCmdLineModule = compMgr.unregisterFactoryLocation(INSPECTOR_CMDLINE_CLSID, fileSpec); catman = Components.classes[CATMAN_CONTRACTID].getService(nsICategoryManager); catman.deleteCategoryEntry("command-line-argument-handlers", - INSPECTOR_CMDLINE_CONTRACTID, true); + "inspector command line handler", true); + catman.deleteCategoryEntry("command-line-handler", + "m-inspector", true); }, getClassObject : function(compMgr, cid, iid) diff --git a/mozilla/mail/components/Makefile.in b/mozilla/mail/components/Makefile.in index 0c8ec0b6449..4eea94aeb13 100644 --- a/mozilla/mail/components/Makefile.in +++ b/mozilla/mail/components/Makefile.in @@ -34,5 +34,7 @@ endif DIRS += build +EXTRA_PP_COMPONENTS = nsMailDefaultHandler.js + include $(topsrcdir)/config/rules.mk diff --git a/mozilla/mail/components/gnome/nsMailGNOMEIntegration.cpp b/mozilla/mail/components/gnome/nsMailGNOMEIntegration.cpp index 00ad498070d..2065f4300f9 100644 --- a/mozilla/mail/components/gnome/nsMailGNOMEIntegration.cpp +++ b/mozilla/mail/components/gnome/nsMailGNOMEIntegration.cpp @@ -42,11 +42,13 @@ #include "nsCOMPtr.h" #include "nsIServiceManager.h" #include "prenv.h" -#include "nsICmdLineService.h" +#include "nsIFile.h" #include "nsIStringBundle.h" #include "nsIPromptService.h" #include "nsIPrefService.h" #include "nsIPrefBranch.h" +#include "nsDirectoryServiceDefs.h" +#include "nsDirectoryServiceUtils.h" #include #include @@ -65,6 +67,8 @@ static const char* const sNewsProtocols[] = { nsresult nsMailGNOMEIntegration::Init() { + nsresult rv; + // GConf _must_ be available, or we do not allow CreateInstance to succeed. nsCOMPtr gconf = do_GetService(NS_GCONFSERVICE_CONTRACTID); @@ -76,37 +80,16 @@ nsMailGNOMEIntegration::Init() // the locale encoding. If it's not set, they use UTF-8. mUseLocaleFilenames = PR_GetEnv("G_BROKEN_FILENAMES") != nsnull; - // Get the path we were launched from. - nsCOMPtr cmdService = - do_GetService("@mozilla.org/appshell/commandLineService;1"); - if (!cmdService) - return NS_ERROR_NOT_AVAILABLE; + nsCOMPtr appPath; + rv = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, + getter_AddRefs(appPath)); + NS_ENSURE_SUCCESS(rv, rv); - nsXPIDLCString programName; - cmdService->GetProgramName(getter_Copies(programName)); + rv = appPath->AppendNative(NS_LITERAL_CSTRING("thunderbird")); + NS_ENSURE_SUCCESS(rv, rv); - // Make sure we have an absolute pathname. - if (programName[0] != '/') { - // First search PATH if we were just launched as 'thunderbird-bin'. - // If we were launched as './thunderbird-bin', this will just return - // the original string. - - gchar *appPath = g_find_program_in_path(programName.get()); - - // Now resolve it. - char resolvedPath[PATH_MAX] = ""; - if (realpath(appPath, resolvedPath)) { - mAppPath.Assign(resolvedPath); - } - - g_free(appPath); - } else { - mAppPath.Assign(programName); - } - - // strip "-bin" off of the binary name - if (StringEndsWith(mAppPath, NS_LITERAL_CSTRING("-bin"))) - mAppPath.SetLength(mAppPath.Length() - 4); + rv = appPath->GetNativePath(mAppPath); + NS_ENSURE_SUCCESS(rv, rv); PRBool isDefault; nsMailGNOMEIntegration::GetIsDefaultMailClient(&isDefault); diff --git a/mozilla/mail/components/nsMailDefaultHandler.js b/mozilla/mail/components/nsMailDefaultHandler.js new file mode 100644 index 00000000000..21eda2f4235 --- /dev/null +++ b/mozilla/mail/components/nsMailDefaultHandler.js @@ -0,0 +1,212 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla Firefox browser. + * + * The Initial Developer of the Original Code is + * Benjamin Smedberg + * + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +const nsISupports = Components.interfaces.nsISupporst; + +const nsICommandLine = Components.interfaces.nsICommandLine; +const nsICommandLineHandler = Components.interfaces.nsICommandLineHandler; +const nsIDOMWindowInternal = Components.interfaces.nsIDOMWindowInternal; +const nsIFactory = Components.interfaces.nsIFactory; +const nsISupportsString = Components.interfaces.nsISupportsString; +const nsIWindowMediator = Components.interfaces.nsIWindowMediator; +const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher; + +var nsMailDefaultHandler = { + /* nsISupports */ + + QueryInterface : function mdh_QI(iid) { + if (iid.equals(nsICommandLineHandler) || + iid.equals(nsIFactory) || + iid.equals(nsISupports)) + return this; + + throw Components.results.NS_ERROR_NO_INTERFACE; + }, + + /* nsICommandLineHandler */ + + handle : function mdh_handle(cmdLine) { + var uri; + + var count = cmdLine.length; + if (count) { + var i = 0; + while (i < count) { + var curarg = cmdLine.getArgument(i); + if (curarg.match(/^-/)) { + dump ("Warning: unrecognized command line flag " + curarg + "\n"); + // To emulate the pre-nsICommandLine behavior, we ignore the + // argument after an unrecognized flag. + ++i; + // xxxbsmedberg: make me use the console service! + } + ++i; + } + + if (i < count) { + uri = cmdLine.getArgument(i); + + // mailto: URIs are frequently passed with spaces in them. They should be + // escaped into %20, but we hack around bad clients, see bug 231032 + if (uri.match.(/^mailto:/)) { + do { + ++i; + var testarg = cmdLine.getArgument(++i); + if (testarg.match(/^-/)) + break; + + uri += " " + testarg; + } while (1); + } + } + } + + if (!uri && cmdLine.preventDefault) + return; + + // xxxbsmedberg: This should be using nsIURILoader.openURI, which is what + // the 1.0 branch does (see nsAppShellService.cpp, revision 1.212.6.6). + // However, nsIURILoader.openURI is async, which means that the event loop + // sometimes is not run when it is supposed to, and other badness. Fix + // this for 1.1! + + if (!uri && cmdLine.state != nsICommandLine.STATE_INITIAL_LAUNCH) { + try { + var wmed = Components.classes["@mozilla.org/appshell/window-mediator;1"] + .getService(nsIWindowMediator); + + var wlist = wmed.getEnumerator("mail:3pane"); + if (wlist.hasMoreElements()) { + var window = wlist.getNext().QueryInterface(nsIDOMWindowInternal); + window.focus(); + return; + } + } + catch (e) { + dump(e); + } + } + + var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] + .getService(nsIWindowWatcher); + + var argstring = Components.classes["@mozilla.org/supports-string;1"] + .createInstance(nsISupportsString); + if (uri) + argstring.data = uri; + + wwatch.openWindow(null, "chrome://messenger/content/", "_blank", + "chrome,dialog=no,all", argstring); + }, + + helpInfo : "", + + /* nsIFactory */ + + createInstance : function mdh_CI(outer, iid) { + if (outer != null) + throw Components.results.NS_ERROR_NO_AGGREGATION; + + return this.QueryInterface(iid); + }, + + lockFactory : function mdh_lock(lock) { + /* no-op */ + } +}; + +const mdh_contractID = "@mozilla.org/mail/clh;1"; +const mdh_CID = Components.ID("{44346520-c5d2-44e5-a1ec-034e04d7fac4}"); + +var Module = { + /* nsISupports */ + + QueryInterface : function QI(iid) { + if (iid.equals(Components.interfaces.nsIModule) && + iid.equals(Components.interfaces.nsISupports)) + return this; + + throw Components.results.NS_ERROR_NO_INTERFACE; + }, + + /* nsIModule */ + getClassObject : function (compMgr, cid, iid) { + if (cid.equals(mdh_CID)) + return nsMailDefaultHandler.QueryInterface(iid); + + throw Components.results.NS_ERROR_FAILURE; + }, + + registerSelf: function mod_regself(compMgr, fileSpec, location, type) { + var compReg = + compMgr.QueryInterface( Components.interfaces.nsIComponentRegistrar ); + + compReg.registerFactoryLocation(mdh_CID, + "nsMailDefaultHandler", + mdh_contractID, + fileSpec, + location, + type ); + + var catMan = Components.classes["@mozilla.org/categorymanager;1"] + .getService(Components.interfaces.nsICategoryManager); + + catMan.addCategoryEntry("command-line-handler", + "x-default", + mdh_contractID, true, true); + }, + + unregisterSelf : function mod_unregself(compMgr, location, type) { + var compReg = compMgr.QueryInterface(nsIComponentRegistrar); + compReg.unregisterFactoryLocation(mdh_CID, location); + + var catMan = Components.classes["@mozilla.org/categorymanager;1"] + .getService(Components.interfaces.nsICategoryManager); + + catMan.deleteCategoryEntry("command-line-handler", + "y-default", true); + }, + + canUnload: function(compMgr) { + return true; + } +} + +// NSGetModule: Return the nsIModule object. +function NSGetModule(compMgr, fileSpec) { + return Module; +} diff --git a/mozilla/mail/installer/windows/basemail-win b/mozilla/mail/installer/windows/basemail-win index 3a120d956e9..3b09a1ab422 100644 --- a/mozilla/mail/installer/windows/basemail-win +++ b/mozilla/mail/installer/windows/basemail-win @@ -100,6 +100,7 @@ bin\components\mapihook.xpt bin\components\nsSetDefaultMail.js bin\components\nsUnsetDefaultMail.js bin\components\offlineStartup.js +bin\components\nsMailDefaultHandler.js bin\components\mdn-service.js @@ -213,6 +214,7 @@ bin\components\toolkitprofile.xpt ; toolkit bin\components\appstartup.xpt +bin\components\commandlines.xpt ; rdf bin\components\rdf.xpt diff --git a/mozilla/mailnews/addrbook/src/Makefile.in b/mozilla/mailnews/addrbook/src/Makefile.in index 7c96d2c89a0..10cc86e9445 100644 --- a/mozilla/mailnews/addrbook/src/Makefile.in +++ b/mozilla/mailnews/addrbook/src/Makefile.in @@ -51,6 +51,7 @@ REQUIRES = xpcom \ rdf \ rdfutil \ appshell \ + toolkitcomps \ appcomps \ dom \ layout \ diff --git a/mozilla/mailnews/addrbook/src/nsAddressBook.cpp b/mozilla/mailnews/addrbook/src/nsAddressBook.cpp index 711164b8740..a03c744937b 100644 --- a/mozilla/mailnews/addrbook/src/nsAddressBook.cpp +++ b/mozilla/mailnews/addrbook/src/nsAddressBook.cpp @@ -76,6 +76,7 @@ #include "nsIAbCard.h" #include "nsIAbMDBCard.h" #include "plbase64.h" +#include "nsIWindowWatcher.h" #include "nsEscape.h" #include "nsVCard.h" @@ -89,6 +90,10 @@ #include "nsCRT.h" +#ifdef MOZ_XUL_APP +#include "nsICommandLine.h" +#endif + // according to RFC 2849 // SEP = (CR LF / LF) // so we LF for unix and beos (since that is the natural line ending for @@ -177,7 +182,11 @@ nsAddressBook::~nsAddressBook() NS_IMPL_THREADSAFE_ADDREF(nsAddressBook) NS_IMPL_THREADSAFE_RELEASE(nsAddressBook) -NS_IMPL_QUERY_INTERFACE4(nsAddressBook, nsIAddressBook, nsICmdLineHandler, nsIContentHandler, nsIStreamLoaderObserver) +NS_IMPL_QUERY_INTERFACE4(nsAddressBook, + nsIAddressBook, + ICOMMANDLINEHANDLER, + nsIContentHandler, + nsIStreamLoaderObserver) // // nsIAddressBook @@ -2254,5 +2263,39 @@ NS_IMETHODIMP nsAddressBook::Convert4xVCardPrefs(const char *prefRoot, char **es return rv; } +#ifdef MOZ_XUL_APP + +NS_IMETHODIMP +nsAddressBook::Handle(nsICommandLine* aCmdLine) +{ + nsresult rv; + PRBool found; + + rv = aCmdLine->HandleFlag(NS_LITERAL_STRING("addressbook"), PR_FALSE, &found); + NS_ENSURE_SUCCESS(rv, rv); + + if (!found) + return NS_OK; + + nsCOMPtr wwatch (do_GetService(NS_WINDOWWATCHER_CONTRACTID)); + NS_ENSURE_TRUE(wwatch, NS_ERROR_FAILURE); + + nsCOMPtr opened; + wwatch->OpenWindow(nsnull, "chrome://messenger/content/addressbook/addressbook.xul", + "_blank", "chrome,dialog=no,all", nsnull, getter_AddRefs(opened)); + aCmdLine->SetPreventDefault(PR_TRUE); + return NS_OK; +} + +NS_IMETHODIMP +nsAddressBook::GetHelpInfo(nsACString& aResult) +{ + aResult.Assign(NS_LITERAL_CSTRING(" -addressbook Open the address book at startup.\n")); + return NS_OK; +} + +#else // !MOZ_XUL_APP + CMDLINEHANDLER_IMPL(nsAddressBook,"-addressbook","general.startup.addressbook","chrome://messenger/content/addressbook/addressbook.xul","Start with the addressbook.",NS_ADDRESSBOOKSTARTUPHANDLER_CONTRACTID,"Addressbook Startup Handler",PR_FALSE,"", PR_TRUE) +#endif diff --git a/mozilla/mailnews/addrbook/src/nsAddressBook.h b/mozilla/mailnews/addrbook/src/nsAddressBook.h index a9145d8fedc..940695d8229 100644 --- a/mozilla/mailnews/addrbook/src/nsAddressBook.h +++ b/mozilla/mailnews/addrbook/src/nsAddressBook.h @@ -43,12 +43,19 @@ #include "nsCOMPtr.h" #include "nsIAddrDatabase.h" #include "nsIScriptGlobalObject.h" -#include "nsICmdLineHandler.h" #include "nsIComponentManager.h" #include "nsIContentHandler.h" #include "nsIStreamLoader.h" #include "rdf.h" +#ifdef MOZ_XUL_APP +#include "nsICommandLineHandler.h" +#define ICOMMANDLINEHANDLER nsICommandLineHandler +#else +#include "nsICmdLineHandler.h" +#define ICOMMANDLINEHANDLER nsICmdLineHandler +#endif + class nsILocalFile; class nsIAbDirectory; @@ -83,7 +90,10 @@ const extern ExportAttributesTableStruct EXPORT_ATTRIBUTES_TABLE[EXPORT_ATTRIBUT // are probably out there that can handle 4.x LDIF) // else use the MOZ_AB_LDIF_PREFIX prefix, see nsIAddrDatabase.idl -class nsAddressBook : public nsIAddressBook, public nsICmdLineHandler, public nsIContentHandler, public nsIStreamLoaderObserver +class nsAddressBook : public nsIAddressBook, + public ICOMMANDLINEHANDLER, + public nsIContentHandler, + public nsIStreamLoaderObserver { public: @@ -92,11 +102,15 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIADDRESSBOOK - NS_DECL_NSICMDLINEHANDLER NS_DECL_NSICONTENTHANDLER NS_DECL_NSISTREAMLOADEROBSERVER - CMDLINEHANDLER_REGISTERPROC_DECLS +#ifdef MOZ_XUL_APP + NS_DECL_NSICOMMANDLINEHANDLER +#else + NS_DECL_NSICMDLINEHANDLER + CMDLINEHANDLER_REGISTERPROC_DECLS +#endif protected: nsresult DoCommand(nsIRDFDataSource *db, const nsACString& command, diff --git a/mozilla/mailnews/base/src/Makefile.in b/mozilla/mailnews/base/src/Makefile.in index 8d19a70de6a..93644d14328 100644 --- a/mozilla/mailnews/base/src/Makefile.in +++ b/mozilla/mailnews/base/src/Makefile.in @@ -51,6 +51,7 @@ REQUIRES = xpcom \ necko \ dom \ appshell \ + toolkitcomps \ appcomps \ uconv \ intl \ diff --git a/mozilla/mailnews/base/src/nsMessengerBootstrap.cpp b/mozilla/mailnews/base/src/nsMessengerBootstrap.cpp index 19e6bbb0cdc..5fd7a292031 100644 --- a/mozilla/mailnews/base/src/nsMessengerBootstrap.cpp +++ b/mozilla/mailnews/base/src/nsMessengerBootstrap.cpp @@ -56,9 +56,16 @@ #include "nsIURI.h" #include "nsIDialogParamBlock.h" +#ifdef MOZ_XUL_APP +#include "nsICommandLine.h" +#endif + NS_IMPL_THREADSAFE_ADDREF(nsMessengerBootstrap) NS_IMPL_THREADSAFE_RELEASE(nsMessengerBootstrap) -NS_IMPL_QUERY_INTERFACE2(nsMessengerBootstrap, nsICmdLineHandler, nsIMessengerWindowService) + +NS_IMPL_QUERY_INTERFACE2(nsMessengerBootstrap, + ICOMMANDLINEHANDLER, + nsIMessengerWindowService) nsMessengerBootstrap::nsMessengerBootstrap() { @@ -68,11 +75,49 @@ nsMessengerBootstrap::~nsMessengerBootstrap() { } +#ifdef MOZ_XUL_APP +NS_IMETHODIMP +nsMessengerBootstrap::Handle(nsICommandLine* aCmdLine) +{ + nsresult rv; + PRBool found; + + nsCOMPtr wwatch (do_GetService(NS_WINDOWWATCHER_CONTRACTID)); + NS_ENSURE_TRUE(wwatch, NS_ERROR_FAILURE); + + nsCOMPtr opened; + + rv = aCmdLine->HandleFlag(NS_LITERAL_STRING("options"), PR_FALSE, &found); + if (NS_SUCCEEDED(rv) && found) { + wwatch->OpenWindow(nsnull, "chrome://communicator/content/pref/pref.xul", "_blank", + "chrome,dialog=no,all", nsnull, getter_AddRefs(opened)); + } + + rv = aCmdLine->HandleFlag(NS_LITERAL_STRING("mail"), PR_FALSE, &found); + if (NS_SUCCEEDED(rv) && found) { + wwatch->OpenWindow(nsnull, "chrome://messenger/content/", "_blank", + "chrome,dialog=no,all", nsnull, getter_AddRefs(opened)); + aCmdLine->SetPreventDefault(PR_TRUE); + } + + return NS_OK; +} + +NS_IMETHODIMP +nsMessengerBootstrap::GetHelpInfo(nsACString& aResult) +{ + aResult.Assign(NS_LITERAL_CSTRING( + " -mail Open the mail folder view.\n" + " -options Open the options dialog.\n")); + + return NS_OK; +} + +#else CMDLINEHANDLER3_IMPL(nsMessengerBootstrap,"-mail","general.startup.mail","Start with mail.",NS_MAILSTARTUPHANDLER_CONTRACTID,"Mail Cmd Line Handler",PR_TRUE,"", PR_TRUE) NS_IMETHODIMP nsMessengerBootstrap::GetChromeUrlForTask(char **aChromeUrlForTask) { -#ifndef MOZ_THUNDERBIRD if (!aChromeUrlForTask) return NS_ERROR_FAILURE; nsCOMPtr pPrefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); if (pPrefBranch) @@ -92,19 +137,22 @@ NS_IMETHODIMP nsMessengerBootstrap::GetChromeUrlForTask(char **aChromeUrlForTask } } *aChromeUrlForTask = PL_strdup("chrome://messenger/content/messenger.xul"); -#else - NS_ENSURE_ARG_POINTER(aChromeUrlForTask); - *aChromeUrlForTask = PL_strdup("chrome://messenger/content/"); -#endif return NS_OK; } +#endif NS_IMETHODIMP nsMessengerBootstrap::OpenMessengerWindowWithUri(const char *windowType, const char * aFolderURI, nsMsgKey aMessageKey) { - nsXPIDLCString chromeurl; - nsresult rv = GetChromeUrlForTask(getter_Copies(chromeurl)); - if (NS_FAILED(rv)) return rv; + nsresult rv; + +#ifdef MOZ_XUL_APP + NS_NAMED_LITERAL_CSTRING(chromeurl, "chrome://messenger/content/"); +#else + nsXPIDLCString chromeurl; + rv = GetChromeUrlForTask(getter_Copies(chromeurl)); + if (NS_FAILED(rv)) return rv; +#endif nsCOMPtr argsArray; rv = NS_NewISupportsArray(getter_AddRefs(argsArray)); @@ -138,19 +186,3 @@ NS_IMETHODIMP nsMessengerBootstrap::OpenMessengerWindowWithUri(const char *windo return NS_OK; } - -#ifdef MOZ_THUNDERBIRD -nsMsgOptionsCmdLineHandler::nsMsgOptionsCmdLineHandler() -{ -} - -nsMsgOptionsCmdLineHandler::~nsMsgOptionsCmdLineHandler() -{ -} - -NS_IMPL_ISUPPORTS1(nsMsgOptionsCmdLineHandler, nsICmdLineHandler) - -CMDLINEHANDLER_IMPL(nsMsgOptionsCmdLineHandler,"-options","", "chrome://communicator/content/pref/pref.xul", - "Open Options Dialog.", NS_MAILOPTIONSTARTUPHANDLER_CONTRACTID,"Mail Options Startup Handler", PR_TRUE,"", PR_TRUE) - -#endif diff --git a/mozilla/mailnews/base/src/nsMessengerBootstrap.h b/mozilla/mailnews/base/src/nsMessengerBootstrap.h index 5954d925910..bec5a3a32b6 100644 --- a/mozilla/mailnews/base/src/nsMessengerBootstrap.h +++ b/mozilla/mailnews/base/src/nsMessengerBootstrap.h @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * @@ -41,50 +41,39 @@ #include "nscore.h" #include "nsIServiceManager.h" -#include "nsICmdLineHandler.h" #include "nsIMessengerWindowService.h" +#ifdef MOZ_XUL_APP +#include "nsICommandLineHandler.h" +#define ICOMMANDLINEHANDLER nsICommandLineHandler +#else +#include "nsICmdLineHandler.h" +#define ICOMMANDLINEHANDLER nsICmdLineHandler +#endif + #define NS_MESSENGERBOOTSTRAP_CID \ { /* 4a85a5d0-cddd-11d2-b7f6-00805f05ffa5 */ \ 0x4a85a5d0, 0xcddd, 0x11d2, \ {0xb7, 0xf6, 0x00, 0x80, 0x5f, 0x05, 0xff, 0xa5}} -#define NS_MESSENGEROPTIONSSTARTUP_CID \ -{ /* 87A35D6C-9BB9-49f8-9CAC-5D5214550B2D */ \ - 0x87a35d6c, 0x9bb9, 0x49f8, \ - { 0x9c, 0xac, 0x5d, 0x52, 0x14, 0x55, 0xb, 0x2d }} - -class nsMessengerBootstrap : public nsICmdLineHandler, public nsIMessengerWindowService { +class nsMessengerBootstrap : + public ICOMMANDLINEHANDLER, + public nsIMessengerWindowService +{ public: nsMessengerBootstrap(); virtual ~nsMessengerBootstrap(); NS_DECL_ISUPPORTS - NS_DECL_NSICMDLINEHANDLER NS_DECL_NSIMESSENGERWINDOWSERVICE - CMDLINEHANDLER_REGISTERPROC_DECLS - -}; -#ifdef MOZ_THUNDERBIRD - -// thunderbird has a new command line argument called -options which launches -// the Options dialog. - -class nsMsgOptionsCmdLineHandler : public nsICmdLineHandler -{ -public: - - NS_DECL_ISUPPORTS +#ifdef MOZ_XUL_APP + NS_DECL_NSICOMMANDLINEHANDLER +#else NS_DECL_NSICMDLINEHANDLER - - nsMsgOptionsCmdLineHandler(); - virtual ~nsMsgOptionsCmdLineHandler(); - CMDLINEHANDLER_REGISTERPROC_DECLS -}; - #endif +}; #endif diff --git a/mozilla/mailnews/build/Makefile.in b/mozilla/mailnews/build/Makefile.in index 4b4a9e192fa..3ab73ea8b6c 100644 --- a/mozilla/mailnews/build/Makefile.in +++ b/mozilla/mailnews/build/Makefile.in @@ -63,9 +63,10 @@ MODULE_NAME = nsMailModule REQUIRES = xpcom \ xpcom_obsolete \ xpobsolete \ - addrbook \ + addrbook \ appcomps \ appshell \ + toolkitcomps \ bayesflt \ xmlextras \ content \ @@ -76,7 +77,7 @@ REQUIRES = xpcom \ intl \ locale \ layout \ - lwbrk \ + lwbrk \ mailnews \ mailview \ msglocal \ @@ -86,20 +87,20 @@ REQUIRES = xpcom \ msgnews \ msgimap \ msgdb \ - msgmdn \ + msgmdn \ mime \ mimeemitter \ mork \ necko \ - nkcache \ + nkcache \ pref \ rdf \ - rdfutil \ + rdfutil \ string \ txmgr \ widget \ webbrwsr \ - uconv \ + uconv \ uriloader \ $(NULL) @@ -118,7 +119,7 @@ SHARED_LIBRARY_LIBS = \ $(DIST)/lib/$(LIB_PREFIX)msgbsutl_s.$(LIB_SUFFIX) \ $(DIST)/lib/$(LIB_PREFIX)msgbase_s.$(LIB_SUFFIX) \ $(DIST)/lib/$(LIB_PREFIX)msgsearch_s.$(LIB_SUFFIX) \ - $(DIST)/lib/$(LIB_PREFIX)msglocal_s.$(LIB_SUFFIX) \ + $(DIST)/lib/$(LIB_PREFIX)msglocal_s.$(LIB_SUFFIX) \ $(DIST)/lib/$(LIB_PREFIX)msgcompose_s.$(LIB_SUFFIX) \ $(DIST)/lib/$(LIB_PREFIX)msgdb_s.$(LIB_SUFFIX) \ $(DIST)/lib/$(LIB_PREFIX)msgimap_s.$(LIB_SUFFIX) \ diff --git a/mozilla/mailnews/build/nsMailModule.cpp b/mozilla/mailnews/build/nsMailModule.cpp index aa413d061d0..9375de504b1 100644 --- a/mozilla/mailnews/build/nsMailModule.cpp +++ b/mozilla/mailnews/build/nsMailModule.cpp @@ -46,6 +46,7 @@ #include "nsIModule.h" #include "nsIGenericFactory.h" #include "pratom.h" +#include "nsICategoryManager.h" #include "nsIComponentManager.h" #include "nsIServiceManager.h" #include "nsCRT.h" @@ -284,7 +285,6 @@ // mailnews base factories //////////////////////////////////////////////////////////////////////////////// NS_GENERIC_FACTORY_CONSTRUCTOR(nsMessengerBootstrap) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgOptionsCmdLineHandler) NS_GENERIC_FACTORY_CONSTRUCTOR(nsUrlListenerManager) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMsgMailSession, Init) NS_GENERIC_FACTORY_CONSTRUCTOR(nsMessenger) @@ -569,6 +569,54 @@ static NS_METHOD UnregisterContentPolicy(nsIComponentManager *aCompMgr, nsIFile return catman->DeleteCategoryEntry("content-policy", NS_MSGCONTENTPOLICY_CONTRACTID, PR_TRUE); } +static NS_METHOD +RegisterCommandLineHandlers(nsIComponentManager* compMgr, nsIFile* path, + const char *location, const char *type, + const nsModuleComponentInfo *info) +{ + nsresult rv; + nsCOMPtr catMan (do_GetService(NS_CATEGORYMANAGER_CONTRACTID)); + NS_ENSURE_TRUE(catMan, NS_ERROR_FAILURE); + + rv = catMan->AddCategoryEntry("command-line-handler", "m-mail", + NS_MESSENGERBOOTSTRAP_CONTRACTID, + PR_TRUE, PR_TRUE, nsnull); + rv |= catMan->AddCategoryEntry("command-line-handler", "m-addressbook", + NS_ADDRESSBOOK_CONTRACTID, + PR_TRUE, PR_TRUE, nsnull); + rv |= catMan->AddCategoryEntry("command-line-handler", "m-compose", + NS_MSGCOMPOSESERVICE_CONTRACTID, + PR_TRUE, PR_TRUE, nsnull); + rv |= catMan->AddCategoryEntry("command-line-handler", "m-news", + NS_NNTPSERVICE_CONTRACTID, + PR_TRUE, PR_TRUE, nsnull); + if (NS_FAILED(rv)) + return NS_ERROR_FAILURE; + + return NS_OK; +} + +static NS_METHOD +UnregisterCommandLineHandlers(nsIComponentManager* compMgr, nsIFile* path, + const char *location, + const nsModuleComponentInfo *info) +{ + nsCOMPtr catMan (do_GetService(NS_CATEGORYMANAGER_CONTRACTID)); + NS_ENSURE_TRUE(catMan, NS_ERROR_FAILURE); + + catMan->DeleteCategoryEntry("command-line-handler", "m-mail", + PR_TRUE); + catMan->DeleteCategoryEntry("command-line-handler", "m-addressbook", + PR_TRUE); + catMan->DeleteCategoryEntry("command-line-handler", "m-compose", + PR_TRUE); + catMan->DeleteCategoryEntry("command-line-handler", "m-news", + PR_TRUE); + + return NS_OK; +} + + // The list of components we register static const nsModuleComponentInfo gComponents[] = { //////////////////////////////////////////////////////////////////////////////// @@ -577,23 +625,13 @@ static const nsModuleComponentInfo gComponents[] = { { "Netscape Messenger Bootstrapper", NS_MESSENGERBOOTSTRAP_CID, NS_MESSENGERBOOTSTRAP_CONTRACTID, nsMessengerBootstrapConstructor, - }, - { "Options Startup Handler", NS_MESSENGEROPTIONSSTARTUP_CID, - NS_MAILOPTIONSTARTUPHANDLER_CONTRACTID, - nsMsgOptionsCmdLineHandlerConstructor, - nsMsgOptionsCmdLineHandler::RegisterProc, - nsMsgOptionsCmdLineHandler::UnregisterProc + RegisterCommandLineHandlers, + UnregisterCommandLineHandlers }, { "Netscape Messenger Window Service", NS_MESSENGERWINDOWSERVICE_CID, NS_MESSENGERWINDOWSERVICE_CONTRACTID, nsMessengerBootstrapConstructor, }, - { "Mail Startup Handler", NS_MESSENGERBOOTSTRAP_CID, - NS_MAILSTARTUPHANDLER_CONTRACTID, - nsMessengerBootstrapConstructor, - nsMessengerBootstrap::RegisterProc, - nsMessengerBootstrap::UnregisterProc - }, { "UrlListenerManager", NS_URLLISTENERMANAGER_CID, NS_URLLISTENERMANAGER_CONTRACTID, nsUrlListenerManagerConstructor, @@ -802,9 +840,6 @@ static const nsModuleComponentInfo gComponents[] = { //////////////////////////////////////////////////////////////////////////////// { "Address Book", NS_ADDRESSBOOK_CID, NS_ADDRESSBOOK_CONTRACTID, nsAddressBookConstructor }, - { "Address Book Startup Handler", NS_ADDRESSBOOK_CID, - NS_ADDRESSBOOKSTARTUPHANDLER_CONTRACTID, nsAddressBookConstructor, - nsAddressBook::RegisterProc, nsAddressBook::UnregisterProc }, { "Address Book Directory Datasource", NS_ABDIRECTORYDATASOURCE_CID, NS_ABDIRECTORYDATASOURCE_CONTRACTID, nsAbDirectoryDataSourceConstructor }, { "Address Boot Strap Directory", NS_ABDIRECTORY_CID, @@ -894,9 +929,6 @@ static const nsModuleComponentInfo gComponents[] = { NS_MSGCOMPOSE_CONTRACTID, nsMsgComposeConstructor }, { "Msg Compose Service", NS_MSGCOMPOSESERVICE_CID, NS_MSGCOMPOSESERVICE_CONTRACTID, nsMsgComposeServiceConstructor }, - { "Msg Compose Startup Handler", NS_MSGCOMPOSESERVICE_CID, - NS_MSGCOMPOSESTARTUPHANDLER_CONTRACTID, nsMsgComposeServiceConstructor, nsMsgComposeService::RegisterProc, - nsMsgComposeService::UnregisterProc }, { "mailto content handler", NS_MSGCOMPOSECONTENTHANDLER_CID, NS_MSGCOMPOSECONTENTHANDLER_CONTRACTID, nsMsgComposeContentHandlerConstructor }, { "Msg Compose Parameters", NS_MSGCOMPOSEPARAMS_CID, @@ -1097,9 +1129,6 @@ static const nsModuleComponentInfo gComponents[] = { NS_NNTPURL_CONTRACTID, nsNntpUrlConstructor }, { "NNTP Service", NS_NNTPSERVICE_CID, NS_NNTPSERVICE_CONTRACTID, nsNntpServiceConstructor }, - { "News Startup Handler", NS_NNTPSERVICE_CID, - NS_NEWSSTARTUPHANDLER_CONTRACTID, nsNntpServiceConstructor, - nsNntpService::RegisterProc, nsNntpService::UnregisterProc }, { "NNTP Protocol Info", NS_NNTPSERVICE_CID, NS_NNTPPROTOCOLINFO_CONTRACTID, nsNntpServiceConstructor }, { "NNTP Message Service",NS_NNTPSERVICE_CID, diff --git a/mozilla/mailnews/compose/src/Makefile.in b/mozilla/mailnews/compose/src/Makefile.in index f8cd6e840cb..8e454f189e8 100644 --- a/mozilla/mailnews/compose/src/Makefile.in +++ b/mozilla/mailnews/compose/src/Makefile.in @@ -66,6 +66,7 @@ REQUIRES = xpcom \ msgdb \ rdf \ appshell \ + toolkitcomps \ appcomps \ msgimap \ msgnews \ diff --git a/mozilla/mailnews/compose/src/nsMsgComposeService.cpp b/mozilla/mailnews/compose/src/nsMsgComposeService.cpp index c248c43929a..6a1f95fac9c 100644 --- a/mozilla/mailnews/compose/src/nsMsgComposeService.cpp +++ b/mozilla/mailnews/compose/src/nsMsgComposeService.cpp @@ -92,6 +92,10 @@ #include "nsIContentSink.h" #include "mozISanitizingSerializer.h" +#ifdef MOZ_XUL_APP +#include "nsICommandLine.h" +#endif + #ifdef XP_WIN32 #include #include @@ -158,7 +162,11 @@ nsMsgComposeService::nsMsgComposeService() mCachedWindows = nsnull; } -NS_IMPL_ISUPPORTS4(nsMsgComposeService, nsIMsgComposeService, nsIObserver, nsICmdLineHandler, nsISupportsWeakReference) +NS_IMPL_ISUPPORTS4(nsMsgComposeService, + nsIMsgComposeService, + nsIObserver, + ICOMMANDLINEHANDLER, + nsISupportsWeakReference) nsMsgComposeService::~nsMsgComposeService() { @@ -991,7 +999,76 @@ nsresult nsMsgComposeService::AddGlobalHtmlDomains() return NS_OK; } +#ifdef MOZ_XUL_APP +NS_IMETHODIMP +nsMsgComposeService::Handle(nsICommandLine* aCmdLine) +{ + nsresult rv; + PRInt32 found, end, count; + nsAutoString uristr; + + rv = aCmdLine->FindFlag(NS_LITERAL_STRING("compose"), PR_FALSE, &found); + NS_ENSURE_SUCCESS(rv, rv); + + if (found == -1) + return NS_OK; + + end = found; + + rv = aCmdLine->GetLength(&count); + NS_ENSURE_SUCCESS(rv, rv); + + if (count >= found) { + aCmdLine->GetArgument(found + 1, uristr); + if (StringBeginsWith(uristr, NS_LITERAL_STRING("mailto:"))) { + end++; + // mailto: URIs are frequently passed with spaces in them. They should be + // escaped with %20, but we hack around broken clients. See bug 231032. + while (end + 1 < count) { + nsAutoString curarg; + aCmdLine->GetArgument(end + 1, curarg); + if (curarg.First() == '-') + break; + + uristr.Append(' '); + uristr.Append(curarg); + ++end; + } + } + else { + uristr.Truncate(); + } + } + + aCmdLine->RemoveArguments(found, end); + + nsCOMPtr wwatch (do_GetService(NS_WINDOWWATCHER_CONTRACTID)); + NS_ENSURE_TRUE(wwatch, NS_ERROR_FAILURE); + + nsCOMPtr arg; + if (!uristr.IsEmpty()) { + arg = do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID); + if (arg) + arg->SetData(uristr); + } + + nsCOMPtr opened; + wwatch->OpenWindow(nsnull, DEFAULT_CHROME, "_blank", + "chrome,dialog=no,all", arg, getter_AddRefs(opened)); + + aCmdLine->SetPreventDefault(PR_TRUE); + return NS_OK; +} + +NS_IMETHODIMP +nsMsgComposeService::GetHelpInfo(nsACString& aResult) +{ + aResult.Assign(NS_LITERAL_CSTRING(" -compose Compose a mail or news message.\n")); + return NS_OK; +} + +#else CMDLINEHANDLER_IMPL(nsMsgComposeService, "-compose", "general.startup.messengercompose", DEFAULT_CHROME, "Start with messenger compose.", NS_MSGCOMPOSESTARTUPHANDLER_CONTRACTID, "Messenger Compose Startup Handler", PR_TRUE, "about:blank", PR_TRUE) - +#endif diff --git a/mozilla/mailnews/compose/src/nsMsgComposeService.h b/mozilla/mailnews/compose/src/nsMsgComposeService.h index 21068ed8a6f..458a9ab1165 100644 --- a/mozilla/mailnews/compose/src/nsMsgComposeService.h +++ b/mozilla/mailnews/compose/src/nsMsgComposeService.h @@ -41,11 +41,18 @@ #include "nsIMsgComposeService.h" #include "nsISupportsArray.h" #include "nsCOMPtr.h" -#include "nsICmdLineHandler.h" #include "nsIDOMWindowInternal.h" #include "nsIObserver.h" #include "nsWeakReference.h" +#ifdef MOZ_XUL_APP +#include "nsICommandLineHandler.h" +#define ICOMMANDLINEHANDLER nsICommandLineHandler +#else +#include "nsICmdLineHandler.h" +#define ICOMMANDLINEHANDLER nsICmdLineHandler +#endif + class nsMsgCachedWindowInfo { public: @@ -67,7 +74,11 @@ public: PRBool htmlCompose; }; -class nsMsgComposeService : public nsIMsgComposeService, public nsIObserver ,public nsICmdLineHandler, public nsSupportsWeakReference +class nsMsgComposeService : + public nsIMsgComposeService, + public nsIObserver, + public ICOMMANDLINEHANDLER, + public nsSupportsWeakReference { public: nsMsgComposeService(); @@ -76,8 +87,13 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIMSGCOMPOSESERVICE NS_DECL_NSIOBSERVER + +#ifdef MOZ_XUL_APP + NS_DECL_NSICOMMANDLINEHANDLER +#else NS_DECL_NSICMDLINEHANDLER - CMDLINEHANDLER_REGISTERPROC_DECLS + CMDLINEHANDLER_REGISTERPROC_DECLS +#endif nsresult Init(); void Reset(); diff --git a/mozilla/mailnews/mapi/mapihook/src/msgMapiHook.cpp b/mozilla/mailnews/mapi/mapihook/src/msgMapiHook.cpp index c11cfb69af0..d780163e58f 100644 --- a/mozilla/mailnews/mapi/mapihook/src/msgMapiHook.cpp +++ b/mozilla/mailnews/mapi/mapihook/src/msgMapiHook.cpp @@ -58,7 +58,6 @@ #include "nsIAppShellService.h" #include "nsIDOMWindowInternal.h" #include "nsINativeAppSupport.h" -#include "nsICmdLineService.h" #include "nsIMsgAccountManager.h" #include "nsIDOMWindowInternal.h" #include "nsXPIDLString.h" @@ -88,6 +87,10 @@ #include "msgMapiMain.h" #include "nsNetUtil.h" +#ifndef MOZ_XUL_APP +#include "nsICmdLineService.h" +#endif + extern PRLogModuleInfo *MAPI; diff --git a/mozilla/mailnews/news/src/Makefile.in b/mozilla/mailnews/news/src/Makefile.in index 6f4b0d9aa0e..c59bf813395 100644 --- a/mozilla/mailnews/news/src/Makefile.in +++ b/mozilla/mailnews/news/src/Makefile.in @@ -63,6 +63,7 @@ REQUIRES = xpcom \ uriloader \ appshell \ appcomps \ + toolkitcomps \ mime \ intl \ webshell \ diff --git a/mozilla/mailnews/news/src/nsNntpService.cpp b/mozilla/mailnews/news/src/nsNntpService.cpp index edefb09de72..f9963e3156e 100644 --- a/mozilla/mailnews/news/src/nsNntpService.cpp +++ b/mozilla/mailnews/news/src/nsNntpService.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * @@ -66,7 +66,6 @@ #include "nsIMsgAccountManager.h" #include "nsIMessengerMigrator.h" #include "nsINntpIncomingServer.h" -#include "nsICmdLineHandler.h" #include "nsICategoryManager.h" #include "nsIDocShell.h" #include "nsIDocShellLoadInfo.h" @@ -86,6 +85,11 @@ #include "nsMsgUtils.h" #include "nsEscape.h" #include "nsNetUtil.h" +#include "nsIWindowWatcher.h" + +#ifdef MOZ_XUL_APP +#include "nsICommandLine.h" +#endif #undef GetPort // XXX Windows! #undef SetPort // XXX Windows! @@ -117,7 +121,7 @@ NS_IMPL_QUERY_INTERFACE7(nsNntpService, nsIMsgMessageService, nsIProtocolHandler, nsIMsgProtocolInfo, - nsICmdLineHandler, + ICOMMANDLINEHANDLER, nsIMsgMessageFetchPartService, nsIContentHandler) @@ -1690,11 +1694,42 @@ nsNntpService::GetListOfGroupsOnServer(nsINntpIncomingServer *aNntpServer, nsIMs return NS_OK; } + +#ifdef MOZ_XUL_APP + +NS_IMETHODIMP +nsNntpService::Handle(nsICommandLine* aCmdLine) +{ + nsresult rv; + PRBool found; + + rv = aCmdLine->HandleFlag(NS_LITERAL_STRING("news"), PR_FALSE, &found); + if (NS_SUCCEEDED(rv) && found) { + nsCOMPtr wwatch (do_GetService(NS_WINDOWWATCHER_CONTRACTID)); + NS_ENSURE_TRUE(wwatch, NS_ERROR_FAILURE); + + nsCOMPtr opened; + wwatch->OpenWindow(nsnull, "chrome://messenger/content/", "_blank", + "chrome,dialog=no,all", nsnull, getter_AddRefs(opened)); + aCmdLine->SetPreventDefault(PR_TRUE); + } + + return NS_OK; +} + +NS_IMETHODIMP +nsNntpService::GetHelpInfo(nsACString& aResult) +{ + aResult.Assign(NS_LITERAL_CSTRING(" -news Open the news client.\n")); + return NS_OK; +} + +#else // MOZ_XUL_APP + CMDLINEHANDLER3_IMPL(nsNntpService,"-news","general.startup.news","Start with news.",NS_NEWSSTARTUPHANDLER_CONTRACTID,"News Cmd Line Handler", PR_FALSE,"", PR_TRUE) NS_IMETHODIMP nsNntpService::GetChromeUrlForTask(char **aChromeUrlForTask) { -#ifndef MOZ_THUNDERBIRD if (!aChromeUrlForTask) return NS_ERROR_FAILURE; nsresult rv; nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); @@ -1715,11 +1750,8 @@ NS_IMETHODIMP nsNntpService::GetChromeUrlForTask(char **aChromeUrlForTask) } *aChromeUrlForTask = PL_strdup("chrome://messenger/content/messenger.xul"); return NS_OK; -#else - NS_ENSURE_ARG_POINTER(aChromeUrlForTask); - *aChromeUrlForTask = PL_strdup("chrome://messenger/content/"); -#endif } +#endif // MOZ_XUL_APP NS_IMETHODIMP nsNntpService::HandleContent(const char * aContentType, nsIInterfaceRequestor* aWindowContext, nsIRequest *request) diff --git a/mozilla/mailnews/news/src/nsNntpService.h b/mozilla/mailnews/news/src/nsNntpService.h index 59420ba2816..8551011360b 100644 --- a/mozilla/mailnews/news/src/nsNntpService.h +++ b/mozilla/mailnews/news/src/nsNntpService.h @@ -48,11 +48,18 @@ #include "nsIMsgProtocolInfo.h" #include "nsIMsgWindow.h" #include "nsINntpUrl.h" -#include "nsICmdLineHandler.h" #include "nsCOMPtr.h" #include "nsIContentHandler.h" #include "nsICacheSession.h" +#ifdef MOZ_XUL_APP +#include "nsICommandLineHandler.h" +#define ICOMMANDLINEHANDLER nsICommandLineHandler +#else +#include "nsICmdLineHandler.h" +#define ICOMMANDLINEHANDLER nsICmdLineHandler +#endif + class nsIURI; class nsIUrlListener; @@ -61,7 +68,7 @@ class nsNntpService : public nsINntpService, public nsIMsgMessageFetchPartService, public nsIProtocolHandler, public nsIMsgProtocolInfo, - public nsICmdLineHandler, + public ICOMMANDLINEHANDLER, public nsIContentHandler { public: @@ -71,16 +78,20 @@ public: NS_DECL_NSIMSGMESSAGESERVICE NS_DECL_NSIPROTOCOLHANDLER NS_DECL_NSIMSGPROTOCOLINFO - NS_DECL_NSICMDLINEHANDLER NS_DECL_NSICONTENTHANDLER NS_DECL_NSIMSGMESSAGEFETCHPARTSERVICE +#ifdef MOZ_XUL_APP + NS_DECL_NSICOMMANDLINEHANDLER +#else + NS_DECL_NSICMDLINEHANDLER + CMDLINEHANDLER_REGISTERPROC_DECLS +#endif + // nsNntpService nsNntpService(); virtual ~nsNntpService(); - CMDLINEHANDLER_REGISTERPROC_DECLS - protected: PRBool WeAreOffline(); diff --git a/mozilla/toolkit/components/Makefile.in b/mozilla/toolkit/components/Makefile.in index c830cfb76f0..2056f450ec1 100644 --- a/mozilla/toolkit/components/Makefile.in +++ b/mozilla/toolkit/components/Makefile.in @@ -72,8 +72,11 @@ endif endif DIRS += \ + commandlines \ startup \ build \ $(NULL) +EXTRA_PP_COMPONENTS = nsDefaultCLH.js + include $(topsrcdir)/config/rules.mk diff --git a/mozilla/toolkit/components/build/nsModule.cpp b/mozilla/toolkit/components/build/nsModule.cpp index 6130675542d..1437b5ba1ba 100644 --- a/mozilla/toolkit/components/build/nsModule.cpp +++ b/mozilla/toolkit/components/build/nsModule.cpp @@ -38,7 +38,6 @@ #include "nsIGenericFactory.h" #include "nsAppStartup.h" #include "nsUserInfo.h" -#include "nsCommandLineService.h" #include "nsXPFEComponentsCID.h" #if defined(MOZ_PHOENIX) || defined(MOZ_SUNBIRD) @@ -63,7 +62,6 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsAppStartup, Init) NS_GENERIC_FACTORY_CONSTRUCTOR(nsUserInfo) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsCmdLineService) #if defined(MOZ_PHOENIX) || defined(MOZ_SUNBIRD) #ifdef XP_WIN @@ -106,11 +104,6 @@ static const nsModuleComponentInfo components[] = NS_USERINFO_CONTRACTID, nsUserInfoConstructor }, - { "Command Line Service", - NS_COMMANDLINESERVICE_CID, - NS_COMMANDLINESERVICE_CONTRACTID, - nsCmdLineServiceConstructor }, - #if defined(MOZ_PHOENIX) || defined(MOZ_SUNBIRD) #ifdef XP_WIN { "Alerts Service", diff --git a/mozilla/toolkit/components/commandlines/Makefile.in b/mozilla/toolkit/components/commandlines/Makefile.in new file mode 100644 index 00000000000..fa8a72f1215 --- /dev/null +++ b/mozilla/toolkit/components/commandlines/Makefile.in @@ -0,0 +1,50 @@ +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is the Mozilla toolkit. +# +# The Initial Developer of the Original Code is +# Benjamin Smedberg . +# +# Portions created by the Initial Developer are Copyright (C) 2004 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +DIRS = \ + public \ + src \ + $(NULL) + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/toolkit/components/commandlines/public/Makefile.in b/mozilla/toolkit/components/commandlines/public/Makefile.in new file mode 100644 index 00000000000..64890e045bc --- /dev/null +++ b/mozilla/toolkit/components/commandlines/public/Makefile.in @@ -0,0 +1,54 @@ +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is the Mozilla toolkit. +# +# The Initial Developer of the Original Code is +# Benjamin Smedberg . +# +# Portions created by the Initial Developer are Copyright (C) 2004 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +DEPTH = ../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = toolkitcomps +XPIDL_MODULE = commandlines + +XPIDLSRCS = \ + nsICommandLine.idl \ + nsICommandLineRunner.idl \ + nsICommandLineHandler.idl \ + $(NULL) + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/toolkit/components/commandlines/public/nsICommandLine.idl b/mozilla/toolkit/components/commandlines/public/nsICommandLine.idl new file mode 100644 index 00000000000..5e3bfe923fd --- /dev/null +++ b/mozilla/toolkit/components/commandlines/public/nsICommandLine.idl @@ -0,0 +1,170 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla toolkit. + * + * The Initial Developer of the Original Code is + * Benjamin Smedberg + * + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" + +interface nsIFile; +interface nsIURI; + +/** + * Represents the command line used to invoke a XUL application. This may be the + * original command-line of this instance, or a command line remoted from another + * instance of the application. + * + * DEFINITIONS: + * "arguments" are any values found on the command line. + * "flags" are switches. In normalized form they are preceded by a single dash. + * Some flags may take "parameters", e.g. "-url " or "-install-xpi " + * + * @status UNDER_REVIEW This interface is intended to be frozen, but isn't frozen + * yet. Please use with care. + */ + +[scriptable, uuid(d2368f41-b2ed-424e-891e-f7aedd92d5d3)] +interface nsICommandLine : nsISupports +{ + /** + * Number of arguments in the command line. The application name is not + * part of the command line. + */ + readonly attribute long length; + + /** + * Get an argument from the array of command-line arguments. + * + * On windows, flags of the form /flag are normalized to -flag. /flag:param + * are normalized to -flag param. + * + * On *nix and mac flags of the form --flag are normalized to -flag. --flag=param + * are normalized to the form -flag param. + * + * @param aIndex The argument to retrieve. This index is 0-based, and does + * not include the application name. + * @return The indexth argument. + * @throws NS_ERROR_INVALID_ARG if aIndex is out of bounds. + */ + AString getArgument(in long aIndex); + + /** + * Find a command-line flag. + * + * @param aFlag The flag name to locate. Do not include the initial + * hyphen. + * @param aCaseSensitive Whether to do case-sensitive comparisons. + * @return The position of the flag in the command line. + */ + long findFlag(in AString aFlag, in boolean aCaseSensitive); + + /** + * Remove arguments from the command line. This normally occurs after + * a handler has processed the arguments. + * + * @param aStart Index to begin removing. + * @param aEnd Index to end removing, inclusive. + */ + void removeArguments(in long aStart, in long aEnd); + + /** + * A helper method which will find a flag and remove it in one step. + * + * @param aFlag The flag name to find and remove. + * @param aCaseSensitive Whether to do case-sensitive comparisons. + * @return Whether the flag was found. + */ + boolean handleFlag(in AString aFlag, in boolean aCaseSensitive); + + /** + * Find a flag with a parameter and remove both. This is a helper + * method that combines "findFlag" and "removeArguments" in one step. + * + * @return null (a void astring) if the flag is not found. The parameter value + * if found. Note that null and the empty string are not the same. + * @throws NS_ERROR_INVALID_ARG if the flag exists without a parameter + * + * @param aFlag The flag name to find and remove. + * @param aCaseSensitive Whether to do case-sensitive flag search. + */ + AString handleFlagWithParam(in AString aFlag, in boolean aCaseSensitive); + + /** + * The type of command line being processed. + * + * STATE_INITIAL_LAUNCH is the first launch of the application instance. + * STATE_REMOTE_AUTO is a remote command line automatically redirected to + * this instance. + * STATE_REMOTE_EXPLICIT is a remote command line explicitly redirected to + * this instance using xremote/windde/appleevents. + */ + readonly attribute unsigned long state; + + const unsigned long STATE_INITIAL_LAUNCH = 0; + const unsigned long STATE_REMOTE_AUTO = 1; + const unsigned long STATE_REMOTE_EXPLICIT = 2; + + /** + * There may be a command-line handler which performs a default action if + * there was no explicit action on the command line (open a default browser + * window, for example). This flag allows the default action to be prevented. + */ + attribute boolean preventDefault; + + /** + * The working directory for this command line. Use this property instead + * of the working directory for the current process, since a redirected + * command line may have had a different working directory. + */ + readonly attribute nsIFile workingDirectory; + + /** + * Resolve a file-path argument into an nsIFile. This method gracefully + * handles relative or absolute file paths, according to the working + * directory of this command line. + * + * @param aArgument The command-line argument to resolve. + */ + nsIFile resolveFile(in AString aArgument); + + /** + * Resolves a URI argument into a URI. This method has platform-specific + * logic for converting an absolute URI or a relative file-path into the + * appropriate URI object; it gracefully handles win32 C:\ paths which would + * confuse the ioservice if passed directly. + * + * @param aArgument The command-line argument to resolve. + */ + nsIURI resolveURI(in AString aArgument); +}; diff --git a/mozilla/toolkit/components/commandlines/public/nsICommandLineHandler.idl b/mozilla/toolkit/components/commandlines/public/nsICommandLineHandler.idl new file mode 100644 index 00000000000..51f5153195d --- /dev/null +++ b/mozilla/toolkit/components/commandlines/public/nsICommandLineHandler.idl @@ -0,0 +1,89 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla toolkit. + * + * The Initial Developer of the Original Code is + * Benjamin Smedberg + * + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" + +interface nsICommandLine; + +/** + * Handles arguments on the command line of an XUL application. + * + * Each handler is registered in the category "command-line-handler". + * The entries in this category are read in alphabetical order, and each + * category value is treated as a service contractid implementing this + * interface. + * + * By convention, handler with ordinary priority should begin with "m". + * + * Example: + * Category Entry Value + * command-line-handler b-jsdebug @mozilla.org/venkman/clh;1 + * command-line-handler c-extensions @mozilla.org/extension-manager/clh;1 + * command-line-hanlder m-edit @mozilla.org/composer/clh;1 + * command-line-handler m-irc @mozilla.org/chatzilla/clh;1 + * command-line-handler y-final @mozilla.org/browser/clh-final;1 + * + * @status UNDER_REVIEW This interface is intended to be frozen, but it isn't + * frozen yet. Be careful! + * @note What do we do about localizing helpInfo? Do we make each handler do it, + * or provide a generic solution of some sort? Don't freeze this interface + * without thinking about this! + */ + +[scriptable, uuid(d4b123df-51ee-48b1-a663-002180e60d3b)] +interface nsICommandLineHandler : nsISupports +{ + /** + * Process a command line. If this handler finds arguments that it + * understands, it should perform the appropriate actions (such as opening + * a window), and remove the arguments from the command-line array. + * + * @throw NS_ERROR_ABORT to immediately cease command-line handling + * (if this is STATE_INITIAL_LAUNCH, quits the app). + * All other exceptions are silently ignored. + */ + void handle(in nsICommandLine aCommandLine); + + /** + * When the app is launched with the -help argument, this attribute + * is retrieved and displayed to the user (on stdout). The text should + * have embedded newlines which wrap at 76 columns, and should include + * a newline at the end. By convention, the right column which contains flag + * descriptions begins at the 24th character. + */ + readonly attribute AUTF8String helpInfo; +}; diff --git a/mozilla/toolkit/components/commandlines/public/nsICommandLineRunner.idl b/mozilla/toolkit/components/commandlines/public/nsICommandLineRunner.idl new file mode 100644 index 00000000000..2a458c9e11e --- /dev/null +++ b/mozilla/toolkit/components/commandlines/public/nsICommandLineRunner.idl @@ -0,0 +1,81 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla toolkit. + * + * The Initial Developer of the Original Code is + * Benjamin Smedberg + * + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" +#include "nsICommandLine.idl" + +[ptr] native nsCharPtrArray(char*); + +/** + * Extension of nsICommandLine that allows for initialization of new command lines + * and running the command line actions by processing the command line handlers. + * + * @status INTERNAL - This interface is not meant for use by embedders, and is + * not intended to be frozen. If you are an embedder and need + * functionality provided by this interface, talk to Benjamin + * Smedberg . + */ + +[uuid(8089187e-2f73-48dc-a8e1-baa2633618e3)] +interface nsICommandLineRunner : nsICommandLine +{ + /** + * This method assumes a native character set, and is meant to be called + * with the argc/argv passed to main(). Talk to bsmedberg if you need to + * create a command line using other data. argv will not be altered in any + * way. + * + * @param workingDir The working directory for resolving file and URI paths. + * @param state The nsICommandLine.state flag. + */ + void init(in long argc, in nsCharPtrArray argv, + in nsIFile workingDir, in unsigned long state); + + /** + * Process the command-line handlers in the proper order, calling "handle()" on + * each. + * + * @throws NS_ERROR_ABORT if any handler throws NS_ERROR_ABORT. All other errors + * thrown by handlers will be silently ignored. + */ + void run(); + + /** + * Process and combine the help text provided by each command-line handler. + */ + readonly attribute AUTF8String helpText; +}; diff --git a/mozilla/toolkit/components/commandlines/src/Makefile.in b/mozilla/toolkit/components/commandlines/src/Makefile.in new file mode 100644 index 00000000000..06c4770142a --- /dev/null +++ b/mozilla/toolkit/components/commandlines/src/Makefile.in @@ -0,0 +1,74 @@ +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is the Mozilla toolkit. +# +# The Initial Developer of the Original Code is +# Benjamin Smedberg . +# +# Portions created by the Initial Developer are Copyright (C) 2004 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# +# Alternatively, the contents of this file may be used under the terms of +# either the GNU General Public License Version 2 or later (the "GPL"), or +# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** + +DEPTH = ../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +# Because this is used by seamonkey and the toolkit, we build this as its +# own component, instead of building it into toolkit/components/build + +MODULE = toolkitcomps +LIBRARY_NAME = commandlines +EXPORT_LIBRARY = 1 +IS_COMPONENT = 1 +MODULE_NAME = CommandLineModule + +REQUIRES = \ + xpcom \ + string \ + necko \ + unicharutil \ + $(NULL) + +CPPSRCS = \ + nsCommandLine.cpp \ + $(NULL) + +EXTRA_DSO_LDOPTS += \ + $(MOZ_COMPONENT_LIBS) \ + $(MOZ_UNICHARUTIL_LIBS) \ + $(NULL) + +ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) +EXTRA_DSO_LDOPTS += $(TK_LIBS) +endif + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/toolkit/components/commandlines/src/nsCommandLine.cpp b/mozilla/toolkit/components/commandlines/src/nsCommandLine.cpp new file mode 100644 index 00000000000..6cd056fdb9c --- /dev/null +++ b/mozilla/toolkit/components/commandlines/src/nsCommandLine.cpp @@ -0,0 +1,624 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla toolkit. + * + * The Initial Developer of the Original Code is + * Benjamin Smedberg + * + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsICommandLineRunner.h" + +#include "nsICategoryManager.h" +#include "nsICommandLineHandler.h" +#include "nsIFile.h" +#include "nsISimpleEnumerator.h" +#include "nsIStringEnumerator.h" + +#include "nsCOMPtr.h" +#include "nsIGenericFactory.h" +#include "nsISupportsImpl.h" +#include "nsNativeCharsetUtils.h" +#include "nsNetUtil.h" +#include "nsUnicharUtils.h" +#include "nsVoidArray.h" +#include "nsXPCOMCID.h" +#include "plstr.h" + +#ifdef XP_MACOSX +#include +#include "nsILocalFileMac.h" +#elif defined(XP_WIN) +#include +#include +#elif defined(XP_BEOS) +#include +#elif defined(XP_UNIX) +#include +#endif + +#ifdef DEBUG_bsmedberg +#define DEBUG_COMMANDLINE +#endif + +class nsCommandLine : public nsICommandLineRunner +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSICOMMANDLINE + NS_DECL_NSICOMMANDLINERUNNER + + nsCommandLine(); + +protected: + ~nsCommandLine() { } + + void appendArg(const char* arg); + nsresult getHandlers(nsCStringArray& handlers, nsICategoryManager* catman); + + nsStringArray mArgs; + PRUint32 mState; + nsCOMPtr mWorkingDir; + PRBool mPreventDefault; +}; + +nsCommandLine::nsCommandLine() : + mState(STATE_INITIAL_LAUNCH), + mPreventDefault(PR_FALSE) +{ + +} + + +NS_IMPL_ISUPPORTS2(nsCommandLine, + nsICommandLine, + nsICommandLineRunner) + +NS_IMETHODIMP +nsCommandLine::GetLength(PRInt32 *aResult) +{ + *aResult = mArgs.Count(); + return NS_OK; +} + +NS_IMETHODIMP +nsCommandLine::GetArgument(PRInt32 aIndex, nsAString& aResult) +{ + NS_ENSURE_ARG_MIN(aIndex, 0); + NS_ENSURE_ARG_MAX(aIndex, mArgs.Count()); + + mArgs.StringAt(aIndex, aResult); + return NS_OK; +} + +NS_IMETHODIMP +nsCommandLine::FindFlag(const nsAString& aFlag, PRBool aCaseSensitive, PRInt32 *aResult) +{ + NS_ENSURE_ARG(!aFlag.IsEmpty()); + + PRInt32 f; + + nsDefaultStringComparator caseCmp; + nsCaseInsensitiveStringComparator caseICmp; + nsStringComparator& c = aCaseSensitive ? + NS_STATIC_CAST(nsStringComparator&, caseCmp) : + NS_STATIC_CAST(nsStringComparator&, caseICmp); + + for (f = 0; f < mArgs.Count(); ++f) { + const nsString &arg = *mArgs[f]; + + if (arg.Length() >= 2 && arg.First() == PRUnichar('-')) { + if (aFlag.Equals(Substring(arg, 1), c)) { + *aResult = f; + return NS_OK; + } + } + } + + *aResult = -1; + return NS_OK; +} + +NS_IMETHODIMP +nsCommandLine::RemoveArguments(PRInt32 aStart, PRInt32 aEnd) +{ + NS_ENSURE_ARG_MIN(aStart, 0); + NS_ENSURE_ARG_MAX(aEnd, mArgs.Count() - 1); + + for (PRInt32 i = aEnd; i >= aStart; --i) { + mArgs.RemoveStringAt(i); + } + + return NS_OK; +} + +NS_IMETHODIMP +nsCommandLine::HandleFlag(const nsAString& aFlag, PRBool aCaseSensitive, + PRBool *aResult) +{ + nsresult rv; + + PRInt32 found; + rv = FindFlag(aFlag, aCaseSensitive, &found); + NS_ENSURE_SUCCESS(rv, rv); + + if (found == -1) { + *aResult = PR_FALSE; + return NS_OK; + } + + *aResult = PR_TRUE; + RemoveArguments(found, found); + + return NS_OK; +} + +NS_IMETHODIMP +nsCommandLine::HandleFlagWithParam(const nsAString& aFlag, PRBool aCaseSensitive, + nsAString& aResult) +{ + nsresult rv; + + PRInt32 found; + rv = FindFlag(aFlag, aCaseSensitive, &found); + NS_ENSURE_SUCCESS(rv, rv); + + if (found == -1) { + aResult.SetIsVoid(PR_TRUE); + return NS_OK; + } + + if (found == mArgs.Count() - 1) { + return NS_ERROR_INVALID_ARG; + } + + ++found; + + if (mArgs[found]->First() == '-') { + return NS_ERROR_INVALID_ARG; + } + + mArgs.StringAt(found, aResult); + RemoveArguments(found - 1, found); + + return NS_OK; +} + +NS_IMETHODIMP +nsCommandLine::GetState(PRUint32 *aResult) +{ + *aResult = mState; + return NS_OK; +} + +NS_IMETHODIMP +nsCommandLine::GetPreventDefault(PRBool *aResult) +{ + *aResult = mPreventDefault; + return NS_OK; +} + +NS_IMETHODIMP +nsCommandLine::SetPreventDefault(PRBool aValue) +{ + mPreventDefault = aValue; + return NS_OK; +} + +NS_IMETHODIMP +nsCommandLine::GetWorkingDirectory(nsIFile* *aResult) +{ + NS_ENSURE_TRUE(mWorkingDir, NS_ERROR_NOT_INITIALIZED); + + NS_ADDREF(*aResult = mWorkingDir); + return NS_OK; +} + +NS_IMETHODIMP +nsCommandLine::ResolveFile(const nsAString& aArgument, nsIFile* *aResult) +{ + NS_ENSURE_TRUE(mWorkingDir, NS_ERROR_NOT_INITIALIZED); + + // This is some seriously screwed-up code. nsILocalFile.appendRelativeNativePath + // explicitly does not accept .. or . path parts, but that is exactly what we + // need here. So we hack around it. + + nsresult rv; + +#if defined(XP_MACOSX) + nsCOMPtr lfm (do_QueryInterface(mWorkingDir)); + NS_ENSURE_TRUE(lfm, NS_ERROR_NO_INTERFACE); + + nsCOMPtr newfile (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); + NS_ENSURE_TRUE(newfile, NS_ERROR_OUT_OF_MEMORY); + + CFURLRef baseurl; + rv = lfm->GetCFURL(&baseurl); + NS_ENSURE_SUCCESS(rv, rv); + + nsCAutoString path; + NS_CopyUnicodeToNative(aArgument, path); + + CFURLRef newurl = + CFURLCreateFromFileSystemRepresentationRelativeToBase(NULL, (const UInt8*) path.get(), + path.Length(), + true, baseurl); + + CFRelease(baseurl); + + rv = newfile->InitWithCFURL(newurl); + CFRelease(newurl); + if (NS_FAILED(rv)) return rv; + + NS_ADDREF(*aResult = newfile); + return NS_OK; + +#elif defined(XP_BEOS) + nsCOMPtr lf (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); + NS_ENSURE_TRUE(lf, NS_ERROR_OUT_OF_MEMORY); + + if (aArgument.First() == '/') { + // absolute path + rv = lf->InitWithPath(aArgument); + if (NS_FAILED(rv)) return rv; + + NS_ADDREF(*aResult = lf); + return NS_OK; + } + + nsCAutoString carg; + NS_CopyUnicodeToNative(aArgument, carg); + + nsCAutoString wd; + rv = mWorkingDir->GetNativePath(wd); + NS_ENSURE_SUCCESS(rv, rv); + + BDirectory bwd(wd.get()); + + BPath resolved(bwd, carg.get(), true); + if (resolved.InitCheck() != B_OK) + return NS_ERROR_FAILURE; + + rv = lf->InitWithNativePath(BPath.Path()); + if (NS_FAILED(rv)) return rv; + + NS_ADDREF(*aResult = lf); + return NS_OK; + +#elif defined(XP_UNIX) + nsCOMPtr lf (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); + NS_ENSURE_TRUE(lf, NS_ERROR_OUT_OF_MEMORY); + + if (aArgument.First() == '/') { + // absolute path + rv = lf->InitWithPath(aArgument); + if (NS_FAILED(rv)) return rv; + + NS_ADDREF(*aResult = lf); + return NS_OK; + } + + nsCAutoString nativeArg; + NS_CopyUnicodeToNative(aArgument, nativeArg); + + nsCAutoString newpath; + mWorkingDir->GetNativePath(newpath); + + newpath.Append('/'); + newpath.Append(nativeArg); + + rv = lf->InitWithNativePath(newpath); + if (NS_FAILED(rv)) return rv; + + rv = lf->Normalize(); + if (NS_FAILED(rv)) return rv; + + NS_ADDREF(*aResult = lf); + return NS_OK; + +#elif defined(XP_WIN32) || defined(XP_OS2) + nsCOMPtr lf (do_CreateInstance(NS_LOCAL_FILE_CONTRACTID)); + NS_ENSURE_TRUE(lf, NS_ERROR_OUT_OF_MEMORY); + + rv = lf->InitWithPath(aArgument); + if (NS_FAILED(rv)) { + // If it's a relative path, the Init is *going* to fail. We use string magic and + // win32 _fullpath. Note that paths of the form "\Relative\To\CurDrive" are + // going to fail, and I haven't figured out a way to work around this without + // the PathCombine() function, which is not available in plain win95/nt4 + + nsCAutoString fullPath; + mWorkingDir->GetNativePath(fullPath); + + nsCAutoString carg; + NS_CopyUnicodeToNative(aArgument, carg); + + fullPath.Append('\\'); + fullPath.Append(carg); + + char pathBuf[MAX_PATH]; + if (!_fullpath(pathBuf, fullPath.get(), MAX_PATH)) + return NS_ERROR_FAILURE; + + rv = lf->InitWithNativePath(nsDependentCString(pathBuf)); + if (NS_FAILED(rv)) return rv; + } + NS_ADDREF(*aResult = lf); + return NS_OK; + +#else +#error Need platform-specific logic here. +#endif +} + +NS_IMETHODIMP +nsCommandLine::ResolveURI(const nsAString& aArgument, nsIURI* *aResult) +{ + nsresult rv; + + NS_ENSURE_TRUE(mWorkingDir, NS_ERROR_NOT_INITIALIZED); + + nsCOMPtr io = do_GetIOService(); + NS_ENSURE_TRUE(io, NS_ERROR_OUT_OF_MEMORY); + + // First, pretend it's a file + nsCOMPtr file; + rv = ResolveFile(aArgument, getter_AddRefs(file)); + if (NS_SUCCEEDED(rv)) { + return io->NewFileURI(file, aResult); + } + + nsCOMPtr workingDirURI; + rv = io->NewFileURI(mWorkingDir, getter_AddRefs(workingDirURI)); + NS_ENSURE_SUCCESS(rv, rv); + + return io->NewURI(NS_ConvertUTF16toUTF8(aArgument), + nsnull, + workingDirURI, + aResult); +} + +void +nsCommandLine::appendArg(const char* arg) +{ +#ifdef DEBUG_COMMANDLINE + printf("Adding XP arg: %s\n", arg); +#endif + + nsAutoString warg; + NS_CopyNativeToUnicode(nsDependentCString(arg), warg); + + mArgs.AppendString(warg); +} + +NS_IMETHODIMP +nsCommandLine::Init(PRInt32 argc, char** argv, nsIFile* aWorkingDir, + PRUint32 aState) +{ + NS_ENSURE_ARG_MIN(aState, 0); + NS_ENSURE_ARG_MAX(aState, 2); + + PRInt32 i; + + mWorkingDir = aWorkingDir; + + // skip argv[0], we don't want it + for (i = 1; i < argc; ++i) { + const char* curarg = argv[i]; + +#ifdef DEBUG_COMMANDLINE + printf("Testing native arg %i: '%s'\n", i, curarg); +#endif +#if defined(XP_WIN) || defined(XP_OS2) + if (*curarg == '/') { + char* dup = PL_strdup(curarg); + if (!dup) return NS_ERROR_OUT_OF_MEMORY; + + *dup = '-'; + char* colon = PL_strchr(dup, ':'); + if (colon) { + *colon = '\0'; + appendArg(dup); + appendArg(colon+1); + } else { + appendArg(dup); + } + PL_strfree(dup); + continue; + } +#endif +#ifdef XP_UNIX + if (*curarg == '-' && + *(curarg+1) == '-') { + ++curarg; + + char* dup = PL_strdup(curarg); + if (!dup) return NS_ERROR_OUT_OF_MEMORY; + + char* eq = PL_strchr(dup, '='); + if (eq) { + *eq = '\0'; + appendArg(dup); + appendArg(eq + 1); + } else { + appendArg(dup); + } + PL_strfree(dup); + continue; + } +#endif + + appendArg(curarg); + } + + mState = aState; + + return NS_OK; +} + +nsresult +nsCommandLine::getHandlers(nsCStringArray &handlers, nsICategoryManager* catman) +{ + nsresult rv; + + nsCOMPtr entenum; + rv = catman->EnumerateCategory("command-line-handler", + getter_AddRefs(entenum)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr strenum (do_QueryInterface(entenum)); + NS_ENSURE_TRUE(strenum, NS_ERROR_UNEXPECTED); + + nsCAutoString entry; + PRBool hasMore; + while (NS_SUCCEEDED(strenum->HasMore(&hasMore)) && hasMore) { + strenum->GetNext(entry); + handlers.AppendCString(entry); + } + + handlers.Sort(); + return NS_OK; +} + +struct RunClosure +{ + nsICommandLine* cl; + nsICategoryManager* catman; +}; + +static PRBool +EnumRun(nsCString& aEntry, void* aData) +{ + nsresult rv; + + RunClosure* closure = NS_STATIC_CAST(RunClosure*, aData); + + nsXPIDLCString value; + rv = closure->catman->GetCategoryEntry("command-line-handler", + aEntry.get(), + getter_Copies(value)); + NS_ENSURE_SUCCESS(rv, PR_TRUE); + + nsCOMPtr clh (do_GetService(value)); + NS_ENSURE_TRUE(clh, PR_TRUE); + + rv = clh->Handle(closure->cl); + return rv != NS_ERROR_ABORT; +} + +NS_IMETHODIMP +nsCommandLine::Run() +{ + nsresult rv; + + nsCOMPtr catman + (do_GetService(NS_CATEGORYMANAGER_CONTRACTID)); + NS_ENSURE_TRUE(catman, NS_ERROR_UNEXPECTED); + + nsCStringArray handlers; + rv = getHandlers(handlers, catman); + NS_ENSURE_SUCCESS(rv, rv); + + RunClosure closure = { this, catman }; + + if (!handlers.EnumerateForwards(&EnumRun, &closure)) + return NS_ERROR_ABORT; + + return NS_OK; +} + +struct HelpClosure +{ + HelpClosure(nsACString& aText, nsICategoryManager* aCatman) : + text(aText), catman(aCatman) { } + + nsACString& text; + nsICategoryManager* catman; +}; + +static PRBool +EnumHelp(nsCString& aEntry, void* aData) +{ + nsresult rv; + + HelpClosure* closure = NS_STATIC_CAST(HelpClosure*, aData); + + nsXPIDLCString value; + rv = closure->catman->GetCategoryEntry("command-line-handler", + aEntry.get(), + getter_Copies(value)); + NS_ENSURE_SUCCESS(rv, PR_TRUE); + + nsCOMPtr clh (do_GetService(value)); + NS_ENSURE_TRUE(clh, PR_TRUE); + + nsCString text; + rv = clh->GetHelpInfo(text); + if (NS_SUCCEEDED(rv)) { + NS_ASSERTION(text.Length() == 0 || text.Last() == '\n', + "Help text from command line handlers should end in a newline."); + closure->text.Append(text); + } + + return PR_TRUE; +} + +NS_IMETHODIMP +nsCommandLine::GetHelpText(nsACString& aResult) +{ + nsresult rv; + + nsCOMPtr catman + (do_GetService(NS_CATEGORYMANAGER_CONTRACTID)); + NS_ENSURE_TRUE(catman, NS_ERROR_UNEXPECTED); + + nsCStringArray handlers; + rv = getHandlers(handlers, catman); + NS_ENSURE_SUCCESS(rv, rv); + + HelpClosure closure (aResult, catman); + + handlers.EnumerateForwards(EnumHelp, &closure); + return NS_OK; +} + +NS_GENERIC_FACTORY_CONSTRUCTOR(nsCommandLine) + +static const nsModuleComponentInfo components[] = +{ + { "nsCommandLine", + { 0x23bcc750, 0xdc20, 0x460b, { 0xb2, 0xd4, 0x74, 0xd8, 0xf5, 0x8d, 0x36, 0x15 } }, + "@mozilla.org/toolkit/command-line;1", + nsCommandLineConstructor + } +}; + +NS_IMPL_NSGETMODULE(CommandLineModule, components) diff --git a/mozilla/toolkit/components/nsDefaultCLH.js b/mozilla/toolkit/components/nsDefaultCLH.js new file mode 100644 index 00000000000..cf97a6441a0 --- /dev/null +++ b/mozilla/toolkit/components/nsDefaultCLH.js @@ -0,0 +1,164 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Mozilla Firefox browser. + * + * The Initial Developer of the Original Code is + * Benjamin Smedberg + * + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +const nsISupports = Components.interfaces.nsISupporst; + +const nsICategoryManager = Components.interfaces.nsICategoryManager; +const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar; +const nsICommandLine = Components.interfaces.nsICommandLine; +const nsICommandLineHandler = Components.interfaces.nsICommandLineHandler; +const nsIFactory = Components.interfaces.nsIFactory; +const nSIModule = Components.interfaces.nsIModule; +const nsIPrefBranch = Components.interfaces.nsIPrefBranch; +const nsISupportsString = Components.interfaces.nsISupportsString; +const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher; + +/** + * This file provides a generic default command-line handler. + * + * It opens the chrome window specified by the pref "toolkit.defaultChromeURI" + * the arguments passed to the window are the nsICommandLine instance. + * + * It doesn't do anything if the pref is unset. + */ + +var nsDefaultCLH = { + /* nsISupports */ + + QueryInterface : function clh_QI(iid) { + if (iid.equals(nsICommandLineHandler) || + iid.equals(nsIFactory) || + iid.equals(nsISupports)) + return this; + + throw Components.results.NS_ERROR_NO_INTERFACE; + }, + + /* nsICommandLineHandler */ + + handle : function clh_handle(cmdLine) { + if (cmdLine.preventDefault) + return; + + var prefs = Components.classes["@mozilla.org/preferences-service;1"] + .getService(nsIPrefBranch); + + // if the pref is missing, just let the exception fall through + var chromeURI = prefs.getCharPref("toolkit.defaultChromeURI"); + + var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] + .getService(nsIWindowWatcher); + wwatch.openWindow(null, chromeURI, "_blank", + "chrome,dialog=no,all", cmdLine); + }, + + helpInfo : "", + + /* nsIFactory */ + + createInstance : function mdh_CI(outer, iid) { + if (outer != null) + throw Components.results.NS_ERROR_NO_AGGREGATION; + + return this.QueryInterface(iid); + }, + + lockFactory : function mdh_lock(lock) { + /* no-op */ + } +}; + +const clh_contractID = "@mozilla.org/toolkit/default-clh;1"; +const clh_CID = Components.ID("{6ebc941a-f2ff-4d56-b3b6-f7d0b9d73344}"); + +var Module = { + /* nsISupports */ + + QueryInterface : function mod_QI(iid) { + if (iid.equals(nsIModule) || + iid.equals(nsISupports)) + return this; + + throw Components.results.NS_ERROR_NO_INTERFACE; + }, + + /* nsIModule */ + + getClassObject : function mod_gch(compMgr, cid, iid) { + if (cid.equals(clh_CID)) + return nsDefaultCLH.QueryInterface(iid); + + throw components.results.NS_ERROR_FAILURE; + }, + + registerSelf : function mod_regself(compMgr, fileSpec, location, type) { + var compReg = compMgr.QueryInterface(nsIComponentRegistrar); + + compReg.registerFactoryLocation(clh_CID, + "nsDefaultCLH", + clh_contractID, + fileSpec, + location, + type); + + var catMan = Components.classes["@mozilla.org/categorymanager;1"] + .getService(nsICategoryManager); + + catMan.addCategoryEntry("command-line-handler", + "y-default", + clh_contractID, true, true); + }, + + unregisterSelf : function mod_unreg(compMgr, location, type) { + var compReg = compMgr.QueryInterface(nsIComponentRegistrar); + compReg.unregisterFactoryLocation(clh_CID, location); + + var catMan = Components.classes["@mozilla.org/categorymanager;1"] + .getService(nsICategoryManager); + + catMan.deleteCategoryEntry("command-line-handler", + "y-default"); + }, + + canUnload : function (compMgr) { + return true; + } +}; + +function NSGetModule(compMgr, fileSpec) { + return Module; +} diff --git a/mozilla/toolkit/components/startup/public/Makefile.in b/mozilla/toolkit/components/startup/public/Makefile.in index 343698ba23f..188f88cfbd4 100644 --- a/mozilla/toolkit/components/startup/public/Makefile.in +++ b/mozilla/toolkit/components/startup/public/Makefile.in @@ -49,8 +49,6 @@ XPIDL_MODULE = appstartup XPIDLSRCS = \ nsIAppStartup.idl \ nsICloseAllWindows.idl \ - nsICmdLineHandler.idl \ - nsICmdLineService.idl \ nsIUserInfo.idl \ $(NULL) diff --git a/mozilla/toolkit/components/startup/public/nsIAppStartup.idl b/mozilla/toolkit/components/startup/public/nsIAppStartup.idl index 993b39d92e3..16024ff78e2 100644 --- a/mozilla/toolkit/components/startup/public/nsIAppStartup.idl +++ b/mozilla/toolkit/components/startup/public/nsIAppStartup.idl @@ -21,6 +21,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * Benjamin Smedberg * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -40,7 +41,7 @@ interface nsICmdLineService; -[scriptable, uuid(7877c9eb-ec6c-4214-9b59-48ee78f09eb9)] +[scriptable, uuid(e9b0f89b-0529-4d96-98a8-eb5b2b9a8383)] interface nsIAppStartup : nsISupports { /** @@ -73,23 +74,4 @@ interface nsIAppStartup : nsISupports * Exit the event loop, shut down the app */ void quit(in PRUint32 aFerocity); - - /** - * Creates the initial state of the application by launching tasks - * specfied by "general.startup.*" prefs. - * @param aWindowWidth the width to make the initial window(s) opened - * @param aWindowHeight the height to make the initial window(s) opened - * @note SIZE_TO_CONTENT may be used for width or height. - * @return TRUE if a window was opened - */ - boolean createStartupState(in long aWindowWidth, in long aWindowHeight); - - /** - * Ensures that at least one window exists after creating the startup state. - * If one has not been made, this will create a browser window. - * - * @param aCmdLineService the command line from which startup args - * can be read. - */ - void ensure1Window(in nsICmdLineService aCmdLineService); }; diff --git a/mozilla/toolkit/components/startup/src/Makefile.in b/mozilla/toolkit/components/startup/src/Makefile.in index 7bcdd2d28c7..1812a368b61 100644 --- a/mozilla/toolkit/components/startup/src/Makefile.in +++ b/mozilla/toolkit/components/startup/src/Makefile.in @@ -69,7 +69,6 @@ REQUIRES = \ CPPSRCS = \ nsAppStartup.cpp \ - nsCommandLineService.cpp \ $(NULL) ifeq (os2,$(MOZ_WIDGET_TOOLKIT)) diff --git a/mozilla/toolkit/components/startup/src/nsAppStartup.cpp b/mozilla/toolkit/components/startup/src/nsAppStartup.cpp index f9ccd4c5766..289441d1e32 100644 --- a/mozilla/toolkit/components/startup/src/nsAppStartup.cpp +++ b/mozilla/toolkit/components/startup/src/nsAppStartup.cpp @@ -105,7 +105,6 @@ nsAppStartup::Init() os->AddObserver(this, "nsIEventQueueActivated", PR_TRUE); os->AddObserver(this, "nsIEventQueueDestroyed", PR_TRUE); os->AddObserver(this, "profile-change-teardown", PR_TRUE); - os->AddObserver(this, "profile-initial-state", PR_TRUE); os->AddObserver(this, "xul-window-registered", PR_TRUE); os->AddObserver(this, "xul-window-destroyed", PR_TRUE); @@ -357,101 +356,6 @@ nsAppStartup::ExitLastWindowClosingSurvivalArea(void) } -NS_IMETHODIMP -nsAppStartup::CreateStartupState(PRInt32 aWindowWidth, PRInt32 aWindowHeight, - PRBool *_retval) -{ - NS_ENSURE_ARG_POINTER(_retval); - nsresult rv; - -#ifndef MOZ_THUNDERBIRD // xxxbsmedberg: more ifdef badness! - nsCOMPtr prefService(do_GetService(NS_PREFSERVICE_CONTRACTID)); - if (!prefService) - return NS_ERROR_FAILURE; - nsCOMPtr startupBranch; - prefService->GetBranch(PREF_STARTUP_PREFIX, getter_AddRefs(startupBranch)); - if (!startupBranch) - return NS_ERROR_FAILURE; - - PRUint32 childCount; - char **childArray = nsnull; - rv = startupBranch->GetChildList("", &childCount, &childArray); - if (NS_FAILED(rv)) - return rv; - - for (PRUint32 i = 0; i < childCount; i++) { - PRBool prefValue; - startupBranch->GetBoolPref(childArray[i], &prefValue); - if (prefValue) { - PRBool windowOpened; - rv = LaunchTask(childArray[i], aWindowHeight, aWindowWidth, &windowOpened); - if (NS_SUCCEEDED(rv) && windowOpened) - *_retval = PR_TRUE; - } - } - - NS_FREE_XPCOM_ALLOCATED_POINTER_ARRAY(childCount, childArray); -#else - PRBool windowOpened; - rv = LaunchTask("mail", aWindowHeight, aWindowWidth, &windowOpened); - if (NS_SUCCEEDED(rv) && windowOpened) - *_retval = PR_TRUE; - else - *_retval = PR_FALSE; -#endif - - return NS_OK; -} - - -NS_IMETHODIMP -nsAppStartup::Ensure1Window(nsICmdLineService *aCmdLineService) -{ - nsresult rv; - - nsCOMPtr windowMediator - (do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv)); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr windowEnumerator; - if (NS_SUCCEEDED(windowMediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator)))) - { - PRBool more; - windowEnumerator->HasMoreElements(&more); - if (!more) - { - // No window exists so lets create a browser one - PRInt32 height = nsIAppShellService::SIZE_TO_CONTENT; - PRInt32 width = nsIAppShellService::SIZE_TO_CONTENT; - - // Get the value of -width option - nsXPIDLCString tempString; - rv = aCmdLineService->GetCmdLineValue("-width", getter_Copies(tempString)); - if (NS_SUCCEEDED(rv) && !tempString.IsEmpty()) - PR_sscanf(tempString.get(), "%d", &width); - - - // Get the value of -height option - rv = aCmdLineService->GetCmdLineValue("-height", getter_Copies(tempString)); - if (NS_SUCCEEDED(rv) && !tempString.IsEmpty()) - PR_sscanf(tempString.get(), "%d", &height); - -#ifdef MOZ_THUNDERBIRD // XXXbsmedberg more badness, needs NVU thought - PRBool windowOpened = PR_FALSE; - - rv = LaunchTask(NULL, height, width, &windowOpened); - - if (NS_FAILED(rv) || !windowOpened) - rv = LaunchTask("mail", height, width, &windowOpened); -#else - rv = OpenBrowserWindow(height, width); -#endif - } - } - return rv; -} - - void* PR_CALLBACK nsAppStartup::HandleExitEvent(PLEvent* aEvent) { @@ -477,150 +381,6 @@ nsAppStartup::DestroyExitEvent(PLEvent* aEvent) } -nsresult -nsAppStartup::LaunchTask(const char *aParam, PRInt32 height, PRInt32 width, PRBool *windowOpened) -{ - nsresult rv = NS_OK; - - nsCOMPtr cmdLine = - do_GetService(NS_COMMANDLINESERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr handler; - rv = cmdLine->GetHandlerForParam(aParam, getter_AddRefs(handler)); - if (NS_FAILED(rv)) return rv; - - nsXPIDLCString chromeUrlForTask; - rv = handler->GetChromeUrlForTask(getter_Copies(chromeUrlForTask)); - if (NS_FAILED(rv)) return rv; - - PRBool handlesArgs = PR_FALSE; - rv = handler->GetHandlesArgs(&handlesArgs); - if (handlesArgs) { -#ifndef MOZ_THUNDERBIRD //XXXbsmedberg bad toolkit->app dependency! - nsXPIDLString defaultArgs; - rv = handler->GetDefaultArgs(getter_Copies(defaultArgs)); - if (NS_FAILED(rv)) return rv; - rv = OpenWindow(chromeUrlForTask, defaultArgs, - nsIAppShellService::SIZE_TO_CONTENT, - nsIAppShellService::SIZE_TO_CONTENT); -#else - // XXX horibble thunderbird hack. Don't pass in the default args if the - // cmd line service says we have real arguments! Use those instead. - nsXPIDLCString args; - nsXPIDLCString cmdLineArgument; // -mail, -compose, etc. - rv = handler->GetCommandLineArgument(getter_Copies(cmdLineArgument)); - if (NS_SUCCEEDED(rv)) { - rv = cmdLine->GetCmdLineValue(cmdLineArgument, getter_Copies(args)); - if (NS_SUCCEEDED(rv) && args.get() && strcmp(args.get(), "1")) { - nsAutoString cmdArgs; cmdArgs.AssignWithConversion(args); - rv = OpenWindow(chromeUrlForTask, cmdArgs, height, width); - } - else - rv = NS_ERROR_FAILURE; - } - - // any failure case, do what we used to do: - if (NS_FAILED(rv)) { - nsXPIDLString defaultArgs; - rv = handler->GetDefaultArgs(getter_Copies(defaultArgs)); - if (NS_FAILED(rv)) return rv; - rv = OpenWindow(chromeUrlForTask, defaultArgs, - nsIAppShellService::SIZE_TO_CONTENT, nsIAppShellService::SIZE_TO_CONTENT); - } -#endif - } - else { - rv = OpenWindow(chromeUrlForTask, EmptyString(), width, height); - } - - // If we get here without an error, then a window was opened OK. - if (NS_SUCCEEDED(rv)) { - *windowOpened = PR_TRUE; - } - - return rv; -} - -nsresult -nsAppStartup::OpenWindow(const nsAFlatCString& aChromeURL, - const nsAFlatString& aAppArgs, - PRInt32 aWidth, PRInt32 aHeight) -{ - nsCOMPtr wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)); - nsCOMPtr sarg(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID)); - if (!wwatch || !sarg) - return NS_ERROR_FAILURE; - - sarg->SetData(aAppArgs); - - nsCAutoString features("chrome,dialog=no,all"); - if (aHeight != nsIAppShellService::SIZE_TO_CONTENT) { - features.Append(",height="); - features.AppendInt(aHeight); - } - if (aWidth != nsIAppShellService::SIZE_TO_CONTENT) { - features.Append(",width="); - features.AppendInt(aWidth); - } - - nsCOMPtr newWindow; - return wwatch->OpenWindow(0, aChromeURL.get(), "_blank", - features.get(), sarg, - getter_AddRefs(newWindow)); -} - - -nsresult -nsAppStartup::OpenBrowserWindow(PRInt32 height, PRInt32 width) -{ - nsresult rv; - nsCOMPtr handler(do_GetService("@mozilla.org/commandlinehandler/general-startup;1?type=browser", &rv)); - if (NS_FAILED(rv)) return rv; - - nsXPIDLCString chromeUrlForTask; - rv = handler->GetChromeUrlForTask(getter_Copies(chromeUrlForTask)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr cmdLine = do_GetService(NS_COMMANDLINESERVICE_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - - nsXPIDLCString urlToLoad; - rv = cmdLine->GetURLToLoad(getter_Copies(urlToLoad)); - if (NS_FAILED(rv)) return rv; - - if (!urlToLoad.IsEmpty()) { - -#ifdef DEBUG_CMD_LINE - printf("url to load: %s\n", urlToLoad.get()); -#endif /* DEBUG_CMD_LINE */ - - nsAutoString url; - // convert the cmdLine URL to Unicode - rv = NS_CopyNativeToUnicode(nsDependentCString(urlToLoad), url); - if (NS_FAILED(rv)) { - NS_ERROR("Failed to convert commandline url to unicode"); - return rv; - } - rv = OpenWindow(chromeUrlForTask, url, width, height); - - } else { - - nsXPIDLString defaultArgs; - rv = handler->GetDefaultArgs(getter_Copies(defaultArgs)); - if (NS_FAILED(rv)) return rv; - -#ifdef DEBUG_CMD_LINE - printf("default args: %s\n", NS_ConvertUCS2toUTF8(defaultArgs).get()); -#endif /* DEBUG_CMD_LINE */ - - rv = OpenWindow(chromeUrlForTask, defaultArgs, width, height); - } - - return rv; -} - - // // nsAppStartup->nsIWindowCreator // @@ -735,16 +495,6 @@ nsAppStartup::Observe(nsISupports *aSubject, changeStatus->VetoChange(); } ExitLastWindowClosingSurvivalArea(); - } else if (!strcmp(aTopic, "profile-initial-state")) { - if (nsDependentString(aData).Equals(NS_LITERAL_STRING("switch"))) { - // Now, establish the startup state according to the new prefs. - PRBool openedWindow; - CreateStartupState(nsIAppShellService::SIZE_TO_CONTENT, - nsIAppShellService::SIZE_TO_CONTENT, &openedWindow); - if (!openedWindow) - OpenBrowserWindow(nsIAppShellService::SIZE_TO_CONTENT, - nsIAppShellService::SIZE_TO_CONTENT); - } } else if (!strcmp(aTopic, "xul-window-registered")) { AttemptingQuit(PR_FALSE); } else if (!strcmp(aTopic, "xul-window-destroyed")) { diff --git a/mozilla/toolkit/components/startup/src/nsAppStartup.h b/mozilla/toolkit/components/startup/src/nsAppStartup.h index c6e0d0f2173..b6f62739a51 100644 --- a/mozilla/toolkit/components/startup/src/nsAppStartup.h +++ b/mozilla/toolkit/components/startup/src/nsAppStartup.h @@ -45,7 +45,6 @@ #include "nsIObserver.h" #include "nsWeakReference.h" -#include "nsICmdLineService.h" #include "nsINativeAppSupport.h" #include "nsIAppShell.h" @@ -80,14 +79,6 @@ private: PR_STATIC_CALLBACK(void*) HandleExitEvent(PLEvent* aEvent); PR_STATIC_CALLBACK(void) DestroyExitEvent(PLEvent* aEvent); - nsresult LaunchTask(const char* aParam, - PRInt32 height, PRInt32 width, - PRBool *windowOpened); - nsresult OpenWindow(const nsAFlatCString& aChromeURL, - const nsAFlatString& aAppArgs, - PRInt32 aWidth, PRInt32 aHeight); - nsresult OpenBrowserWindow(PRInt32 height, PRInt32 width); - nsCOMPtr mAppShell; PRInt32 mConsiderQuitStopper; // if > 0, Quit(eConsiderQuit) fails diff --git a/mozilla/toolkit/mozapps/extensions/public/nsIExtensionManager.idl b/mozilla/toolkit/mozapps/extensions/public/nsIExtensionManager.idl index 758311225e2..1126ba1b93e 100644 --- a/mozilla/toolkit/mozapps/extensions/public/nsIExtensionManager.idl +++ b/mozilla/toolkit/mozapps/extensions/public/nsIExtensionManager.idl @@ -41,6 +41,7 @@ interface nsIFile; interface nsIRDFDataSource; interface nsIUpdateItem; +interface nsICommandLine; [scriptable, uuid(9048223f-ec50-49e5-9866-80ee8f26179d)] interface nsIExtensionDownloadProgressListener : nsISupports @@ -50,18 +51,18 @@ interface nsIExtensionDownloadProgressListener : nsISupports void onProgress(in wstring aURL, in unsigned long aValue, in unsigned long aMaxValue); }; -[scriptable, uuid(c3515b0f-99f4-453b-805e-1fdf5724d6d9)] +[scriptable, uuid(1a1e274d-c675-4177-99d3-4d153d1b795e)] interface nsIExtensionManager : nsISupports { // Apprunner hooks - boolean start(in boolean aIsDirty); + boolean start(in nsICommandLine aCmdLine, in boolean aIsDirty); /** * Returns true if mismatches were found and the app needs to restart. */ boolean checkForMismatches(); - void handleCommandLineArgs(); + void handleCommandLineArgs(in nsICommandLine cmdline); void register(); diff --git a/mozilla/toolkit/mozapps/extensions/src/nsExtensionManager.js.in b/mozilla/toolkit/mozapps/extensions/src/nsExtensionManager.js.in index 8f6d8de676d..ea20c9d1774 100644 --- a/mozilla/toolkit/mozapps/extensions/src/nsExtensionManager.js.in +++ b/mozilla/toolkit/mozapps/extensions/src/nsExtensionManager.js.in @@ -1594,7 +1594,7 @@ nsExtensionManager.prototype = { } }, - start: function nsExtensionManager_start (aIsDirty) + start: function nsExtensionManager_start (aCmdLine, aIsDirty) { this._started = true; @@ -1614,10 +1614,8 @@ nsExtensionManager.prototype = { // cases to see what is stopping these dirs from being removed, but no // time now. this._cleanDirs(); - - var cmdLineSvc = Components.classes["@mozilla.org/app-startup/commandLineService;1"] - .getService(Components.interfaces.nsICmdLineService); - var safeMode = cmdLineSvc.getCmdLineValue("-safe-mode") != null; + + var safeMode = aCmdLine.handleFlag("safe-mode", false); if (!safeMode) { var wasInSafeModeFile = getFile(KEY_PROFILEDIR, [DIR_EXTENSIONS, FILE_WASINSAFEMODE]); if (wasInSafeModeFile.exists()) { @@ -1709,32 +1707,49 @@ nsExtensionManager.prototype = { return needsRestart; }, - handleCommandLineArgs: function nsExtensionManager_handleCommandLineArgs () + handleCommandLineArgs: function nsExtensionManager_handleCommandLineArgs (aCmdLine) { - var cmdLineSvc = Components.classes["@mozilla.org/app-startup/commandLineService;1"] - .getService(Components.interfaces.nsICmdLineService); - var globalExtension = cmdLineSvc.getCmdLineValue("-install-global-extension"); - if (globalExtension) - this._checkForGlobalInstalls(globalExtension, nsIUpdateItem.TYPE_EXTENSION); - - var globalTheme = cmdLineSvc.getCmdLineValue("-install-global-theme"); - if (globalTheme) - this._checkForGlobalInstalls(globalTheme, nsIUpdateItem.TYPE_THEME); - - var showList = cmdLineSvc.getCmdLineValue("-list-global-items"); - if (showList) - this._showGlobalItemList(); - - var locked = cmdLineSvc.getCmdLineValue("-lock-item"); - if (locked) { - this._ensureDS(); - this._ds.lockUnlockItem(locked, true); + try { + var globalExtension = aCmdLine.handleFlagWithParam("install-global-extension", false); + if (globalExtension) + this._checkForGlobalInstalls(globalExtension, nsIUpdateItem.TYPE_EXTENSION); + } + catch (e) { + // The command line had the flag, but no param. XXXReport this error! } - var unlocked = cmdLineSvc.getCmdLineValue("-unlock-item"); - if (unlocked) { - this._ensureDS(); - this._ds.lockUnlockItem(unlocked, false); + try { + var globalTheme = aCmdLine.handleFlagWithParam("install-global-theme", false); + if (globalTheme) + this._checkForGlobalInstalls(globalTheme, nsIUpdateItem.TYPE_THEME); + } + catch (e) { + // The command line had the flag, but no param. XXXReport this error! + } + + if (aCmdLine.handleFlag("list-global-items", false)) + this._showGlobalItemList(); + + try { + var locked = aCmdLine.handleFlagWithParam("lock-item", false); + if (locked) { + this._ensureDS(); + this._ds.lockUnlockItem(locked, true); + } + } + catch (e) { + // The command line had the flag, but no param. XXXReport this error! + } + + try { + var unlocked = aCmdLine.handleFlagWithParam("unlock-item", false); + if (unlocked) { + this._ensureDS(); + this._ds.lockUnlockItem(unlocked, false); + } + } + catch (e) { + // The command line had the flag, but no param. XXXReport this error! } this._finishOperations(); diff --git a/mozilla/toolkit/xre/Makefile.in b/mozilla/toolkit/xre/Makefile.in index c80d6be8d58..3805f898fd7 100644 --- a/mozilla/toolkit/xre/Makefile.in +++ b/mozilla/toolkit/xre/Makefile.in @@ -48,6 +48,7 @@ EXPORT_LIBRARY = 1 REQUIRES = \ appcomps \ + toolkitcomps \ appshell \ appstartup \ content \ diff --git a/mozilla/toolkit/xre/nsAppRunner.cpp b/mozilla/toolkit/xre/nsAppRunner.cpp index 0fb58ff7b7e..444ff83b89c 100644 --- a/mozilla/toolkit/xre/nsAppRunner.cpp +++ b/mozilla/toolkit/xre/nsAppRunner.cpp @@ -62,8 +62,7 @@ #include "nsIArray.h" #include "nsICategoryManager.h" #include "nsIChromeRegistry.h" -#include "nsICmdLineHandler.h" -#include "nsICmdLineService.h" +#include "nsICommandLineRunner.h" #include "nsIComponentManager.h" #include "nsIComponentRegistrar.h" #include "nsIContentHandler.h" @@ -88,6 +87,8 @@ #include "nsCRT.h" #include "nsCOMPtr.h" +#include "nsDirectoryServiceDefs.h" +#include "nsDirectoryServiceUtils.h" #include "nsNetUtil.h" #include "nsXPCOM.h" #include "nsXPIDLString.h" @@ -140,10 +141,6 @@ #include #endif -#if defined(DEBUG_pra) -#define DEBUG_CMD_LINE -#endif - extern "C" void ShowOSAlert(const char* aMessage); #define HELP_SPACER_1 "\t" @@ -331,6 +328,15 @@ enum ArgResult { ARG_BAD = 2 // you wanted a param, but there isn't one }; +static void RemoveArg(char **argv) +{ + do { + *argv = *(++argv); + } while (*argv); + + --gArgc; +} + /** * Check for a commandline flag. If the flag takes a parameter, the * parameter is returned in aParam. Flags may be in the form -arg or @@ -358,9 +364,12 @@ CheckArg(const char* aArg, const char **aParam = nsnull) ++arg; if (strimatch(aArg, arg)) { - if (!aParam) return ARG_FOUND; + RemoveArg(curarg); + if (!aParam) { + return ARG_FOUND; + } - if (*(++curarg)) { + if (*curarg) { if (**curarg == '-' #if defined(XP_WIN) || defined(XP_OS2) || **curarg == '/' @@ -369,6 +378,7 @@ CheckArg(const char* aArg, const char **aParam = nsnull) return ARG_BAD; *aParam = *curarg; + RemoveArg(curarg); return ARG_FOUND; } return ARG_BAD; @@ -381,380 +391,6 @@ CheckArg(const char* aArg, const char **aParam = nsnull) return ARG_NONE; } -static nsresult OpenWindow(const nsAFlatCString& aChromeURL, - const nsAFlatString& aAppArgs, - PRInt32 aWidth, PRInt32 aHeight); - -static nsresult OpenWindow(const nsAFlatCString& aChromeURL, - const nsAFlatString& aAppArgs) -{ - return OpenWindow(aChromeURL, aAppArgs, - nsIAppShellService::SIZE_TO_CONTENT, - nsIAppShellService::SIZE_TO_CONTENT); -} - -static nsresult OpenWindow(const nsAFlatCString& aChromeURL, - PRInt32 aWidth, PRInt32 aHeight) -{ - return OpenWindow(aChromeURL, EmptyString(), aWidth, aHeight); -} - -static nsresult OpenWindow(const nsAFlatCString& aChromeURL, - const nsAFlatString& aAppArgs, - PRInt32 aWidth, PRInt32 aHeight) -{ - -#ifdef DEBUG_CMD_LINE - printf("OpenWindow(%s, %s, %d, %d)\n", aChromeURL.get(), - NS_ConvertUCS2toUTF8(aAppArgs).get(), - aWidth, aHeight); -#endif /* DEBUG_CMD_LINE */ - - nsCOMPtr wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)); - nsCOMPtr sarg(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID)); - if (!wwatch || !sarg) - return NS_ERROR_FAILURE; - - sarg->SetData(aAppArgs); - - nsCAutoString features("chrome,dialog=no,all"); - if (aHeight != nsIAppShellService::SIZE_TO_CONTENT) { - features.Append(",height="); - features.AppendInt(aHeight); - } - if (aWidth != nsIAppShellService::SIZE_TO_CONTENT) { - features.Append(",width="); - features.AppendInt(aWidth); - } - -#ifdef DEBUG_CMD_LINE - printf("features: %s...\n", features.get()); -#endif /* DEBUG_CMD_LINE */ - - nsCOMPtr newWindow; - return wwatch->OpenWindow(0, aChromeURL.get(), "_blank", - features.get(), sarg, - getter_AddRefs(newWindow)); -} - -static void DumpArbitraryHelp() -{ - nsresult rv; - nsCOMPtr catman(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv)); - if(NS_SUCCEEDED(rv) && catman) { - nsCOMPtr e; - rv = catman->EnumerateCategory(COMMAND_LINE_ARGUMENT_HANDLERS, getter_AddRefs(e)); - if(NS_SUCCEEDED(rv) && e) { - while (PR_TRUE) { - nsCOMPtr catEntry; - rv = e->GetNext(getter_AddRefs(catEntry)); - if (NS_FAILED(rv) || !catEntry) break; - - nsCAutoString entryString; - rv = catEntry->GetData(entryString); - if (NS_FAILED(rv) || entryString.IsEmpty()) break; - - nsXPIDLCString contractidString; - rv = catman->GetCategoryEntry(COMMAND_LINE_ARGUMENT_HANDLERS, - entryString.get(), - getter_Copies(contractidString)); - if (NS_FAILED(rv) || !((const char *)contractidString)) break; - -#ifdef DEBUG_CMD_LINE - printf("cmd line handler contractid = %s\n", (const char *)contractidString); -#endif /* DEBUG_CMD_LINE */ - - nsCOMPtr handler(do_GetService((const char *)contractidString, &rv)); - - if (handler) { - nsXPIDLCString commandLineArg; - rv = handler->GetCommandLineArgument(getter_Copies(commandLineArg)); - if (NS_FAILED(rv)) continue; - - nsXPIDLCString helpText; - rv = handler->GetHelpText(getter_Copies(helpText)); - if (NS_FAILED(rv)) continue; - - if ((const char *)commandLineArg) { - printf("%s%s", HELP_SPACER_1,(const char *)commandLineArg); - - PRBool handlesArgs = PR_FALSE; - rv = handler->GetHandlesArgs(&handlesArgs); - if (NS_SUCCEEDED(rv) && handlesArgs) { - printf(" "); - } - if ((const char *)helpText) { - printf("%s%s\n",HELP_SPACER_2,(const char *)helpText); - } - } - } - - } - } - } - return; -} - -static nsresult -LaunchApplicationWithArgs(const char *commandLineArg, - nsICmdLineService *cmdLineArgs, - const char *aParam, - PRInt32 height, PRInt32 width, PRBool *windowOpened) -{ - NS_ENSURE_ARG(commandLineArg); - NS_ENSURE_ARG(cmdLineArgs); - NS_ENSURE_ARG(aParam); - NS_ENSURE_ARG(windowOpened); - - nsresult rv; - - nsCOMPtr cmdLine = - do_GetService("@mozilla.org/app-startup/commandLineService;1",&rv); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr handler; - rv = cmdLine->GetHandlerForParam(aParam, getter_AddRefs(handler)); - if (NS_FAILED(rv)) return rv; - - if (!handler) return NS_ERROR_FAILURE; - - nsXPIDLCString chromeUrlForTask; - rv = handler->GetChromeUrlForTask(getter_Copies(chromeUrlForTask)); - if (NS_FAILED(rv)) return rv; - -#ifdef DEBUG_CMD_LINE - printf("XXX got this one:\t%s\n\t%s\n\n",commandLineArg,(const char *)chromeUrlForTask); -#endif /* DEBUG_CMD_LINE */ - - nsXPIDLCString cmdResult; - rv = cmdLineArgs->GetCmdLineValue(commandLineArg, getter_Copies(cmdResult)); - if (NS_FAILED(rv)) return rv; -#ifdef DEBUG_CMD_LINE - printf("%s, cmdResult = %s\n",commandLineArg,(const char *)cmdResult); -#endif /* DEBUG_CMD_LINE */ - - PRBool handlesArgs = PR_FALSE; - rv = handler->GetHandlesArgs(&handlesArgs); - if (handlesArgs) { - if ((const char *)cmdResult) { - if (PL_strcmp("1",(const char *)cmdResult)) { - PRBool openWindowWithArgs = PR_TRUE; - rv = handler->GetOpenWindowWithArgs(&openWindowWithArgs); - if (NS_FAILED(rv)) return rv; - - if (openWindowWithArgs) { - nsAutoString cmdArgs; cmdArgs.AssignWithConversion(cmdResult); -#ifdef DEBUG_CMD_LINE - printf("opening %s with %s\n", chromeUrlForTask.get(), "OpenWindow"); -#endif /* DEBUG_CMD_LINE */ - rv = OpenWindow(chromeUrlForTask, cmdArgs); - } - else { -#ifdef DEBUG_CMD_LINE - printf("opening %s with %s\n", cmdResult.get(), "OpenWindow"); -#endif /* DEBUG_CMD_LINE */ - rv = OpenWindow(cmdResult, width, height); - if (NS_FAILED(rv)) return rv; - } - // If we get here without an error, then a window was opened OK. - if (NS_SUCCEEDED(rv)) { - *windowOpened = PR_TRUE; - } - } - else { - nsXPIDLString defaultArgs; - rv = handler->GetDefaultArgs(getter_Copies(defaultArgs)); - if (NS_FAILED(rv)) return rv; - - rv = OpenWindow(chromeUrlForTask, defaultArgs); - if (NS_FAILED(rv)) return rv; - // Window was opened OK. - *windowOpened = PR_TRUE; - } - } - } - else { - if (NS_SUCCEEDED(rv) && (const char*)cmdResult) { - if (PL_strcmp("1",cmdResult) == 0) { - rv = OpenWindow(chromeUrlForTask, width, height); - if (NS_FAILED(rv)) return rv; - } - else { - rv = OpenWindow(cmdResult, width, height); - if (NS_FAILED(rv)) return rv; - } - // If we get here without an error, then a window was opened OK. - if (NS_SUCCEEDED(rv)) { - *windowOpened = PR_TRUE; - } - } - } - - return NS_OK; -} - -static PRBool IsStartupCommand(const char *arg) -{ - if (!arg) return PR_FALSE; - - if (PL_strlen(arg) <= 1) return PR_FALSE; - - // windows allows /mail or -mail - if ((arg[0] == '-') -#if defined(XP_WIN) || defined(XP_OS2) - || (arg[0] == '/') -#endif /* XP_WIN || XP_OS2 */ - ) { - return PR_TRUE; - } - - return PR_FALSE; -} - - -// This should be done by app shell enumeration someday -nsresult -DoCommandLines(nsICmdLineService* cmdLineArgs, PRBool heedGeneralStartupPrefs, PRBool *windowOpened) -{ - NS_ENSURE_ARG(windowOpened); - *windowOpened = PR_FALSE; - - nsresult rv; - - PRInt32 height = nsIAppShellService::SIZE_TO_CONTENT; - PRInt32 width = nsIAppShellService::SIZE_TO_CONTENT; - nsXPIDLCString tempString; - - // Get the value of -width option - rv = cmdLineArgs->GetCmdLineValue("-width", getter_Copies(tempString)); - if (NS_SUCCEEDED(rv) && !tempString.IsEmpty()) - PR_sscanf(tempString.get(), "%d", &width); - - // Get the value of -height option - rv = cmdLineArgs->GetCmdLineValue("-height", getter_Copies(tempString)); - if (NS_SUCCEEDED(rv) && !tempString.IsEmpty()) - PR_sscanf(tempString.get(), "%d", &height); - - if (heedGeneralStartupPrefs) { - nsCOMPtr appStartup - (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv)); - NS_ENSURE_SUCCESS(rv, rv); - rv = appStartup->CreateStartupState(width, height, windowOpened); - NS_ENSURE_SUCCESS(rv, rv); - } - else { - PRInt32 argc = 0; - rv = cmdLineArgs->GetArgc(&argc); - if (NS_FAILED(rv)) return rv; - - char **argv = nsnull; - rv = cmdLineArgs->GetArgv(&argv); - if (NS_FAILED(rv)) return rv; - - PRInt32 i = 0; - for (i=1;i%sSet height of startup window to .\n",HELP_SPACER_1,HELP_SPACER_2); - printf("%s-h or -help%sPrint this message.\n",HELP_SPACER_1,HELP_SPACER_2); - printf("%s-width %sSet width of startup window to .\n",HELP_SPACER_1,HELP_SPACER_2); - printf("%s-v or -version%sPrint %s version.\n",HELP_SPACER_1,HELP_SPACER_2, gAppData->appName); - printf("%s-P %sStart with .\n",HELP_SPACER_1,HELP_SPACER_2); - printf("%s-ProfileManager%sStart with profile manager.\n",HELP_SPACER_1,HELP_SPACER_2); - printf("%s-UILocale %sStart with resources as UI Locale.\n",HELP_SPACER_1,HELP_SPACER_2); - printf("%s-contentLocale %sStart with resources as content Locale.\n",HELP_SPACER_1,HELP_SPACER_2); -#ifdef XP_WIN - printf("%s-console%sStart Mozilla with a debugging console.\n",HELP_SPACER_1,HELP_SPACER_2); -#endif -#ifdef MOZ_ENABLE_XREMOTE - printf("%s-remote %sExecute in an already running\n" - "%sMozilla process. For more info, see:\n" - "\n%shttp://www.mozilla.org/unix/remote.html\n\n", - HELP_SPACER_1,HELP_SPACER_1,HELP_SPACER_4,HELP_SPACER_2); -#endif - - // this works, but only after the components have registered. so if you drop in a new command line handler, -help - // won't not until the second run. - // out of the bug, because we ship a component.reg file, it works correctly. - DumpArbitraryHelp(); -} - /** * The nsXULAppInfo object implements nsIFactory so that it can be its own * singleton. @@ -1036,20 +672,6 @@ ScopedXPCOMStartup::SetWindowCreator(nsINativeAppSupport* native) nativeFactory); NS_ENSURE_SUCCESS(rv, rv); - // Initialize the cmd line service - nsCOMPtr cmdLineArgs - (do_GetService("@mozilla.org/app-startup/commandLineService;1")); - NS_ENSURE_TRUE(cmdLineArgs, NS_ERROR_FAILURE); - - rv = cmdLineArgs->Initialize(gArgc, gArgv); - - if (NS_FAILED(rv)) { - if (rv == NS_ERROR_INVALID_ARG) - DumpHelp(); - - return rv; - } - nsCOMPtr creator (do_GetService(NS_APPSTARTUP_CONTRACTID)); if (!creator) return NS_ERROR_UNEXPECTED; @@ -1060,6 +682,104 @@ ScopedXPCOMStartup::SetWindowCreator(nsINativeAppSupport* native) return wwatch->SetWindowCreator(creator); } +static void DumpArbitraryHelp() +{ + nsresult rv; + + nsXREDirProvider dirProvider; + dirProvider.Initialize(nsnull); + + ScopedXPCOMStartup xpcom; + xpcom.Initialize(); + xpcom.DoAutoreg(); + + nsCOMPtr cmdline + (do_CreateInstance("@mozilla.org/toolkit/command-line;1")); + if (!cmdline) + return; + + nsCString text; + rv = cmdline->GetHelpText(text); + if (NS_SUCCEEDED(rv)) + printf("%s", text.get()); +} + +// English text needs to go into a dtd file. +// But when this is called we have no components etc. These strings must either be +// here, or in a native resource file. +static void +DumpHelp() +{ + printf("Usage: %s [ options ... ] [URL]\n", gArgv[0]); + printf(" where options include:\n"); + printf("\n"); + +#ifdef MOZ_WIDGET_GTK + /* insert gtk options above moz options, like any other gtk app + * + * note: this isn't a very cool way to do things -- i'd rather get + * these straight from a user's gtk version -- but it seems to be + * what most gtk apps do. -dr + */ + + printf("GTK options\n"); + printf("%s--gdk-debug=FLAGS%sGdk debugging flags to set\n", HELP_SPACER_1, HELP_SPACER_2); + printf("%s--gdk-no-debug=FLAGS%sGdk debugging flags to unset\n", HELP_SPACER_1, HELP_SPACER_2); + printf("%s--gtk-debug=FLAGS%sGtk+ debugging flags to set\n", HELP_SPACER_1, HELP_SPACER_2); + printf("%s--gtk-no-debug=FLAGS%sGtk+ debugging flags to unset\n", HELP_SPACER_1, HELP_SPACER_2); + printf("%s--gtk-module=MODULE%sLoad an additional Gtk module\n", HELP_SPACER_1, HELP_SPACER_2); + printf("%s-install%sInstall a private colormap\n", HELP_SPACER_1, HELP_SPACER_2); + + /* end gtk toolkit options */ +#endif /* MOZ_WIDGET_GTK */ +#if MOZ_WIDGET_XLIB + printf("Xlib options\n"); + printf("%s-display=DISPLAY%sX display to use\n", HELP_SPACER_1, HELP_SPACER_2); + printf("%s-visual=VISUALID%sX visual to use\n", HELP_SPACER_1, HELP_SPACER_2); + printf("%s-install_colormap%sInstall own colormap\n", HELP_SPACER_1, HELP_SPACER_2); + printf("%s-sync%sMake X calls synchronous\n", HELP_SPACER_1, HELP_SPACER_2); + printf("%s-no-xshm%sDon't use X shared memory extension\n", HELP_SPACER_1, HELP_SPACER_2); + + /* end xlib toolkit options */ +#endif /* MOZ_WIDGET_XLIB */ +#ifdef MOZ_X11 + printf("X11 options\n"); + printf("%s--display=DISPLAY%sX display to use\n", HELP_SPACER_1, HELP_SPACER_2); + printf("%s--sync%sMake X calls synchronous\n", HELP_SPACER_1, HELP_SPACER_2); + printf("%s--no-xshm%sDon't use X shared memory extension\n", HELP_SPACER_1, HELP_SPACER_2); + printf("%s--xim-preedit=STYLE\n", HELP_SPACER_1); + printf("%s--xim-status=STYLE\n", HELP_SPACER_1); +#endif +#ifdef XP_UNIX + printf("%s--g-fatal-warnings%sMake all warnings fatal\n", HELP_SPACER_1, HELP_SPACER_2); + + printf("\nMozilla options\n"); +#endif + + printf("%s-height %sSet height of startup window to .\n",HELP_SPACER_1,HELP_SPACER_2); + printf("%s-h or -help%sPrint this message.\n",HELP_SPACER_1,HELP_SPACER_2); + printf("%s-width %sSet width of startup window to .\n",HELP_SPACER_1,HELP_SPACER_2); + printf("%s-v or -version%sPrint %s version.\n",HELP_SPACER_1,HELP_SPACER_2, gAppData->appName); + printf("%s-P %sStart with .\n",HELP_SPACER_1,HELP_SPACER_2); + printf("%s-ProfileManager%sStart with profile manager.\n",HELP_SPACER_1,HELP_SPACER_2); + printf("%s-UILocale %sStart with resources as UI Locale.\n",HELP_SPACER_1,HELP_SPACER_2); + printf("%s-contentLocale %sStart with resources as content Locale.\n",HELP_SPACER_1,HELP_SPACER_2); +#ifdef XP_WIN + printf("%s-console%sStart Mozilla with a debugging console.\n",HELP_SPACER_1,HELP_SPACER_2); +#endif +#ifdef MOZ_ENABLE_XREMOTE + printf("%s-remote %sExecute in an already running\n" + "%sMozilla process. For more info, see:\n" + "\n%shttp://www.mozilla.org/unix/remote.html\n\n", + HELP_SPACER_1,HELP_SPACER_1,HELP_SPACER_4,HELP_SPACER_2); +#endif + + // this works, but only after the components have registered. so if you drop in a new command line handler, -help + // won't not until the second run. + // out of the bug, because we ship a component.reg file, it works correctly. + DumpArbitraryHelp(); +} + // don't modify aAppDir directly... clone it first static int VerifyInstallation(nsIFile* aAppDir) @@ -2049,6 +1769,26 @@ int xre_main(int argc, char* argv[], const nsXREAppData* aAppData) } dirProvider.DoStartup(); + nsCOMPtr cmdLine + (do_CreateInstance("@mozilla.org/toolkit/command-line;1")); + NS_ENSURE_TRUE(cmdLine, 1); + + nsCOMPtr workingDir; + rv = NS_GetSpecialDirectory(NS_OS_CURRENT_WORKING_DIR, getter_AddRefs(workingDir)); + NS_ENSURE_SUCCESS(rv, 1); + + rv = cmdLine->Init(gArgc, gArgv, + workingDir, nsICommandLine::STATE_INITIAL_LAUNCH); + NS_ENSURE_SUCCESS(rv, 1); + + /* Special-case services that need early access to the command + line. */ + nsCOMPtr chromeObserver + (do_GetService("@mozilla.org/chrome/chrome-registry;1")); + if (chromeObserver) { + chromeObserver->Observe(cmdLine, "command-line-startup", nsnull); + } + NS_TIMELINE_ENTER("appStartup->CreateHiddenWindow"); rv = appStartup->CreateHiddenWindow(); NS_TIMELINE_LEAVE("appStartup->CreateHiddenWindow"); @@ -2063,7 +1803,7 @@ int xre_main(int argc, char* argv[], const nsXREAppData* aAppData) CheckArg("install-global-theme") || CheckArg("list-global-items") || CheckArg("lock-item") || CheckArg("unlock-item")) { // Do the required processing and then shut down. - em->HandleCommandLineArgs(); + em->HandleCommandLineArgs(cmdLine); return 0; } @@ -2079,7 +1819,7 @@ int xre_main(int argc, char* argv[], const nsXREAppData* aAppData) } if (noRestart || (!upgraded || !needsRestart)) - em->Start(componentsListChanged, &needsRestart); + em->Start(cmdLine, componentsListChanged, &needsRestart); } if (noRestart || (!upgraded && !needsRestart)) { @@ -2098,54 +1838,49 @@ int xre_main(int argc, char* argv[], const nsXREAppData* aAppData) UpdatePrebinding(); #endif - nsCOMPtr cmdLineArgs - (do_GetService("@mozilla.org/app-startup/commandLineService;1")); - NS_ENSURE_TRUE(cmdLineArgs, 1); - - // This will go away once Components are handling their own commandlines - // if we have no command line arguments, we need to heed the - // "general.startup.*" prefs - // if we had no command line arguments, argc == 1. - - PRBool windowOpened = PR_FALSE; - rv = DoCommandLines(cmdLineArgs, - aAppData->flags & NS_XRE_USE_STARTUP_PREFS, - &windowOpened); + rv = cmdLine->Run(); NS_ENSURE_SUCCESS(rv, 1); - + + nsCOMPtr windowMediator + (do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv)); + NS_ENSURE_SUCCESS(rv, 1); + // Make sure there exists at least 1 window. - NS_TIMELINE_ENTER("Ensure1Window"); - rv = appStartup->Ensure1Window(cmdLineArgs); - NS_TIMELINE_LEAVE("Ensure1Window"); + nsCOMPtr windowEnumerator; + rv = windowMediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator)); NS_ENSURE_SUCCESS(rv, 1); + PRBool more; + windowEnumerator->HasMoreElements(&more); + if (more) { #ifndef XP_MACOSX - appStartup->ExitLastWindowClosingSurvivalArea(); + appStartup->ExitLastWindowClosingSurvivalArea(); #endif #ifdef MOZ_ENABLE_XREMOTE - // if we have X remote support and we have our one window up and - // running start listening for requests on the proxy window. - nsCOMPtr remoteService; - remoteService = do_GetService(NS_IXREMOTESERVICE_CONTRACTID); - if (remoteService) - remoteService->Startup(aAppData->appName); + // if we have X remote support and we have our one window up and + // running start listening for requests on the proxy window. + nsCOMPtr remoteService; + remoteService = do_GetService(NS_IXREMOTESERVICE_CONTRACTID); + if (remoteService) + remoteService->Startup(aAppData->appName); #endif /* MOZ_ENABLE_XREMOTE */ - // enable win32 DDE responses and Mac appleevents responses - nativeApp->Enable(); + // enable win32 DDE responses and Mac appleevents responses + nativeApp->Enable(); - // Start main event loop - NS_TIMELINE_ENTER("appStartup->Run"); - rv = appStartup->Run(); - NS_TIMELINE_LEAVE("appStartup->Run"); - NS_ASSERTION(NS_SUCCEEDED(rv), "failed to run appstartup"); + // Start main event loop + NS_TIMELINE_ENTER("appStartup->Run"); + rv = appStartup->Run(); + NS_TIMELINE_LEAVE("appStartup->Run"); + NS_ASSERTION(NS_SUCCEEDED(rv), "failed to run appstartup"); #ifdef MOZ_ENABLE_XREMOTE - // shut down the x remote proxy window - if (remoteService) - remoteService->Shutdown(); + // shut down the x remote proxy window + if (remoteService) + remoteService->Shutdown(); #endif /* MOZ_ENABLE_XREMOTE */ + } #ifdef MOZ_TIMELINE // Make sure we print this out even if timeline is runtime disabled diff --git a/mozilla/toolkit/xre/nsNativeAppSupportMac.cpp b/mozilla/toolkit/xre/nsNativeAppSupportMac.cpp index aebe69aab5d..79380bb77c8 100644 --- a/mozilla/toolkit/xre/nsNativeAppSupportMac.cpp +++ b/mozilla/toolkit/xre/nsNativeAppSupportMac.cpp @@ -49,7 +49,7 @@ #include "nsIAppShellService.h" #include "nsIAppStartup.h" #include "nsIBaseWindow.h" -#include "nsICmdLineService.h" +#include "nsICommandLineRunner.h" #include "nsIDOMWindowInternal.h" #include "nsIDocShellTreeItem.h" #include "nsIDocShellTreeOwner.h" @@ -253,19 +253,20 @@ nsNativeAppSupportMac::ReOpen() } // end if have uncollapsed if (!haveOpenWindows && !done) - { + { + char* argv[] = { nsnull }; - NS_WARNING("trying to open new window"); - //use the bootstrap helpers to make the right kind(s) of window open - nsresult rv = PR_FALSE; - nsCOMPtr appStartup(do_GetService(NS_APPSTARTUP_CONTRACTID)); - if (appStartup) - { - PRBool openedAWindow = PR_FALSE; - appStartup->CreateStartupState(nsIAppShellService::SIZE_TO_CONTENT, - nsIAppShellService::SIZE_TO_CONTENT, - &openedAWindow); - } + // use an empty command line to make the right kind(s) of window open + nsCOMPtr cmdLine + (do_CreateInstance("@mozilla.org/toolkit/command-line;1")); + NS_ENSURE_TRUE(cmdLine, NS_ERROR_FAILURE); + + nsresult rv; + rv = cmdLine->Init(argv, 0, nsnull, + nsICommandLine::STATE_REMOTE_EXPLICIT); + NS_ENSURE_SUCCESS(rv, rv); + + return cmdLine->Run(); } } // got window mediator diff --git a/mozilla/toolkit/xre/nsNativeAppSupportWin.cpp b/mozilla/toolkit/xre/nsNativeAppSupportWin.cpp index 9a2859ca5d3..a6a9b03f3fb 100644 --- a/mozilla/toolkit/xre/nsNativeAppSupportWin.cpp +++ b/mozilla/toolkit/xre/nsNativeAppSupportWin.cpp @@ -42,12 +42,11 @@ #include "nsXULAppAPI.h" #include "nsString.h" #include "nsIBrowserDOMWindow.h" -#include "nsICmdLineService.h" +#include "nsICommandLineRunner.h" #include "nsCOMPtr.h" #include "nsXPIDLString.h" #include "nsIComponentManager.h" #include "nsIServiceManager.h" -#include "nsICmdLineHandler.h" #include "nsIDOMWindow.h" #include "nsIDOMChromeWindow.h" #include "nsXPCOM.h" @@ -84,14 +83,9 @@ #include #include #include +#include #include -#define kMailtoUrlScheme "mailto:" - -#ifdef MOZ_THUNDERBIRD -#define MAPI_STARTUP_ARG "/MAPIStartUp" -#endif - static HWND hwndForDOMWindow( nsISupports * ); static @@ -296,7 +290,7 @@ private: HDDEDATA hdata, ULONG dwData1, ULONG dwData2 ); - static void HandleRequest( LPBYTE request, PRBool newWindow = PR_TRUE ); + static void HandleCommandLine(const char* aCmdLineString, nsIFile* aWorkingDir, PRUint32 aState); static void ParseDDEArg( HSZ args, int index, nsCString& string); static void ParseDDEArg( const char* args, int index, nsCString& aString); static void ActivateLastWindow(); @@ -304,11 +298,9 @@ private: static HDDEDATA CreateDDEData( LPBYTE value, DWORD len ); static PRBool InitTopicStrings(); static int FindTopic( HSZ topic ); - static nsresult GetCmdLineArgs( LPBYTE request, nsICmdLineService **aResult ); static nsresult OpenWindow( const char *urlstr, const char *args ); - static nsresult OpenBrowserWindow( const char *args, PRBool newWindow = PR_TRUE ); + static nsresult OpenBrowserWindow(); static nsresult ReParent( nsISupports *window, HWND newParent ); - static nsresult GetStartupURL(nsICmdLineService *args, nsCString& taskURL); static void SetupSysTrayIcon(); static void RemoveSysTrayIcon(); @@ -524,7 +516,22 @@ struct MessageWindow { // SendRequest: Pass string via WM_COPYDATA to message window. NS_IMETHOD SendRequest( const char *cmd ) { - COPYDATASTRUCT cds = { 0, ::strlen( cmd ) + 1, (void*)cmd }; + // Construct a data buffer \0\0 + int cmdlen = strlen(cmd); + char* cmdbuf = (char*) malloc(cmdlen + MAX_PATH + 1); + if (!cmdbuf) + return NS_ERROR_OUT_OF_MEMORY; + + strcpy(cmdbuf, cmd); + _getcwd(cmdbuf + cmdlen + 1, MAX_PATH); + + // We used to set dwData to zero, when we didn't send the working dir. + // Now we're using it as a version number. + COPYDATASTRUCT cds = { + 1, + cmdlen + strlen(cmdbuf + cmdlen + 1) + 2, + (void*) cmdbuf + }; HWND newWin = (HWND)::SendMessage( mHandle, WM_COPYDATA, 0, (LPARAM)&cds ); if ( newWin ) { // Restore the window if it is minimized. @@ -533,6 +540,7 @@ struct MessageWindow { } ::SetForegroundWindow( newWin ); } + free (cmdbuf); return NS_OK; } @@ -547,39 +555,49 @@ struct MessageWindow { #if MOZ_DEBUG_DDE printf( "Incoming request: %s\n", (const char*)cds->lpData ); #endif - (void)nsNativeAppSupportWin::HandleRequest( (LPBYTE)cds->lpData ); + nsCOMPtr workingDir; + + if (1 >= cds->dwData) { + char* wdpath = (char*) cds->lpData; + // skip the command line, and get the working dir of the + // other process, which is after the first null char + while (*wdpath) + ++wdpath; + + ++wdpath; + +#ifdef MOZ_DEBUG_DDE + printf( "Working dir: %s\n", wdpath); +#endif + + NS_NewNativeLocalFile(nsDependentCString(wdpath), + PR_FALSE, + getter_AddRefs(workingDir)); + } + (void)nsNativeAppSupportWin::HandleCommandLine((char*)cds->lpData, workingDir, nsICommandLine::STATE_REMOTE_AUTO); // Get current window and return its window handle. nsCOMPtr win; GetMostRecentWindow( 0, getter_AddRefs( win ) ); return win ? (long)hwndForDOMWindow( win ) : 0; - } else if ( msg == WM_QUERYENDSESSION ) { - if (!nsNativeAppSupportWin::mCanHandleRequests) - return 0; - // Invoke "-killAll" cmd line handler. That will close all open windows, - // and display dialog asking whether to save/don't save/cancel. If the - // user says cancel, then we pass that indicator along to the system - // in order to stop the system shutdown/logoff. - nsCOMPtr - killAll( do_CreateInstance( "@mozilla.org/commandlinehandler/general-startup;1?type=killAll" ) ); - if ( killAll ) { - nsXPIDLCString unused; - // Note: "GetChromeUrlForTask" is a euphemism for - // "ProcessYourCommandLineSwitch". The interface was written - // presuming a less general-purpose role for command line - // handlers than it ought to have. - nsresult rv = killAll->GetChromeUrlForTask( getter_Copies( unused ) ); - if ( rv == NS_ERROR_ABORT ) { - // User cancelled shutdown/logoff. - return FALSE; - } else { - // Shutdown/logoff OK. - return TRUE; + } else if ( msg == WM_QUERYENDSESSION ) { + if (!nsNativeAppSupportWin::mCanHandleRequests) + return 0; + // Invoke "-killAll" cmd line handler. That will close all open windows, + // and display dialog asking whether to save/don't save/cancel. If the + // user says cancel, then we pass that indicator along to the system + // in order to stop the system shutdown/logoff. + nsCOMPtr cmdLine + (do_CreateInstance("@mozilla.org/toolkit/command-line;1")); + char* argv[] = { "-killAll", 0 }; + if (cmdLine && + NS_SUCCEEDED(cmdLine->Init(1, argv, nsnull, + nsICommandLine::STATE_REMOTE_AUTO))) { + return cmdLine->Run() != NS_ERROR_ABORT; + } } + return DefWindowProc( msgWindow, msg, wp, lp ); } - } - return DefWindowProc( msgWindow, msg, wp, lp ); -} private: HWND mHandle; @@ -978,28 +996,27 @@ nsNativeAppSupportWin::HandleDDENotification( UINT uType, // transaction t case topicOpenURL: { // Open a given URL... - // Default is to open in current window. - PRBool new_window = PR_FALSE; - // Get the URL from the first argument in the command. nsCAutoString url; ParseDDEArg(hsz2, 0, url); + // Read the 3rd argument in the command to determine if a // new window is to be used. nsCAutoString windowID; ParseDDEArg(hsz2, 2, windowID); - // "0" means to open the URL in a new window. - if ( windowID.Equals( "0" ) ) { - new_window = PR_TRUE; + // "" means to open the URL in a new window. + if ( windowID.Equals( "" ) ) { + url.Insert("mozilla -new-window ", 0); + } + else { + url.Insert("mozilla -url ", 0); } - // Make it look like command line args. - url.Insert( "mozilla -url ", 0 ); #if MOZ_DEBUG_DDE printf( "Handling dde XTYP_REQUEST request: [%s]...\n", url.get() ); #endif // Now handle it. - HandleRequest( LPBYTE( url.get() ), new_window ); + HandleCommandLine(url.get(), nsnull, nsICommandLine::STATE_REMOTE_EXPLICIT); // Return pseudo window ID. result = CreateDDEData( 1 ); break; @@ -1158,18 +1175,18 @@ nsNativeAppSupportWin::HandleDDENotification( UINT uType, // transaction t nsCAutoString windowID; ParseDDEArg((const char*) request, 2, windowID); - // "0" means to open the URL in a new window. - if ( windowID.Equals( "0" ) ) { - new_window = PR_TRUE; + // "" means to open the URL in a new window. + if ( windowID.Equals( "" ) ) { + url.Insert("mozilla -new-window ", 0); + } + else { + url.Insert("mozilla -url ", 0); } - - // Make it look like command line args. - url.Insert( "mozilla -url ", 0 ); #if MOZ_DEBUG_DDE printf( "Handling dde XTYP_REQUEST request: [%s]...\n", url.get() ); #endif // Now handle it. - HandleRequest( LPBYTE( url.get() ), new_window ); + HandleCommandLine(url.get(), nsnull, nsICommandLine::STATE_REMOTE_EXPLICIT); // Release the data. DdeUnaccessData( hdata ); @@ -1269,7 +1286,7 @@ void nsNativeAppSupportWin::ActivateLastWindow() { activateWindow( navWin ); } else { // Need to create a Navigator window, then. - OpenBrowserWindow( "about:blank" ); + OpenBrowserWindow(); } } @@ -1288,138 +1305,37 @@ HDDEDATA nsNativeAppSupportWin::CreateDDEData( LPBYTE value, DWORD len ) { return result; } -// Handle DDE request. The argument is the command line received by the -// DDE client process. We convert that string to an nsICmdLineService -// object via GetCmdLineArgs. Then, we look for certain well-known cmd -// arguments. This replicates code elsewhere, to some extent, -// unfortunately (if you can fix that, please do). void -nsNativeAppSupportWin::HandleRequest( LPBYTE request, PRBool newWindow ) { - - // Parse command line. - - nsCOMPtr args; +nsNativeAppSupportWin::HandleCommandLine(const char* aCmdLineString, + nsIFile* aWorkingDir, + PRUint32 aState) +{ nsresult rv; - rv = GetCmdLineArgs( request, getter_AddRefs( args ) ); - if (NS_FAILED(rv)) return; - - // first see if there is a url - nsXPIDLCString arg; - rv = args->GetURLToLoad(getter_Copies(arg)); - if (NS_SUCCEEDED(rv) && (const char*)arg ) { - // Launch browser. -#if MOZ_DEBUG_DDE - printf( "Launching browser on url [%s]...\n", (const char*)arg ); -#endif - OpenBrowserWindow( arg, PR_FALSE ); // newWindow = false means use prefs - return; - } - - - // ok, let's try the -chrome argument - rv = args->GetCmdLineValue("-chrome", getter_Copies(arg)); - if (NS_SUCCEEDED(rv) && (const char*)arg ) { - // Launch chrome. -#if MOZ_DEBUG_DDE - printf( "Launching chrome url [%s]...\n", (const char*)arg ); -#endif - (void)OpenWindow( arg, "" ); - return; - } - -#ifdef MOZ_THUNDERBIRD - // check wheather it is a MAPI request. If yes, don't open any new - // windows and just return. - rv = args->GetCmdLineValue(MAPI_STARTUP_ARG, getter_Copies(arg)); - if (NS_SUCCEEDED(rv) && (const char*)arg) { - return; - } -#endif - - // Try standard startup's command-line handling logic from nsAppRunner.cpp... - - // This will tell us whether the command line processing opened a window. - PRBool windowOpened = PR_FALSE; - - // If there are no command line arguments, then we want to open windows - // based on startup prefs (which say to open navigator and/or mailnews - // and/or composer), or, open just a Navigator window. We do the former - // if there are no open windows (i.e., we're in turbo mode), the latter - // if there are open windows. Note that we call DoCommandLines in the - // case where there are no command line args but there are windows open - // (i.e., with heedStartupPrefs==PR_FALSE) despite the fact that it may - // not actually do anything in that case. That way we're covered if the - // logic in DoCommandLines changes. Note that we cover this case below - // by opening a navigator window if DoCommandLines doesn't open one. We - // have to cover that case anyway, because DoCommandLines won't open a - // window when given "mozilla -foobar" or the like. - PRBool heedStartupPrefs = PR_FALSE; - PRInt32 argc = 0; - args->GetArgc( &argc ); - if ( argc <= 1 ) { - // Use startup prefs iff there are no windows currently open. - nsCOMPtr win; - GetMostRecentWindow( 0, getter_AddRefs( win ) ); - if ( !win ) { - heedStartupPrefs = PR_TRUE; - } - } - - // Process command line options. - rv = DoCommandLines( args, heedStartupPrefs, &windowOpened ); - - // If a window was opened, then we're done. - // Note that we keep on trying in the unlikely event of an error. - if (rv == NS_ERROR_NOT_AVAILABLE || rv == NS_ERROR_ABORT || windowOpened) { - return; - } - - // ok, no idea what the param is. -#if MOZ_DEBUG_DDE - printf( "Unknown request [%s]\n", (char*) request ); -#endif - // if all else fails, open a browser window - const char * const contractID = - "@mozilla.org/commandlinehandler/general-startup;1?type=browser"; - nsCOMPtr handler = do_GetService(contractID, &rv); - if (NS_FAILED(rv)) return; - - nsXPIDLString defaultArgs; - rv = handler->GetDefaultArgs(getter_Copies(defaultArgs)); - if (NS_FAILED(rv) || !defaultArgs) return; - - if (defaultArgs) { - nsCAutoString url; - url.AssignWithConversion( defaultArgs ); - OpenBrowserWindow(url.get()); - } else { - OpenBrowserWindow("about:blank"); - } -} - -// Parse command line args according to MS spec -// (see "Parsing C++ Command-Line Arguments" at -// http://msdn.microsoft.com/library/devprods/vs6/visualc/vclang/_pluslang_parsing_c.2b2b_.command.2d.line_arguments.htm). -nsresult -nsNativeAppSupportWin::GetCmdLineArgs( LPBYTE request, nsICmdLineService **aResult ) { - nsresult rv = NS_OK; - int justCounting = 1; char **argv = 0; // Flags, etc. int init = 1; int between, quoted, bSlashCount; int argc; - char *p; + const char *p; nsCAutoString arg; - nsDependentCString mailtoUrlScheme (kMailtoUrlScheme); + nsCOMPtr cmdLine + (do_CreateInstance("@mozilla.org/toolkit/command-line;1")); + if (!cmdLine) { + NS_ERROR("Couldn't create command line!"); + return; + } + + // Parse command line args according to MS spec + // (see "Parsing C++ Command-Line Arguments" at + // http://msdn.microsoft.com/library/devprods/vs6/visualc/vclang/_pluslang_parsing_c.2b2b_.command.2d.line_arguments.htm). // We loop if we've not finished the second pass through. while ( 1 ) { // Initialize if required. if ( init ) { - p = (char*)request; + p = aCmdLineString; between = 1; argc = quoted = bSlashCount = 0; @@ -1452,9 +1368,7 @@ nsNativeAppSupportWin::GetCmdLineArgs( LPBYTE request, nsICmdLineService **aResu } else { // We are processing the contents of an argument. // Check for whitespace or end. - // if the argument we are parsing is a mailto url then all of the remaining command line data - // needs to be part of the mailto url even if it has spaces. See Bug #231032 - if ( *p == 0 || ( !quoted && isspace( *p ) && !StringBeginsWith(arg, mailtoUrlScheme, nsCaseInsensitiveCStringComparator()) ) ) { + if ( *p == 0 || ( !quoted && isspace( *p ) ) ) { // Process pending backslashes (interpret them // literally since they're not followed by a "). while( bSlashCount ) { @@ -1537,18 +1451,7 @@ nsNativeAppSupportWin::GetCmdLineArgs( LPBYTE request, nsICmdLineService **aResu } } - // OK, now create nsICmdLineService object from argc/argv. - nsCOMPtr compMgr; - NS_GetComponentManager(getter_AddRefs(compMgr)); - rv = compMgr->CreateInstanceByContractID("@mozilla.org/app-startup/commandLineService;1", - 0, NS_GET_IID( nsICmdLineService ), - (void**) aResult); - - if ( NS_FAILED( rv ) || NS_FAILED( ( rv = (*aResult)->Initialize( argc, argv ) ) ) ) { -#if MOZ_DEBUG_DDE - printf( "Error creating command line service = 0x%08X (argc=%d, argv=0x%08X)\n", (int)rv, (int)argc, (void*)argv ); -#endif - } + rv = cmdLine->Init(argc, argv, aWorkingDir, aState); // Cleanup. while ( argc ) { @@ -1556,7 +1459,12 @@ nsNativeAppSupportWin::GetCmdLineArgs( LPBYTE request, nsICmdLineService **aResu } delete [] argv; - return rv; + if (NS_FAILED(rv)) { + NS_ERROR("Error initializing command line."); + return; + } + + cmdLine->Run(); } nsresult @@ -1647,8 +1555,8 @@ nsresult SafeJSContext::Push() { nsresult -nsNativeAppSupportWin::OpenBrowserWindow( const char *args, PRBool newWindow ) { - +nsNativeAppSupportWin::OpenBrowserWindow() +{ nsresult rv = NS_OK; // Open the argument URL in the most recently used Navigator window. @@ -1664,9 +1572,6 @@ nsNativeAppSupportWin::OpenBrowserWindow( const char *args, PRBool newWindow ) { // out to the OpenWindow call when things go awry. do { // If caller requires a new window, then don't use an existing one. - if ( newWindow ) { - break; - } if ( !navWin ) { // Have to open a new one. break; @@ -1687,8 +1592,7 @@ nsNativeAppSupportWin::OpenBrowserWindow( const char *args, PRBool newWindow ) { } if ( bwin ) { nsCOMPtr uri; - nsDependentCString urlStr( args ); - NS_NewURI( getter_AddRefs( uri ), urlStr, 0, 0 ); + NS_NewURI( getter_AddRefs( uri ), NS_LITERAL_CSTRING("about:blank"), 0, 0 ); if ( uri ) { nsCOMPtr container; rv = bwin->OpenURI( uri, 0, @@ -1705,14 +1609,14 @@ nsNativeAppSupportWin::OpenBrowserWindow( const char *args, PRBool newWindow ) { // open a new window if caller requested it or if anything above failed - nsCOMPtr handler(do_GetService("@mozilla.org/commandlinehandler/general-startup;1?type=browser", &rv)); - if (NS_FAILED(rv)) return rv; + char* argv[] = { 0 }; + nsCOMPtr cmdLine + (do_CreateInstance("@mozilla.org/toolkit/command-line;1")); + NS_ENSURE_TRUE(cmdLine, NS_ERROR_FAILURE); - nsXPIDLCString chromeUrlForTask; - rv = handler->GetChromeUrlForTask(getter_Copies(chromeUrlForTask)); - if (NS_FAILED(rv)) return rv; + rv = cmdLine->Init(0, argv, nsnull, nsICommandLine::STATE_REMOTE_EXPLICIT); + NS_ENSURE_SUCCESS(rv, rv); - // Last resort is to open a brand new window. - return OpenWindow( chromeUrlForTask, args ); + return cmdLine->Run(); } diff --git a/mozilla/xpfe/bootstrap/appleevents/nsAEApplicationClass.cpp b/mozilla/xpfe/bootstrap/appleevents/nsAEApplicationClass.cpp index 11fc337d943..6a71bb83b35 100644 --- a/mozilla/xpfe/bootstrap/appleevents/nsAEApplicationClass.cpp +++ b/mozilla/xpfe/bootstrap/appleevents/nsAEApplicationClass.cpp @@ -50,11 +50,12 @@ #include "nsINativeAppSupport.h" #include "nsCommandLineServiceMac.h" -#include "nsICmdLineService.h" #include "nsCOMPtr.h" #include "nsIAppStartup.h" #include "nsXPFEComponentsCID.h" +#include "nsComponentManagerUtils.h" + #ifdef MOZ_XUL_APP #include "nsAppRunner.h" #endif diff --git a/mozilla/xpfe/browser/src/nsBrowserInstance.cpp b/mozilla/xpfe/browser/src/nsBrowserInstance.cpp index 73b78f548ea..ed2bd06680d 100644 --- a/mozilla/xpfe/browser/src/nsBrowserInstance.cpp +++ b/mozilla/xpfe/browser/src/nsBrowserInstance.cpp @@ -92,7 +92,9 @@ #include "nsDirectoryServiceDefs.h" #include "nsNetUtil.h" +#ifndef MOZ_XUL_APP #include "nsICmdLineService.h" +#endif // Stuff to implement file download dialog. #include "nsIProxyObjectManager.h" @@ -512,9 +514,11 @@ nsBrowserInstance::GetCmdLineURLUsed(PRBool* aCmdLineURLUsed) NS_IMETHODIMP nsBrowserInstance::StartPageCycler(PRBool* aIsPageCycling) { + *aIsPageCycling = PR_FALSE; + +#ifndef MOZ_XUL_APP nsresult rv; - *aIsPageCycling = PR_FALSE; if (!sCmdLineURLUsed) { nsCOMPtr cmdLineArgs = do_GetService(NS_COMMANDLINESERVICE_CONTRACTID, &rv); @@ -561,6 +565,7 @@ nsBrowserInstance::StartPageCycler(PRBool* aIsPageCycling) } #endif //ENABLE_PAGE_CYCLER } +#endif // MOZ_XUL_APP return NS_OK; } @@ -605,11 +610,11 @@ nsBrowserInstance::Close() return NS_OK; } +#ifndef MOZ_XUL_APP //***************************************************************************** // nsBrowserInstance: Helpers //***************************************************************************** - //////////////////////////////////////////////////////////////////////// // browserCntHandler is a content handler component that registers // the browse as the preferred content handler for various content @@ -814,3 +819,5 @@ NS_IMETHODIMP nsBrowserContentHandler::HandleContent(const char * aContentType, return NS_OK; } + +#endif // MOZ_XUL_APP diff --git a/mozilla/xpfe/browser/src/nsBrowserInstance.h b/mozilla/xpfe/browser/src/nsBrowserInstance.h index 0009ebf95fc..fb64b2548ec 100644 --- a/mozilla/xpfe/browser/src/nsBrowserInstance.h +++ b/mozilla/xpfe/browser/src/nsBrowserInstance.h @@ -47,9 +47,11 @@ #include "nscore.h" #include "nsISupports.h" +#ifndef MOZ_XUL_APP // for nsBrowserStatusHandler #include "nsIContentHandler.h" #include "nsICmdLineHandler.h" +#endif class nsIDocShell; class nsIDOMWindowInternal; @@ -94,6 +96,7 @@ class nsBrowserInstance : public nsIBrowserInstance, #endif }; +#ifndef MOZ_XUL_APP class nsBrowserContentHandler : public nsIContentHandler, public nsICmdLineHandler { public: @@ -108,5 +111,6 @@ public: protected: PRBool NeedHomepageOverride(nsIPref *aPrefService); }; +#endif #endif // nsBrowserInstance_h___ diff --git a/mozilla/xpfe/components/build/nsModule.cpp b/mozilla/xpfe/components/build/nsModule.cpp index c1500f4e695..48153b51e4c 100644 --- a/mozilla/xpfe/components/build/nsModule.cpp +++ b/mozilla/xpfe/components/build/nsModule.cpp @@ -112,8 +112,10 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsUrlWidget, Init) NS_GENERIC_FACTORY_CONSTRUCTOR(nsBrowserStatusFilter) NS_GENERIC_FACTORY_CONSTRUCTOR(nsBrowserInstance) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsBrowserContentHandler) +#ifndef MOZ_XUL_APP +NS_GENERIC_FACTORY_CONSTRUCTOR(nsBrowserContentHandler) +#endif static NS_METHOD @@ -231,6 +233,7 @@ static const nsModuleComponentInfo components[] = { NS_BROWSERINSTANCE_CONTRACTID, nsBrowserInstanceConstructor }, +#ifndef MOZ_XUL_APP { "Browser Content Handler", NS_BROWSERCONTENTHANDLER_CID, NS_CONTENT_HANDLER_CONTRACTID_PREFIX"text/html", @@ -335,6 +338,7 @@ static const nsModuleComponentInfo components[] = { "@mozilla.org/commandlinehandler/general-startup;1?type=chrome", nsBrowserContentHandlerConstructor, }, +#endif //!MOZ_XUL_APP { NS_BROWSERSTATUSFILTER_CLASSNAME, NS_BROWSERSTATUSFILTER_CID, NS_BROWSERSTATUSFILTER_CONTRACTID, diff --git a/mozilla/xpfe/components/winhooks/nsWindowsHooks.cpp b/mozilla/xpfe/components/winhooks/nsWindowsHooks.cpp index bee36b3210a..7bf38d2f685 100644 --- a/mozilla/xpfe/components/winhooks/nsWindowsHooks.cpp +++ b/mozilla/xpfe/components/winhooks/nsWindowsHooks.cpp @@ -51,7 +51,6 @@ #include "nsIPromptService.h" #include "nsIStringBundle.h" #include "nsIAllocator.h" -#include "nsICmdLineService.h" #include "nsXPIDLString.h" #include "nsString.h" #include "nsMemory.h" @@ -76,6 +75,10 @@ #include "nsDirectoryServiceUtils.h" #include "nsAppDirectoryServiceDefs.h" +#ifndef MOZ_XUL_APP +#include "nsICmdLineService.h" +#endif + #include "nsXPFEComponentsCID.h" #define RUNKEY "Software\\Microsoft\\Windows\\CurrentVersion\\Run" @@ -388,6 +391,7 @@ nsWindowsHooks::CheckSettings( nsIDOMWindowInternal *aParent, // If launched with "-installer" then override mShowDialog. PRBool installing = PR_FALSE; +#ifndef MOZ_XUL_APP if ( !settings->mShowDialog ) { // Get command line service. nsCOMPtr cmdLineArgs @@ -401,6 +405,7 @@ nsWindowsHooks::CheckSettings( nsIDOMWindowInternal *aParent, } } } +#endif // First, make sure the user cares. if ( settings->mShowDialog || installing ) { diff --git a/mozilla/xpfe/components/winhooks/nsWindowsHooksUtil.cpp b/mozilla/xpfe/components/winhooks/nsWindowsHooksUtil.cpp index c15bcc79dd1..e4968107840 100644 --- a/mozilla/xpfe/components/winhooks/nsWindowsHooksUtil.cpp +++ b/mozilla/xpfe/components/winhooks/nsWindowsHooksUtil.cpp @@ -50,6 +50,7 @@ #include "nsNativeAppSupportWin.h" #else #include "nsINativeAppSupportWin.h" +#include "nsICmdLineHandler.h" #endif #define MOZ_HWND_BROADCAST_MSG_TIMEOUT 5000 @@ -871,6 +872,7 @@ nsresult FileTypeRegistryEntry::reset() { // "edit" entry a SavedRegistryEntry). nsresult EditableFileTypeRegistryEntry::set() { nsresult rv = FileTypeRegistryEntry::set(); +#ifndef MOZ_XUL_APP if ( NS_SUCCEEDED( rv ) ) { // only set this if we support "-edit" on the command-line nsCOMPtr editorService = @@ -884,6 +886,7 @@ nsresult EditableFileTypeRegistryEntry::set() { rv = RegistryEntry( HKEY_LOCAL_MACHINE, editKey.get(), "", editor.get() ).set(); } } +#endif return rv; } diff --git a/mozilla/xpfe/components/xremote/src/Makefile.in b/mozilla/xpfe/components/xremote/src/Makefile.in index 99de6465509..78596dc0ca7 100644 --- a/mozilla/xpfe/components/xremote/src/Makefile.in +++ b/mozilla/xpfe/components/xremote/src/Makefile.in @@ -61,6 +61,7 @@ REQUIRES = xpcom \ windowwatcher \ necko \ appshell \ + toolkitcomps \ appcomps \ rdf \ exthandler \ diff --git a/mozilla/xpfe/components/xremote/src/XRemoteService.cpp b/mozilla/xpfe/components/xremote/src/XRemoteService.cpp index 141bccf49c8..62b97d0a423 100644 --- a/mozilla/xpfe/components/xremote/src/XRemoteService.cpp +++ b/mozilla/xpfe/components/xremote/src/XRemoteService.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim:expandtab:shiftwidth=4:tabstop=4: */ /* ***** BEGIN LICENSE BLOCK ***** @@ -73,7 +73,12 @@ #include #include #include -#include + +#ifdef MOZ_XUL_APP +#include "nsICommandLineRunner.h" +#else +#include "nsICmdLineHandler.h" +#endif NS_DEFINE_CID(kWindowCID, NS_WINDOW_CID); @@ -1032,6 +1037,19 @@ XRemoteService::XfeDoCommand(nsCString &aArgument, // open a new browser window else if (aArgument.LowerCaseEqualsLiteral("openbrowser")) { +#ifdef MOZ_XUL_APP + char* argc = "-browser"; + + nsCOMPtr cmdLine + (do_GetService("@mozilla.org/toolkit/command-line;1")); + NS_ENSURE_TRUE(cmdLine, NS_ERROR_FAILURE); + + rv = cmdLine->Init(1, &argc, nsnull, nsICommandLine::STATE_REMOTE_EXPLICIT); + NS_ENSURE_SUCCESS(rv, rv); + + rv = cmdLine->Run(); + +#else // Get the browser URL and the default start page URL. nsCOMPtr browserHandler = do_GetService("@mozilla.org/commandlinehandler/general-startup;1?type=browser"); @@ -1050,6 +1068,7 @@ XRemoteService::XfeDoCommand(nsCString &aArgument, nsCOMPtr newWindow; rv = OpenChromeWindow(0, browserLocation, "chrome,all,dialog=no", arg, getter_AddRefs(newWindow)); +#endif } // open a new compose window diff --git a/mozilla/xulrunner/examples/simple/defaults/pref/simple.js b/mozilla/xulrunner/examples/simple/defaults/pref/simple.js index 804c9349169..ca785f9706b 100644 --- a/mozilla/xulrunner/examples/simple/defaults/pref/simple.js +++ b/mozilla/xulrunner/examples/simple/defaults/pref/simple.js @@ -1 +1 @@ -pref("browser.chromeURL", "chrome://simple/content/simple.xul"); +pref("toolkit.defaultChromeURI", "chrome://simple/content/simple.xul");