diff --git a/mozilla/Makefile.in b/mozilla/Makefile.in index a4d15c114f5..171472694e1 100644 --- a/mozilla/Makefile.in +++ b/mozilla/Makefile.in @@ -206,10 +206,6 @@ tier_9_dirs += \ editor \ $(NULL) -ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) -tier_9_dirs += xpfe/bootstrap/appleevents -endif - ifdef MOZ_THUNDERBIRD ifdef MOZ_USE_OFFICIAL_BRANDING tier_9_dirs += other-licenses/branding/thunderbird @@ -222,23 +218,8 @@ tier_9_dirs += other-licenses/branding/firefox endif endif -# profile and chrome should be in tier 50, but are required by xpfe/appshell -# This is a temporary hack until the app-startup patch lands. - -ifdef MOZ_XUL -ifdef MOZ_XUL_APP -tier_9_dirs += chrome -else -tier_9_dirs += rdf/chrome -endif -endif - -tier_9_dirs += profile - tier_9_dirs += \ xpfe/appshell \ - xpfe/browser/public \ - xpfe/components/sidebar/public \ xpfe/components/xremote/public \ $(NULL) @@ -250,10 +231,6 @@ ifdef MOZ_LDAP_XPCOM tier_9_dirs += directory/xpcom endif -ifndef MOZ_XUL -tier_9_dirs += embedding/minimo/chromelite -endif - ifdef MOZ_XUL_APP ifdef MOZ_ENABLE_GTK2 tier_9_dirs += toolkit/components/gnome @@ -264,6 +241,18 @@ endif # tier 50 - xpfe & toolkit # +ifdef MOZ_XUL +ifdef MOZ_XUL_APP +tier_50_dirs += chrome +else +tier_50_dirs += rdf/chrome +endif +else +tier_50_dirs += embedding/minimo/chromelite +endif + +tier_50_dirs += profile + ifdef MOZ_PSM tier_50_dirs += security/manager endif @@ -273,10 +262,8 @@ ifdef MOZ_JPROF tier_50_dirs += tools/jprof endif -ifdef MOZ_XUL_APP -tier_50_dirs += toolkit/components/history/public -else -tier_50_dirs += xpfe/components/history/public +ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) +tier_50_dirs += xpfe/bootstrap/appleevents endif tier_50_dirs += xpfe themes @@ -289,10 +276,6 @@ ifdef MOZ_MAPINFO tier_50_dirs += tools/codesighs endif -ifneq (,$(MOZ_L10N_LANG)$(MOZ_L10N_TOOLS)) -tier_50_dirs += l10n -endif - ifdef MOZ_XUL_APP tier_50_dirs += toolkit endif @@ -358,6 +341,10 @@ tier_99_dirs += other-licenses/branding/thunderbird/content endif endif +ifdef MOZ_COMPOSER +tier_99_dirs += editor/ui +endif + ifdef MOZ_STANDALONE_COMPOSER tier_99_dirs += composer endif @@ -385,11 +372,17 @@ ifneq (,$(ENABLE_TESTS)) tier_99_dirs += webshell/tests endif -# winembed, mfcembed +# winembed, mfcembed, axcontrol ifeq ($(OS_ARCH),WINNT) ifneq (,$(ENABLE_TESTS)$(MOZILLA_OFFICIAL)) tier_99_dirs += embedding/tests endif +ifndef MOZ_NO_ACTIVEX_SUPPORT +tier_99_dirs += \ + embedding/browser/activex/src/control \ + embedding/browser/activex/src/control_kicker \ + $(NULL) +endif endif # os2embed diff --git a/mozilla/allmakefiles.sh b/mozilla/allmakefiles.sh index 467e975d772..a82a3d349f6 100755 --- a/mozilla/allmakefiles.sh +++ b/mozilla/allmakefiles.sh @@ -700,6 +700,9 @@ xpfe/components/search/src/Makefile xpfe/components/sidebar/Makefile xpfe/components/sidebar/public/Makefile xpfe/components/sidebar/src/Makefile +xpfe/components/startup/Makefile +xpfe/components/startup/public/Makefile +xpfe/components/startup/src/Makefile xpfe/components/autocomplete/Makefile xpfe/components/autocomplete/public/Makefile xpfe/components/autocomplete/src/Makefile @@ -945,6 +948,9 @@ toolkit/components/printing/Makefile toolkit/components/satchel/Makefile toolkit/components/satchel/public/Makefile toolkit/components/satchel/src/Makefile +toolkit/components/startup/Makefile +toolkit/components/startup/public/Makefile +toolkit/components/startup/src/Makefile toolkit/components/viewconfig/Makefile toolkit/components/viewsource/Makefile toolkit/mozapps/Makefile diff --git a/mozilla/browser/app/splash.rc b/mozilla/browser/app/splash.rc index a5bb52fe5b2..bfff9f8dc0b 100644 --- a/mozilla/browser/app/splash.rc +++ b/mozilla/browser/app/splash.rc @@ -37,7 +37,7 @@ * * ***** END LICENSE BLOCK ***** */ #include -#include "nsINativeAppSupportWin.h" +#include "nsNativeAppSupportWin.h" 1 24 "firefox.exe.manifest" diff --git a/mozilla/browser/components/bookmarks/src/Makefile.in b/mozilla/browser/components/bookmarks/src/Makefile.in index 75e50f4eb1e..632858c95e4 100644 --- a/mozilla/browser/components/bookmarks/src/Makefile.in +++ b/mozilla/browser/components/bookmarks/src/Makefile.in @@ -33,6 +33,7 @@ REQUIRES = xpcom \ string \ rdf \ appshell \ + appcomps \ widget \ necko \ nkcache \ diff --git a/mozilla/browser/components/shell/src/Makefile.in b/mozilla/browser/components/shell/src/Makefile.in index 48b3420f242..8ca680168f3 100644 --- a/mozilla/browser/components/shell/src/Makefile.in +++ b/mozilla/browser/components/shell/src/Makefile.in @@ -35,6 +35,7 @@ REQUIRES = \ windowwatcher \ intl \ appshell \ + appcomps \ necko \ layout \ content \ diff --git a/mozilla/chrome/src/Makefile.in b/mozilla/chrome/src/Makefile.in index 30333c75aa2..91f13a0a4a6 100644 --- a/mozilla/chrome/src/Makefile.in +++ b/mozilla/chrome/src/Makefile.in @@ -49,6 +49,7 @@ REQUIRES = xpcom \ widget \ js \ appshell \ + appcomps \ caps \ pref \ docshell \ diff --git a/mozilla/editor/Makefile.in b/mozilla/editor/Makefile.in index beadad90e74..69a6bc2815c 100644 --- a/mozilla/editor/Makefile.in +++ b/mozilla/editor/Makefile.in @@ -45,10 +45,5 @@ include $(DEPTH)/config/autoconf.mk MODULE = editor DIRS = public idl txtsvc libeditor txmgr composer -# We need to export headers from composer/ even if we're not building composer. -ifdef MOZ_COMPOSER -DIRS += ui -endif - include $(topsrcdir)/config/rules.mk diff --git a/mozilla/editor/composer/src/Makefile.in b/mozilla/editor/composer/src/Makefile.in index 0d41266b483..2e8ac98c70e 100644 --- a/mozilla/editor/composer/src/Makefile.in +++ b/mozilla/editor/composer/src/Makefile.in @@ -82,7 +82,6 @@ CPPSRCS = \ nsComposerRegistration.cpp \ nsEditingSession.cpp \ nsComposerCommandsUpdater.cpp \ - nsEditorService.cpp \ nsEditorSpellCheck.cpp \ $(NULL) diff --git a/mozilla/editor/composer/src/nsComposerRegistration.cpp b/mozilla/editor/composer/src/nsComposerRegistration.cpp index f1821c9c08f..8d814089a8c 100644 --- a/mozilla/editor/composer/src/nsComposerRegistration.cpp +++ b/mozilla/editor/composer/src/nsComposerRegistration.cpp @@ -42,12 +42,13 @@ #include "nsEditingSession.h" // for the CID #include "nsComposerController.h" // for the CID #include "nsEditorSpellCheck.h" // for the CID -#include "nsEditorService.h" #include "nsComposeTxtSrvFilter.h" #include "nsIController.h" #include "nsIControllerContext.h" #include "nsIControllerCommandTable.h" +#include "nsIServiceManagerUtils.h" + #define NS_HTMLEDITOR_COMMANDTABLE_CID \ { 0x7a727843, 0x6ae1, 0x11d7, { 0xa5eb, 0x00, 0x03, 0x93, 0x63, 0x65, 0x92 } } @@ -66,7 +67,6 @@ static NS_DEFINE_CID(kHTMLEditorDocStateCommandTableCID, NS_HTMLEDITOR_DOCSTATE_ // NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditingSession) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorService) NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorSpellCheck) // There are no macros that enable us to have 2 constructors @@ -236,23 +236,10 @@ static const nsModuleComponentInfo components[] = { { "Editing Session", NS_EDITINGSESSION_CID, "@mozilla.org/editor/editingsession;1", nsEditingSessionConstructor, }, - { "Editor Service", NS_EDITORSERVICE_CID, - "@mozilla.org/editor/editorservice;1", nsEditorServiceConstructor,}, - { "Editor Spell Checker", NS_EDITORSPELLCHECK_CID, "@mozilla.org/editor/editorspellchecker;1", nsEditorSpellCheckConstructor,}, - { "Editor Startup Handler", NS_EDITORSERVICE_CID, - "@mozilla.org/commandlinehandler/general-startup;1?type=editor", - nsEditorServiceConstructor, - nsEditorService::RegisterProc, - nsEditorService::UnregisterProc, }, - - { "Edit Startup Handler", NS_EDITORSERVICE_CID, - "@mozilla.org/commandlinehandler/general-startup;1?type=edit", - nsEditorServiceConstructor, }, - { "TxtSrv Filter", NS_COMPOSERTXTSRVFILTER_CID, COMPOSER_TXTSRVFILTER_CONTRACTID, nsComposeTxtSrvFilterConstructorForComposer, }, diff --git a/mozilla/editor/ui/Makefile.in b/mozilla/editor/ui/Makefile.in index 52e961ad6c2..baa0d603516 100644 --- a/mozilla/editor/ui/Makefile.in +++ b/mozilla/editor/ui/Makefile.in @@ -44,6 +44,7 @@ include $(DEPTH)/config/autoconf.mk ifndef MOZ_STANDALONE_COMPOSER PREF_JS_EXPORTS = $(srcdir)/composer.js +EXTRA_COMPONENTS = nsComposerCmdLineHandler.js endif include $(topsrcdir)/config/rules.mk diff --git a/mozilla/editor/ui/nsComposerCmdLineHandler.js b/mozilla/editor/ui/nsComposerCmdLineHandler.js new file mode 100644 index 00000000000..f51dce549c2 --- /dev/null +++ b/mozilla/editor/ui/nsComposerCmdLineHandler.js @@ -0,0 +1,186 @@ +/* ***** 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 Mozilla Seamonkey Composer. + * + * 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 nsICmdLineHandler = Components.interfaces.nsICmdLineHandler; +const nsIFactory = Components.interfaces.nsIFactory; +const nsISupports = Components.interfaces.nsISupports; +const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar; +const nsICategoryManager = Components.interfaces.nsICategoryManager; + +const NS_ERROR_FAILURE = Components.results.NS_ERROR_FAILURE; +const NS_ERROR_NO_AGGREGATION = Components.results.NS_ERROR_NO_AGGREGATION; +const NS_ERROR_NO_INTERFACE = Components.results.NS_ERROR_NO_INTERFACE; + +function nsComposerCmdLineHandler() { +} + +nsComposerCmdLineHandler.prototype = { + /* nsISupports */ + + QueryInterface: function(iid) { + if (!iid.equals(nsICmdLineHandler) && + !iid.equals(nsISupports)) { + throw Components.results.NS_ERROR_NO_INTERFACE; + } + return this; + }, + + /* nsICmdLineHandler */ + + get commandLineArgument() { + return "-edit"; + }, + + get prefNameForStartup() { + return "general.startup.editor"; + }, + + get chromeUrlForTask() { + return "chrome://editor/content/editor.xul"; + }, + + get helpText() { + return "Start with editor." + }, + + get handlesArgs() { + return true; + }, + + get defaultArgs() { + return "about:blank"; + }, + + get openWindowWithArgs() { + return true; + } +}; + +function nsComposerCmdLineHandlerFactory() { +} + +nsComposerCmdLineHandlerFactory.prototype = { + /* nsISupports */ + + QueryInterface: function(iid) { + if (!iid.equals(nsIFactory) && + !iid.equals(nsISupports)) { + throw Components.results.NS_ERROR_NO_INTERFACE; + } + return this; + }, + + /* nsIFactory */ + + createInstance: function(outer, iid) { + if (outer != null) { + throw NS_ERROR_NO_AGGREGATION; + } + + return new nsComposerCmdLineHandler().QueryInterface(iid); + }, + + lockFactory: function(lock) { + } +}; + +const nsComposerCmdLineHandler_CID = + Components.ID("{f7d8db95-ab5d-4393-a796-9112fe758cfa}"); + +const ContractIDPrefix = + "@mozilla.org/commandlinehandler/general-startup;1?type="; + +var thisModule = { + /* nsISupports */ + + QueryInterface: function(iid) { + if (!iid.equals(nsIModule) && + !iid.equals(nsISupports)) { + throw Components.results.NS_ERROR_NO_INTERFACE; + } + return this; + }, + + /* nsIModule */ + + getClassObject: function (compMgr, cid, iid) { + if (!cid.equals(nsComposerCmdLineHandler_CID)) { + throw NS_ERROR_FAILURE; + } + + if (!iid.equals(nsIFactory)) { + throw NS_ERROR_NO_INTERFACE; + } + + return new nsComposerCmdLineHandlerFactory(); + }, + + registerSelf: function (compMgr, fileSpec, location, type) { + var compReg = compMgr.QueryInterface(nsIComponentRegistrar); + compReg.registerFactoryLocation(nsComposerCmdLineHandler_CID, + "nsComposerCmdLineHandler", + ContractIDPrefix + "edit", + fileSpec, location, type); + compReg.registerFactoryLocation(nsComposerCmdLineHandler_CID, + "nsComposerCmdLineHandler", + ContractIDPrefix + "editor", + fileSpec, location, type); + + var catMan = Components.classes["@mozilla.org/categorymanager;1"].getService(nsICategoryManager); + catMan.addCategoryEntry("command-line-argument-handlers", + "nsComposerCmdLineHandler", + ContractIDPrefix + "edit", + true, true); + }, + + unregisterSelf: function (compMgr, location, type) { + var compReg = compMgr.QueryInterface(nsIComponentRegistrar); + compReg.unregisterFactoryLocation(nsComposerCmdLineHandler_CID, + location); + + var catMan = Components.classes["@mozilla.org/categorymanager;1"].getService(nsICategoryManager); + catMan.deleteCategoryEntry("command-line-argument-handlers", + "nsComposerCmdLineHandler", true); + }, + + canUnload: function (compMgr) { + return true; + } +}; + +function NSGetModule(compMgr, fileSpec) { + return thisModule; +} diff --git a/mozilla/embedding/browser/activex/src/Makefile.in b/mozilla/embedding/browser/activex/src/Makefile.in index 8e753a7c057..9c1af1197a0 100644 --- a/mozilla/embedding/browser/activex/src/Makefile.in +++ b/mozilla/embedding/browser/activex/src/Makefile.in @@ -50,12 +50,11 @@ DIRS = $(NULL) # Common DIRS += common -# ActiveX control -DIRS += control control_kicker - # ActiveX plugin ifdef MOZ_ACTIVEX_SCRIPTING_SUPPORT DIRS += plugin endif +# The ActiveX control is now built in tier 99 from mozilla/Makefile.in + include $(topsrcdir)/config/rules.mk diff --git a/mozilla/extensions/pref/autoconfig/src/Makefile.in b/mozilla/extensions/pref/autoconfig/src/Makefile.in index 31077690e43..127f1b9f0b5 100644 --- a/mozilla/extensions/pref/autoconfig/src/Makefile.in +++ b/mozilla/extensions/pref/autoconfig/src/Makefile.in @@ -51,7 +51,18 @@ MODULE_NAME = nsAutoConfigModule PACKAGE_FILE = autoconfig.pkg -REQUIRES = xpcom string intl js xpconnect necko profile pref appshell embedcomponents windowwatcher +REQUIRES = xpcom \ + string \ + intl \ + js \ + xpconnect \ + necko \ + profile \ + pref \ + appcomps \ + embedcomponents \ + windowwatcher \ + $(NULL) include $(topsrcdir)/config/config.mk diff --git a/mozilla/extensions/pref/autoconfig/src/nsReadConfig.cpp b/mozilla/extensions/pref/autoconfig/src/nsReadConfig.cpp index 06eec6fc945..f6667273fa4 100644 --- a/mozilla/extensions/pref/autoconfig/src/nsReadConfig.cpp +++ b/mozilla/extensions/pref/autoconfig/src/nsReadConfig.cpp @@ -43,7 +43,7 @@ #endif #include "nsReadConfig.h" #include "nsAppDirectoryServiceDefs.h" -#include "nsIAppShellService.h" +#include "nsIAppStartup.h" #include "nsDirectoryServiceDefs.h" #include "nsIAutoConfig.h" #include "nsIComponentManager.h" @@ -54,6 +54,7 @@ #include "nsIPromptService.h" #include "nsIServiceManager.h" #include "nsIStringBundle.h" +#include "nsXPFEComponentsCID.h" #include "nsXPIDLString.h" #include "nsNetUtil.h" #include "prmem.h" @@ -141,10 +142,10 @@ NS_IMETHODIMP nsReadConfig::Observe(nsISupports *aSubject, const char *aTopic, c if (NS_FAILED(rv)) { DisplayError(); - nsCOMPtr appShellService = - do_GetService("@mozilla.org/appshell/appShellService;1"); - if (appShellService) - appShellService->Quit(nsIAppShellService::eAttemptQuit); + nsCOMPtr appStartup = + do_GetService(NS_APPSTARTUP_CONTRACTID); + if (appStartup) + appStartup->Quit(nsIAppStartup::eAttemptQuit); } } return rv; diff --git a/mozilla/extensions/pref/system-pref/src/nsSystemPref.cpp b/mozilla/extensions/pref/system-pref/src/nsSystemPref.cpp index 738b9589deb..69445d385da 100644 --- a/mozilla/extensions/pref/system-pref/src/nsSystemPref.cpp +++ b/mozilla/extensions/pref/system-pref/src/nsSystemPref.cpp @@ -105,7 +105,8 @@ nsSystemPref::Init(void) if (!gSysPrefLog) { gSysPrefLog = PR_NewLogModule("Syspref"); - PR_ASSERT(gSysPrefLog); + if (!gSysPrefLog) + return NS_ERROR_OUT_OF_MEMORY; } nsCOMPtr observerService = diff --git a/mozilla/mail/app/splash.rc b/mozilla/mail/app/splash.rc index 786e4b1934c..554a342b2e8 100644 --- a/mozilla/mail/app/splash.rc +++ b/mozilla/mail/app/splash.rc @@ -36,7 +36,7 @@ * * ***** END LICENSE BLOCK ***** */ #include -#include "nsINativeAppSupportWin.h" +#include "nsNativeAppSupportWin.h" 1 24 "thunderbird.exe.manifest" diff --git a/mozilla/mailnews/addrbook/build/Makefile.in b/mozilla/mailnews/addrbook/build/Makefile.in index 3517c55ed05..e6657a35aa2 100644 --- a/mozilla/mailnews/addrbook/build/Makefile.in +++ b/mozilla/mailnews/addrbook/build/Makefile.in @@ -62,6 +62,7 @@ REQUIRES = xpcom \ rdfutil \ docshell \ appshell \ + appcomps \ dom \ widget \ locale \ diff --git a/mozilla/mailnews/addrbook/src/Makefile.in b/mozilla/mailnews/addrbook/src/Makefile.in index babc22377da..ee04d813a1b 100644 --- a/mozilla/mailnews/addrbook/src/Makefile.in +++ b/mozilla/mailnews/addrbook/src/Makefile.in @@ -51,6 +51,7 @@ REQUIRES = xpcom \ rdf \ rdfutil \ appshell \ + appcomps \ dom \ layout \ widget \ diff --git a/mozilla/mailnews/addrbook/src/nsAddressBook.cpp b/mozilla/mailnews/addrbook/src/nsAddressBook.cpp index 609001bc0a5..81fefc5a76b 100644 --- a/mozilla/mailnews/addrbook/src/nsAddressBook.cpp +++ b/mozilla/mailnews/addrbook/src/nsAddressBook.cpp @@ -60,8 +60,6 @@ #include "nsRDFResource.h" #include "nsIRDFService.h" #include "nsIServiceManager.h" -#include "nsAppShellCIDs.h" -#include "nsIAppShellService.h" #include "nsIDOMWindowInternal.h" #include "nsIContentViewer.h" #include "nsIDocShell.h" diff --git a/mozilla/mailnews/base/build/Makefile.in b/mozilla/mailnews/base/build/Makefile.in index ec77540908a..e8a441d0756 100644 --- a/mozilla/mailnews/base/build/Makefile.in +++ b/mozilla/mailnews/base/build/Makefile.in @@ -77,6 +77,7 @@ REQUIRES = xpcom \ msgbaseutil \ msgdb \ appshell \ + appcomps \ msgnews \ msgimap \ gfx \ diff --git a/mozilla/mailnews/base/src/Makefile.in b/mozilla/mailnews/base/src/Makefile.in index 5fffad51703..8d19a70de6a 100644 --- a/mozilla/mailnews/base/src/Makefile.in +++ b/mozilla/mailnews/base/src/Makefile.in @@ -51,6 +51,7 @@ REQUIRES = xpcom \ necko \ dom \ appshell \ + appcomps \ uconv \ intl \ htmlparser \ diff --git a/mozilla/mailnews/base/src/nsMessengerWinIntegration.cpp b/mozilla/mailnews/base/src/nsMessengerWinIntegration.cpp index d5501a32927..3eb87e8b617 100644 --- a/mozilla/mailnews/base/src/nsMessengerWinIntegration.cpp +++ b/mozilla/mailnews/base/src/nsMessengerWinIntegration.cpp @@ -411,24 +411,24 @@ nsMessengerWinIntegration::Init() rv = profilePath->GetPath(mProfilePath); NS_ENSURE_SUCCESS(rv, rv); #else - // get current profile name to fill in commandliner. + // get current profile name to fill in commandliner. nsCOMPtr profileService = do_GetService(NS_PROFILE_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv,rv); + NS_ENSURE_SUCCESS(rv,rv); - profileService->GetCurrentProfile(getter_Copies(mProfileName)); + profileService->GetCurrentProfile(getter_Copies(mProfileName)); #endif - // get application path - char appPath[_MAX_PATH] = {0}; - GetModuleFileName(nsnull, appPath, sizeof(appPath)); - WCHAR wideFormatAppPath[_MAX_PATH*2] = {0}; - MultiByteToWideChar(CP_ACP, 0, appPath, strlen(appPath), wideFormatAppPath, _MAX_PATH*2); - mAppName.Assign((PRUnichar *)wideFormatAppPath); + // get application path + char appPath[_MAX_PATH] = {0}; + GetModuleFileName(nsnull, appPath, sizeof(appPath)); + WCHAR wideFormatAppPath[_MAX_PATH*2] = {0}; + MultiByteToWideChar(CP_ACP, 0, appPath, strlen(appPath), wideFormatAppPath, _MAX_PATH*2); + mAppName.Assign((PRUnichar *)wideFormatAppPath); - rv = ResetCurrent(); - NS_ENSURE_SUCCESS(rv,rv); + rv = ResetCurrent(); + NS_ENSURE_SUCCESS(rv,rv); - rv = SetupUnreadCountUpdateTimer(); + rv = SetupUnreadCountUpdateTimer(); } return NS_OK; diff --git a/mozilla/mailnews/compose/build/Makefile.in b/mozilla/mailnews/compose/build/Makefile.in index 85d5697e779..2dc253b4ad5 100644 --- a/mozilla/mailnews/compose/build/Makefile.in +++ b/mozilla/mailnews/compose/build/Makefile.in @@ -73,6 +73,7 @@ REQUIRES = xpcom \ widget \ msgdb \ appshell \ + appcomps \ nkcache \ $(NULL) diff --git a/mozilla/mailnews/compose/src/Makefile.in b/mozilla/mailnews/compose/src/Makefile.in index 3fb13eb73e9..f8cd6e840cb 100644 --- a/mozilla/mailnews/compose/src/Makefile.in +++ b/mozilla/mailnews/compose/src/Makefile.in @@ -66,6 +66,7 @@ REQUIRES = xpcom \ msgdb \ rdf \ appshell \ + appcomps \ msgimap \ msgnews \ docshell \ diff --git a/mozilla/mailnews/compose/src/nsMsgSend.cpp b/mozilla/mailnews/compose/src/nsMsgSend.cpp index 8bdb64ab7ab..74e37c31087 100644 --- a/mozilla/mailnews/compose/src/nsMsgSend.cpp +++ b/mozilla/mailnews/compose/src/nsMsgSend.cpp @@ -88,7 +88,6 @@ #include "nsTextFormatter.h" #include "nsIWebShell.h" #include "nsIPrompt.h" -#include "nsIAppShellService.h" #include "nsMailHeaders.h" #include "nsIDocShell.h" #include "nsMimeTypes.h" diff --git a/mozilla/mailnews/mapi/mapihook/src/Makefile.in b/mozilla/mailnews/mapi/mapihook/src/Makefile.in index 86042df8fca..287532834b5 100644 --- a/mozilla/mailnews/mapi/mapihook/src/Makefile.in +++ b/mozilla/mailnews/mapi/mapihook/src/Makefile.in @@ -54,6 +54,7 @@ REQUIRES = xpcom \ string \ MapiProxy \ appshell \ + appcomps \ windowwatcher \ dom \ profile \ diff --git a/mozilla/mailnews/mapi/mapihook/src/msgMapiHook.cpp b/mozilla/mailnews/mapi/mapihook/src/msgMapiHook.cpp index 95545cd15c6..d6f5d89d950 100644 --- a/mozilla/mailnews/mapi/mapihook/src/msgMapiHook.cpp +++ b/mozilla/mailnews/mapi/mapihook/src/msgMapiHook.cpp @@ -54,12 +54,11 @@ #include "nsIServiceManager.h" #include "nsISupports.h" #include "nsIPromptService.h" -#include "nsAppShellCIDs.h" -#include "nsIDOMWindowInternal.h" +#include "nsIAppStartup.h" #include "nsIAppShellService.h" +#include "nsIDOMWindowInternal.h" #include "nsINativeAppSupport.h" #include "nsICmdLineService.h" -#include "nsIProfileInternal.h" #include "nsIMsgAccountManager.h" #include "nsIDOMWindowInternal.h" #include "nsXPIDLString.h" @@ -74,6 +73,7 @@ #include "nsIMsgComposeParams.h" #include "nsIMsgCompose.h" #include "nsMsgCompCID.h" +#include "nsXPFEComponentsCID.h" #include "nsIMsgSend.h" #include "nsIProxyObjectManager.h" #include "nsIMsgComposeService.h" @@ -90,8 +90,6 @@ extern PRLogModuleInfo *MAPI; -static NS_DEFINE_CID(kCmdLineServiceCID, NS_COMMANDLINE_SERVICE_CID); - class nsMAPISendListener : public nsIMsgSendListener { public: @@ -160,20 +158,23 @@ PRBool nsMapiHook::isMapiService = PR_FALSE; PRBool nsMapiHook::Initialize() { +#ifndef MOZ_THUNDERBIRD nsresult rv; nsCOMPtr native; - nsCOMPtr cmdLineArgs(do_GetService(kCmdLineServiceCID, &rv)); + nsCOMPtr cmdLineArgs ( + do_GetService(NS_COMMANDLINESERVICE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return PR_FALSE; - nsCOMPtr appShell (do_GetService( "@mozilla.org/appshell/appShellService;1", &rv)); + nsCOMPtr appStartup (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv)); if (NS_FAILED(rv)) return PR_FALSE; - rv = appShell->GetNativeAppSupport( getter_AddRefs( native )); + rv = appStartup->GetNativeAppSupport(getter_AddRefs(native)); if (NS_FAILED(rv)) return PR_FALSE; rv = native->EnsureProfile(cmdLineArgs); if (NS_FAILED(rv)) return PR_FALSE; +#endif return PR_TRUE; } @@ -190,9 +191,6 @@ PRBool nsMapiHook::DisplayLoginDialog(PRBool aLogin, PRUnichar **aUsername, nsresult rv; PRBool btnResult = PR_FALSE; - nsCOMPtr appShell(do_GetService( "@mozilla.org/appshell/appShellService;1", &rv)); - if (NS_FAILED(rv) || !appShell) return PR_FALSE; - nsCOMPtr dlgService(do_GetService("@mozilla.org/embedcomp/prompt-service;1", &rv)); if (NS_SUCCEEDED(rv) && dlgService) { diff --git a/mozilla/mailnews/news/build/Makefile.in b/mozilla/mailnews/news/build/Makefile.in index 65df56636e6..f3b6a11b32d 100644 --- a/mozilla/mailnews/news/build/Makefile.in +++ b/mozilla/mailnews/news/build/Makefile.in @@ -59,6 +59,7 @@ REQUIRES = xpcom \ msgbaseutil \ msgdb \ appshell \ + appcomps \ mime \ necko \ rdf \ diff --git a/mozilla/mailnews/news/src/Makefile.in b/mozilla/mailnews/news/src/Makefile.in index b7bf2fa1f4c..6f4b0d9aa0e 100644 --- a/mozilla/mailnews/news/src/Makefile.in +++ b/mozilla/mailnews/news/src/Makefile.in @@ -62,6 +62,7 @@ REQUIRES = xpcom \ pref \ uriloader \ appshell \ + appcomps \ mime \ intl \ webshell \ diff --git a/mozilla/profile/build/Makefile.in b/mozilla/profile/build/Makefile.in index 41bf772a986..81e7b72b8dd 100644 --- a/mozilla/profile/build/Makefile.in +++ b/mozilla/profile/build/Makefile.in @@ -46,7 +46,6 @@ LIBRARY_NAME = profile EXPORT_LIBRARY = 1 IS_COMPONENT = 1 MODULE_NAME = nsProfileModule -GRE_MODULE = 1 PACKAGE_FILE = profile.pkg @@ -55,6 +54,7 @@ REQUIRES = xpcom \ string \ uriloader \ appshell \ + appcomps \ $(NULL) CPPSRCS = \ diff --git a/mozilla/profile/public/Makefile.in b/mozilla/profile/public/Makefile.in index 652322c83e3..5214ecb81eb 100644 --- a/mozilla/profile/public/Makefile.in +++ b/mozilla/profile/public/Makefile.in @@ -43,7 +43,6 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk MODULE = profile -GRE_MODULE = 1 SDK_XPIDLSRCS = \ nsIProfile.idl \ diff --git a/mozilla/profile/resources/content/profileSelection.js b/mozilla/profile/resources/content/profileSelection.js index f86ae51b1d6..b4417b64857 100644 --- a/mozilla/profile/resources/content/profileSelection.js +++ b/mozilla/profile/resources/content/profileSelection.js @@ -265,9 +265,9 @@ function onStart() if (fatalError) { - var appShellService = Components.classes["@mozilla.org/appshell/appShellService;1"] - .getService(Components.interfaces.nsIAppShellService); - appShellService.quit(Components.interfaces.nsIAppShellService.eForceQuit); + var appStartup = Components.classes["@mozilla.org/seamonkey/app-startup;1"] + .getService(Components.interfaces.nsIAppStartup); + appStartup.quit(Components.interfaces.nsIAppStartup.eForceQuit); } return false; diff --git a/mozilla/profile/src/Makefile.in b/mozilla/profile/src/Makefile.in index 0de85d87658..b77756f9b98 100644 --- a/mozilla/profile/src/Makefile.in +++ b/mozilla/profile/src/Makefile.in @@ -60,6 +60,7 @@ REQUIRES = xpcom \ pref \ prefmigr \ appshell \ + appcomps \ chrome \ uconv \ windowwatcher \ diff --git a/mozilla/toolkit/components/Makefile.in b/mozilla/toolkit/components/Makefile.in index 3a020ae162f..f19211feb0e 100644 --- a/mozilla/toolkit/components/Makefile.in +++ b/mozilla/toolkit/components/Makefile.in @@ -52,6 +52,7 @@ ifdef MOZ_SUNBIRD DIRS = autocomplete console filepicker help printing passwordmgr else DIRS = \ + startup \ autocomplete \ console \ filepicker \ diff --git a/mozilla/toolkit/components/build/Makefile.in b/mozilla/toolkit/components/build/Makefile.in index 34732fa4bac..2f1c23a52ef 100644 --- a/mozilla/toolkit/components/build/Makefile.in +++ b/mozilla/toolkit/components/build/Makefile.in @@ -36,6 +36,7 @@ MODULE_NAME = nsToolkitCompsModule REQUIRES = \ xpcom \ string \ + widget \ layout \ dom \ mork \ @@ -44,6 +45,7 @@ REQUIRES = \ intl \ docshell \ autocomplete \ + appcomps \ downloads \ mimetype \ webbrowserpersist \ @@ -54,6 +56,8 @@ REQUIRES = \ windowwatcher \ uriloader \ xpinstall \ + xulapp \ + embed_base \ $(NULL) ifeq ($(OS_ARCH),WINNT) @@ -70,6 +74,7 @@ LOCAL_INCLUDES = \ -I$(srcdir)/../history/src \ -I$(srcdir)/../satchel/src \ -I$(srcdir)/../passwordmgr/base \ + -I$(srcdir)/../startup/src \ $(NULL) ifeq ($(OS_ARCH),WINNT) @@ -77,6 +82,11 @@ LOCAL_INCLUDES += -I$(srcdir)/../alerts/src endif SHARED_LIBRARY_LIBS = \ + ../startup/src/$(LIB_PREFIX)appstartup_s.$(LIB_SUFFIX) \ + $(NULL) + +ifdef MOZ_PHOENIX +SHARED_LIBRARY_LIBS += \ $(DIST)/lib/$(LIB_PREFIX)autocomplete_s.$(LIB_SUFFIX) \ $(DIST)/lib/$(LIB_PREFIX)download_s.$(LIB_SUFFIX) \ $(DIST)/lib/$(LIB_PREFIX)history_s.$(LIB_SUFFIX) \ @@ -89,6 +99,7 @@ SHARED_LIBRARY_LIBS += $(DIST)/lib/$(LIB_PREFIX)alerts_s.$(LIB_SUFFIX) endif EXTRA_DSO_LIBS = gkgfx +endif # MOZ_PHOENIX EXTRA_DSO_LDOPTS += \ $(LIBS_DIR) \ @@ -98,4 +109,9 @@ EXTRA_DSO_LDOPTS += \ $(MOZ_JS_LIBS) \ $(NULL) +ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) +SHARED_LIBRARY_LIBS += $(DIST)/lib/$(LIB_PREFIX)appleevents_s.$(LIB_SUFFIX) +EXTRA_DSO_LDOPTS += $(TK_LIBS) +endif + include $(topsrcdir)/config/rules.mk diff --git a/mozilla/toolkit/components/build/nsModule.cpp b/mozilla/toolkit/components/build/nsModule.cpp index e6cc81b4188..cec4e5cee85 100644 --- a/mozilla/toolkit/components/build/nsModule.cpp +++ b/mozilla/toolkit/components/build/nsModule.cpp @@ -36,7 +36,12 @@ * ***** END LICENSE BLOCK ***** */ #include "nsIGenericFactory.h" +#include "nsAppStartup.h" +#include "nsUserInfo.h" +#include "nsCommandLineService.h" +#include "nsXPFEComponentsCID.h" +#ifdef MOZ_PHOENIX #ifdef XP_WIN #include "nsAlertsService.h" #endif @@ -51,9 +56,15 @@ #include "nsGlobalHistory.h" #include "nsPasswordManager.h" #include "nsSingleSignonPrompt.h" +#endif ///////////////////////////////////////////////////////////////////////////// +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsAppStartup, Init) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsUserInfo) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsCmdLineService) + +#ifdef MOZ_PHOENIX #ifdef XP_WIN NS_GENERIC_FACTORY_CONSTRUCTOR(nsAlertsService) #endif @@ -66,20 +77,39 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsFormFillController) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGlobalHistory, Init) NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsPasswordManager, nsPasswordManager::GetInstance) NS_GENERIC_FACTORY_CONSTRUCTOR(nsSingleSignonPrompt) +#endif ///////////////////////////////////////////////////////////////////////////// //// Module Destructor static void PR_CALLBACK nsToolkitCompModuleDtor(nsIModule* self) { +#ifdef MOZ_PHOENIX nsFormHistory::ReleaseInstance(); nsPasswordManager::Shutdown(); +#endif } ///////////////////////////////////////////////////////////////////////////// static const nsModuleComponentInfo components[] = { + { "App Startup Service", + NS_TOOLKIT_APPSTARTUP_CID, + NS_APPSTARTUP_CONTRACTID, + nsAppStartupConstructor }, + + { "User Info Service", + NS_USERINFO_CID, + NS_USERINFO_CONTRACTID, + nsUserInfoConstructor }, + + { "Command Line Service", + NS_COMMANDLINESERVICE_CID, + NS_COMMANDLINESERVICE_CONTRACTID, + nsCmdLineServiceConstructor }, + +#ifdef MOZ_PHOENIX #ifdef XP_WIN { "Alerts Service", NS_ALERTSSERVICE_CID, @@ -147,6 +177,7 @@ static const nsModuleComponentInfo components[] = NS_SINGLE_SIGNON_PROMPT_CID, "@mozilla.org/wallet/single-sign-on-prompt;1", nsSingleSignonPromptConstructor }, +#endif }; NS_IMPL_NSGETMODULE_WITH_DTOR(nsToolkitCompsModule, components, nsToolkitCompModuleDtor) diff --git a/mozilla/toolkit/components/startup/Makefile.in b/mozilla/toolkit/components/startup/Makefile.in new file mode 100644 index 00000000000..558695ca954 --- /dev/null +++ b/mozilla/toolkit/components/startup/Makefile.in @@ -0,0 +1,46 @@ +# ***** 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 Mozilla Seamonkey bootstrap code. +# +# 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 + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/toolkit/components/startup/public/Makefile.in b/mozilla/toolkit/components/startup/public/Makefile.in new file mode 100644 index 00000000000..343698ba23f --- /dev/null +++ b/mozilla/toolkit/components/startup/public/Makefile.in @@ -0,0 +1,57 @@ +# ***** 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 Mozilla Seamonkey bootstrap code. +# +# 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 + +# note: everything depends on appcomps, so to avoid confusion these IDL files are +# exported there, not toolkitcomps, which would be more logical +MODULE = appcomps +XPIDL_MODULE = appstartup + +XPIDLSRCS = \ + nsIAppStartup.idl \ + nsICloseAllWindows.idl \ + nsICmdLineHandler.idl \ + nsICmdLineService.idl \ + nsIUserInfo.idl \ + $(NULL) + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/toolkit/components/startup/public/nsIAppStartup.idl b/mozilla/toolkit/components/startup/public/nsIAppStartup.idl new file mode 100644 index 00000000000..993b39d92e3 --- /dev/null +++ b/mozilla/toolkit/components/startup/public/nsIAppStartup.idl @@ -0,0 +1,95 @@ +/* -*- Mode: IDL; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** 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 Mozilla Communicator client code, copied from + * xpfe/appshell/public/nsIAppShellService.idl + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1999 + * 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 nsICmdLineService; + +[scriptable, uuid(7877c9eb-ec6c-4214-9b59-48ee78f09eb9)] +interface nsIAppStartup : nsISupports +{ + /** + * Create the hidden window. + */ + void createHiddenWindow(); + + /** + * Runs an application event loop: normally the main event pump which + * defines the lifetime of the application. + */ + void run(); + + /** + * During application startup (and at other times!) we may temporarily + * encounter a situation where all application windows will be closed + * but we don't want to take this as a signal to quit the app. Bracket + * the code where the last window could close with these. + * (And at application startup, on platforms that don't normally quit + * when the last window has closed, call Enter once, but not Exit) + */ + void enterLastWindowClosingSurvivalArea(); + void exitLastWindowClosingSurvivalArea(); + + const PRUint32 eConsiderQuit = 1; // attempt to quit if all windows are closed + const PRUint32 eAttemptQuit = 2; // try to close all windows, then quit if successful + const PRUint32 eForceQuit = 3; // quit, damnit + + /** + * 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/xpfe/bootstrap/nsWindowCreator.h b/mozilla/toolkit/components/startup/public/nsICloseAllWindows.idl similarity index 75% rename from mozilla/xpfe/bootstrap/nsWindowCreator.h rename to mozilla/toolkit/components/startup/public/nsICloseAllWindows.idl index 5d782f1a8ab..127b0c9a223 100644 --- a/mozilla/xpfe/bootstrap/nsWindowCreator.h +++ b/mozilla/toolkit/components/startup/public/nsICloseAllWindows.idl @@ -20,10 +20,11 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * Conrad Carlen * * Alternatively, the contents of this file may be used under the terms of - * either of 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"), + * 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 @@ -35,22 +36,15 @@ * * ***** END LICENSE BLOCK ***** */ -#ifndef __nsWindowCreator_h_ -#define __nsWindowCreator_h_ +#include "nsISupports.idl" -#include "nsIWindowCreator2.h" - -class nsWindowCreator : - public nsIWindowCreator2 +[scriptable, uuid(2f977d49-5485-11d4-87e2-0010a4e75ef2)] +interface nsICloseAllWindows : nsISupports { -public: - nsWindowCreator(); - virtual ~nsWindowCreator(); - - NS_DECL_ISUPPORTS - NS_DECL_NSIWINDOWCREATOR - NS_DECL_NSIWINDOWCREATOR2 + /** + * Closes all open windows, optionally asking to confirm changes if any. + * @return TRUE if the user does not cancel from any confirmation dialog. + */ + boolean closeAll(in boolean askSave); }; -#endif - diff --git a/mozilla/toolkit/components/startup/public/nsICmdLineHandler.idl b/mozilla/toolkit/components/startup/public/nsICmdLineHandler.idl new file mode 100644 index 00000000000..73ff5d975c1 --- /dev/null +++ b/mozilla/toolkit/components/startup/public/nsICmdLineHandler.idl @@ -0,0 +1,207 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Seth Spitzer + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" + + +%{C++ + +#define COMMAND_LINE_ARGUMENT_HANDLERS "command-line-argument-handlers" +#define PREF_STARTUP_PREFIX "general.startup." + +#include "nsCOMPtr.h" +#include "nsIComponentManager.h" +#include "nsICategoryManager.h" +#include "nsIFile.h" +#include "nsXPIDLString.h" +#include "nsReadableUtils.h" +#include "nsIServiceManager.h" + +struct nsModuleComponentInfo; // forward declaration + +#define CMDLINEHANDLER_REGISTERPROC_DECLS \ +static NS_METHOD RegisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const char *componentType, const nsModuleComponentInfo *info); \ +static NS_METHOD UnregisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const nsModuleComponentInfo *info); + +#define CMDLINEHANDLER_GETDEFAULTARGS_IMPL(macro_class,macro_default_args)\ +NS_IMETHODIMP macro_class::GetDefaultArgs(PRUnichar **aDefaultArgs) \ +{ \ + if (!aDefaultArgs) return NS_ERROR_FAILURE; \ + *aDefaultArgs = ToNewUnicode(nsDependentCString(macro_default_args)); \ + return NS_OK; \ +} + +#define CMDLINEHANDLER_GETCHROMEURL_IMPL(macro_class,macro_chrome_url)\ +NS_IMETHODIMP macro_class::GetChromeUrlForTask(char **aChromeUrlForTask) \ +{ \ + if (!aChromeUrlForTask) return NS_ERROR_FAILURE; \ + *aChromeUrlForTask = PL_strdup(macro_chrome_url); \ + return NS_OK; \ +} + +#define CMDLINEHANDLER_OTHERS_IMPL(macro_class,macro_cmd_line_arg,macro_pref_name,macro_help_text, macro_handles_args, macro_open_window_with_args)\ +NS_IMETHODIMP macro_class::GetCommandLineArgument(char **aCommandLineArgument) \ +{ \ + if (!aCommandLineArgument) return NS_ERROR_FAILURE; \ + *aCommandLineArgument = PL_strdup(macro_cmd_line_arg); \ + return NS_OK; \ +} \ +NS_IMETHODIMP macro_class::GetPrefNameForStartup(char **aPrefNameForStartup) \ +{ \ + if (!aPrefNameForStartup) return NS_ERROR_FAILURE; \ + *aPrefNameForStartup = PL_strdup(macro_pref_name); \ + return NS_OK; \ +} \ +NS_IMETHODIMP macro_class::GetHelpText(char **aHelpText) \ +{ \ + if (!aHelpText) return NS_ERROR_FAILURE; \ + *aHelpText = PL_strdup(macro_help_text); \ + return NS_OK; \ +} \ +NS_IMETHODIMP macro_class::GetHandlesArgs(PRBool *aHandlesArgs) \ +{ \ + if (!aHandlesArgs) return NS_ERROR_FAILURE; \ + *aHandlesArgs = macro_handles_args; \ + return NS_OK; \ +} \ +NS_IMETHODIMP macro_class::GetOpenWindowWithArgs(PRBool *aOpenWindowWithArgs) \ +{ \ + if (!aOpenWindowWithArgs) return NS_ERROR_FAILURE; \ + *aOpenWindowWithArgs = macro_open_window_with_args; \ + return NS_OK; \ +} + +#define CMDLINEHANDLER_REGISTERPROC_IMPL(macro_class, \ + macro_pretty_name, \ + macro_contractid) \ +NS_METHOD macro_class::RegisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const char *componentType, const nsModuleComponentInfo *info) \ +{ \ + nsresult rv; \ + nsCOMPtr catman = do_GetService("@mozilla.org/categorymanager;1", &rv); \ + if (NS_FAILED(rv)) return rv; \ + nsXPIDLCString prevEntry; \ + rv = catman->AddCategoryEntry(COMMAND_LINE_ARGUMENT_HANDLERS, macro_pretty_name, macro_contractid, PR_TRUE, PR_TRUE, getter_Copies(prevEntry)); \ + return NS_OK; \ +} \ +NS_METHOD macro_class::UnregisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *registryLocation, const nsModuleComponentInfo *info) \ +{ \ + nsresult rv; \ + nsCOMPtr catman = do_GetService("@mozilla.org/categorymanager;1", &rv); \ + if (NS_FAILED(rv)) return rv; \ + rv = catman->DeleteCategoryEntry(COMMAND_LINE_ARGUMENT_HANDLERS, macro_contractid, PR_TRUE); \ + return NS_OK; \ +} + +// basic definition +#define CMDLINEHANDLER1_IMPL(macro_class, \ + macro_cmd_line_arg, \ + macro_pref_name, \ + macro_help_text, \ + macro_handles_args, \ + macro_default_args, \ + macro_open_window_with_args)\ +CMDLINEHANDLER_OTHERS_IMPL(macro_class, macro_cmd_line_arg,macro_pref_name,\ + macro_help_text, macro_handles_args, \ + macro_open_window_with_args) + +// provides everything above, plus GetChromeUrl and regproc stuff +#define CMDLINEHANDLER2_IMPL(macro_class, \ + macro_cmd_line_arg, \ + macro_pref_name, \ + macro_chrome_url, \ + macro_help_text, \ + macro_contractid, \ + macro_pretty_name, \ + macro_handles_args, \ + macro_open_window_with_args) \ +CMDLINEHANDLER_OTHERS_IMPL(macro_class,macro_cmd_line_arg,macro_pref_name,\ + macro_help_text, macro_handles_args, \ + macro_open_window_with_args) \ +CMDLINEHANDLER_REGISTERPROC_IMPL(macro_class, macro_pretty_name, \ + macro_contractid) \ +CMDLINEHANDLER_GETCHROMEURL_IMPL(macro_class,macro_chrome_url) + +// deprecated: includes everything above, plus getdefaultargs +#define CMDLINEHANDLER_IMPL(macro_class, \ + macro_cmd_line_arg,\ + macro_pref_name, \ + macro_chrome_url,\ + macro_help_text, \ + macro_contractid, \ + macro_pretty_name, \ + macro_handles_args, \ + macro_default_args, \ + macro_open_window_with_args) \ +CMDLINEHANDLER_GETDEFAULTARGS_IMPL(macro_class,macro_default_args) \ +CMDLINEHANDLER2_IMPL(macro_class,macro_cmd_line_arg,macro_pref_name, \ + macro_chrome_url,macro_help_text, macro_contractid, \ + macro_pretty_name, macro_handles_args, \ + macro_open_window_with_args) + +//Creates a version without the GetChromeUrlForTaskFunction +#define CMDLINEHANDLER3_IMPL(macro_class, \ + macro_cmd_line_arg, \ + macro_pref_name, \ + macro_help_text, \ + macro_contractid, \ + macro_pretty_name, \ + macro_handles_args, \ + macro_default_args, \ + macro_open_window_with_args)\ +CMDLINEHANDLER_GETDEFAULTARGS_IMPL(macro_class,macro_default_args)\ +CMDLINEHANDLER_OTHERS_IMPL(macro_class,macro_cmd_line_arg,macro_pref_name,\ + macro_help_text, macro_handles_args, \ + macro_open_window_with_args) \ +CMDLINEHANDLER_REGISTERPROC_IMPL(macro_class, macro_pretty_name, \ + macro_contractid) + +%} + +[scriptable, uuid(54e1a910-c064-4756-b1d3-82c6b2e0be24)] +interface nsICmdLineHandler : nsISupports +{ + readonly attribute string commandLineArgument; + readonly attribute string prefNameForStartup; + readonly attribute string chromeUrlForTask; + readonly attribute string helpText; + + readonly attribute boolean handlesArgs; + readonly attribute wstring defaultArgs; + readonly attribute boolean openWindowWithArgs; +}; + diff --git a/mozilla/toolkit/components/startup/public/nsICmdLineService.idl b/mozilla/toolkit/components/startup/public/nsICmdLineService.idl new file mode 100644 index 00000000000..38f94a6b4ce --- /dev/null +++ b/mozilla/toolkit/components/startup/public/nsICmdLineService.idl @@ -0,0 +1,94 @@ +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" +#include "nsIFactory.idl" +#include "nsICmdLineHandler.idl" + +[ptr] native charArray(char*); +[scriptable, uuid(e34783f4-ac08-11d2-8d19-00805fc2500c)] +interface nsICmdLineService : nsISupports +{ + /** + * initialize + * Used to pass the original argv/argc from main() + * Warning: This will hold a reference to the original argv + * passed into Initialze(); + */ + [noscript] void initialize(in long argc, out string argv); + + /** + * getCmdLineValue + * returns the 2nd parameter, if any, to the parameter passed in + * For example, getCmdLineValue "-edit" will return any url that + * came after the -edit parameter + */ + string getCmdLineValue(in string argv); + + /** + * URLToLoad + * The URL to load as passed to the command line + */ + readonly attribute string URLToLoad; + + /** + * programName + * + */ + readonly attribute string programName; + + /** + * argc + * The number of parameters passed in on the command line + */ + readonly attribute long argc; + + /** + * argv + * returns a direct reference to the parameter array passed in + * to initialize() - do NOT dereference this array! + */ + [noscript] readonly attribute charArray argv; + + /** + * Get the command line handler for the given parameter + * @param param - can be any parameter, with or without leading + * "-" such as "-mail" or "edit" - Pass in a null + * string if you want the "default" handler + */ + nsICmdLineHandler getHandlerForParam(in string param); +}; diff --git a/mozilla/toolkit/components/startup/public/nsIUserInfo.idl b/mozilla/toolkit/components/startup/public/nsIUserInfo.idl new file mode 100644 index 00000000000..f1e0df4d214 --- /dev/null +++ b/mozilla/toolkit/components/startup/public/nsIUserInfo.idl @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Seth Spitzer + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" + +[scriptable, uuid(6c1034f0-1dd2-11b2-aa14-e6657ed7bb0b)] +interface nsIUserInfo : nsISupports +{ + /* these are things the system may know about the current user */ + + readonly attribute wstring fullname; + + readonly attribute string emailAddress; + + /* should this be a wstring? */ + readonly attribute string username; + + readonly attribute string domain; +}; + +%{C++ + +// 14c13684-1dd2-11b2-9463-bb10ba742554 +#define NS_USERINFO_CID \ +{ 0x14c13684, 0x1dd2, 0x11b2, \ + {0x94, 0x63, 0xbb, 0x10, 0xba, 0x74, 0x25, 0x54}} + +#define NS_USERINFO_CONTRACTID "@mozilla.org/userinfo;1" + +%} diff --git a/mozilla/toolkit/components/startup/src/Makefile.in b/mozilla/toolkit/components/startup/src/Makefile.in new file mode 100644 index 00000000000..0ab2abb8985 --- /dev/null +++ b/mozilla/toolkit/components/startup/src/Makefile.in @@ -0,0 +1,98 @@ +# ***** 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 Mozilla Seamonkey bootstrap code. +# +# 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 +LIBRARY_NAME = appstartup_s +FORCE_STATIC_LIB = 1 + +REQUIRES = \ + xpcom \ + string \ + js \ + widget \ + appshell \ + appcomps \ + docshell \ + exthandler \ + webshell \ + dom \ + necko \ + pref \ + profile \ + embed_base \ + webbrwsr \ + windowwatcher \ + intl \ + util \ + uconv \ + xulapp \ + $(NULL) + +CPPSRCS = \ + nsAppStartup.cpp \ + nsCommandLineService.cpp \ + $(NULL) + +ifeq (os2,$(MOZ_WIDGET_TOOLKIT)) +CPPSRCS += nsUserInfoOS2.cpp +else +ifeq (WINNT,$(OS_ARCH)) +CPPSRCS += nsUserInfoWin.cpp +else +ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) +CPPSRCS += \ + nsUserInfoMac.cpp \ + nsCommandLineServiceMac.cpp \ + $(NULL) + +LOCAL_INCLUDES += -I$(topsrcdir)/xpfe/bootstrap/appleevents +OS_CXXFLAGS += -fexceptions +else +CPPSRCS += nsUserInfoUnix.cpp +endif +endif +endif + +EXTRA_COMPONENTS = nsCloseAllWindows.js + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/toolkit/components/startup/src/nsAppStartup.cpp b/mozilla/toolkit/components/startup/src/nsAppStartup.cpp new file mode 100644 index 00000000000..d006fa34674 --- /dev/null +++ b/mozilla/toolkit/components/startup/src/nsAppStartup.cpp @@ -0,0 +1,828 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** 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 Mozilla Communicator client code. This file was split + * from xpfe/appshell/src/nsAppShellService.cpp + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Pierre Phaneuf + * Robert O'Callahan + * Benjamin Smedberg + * + * Alternatively, the contents of this file may be used under the terms of + * either of 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 "nsAppStartup.h" + +#include "nsIAppShellService.h" +#include "nsICharsetConverterManager.h" +#include "nsICloseAllWindows.h" +#include "nsIDOMWindowInternal.h" +#include "nsIEventQueue.h" +#include "nsIEventQueueService.h" +#include "nsIInterfaceRequestor.h" +#include "nsILocalFile.h" +#include "nsIObserverService.h" +#include "nsIPlatformCharset.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" +#include "nsIProfileChangeStatus.h" +#include "nsIPromptService.h" +#include "nsIStringBundle.h" +#include "nsISupportsPrimitives.h" +#include "nsITimelineService.h" +#include "nsIUnicodeDecoder.h" +#include "nsIWebBrowserChrome.h" +#include "nsIWebShellWindow.h" +#include "nsIWindowMediator.h" +#include "nsIWindowWatcher.h" +#include "nsIXULWindow.h" + +#include "prprf.h" +#include "nsCRT.h" +#include "nsIInterfaceRequestorUtils.h" +#include "nsWidgetsCID.h" +#include "nsAppShellCID.h" +#include "nsXPFEComponentsCID.h" + +NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID); + +// Static Function Prototypes +static nsresult ConvertToUnicode(nsCString& aCharset, const char* inString, nsAString& outString); + +// +// nsAppStartup +// + +nsAppStartup::nsAppStartup() : + mConsiderQuitStopper(0), + mShuttingDown(PR_FALSE), + mAttemptingQuit(PR_FALSE) +{ } + + +nsresult +nsAppStartup::Init() +{ + nsresult rv; + + // Create widget application shell + mAppShell = do_CreateInstance(kAppShellCID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr cmdLineService + (do_GetService(NS_COMMANDLINESERVICE_CONTRACTID, &rv)); + NS_ENSURE_SUCCESS(rv, rv); + + PRInt32 argc = 0; + char** argv = nsnull; + cmdLineService->GetArgc(&argc); + cmdLineService->GetArgv(&argv); + + rv = mAppShell->Create(&argc, argv); + NS_ENSURE_SUCCESS(rv, rv); + + // listen to EventQueues' comings and goings. do this after the appshell + // has been created, but after the event queue has been created. that + // latter bit is unfortunate, but we deal with it. + nsCOMPtr os + (do_GetService("@mozilla.org/observer-service;1", &rv)); + NS_ENSURE_SUCCESS(rv, rv); + + 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); + + return NS_OK; +} + + +// +// nsAppStartup->nsISupports +// + +NS_IMPL_THREADSAFE_ISUPPORTS5(nsAppStartup, + nsIAppStartup, + nsIWindowCreator, + nsIWindowCreator2, + nsIObserver, + nsISupportsWeakReference) + + +// +// nsAppStartup->nsIAppStartup +// + +NS_IMETHODIMP +nsAppStartup::CreateHiddenWindow() +{ + nsCOMPtr appShellService + (do_GetService(NS_APPSHELLSERVICE_CONTRACTID)); + NS_ENSURE_TRUE(appShellService, NS_ERROR_FAILURE); + + return appShellService->CreateHiddenWindow(mAppShell); +} + + +NS_IMETHODIMP +nsAppStartup::Run(void) +{ + return mAppShell->Run(); +} + + +NS_IMETHODIMP +nsAppStartup::Quit(PRUint32 aFerocity) +{ + // Quit the application. We will asynchronously call the appshell's + // Exit() method via the ExitCallback() to allow one last pass + // through any events in the queue. This guarantees a tidy cleanup. + nsresult rv = NS_OK; + PRBool postedExitEvent = PR_FALSE; + + if (mShuttingDown) + return NS_OK; + + /* eForceQuit doesn't actually work; it can cause a subtle crash if + there are windows open which have unload handlers which open + new windows. Use eAttemptQuit for now. */ + if (aFerocity == eForceQuit) { + NS_WARNING("attempted to force quit"); + // it will be treated the same as eAttemptQuit, below + } + + mShuttingDown = PR_TRUE; + + nsCOMPtr mediator + (do_GetService(NS_WINDOWMEDIATOR_CONTRACTID)); + + if (aFerocity == eConsiderQuit && mConsiderQuitStopper == 0) { + // attempt quit if the last window has been unregistered/closed + + PRBool windowsRemain = PR_TRUE; + + if (mediator) { + nsCOMPtr windowEnumerator; + mediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator)); + if (windowEnumerator) + windowEnumerator->HasMoreElements(&windowsRemain); + } + if (!windowsRemain) { + aFerocity = eAttemptQuit; + } + } + + /* Currently aFerocity can never have the value of eForceQuit here. + That's temporary (in an unscheduled kind of way) and logically + this code is part of the eForceQuit case, so I'm checking against + that value anyway. Reviewers made me add this comment. */ + if (aFerocity == eAttemptQuit || aFerocity == eForceQuit) { + + AttemptingQuit(PR_TRUE); + + /* Enumerate through each open window and close it. It's important to do + this before we forcequit because this can control whether we really quit + at all. e.g. if one of these windows has an unload handler that + opens a new window. Ugh. I know. */ + if (mediator) { + nsCOMPtr windowEnumerator; + + mediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator)); + + if (windowEnumerator) { + + while (1) { + PRBool more; + if (NS_FAILED(rv = windowEnumerator->HasMoreElements(&more)) || !more) + break; + + nsCOMPtr isupports; + rv = windowEnumerator->GetNext(getter_AddRefs(isupports)); + if (NS_FAILED(rv)) + break; + + nsCOMPtr window = do_QueryInterface(isupports); + NS_ASSERTION(window, "not an nsIDOMWindowInternal"); + if (!window) + continue; + + window->Close(); + } + } + + if (aFerocity == eAttemptQuit) { + + aFerocity = eForceQuit; // assume success + + /* Were we able to immediately close all windows? if not, eAttemptQuit + failed. This could happen for a variety of reasons; in fact it's + very likely. Perhaps we're being called from JS and the window->Close + method hasn't had a chance to wrap itself up yet. So give up. + We'll return (with eConsiderQuit) as the remaining windows are + closed. */ + mediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator)); + if (windowEnumerator) { + PRBool more; + while (windowEnumerator->HasMoreElements(&more), more) { + /* we can't quit immediately. we'll try again as the last window + finally closes. */ + aFerocity = eAttemptQuit; + nsCOMPtr window; + windowEnumerator->GetNext(getter_AddRefs(window)); + nsCOMPtr domWindow(do_QueryInterface(window)); + if (domWindow) { + PRBool closed = PR_FALSE; + domWindow->GetClosed(&closed); + if (!closed) { + rv = NS_ERROR_FAILURE; + break; + } + } + } + } + } + } + } + + if (aFerocity == eForceQuit) { + // do it! + + // No chance of the shutdown being cancelled from here on; tell people + // we're shutting down for sure while all services are still available. + nsCOMPtr obsService + (do_GetService("@mozilla.org/observer-service;1")); + if (obsService) + obsService->NotifyObservers(nsnull, "quit-application", nsnull); + + nsCOMPtr appShellService + (do_GetService(NS_APPSHELLSERVICE_CONTRACTID)); + NS_ASSERTION(appShellService, "We're gonna leak something."); + if (appShellService) + appShellService->DestroyHiddenWindow(); + + // no matter what, make sure we send the exit event. If + // worst comes to worst, we'll do a leaky shutdown but we WILL + // shut down. Well, assuming that all *this* stuff works ;-). + nsCOMPtr svc = do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + + nsCOMPtr queue; + rv = svc->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(queue)); + if (NS_SUCCEEDED(rv)) { + + PLEvent* event = new PLEvent; + if (event) { + NS_ADDREF_THIS(); + PL_InitEvent(event, + this, + HandleExitEvent, + DestroyExitEvent); + + rv = queue->PostEvent(event); + if (NS_SUCCEEDED(rv)) { + postedExitEvent = PR_TRUE; + } + else { + PL_DestroyEvent(event); + } + } + else { + rv = NS_ERROR_OUT_OF_MEMORY; + } + } + } + } + + // turn off the reentrancy check flag, but not if we have + // more asynchronous work to do still. + if (!postedExitEvent) + mShuttingDown = PR_FALSE; + return rv; +} + + +/* We know we're trying to quit the app, but may not be able to do so + immediately. Enter a state where we're more ready to quit. + (Does useful work only on the Mac.) */ +void +nsAppStartup::AttemptingQuit(PRBool aAttempt) +{ +#if defined(XP_MAC) || defined(XP_MACOSX) + if (aAttempt) { + // now even the Mac wants to quit when the last window is closed + if (!mAttemptingQuit) + ExitLastWindowClosingSurvivalArea(); + mAttemptingQuit = PR_TRUE; + } else { + // changed our mind. back to normal. + if (mAttemptingQuit) + EnterLastWindowClosingSurvivalArea(); + mAttemptingQuit = PR_FALSE; + } +#else + mAttemptingQuit = aAttempt; +#endif +} + +NS_IMETHODIMP +nsAppStartup::EnterLastWindowClosingSurvivalArea(void) +{ + ++mConsiderQuitStopper; + return NS_OK; +} + + +NS_IMETHODIMP +nsAppStartup::ExitLastWindowClosingSurvivalArea(void) +{ + NS_ASSERTION(mConsiderQuitStopper > 0, "consider quit stopper out of bounds"); + --mConsiderQuitStopper; + return NS_OK; +} + + +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) +{ + nsAppStartup *service = + NS_REINTERPRET_CAST(nsAppStartup*, aEvent->owner); + + // Tell the appshell to exit + service->mAppShell->Exit(); + + // We're done "shutting down". + service->mShuttingDown = PR_FALSE; + + return nsnull; +} + +void PR_CALLBACK +nsAppStartup::DestroyExitEvent(PLEvent* aEvent) +{ + nsAppStartup *service = + NS_REINTERPRET_CAST(nsAppStartup*, aEvent->owner); + NS_RELEASE(service); + delete 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, nsString(), 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; + if (nsCRT::IsAscii(urlToLoad)) { + url.AssignWithConversion(urlToLoad); + } + else { + // get a platform charset + nsCAutoString charSet; + nsCOMPtr platformCharset(do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv)); + if (NS_FAILED(rv)) { + NS_ASSERTION(0, "Failed to get a platform charset"); + return rv; + } + + rv = platformCharset->GetCharset(kPlatformCharsetSel_FileName, charSet); + if (NS_FAILED(rv)) { + NS_ASSERTION(0, "Failed to get a charset"); + return rv; + } + + // convert the cmdLine URL to Unicode + rv = ConvertToUnicode(charSet, urlToLoad, url); + if (NS_FAILED(rv)) { + NS_ASSERTION(0, "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 +// + +NS_IMETHODIMP +nsAppStartup::CreateChromeWindow(nsIWebBrowserChrome *aParent, + PRUint32 aChromeFlags, + nsIWebBrowserChrome **_retval) +{ + PRBool cancel; + return CreateChromeWindow2(aParent, aChromeFlags, 0, 0, &cancel, _retval); +} + + +// +// nsAppStartup->nsIWindowCreator2 +// + +NS_IMETHODIMP +nsAppStartup::CreateChromeWindow2(nsIWebBrowserChrome *aParent, + PRUint32 aChromeFlags, + PRUint32 aContextFlags, + nsIURI *aURI, + PRBool *aCancel, + nsIWebBrowserChrome **_retval) +{ + NS_ENSURE_ARG_POINTER(aCancel); + NS_ENSURE_ARG_POINTER(_retval); + *aCancel = PR_FALSE; + *_retval = 0; + + nsCOMPtr newWindow; + + if (aParent) { + nsCOMPtr xulParent(do_GetInterface(aParent)); + NS_ASSERTION(xulParent, "window created using non-XUL parent. that's unexpected, but may work."); + + if (xulParent) + xulParent->CreateNewWindow(aChromeFlags, mAppShell, getter_AddRefs(newWindow)); + // And if it fails, don't try again without a parent. It could fail + // intentionally (bug 115969). + } else { // try using basic methods: + /* You really shouldn't be making dependent windows without a parent. + But unparented modal (and therefore dependent) windows happen + in our codebase, so we allow it after some bellyaching: */ + if (aChromeFlags & nsIWebBrowserChrome::CHROME_DEPENDENT) + NS_WARNING("dependent window created without a parent"); + + nsCOMPtr appShell(do_GetService(NS_APPSHELLSERVICE_CONTRACTID)); + if (!appShell) + return NS_ERROR_FAILURE; + + appShell->CreateTopLevelWindow(0, 0, PR_FALSE, PR_FALSE, + aChromeFlags, nsIAppShellService::SIZE_TO_CONTENT, + nsIAppShellService::SIZE_TO_CONTENT, mAppShell, getter_AddRefs(newWindow)); + } + + // if anybody gave us anything to work with, use it + if (newWindow) { + newWindow->SetContextFlags(aContextFlags); + nsCOMPtr thing(do_QueryInterface(newWindow)); + if (thing) + CallGetInterface(thing.get(), _retval); + } + + return *_retval ? NS_OK : NS_ERROR_FAILURE; +} + + +// +// nsAppStartup->nsIObserver +// + +NS_IMETHODIMP +nsAppStartup::Observe(nsISupports *aSubject, + const char *aTopic, const PRUnichar *aData) +{ + NS_ASSERTION(mAppShell, "appshell service notified before appshell built"); + if (!strcmp(aTopic, "nsIEventQueueActivated")) { + nsCOMPtr eq(do_QueryInterface(aSubject)); + if (eq) { + PRBool isNative = PR_TRUE; + // we only add native event queues to the appshell + eq->IsQueueNative(&isNative); + if (isNative) + mAppShell->ListenToEventQueue(eq, PR_TRUE); + } + } else if (!strcmp(aTopic, "nsIEventQueueDestroyed")) { + nsCOMPtr eq(do_QueryInterface(aSubject)); + if (eq) { + PRBool isNative = PR_TRUE; + // we only remove native event queues from the appshell + eq->IsQueueNative(&isNative); + if (isNative) + mAppShell->ListenToEventQueue(eq, PR_FALSE); + } + } else if (!strcmp(aTopic, "profile-change-teardown")) { + nsresult rv; + EnterLastWindowClosingSurvivalArea(); + // NOTE: No early error exits because we need to execute the + // balancing ExitLastWindowClosingSurvivalArea(). + nsCOMPtr closer = + do_CreateInstance("@mozilla.org/appshell/closeallwindows;1", &rv); + NS_ASSERTION(closer, "Failed to create nsICloseAllWindows impl."); + PRBool proceedWithSwitch = PR_FALSE; + if (closer) + rv = closer->CloseAll(PR_TRUE, &proceedWithSwitch); + + if (NS_FAILED(rv) || !proceedWithSwitch) { + nsCOMPtr changeStatus(do_QueryInterface(aSubject)); + if (changeStatus) + 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")) { + Quit(eConsiderQuit); + } else { + NS_ERROR("Unexpected observer topic."); + } + + return NS_OK; +} + +static nsresult +ConvertToUnicode(nsCString& aCharset, const char* inString, nsAString& outString) +{ + nsresult rv; + + // convert result to unicode + nsCOMPtr ccm(do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID , &rv)); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr decoder; + rv = ccm->GetUnicodeDecoderRaw(aCharset.get(), getter_AddRefs(decoder)); + if (NS_FAILED(rv)) + return rv; + + PRInt32 uniLength = 0; + PRInt32 srcLength = strlen(inString); + rv = decoder->GetMaxLength(inString, srcLength, &uniLength); + if (NS_FAILED(rv)) + return rv; + + PRUnichar *unichars = new PRUnichar [uniLength]; + if (nsnull != unichars) { + // convert to unicode + rv = decoder->Convert(inString, &srcLength, unichars, &uniLength); + if (NS_SUCCEEDED(rv)) { + // Pass back the unicode string + outString.Assign(unichars, uniLength); + } + delete [] unichars; + } + else { + rv = NS_ERROR_OUT_OF_MEMORY; + } + + return rv; +} diff --git a/mozilla/toolkit/components/startup/src/nsAppStartup.h b/mozilla/toolkit/components/startup/src/nsAppStartup.h new file mode 100644 index 00000000000..c6e0d0f2173 --- /dev/null +++ b/mozilla/toolkit/components/startup/src/nsAppStartup.h @@ -0,0 +1,98 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** 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 Mozilla Communicator client code. This file was split + * from xpfe/appshell/src/nsAppShellService.h + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Benjamin Smedberg + * + * Alternatively, the contents of this file may be used under the terms of + * either of 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 ***** */ + +#ifndef nsAppStartup_h__ +#define nsAppStartup_h__ + +#include "nsIAppStartup.h" +#include "nsIWindowCreator2.h" +#include "nsIObserver.h" +#include "nsWeakReference.h" + +#include "nsICmdLineService.h" +#include "nsINativeAppSupport.h" +#include "nsIAppShell.h" + +struct PLEvent; + +// {7DD4D320-C84B-4624-8D45-7BB9B2356977} +#define NS_TOOLKIT_APPSTARTUP_CID \ +{ 0x7dd4d320, 0xc84b, 0x4624, { 0x8d, 0x45, 0x7b, 0xb9, 0xb2, 0x35, 0x69, 0x77 } } + + +class nsAppStartup : public nsIAppStartup, + public nsIWindowCreator2, + public nsIObserver, + public nsSupportsWeakReference +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIAPPSTARTUP + NS_DECL_NSIWINDOWCREATOR + NS_DECL_NSIWINDOWCREATOR2 + NS_DECL_NSIOBSERVER + + nsAppStartup(); + nsresult Init(); + +private: + ~nsAppStartup() { } + + void AttemptingQuit(PRBool aAttempt); + + // A "last event" that is used to flush the appshell's event queue. + 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 + PRPackedBool mShuttingDown; // Quit method reentrancy check + PRPackedBool mAttemptingQuit; // Quit(eAttemptQuit) still trying +}; + +#endif // nsAppStartup_h__ diff --git a/mozilla/toolkit/components/startup/src/nsCloseAllWindows.js b/mozilla/toolkit/components/startup/src/nsCloseAllWindows.js new file mode 100644 index 00000000000..6f3e0fdfbeb --- /dev/null +++ b/mozilla/toolkit/components/startup/src/nsCloseAllWindows.js @@ -0,0 +1,143 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2001 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Conrad Carlen + * + * 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 ***** */ + + +/* This file implements the nsCloseAllWindows component which implements + * the nsICloseAllWindows interface. Use this component when all + * windows need to be closed and confirmation to save changes is required. + */ + + +/* ctor + */ +function nsCloseAllWindows() { +} + +nsCloseAllWindows.prototype = { + + // This "class" supports nsICloseAllWindows, and nsISupports. + QueryInterface: function (iid) { + if (!iid.equals(Components.interfaces.nsICloseAllWindows) && + !iid.equals(Components.interfaces.nsISupports)) { + throw Components.results.NS_ERROR_NO_INTERFACE; + } + return this; + }, + + // ---------- nsICloseAllWindows methods ---------- + + // closeAll: Close all open windows + closeAll: function(aAskToSave) { + + var windowMediator = Components.classes['@mozilla.org/appshell/window-mediator;1']. + getService(Components.interfaces.nsIWindowMediator); + var enumerator = windowMediator.getEnumerator(null); + + while (enumerator.hasMoreElements()) { + var domWindow = enumerator.getNext(); + if (aAskToSave && ("tryToClose" in domWindow)) { + if (!domWindow.tryToClose()) + return false; + } + domWindow.close(); + }; + + return true; + } +} + +// This Component's module implementation. All the code below is used to get this +// component registered and accessible via XPCOM. +var module = { + firstTime: true, + + // registerSelf: Register this component. + registerSelf: function (compMgr, fileSpec, location, type) { + if (this.firstTime) { + this.firstTime = false; + throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN; + } + compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar); + compMgr.registerFactoryLocation( this.cid, + "Close All Windows", + 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("{2f977d48-5485-11d4-87e2-0010a4e75ef2}"), + + /* Contract ID for this class */ + contractId: "@mozilla.org/appshell/closeallwindows;1", + + /* factory object */ + factory: { + // createInstance: Return a new nsCloseAllWindows object. + createInstance: function (outer, iid) { + if (outer != null) + throw Components.results.NS_ERROR_NO_AGGREGATION; + + return (new nsCloseAllWindows()).QueryInterface(iid); + } + }, + + // canUnload: n/a (returns true) + canUnload: function(compMgr) { + return true; + } +}; + +// NSGetModule: Return the nsIModule object. +function NSGetModule(compMgr, fileSpec) { + return module; +} diff --git a/mozilla/toolkit/components/startup/src/nsCommandLineService.cpp b/mozilla/toolkit/components/startup/src/nsCommandLineService.cpp new file mode 100644 index 00000000000..a4d7233b812 --- /dev/null +++ b/mozilla/toolkit/components/startup/src/nsCommandLineService.cpp @@ -0,0 +1,397 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + + +#include "nsICmdLineService.h" +#include "nsCommandLineService.h" +#include "nsIComponentManager.h" +#include "nsILocalFile.h" +#include "nsString.h" +#include "plstr.h" +#include "nsCRT.h" +#include "nsNetUtil.h" +#ifdef XP_MACOSX +#include "nsCommandLineServiceMac.h" +#endif + +nsCmdLineService::nsCmdLineService() + : mArgCount(0), mArgc(0), mArgv(0) +{ +} + +/* + * Implement the nsISupports methods... + */ +NS_IMPL_ISUPPORTS1(nsCmdLineService, nsICmdLineService) + +static void* ProcessURLArg(char* str) +{ + // Problem: since the arg parsing code doesn't know which flags + // take arguments, it always calls this method for the last + // non-flag argument. But sometimes that argument is actually + // the arg for the last switch, e.g. -width 500 or -Profile default. + // nsLocalFile will only work on absolute pathnames, so return + // if str doesn't start with '/' or '\'. + if (str && (*str == '\\' || *str == '/')) + { + nsCOMPtr uri; + nsresult rv = NS_NewURI(getter_AddRefs(uri), str); + if (NS_FAILED(rv)) + { + nsCOMPtr file(do_CreateInstance("@mozilla.org/file/local;1")); + if (file) + { + rv = file->InitWithNativePath(nsDependentCString(str)); + if (NS_SUCCEEDED(rv)) + { + nsCAutoString fileurl; + rv = NS_GetURLSpecFromFile(file, fileurl); + if (NS_SUCCEEDED(rv)) + return NS_REINTERPRET_CAST(void*, ToNewCString(fileurl)); + } + } + } + } + + return NS_REINTERPRET_CAST(void*, nsCRT::strdup(str)); +} + +NS_IMETHODIMP +nsCmdLineService::Initialize(int aArgc, char ** aArgv) +{ + + + PRInt32 i=0; + nsresult rv = nsnull; + +#ifdef XP_MACOSX + rv = InitializeMacCommandLine(aArgc, aArgv); + NS_ASSERTION(NS_SUCCEEDED(rv), "Initializing AppleEvents failed"); +#endif + + // Save aArgc and argv + mArgc = aArgc; + mArgv = new char*[ aArgc ]; + for(i=0; i 0 && aArgv[0]) + { + mArgList.AppendElement(NS_REINTERPRET_CAST(void*, nsCRT::strdup("-progname"))); + mArgValueList.AppendElement(NS_REINTERPRET_CAST(void*, nsCRT::strdup(aArgv[0]))); + mArgCount++; + i++; + } + + for(i=1; iCount(); i++) { + const char *param = (const char*)paramList->ElementAt(i); + + // skip past leading / and - + if (*param == '-' || *param == '/') { + ++param; + if (*param == *(param-1)) // skip "--" or "//" + ++param; + } + + nsCAutoString + contractID("@mozilla.org/commandlinehandler/general-startup;1?type="); + + contractID += param; + + nsCOMPtr handler = + do_GetService(contractID.get(), &rv); + if (NS_FAILED(rv)) continue; + + *aResult = handler; + NS_ADDREF(*aResult); + return NS_OK; + } + + // went through all the parameters, didn't find one + return NS_ERROR_FAILURE; +} + +#if 0 +NS_IMETHODIMP +nsCmdLineService::PrintCmdArgs() +{ + + if (mArgCount == 0) { + printf("No command line options provided\n"); + return; + } + + for (int i=0; i + * Pierre Phaneuf + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +// Special stuff for the Macintosh implementation of command-line service. + +#include "nsCommandLineServiceMac.h" + +// Mozilla +#include "nsDebug.h" +#include "nsILocalFileMac.h" +#include "nsDebug.h" +#include "nsNetUtil.h" +#include "nsIAppStartup.h" +#include "nsIServiceManager.h" +#include "nsIURL.h" +#include "nsIIOService.h" +#include "nsIURL.h" +#include "nsIServiceManager.h" +#include "nsNetCID.h" +#include "nsIWebShellWindow.h" +#include "nsIWebShell.h" +#include "nsIDOMWindow.h" +#include "nsXPCOM.h" +#include "nsISupportsPrimitives.h" +#include "nsIWindowWatcher.h" +#include "jsapi.h" +#include "nsReadableUtils.h" +#include "nsICloseAllWindows.h" +#include "nsIPrefService.h" + +#include "nsAEEventHandling.h" +#include "nsXPFEComponentsCID.h" + +// NSPR +#include "prmem.h" +#include "plstr.h" +#include "prenv.h" +#ifdef XP_MAC +#include "pprio.h" // PR_Init_Log +#endif + +// the static instance +nsMacCommandLine nsMacCommandLine::sMacCommandLine; + +/* + * ReadLine -- + * + * Read in a line of text, terminated by CR or LF, from inStream into buf. + * The terminating CR or LF is not included. The text in buf is terminated + * by a null byte. + * Returns the number of bytes in buf. If EOF and zero bytes were read, returns -1. + */ + +static PRInt32 ReadLine(FILE* inStream, char* buf, PRInt32 bufSize) +{ + PRInt32 charsRead = 0; + int c; + + if (bufSize < 2) + return -1; + + while (charsRead < (bufSize-1)) { + c = getc(inStream); + if (c == EOF || c == '\n' || c == '\r') + break; + buf[charsRead++] = c; + } + buf[charsRead] = '\0'; + + return (c == EOF && !charsRead) ? -1 : charsRead; +} + +//---------------------------------------------------------------------------------------- +nsMacCommandLine::nsMacCommandLine() +: mArgs(NULL) +, mArgsAllocated(0) +, mArgsUsed(0) +, mStartedUp(PR_FALSE) +//---------------------------------------------------------------------------------------- +{ +} + + +//---------------------------------------------------------------------------------------- +nsMacCommandLine::~nsMacCommandLine() +//---------------------------------------------------------------------------------------- +{ + ShutdownAEHandlerClasses(); + if (mArgs) { + for (PRUint32 i = 0; i < mArgsUsed; i++) + free(mArgs[i]); + free(mArgs); + } +} + + +//---------------------------------------------------------------------------------------- +nsresult nsMacCommandLine::Initialize(int& argc, char**& argv) +//---------------------------------------------------------------------------------------- +{ + mArgs = static_cast(malloc(kArgsGrowSize * sizeof(char *))); + if (!mArgs) + return NS_ERROR_FAILURE; + mArgs[0] = nsnull; + mArgsAllocated = kArgsGrowSize; + mArgsUsed = 0; + +#if defined(XP_MACOSX) + // Here, we may actually get useful args. + // Copy them first to mArgv. + for (int arg = 0; arg < argc; arg++) + AddToCommandLine(argv[arg]); +#else + // init the args buffer with the program name + AddToCommandLine("mozilla"); +#endif + + // Set up AppleEvent handling. + OSErr err = CreateAEHandlerClasses(false); + if (err != noErr) return NS_ERROR_FAILURE; + + // Snarf all the odoc and pdoc apple-events. + // + // 1. If they are odoc for 'CMDL' documents, read them into the buffer ready for + // parsing (concatenating multiple files). + // + // 2. If they are any other kind of document, convert them into -url command-line + // parameters or -print parameters, with file URLs. + + EventRecord anEvent; + for (short i = 1; i < 5; i++) + ::WaitNextEvent(0, &anEvent, 0, nsnull); + + while (::EventAvail(highLevelEventMask, &anEvent)) + { + ::WaitNextEvent(highLevelEventMask, &anEvent, 0, nsnull); + if (anEvent.what == kHighLevelEvent) + { + // here we process startup odoc/pdoc events, which can + // add items to the command line. + err = ::AEProcessAppleEvent(&anEvent); + } + } + + if (GetCurrentKeyModifiers() & optionKey) + AddToCommandLine("-p"); + + // we've started up now + mStartedUp = PR_TRUE; + + argc = mArgsUsed; + argv = mArgs; + + return NS_OK; +} + +//---------------------------------------------------------------------------------------- +nsresult nsMacCommandLine::AddToCommandLine(const char* inArgText) +//---------------------------------------------------------------------------------------- +{ + if (mArgsUsed >= mArgsAllocated) { + // realloc does not free the given pointer if allocation fails. + char **temp = static_cast(realloc(mArgs, (mArgsAllocated + kArgsGrowSize) * sizeof(char *))); + if (!temp) + return NS_ERROR_OUT_OF_MEMORY; + mArgs = temp; + mArgsAllocated += kArgsGrowSize; + } + char *temp2 = strdup(inArgText); + if (!temp2) + return NS_ERROR_OUT_OF_MEMORY; + mArgs[mArgsUsed++] = temp2; + return NS_OK; +} + + +//---------------------------------------------------------------------------------------- +nsresult nsMacCommandLine::AddToCommandLine(const char* inOptionString, const FSSpec& inFileSpec) +//---------------------------------------------------------------------------------------- +{ + // Convert the filespec to a URL + FSSpec nonConstSpec = inFileSpec; + nsCOMPtr inFile; + nsresult rv = NS_NewLocalFileWithFSSpec(&nonConstSpec, PR_TRUE, getter_AddRefs(inFile)); + if (NS_FAILED(rv)) + return rv; + nsCAutoString specBuf; + rv = NS_GetURLSpecFromFile(inFile, specBuf); + if (NS_FAILED(rv)) + return rv; + AddToCommandLine(inOptionString); + AddToCommandLine(specBuf.get()); + return NS_OK; +} + +//---------------------------------------------------------------------------------------- +nsresult nsMacCommandLine::AddToEnvironmentVars(const char* inArgText) +//---------------------------------------------------------------------------------------- +{ + (void)PR_SetEnv(inArgText); + return NS_OK; +} + + +//---------------------------------------------------------------------------------------- +OSErr nsMacCommandLine::HandleOpenOneDoc(const FSSpec& inFileSpec, OSType inFileType) +//---------------------------------------------------------------------------------------- +{ + nsCOMPtr inFile; + nsresult rv = NS_NewLocalFileWithFSSpec(&inFileSpec, PR_TRUE, getter_AddRefs(inFile)); + if (NS_FAILED(rv)) + return errAEEventNotHandled; + + if (!mStartedUp) + { + // Is it the right type to be a command-line file? + if (inFileType == 'TEXT' || inFileType == 'CMDL') + { + // Can we open the file? + FILE *fp = 0; + rv = inFile->OpenANSIFileDesc("r", &fp); + if (NS_SUCCEEDED(rv)) + { + Boolean foundArgs = false; + Boolean foundEnv = false; + char chars[1024]; + static const char kCommandLinePrefix[] = "ARGS:"; + static const char kEnvVarLinePrefix[] = "ENV:"; + + while (ReadLine(fp, chars, sizeof(chars)) != -1) + { // See if there are any command line or environment var settings + if (PL_strstr(chars, kCommandLinePrefix) == chars) + { + (void)AddToCommandLine(chars + sizeof(kCommandLinePrefix) - 1); + foundArgs = true; + } + else if (PL_strstr(chars, kEnvVarLinePrefix) == chars) + { + (void)AddToEnvironmentVars(chars + sizeof(kEnvVarLinePrefix) - 1); + foundEnv = true; + } + } + + fclose(fp); +#ifndef XP_MACOSX + // If we found any environment vars we need to re-init NSPR's logging + // so that it knows what the new vars are + if (foundEnv) + PR_Init_Log(); +#endif + // If we found a command line or environment vars we want to return now + // raather than trying to open the file as a URL + if (foundArgs || foundEnv) + return noErr; + } + } + // If it's not a command-line argument, and we are starting up the application, + // add a command-line "-url" argument to the global list. This means that if + // the app is opened with documents on the mac, they'll be handled the same + // way as if they had been typed on the command line in Unix or DOS. + return AddToCommandLine("-url", inFileSpec); + } + + // Final case: we're not just starting up. How do we handle this? + nsCAutoString specBuf; + rv = NS_GetURLSpecFromFile(inFile, specBuf); + if (NS_FAILED(rv)) + return errAEEventNotHandled; + + return OpenURL(specBuf.get()); +} + +OSErr nsMacCommandLine::OpenURL(const char* aURL) +{ + nsresult rv; + + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv)); + + nsXPIDLCString browserURL; + if (NS_SUCCEEDED(rv)) + rv = prefBranch->GetCharPref("browser.chromeURL", getter_Copies(browserURL)); + + if (NS_FAILED(rv)) { + NS_WARNING("browser.chromeURL not supplied! How is the app supposed to know what the main window is?"); + browserURL.Assign("chrome://navigator/content/navigator.xul"); + } + + rv = OpenWindow(browserURL.get(), NS_ConvertASCIItoUCS2(aURL).get()); + if (NS_FAILED(rv)) + return errAEEventNotHandled; + + return noErr; +} + + + +//---------------------------------------------------------------------------------------- +OSErr nsMacCommandLine::HandlePrintOneDoc(const FSSpec& inFileSpec, OSType fileType) +//---------------------------------------------------------------------------------------- +{ + // If we are starting up the application, + // add a command-line "-print" argument to the global list. This means that if + // the app is opened with documents on the mac, they'll be handled the same + // way as if they had been typed on the command line in Unix or DOS. + if (!mStartedUp) + return AddToCommandLine("-print", inFileSpec); + + // Final case: we're not just starting up. How do we handle this? + NS_NOTYETIMPLEMENTED("Write Me"); + return errAEEventNotHandled; +} + + + +//---------------------------------------------------------------------------------------- +nsresult nsMacCommandLine::OpenWindow(const char *chrome, const PRUnichar *url) +//---------------------------------------------------------------------------------------- +{ + nsCOMPtr wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)); + nsCOMPtr urlWrapper(do_CreateInstance(NS_SUPPORTS_STRING_CONTRACTID)); + if (!wwatch || !urlWrapper) + return NS_ERROR_FAILURE; + + urlWrapper->SetData(nsDependentString(url)); + + nsCOMPtr newWindow; + nsresult rv; + rv = wwatch->OpenWindow(0, chrome, "_blank", + "chrome,dialog=no,all", urlWrapper, + getter_AddRefs(newWindow)); + + return rv; +} + +//---------------------------------------------------------------------------------------- +OSErr nsMacCommandLine::DispatchURLToNewBrowser(const char* url) +//---------------------------------------------------------------------------------------- +{ + OSErr err = errAEEventNotHandled; + if (mStartedUp) + return OpenURL(url); + else { + err = AddToCommandLine("-url"); + if (err == noErr) + err = AddToCommandLine(url); + } + + return err; +} + +//---------------------------------------------------------------------------------------- +OSErr nsMacCommandLine::Quit(TAskSave askSave) +//---------------------------------------------------------------------------------------- +{ + nsresult rv; + + nsCOMPtr closer = + do_CreateInstance("@mozilla.org/appshell/closeallwindows;1", &rv); + if (NS_FAILED(rv)) + return errAEEventNotHandled; + + PRBool doQuit; + rv = closer->CloseAll(askSave != eSaveNo, &doQuit); + if (NS_FAILED(rv) || !doQuit) + return errAEEventNotHandled; + + nsCOMPtr appStartup = + (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv)); + if (NS_FAILED(rv)) + return errAEEventNotHandled; + + (void)appStartup->Quit(nsIAppStartup::eAttemptQuit); + return noErr; +} + + +//======================================================================================== +// InitializeMacCommandLine +// The only external entry point to this file. +//======================================================================================== + +#pragma mark - + +//---------------------------------------------------------------------------------------- +nsresult InitializeMacCommandLine(int& argc, char**& argv) +//---------------------------------------------------------------------------------------- +{ + + nsMacCommandLine& cmdLine = nsMacCommandLine::GetMacCommandLine(); + return cmdLine.Initialize(argc, argv); +} // InitializeMac diff --git a/mozilla/toolkit/components/startup/src/nsCommandLineServiceMac.h b/mozilla/toolkit/components/startup/src/nsCommandLineServiceMac.h new file mode 100644 index 00000000000..f6e3ceebf7e --- /dev/null +++ b/mozilla/toolkit/components/startup/src/nsCommandLineServiceMac.h @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +// Special stuff for the Macintosh implementation of command-line service. + +#ifndef nsCommandLineServiceMac_h_ +#define nsCommandLineServiceMac_h_ + +#include + +#include "nscore.h" +#include "nsError.h" +#include "nsString.h" + +#include "nsAEDefs.h" + +#ifdef __cplusplus + +class nsMacCommandLine +{ +public: + + + enum + { + kArgsGrowSize = 20 + }; + + nsMacCommandLine(); + ~nsMacCommandLine(); + + nsresult Initialize(int& argc, char**& argv); + + nsresult AddToCommandLine(const char* inArgText); + nsresult AddToCommandLine(const char* inOptionString, const FSSpec& inFileSpec); + nsresult AddToEnvironmentVars(const char* inArgText); + + OSErr HandleOpenOneDoc(const FSSpec& inFileSpec, OSType inFileType); + OSErr HandlePrintOneDoc(const FSSpec& inFileSpec, OSType fileType); + + OSErr DispatchURLToNewBrowser(const char* url); + + OSErr Quit(TAskSave askSave); + +protected: + + OSErr OpenURL(const char* aURL); + + nsresult OpenWindow(const char *chrome, const PRUnichar *url); + + char** mArgs; // array of arg pointers (augmented argv) + PRUint32 mArgsAllocated; // number of slots available in mArgs + PRUint32 mArgsUsed; // number of slots used in mArgs + + PRBool mStartedUp; + +public: + + static nsMacCommandLine& GetMacCommandLine() { return sMacCommandLine; } + +private: + + static nsMacCommandLine sMacCommandLine; + +}; + +#endif //__cplusplus + + +#ifdef __cplusplus +extern "C" { +#endif + +nsresult InitializeMacCommandLine(int& argc, char**& argv); + +#ifdef __cplusplus +} +#endif + + +#endif // nsCommandLineServiceMac_h_ diff --git a/mozilla/toolkit/components/startup/src/nsUserInfo.h b/mozilla/toolkit/components/startup/src/nsUserInfo.h new file mode 100644 index 00000000000..88366662971 --- /dev/null +++ b/mozilla/toolkit/components/startup/src/nsUserInfo.h @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Seth Spitzer + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +#ifndef __nsUserInfo_h +#define __nsUserInfo_h + +#include "nsIUserInfo.h" + +class nsUserInfo: public nsIUserInfo + +{ +public: + nsUserInfo(void); + + NS_DECL_ISUPPORTS + NS_DECL_NSIUSERINFO + + virtual ~nsUserInfo(); +}; + +#endif /* __nsUserInfo_h */ diff --git a/mozilla/toolkit/components/startup/src/nsUserInfoMac.cpp b/mozilla/toolkit/components/startup/src/nsUserInfoMac.cpp new file mode 100644 index 00000000000..06c65305a0f --- /dev/null +++ b/mozilla/toolkit/components/startup/src/nsUserInfoMac.cpp @@ -0,0 +1,142 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsUserInfo.h" +#include "nsString.h" +#include "nsReadableUtils.h" + +#include "nsIServiceManager.h" +#include "nsIInternetConfigService.h" + +nsUserInfo::nsUserInfo() +{ +} + +nsUserInfo::~nsUserInfo() +{ +} + +NS_IMPL_ISUPPORTS1(nsUserInfo,nsIUserInfo) + +NS_IMETHODIMP +nsUserInfo::GetFullname(PRUnichar **aFullname) +{ + nsresult result = NS_ERROR_FAILURE; + nsCOMPtr icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID)); + if (icService) + { + nsCAutoString cName; + result = icService->GetString(nsIInternetConfigService::eICString_RealName, cName); + if ( NS_SUCCEEDED ( result ) ) + { + nsString fullName; + *aFullname = ToNewUnicode(cName); + } + } + return result; + +} + +NS_IMETHODIMP +nsUserInfo::GetEmailAddress(char * *aEmailAddress) +{ + nsresult result = NS_ERROR_FAILURE; + nsCOMPtr icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID)); + if (icService) + { + nsCAutoString tempString; + result = icService->GetString(nsIInternetConfigService::eICString_Email, tempString); + if (NS_SUCCEEDED(result)) + *aEmailAddress = ToNewCString(tempString); + + } + return result; +} + +NS_IMETHODIMP +nsUserInfo::GetUsername(char * *aUsername) +{ + *aUsername = nsnull; + + nsCAutoString tempString; + nsresult rv = NS_ERROR_FAILURE; + nsCOMPtr icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID)); + if (icService) + rv = icService->GetString(nsIInternetConfigService::eICString_Email, tempString); + + if ( NS_FAILED( rv ) ) return rv; + + const char* atString = "@"; + PRInt32 atOffset = tempString.Find(atString); + if (atOffset != kNotFound) + tempString.Truncate(atOffset); + + *aUsername = ToNewCString(tempString); + return NS_OK; +} + +NS_IMETHODIMP +nsUserInfo::GetDomain(char * *aDomain) +{ + *aDomain = nsnull; + nsCAutoString tempString; + nsresult rv = NS_ERROR_FAILURE; + nsCOMPtr icService (do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID)); + if (icService) + rv = icService->GetString(nsIInternetConfigService::eICString_Email, tempString); + if ( NS_FAILED( rv ) ) return rv; + const char* atString = "@"; + PRInt32 atOffset = tempString.Find(atString); + if (atOffset != kNotFound) + { + nsCAutoString domainString; + tempString.Right(domainString, tempString.Length() - (atOffset + 1)); + *aDomain = ToNewCString(domainString); + return NS_OK; + } + + // no domain in the pref + return NS_ERROR_FAILURE; +} + +#pragma mark - + + + + + + diff --git a/mozilla/xpfe/appshell/src/nsPreloader.h b/mozilla/toolkit/components/startup/src/nsUserInfoMac.h similarity index 50% rename from mozilla/xpfe/appshell/src/nsPreloader.h rename to mozilla/toolkit/components/startup/src/nsUserInfoMac.h index 14cb7307776..eddf0c6fdc6 100644 --- a/mozilla/xpfe/appshell/src/nsPreloader.h +++ b/mozilla/toolkit/components/startup/src/nsUserInfoMac.h @@ -1,11 +1,11 @@ /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * Version: NPL 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/ + * The contents of this file are subject to the Netscape 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/NPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License @@ -14,51 +14,58 @@ * * The Original Code is Mozilla Communicator client code. * - * The Initial Developer of the Original Code is + * The Initial Developer of the Original Code is * Netscape Communications Corporation. * Portions created by the Initial Developer are Copyright (C) 1998 * the Initial Developer. All Rights Reserved. * * Contributor(s): - * Alec Flett + * Seth Spitzer * * Alternatively, the contents of this file may be used under the terms of - * either of 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"), + * 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 + * use your version of this file under the terms of the NPL, 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. + * the terms of any one of the NPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ +#ifndef __nsUserInfoMac_h +#define __nsUserInfoMac_h -#include "nsICmdLineHandler.h" +#include "nsIUserInfo.h" -#define NS_PRELOADER_CID \ -{ /* 5ad506ee-393e-45d9-8d6f-53066fa8dc3a */ \ - 0x5ad506ee, \ - 0x393e, \ - 0x45d9, \ - {0x8d, 0x6f, 0x53, 0x06, 0x6f, 0xa8, 0xdc, 0x3a} \ - } \ -#define NS_PRELOADER_CONTRACTID \ - "@mozilla.org/commandlinehandler/general-startup;1?type=preloader" +#include + +class nsUserInfo: public nsIUserInfo -class nsPreloader : public nsICmdLineHandler { - public: - nsPreloader(); - virtual ~nsPreloader(); +public: + nsUserInfo(void); + virtual ~nsUserInfo(); - NS_DECL_ISUPPORTS - NS_DECL_NSICMDLINEHANDLER - CMDLINEHANDLER_REGISTERPROC_DECLS + NS_DECL_ISUPPORTS + NS_DECL_NSIUSERINFO - nsresult Init(); + +protected: + + nsresult EnsureInitted(); + + static OSType GetAppCreatorCode(); + static PRUnichar* PStringToNewUCS2(ConstStr255Param str); + +protected: + + ICInstance mInstance; + PRBool mInitted; + }; +#endif /* __nsUserInfo_h */ diff --git a/mozilla/toolkit/components/startup/src/nsUserInfoOS2.cpp b/mozilla/toolkit/components/startup/src/nsUserInfoOS2.cpp new file mode 100644 index 00000000000..fb6e081c123 --- /dev/null +++ b/mozilla/toolkit/components/startup/src/nsUserInfoOS2.cpp @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is Netscape Communications + * Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + * This Original Code has been modified by IBM Corporation. Modifications made by IBM + * described herein are Copyright (c) International Business Machines Corporation, 2000. + * Modifications to Mozilla code or documentation identified per MPL Section 3.3 + * + * Date Modified by Description of modification + * 05/11/2000 IBM Corp. Created for OS/2 VisualAge build. + */ + +#include "nsUserInfo.h" +#include "nsString.h" +#include "nsCRT.h" +#include "nsXPIDLString.h" + +nsUserInfo::nsUserInfo() +{ +} + +nsUserInfo::~nsUserInfo() +{ +} + +NS_IMPL_ISUPPORTS1(nsUserInfo,nsIUserInfo) + +NS_IMETHODIMP +nsUserInfo::GetUsername(char **aUsername) +{ + *aUsername = nsnull; + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsUserInfo::GetFullname(PRUnichar **aFullname) +{ + *aFullname = nsnull; + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsUserInfo::GetDomain(char * *aDomain) +{ + *aDomain = nsnull; + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsUserInfo::GetEmailAddress(char * *aEmailAddress) +{ + *aEmailAddress = nsnull; + return NS_ERROR_NOT_IMPLEMENTED; +} diff --git a/mozilla/toolkit/components/startup/src/nsUserInfoUnix.cpp b/mozilla/toolkit/components/startup/src/nsUserInfoUnix.cpp new file mode 100644 index 00000000000..74a5658cc8f --- /dev/null +++ b/mozilla/toolkit/components/startup/src/nsUserInfoUnix.cpp @@ -0,0 +1,199 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Seth Spitzer + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsUserInfo.h" +#include "nsCRT.h" + +#include +#include +#include +#include + +#include "nsString.h" +#include "nsXPIDLString.h" +#include "nsReadableUtils.h" + +/* Some UNIXy platforms don't have pw_gecos. In this case we use pw_name */ +#if defined(NO_PW_GECOS) +#define PW_GECOS pw_name +#else +#define PW_GECOS pw_gecos +#endif + +nsUserInfo::nsUserInfo() +{ +} + +nsUserInfo::~nsUserInfo() +{ +} + +NS_IMPL_ISUPPORTS1(nsUserInfo,nsIUserInfo) + +NS_IMETHODIMP +nsUserInfo::GetFullname(PRUnichar **aFullname) +{ + struct passwd *pw = nsnull; + + pw = getpwuid (geteuid()); + + if (!pw || !pw->PW_GECOS) return NS_ERROR_FAILURE; + +#ifdef DEBUG_sspitzer + printf("fullname = %s\n", pw->PW_GECOS); +#endif + + nsCAutoString fullname(pw->PW_GECOS); + + // now try to parse the GECOS information, which will be in the form + // Full Name, - eliminate the ", + // also, sometimes GECOS uses "&" to mean "the user name" so do + // the appropriate substitution + + // truncate at first comma (field delimiter) + PRInt32 index; + if ((index = fullname.Find(",")) != kNotFound) + fullname.Truncate(index); + + // replace ampersand with username + if (pw->pw_name) { + nsCAutoString username(pw->pw_name); + if (!username.IsEmpty() && nsCRT::IsLower(username.CharAt(0))) + username.SetCharAt(nsCRT::ToUpper(username.CharAt(0)), 0); + + fullname.ReplaceSubstring("&", username.get()); + } + + *aFullname = ToNewUnicode(fullname); + + if (*aFullname) + return NS_OK; + + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +nsUserInfo::GetUsername(char * *aUsername) +{ + struct passwd *pw = nsnull; + + // is this portable? those are POSIX compliant calls, but I need to check + pw = getpwuid(geteuid()); + + if (!pw || !pw->pw_name) return NS_ERROR_FAILURE; + +#ifdef DEBUG_sspitzer + printf("username = %s\n", pw->pw_name); +#endif + + *aUsername = nsCRT::strdup(pw->pw_name); + + return NS_OK; +} + +NS_IMETHODIMP +nsUserInfo::GetDomain(char * *aDomain) +{ + nsresult rv = NS_ERROR_FAILURE; + + struct utsname buf; + char *domainname = nsnull; + + // is this portable? that is a POSIX compliant call, but I need to check + if (uname(&buf)) { + return rv; + } + +#if defined(HAVE_UNAME_DOMAINNAME_FIELD) + domainname = buf.domainname; +#elif defined(HAVE_UNAME_US_DOMAINNAME_FIELD) + domainname = buf.__domainname; +#endif + + if (domainname && domainname[0]) { + *aDomain = nsCRT::strdup(domainname); + rv = NS_OK; + } + else { + // try to get the hostname from the nodename + // on machines that use DHCP, domainname may not be set + // but the nodename might. + if (buf.nodename && buf.nodename[0]) { + // if the nodename is foo.bar.org, use bar.org as the domain + char *pos = strchr(buf.nodename,'.'); + if (pos) { + *aDomain = nsCRT::strdup(pos+1); + rv = NS_OK; + } + } + } + + return rv; +} + +NS_IMETHODIMP +nsUserInfo::GetEmailAddress(char * *aEmailAddress) +{ + // use username + "@" + domain for the email address + + nsresult rv; + + nsCAutoString emailAddress; + nsXPIDLCString username; + nsXPIDLCString domain; + + rv = GetUsername(getter_Copies(username)); + if (NS_FAILED(rv)) return rv; + + rv = GetDomain(getter_Copies(domain)); + if (NS_FAILED(rv)) return rv; + + if (!username.IsEmpty() && !domain.IsEmpty()) { + emailAddress = (const char *)username; + emailAddress += "@"; + emailAddress += (const char *)domain; + } + else { + return NS_ERROR_FAILURE; + } + + *aEmailAddress = ToNewCString(emailAddress); + + return NS_OK; +} + diff --git a/mozilla/toolkit/components/startup/src/nsUserInfoWin.cpp b/mozilla/toolkit/components/startup/src/nsUserInfoWin.cpp new file mode 100644 index 00000000000..b17e241730e --- /dev/null +++ b/mozilla/toolkit/components/startup/src/nsUserInfoWin.cpp @@ -0,0 +1,93 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Doug Turner + * Seth Spitzer + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsUserInfo.h" +#include "nsString.h" +#include "windows.h" +#include "nsCRT.h" +#include "nsXPIDLString.h" + +nsUserInfo::nsUserInfo() +{ +} + +nsUserInfo::~nsUserInfo() +{ +} + +NS_IMPL_ISUPPORTS1(nsUserInfo,nsIUserInfo) + +NS_IMETHODIMP +nsUserInfo::GetUsername(char **aUsername) +{ + *aUsername = nsnull; + + TCHAR username[256]; + DWORD size = 256; + + if (!GetUserName(username, &size)) + return NS_ERROR_FAILURE; + + *aUsername = nsCRT::strdup(username); + + if (*aUsername) return NS_OK; + + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +nsUserInfo::GetFullname(PRUnichar **aFullname) +{ + *aFullname = nsnull; + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsUserInfo::GetDomain(char * *aDomain) +{ + *aDomain = nsnull; + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsUserInfo::GetEmailAddress(char * *aEmailAddress) +{ + *aEmailAddress = nsnull; + return NS_ERROR_NOT_IMPLEMENTED; +} diff --git a/mozilla/toolkit/content/globalOverlay.js b/mozilla/toolkit/content/globalOverlay.js index a36f4841638..ee8ab941aa5 100644 --- a/mozilla/toolkit/content/globalOverlay.js +++ b/mozilla/toolkit/content/globalOverlay.js @@ -47,15 +47,8 @@ function goQuitApplication() var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(); var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator); var enumerator = windowManagerInterface.getEnumerator( null ); - var appShell = Components.classes['@mozilla.org/appshell/appShellService;1'].getService(); - appShell = appShell.QueryInterface( Components.interfaces.nsIAppShellService ); - - var nativeAppSupport = null; - try { - nativeAppSupport = appShell.nativeAppSupport; - } - catch ( ex ) { - } + var appStartup = Components.classes['@mozilla.org/toolkit/app-startup;1']. + getService(Components.interfaces.nsIAppStartup); while ( enumerator.hasMoreElements() ) { @@ -64,7 +57,7 @@ function goQuitApplication() return false; domWindow.close(); }; - appShell.quit(Components.interfaces.nsIAppShellService.eAttemptQuit); + appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit); return true; } diff --git a/mozilla/toolkit/mozapps/extensions/src/nsExtensionManager.js.in b/mozilla/toolkit/mozapps/extensions/src/nsExtensionManager.js.in index 9732f678744..e4ba0b59314 100644 --- a/mozilla/toolkit/mozapps/extensions/src/nsExtensionManager.js.in +++ b/mozilla/toolkit/mozapps/extensions/src/nsExtensionManager.js.in @@ -1544,7 +1544,7 @@ nsExtensionManager.prototype = { // time now. this._cleanDirs(); - var cmdLineSvc = Components.classes["@mozilla.org/appshell/commandLineService;1"] + var cmdLineSvc = Components.classes["@mozilla.org/app-startup/commandLineService;1"] .getService(Components.interfaces.nsICmdLineService); var safeMode = cmdLineSvc.getCmdLineValue("-safe-mode") != null; if (!safeMode) { @@ -1647,7 +1647,7 @@ nsExtensionManager.prototype = { handleCommandLineArgs: function nsExtensionManager_handleCommandLineArgs () { - var cmdLineSvc = Components.classes["@mozilla.org/appshell/commandLineService;1"] + var cmdLineSvc = Components.classes["@mozilla.org/app-startup/commandLineService;1"] .getService(Components.interfaces.nsICmdLineService); var globalExtension = cmdLineSvc.getCmdLineValue("-install-global-extension"); if (globalExtension) diff --git a/mozilla/toolkit/xre/Makefile.in b/mozilla/toolkit/xre/Makefile.in index 5dcdcfd0d14..0bf0a41ede9 100644 --- a/mozilla/toolkit/xre/Makefile.in +++ b/mozilla/toolkit/xre/Makefile.in @@ -87,10 +87,11 @@ endif FORCE_STATIC_LIB = 1 +XPIDLSRCS = nsINativeAppSupport.idl + EXPORTS = nsXULAppAPI.h SHAREDCPPSRCS = \ - nsWindowCreator.cpp \ showOSAlert.cpp \ $(NULL) diff --git a/mozilla/toolkit/xre/nsAppRunner.cpp b/mozilla/toolkit/xre/nsAppRunner.cpp index de93b23cd1b..c2b81ac462f 100644 --- a/mozilla/toolkit/xre/nsAppRunner.cpp +++ b/mozilla/toolkit/xre/nsAppRunner.cpp @@ -56,6 +56,7 @@ #include "prenv.h" #include "nsIAppShellService.h" +#include "nsIAppStartup.h" #include "nsIAppStartupNotifier.h" #include "nsIArray.h" #include "nsICategoryManager.h" @@ -89,11 +90,11 @@ #include "nsNetUtil.h" #include "nsXPCOM.h" #include "nsXPIDLString.h" +#include "nsXPFEComponentsCID.h" #include "nsAppDirectoryServiceDefs.h" #include "nsXULAppAPI.h" #include "nsXREDirProvider.h" -#include "nsWindowCreator.h" #include "nsINIParser.h" @@ -593,7 +594,7 @@ LaunchApplicationWithArgs(const char *commandLineArg, nsresult rv; nsCOMPtr cmdLine = - do_GetService("@mozilla.org/appshell/commandLineService;1",&rv); + do_GetService("@mozilla.org/app-startup/commandLineService;1",&rv); if (NS_FAILED(rv)) return rv; nsCOMPtr handler; @@ -720,10 +721,10 @@ DoCommandLines(nsICmdLineService* cmdLineArgs, PRBool heedGeneralStartupPrefs, P PR_sscanf(tempString.get(), "%d", &height); if (heedGeneralStartupPrefs) { - nsCOMPtr appShellService - (do_GetService("@mozilla.org/appshell/appShellService;1", &rv)); + nsCOMPtr appStartup + (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv)); NS_ENSURE_SUCCESS(rv, rv); - rv = appShellService->CreateStartupState(width, height, windowOpened); + rv = appStartup->CreateStartupState(width, height, windowOpened); NS_ENSURE_SUCCESS(rv, rv); } else { @@ -956,7 +957,7 @@ ScopedXPCOMStartup::SetWindowCreator(nsINativeAppSupport* native) // Initialize the cmd line service nsCOMPtr cmdLineArgs - (do_GetService("@mozilla.org/appshell/commandLineService;1")); + (do_GetService("@mozilla.org/app-startup/commandLineService;1")); NS_ENSURE_TRUE(cmdLineArgs, NS_ERROR_FAILURE); rv = cmdLineArgs->Initialize(gArgc, gArgv); @@ -968,15 +969,8 @@ ScopedXPCOMStartup::SetWindowCreator(nsINativeAppSupport* native) return rv; } - nsCOMPtr appShellService - (do_GetService("@mozilla.org/appshell/appShellService;1")); - NS_ENSURE_TRUE(appShellService, NS_ERROR_UNEXPECTED); - - rv = appShellService->Initialize(cmdLineArgs, native); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr creator = new nsWindowCreator(); - if (!creator) return NS_ERROR_OUT_OF_MEMORY; + nsCOMPtr creator (do_GetService(NS_APPSTARTUP_CONTRACTID)); + if (!creator) return NS_ERROR_UNEXPECTED; nsCOMPtr wwatch (do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv)); @@ -1310,11 +1304,11 @@ ShowProfileManager(nsIToolkitProfileService* aProfileSvc, ioParamBlock->SetObjects(dlgArray); - nsCOMPtr appShellService - (do_GetService("@mozilla.org/appshell/appShellService;1")); - NS_ENSURE_TRUE(appShellService, NS_ERROR_FAILURE); + nsCOMPtr appStartup + (do_GetService(NS_APPSTARTUP_CONTRACTID)); + NS_ENSURE_TRUE(appStartup, NS_ERROR_FAILURE); - appShellService->EnterLastWindowClosingSurvivalArea(); + appStartup->EnterLastWindowClosingSurvivalArea(); nsCOMPtr newWindow; rv = windowWatcher->OpenWindow(nsnull, @@ -1324,7 +1318,7 @@ ShowProfileManager(nsIToolkitProfileService* aProfileSvc, ioParamBlock, getter_AddRefs(newWindow)); - appShellService->ExitLastWindowClosingSurvivalArea(); + appStartup->ExitLastWindowClosingSurvivalArea(); NS_ENSURE_SUCCESS(rv, rv); @@ -1916,12 +1910,12 @@ int xre_main(int argc, char* argv[], const nsXREAppData* aAppData) NS_TIMELINE_LEAVE("startupNotifier"); } - nsCOMPtr appShellService; - appShellService = do_GetService("@mozilla.org/appshell/appShellService;1"); - NS_ENSURE_TRUE(appShellService, 1); + nsCOMPtr appStartup + (do_GetService(NS_APPSTARTUP_CONTRACTID)); + NS_ENSURE_TRUE(appStartup, 1); // So we can open and close windows during startup - appShellService->EnterLastWindowClosingSurvivalArea(); + appStartup->EnterLastWindowClosingSurvivalArea(); // Profile Migration if (gAppData->flags & NS_XRE_ENABLE_PROFILE_MIGRATOR && gDoMigration) { @@ -1933,9 +1927,9 @@ int xre_main(int argc, char* argv[], const nsXREAppData* aAppData) } dirProvider.DoStartup(); - NS_TIMELINE_ENTER("appShellService->CreateHiddenWindow"); - rv = appShellService->CreateHiddenWindow(); - NS_TIMELINE_LEAVE("appShellService->CreateHiddenWindow"); + NS_TIMELINE_ENTER("appStartup->CreateHiddenWindow"); + rv = appStartup->CreateHiddenWindow(); + NS_TIMELINE_LEAVE("appStartup->CreateHiddenWindow"); NS_ENSURE_SUCCESS(rv, 1); // Extension Compatibility Checking and Startup @@ -1983,10 +1977,10 @@ int xre_main(int argc, char* argv[], const nsXREAppData* aAppData) #endif nsCOMPtr cmdLineArgs - (do_GetService("@mozilla.org/appshell/commandLineService;1")); + (do_GetService("@mozilla.org/app-startup/commandLineService;1")); NS_ENSURE_TRUE(cmdLineArgs, 1); - // This will go away once Components are handling there own commandlines + // 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. @@ -1999,12 +1993,12 @@ int xre_main(int argc, char* argv[], const nsXREAppData* aAppData) // Make sure there exists at least 1 window. NS_TIMELINE_ENTER("Ensure1Window"); - rv = appShellService->Ensure1Window(cmdLineArgs); + rv = appStartup->Ensure1Window(cmdLineArgs); NS_TIMELINE_LEAVE("Ensure1Window"); NS_ENSURE_SUCCESS(rv, 1); #ifndef XP_MACOSX - appShellService->ExitLastWindowClosingSurvivalArea(); + appStartup->ExitLastWindowClosingSurvivalArea(); #endif #ifdef MOZ_ENABLE_XREMOTE @@ -2017,13 +2011,13 @@ int xre_main(int argc, char* argv[], const nsXREAppData* aAppData) #endif /* MOZ_ENABLE_XREMOTE */ // enable win32 DDE responses and Mac appleevents responses - nativeApp->SetShouldShowUI(PR_TRUE); + nativeApp->Enable(); // Start main event loop - NS_TIMELINE_ENTER("appShell->Run"); - rv = appShellService->Run(); - NS_TIMELINE_LEAVE("appShell->Run"); - NS_ASSERTION(NS_SUCCEEDED(rv), "failed to run appshell"); + 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 diff --git a/mozilla/toolkit/xre/nsINativeAppSupport.idl b/mozilla/toolkit/xre/nsINativeAppSupport.idl new file mode 100644 index 00000000000..2400bf62db8 --- /dev/null +++ b/mozilla/toolkit/xre/nsINativeAppSupport.idl @@ -0,0 +1,139 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** 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 Mozilla Communicator client code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Bill Law + * Blake Ross + * Benjamin Smedberg + * + * Alternatively, the contents of this file may be used under the terms of + * either of 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" + +/* nsINativeAppSupport + * + * This "pseudo" (in the XPCOM sense) interface provides for + * platform-specific general aplication support: + * o It manages the details of the simple DDE communication + * supported on the Win32 platform (it is the addition of this + * item that prompted the creation of this interface. + * + * Due to the nature of the beast, this interface is not a full-blown + * XPCOM component. The primary reason is that objects that implement + * this interface generally must be operational *before* XPCOM (or any + * of the rest of Mozilla) are initialized. As a result, this + * interface is instantiated by somewhat unconventional means. + * + * To create the implementor of this interface, you call the function + * NS_CreateNativeAppSupport. This is done in the startup code + * in nsAppRunner.cpp + * + * The interface provides these functions: + * start - You call this to inform the native app support that the + * application is starting. In addition, it serves as a + * query as to whether the application should continue to + * run. + * + * If the returned boolean result is PR_FALSE, then the + * application should exit without further processing. In + * such cases, the returned nsresult indicates whether the + * reason to exit is due to an error or not. + * + * Win32 Note: In the case of starting a second instance + * of this executable, this function will return + * PR_FALSE and nsresult==NS_OK. This means that + * the command line arguments have been + * successfully passed to the instance of the + * application acting as a DDE server. + * + * stop - You call this to inform the native app support that the + * application *wishes* to terminate. If the returned boolean + * value is PR_FALSE, then the application should continue + * (as if there were still additional top-level windows open). + * + * Win32 Note: If this is the instance of the application + * acting as the DDE server, and there are current + * DDE conversations active with other instances + * acting as DDE clients, then this function will + * return PR_FALSE. + * + * quit - Like Stop, but this method *forces* termination (or more + * precisely, indicates that the application is about to be + * terminated regardless of what a call to Stop might have + * returned. + * + * This method is intended to be called when the user selects + * the "Quit" option (close all windows and exit). + * + * Win32 Note: Stop is problematic in the case of "Quit" (close + * all windows and exit the application) because + * either we don't Quit or (potentially) we lose + * requests coming from other instances of the + * application. The strategy is to give preference + * to the user's explicit Quit request. In the + * unlikely event that a request is pending from + * another instance of the application, then such + * requests are essentially ignored. This is + * roughly equivalent to handling that request by + * opening a new window, followed by immediately + * closing it. Since this is the same as if the + * request came in immediately before the Quit + * call (versus immediately after it), no harm. + * + * There is an exposure here: Upon return from this + * function, any DDE connect request (for Mozilla) + * will fail and other instances of the application + * will start up as a DDE server. In that case, + * those instances may do things that conflict with + * the subsequent shutting down of the instance that + * is quitting. For this reason, the call to Quit + * should be deferred as long as possible. + * + * onLastWindowClosing - Called when the last window is closed. Used as a + * "soft" shutdown, passwords are flushed. + */ + +interface nsIXULWindow; +interface nsICmdLineService; + +[scriptable, uuid(5fdf8480-1f98-11d4-8077-00600811a9c3)] +interface nsINativeAppSupport : nsISupports { + // Startup/shutdown. + boolean start(); + void enable(); + boolean stop(); + void quit(); + + void onLastWindowClosing(); + void ReOpen(); +}; diff --git a/mozilla/toolkit/xre/nsNativeAppSupportBase.cpp b/mozilla/toolkit/xre/nsNativeAppSupportBase.cpp index 4206a14e660..4c45f743b41 100644 --- a/mozilla/toolkit/xre/nsNativeAppSupportBase.cpp +++ b/mozilla/toolkit/xre/nsNativeAppSupportBase.cpp @@ -35,37 +35,45 @@ * the terms of any one of the NPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ + #include "nsNativeAppSupportBase.h" nsNativeAppSupportBase::nsNativeAppSupportBase() { } -nsNativeAppSupportBase::~nsNativeAppSupportBase() { +nsNativeAppSupportBase::~nsNativeAppSupportBase() +{ } NS_IMPL_ISUPPORTS1(nsNativeAppSupportBase, nsINativeAppSupport) // Start answer defaults to OK. NS_IMETHODIMP -nsNativeAppSupportBase::Start( PRBool *result ) { - NS_ENSURE_ARG( result ); - *result = PR_TRUE; - return NS_OK; +nsNativeAppSupportBase::Start( PRBool *result ) +{ + *result = PR_TRUE; + return NS_OK; +} + +NS_IMETHODIMP +nsNativeAppSupportBase::Enable() +{ + return NS_OK; } // Stop answer defaults to OK. NS_IMETHODIMP -nsNativeAppSupportBase::Stop( PRBool *result ) { - NS_ENSURE_ARG( result ); - *result = PR_TRUE; - return NS_OK; +nsNativeAppSupportBase::Stop( PRBool *result ) +{ + *result = PR_TRUE; + return NS_OK; } -// Quit is a 0x90. NS_IMETHODIMP -nsNativeAppSupportBase::Quit() { - return NS_OK; +nsNativeAppSupportBase::Quit() +{ + return NS_OK; } NS_IMETHODIMP @@ -74,55 +82,7 @@ nsNativeAppSupportBase::ReOpen() return NS_OK; } -// Show splash screen if implementation has one. -NS_IMETHODIMP -nsNativeAppSupportBase::ShowSplashScreen() { - NS_NOTREACHED("Don't call me, I'm obsolete!"); - return NS_OK; -} - -// Hide splash screen if there is one. -NS_IMETHODIMP -nsNativeAppSupportBase::HideSplashScreen() { - NS_NOTREACHED("Don't call me, I'm obsolete!"); - return NS_OK; -} - -NS_IMETHODIMP -nsNativeAppSupportBase::SetIsServerMode(PRBool aIsServerMode) { - NS_NOTREACHED("Don't call me, I'm obsolete!"); - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsNativeAppSupportBase::GetIsServerMode(PRBool *aIsServerMode) { - NS_NOTREACHED("Don't call me, I'm obsolete!"); - *aIsServerMode = PR_FALSE; - return NS_OK; -} - -NS_IMETHODIMP -nsNativeAppSupportBase::SetShouldShowUI(PRBool aShouldShowUI) { - return NS_OK; -} - -NS_IMETHODIMP -nsNativeAppSupportBase::GetShouldShowUI(PRBool *aShouldShowUI) { - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -nsNativeAppSupportBase::StartServerMode() { - return NS_OK; -} - NS_IMETHODIMP nsNativeAppSupportBase::OnLastWindowClosing() { - return NS_OK; -} - -NS_IMETHODIMP -nsNativeAppSupportBase::EnsureProfile(nsICmdLineService* args) -{ - return NS_OK; + return NS_OK; } diff --git a/mozilla/toolkit/xre/nsNativeAppSupportMac.cpp b/mozilla/toolkit/xre/nsNativeAppSupportMac.cpp index a18c663d663..a124650907c 100644 --- a/mozilla/toolkit/xre/nsNativeAppSupportMac.cpp +++ b/mozilla/toolkit/xre/nsNativeAppSupportMac.cpp @@ -91,7 +91,7 @@ public: NS_IMETHOD Start(PRBool* aRetVal); NS_IMETHOD ReOpen(); - NS_IMETHOD SetShouldShowUI(PRBool aValue); + NS_IMETHOD Enable(); private: PRBool mCanShowUI; @@ -99,11 +99,10 @@ private: }; NS_IMETHODIMP -nsNativeAppSupportMac::SetShouldShowUI(PRBool aValue) +nsNativeAppSupportMac::Enable() { - NS_ASSERTION(aValue, "True is the only allowed value!"); - mCanShowUI = aValue; - return NS_OK; + mCanShowUI = PR_TRUE; + return NS_OK; } /* boolean start (); */ diff --git a/mozilla/toolkit/xre/nsNativeAppSupportOS2.cpp b/mozilla/toolkit/xre/nsNativeAppSupportOS2.cpp index 128fd73c6ca..21c82139958 100644 --- a/mozilla/toolkit/xre/nsNativeAppSupportOS2.cpp +++ b/mozilla/toolkit/xre/nsNativeAppSupportOS2.cpp @@ -72,6 +72,7 @@ #include "nsIPref.h" #include "nsIPromptService.h" #include "nsNetCID.h" +#include "nsIObserver.h" #include "nsIObserverService.h" #include "nsXPCOM.h" #ifdef MOZ_PHOENIX @@ -289,13 +290,18 @@ private: * whether Mozilla is already running. */ -class nsNativeAppSupportOS2 : public nsNativeAppSupportBase { +class nsNativeAppSupportOS2 : public nsNativeAppSupportBase, + public nsIObserver +{ public: + NS_DECL_NSIOBSERVER + NS_DECL_ISUPPORTS_INHERITED + // Overrides of base implementation. NS_IMETHOD Start( PRBool *aResult ); NS_IMETHOD Stop( PRBool *aResult ); - NS_IMETHOD Quit(); - NS_IMETHOD SetShouldShowUI(PRBool aValue); + void Quit(); + NS_IMETHOD Enable(); // The "old" Start method (renamed). NS_IMETHOD StartDDE(); @@ -350,6 +356,13 @@ private: friend struct MessageWindow; }; // nsNativeAppSupportOS2 +NS_INTERFACE_MAP_BEGIN(nsNativeAppSupportOS2) + NS_INTERFACE_MAP_ENTRY(nsIObserver) +NS_INTERFACE_MAP_END_INHERITING(nsNativeAppSupportBase) + +NS_IMPL_ADDREF_INHERITED(nsNativeAppSupportOS2, nsNativeAppSupportBase) +NS_IMPL_RELEASE_INHERITED(nsNativeAppSupportOS2, nsNativeAppSupportBase) + void nsNativeAppSupportOS2::CheckConsole() { return; @@ -912,6 +925,19 @@ nsNativeAppSupportOS2::Stop( PRBool *aResult ) { return rv; } +NS_IMETHODIMP +nsNativeAppSupportOS2::Observe(nsISupports* aSubject, const char* aTopic, + const PRUnichar* aData) +{ + if (strcmp(aTopic, "quit-application") == 0) { + Quit(); + } else { + NS_ERROR("Unexpected observer topic."); + } + + return NS_OK; +} + // Terminate DDE regardless. NS_IMETHODIMP nsNativeAppSupportOS2::Quit() { @@ -920,7 +946,7 @@ nsNativeAppSupportOS2::Quit() { // window as we will destroy ours under our lock. // When the mutex goes off the stack, it is unlocked via destructor. Mutex mutexLock(mMutexName); - NS_ENSURE_TRUE(mutexLock.Lock(MOZ_DDE_START_TIMEOUT), NS_ERROR_FAILURE ); + NS_ENSURE_TRUE(mutexLock.Lock(MOZ_DDE_START_TIMEOUT), NS_ERROR_FAILURE); // If we've got a message window to receive IPC or new window requests, // get rid of it as we are shutting down. @@ -951,10 +977,17 @@ nsNativeAppSupportOS2::Quit() { } NS_IMETHODIMP -nsNativeAppSupportOS2::SetShouldShowUI(PRBool aValue) +nsNativeAppSupportOS2::Enable() { - NS_ASSERTION(aValue, "True is the only allowed value!"); - mCanHandleRequests = aValue; + mCanHandleRequests = PR_TRUE; + nsCOMPtr obs + (do_GetService("@mozilla.org/observer-service;1")); + if (obs) { + obs->AddObserver(this, "quit-application", PR_FALSE); + } else { + NS_ERROR("No observer service?"); + } + return NS_OK; } @@ -1614,14 +1647,11 @@ nsNativeAppSupportOS2::GetCmdLineArgs( LPBYTE request, nsICmdLineService **aResu } // OK, now create nsICmdLineService object from argc/argv. - static NS_DEFINE_CID( kCmdLineServiceCID, NS_COMMANDLINE_SERVICE_CID ); - nsCOMPtr compMgr; NS_GetComponentManager(getter_AddRefs(compMgr)); - rv = compMgr->CreateInstance( kCmdLineServiceCID, - 0, - NS_GET_IID( nsICmdLineService ), - (void**)aResult ); + 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 diff --git a/mozilla/toolkit/xre/nsNativeAppSupportWin.cpp b/mozilla/toolkit/xre/nsNativeAppSupportWin.cpp index 6910b329f8f..d140140f8d1 100644 --- a/mozilla/toolkit/xre/nsNativeAppSupportWin.cpp +++ b/mozilla/toolkit/xre/nsNativeAppSupportWin.cpp @@ -65,6 +65,7 @@ #include "nsIPref.h" #include "nsIPromptService.h" #include "nsNetCID.h" +#include "nsIObserver.h" #include "nsIObserverService.h" #include "nsXPCOM.h" #ifdef MOZ_PHOENIX @@ -264,13 +265,18 @@ private: * whether Mozilla is already running. */ -class nsNativeAppSupportWin : public nsNativeAppSupportBase { +class nsNativeAppSupportWin : public nsNativeAppSupportBase, + public nsIObserver +{ public: + NS_DECL_NSIOBSERVER + NS_DECL_ISUPPORTS_INHERITED + // Overrides of base implementation. NS_IMETHOD Start( PRBool *aResult ); NS_IMETHOD Stop( PRBool *aResult ); NS_IMETHOD Quit(); - NS_IMETHOD SetShouldShowUI(PRBool aValue); + NS_IMETHOD Enable(); // The "old" Start method (renamed). NS_IMETHOD StartDDE(); @@ -326,6 +332,13 @@ private: friend struct MessageWindow; }; // nsNativeAppSupportWin +NS_INTERFACE_MAP_BEGIN(nsNativeAppSupportWin) + NS_INTERFACE_MAP_ENTRY(nsIObserver) +NS_INTERFACE_MAP_END_INHERITING(nsNativeAppSupportBase) + +NS_IMPL_ADDREF_INHERITED(nsNativeAppSupportWin, nsNativeAppSupportBase) +NS_IMPL_RELEASE_INHERITED(nsNativeAppSupportWin, nsNativeAppSupportBase) + void nsNativeAppSupportWin::CheckConsole() { for ( int i = 1; i < __argc; i++ ) { @@ -766,6 +779,19 @@ nsNativeAppSupportWin::Stop( PRBool *aResult ) { return rv; } +NS_IMETHODIMP +nsNativeAppSupportWin::Observe(nsISupports* aSubject, const char* aTopic, + const PRUnichar* aData) +{ + if (strcmp(aTopic, "quit-application") == 0) { + Quit(); + } else { + NS_ERROR("Unexpected observer topic."); + } + + return NS_OK; +} + // Terminate DDE regardless. NS_IMETHODIMP nsNativeAppSupportWin::Quit() { @@ -774,7 +800,7 @@ nsNativeAppSupportWin::Quit() { // window as we will destroy ours under our lock. // When the mutex goes off the stack, it is unlocked via destructor. Mutex mutexLock(mMutexName); - NS_ENSURE_TRUE(mutexLock.Lock(MOZ_DDE_START_TIMEOUT), NS_ERROR_FAILURE ); + NS_ENSURE_TRUE(mutexLock.Lock(MOZ_DDE_START_TIMEOUT), NS_ERROR_FAILURE); // If we've got a message window to receive IPC or new window requests, // get rid of it as we are shutting down. @@ -814,10 +840,18 @@ nsNativeAppSupportWin::Quit() { } NS_IMETHODIMP -nsNativeAppSupportWin::SetShouldShowUI(PRBool aValue) +nsNativeAppSupportWin::Enable() { - NS_ASSERTION(aValue, "True is the only allowed value!"); - mCanHandleRequests = aValue; + mCanHandleRequests = PR_TRUE; + + nsCOMPtr obs + (do_GetService("@mozilla.org/observer-service;1")); + if (obs) { + obs->AddObserver(this, "quit-application", PR_FALSE); + } else { + NS_ERROR("No observer service?"); + } + return NS_OK; } @@ -1499,14 +1533,11 @@ nsNativeAppSupportWin::GetCmdLineArgs( LPBYTE request, nsICmdLineService **aResu } // OK, now create nsICmdLineService object from argc/argv. - static NS_DEFINE_CID( kCmdLineServiceCID, NS_COMMANDLINE_SERVICE_CID ); - nsCOMPtr compMgr; NS_GetComponentManager(getter_AddRefs(compMgr)); - rv = compMgr->CreateInstance( kCmdLineServiceCID, - 0, - NS_GET_IID( nsICmdLineService ), - (void**)aResult ); + 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 diff --git a/mozilla/xpfe/appshell/public/nsAppShellCIDs.h b/mozilla/toolkit/xre/nsNativeAppSupportWin.h similarity index 70% rename from mozilla/xpfe/appshell/public/nsAppShellCIDs.h rename to mozilla/toolkit/xre/nsNativeAppSupportWin.h index eb0bbf2a119..9291250f409 100644 --- a/mozilla/xpfe/appshell/public/nsAppShellCIDs.h +++ b/mozilla/toolkit/xre/nsNativeAppSupportWin.h @@ -20,6 +20,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * Bill Law * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -34,26 +35,32 @@ * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ + +/* This file has *public* stuff needed for the Win32 implementation of + * the nsINativeAppSupport interface. It has to be broken out into a + * separate file in order to ensure that the generated .h file can be + * used in a Win32 .rc file. See /mozilla/xpfe/bootstrap/splash.rc. + * + * This file, and the generated .h, are only needed on Win32 platforms. + */ -#ifndef nsAppShellCIDs_h__ -#define nsAppShellCIDs_h__ -#include "nsIFactory.h" +// Constants identifying Win32 "native" resources. -// 43147b80-8a39-11d2-9938-0080c7cb1080 -#define NS_APPSHELL_SERVICE_CID \ -{ 0x43147b80, 0x8a39, 0x11d2, \ - {0x99, 0x38, 0x00, 0x80, 0xc7, 0xcb, 0x10, 0x80} } +#ifdef MOZ_PHOENIX -// XXX: This is temporary... -// 106b6f40-d79e-11d2-99db-0080c7cb1080 -#define NS_PROTOCOL_HELPER_CID \ -{ 0x106b6f40, 0xd79e, 0x11d2, \ - {0x99, 0xdb, 0x00, 0x80, 0xc7, 0xcb, 0x10, 0x80} } +// Splash screen dialog ID. +#define IDD_SPLASH 100 -#define NS_SESSIONHISTORY_CID \ -{ 0x68e73d52, 0x12eb, 0x11d3, { 0xbd, 0xc0, 0x00, 0x50, 0x04, 0x0a, 0x9b, 0x44 } } +// Splash screen bitmap ID. +#define IDB_SPLASH 101 -extern nsresult NS_NewSessionHistoryFactory(nsIFactory** aResult); +// DDE application name +#define ID_DDE_APPLICATION_NAME 102 -#endif /* nsAppShellCIDs_h__ */ +#define IDI_APPICON 0 +#define IDI_DOCUMENT 1 +#endif + +// String that goes in the WinXP Start Menu. +#define IDS_STARTMENU_APPNAME 103 diff --git a/mozilla/widget/src/gtk/nsAppShell.cpp b/mozilla/widget/src/gtk/nsAppShell.cpp index 688b56d30bf..651b64d2cf4 100644 --- a/mozilla/widget/src/gtk/nsAppShell.cpp +++ b/mozilla/widget/src/gtk/nsAppShell.cpp @@ -46,7 +46,6 @@ #include "nsIAppShell.h" #include "nsIServiceManager.h" #include "nsIEventQueueService.h" -#include "nsICmdLineService.h" #include "nsGtkEventHandler.h" #include #include @@ -126,7 +125,6 @@ static unsigned long getNextRequest (void *aClosure) { // //------------------------------------------------------------------------- static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); -static NS_DEFINE_CID(kCmdLineServiceCID, NS_COMMANDLINE_SERVICE_CID); //------------------------------------------------------------------------- @@ -206,22 +204,6 @@ NS_IMETHODIMP nsAppShell::Create(int *bac, char **bav) sInitialized = PR_TRUE; - int argc = bac ? *bac : 0; - char **argv = bav; - - nsresult rv; - - nsCOMPtr cmdLineArgs = do_GetService(kCmdLineServiceCID); - if (cmdLineArgs) { - rv = cmdLineArgs->GetArgc(&argc); - if(NS_FAILED(rv)) - argc = bac ? *bac : 0; - - rv = cmdLineArgs->GetArgv(&argv); - if(NS_FAILED(rv)) - argv = bav; - } - return NS_OK; } diff --git a/mozilla/widget/src/xlib/nsAppShell.cpp b/mozilla/widget/src/xlib/nsAppShell.cpp index 1a5265b7bb3..a44ca542b9d 100644 --- a/mozilla/widget/src/xlib/nsAppShell.cpp +++ b/mozilla/widget/src/xlib/nsAppShell.cpp @@ -58,7 +58,6 @@ #include "nsIWidget.h" #include "nsIEventQueueService.h" #include "nsIServiceManager.h" -#include "nsICmdLineService.h" #include "nsIDragService.h" #include "nsIDragSessionXlib.h" #include "nsITimer.h" @@ -68,7 +67,6 @@ #define CHAR_BUF_SIZE 80 static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); -static NS_DEFINE_CID(kCmdLineServiceCID, NS_COMMANDLINE_SERVICE_CID); static NS_DEFINE_IID(kCDragServiceCID, NS_DRAGSERVICE_CID); /* nsAppShell static members */ @@ -178,17 +176,6 @@ NS_METHOD nsAppShell::Create(int* bac, char ** bav) char **argv = bav; nsresult rv; - nsCOMPtr cmdLineArgs = do_GetService(kCmdLineServiceCID); - if (cmdLineArgs) { - rv = cmdLineArgs->GetArgc(&argc); - if(NS_FAILED(rv)) - argc = bac ? *bac : 0; - - rv = cmdLineArgs->GetArgv(&argv); - if(NS_FAILED(rv)) - argv = bav; - } - char *displayName = nsnull; Bool synchronize = False; int i; diff --git a/mozilla/xpfe/appshell/public/Makefile.in b/mozilla/xpfe/appshell/public/Makefile.in index 56c3182f977..159483eceb1 100644 --- a/mozilla/xpfe/appshell/public/Makefile.in +++ b/mozilla/xpfe/appshell/public/Makefile.in @@ -48,30 +48,17 @@ GRE_MODULE = 1 EXPORTS = \ nsIWebShellWindow.h \ - nsAppShellCIDs.h \ - nsISplashScreen.h \ + nsAppShellCID.h \ $(NULL) XPIDLSRCS = \ nsIAppShellService.idl \ - nsICmdLineService.idl \ - nsICmdLineHandler.idl \ nsIWindowMediator.idl \ nsIWindowMediatorListener.idl \ nsIXULWindow.idl \ - nsIUserInfo.idl \ - nsINativeAppSupport.idl \ nsIPopupWindowManager.idl \ - nsICloseAllWindows.idl \ + nsIXULBrowserWindow.idl \ $(NULL) -ifeq ($(MOZ_WIDGET_TOOLKIT),windows) -XPIDLSRCS += nsINativeAppSupportWin.idl -endif -ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) -EXPORTS += nsAppleEvents.h -XPIDLSRCS += nsICloseAllWindows.idl -endif - include $(topsrcdir)/config/rules.mk diff --git a/mozilla/editor/composer/src/nsEditorService.cpp b/mozilla/xpfe/appshell/public/nsAppShellCID.h similarity index 61% rename from mozilla/editor/composer/src/nsEditorService.cpp rename to mozilla/xpfe/appshell/public/nsAppShellCID.h index 0db650ee640..409f89dfc93 100644 --- a/mozilla/editor/composer/src/nsEditorService.cpp +++ b/mozilla/xpfe/appshell/public/nsAppShellCID.h @@ -1,4 +1,3 @@ -/* -*- 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 * @@ -12,19 +11,18 @@ * for the specific language governing rights and limitations under the * License. * - * The Original Code is mozilla.org code. + * The Original Code is Mozilla Gecko. * * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 + * Benjamin Smedberg + * Portions created by the Initial Developer are Copyright (C) 2004 * the Initial Developer. All Rights Reserved. * * Contributor(s): - * Seth Spitzer * * Alternatively, the contents of this file may be used under the terms of - * either of 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"), + * 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 @@ -36,18 +34,9 @@ * * ***** END LICENSE BLOCK ***** */ -#include "nsEditorService.h" -#include "nsString.h" -#include "plstr.h" +#ifndef nsAppShellCID_h__ +#define nsAppShellCID_h__ -nsEditorService::nsEditorService() -{ -} +#define NS_APPSHELLSERVICE_CONTRACTID "@mozilla.org/appshell/appShellService;1" -nsEditorService::~nsEditorService() -{ -} - -NS_IMPL_ISUPPORTS1(nsEditorService, nsICmdLineHandler) - -CMDLINEHANDLER_IMPL(nsEditorService,"-edit","general.startup.editor","chrome://editor/content/editor.xul","Start with editor.","@mozilla.org/commandlinehandler/general-startup;1?type=editor","Editor Startup Handler", PR_TRUE,"about:blank", PR_TRUE) +#endif diff --git a/mozilla/xpfe/appshell/public/nsIAppShellService.idl b/mozilla/xpfe/appshell/public/nsIAppShellService.idl index 955fd061967..d20beed3b0b 100644 --- a/mozilla/xpfe/appshell/public/nsIAppShellService.idl +++ b/mozilla/xpfe/appshell/public/nsIAppShellService.idl @@ -39,9 +39,8 @@ interface nsIXULWindow; interface nsIURI; -interface nsICmdLineService; -interface nsINativeAppSupport; interface nsIDOMWindowInternal; +interface nsIAppShell; [ptr] native JSContext(JSContext); @@ -49,49 +48,9 @@ interface nsIDOMWindowInternal; struct JSContext; %} -[scriptable, uuid(E5E5AF70-8A38-11D2-9938-0080C7CB1080)] +[scriptable, uuid(70c04d53-150f-450b-9106-387487a3c031)] interface nsIAppShellService : nsISupports { - - const PRUint32 eConsiderQuit = 1; // attempt to quit if all windows are closed - const PRUint32 eAttemptQuit = 2; // try to close all windows, then quit if successful - const PRUint32 eForceQuit = 3; // quit, damnit - - /** - * Required initialization routine. - * @param aCmdLineService is stored and passed to appshell components as - * they are initialized. - * @param aNativeAppSupportOrSplashScreen is an object that can be - * QI'd to either an nsINativeAppSupport or - * nsISplashScreen; this object will be used to - * implement HideSplashScreen. - */ - void initialize(in nsICmdLineService aCmdLineService, - in nsISupports nativeAppSupportOrSplashScreen); - - /** - * Starts up the profile manager with the given arguments - * @param aCmdLineService the arguments given to the program - * @param canInteract If FALSE and UI is needed, will fail - */ - void doProfileStartup(in nsICmdLineService aCmdLineService, in boolean canInteract); - - /** - * Getter for "native app support." - */ - readonly attribute nsINativeAppSupport nativeAppSupport; - - /** - * Runs an application event loop: normally the main event pump which - * defines the lifetime of the application. - */ - void run(); - - /** - * Exit the event loop, shut down the app - */ - void quit(in PRUint32 aFerocity); - /** * Create a window. * @param aParent the parent window. Can be null. @@ -110,6 +69,8 @@ interface nsIAppShellService : nsISupports * tag in the XUL. Set to NS_SIZETOCONTENT to force * the window to wrap to its contents. * @param aInitialHeight like aInitialWidth, but subtly different. + * @param aAppShell a widget "appshell" (event processor) to associate + * with the new window * @param aResult the newly created window is returned here. */ const long SIZE_TO_CONTENT = -1; @@ -119,7 +80,8 @@ interface nsIAppShellService : nsISupports in boolean aLoadDefaultPage, in PRUint32 aChromeMask, in long aInitialWidth, - in long aInitialHeight); + in long aInitialHeight, + in nsIAppShell aAppShell); /** * Close a window. @@ -128,7 +90,9 @@ interface nsIAppShellService : nsISupports void closeTopLevelWindow(in nsIXULWindow aWindow); [noscript] - void createHiddenWindow(); + void createHiddenWindow(in nsIAppShell aAppShell); + + void destroyHiddenWindow(); /** * Return the (singleton) application hidden window, automatically created @@ -146,7 +110,6 @@ interface nsIAppShellService : nsISupports */ readonly attribute nsIDOMWindowInternal hiddenDOMWindow; - /** * Return the (singleton) application hidden window as an nsIDOMWindowInternal, * and, the corresponding JavaScript context pointer. This is useful @@ -162,7 +125,9 @@ interface nsIAppShellService : nsISupports * Add a window to the application's registry of windows. These windows * are generally shown in the Windows taskbar, and the application * knows it can't quit until it's out of registered windows. - * @param aWindow yes + * @param aWindow the window to register + * @note When this method is successful, it fires the global notification + * "xul-window-registered" */ void registerTopLevelWindow(in nsIXULWindow aWindow); @@ -183,39 +148,4 @@ interface nsIAppShellService : nsISupports * false if aWindow is becoming nonmodal (or being closed) */ void topLevelWindowIsModal(in nsIXULWindow aWindow, in boolean aModal); - - /** - * Remove the splash screen (if visible). This need be called - * only once per application session. - */ - void hideSplashScreen(); - - /** - * During application startup (and at other times!) we may temporarily - * encounter a situation where all application windows will be closed - * but we don't want to take this as a signal to quit the app. Bracket - * the code where the last window could close with these. - * (And at application startup, on platforms that don't normally quit - * when the last window has closed, call Enter once, but not Exit) - */ - void enterLastWindowClosingSurvivalArea(); - void exitLastWindowClosingSurvivalArea(); - - /** - * 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/xpfe/appshell/public/nsICloseAllWindows.idl b/mozilla/xpfe/appshell/public/nsICloseAllWindows.idl index 95191eecc9b..f4a64521a85 100644 --- a/mozilla/xpfe/appshell/public/nsICloseAllWindows.idl +++ b/mozilla/xpfe/appshell/public/nsICloseAllWindows.idl @@ -42,9 +42,9 @@ interface nsICloseAllWindows : nsISupports { /** - Closes all open windows, optionally asking to confirm changes if any. - Returns TRUE is the user does not cancel from any confirmation dialog. - */ + * Closes all open windows, optionally asking to confirm changes if any. + * @return TRUE if the user does not cancel from any confirmation dialog. + */ boolean closeAll(in boolean askSave); }; diff --git a/mozilla/xpfe/appshell/public/nsICmdLineService.idl b/mozilla/xpfe/appshell/public/nsICmdLineService.idl index 94d1b8f2fba..200cab8f85a 100644 --- a/mozilla/xpfe/appshell/public/nsICmdLineService.idl +++ b/mozilla/xpfe/appshell/public/nsICmdLineService.idl @@ -39,13 +39,6 @@ #include "nsIFactory.idl" #include "nsICmdLineHandler.idl" -%{C++ -// e34783f5-ac08-11d2-8d19-00805fc2500c -#define NS_COMMANDLINE_SERVICE_CID \ -{ 0xe34783f5, 0xac08, 0x11d2, \ - {0x8d, 0x19, 0x00, 0x80, 0x5f, 0xc2, 0x50,0xc} } -%} - [ptr] native charArray(char*); [scriptable, uuid(e34783f4-ac08-11d2-8d19-00805fc2500c)] interface nsICmdLineService : nsISupports @@ -98,5 +91,4 @@ interface nsICmdLineService : nsISupports * string if you want the "default" handler */ nsICmdLineHandler getHandlerForParam(in string param); - }; diff --git a/mozilla/xpfe/appshell/public/nsIXULWindow.idl b/mozilla/xpfe/appshell/public/nsIXULWindow.idl index 52300a01405..1901e13487a 100644 --- a/mozilla/xpfe/appshell/public/nsIXULWindow.idl +++ b/mozilla/xpfe/appshell/public/nsIXULWindow.idl @@ -41,69 +41,78 @@ /** * The nsIXULWindow + * + * When the window is destroyed, it will fire a "xul-window-destroyed" + * notification through the global observer service. */ interface nsIDocShell; interface nsIDocShellTreeItem; +interface nsIAppShell; interface nsIXULBrowserWindow; [scriptable, uuid(5d72a699-a252-4161-a45f-e7d35e78b7f3)] interface nsIXULWindow : nsISupports { /** - The docshell owning the XUL for this window. - */ + * The docshell owning the XUL for this window. + */ readonly attribute nsIDocShell docShell; /** - Indicates if this window is instrinsically sized. - */ + * Indicates if this window is instrinsically sized. + */ attribute boolean intrinsicallySized; /** - This returns the primary content shell. - - Note that this is a docshell tree item and therefore can not be assured of - what object it is. It could be an editor, a docshell, or a browser object. - Or down the road any other object that supports being a DocShellTreeItem - Query accordingly to determine the capabilities. - */ + * The primary content shell. + * + * Note that this is a docshell tree item and therefore can not be assured of + * what object it is. It could be an editor, a docshell, or a browser object. + * Or down the road any other object that supports being a DocShellTreeItem + * Query accordingly to determine the capabilities. + */ readonly attribute nsIDocShellTreeItem primaryContentShell; /** - This returns the content shell specified by the supplied id. - - Note that this is a docshell tree item and therefore can not be assured of - what object it is. It could be an editor, a docshell, or a browser object. - Or down the road any other object that supports being a DocShellTreeItem - Query accordingly to determine the capabilities. - */ + * The content shell specified by the supplied id. + * + * Note that this is a docshell tree item and therefore can not be assured of + * what object it is. It could be an editor, a docshell, or a browser object. + * Or down the road any other object that supports being a DocShellTreeItem + * Query accordingly to determine the capabilities. + */ nsIDocShellTreeItem getContentShellById(in wstring ID); /** - Tell this window that it has picked up or lost a child XUL window - @param aChild the child window being added or removed - */ + * Tell this window that it has picked up a child XUL window + * @param aChild the child window being added + */ void addChildWindow(in nsIXULWindow aChild); + + /** + * Tell this window that it has lost a child XUL window + * @param aChild the child window being removed + */ void removeChildWindow(in nsIXULWindow aChild); /** - Move the window to a centered position. - @param aRelative the window relative to which the window is moved. - See screen parameter for details. if null, the - window is centered relative to the main screen. - @param aScreen PR_TRUE to center the window relative to the screen - containing aRelative. PR_FALSE to center it relative - to aRelative itself. - @param aAlert PR_TRUE to move the window to an alert position, - generally centered horizontally and 1/3 down from the top. - */ + * Move the window to a centered position. + * @param aRelative the window relative to which the window is moved. + * See screen parameter for details. if null, the + * window is centered relative to the main screen. + * @param aScreen PR_TRUE to center the window relative to the screen + * containing aRelative. PR_FALSE to center it relative + * to aRelative itself. + * @param aAlert PR_TRUE to move the window to an alert position, + * generally centered horizontally and 1/3 down from the top. + */ void center(in nsIXULWindow aRelative, in boolean aScreen, in boolean aAlert); /** - Shows the window as a modal window. That is, ensures that it is visible - and runs a local event loop, exiting only once the window has been closed. - */ + * Shows the window as a modal window. That is, ensures that it is visible + * and runs a local event loop, exiting only once the window has been closed. + */ void showModal(); const unsigned long lowestZ = 0; @@ -112,20 +121,20 @@ interface nsIXULWindow : nsISupports const unsigned long raisedZ = 6; /* "alwaysRaised" attribute */ const unsigned long highestZ = 9; - attribute unsigned long zLevel; + attribute unsigned long zLevel; /** * contextFlags are from nsIWindowCreator2 */ - attribute PRUint32 contextFlags; + attribute PRUint32 contextFlags; /** - Create a new window. - @param aChromeFlags: see nsIWebBrowserChrome - @return the newly minted window - */ - nsIXULWindow createNewWindow(in PRInt32 aChromeFlags); + * Create a new window. + * @param aChromeFlags see nsIWebBrowserChrome + * @return the newly minted window + */ + nsIXULWindow createNewWindow(in PRInt32 aChromeFlags, + in nsIAppShell aAppShell); attribute nsIXULBrowserWindow XULBrowserWindow; }; - diff --git a/mozilla/xpfe/appshell/src/Makefile.in b/mozilla/xpfe/appshell/src/Makefile.in index d552fb7cffe..d56ecbd2f9a 100644 --- a/mozilla/xpfe/appshell/src/Makefile.in +++ b/mozilla/xpfe/appshell/src/Makefile.in @@ -72,16 +72,11 @@ REQUIRES = xpcom \ windowwatcher \ browser \ caps \ - profile \ unicharutil \ uconv \ exthandler \ $(NULL) -ifdef MOZ_PHOENIX -REQUIRES += profilemanager -endif - CPPSRCS = \ nsChromeTreeOwner.cpp \ nsContentTreeOwner.cpp \ @@ -89,33 +84,11 @@ CPPSRCS = \ nsAppShellService.cpp \ nsAppShellWindowEnumerator.cpp \ nsWebShellWindow.cpp \ - nsCommandLineService.cpp \ nsWindowMediator.cpp \ nsAbout.cpp \ nsAppShellFactory.cpp \ $(NULL) -ifeq ($(MOZ_WIDGET_TOOLKIT),os2) -CPPSRCS += nsUserInfoOS2.cpp -else -ifeq ($(OS_ARCH),WINNT) -CPPSRCS += nsUserInfoWin.cpp -else -ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) -CPPSRCS += \ - nsUserInfoMac.cpp \ - nsCommandLineServiceMac.cpp \ - $(NULL) -OS_CXXFLAGS += -fexceptions -EXTRA_COMPONENTS += nsCloseAllWindows.js -else -CPPSRCS += nsUserInfoUnix.cpp -endif -endif -endif - -EXTRA_COMPONENTS = nsCloseAllWindows.js - ifeq ($(OS_ARCH),WINNT) EXTRA_DSO_LIBS = gkgfx endif @@ -128,11 +101,5 @@ EXTRA_DSO_LDOPTS = \ $(MOZ_JS_LIBS) \ $(NULL) -ifeq (,$(filter-out mac cocoa,$(MOZ_WIDGET_TOOLKIT))) -SHARED_LIBRARY_LIBS = $(DIST)/lib/$(LIB_PREFIX)appleevents_s.$(LIB_SUFFIX) -EXTRA_DSO_LDOPTS += $(TK_LIBS) -LOCAL_INCLUDES = -I$(srcdir)/../../bootstrap/appleevents -endif - include $(topsrcdir)/config/rules.mk diff --git a/mozilla/xpfe/appshell/src/nsAppShellFactory.cpp b/mozilla/xpfe/appshell/src/nsAppShellFactory.cpp index dce5f0f952d..8a41c233ac2 100644 --- a/mozilla/xpfe/appshell/src/nsAppShellFactory.cpp +++ b/mozilla/xpfe/appshell/src/nsAppShellFactory.cpp @@ -34,45 +34,31 @@ * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ + #include "nsIFactory.h" #include "nsIComponentManager.h" #include "nscore.h" #include "nsIComponentManager.h" -#include "nsAppShellCIDs.h" -#include "nsICmdLineService.h" #include "nsIWindowMediator.h" #include "nsAbout.h" #include "nsIGenericFactory.h" - #include "nsIAppShellService.h" -#include "nsCommandLineService.h" #include "nsAppShellService.h" #include "nsWindowMediator.h" #include "nsChromeTreeOwner.h" +#include "nsAppShellCID.h" -#include "nsUserInfo.h" - -/* extern the factory entry points for each component... */ -nsresult NS_NewAppShellServiceFactory(nsIFactory** aFactory); - -NS_GENERIC_FACTORY_CONSTRUCTOR(nsCmdLineService) NS_GENERIC_FACTORY_CONSTRUCTOR(nsAppShellService) NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindowMediator) -NS_GENERIC_FACTORY_CONSTRUCTOR(nsUserInfo) static const nsModuleComponentInfo gAppShellModuleInfo[] = { { "AppShell Service", - NS_APPSHELL_SERVICE_CID, - "@mozilla.org/appshell/appShellService;1", + NS_APPSHELLSERVICE_CID, + NS_APPSHELLSERVICE_CONTRACTID, nsAppShellServiceConstructor, }, - { "CommandLine Service", - NS_COMMANDLINE_SERVICE_CID, - "@mozilla.org/appshell/commandLineService;1", - nsCmdLineServiceConstructor, - }, { "Window Mediator", NS_WINDOWMEDIATOR_CID, NS_WINDOWMEDIATOR_CONTRACTID, @@ -82,12 +68,7 @@ static const nsModuleComponentInfo gAppShellModuleInfo[] = NS_ABOUT_CID, NS_ABOUT_MODULE_CONTRACTID_PREFIX, nsAbout::Create, - }, - { "User Info Service", - NS_USERINFO_CID, - NS_USERINFO_CONTRACTID, - nsUserInfoConstructor, - }, + } }; PR_STATIC_CALLBACK(nsresult) diff --git a/mozilla/xpfe/appshell/src/nsAppShellService.cpp b/mozilla/xpfe/appshell/src/nsAppShellService.cpp index 010159a0674..240e179d68c 100644 --- a/mozilla/xpfe/appshell/src/nsAppShellService.cpp +++ b/mozilla/xpfe/appshell/src/nsAppShellService.cpp @@ -47,22 +47,24 @@ #include "nsIEventQueueService.h" #include "nsIObserverService.h" #include "nsIObserver.h" -#include "nsWeakReference.h" #include "nsIXPConnect.h" #include "nsIJSContextStack.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" -#include "nsIAppShell.h" #include "nsIWidget.h" +#include "nsIWindowMediator.h" #include "nsIWindowWatcher.h" +#include "nsPIWindowWatcher.h" #include "nsIDOMWindowInternal.h" #include "nsIWebShellWindow.h" #include "nsWebShellWindow.h" #include "nsIEnumerator.h" -#include "nsICmdLineService.h" #include "nsCRT.h" #include "nsITimelineService.h" #include "prprf.h" +#include "plevent.h" #include "nsWidgetsCID.h" #include "nsIRequestObserver.h" @@ -72,44 +74,23 @@ #include "nsIScriptContext.h" #include "jsapi.h" -/* for the "remigration" stuff */ -#include "nsIPrefService.h" -#include "nsIPrefBranch.h" -#include "nsIPromptService.h" -#include "nsIStringBundle.h" - #include "nsAppShellService.h" -#include "nsIProfileInternal.h" -#include "nsIProfileChangeStatus.h" -#include "nsICloseAllWindows.h" #include "nsISupportsPrimitives.h" #include "nsIPlatformCharset.h" #include "nsICharsetConverterManager.h" #include "nsIUnicodeDecoder.h" -/* Define Class IDs */ -static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID); -static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); -static NS_DEFINE_CID(kWindowMediatorCID, NS_WINDOWMEDIATOR_CID); - -#define gEQActivatedNotification "nsIEventQueueActivated" -#define gEQDestroyedNotification "nsIEventQueueDestroyed" -#define gSkinSelectedTopic "skin-selected" -#define gLocaleSelectedTopic "locale-selected" -#define gInstallRestartTopic "xpinstall-restart" -#define gProfileChangeTeardownTopic "profile-change-teardown" -#define gProfileInitialStateTopic "profile-initial-state" - -// Static Function Prototypes -static nsresult ConvertToUnicode(nsCString& aCharset, const char* inString, nsAString& outString); +class nsIAppShell; nsAppShellService::nsAppShellService() : mXPCOMShuttingDown(PR_FALSE), - mModalWindowCount(0), - mConsiderQuitStopper(0), - mShuttingDown(PR_FALSE), - mAttemptingQuit(PR_FALSE) + mModalWindowCount(0) { + nsCOMPtr obs + (do_GetService("@mozilla.org/observer-service;1")); + + if (obs) + obs->AddObserver(this, "xpcom-shutdown", PR_FALSE); } nsAppShellService::~nsAppShellService() @@ -120,60 +101,9 @@ nsAppShellService::~nsAppShellService() /* * Implement the nsISupports methods... */ -NS_IMPL_THREADSAFE_ADDREF(nsAppShellService) -NS_IMPL_THREADSAFE_RELEASE(nsAppShellService) - -NS_INTERFACE_MAP_BEGIN(nsAppShellService) - NS_INTERFACE_MAP_ENTRY(nsIAppShellService) - NS_INTERFACE_MAP_ENTRY(nsIObserver) - NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference) - NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIAppShellService) -NS_INTERFACE_MAP_END_THREADSAFE - - -NS_IMETHODIMP -nsAppShellService::Initialize( nsICmdLineService *aCmdLineService, - nsISupports *aNativeAppSupportOrSplashScreen ) -{ - nsresult rv; - - // Remember cmd line service. - mCmdLineService = aCmdLineService; - - // Remember where the native app support lives. - mNativeAppSupport = do_QueryInterface(aNativeAppSupportOrSplashScreen); - -#ifndef MOZ_XUL_APP - // Or, remember the splash screen (for backward compatibility). - if (!mNativeAppSupport) - mSplashScreen = do_QueryInterface(aNativeAppSupportOrSplashScreen); -#endif - - NS_TIMELINE_ENTER("nsComponentManager::CreateInstance."); - // Create widget application shell - rv = nsComponentManager::CreateInstance(kAppShellCID, nsnull, - NS_GET_IID(nsIAppShell), - (void**)getter_AddRefs(mAppShell)); - NS_TIMELINE_LEAVE("nsComponentManager::CreateInstance"); - if (NS_FAILED(rv)) - goto done; - - rv = mAppShell->Create(0, nsnull); - if (NS_FAILED(rv)) - goto done; - - // listen to EventQueues' comings and goings. do this after the appshell - // has been created, but after the event queue has been created. that - // latter bit is unfortunate, but we deal with it. - RegisterObserver(PR_TRUE); - - // enable window mediation (and fail if we can't get the mediator) - mWindowMediator = do_GetService(kWindowMediatorCID, &rv); - mWindowWatcher = do_GetService(NS_WINDOWWATCHER_CONTRACTID); - -done: - return rv; -} +NS_IMPL_ISUPPORTS2(nsAppShellService, + nsIAppShellService, + nsIObserver); nsresult nsAppShellService::SetXPConnectSafeContext() @@ -182,14 +112,12 @@ nsAppShellService::SetXPConnectSafeContext() nsCOMPtr cxstack = do_GetService("@mozilla.org/js/xpc/ContextStack;1", &rv); - if (NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr junk; JSContext *cx; rv = GetHiddenWindowAndJSContext(getter_AddRefs(junk), &cx); - if (NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); return cxstack->SetSafeJSContext(cx); } @@ -208,13 +136,11 @@ nsresult nsAppShellService::ClearXPConnectSafeContext() nsCOMPtr junk; JSContext *cx; rv = GetHiddenWindowAndJSContext(getter_AddRefs(junk), &cx); - if (NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); JSContext *safe_cx; rv = cxstack->GetSafeJSContext(&safe_cx); - if (NS_FAILED(rv)) - return rv; + NS_ENSURE_SUCCESS(rv, rv); if (cx == safe_cx) rv = cxstack->SetSafeJSContext(nsnull); @@ -222,206 +148,8 @@ nsresult nsAppShellService::ClearXPConnectSafeContext() return rv; } -/* We know we're trying to quit the app, but may not be able to do so - immediately. Enter a state where we're more ready to quit. - (Does useful work only on the Mac.) */ -void -nsAppShellService::AttemptingQuit(PRBool aAttempt) -{ -#if defined(XP_MAC) || defined(XP_MACOSX) - if (aAttempt) { - // now even the Mac wants to quit when the last window is closed - if (!mAttemptingQuit) - ExitLastWindowClosingSurvivalArea(); - mAttemptingQuit = PR_TRUE; - } else { - // changed our mind. back to normal. - if (mAttemptingQuit) - EnterLastWindowClosingSurvivalArea(); - mAttemptingQuit = PR_FALSE; - } -#else - mAttemptingQuit = aAttempt; -#endif -} - -#ifdef MOZ_XUL_APP NS_IMETHODIMP -nsAppShellService::DoProfileStartup(nsICmdLineService *aCmdLineService, PRBool canInteract) -{ - NS_NOTREACHED("Don't call me, I'm dead!"); - return NS_ERROR_FAILURE; -} -#else -NS_IMETHODIMP -nsAppShellService::DoProfileStartup(nsICmdLineService *aCmdLineService, PRBool canInteract) -{ - nsresult rv; - - nsCOMPtr profileMgr(do_GetService(NS_PROFILE_CONTRACTID, &rv)); - NS_ENSURE_SUCCESS(rv,rv); - - EnterLastWindowClosingSurvivalArea(); - - - // If we are being launched in turbo mode, profile mgr cannot show UI - rv = profileMgr->StartupWithArgs(aCmdLineService, canInteract); - if (!canInteract && rv == NS_ERROR_PROFILE_REQUIRES_INTERACTION) { - NS_WARNING("nsIProfileInternal::StartupWithArgs returned NS_ERROR_PROFILE_REQUIRES_INTERACTION"); - rv = NS_OK; - } - - if (NS_SUCCEEDED(rv)) { - rv = CheckAndRemigrateDefunctProfile(); - NS_ASSERTION(NS_SUCCEEDED(rv), "failed to check and remigrate profile"); - rv = NS_OK; - } - - ExitLastWindowClosingSurvivalArea(); - - // if Quit() was called while we were starting up we have a failure situation... - if (mShuttingDown) - return NS_ERROR_FAILURE; - return rv; -} -#endif - -#ifndef MOZ_XUL_APP -nsresult -nsAppShellService::CheckAndRemigrateDefunctProfile() -{ - nsresult rv; - - nsCOMPtr prefBranch; - nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv,rv); - rv = prefs->GetBranch(nsnull, getter_AddRefs(prefBranch)); - NS_ENSURE_SUCCESS(rv,rv); - - PRInt32 secondsBeforeDefunct; - rv = prefBranch->GetIntPref("profile.seconds_until_defunct", &secondsBeforeDefunct); - NS_ENSURE_SUCCESS(rv,rv); - - // -1 is the value for "never go defunct" - // if the pref is set to -1, we'll never prompt the user to remigrate - // see all.js (and all-ns.js) - if (secondsBeforeDefunct == -1) - return NS_OK; - - // used for converting - // seconds -> millisecs - // and microsecs -> millisecs - PRInt64 oneThousand = LL_INIT(0, 1000); - - PRInt64 defunctInterval; - // Init as seconds - LL_I2L(defunctInterval, secondsBeforeDefunct); - // Convert secs to millisecs - LL_MUL(defunctInterval, defunctInterval, oneThousand); - - nsCOMPtr profileMgr(do_GetService(NS_PROFILE_CONTRACTID, &rv)); - NS_ENSURE_SUCCESS(rv,rv); - - nsXPIDLString profileName; - PRInt64 lastModTime; - profileMgr->GetCurrentProfile(getter_Copies(profileName)); - rv = profileMgr->GetProfileLastModTime(profileName.get(), &lastModTime); - NS_ENSURE_SUCCESS(rv,rv); - - // convert "now" from microsecs to millisecs - PRInt64 nowInMilliSecs = PR_Now(); - LL_DIV(nowInMilliSecs, nowInMilliSecs, oneThousand); - - // determine (using the pref value) when the profile would be considered defunct - PRInt64 defunctIntervalAgo; - LL_SUB(defunctIntervalAgo, nowInMilliSecs, defunctInterval); - - // if we've used our current 6.x / mozilla profile more recently than - // when we'd consider it defunct, don't remigrate - if (LL_CMP(lastModTime, >, defunctIntervalAgo)) - return NS_OK; - - nsCOMPtr origProfileDir; - rv = profileMgr->GetOriginalProfileDir(profileName, getter_AddRefs(origProfileDir)); - // if this fails - // then the current profile is a new one (not from 4.x) - // so we are done. - if (NS_FAILED(rv)) - return NS_OK; - - // Now, we know that a matching 4.x profile exists - // See if it has any newer files in it than our defunct profile. - nsCOMPtr dirEnum; - rv = origProfileDir->GetDirectoryEntries(getter_AddRefs(dirEnum)); - NS_ENSURE_SUCCESS(rv,rv); - - PRBool promptForRemigration = PR_FALSE; - PRBool hasMore; - while (NS_SUCCEEDED(dirEnum->HasMoreElements(&hasMore)) && hasMore) { - nsCOMPtr currElem; - rv = dirEnum->GetNext(getter_AddRefs(currElem)); - NS_ENSURE_SUCCESS(rv,rv); - - PRInt64 currElemModTime; - rv = currElem->GetLastModifiedTime(&currElemModTime); - NS_ENSURE_SUCCESS(rv,rv); - // if this file in our 4.x profile is more recent than when we last used our mozilla / 6.x profile - // we should prompt for re-migration - if (LL_CMP(currElemModTime, >, lastModTime)) { - promptForRemigration = PR_TRUE; - break; - } - } - - // If nothing in the 4.x dir is newer than our defunct profile, return. - if (!promptForRemigration) - return NS_OK; - - nsCOMPtr stringBundleService(do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv)); - NS_ENSURE_SUCCESS(rv,rv); - - nsCOMPtr migrationBundle, brandBundle; - rv = stringBundleService->CreateBundle("chrome://communicator/locale/profile/migration.properties", getter_AddRefs(migrationBundle)); - NS_ENSURE_SUCCESS(rv,rv); - - rv = stringBundleService->CreateBundle("chrome://global/locale/brand.properties", getter_AddRefs(brandBundle)); - NS_ENSURE_SUCCESS(rv,rv); - - nsXPIDLString brandName; - rv = brandBundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(), getter_Copies(brandName)); - NS_ENSURE_SUCCESS(rv,rv); - - nsXPIDLString dialogText; - rv = migrationBundle->GetStringFromName(NS_LITERAL_STRING("confirmRemigration").get(), getter_Copies(dialogText)); - NS_ENSURE_SUCCESS(rv,rv); - - nsCOMPtr promptService(do_GetService("@mozilla.org/embedcomp/prompt-service;1", &rv)); - NS_ENSURE_SUCCESS(rv,rv); - PRInt32 buttonPressed; - rv = promptService->ConfirmEx(nsnull, brandName.get(), - dialogText.get(), - (nsIPromptService::BUTTON_POS_0 * - nsIPromptService::BUTTON_TITLE_YES) + - (nsIPromptService::BUTTON_POS_1 * - nsIPromptService::BUTTON_TITLE_NO), - nsnull, nsnull, nsnull, nsnull, nsnull, &buttonPressed); - NS_ENSURE_SUCCESS(rv,rv); - - if (buttonPressed == 0) { - // Need to shut down the current profile before remigrating it - profileMgr->ShutDownCurrentProfile(nsIProfile::SHUTDOWN_PERSIST); - // If this fails, it will restore what was there. - rv = profileMgr->RemigrateProfile(profileName.get()); - NS_ASSERTION(NS_SUCCEEDED(rv), "Remigration of profile failed."); - // Whether or not we succeeded or failed, need to reset this. - profileMgr->SetCurrentProfile(profileName.get()); - } - return NS_OK; -} -#endif - -NS_IMETHODIMP -nsAppShellService::CreateHiddenWindow() +nsAppShellService::CreateHiddenWindow(nsIAppShell* aAppShell) { nsresult rv; PRInt32 initialHeight = 100, initialWidth = 100; @@ -447,7 +175,7 @@ nsAppShellService::CreateHiddenWindow() nsCOMPtr newWindow; rv = JustCreateTopWindow(nsnull, url, PR_FALSE, PR_FALSE, chromeMask, initialWidth, initialHeight, - PR_TRUE, getter_AddRefs(newWindow)); + PR_TRUE, aAppShell, getter_AddRefs(newWindow)); if (NS_SUCCEEDED(rv)) { mHiddenWindow = newWindow; @@ -476,223 +204,20 @@ nsAppShellService::CreateHiddenWindow() return(rv); } - NS_IMETHODIMP -nsAppShellService::Run(void) +nsAppShellService::DestroyHiddenWindow() { - return mAppShell->Run(); -} - - -NS_IMETHODIMP -nsAppShellService::Quit(PRUint32 aFerocity) -{ - // Quit the application. We will asynchronously call the appshell's - // Exit() method via the ExitCallback() to allow one last pass - // through any events in the queue. This guarantees a tidy cleanup. - nsresult rv = NS_OK; - PRBool postedExitEvent = PR_FALSE; - - if (mShuttingDown) - return NS_OK; - - /* eForceQuit doesn't actually work; it can cause a subtle crash if - there are windows open which have unload handlers which open - new windows. Use eAttemptQuit for now. */ - if (aFerocity == eForceQuit) { - NS_WARNING("attempted to force quit"); - // it will be treated the same as eAttemptQuit, below - } - - mShuttingDown = PR_TRUE; - - if (aFerocity == eConsiderQuit && mConsiderQuitStopper == 0) { - // attempt quit if the last window has been unregistered/closed - - PRBool windowsRemain = PR_TRUE; - - if (mWindowMediator) { - nsCOMPtr windowEnumerator; - mWindowMediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator)); - if (windowEnumerator) - windowEnumerator->HasMoreElements(&windowsRemain); - } - if (!windowsRemain) { - aFerocity = eAttemptQuit; - -#ifndef MOZ_XUL_APP - // Check to see if we should quit in this case. - if (mNativeAppSupport) { - PRBool serverMode = PR_FALSE; - mNativeAppSupport->GetIsServerMode(&serverMode); - if (serverMode) { - // stop! give control to server mode - mShuttingDown = PR_FALSE; - mNativeAppSupport->OnLastWindowClosing(); - return NS_OK; - } - } -#endif - } - } - - /* Currently aFerocity can never have the value of eForceQuit here. - That's temporary (in an unscheduled kind of way) and logically - this code is part of the eForceQuit case, so I'm checking against - that value anyway. Reviewers made me add this comment. */ - if (aFerocity == eAttemptQuit || aFerocity == eForceQuit) { - - AttemptingQuit(PR_TRUE); - - /* Enumerate through each open window and close it. It's important to do - this before we forcequit because this can control whether we really quit - at all. e.g. if one of these windows has an unload handler that - opens a new window. Ugh. I know. */ - if (mWindowMediator) { - nsCOMPtr windowEnumerator; - - mWindowMediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator)); - - if (windowEnumerator) { - - while (1) { - PRBool more; - if (NS_FAILED(rv = windowEnumerator->HasMoreElements(&more)) || !more) - break; - - nsCOMPtr isupports; - rv = windowEnumerator->GetNext(getter_AddRefs(isupports)); - if (NS_FAILED(rv)) - break; - - nsCOMPtr window = do_QueryInterface(isupports); - NS_ASSERTION(window, "not an nsIDOMWindowInternal"); - if (!window) - continue; - - window->Close(); - } - } - - if (aFerocity == eAttemptQuit) { - - aFerocity = eForceQuit; // assume success - - /* Were we able to immediately close all windows? if not, eAttemptQuit - failed. This could happen for a variety of reasons; in fact it's - very likely. Perhaps we're being called from JS and the window->Close - method hasn't had a chance to wrap itself up yet. So give up. - We'll return (with eConsiderQuit) as the remaining windows are - closed. */ - mWindowMediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator)); - if (windowEnumerator) { - PRBool more; - while (windowEnumerator->HasMoreElements(&more), more) { - /* we can't quit immediately. we'll try again as the last window - finally closes. */ - aFerocity = eAttemptQuit; - nsCOMPtr window; - windowEnumerator->GetNext(getter_AddRefs(window)); - nsCOMPtr domWindow(do_QueryInterface(window)); - if (domWindow) { - PRBool closed = PR_FALSE; - domWindow->GetClosed(&closed); - if (!closed) { - rv = NS_ERROR_FAILURE; - break; - } - } - } - } - } - } - } - - if (aFerocity == eForceQuit) { - // do it! - - // No chance of the shutdown being cancelled from here on; tell people - // we're shutting down for sure while all services are still available. - nsCOMPtr obsService = do_GetService("@mozilla.org/observer-service;1", &rv); - obsService->NotifyObservers(nsnull, "quit-application", nsnull); - - // first shutdown native app support; doing this first will prevent new - // requests to open additional windows coming in. - if (mNativeAppSupport) { - mNativeAppSupport->Quit(); - mNativeAppSupport = 0; - } - + if (mHiddenWindow) { nsCOMPtr hiddenWin(do_QueryInterface(mHiddenWindow)); + NS_ASSERTION(hiddenWin, "Hidden window is not nsIWebShellWindow!"); if (hiddenWin) { ClearXPConnectSafeContext(); hiddenWin->Close(); } mHiddenWindow = nsnull; - - // no matter what, make sure we send the exit event. If - // worst comes to worst, we'll do a leaky shutdown but we WILL - // shut down. Well, assuming that all *this* stuff works ;-). - nsCOMPtr svc = do_GetService(kEventQueueServiceCID, &rv); - if (NS_SUCCEEDED(rv)) { - - nsCOMPtr queue; - rv = svc->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(queue)); - if (NS_SUCCEEDED(rv)) { - - PLEvent* event = new PLEvent; - if (event) { - NS_ADDREF_THIS(); - PL_InitEvent(event, - this, - HandleExitEvent, - DestroyExitEvent); - - // XXXdf why enter the queue's critical section? - rv = queue->EnterMonitor(); - if (NS_SUCCEEDED(rv)) - rv = queue->PostEvent(event); - if (NS_SUCCEEDED(rv)) - postedExitEvent = PR_TRUE; - queue->ExitMonitor(); - - if (NS_FAILED(rv)) - PL_DestroyEvent(event); - } else - rv = NS_ERROR_OUT_OF_MEMORY; - } - } } - // turn off the reentrancy check flag, but not if we have - // more asynchronous work to do still. - if (!postedExitEvent) - mShuttingDown = PR_FALSE; - return rv; -} - -void* PR_CALLBACK -nsAppShellService::HandleExitEvent(PLEvent* aEvent) -{ - nsAppShellService *service = - NS_REINTERPRET_CAST(nsAppShellService*, aEvent->owner); - - // Tell the appshell to exit - service->mAppShell->Exit(); - - // We're done "shutting down". - service->mShuttingDown = PR_FALSE; - - return nsnull; -} - -void PR_CALLBACK -nsAppShellService::DestroyExitEvent(PLEvent* aEvent) -{ - nsAppShellService *service = - NS_REINTERPRET_CAST(nsAppShellService*, aEvent->owner); - NS_RELEASE(service); - delete aEvent; + return NS_OK; } /* @@ -704,6 +229,7 @@ nsAppShellService::CreateTopLevelWindow(nsIXULWindow *aParent, PRBool aShowWindow, PRBool aLoadDefaultPage, PRUint32 aChromeMask, PRInt32 aInitialWidth, PRInt32 aInitialHeight, + nsIAppShell* aAppShell, nsIXULWindow **aResult) { @@ -711,7 +237,7 @@ nsAppShellService::CreateTopLevelWindow(nsIXULWindow *aParent, rv = JustCreateTopWindow(aParent, aUrl, aShowWindow, aLoadDefaultPage, aChromeMask, aInitialWidth, aInitialHeight, - PR_FALSE, aResult); + PR_FALSE, aAppShell, aResult); if (NS_SUCCEEDED(rv)) { // the addref resulting from this is the owning addref for this window @@ -767,7 +293,8 @@ nsAppShellService::JustCreateTopWindow(nsIXULWindow *aParent, PRBool aShowWindow, PRBool aLoadDefaultPage, PRUint32 aChromeMask, PRInt32 aInitialWidth, PRInt32 aInitialHeight, - PRBool aIsHiddenWindow, nsIXULWindow **aResult) + PRBool aIsHiddenWindow, nsIAppShell* aAppShell, + nsIXULWindow **aResult) { nsresult rv; nsWebShellWindow* window; @@ -840,7 +367,7 @@ nsAppShellService::JustCreateTopWindow(nsIXULWindow *aParent, window->SetIntrinsicallySized(PR_TRUE); } - rv = window->Initialize(aParent, mAppShell, aUrl, + rv = window->Initialize(aParent, aAppShell, aUrl, aShowWindow, aLoadDefaultPage, aInitialWidth, aInitialHeight, aIsHiddenWindow, widgetInitData); @@ -886,10 +413,10 @@ nsAppShellService::GetHiddenDOMWindow(nsIDOMWindowInternal **aWindow) NS_ENSURE_TRUE(mHiddenWindow, NS_ERROR_FAILURE); rv = mHiddenWindow->GetDocShell(getter_AddRefs(docShell)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr hiddenDOMWindow(do_GetInterface(docShell, &rv)); - if (NS_FAILED(rv)) return rv; + NS_ENSURE_SUCCESS(rv, rv); *aWindow = hiddenDOMWindow; NS_IF_ADDREF(*aWindow); @@ -951,22 +478,35 @@ NS_IMETHODIMP nsAppShellService::RegisterTopLevelWindow(nsIXULWindow* aWindow) { // tell the window mediator about the new window - if (mWindowMediator) - mWindowMediator->RegisterWindow(aWindow); + nsCOMPtr mediator + ( do_GetService(NS_WINDOWMEDIATOR_CONTRACTID) ); + NS_ASSERTION(mediator, "Couldn't get window mediator."); + + if (mediator) + mediator->RegisterWindow(aWindow); // tell the window watcher about the new window - if (mWindowWatcher) { + nsCOMPtr wwatcher ( do_GetService(NS_WINDOWWATCHER_CONTRACTID) ); + NS_ASSERTION(wwatcher, "No windowwatcher?"); + if (wwatcher) { nsCOMPtr docShell; aWindow->GetDocShell(getter_AddRefs(docShell)); + NS_ASSERTION(docShell, "Window has no docshell"); if (docShell) { nsCOMPtr domWindow(do_GetInterface(docShell)); + NS_ASSERTION(domWindow, "Couldn't get DOM window."); if (domWindow) - mWindowWatcher->AddWindow(domWindow, 0); + wwatcher->AddWindow(domWindow, 0); } } // an ongoing attempt to quit is stopped by a newly opened window - AttemptingQuit(PR_FALSE); + nsCOMPtr obssvc = + do_GetService("@mozilla.org/observer-service;1"); + NS_ASSERTION(obssvc, "Couldn't get observer service."); + + if (obssvc) + obssvc->NotifyObservers(aWindow, "xul-window-registered", nsnull); return NS_OK; } @@ -990,23 +530,30 @@ nsAppShellService::UnregisterTopLevelWindow(nsIXULWindow* aWindow) NS_ENSURE_ARG_POINTER(aWindow); // tell the window mediator - if (mWindowMediator) - mWindowMediator->UnregisterWindow(aWindow); + nsCOMPtr mediator + ( do_GetService(NS_WINDOWMEDIATOR_CONTRACTID) ); + NS_ASSERTION(mediator, "Couldn't get window mediator. Doing xpcom shutdown?"); + + if (mediator) + mediator->UnregisterWindow(aWindow); // tell the window watcher - if (mWindowWatcher) { + nsCOMPtr wwatcher ( do_GetService(NS_WINDOWWATCHER_CONTRACTID) ); + NS_ASSERTION(wwatcher, "Couldn't get windowwatcher, doing xpcom shutdown?"); + if (wwatcher) { nsCOMPtr docShell; aWindow->GetDocShell(getter_AddRefs(docShell)); if (docShell) { nsCOMPtr domWindow(do_GetInterface(docShell)); if (domWindow) - mWindowWatcher->RemoveWindow(domWindow); + wwatcher->RemoveWindow(domWindow); } } return NS_OK; } +/* Old function, needs to be removed... it was only used on Mac OS9 */ NS_IMETHODIMP nsAppShellService::TopLevelWindowIsModal(nsIXULWindow *aWindow, PRBool aModal) { @@ -1014,476 +561,17 @@ nsAppShellService::TopLevelWindowIsModal(nsIXULWindow *aWindow, PRBool aModal) } NS_IMETHODIMP -nsAppShellService::EnterLastWindowClosingSurvivalArea(void) +nsAppShellService::Observe(nsISupports* aSubject, const char *aTopic, + const PRUnichar *aData) { - PR_AtomicIncrement(&mConsiderQuitStopper); + NS_ASSERTION(!strcmp(aTopic, "xpcom-shutdown"), "Unexpected observer topic!"); + + mXPCOMShuttingDown = PR_TRUE; + nsCOMPtr hiddenWin (do_QueryInterface(mHiddenWindow)); + if (hiddenWin) { + ClearXPConnectSafeContext(); + hiddenWin->Close(); + } + return NS_OK; } - -NS_IMETHODIMP -nsAppShellService::ExitLastWindowClosingSurvivalArea(void) -{ - NS_ASSERTION(mConsiderQuitStopper > 0, "consider quit stopper out of bounds"); - PR_AtomicDecrement(&mConsiderQuitStopper); - return NS_OK; -} - -//------------------------------------------------------------------------- - -NS_IMETHODIMP -nsAppShellService::CreateStartupState(PRInt32 aWindowWidth, PRInt32 aWindowHeight, PRBool *_retval) -{ - NS_ENSURE_ARG_POINTER(_retval); - nsresult rv; -#ifndef MOZ_THUNDERBIRD - 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; -#endif - - return NS_OK; -} - -nsresult -nsAppShellService::LaunchTask(const char *aParam, PRInt32 height, PRInt32 width, PRBool *windowOpened) -{ - nsresult rv = NS_OK; - - nsCOMPtr cmdLine = - do_GetService("@mozilla.org/appshell/commandLineService;1", &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 - nsXPIDLString defaultArgs; - rv = handler->GetDefaultArgs(getter_Copies(defaultArgs)); - if (NS_FAILED(rv)) return rv; - rv = OpenWindow(chromeUrlForTask, defaultArgs, SIZE_TO_CONTENT, 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, SIZE_TO_CONTENT, 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 -nsAppShellService::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; - -#ifndef MOZ_XUL_APP - // Make sure a profile is selected. - - // We need the native app support object. If this fails, we still proceed. - // That's because some platforms don't have a native app - // support implementation. On those platforms, "ensuring a - // profile" is moot (because they don't support "-turbo", - // basically). Specifically, because they don't do turbo, they will - // *always* have a profile selected. - nsCOMPtr nativeApp; - if (NS_SUCCEEDED(GetNativeAppSupport(getter_AddRefs(nativeApp)))) - { - nsCOMPtr cmdLine = - do_GetService("@mozilla.org/appshell/commandLineService;1"); - - if (cmdLine) { - // Make sure profile has been selected. - // At this point, we have to look for failure. That - // handles the case where the user chooses "Exit" on - // the profile manager window. - if (NS_FAILED(nativeApp->EnsureProfile(cmdLine))) - return NS_ERROR_NOT_INITIALIZED; - } - } -#endif - - 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)); -} - -NS_IMETHODIMP -nsAppShellService::Ensure1Window(nsICmdLineService *aCmdLineService) -{ - nsresult rv; - -#ifndef MOZ_XUL_APP - // If starting up in server mode, then we do things differently. - nsCOMPtr nativeApp; - rv = GetNativeAppSupport(getter_AddRefs(nativeApp)); - if (NS_SUCCEEDED(rv)) { - PRBool isServerMode = PR_FALSE; - nativeApp->GetIsServerMode(&isServerMode); - if (isServerMode) { - nativeApp->StartServerMode(); - } - PRBool shouldShowUI = PR_TRUE; - nativeApp->GetShouldShowUI(&shouldShowUI); - if (!shouldShowUI) { - return NS_OK; - } - } -#endif - - nsCOMPtr windowMediator(do_GetService(kWindowMediatorCID, &rv)); - if (NS_FAILED(rv)) - return 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 - 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; -} - -nsresult -nsAppShellService::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("@mozilla.org/appshell/commandLineService;1", &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; - if (nsCRT::IsAscii(urlToLoad)) { - url.AssignWithConversion(urlToLoad); - } - else { - // get a platform charset - nsCAutoString charSet; - nsCOMPtr platformCharset(do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv)); - if (NS_FAILED(rv)) { - NS_ASSERTION(0, "Failed to get a platform charset"); - return rv; - } - - rv = platformCharset->GetCharset(kPlatformCharsetSel_FileName, charSet); - if (NS_FAILED(rv)) { - NS_ASSERTION(0, "Failed to get a charset"); - return rv; - } - - // convert the cmdLine URL to Unicode - rv = ConvertToUnicode(charSet, urlToLoad, url); - if (NS_FAILED(rv)) { - NS_ASSERTION(0, "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; -} - -//------------------------------------------------------------------------- -// nsIObserver interface and friends -//------------------------------------------------------------------------- - -NS_IMETHODIMP nsAppShellService::Observe(nsISupports *aSubject, - const char *aTopic, - const PRUnichar *aData) -{ - NS_ASSERTION(mAppShell, "appshell service notified before appshell built"); - if (!strcmp(aTopic, gEQActivatedNotification)) { - nsCOMPtr eq(do_QueryInterface(aSubject)); - if (eq) { - PRBool isNative = PR_TRUE; - // we only add native event queues to the appshell - eq->IsQueueNative(&isNative); - if (isNative) - mAppShell->ListenToEventQueue(eq, PR_TRUE); - } - } else if (!strcmp(aTopic, gEQDestroyedNotification)) { - nsCOMPtr eq(do_QueryInterface(aSubject)); - if (eq) { - PRBool isNative = PR_TRUE; - // we only remove native event queues from the appshell - eq->IsQueueNative(&isNative); - if (isNative) - mAppShell->ListenToEventQueue(eq, PR_FALSE); - } -#ifndef MOZ_XUL_APP - } else if (!strcmp(aTopic, gSkinSelectedTopic) || - !strcmp(aTopic, gLocaleSelectedTopic) || - !strcmp(aTopic, gInstallRestartTopic)) { - if (mNativeAppSupport) - mNativeAppSupport->SetIsServerMode(PR_FALSE); -#endif - } else if (!strcmp(aTopic, gProfileChangeTeardownTopic)) { - nsresult rv; - EnterLastWindowClosingSurvivalArea(); - // NOTE: No early error exits because we need to execute the - // balancing ExitLastWindowClosingSurvivalArea(). - nsCOMPtr closer = - do_CreateInstance("@mozilla.org/appshell/closeallwindows;1", &rv); - NS_ASSERTION(closer, "Failed to create nsICloseAllWindows impl."); - PRBool proceedWithSwitch = PR_FALSE; - if (closer) - rv = closer->CloseAll(PR_TRUE, &proceedWithSwitch); - if (NS_FAILED(rv) || !proceedWithSwitch) { - nsCOMPtr changeStatus(do_QueryInterface(aSubject)); - if (changeStatus) - changeStatus->VetoChange(); - } - ExitLastWindowClosingSurvivalArea(); - } else if (!strcmp(aTopic, gProfileInitialStateTopic) && - nsDependentString(aData).EqualsLiteral("switch")) { - // Now, establish the startup state according to the new prefs. - PRBool openedWindow; - CreateStartupState(SIZE_TO_CONTENT, SIZE_TO_CONTENT, &openedWindow); - if (!openedWindow) - OpenBrowserWindow(SIZE_TO_CONTENT, SIZE_TO_CONTENT); - } else if (!strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID)) { - mXPCOMShuttingDown = PR_TRUE; - nsCOMPtr hiddenWin(do_QueryInterface(mHiddenWindow)); - if(hiddenWin) { - ClearXPConnectSafeContext(); - hiddenWin->Close(); - } - } - return NS_OK; -} - -/* ask nsIObserverService to tell us about nsEventQueue notifications */ -void nsAppShellService::RegisterObserver(PRBool aRegister) -{ - nsresult rv; - nsISupports *glop; - - // here's a silly dance. seems better to do it than not, though... - nsCOMPtr weObserve(do_QueryInterface(NS_STATIC_CAST(nsIObserver *, this))); - - NS_ASSERTION(weObserve, "who's been chopping bits off nsAppShellService?"); - - rv = nsServiceManager::GetService("@mozilla.org/observer-service;1", - NS_GET_IID(nsIObserverService), &glop); - if (NS_SUCCEEDED(rv)) { - nsIObserverService *os = NS_STATIC_CAST(nsIObserverService*,glop); - if (aRegister) { - os->AddObserver(weObserve, gEQActivatedNotification, PR_TRUE); - os->AddObserver(weObserve, gEQDestroyedNotification, PR_TRUE); - os->AddObserver(weObserve, gSkinSelectedTopic, PR_TRUE); - os->AddObserver(weObserve, gLocaleSelectedTopic, PR_TRUE); - os->AddObserver(weObserve, gInstallRestartTopic, PR_TRUE); - os->AddObserver(weObserve, gProfileChangeTeardownTopic, PR_TRUE); - os->AddObserver(weObserve, gProfileInitialStateTopic, PR_TRUE); - os->AddObserver(weObserve, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE); - } else { - os->RemoveObserver(weObserve, gEQActivatedNotification); - os->RemoveObserver(weObserve, gEQDestroyedNotification); - os->RemoveObserver(weObserve, gSkinSelectedTopic); - os->RemoveObserver(weObserve, gLocaleSelectedTopic); - os->RemoveObserver(weObserve, gInstallRestartTopic); - os->RemoveObserver(weObserve, gProfileChangeTeardownTopic); - os->RemoveObserver(weObserve, gProfileInitialStateTopic); - os->RemoveObserver(weObserve, NS_XPCOM_SHUTDOWN_OBSERVER_ID); - } - NS_RELEASE(glop); - } -} - -NS_IMETHODIMP -nsAppShellService::HideSplashScreen() { -#ifndef MOZ_XUL_APP - // Hide the splash screen. - if ( mNativeAppSupport ) { - mNativeAppSupport->HideSplashScreen(); - } - else if ( mSplashScreen ) { - mSplashScreen->Hide(); - } -#endif - return NS_OK; -} - -NS_IMETHODIMP -nsAppShellService::GetNativeAppSupport( nsINativeAppSupport **aResult ) { - NS_ENSURE_ARG( aResult ); - *aResult = mNativeAppSupport; - NS_IF_ADDREF( *aResult ); - return *aResult ? NS_OK : NS_ERROR_NULL_POINTER; -} - -static nsresult ConvertToUnicode(nsCString& aCharset, const char* inString, nsAString& outString) -{ - nsresult rv; - - // convert result to unicode - nsCOMPtr ccm(do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID , &rv)); - if (NS_FAILED(rv)) - return rv; - - nsCOMPtr decoder; - rv = ccm->GetUnicodeDecoderRaw(aCharset.get(), getter_AddRefs(decoder)); - if (NS_FAILED(rv)) - return rv; - - PRInt32 uniLength = 0; - PRInt32 srcLength = strlen(inString); - rv = decoder->GetMaxLength(inString, srcLength, &uniLength); - if (NS_FAILED(rv)) - return rv; - - PRUnichar *unichars = new PRUnichar [uniLength]; - if (nsnull != unichars) { - // convert to unicode - rv = decoder->Convert(inString, &srcLength, unichars, &uniLength); - if (NS_SUCCEEDED(rv)) { - // Pass back the unicode string - outString.Assign(unichars, uniLength); - } - delete [] unichars; - } - else { - rv = NS_ERROR_OUT_OF_MEMORY; - } - - return rv; -} diff --git a/mozilla/xpfe/appshell/src/nsAppShellService.h b/mozilla/xpfe/appshell/src/nsAppShellService.h index d40123e4bc2..a5c3e524667 100644 --- a/mozilla/xpfe/appshell/src/nsAppShellService.h +++ b/mozilla/xpfe/appshell/src/nsAppShellService.h @@ -34,83 +34,48 @@ * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ + #ifndef __nsAppShellService_h #define __nsAppShellService_h #include "nsIAppShellService.h" -#include "nsINativeAppSupport.h" #include "nsIObserver.h" -#include "nsWeakReference.h" -#include "nsIAppShell.h" -#include "plevent.h" //Interfaces Needed #include "nsIXULWindow.h" -#include "nsIWindowMediator.h" -#include "nsPIWindowWatcher.h" -#include "nsISplashScreen.h" +#include "nsStringFwd.h" + +// {0099907D-123C-4853-A46A-43098B5FB68C} +#define NS_APPSHELLSERVICE_CID \ +{ 0x99907d, 0x123c, 0x4853, { 0xa4, 0x6a, 0x43, 0x9, 0x8b, 0x5f, 0xb6, 0x8c } } class nsAppShellService : public nsIAppShellService, - public nsIObserver, - public nsSupportsWeakReference + public nsIObserver { public: - nsAppShellService(void); - NS_DECL_ISUPPORTS NS_DECL_NSIAPPSHELLSERVICE NS_DECL_NSIOBSERVER -protected: - virtual ~nsAppShellService(); + nsAppShellService(); + +protected: + ~nsAppShellService(); - void RegisterObserver(PRBool aRegister); NS_IMETHOD JustCreateTopWindow(nsIXULWindow *aParent, nsIURI *aUrl, PRBool aShowWindow, PRBool aLoadDefaultPage, PRUint32 aChromeMask, PRInt32 aInitialWidth, PRInt32 aInitialHeight, - PRBool aIsHiddenWindow, nsIXULWindow **aResult); + PRBool aIsHiddenWindow, nsIAppShell* aAppShell, + nsIXULWindow **aResult); PRUint32 CalculateWindowZLevel(nsIXULWindow *aParent, PRUint32 aChromeMask); nsresult SetXPConnectSafeContext(); nsresult ClearXPConnectSafeContext(); - void AttemptingQuit(PRBool aAttempt); - nsCOMPtr mAppShell; - nsCOMPtr mCmdLineService; - nsCOMPtr mWindowMediator; - nsCOMPtr mWindowWatcher; nsCOMPtr mHiddenWindow; - PRBool mXPCOMShuttingDown; -#ifndef MOZ_XUL_APP - nsCOMPtr mSplashScreen; -#endif - nsCOMPtr mNativeAppSupport; - - PRUint16 mModalWindowCount; - PRInt32 mConsiderQuitStopper; // if > 0, Quit(eConsiderQuit) fails - PRPackedBool mShuttingDown; // Quit method reentrancy check - PRPackedBool mAttemptingQuit; // Quit(eAttemptQuit) still trying - - // A "last event" that is used to flush the appshell's event queue. - PR_STATIC_CALLBACK(void*) HandleExitEvent(PLEvent* aEvent); - PR_STATIC_CALLBACK(void) DestroyExitEvent(PLEvent* aEvent); - -private: -#ifndef MOZ_XUL_APP - nsresult CheckAndRemigrateDefunctProfile(); -#endif - - 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); - + PRPackedBool mXPCOMShuttingDown; + PRUint16 mModalWindowCount; }; #endif diff --git a/mozilla/xpfe/appshell/src/nsCommandLineService.h b/mozilla/xpfe/appshell/src/nsCommandLineService.h index afc87f9fb47..7705e96b21b 100644 --- a/mozilla/xpfe/appshell/src/nsCommandLineService.h +++ b/mozilla/xpfe/appshell/src/nsCommandLineService.h @@ -62,4 +62,9 @@ protected: PRBool ArgsMatch(const char *lookingFor, const char *userGave); }; +// e34783f5-ac08-11d2-8d19-00805fc2500c +#define NS_COMMANDLINESERVICE_CID \ +{ 0xe34783f5, 0xac08, 0x11d2, \ + {0x8d, 0x19, 0x00, 0x80, 0x5f, 0xc2, 0x50,0xc} } + #endif diff --git a/mozilla/xpfe/appshell/src/nsCommandLineServiceMac.cpp b/mozilla/xpfe/appshell/src/nsCommandLineServiceMac.cpp index cd27e0628e6..bd6ff7bb44c 100644 --- a/mozilla/xpfe/appshell/src/nsCommandLineServiceMac.cpp +++ b/mozilla/xpfe/appshell/src/nsCommandLineServiceMac.cpp @@ -46,7 +46,7 @@ #include "nsILocalFileMac.h" #include "nsDebug.h" #include "nsNetUtil.h" -#include "nsIAppShellService.h" +#include "nsIAppStartup.h" #include "nsIServiceManager.h" #include "nsIURL.h" #include "nsIIOService.h" @@ -65,6 +65,7 @@ #include "nsIPrefService.h" #include "nsAEEventHandling.h" +#include "nsXPFEComponentsCID.h" // NSPR #include "prmem.h" @@ -74,9 +75,6 @@ #include "pprio.h" // PR_Init_Log #endif -#include "nsAppShellCIDs.h" -static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); - // the static instance nsMacCommandLine nsMacCommandLine::sMacCommandLine; @@ -402,12 +400,12 @@ OSErr nsMacCommandLine::Quit(TAskSave askSave) if (NS_FAILED(rv) || !doQuit) return errAEEventNotHandled; - nsCOMPtr appShellService = - do_GetService(kAppShellServiceCID, &rv); + nsCOMPtr appStartup = + (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv)); if (NS_FAILED(rv)) return errAEEventNotHandled; - (void)appShellService->Quit(nsIAppShellService::eAttemptQuit); + (void)appStartup->Quit(nsIAppStartup::eAttemptQuit); return noErr; } diff --git a/mozilla/xpfe/appshell/src/nsPreloader.cpp b/mozilla/xpfe/appshell/src/nsPreloader.cpp deleted file mode 100644 index 4b7abfa50ad..00000000000 --- a/mozilla/xpfe/appshell/src/nsPreloader.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** 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 Mozilla Communicator client code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Alec Flett - * - * Alternatively, the contents of this file may be used under the terms of - * either of 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 "nsPreloader.h" -#include "nsString.h" -#include "nsIObserver.h" -#include "nsIAppStartupNotifier.h" - -struct preloadEntry { - PRBool isService; - const char* contractId; -}; - -static preloadEntry preloadedObjects[] = { - // necko - {PR_TRUE, "@mozilla.org/network/io-service;1" }, - // rdf - {PR_TRUE, "@mozilla.org/rdf/rdf-service;1" }, - // preferences - {PR_TRUE, "@mozilla.org/preferences-service;1" }, - // string bundles - {PR_TRUE, "@mozilla.org/intl/stringbundle;1" }, - // docshell - {PR_FALSE, "@mozilla.org/docshell/html;1" }, - // imglib - - // appcomps - // parser -}; - -#define PRELOADED_SERVICES_COUNT (sizeof(preloadedObjects) / sizeof(preloadedObjects[0])) - -NS_IMPL_ISUPPORTS1(nsPreloader, nsICmdLineHandler) - -nsPreloader::nsPreloader() -{ -} - -nsresult -nsPreloader::Init() -{ - nsresult rv; - - nsCOMPtr startupNotifier = - do_CreateInstance(NS_APPSTARTUPNOTIFIER_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - - rv = startupNotifier->Observe(nsnull, NS_LITERAL_STRING("preloaded-services").get(), nsnull); - - return rv; -} - -nsPreloader::~nsPreloader() -{ -} - -CMDLINEHANDLER1_IMPL(nsPreloader, // classname - "-server", // arguments - "general.startup.server", // pref name (not used) - "Load and stay resident!", // command line help text - PR_FALSE, // handles window arguments? - "", // no window arguments - PR_FALSE) // don't open a window - -CMDLINEHANDLER_GETCHROMEURL_IMPL(nsPreloader,nsnull) -CMDLINEHANDLER_GETDEFAULTARGS_IMPL(nsPreloader,"") - -NS_METHOD -nsPreloader::RegisterProc(nsIComponentManager *aCompMgr, nsIFile *aPath, - const char *registryLocation, - const char *componentType, - const nsModuleComponentInfo *info) -{ - nsresult rv; - nsCOMPtr catman = - do_GetService("@mozilla.org/categorymanager;1", &rv); - if (NS_FAILED(rv)) return rv; - - rv = catman->AddCategoryEntry(COMMAND_LINE_ARGUMENT_HANDLERS, - "Preloader Commandline Handler", - NS_PRELOADER_CONTRACTID, - PR_TRUE, PR_TRUE, nsnull); - if (NS_FAILED(rv)) return rv; - - // now register all the well-known services - - PRInt32 i; - for (i=0; iAddCategoryEntry("preloaded-services", - categoryEntry.get(), // key - must be unique - categoryEntry.get(), // value - the contractid - PR_TRUE, PR_TRUE, nsnull); - } - - return NS_OK; -} - -NS_METHOD -nsPreloader::UnregisterProc(nsIComponentManager *aCompMgr, - nsIFile *aFile, const char *registryLocation, - const nsModuleComponentInfo *info) -{ - nsresult rv; - nsCOMPtr catman = do_GetService("@mozilla.org/categorymanager;1", &rv); - if (NS_FAILED(rv)) return rv; - - rv = catman->DeleteCategoryEntry(COMMAND_LINE_ARGUMENT_HANDLERS, - NS_PRELOADER_CONTRACTID, - PR_TRUE); - - // unregister well-known services? - - return NS_OK; -} diff --git a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp index 04b4a031903..c71869245a5 100644 --- a/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp +++ b/mozilla/xpfe/appshell/src/nsWebShellWindow.cpp @@ -72,7 +72,6 @@ #include "nsIAppShell.h" #include "nsIAppShellService.h" -#include "nsAppShellCIDs.h" #include "nsIDOMCharacterData.h" #include "nsIDOMNodeList.h" diff --git a/mozilla/xpfe/appshell/src/nsXULWindow.cpp b/mozilla/xpfe/appshell/src/nsXULWindow.cpp index 0646156f564..7035ffb4068 100644 --- a/mozilla/xpfe/appshell/src/nsXULWindow.cpp +++ b/mozilla/xpfe/appshell/src/nsXULWindow.cpp @@ -43,7 +43,6 @@ #include "nsXULWindow.h" // Helper classes -#include "nsAppShellCIDs.h" #include "nsString.h" #include "nsWidgetsCID.h" #include "prprf.h" @@ -86,6 +85,7 @@ #include "nsIDOMViewCSS.h" #include "nsIDOMCSSStyleDeclaration.h" #include "nsITimelineService.h" +#include "nsAppShellCID.h" #include "nsReadableUtils.h" #include "nsStyleConsts.h" @@ -109,7 +109,6 @@ #define ZLEVEL_ATTRIBUTE NS_LITERAL_STRING("zlevel") // CIDs static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID); -static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); @@ -363,7 +362,7 @@ NS_IMETHODIMP nsXULWindow::ShowModal() mContinueModalLoop = PR_TRUE; EnableParent(PR_FALSE); - nsCOMPtr appShellService(do_GetService(kAppShellServiceCID)); + nsCOMPtr appShellService(do_GetService(NS_APPSHELLSERVICE_CONTRACTID)); if (appShellService) appShellService->TopLevelWindowIsModal( NS_STATIC_CAST(nsIXULWindow*, this), PR_TRUE); @@ -434,7 +433,8 @@ NS_IMETHODIMP nsXULWindow::Destroy() if(!mWindow) return NS_OK; - nsCOMPtr appShell(do_GetService(kAppShellServiceCID)); + nsCOMPtr appShell(do_GetService(NS_APPSHELLSERVICE_CONTRACTID)); + NS_ASSERTION(appShell, "Couldn't get appShell... xpcom shutdown?"); if(appShell) appShell->UnregisterTopLevelWindow(NS_STATIC_CAST(nsIXULWindow*, this)); @@ -442,25 +442,6 @@ NS_IMETHODIMP nsXULWindow::Destroy() if (parentWindow) parentWindow->RemoveChildWindow(this); -// Anyone still using native menus should add themselves here. -#if defined(XP_MAC) || defined(XP_MACOSX) - { - // unregister as document listener - // this is needed for menus - nsCOMPtr cv; - if(mDocShell) - mDocShell->GetContentViewer(getter_AddRefs(cv)); - nsCOMPtr docv(do_QueryInterface(cv)); - if(docv) - { - nsCOMPtr doc; - docv->GetDocument(getter_AddRefs(doc)); -/* if(doc) - doc->RemoveObserver(NS_STATIC_CAST(nsIDocumentObserver*, this)); */ - } - } -#endif - // let's make sure the window doesn't get deleted out from under us // while we are trying to close....this can happen if the docshell // we close ends up being the last owning reference to this xulwindow @@ -534,14 +515,18 @@ NS_IMETHODIMP nsXULWindow::Destroy() mWindow = nsnull; } - /* Inform the appshellservice we've destroyed this window and it could + /* Inform appstartup we've destroyed this window and it could quit now if it wanted. This must happen at least after mDocShell is destroyed, because onunload handlers fire then, and those being script, anything could happen. A new window could open, even. See bug 130719. */ - if(appShell) - appShell->Quit(nsIAppShellService::eConsiderQuit); - + nsCOMPtr obssvc = + do_GetService("@mozilla.org/observer-service;1"); + NS_ASSERTION(obssvc, "Couldn't get observer service?"); + + if (obssvc) + obssvc->NotifyObservers(nsnull, "xul-window-destroyed", nsnull); + return NS_OK; } @@ -760,15 +745,14 @@ NS_IMETHODIMP nsXULWindow::SetVisibility(PRBool aVisibility) if(windowMediator) windowMediator->UpdateWindowTimeStamp(NS_STATIC_CAST(nsIXULWindow*, this)); - // Hide splash screen (if there is one). - static PRBool splashScreenGone = PR_FALSE; - if(!splashScreenGone) - { - nsCOMPtr appShellService(do_GetService(kAppShellServiceCID)); - if(appShellService) - appShellService->HideSplashScreen(); - splashScreenGone = PR_TRUE; - } + // notify observers so that we can hide the splash screen if possible + nsCOMPtr obssvc + (do_GetService("@mozilla.org/observer-service;1")); + NS_WARN_IF_FALSE(obssvc, "Couldn't get observer service."); + if (obssvc) { + obssvc->NotifyObservers(nsnull, "xul-window-visible", nsnull); + } + mDebuting = PR_FALSE; NS_TIMELINE_LEAVE("nsXULWindow::SetVisibility"); return NS_OK; @@ -1556,22 +1540,18 @@ NS_IMETHODIMP nsXULWindow::GetWindowDOMElement(nsIDOMElement** aDOMElement) nsCOMPtr cv; mDocShell->GetContentViewer(getter_AddRefs(cv)); - if(!cv) - return NS_ERROR_FAILURE; + NS_ENSURE_TRUE(cv, NS_ERROR_FAILURE); nsCOMPtr docv(do_QueryInterface(cv)); - if(!docv) - return NS_ERROR_FAILURE; + NS_ENSURE_TRUE(docv, NS_ERROR_FAILURE); nsCOMPtr doc; docv->GetDocument(getter_AddRefs(doc)); nsCOMPtr domdoc(do_QueryInterface(doc)); - if(!domdoc) - return NS_ERROR_FAILURE; + NS_ENSURE_TRUE(domdoc, NS_ERROR_FAILURE); domdoc->GetDocumentElement(aDOMElement); - if(!*aDOMElement) - return NS_ERROR_FAILURE; + NS_ENSURE_TRUE(*aDOMElement, NS_ERROR_FAILURE); return NS_OK; } @@ -1700,20 +1680,20 @@ NS_IMETHODIMP nsXULWindow::ExitModalLoop(nsresult aStatus) // top-level function to create a new window NS_IMETHODIMP nsXULWindow::CreateNewWindow(PRInt32 aChromeFlags, - nsIXULWindow **_retval) + nsIAppShell* aAppShell, nsIXULWindow **_retval) { NS_ENSURE_ARG_POINTER(_retval); if (aChromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME) - return CreateNewChromeWindow(aChromeFlags, _retval); - return CreateNewContentWindow(aChromeFlags, _retval); + return CreateNewChromeWindow(aChromeFlags, aAppShell, _retval); + return CreateNewContentWindow(aChromeFlags, aAppShell, _retval); } NS_IMETHODIMP nsXULWindow::CreateNewChromeWindow(PRInt32 aChromeFlags, - nsIXULWindow **_retval) + nsIAppShell* aAppShell, nsIXULWindow **_retval) { NS_TIMELINE_ENTER("nsXULWindow::CreateNewChromeWindow"); - nsCOMPtr appShell(do_GetService(kAppShellServiceCID)); + nsCOMPtr appShell(do_GetService(NS_APPSHELLSERVICE_CONTRACTID)); NS_ENSURE_TRUE(appShell, NS_ERROR_FAILURE); // Just do a normal create of a window and return. @@ -1725,7 +1705,7 @@ NS_IMETHODIMP nsXULWindow::CreateNewChromeWindow(PRInt32 aChromeFlags, nsCOMPtr newWindow; appShell->CreateTopLevelWindow(parent, nsnull, PR_FALSE, PR_FALSE, aChromeFlags, nsIAppShellService::SIZE_TO_CONTENT, - nsIAppShellService::SIZE_TO_CONTENT, getter_AddRefs(newWindow)); + nsIAppShellService::SIZE_TO_CONTENT, aAppShell, getter_AddRefs(newWindow)); NS_ENSURE_TRUE(newWindow, NS_ERROR_FAILURE); @@ -1742,10 +1722,10 @@ NS_IMETHODIMP nsXULWindow::CreateNewChromeWindow(PRInt32 aChromeFlags, } NS_IMETHODIMP nsXULWindow::CreateNewContentWindow(PRInt32 aChromeFlags, - nsIXULWindow **_retval) + nsIAppShell* aAppShell, nsIXULWindow **_retval) { NS_TIMELINE_ENTER("nsXULWindow::CreateNewContentWindow"); - nsCOMPtr appShell(do_GetService(kAppShellServiceCID)); + nsCOMPtr appShell(do_GetService(NS_APPSHELLSERVICE_CONTRACTID)); NS_ENSURE_TRUE(appShell, NS_ERROR_FAILURE); nsCOMPtr parent; @@ -1789,7 +1769,7 @@ NS_IMETHODIMP nsXULWindow::CreateNewContentWindow(PRInt32 aChromeFlags, nsCOMPtr newWindow; appShell->CreateTopLevelWindow(parent, uri, PR_FALSE, PR_FALSE, - aChromeFlags, 615, 480, + aChromeFlags, 615, 480, aAppShell, getter_AddRefs(newWindow)); NS_ENSURE_TRUE(newWindow, NS_ERROR_FAILURE); @@ -1800,7 +1780,7 @@ NS_IMETHODIMP nsXULWindow::CreateNewContentWindow(PRInt32 aChromeFlags, if(browserChrome) browserChrome->SetChromeFlags(aChromeFlags); - nsCOMPtr subShell(do_CreateInstance(kAppShellCID)); + nsCOMPtr subShell(do_CreateInstance(NS_APPSHELLSERVICE_CONTRACTID)); NS_ENSURE_TRUE(subShell, NS_ERROR_FAILURE); subShell->Create(0, nsnull); diff --git a/mozilla/xpfe/appshell/src/nsXULWindow.h b/mozilla/xpfe/appshell/src/nsXULWindow.h index 9dd971a9e30..23a09bc7e8e 100644 --- a/mozilla/xpfe/appshell/src/nsXULWindow.h +++ b/mozilla/xpfe/appshell/src/nsXULWindow.h @@ -118,9 +118,9 @@ protected: PRInt32 aCY); NS_IMETHOD ExitModalLoop(nsresult aStatus); NS_IMETHOD CreateNewChromeWindow(PRInt32 aChromeFlags, - nsIXULWindow **_retval); + nsIAppShell* aAppShell, nsIXULWindow **_retval); NS_IMETHOD CreateNewContentWindow(PRInt32 aChromeFlags, - nsIXULWindow **_retval); + nsIAppShell* aAppShell, nsIXULWindow **_retval); void EnableParent(PRBool aEnable); PRBool ConstrainToZLevel(PRBool aImmediate, nsWindowZ *aPlacement, diff --git a/mozilla/xpfe/bootstrap/Makefile.in b/mozilla/xpfe/bootstrap/Makefile.in index df41a59ca42..34eeb063c42 100644 --- a/mozilla/xpfe/bootstrap/Makefile.in +++ b/mozilla/xpfe/bootstrap/Makefile.in @@ -78,6 +78,7 @@ REQUIRES = xpcom \ content \ pref \ appshell \ + appcomps \ gfx \ xpinstall \ uriloader \ @@ -122,7 +123,6 @@ PREF_JS_EXPORTS = $(srcdir)/browser-prefs.js CPPSRCS = \ nsAppRunner.cpp \ - nsWindowCreator.cpp \ showOSAlert.cpp \ $(NULL) diff --git a/mozilla/xpfe/bootstrap/appleevents/Makefile.in b/mozilla/xpfe/bootstrap/appleevents/Makefile.in index 9c36abfe065..423cc339c4c 100644 --- a/mozilla/xpfe/bootstrap/appleevents/Makefile.in +++ b/mozilla/xpfe/bootstrap/appleevents/Makefile.in @@ -55,6 +55,7 @@ REQUIRES = xpcom \ docshell \ webbrwsr \ appshell \ + appcomps \ caps \ uriloader \ $(NULL) @@ -94,7 +95,7 @@ FORCE_STATIC_LIB = 1 LOCAL_INCLUDES = \ -I$(srcdir) \ -I$(srcdir)/.. \ - -I$(srcdir)/../../appshell/src/ \ + -I$(srcdir)/../../components/startup/src \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/mozilla/xpfe/bootstrap/appleevents/nsAEApplicationClass.cpp b/mozilla/xpfe/bootstrap/appleevents/nsAEApplicationClass.cpp index cb718414609..090276387d9 100644 --- a/mozilla/xpfe/bootstrap/appleevents/nsAEApplicationClass.cpp +++ b/mozilla/xpfe/bootstrap/appleevents/nsAEApplicationClass.cpp @@ -52,10 +52,8 @@ #include "nsCommandLineServiceMac.h" #include "nsICmdLineService.h" #include "nsCOMPtr.h" -#include "nsAppShellCIDs.h" -#include "nsIAppShellService.h" - -static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); +#include "nsIAppStartup.h" +#include "nsXPFEComponentsCID.h" /*---------------------------------------------------------------------------- AEApplicationClass @@ -329,11 +327,11 @@ void AEApplicationClass::HandleReOpen(AEDesc *token, const AppleEvent *appleEven nsresult rv = NS_OK; nsCOMPtr nas; - nsCOMPtr appShell(do_GetService(kAppShellServiceCID, &rv)); - NS_WARN_IF_FALSE(rv==NS_OK, "Failed to get AppShellService"); - if(NS_FAILED(rv)) ThrowIfOSErr(errAEEventNotHandled); + nsCOMPtr appStartup(do_GetService(NS_APPSTARTUP_CONTRACTID)); + NS_WARN_IF_FALSE(appStartup, "Failed to get appstartup service"); + if(!appStartup) ThrowIfOSErr(errAEEventNotHandled); - rv = appShell->GetNativeAppSupport(getter_AddRefs(nas)); + rv = appStartup->GetNativeAppSupport(getter_AddRefs(nas)); NS_WARN_IF_FALSE(rv==NS_OK, "Failed to get NativeAppSupport"); if(NS_FAILED(rv)) ThrowIfOSErr(errAEEventNotHandled); diff --git a/mozilla/xpfe/bootstrap/appleevents/nsWindowUtils.cpp b/mozilla/xpfe/bootstrap/appleevents/nsWindowUtils.cpp index b4b8f6c1340..2152a0594f1 100644 --- a/mozilla/xpfe/bootstrap/appleevents/nsWindowUtils.cpp +++ b/mozilla/xpfe/bootstrap/appleevents/nsWindowUtils.cpp @@ -60,6 +60,7 @@ #include "nsWindowUtils.h" #include "nsMacUtils.h" #include "nsXPIDLString.h" +#include "nsIXULWindow.h" #include "nsIDocShellTreeItem.h" #include "nsWindowUtils.h" #include "nsReadableUtils.h" diff --git a/mozilla/xpfe/bootstrap/nsAppRunner.cpp b/mozilla/xpfe/bootstrap/nsAppRunner.cpp index 7e2015d0950..960da825696 100644 --- a/mozilla/xpfe/bootstrap/nsAppRunner.cpp +++ b/mozilla/xpfe/bootstrap/nsAppRunner.cpp @@ -68,8 +68,8 @@ #include "nsICmdLineService.h" #include "nsIAppShellService.h" #include "nsIAppStartupNotifier.h" +#include "nsIAppStartup.h" #include "nsIObserverService.h" -#include "nsAppShellCIDs.h" #include "prprf.h" #include "nsCRT.h" #include "nsIDirectoryService.h" @@ -85,7 +85,7 @@ #include "nsIEventQueueService.h" #include "nsDirectoryServiceDefs.h" #include "nsBuildID.h" -#include "nsWindowCreator.h" +#include "nsIWindowCreator.h" #include "nsIWindowWatcher.h" #include "nsILocalFile.h" #include "nsILookAndFeel.h" @@ -130,6 +130,8 @@ #endif #include "nsWidgetsCID.h" +#include "nsXPFEComponentsCID.h" + static NS_DEFINE_CID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); #define UILOCALE_CMD_LINE_ARG "-UILocale" @@ -374,10 +376,6 @@ static void InitializeMacOSXApp(int argc, char* argv[]) #include #endif //MOZ_WIDGET_GTK || MOZ_WIDGET_GTK2 -/* Define Class IDs */ -static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); -static NS_DEFINE_CID(kCmdLineServiceCID, NS_COMMANDLINE_SERVICE_CID); - #include "nsNativeAppSupport.h" /*********************************************/ @@ -438,9 +436,9 @@ static nsresult GetNativeAppSupport(nsINativeAppSupport** aNativeApp) NS_ENSURE_ARG_POINTER(aNativeApp); *aNativeApp = nsnull; - nsCOMPtr appShellService(do_GetService(kAppShellServiceCID)); - if (appShellService) - appShellService->GetNativeAppSupport(aNativeApp); + nsCOMPtr appStartup(do_GetService(NS_APPSTARTUP_CONTRACTID)); + if (appStartup) + appStartup->GetNativeAppSupport(aNativeApp); return *aNativeApp ? NS_OK : NS_ERROR_FAILURE; } @@ -511,12 +509,12 @@ static nsresult OpenWindow(const nsCString& aChromeURL, // profile" is moot (because they don't support "-turbo", // basically). Specifically, because they don't do turbo, they will // *always* have a profile selected. - nsCOMPtr appShell(do_GetService("@mozilla.org/appshell/appShellService;1")); - nsCOMPtr cmdLine(do_GetService("@mozilla.org/appshell/commandLineService;1")); - if (appShell && cmdLine) + nsCOMPtr appStartup(do_GetService(NS_APPSTARTUP_CONTRACTID)); + nsCOMPtr cmdLine(do_GetService(NS_COMMANDLINESERVICE_CONTRACTID)); + if (appStartup && cmdLine) { nsCOMPtr nativeApp; - if (NS_SUCCEEDED(appShell->GetNativeAppSupport(getter_AddRefs(nativeApp)))) + if (NS_SUCCEEDED(appStartup->GetNativeAppSupport(getter_AddRefs(nativeApp)))) { // Make sure profile has been selected. // At this point, we have to look for failure. That @@ -621,7 +619,7 @@ LaunchApplicationWithArgs(const char *commandLineArg, nsresult rv; nsCOMPtr cmdLine = - do_GetService("@mozilla.org/appshell/commandLineService;1",&rv); + do_GetService(NS_COMMANDLINESERVICE_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; nsCOMPtr handler; @@ -747,9 +745,9 @@ nsresult DoCommandLines(nsICmdLineService* cmdLineArgs, PRBool heedGeneralStartu PR_sscanf(tempString.get(), "%d", &height); if (heedGeneralStartupPrefs) { - nsCOMPtr appShell(do_GetService("@mozilla.org/appshell/appShellService;1", &rv)); + nsCOMPtr appStartup(do_GetService(NS_APPSTARTUP_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; - rv = appShell->CreateStartupState(width, height, windowOpened); + rv = appStartup->CreateStartupState(width, height, windowOpened); if (NS_FAILED(rv)) return rv; } else { @@ -957,31 +955,13 @@ static nsresult InitializeProfileService(nsICmdLineService *cmdLineArgs) } } nsresult rv; - nsCOMPtr appShellService(do_GetService(kAppShellServiceCID, &rv)); + nsCOMPtr appStartup(do_GetService(NS_APPSTARTUP_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; - rv = appShellService->DoProfileStartup(cmdLineArgs, shouldShowUI); + rv = appStartup->DoProfileStartup(cmdLineArgs, shouldShowUI); return rv; } -static nsresult InitializeWindowCreator() -{ - // create an nsWindowCreator and give it to the WindowWatcher service - nsWindowCreator *creatorCallback = new nsWindowCreator(); - if (!creatorCallback) - return NS_ERROR_OUT_OF_MEMORY; - - nsCOMPtr windowCreator(NS_STATIC_CAST(nsIWindowCreator *, creatorCallback)); - if (windowCreator) { - nsCOMPtr wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)); - if (wwatch) { - wwatch->SetWindowCreator(windowCreator); - return NS_OK; - } - } - return NS_ERROR_FAILURE; -} - // Maximum allowed / used length of alert message is 255 chars, due to restrictions on Mac. // Please make sure that file contents and fallback_alert_text are at most 255 chars. // Fallback_alert_text must be non-const, because of inplace conversion on Mac. @@ -1074,8 +1054,8 @@ static nsresult VerifyInstallation(int argc, char **argv) #endif // Note: nativeApp is an owning reference that this function has responsibility -// to release. This responsibility is delegated to the app shell service -// (see nsAppShellService::Initialize call, below). +// to release. This responsibility is delegated to the app startup service +// (see nsAppStartup::Initialize call, below). static nsresult main1(int argc, char* argv[], nsISupports *nativeApp ) { nsresult rv; @@ -1167,7 +1147,7 @@ static nsresult main1(int argc, char* argv[], nsISupports *nativeApp ) NS_TIMELINE_ENTER("cmdLineArgs"); // Initialize the cmd line service - nsCOMPtr cmdLineArgs(do_GetService(kCmdLineServiceCID, &rv)); + nsCOMPtr cmdLineArgs(do_GetService(NS_COMMANDLINESERVICE_CONTRACTID, &rv)); NS_ASSERTION(NS_SUCCEEDED(rv), "Could not obtain CmdLine processing service\n"); if (NS_FAILED(rv)) return rv; @@ -1187,14 +1167,14 @@ static nsresult main1(int argc, char* argv[], nsISupports *nativeApp ) return rv; NS_TIMELINE_LEAVE("InstallGlobalLocale"); - NS_TIMELINE_ENTER("appShell"); + NS_TIMELINE_ENTER("appStartup"); - nsCOMPtr appShell(do_GetService(kAppShellServiceCID, &rv)); - NS_ASSERTION(NS_SUCCEEDED(rv), "failed to get the appshell service"); + nsCOMPtr appStartup(do_GetService(NS_APPSTARTUP_CONTRACTID)); + NS_ASSERTION(appStartup, "failed to get the appstartup service"); - /* if we couldn't get the nsIAppShellService service, then we should hide the - splash screen and return */ - if (NS_FAILED(rv)) + /* if we couldn't get the nsIAppStartup service, then we should hide the + splash screen and return (and something is seriously screwed up) */ + if (!appStartup) { // See if platform supports nsINativeAppSupport. nsCOMPtr nativeAppSupport(do_QueryInterface(nativeAppOwner)); @@ -1215,24 +1195,30 @@ static nsresult main1(int argc, char* argv[], nsISupports *nativeApp ) return rv; } - NS_TIMELINE_LEAVE("appShell"); + NS_TIMELINE_LEAVE("appStartup"); - NS_TIMELINE_ENTER("appShell->Initialize"); + NS_TIMELINE_ENTER("appStartup->Initialize"); // Create the Application Shell instance... - rv = appShell->Initialize(cmdLineArgs, nativeAppOwner); + rv = appStartup->Initialize(cmdLineArgs, nativeAppOwner); - NS_TIMELINE_LEAVE("appShell->Initialize"); + NS_TIMELINE_LEAVE("appStartup->Initialize"); - NS_ASSERTION(NS_SUCCEEDED(rv), "failed to initialize appshell"); + NS_ASSERTION(NS_SUCCEEDED(rv), "failed to initialize appstartup"); if (NS_FAILED(rv)) return rv; - rv = InitializeWindowCreator(); - NS_ASSERTION(NS_SUCCEEDED(rv), "failed to initialize window creator"); - if (NS_FAILED(rv)) return rv; + nsCOMPtr wcreator (do_QueryInterface(appStartup)); + NS_ASSERTION(wcreator, "appstartup doesn't do nsIWindowCreator?"); + NS_ENSURE_TRUE(wcreator, NS_ERROR_FAILURE); + + nsCOMPtr wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)); + NS_ASSERTION(wwatch, "Couldn't get the window watcher!"); + NS_ENSURE_TRUE(wwatch, NS_ERROR_FAILURE); + + wwatch->SetWindowCreator(wcreator); // So we can open and close windows during startup - appShell->EnterLastWindowClosingSurvivalArea(); + appStartup->EnterLastWindowClosingSurvivalArea(); // Initialize Profile Service here. NS_TIMELINE_ENTER("InitializeProfileService"); @@ -1247,9 +1233,9 @@ static nsresult main1(int argc, char* argv[], nsISupports *nativeApp ) CheckUseAccessibleSkin(); NS_TIMELINE_LEAVE("CheckUseAccessibleSkin"); - NS_TIMELINE_ENTER("appShell->CreateHiddenWindow"); - appShell->CreateHiddenWindow(); - NS_TIMELINE_LEAVE("appShell->CreateHiddenWindow"); + NS_TIMELINE_ENTER("appStartup->CreateHiddenWindow"); + appStartup->CreateHiddenWindow(); + NS_TIMELINE_LEAVE("appStartup->CreateHiddenWindow"); // This will go away once Components are handling there own commandlines // if we have no command line arguments, we need to heed the @@ -1296,13 +1282,13 @@ static nsresult main1(int argc, char* argv[], nsISupports *nativeApp ) // Make sure there exists at least 1 window. NS_TIMELINE_ENTER("Ensure1Window"); - rv = appShell->Ensure1Window(cmdLineArgs); + rv = appStartup->Ensure1Window(cmdLineArgs); NS_TIMELINE_LEAVE("Ensure1Window"); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to Ensure1Window"); if (NS_FAILED(rv)) return rv; #if !defined(XP_MAC) && !defined(XP_MACOSX) - appShell->ExitLastWindowClosingSurvivalArea(); + appStartup->ExitLastWindowClosingSurvivalArea(); #endif #ifdef MOZ_ENABLE_XREMOTE @@ -1331,10 +1317,10 @@ static nsresult main1(int argc, char* argv[], nsISupports *nativeApp ) nativeAppOwner = nsnull; // Start main event loop - NS_TIMELINE_ENTER("appShell->Run"); - rv = appShell->Run(); - NS_TIMELINE_LEAVE("appShell->Run"); - NS_ASSERTION(NS_SUCCEEDED(rv), "failed to run appshell"); + NS_TIMELINE_ENTER("appStartup->Run"); + rv = appStartup->Run(); + NS_TIMELINE_LEAVE("appStartup->Run"); + NS_ASSERTION(NS_SUCCEEDED(rv), "failed to run appstartup"); #ifdef MOZ_TIMELINE // Make sure we print this out even if timeline is runtime disabled diff --git a/mozilla/xpfe/bootstrap/nsNativeAppSupportMac.cpp b/mozilla/xpfe/bootstrap/nsNativeAppSupportMac.cpp index 5540b82b2e3..820248cee47 100644 --- a/mozilla/xpfe/bootstrap/nsNativeAppSupportMac.cpp +++ b/mozilla/xpfe/bootstrap/nsNativeAppSupportMac.cpp @@ -43,11 +43,11 @@ #include #include -#include "nsAppShellCIDs.h" #include "nsCOMPtr.h" #include "nsNativeAppSupportBase.h" #include "nsIAppShellService.h" +#include "nsIAppStartup.h" #include "nsIBaseWindow.h" #include "nsICmdLineService.h" #include "nsIDOMWindowInternal.h" @@ -60,7 +60,7 @@ #include "nsIWidget.h" #include "nsIWindowMediator.h" -static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); +#include "nsXPFEComponentsCID.h" #define rSplashDialog 512 @@ -381,13 +381,13 @@ nsNativeAppSupportMac::ReOpen() 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 appShell(do_GetService(kAppShellServiceCID, &rv)); - if (!rv) + nsCOMPtr appStartup(do_GetService(NS_APPSTARTUP_CONTRACTID)); + if (appStartup) { PRBool openedAWindow = PR_FALSE; - appShell->CreateStartupState(nsIAppShellService::SIZE_TO_CONTENT, - nsIAppShellService::SIZE_TO_CONTENT, - &openedAWindow); + appStartup->CreateStartupState(nsIAppShellService::SIZE_TO_CONTENT, + nsIAppShellService::SIZE_TO_CONTENT, + &openedAWindow); } } diff --git a/mozilla/xpfe/bootstrap/nsNativeAppSupportOS2.cpp b/mozilla/xpfe/bootstrap/nsNativeAppSupportOS2.cpp index 2f2efb7c41d..ad05380759a 100644 --- a/mozilla/xpfe/bootstrap/nsNativeAppSupportOS2.cpp +++ b/mozilla/xpfe/bootstrap/nsNativeAppSupportOS2.cpp @@ -1862,11 +1862,11 @@ nsNativeAppSupportOS2::HandleRequest( LPBYTE request, PRBool newWindow ) { rv = GetCmdLineArgs( request, getter_AddRefs( args ) ); if (NS_FAILED(rv)) return; - nsCOMPtr appShell(do_GetService("@mozilla.org/appshell/appShellService;1", &rv)); - if (NS_FAILED(rv)) return; + nsCOMPtr appStartup(do_GetService(appStartup)); + if (!appStartup) return; nsCOMPtr nativeApp; - rv = appShell->GetNativeAppSupport(getter_AddRefs( nativeApp )); + rv = appStartup->GetNativeAppSupport(getter_AddRefs( nativeApp )); if (NS_FAILED(rv)) return; // first see if there is a url @@ -1911,17 +1911,17 @@ nsNativeAppSupportOS2::HandleRequest( LPBYTE request, PRBool newWindow ) { rv = args->GetCmdLineValue( "-kill", getter_Copies(arg)); if ( NS_SUCCEEDED(rv) && (const char*)arg ) { // Turn off server mode. - nsCOMPtr appShell = - do_GetService( "@mozilla.org/appshell/appShellService;1", &rv); - if (NS_FAILED(rv)) return; + nsCOMPtr appStartup + (do_GetService(NS_APPSTARTUP_CONTRACTID)); + if (!appStartup) return; nsCOMPtr native; - rv = appShell->GetNativeAppSupport( getter_AddRefs( native )); + rv = appStartup->GetNativeAppSupport( getter_AddRefs( native )); if (NS_SUCCEEDED(rv)) { native->SetIsServerMode( PR_FALSE ); // close app if there are no more top-level windows. - appShell->Quit(nsIAppShellService::eConsiderQuit); + appStartup->Quit(nsIAppShellService::eConsiderQuit); } return; @@ -2155,7 +2155,7 @@ nsNativeAppSupportOS2::EnsureProfile(nsICmdLineService* args) nsCOMPtr profileMgr(do_GetService(NS_PROFILE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; - nsCOMPtr appShell(do_GetService("@mozilla.org/appshell/appShellService;1", &rv)); + nsCOMPtr appStartup(do_GetService(NS_APPSTARTUP_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; // If we have a profile, everything is fine. @@ -2181,7 +2181,7 @@ nsNativeAppSupportOS2::EnsureProfile(nsICmdLineService* args) canInteract = PR_FALSE; } } - rv = appShell->DoProfileStartup(args, canInteract); + rv = appStartup->DoProfileStartup(args, canInteract); mForceProfileStartup = PR_FALSE; @@ -2461,8 +2461,8 @@ nsNativeAppSupportOS2::OnLastWindowClosing() { profileCount > 1 ) { // Turn off turbo mode and quit the application. SetIsServerMode( PR_FALSE ); - nsCOMPtr appShell = - do_GetService( "@mozilla.org/appshell/appShellService;1", &rv); + nsCOMPtr appShell + (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv)); if ( NS_SUCCEEDED( rv ) ) { appShell->Quit(nsIAppShellService::eAttemptQuit); } diff --git a/mozilla/xpfe/bootstrap/nsNativeAppSupportWin.cpp b/mozilla/xpfe/bootstrap/nsNativeAppSupportWin.cpp index 80708396e31..0661bc281fd 100644 --- a/mozilla/xpfe/bootstrap/nsNativeAppSupportWin.cpp +++ b/mozilla/xpfe/bootstrap/nsNativeAppSupportWin.cpp @@ -58,7 +58,7 @@ #include "nsIDocShell.h" #include "nsIBaseWindow.h" #include "nsIWidget.h" -#include "nsIAppShellService.h" +#include "nsIAppStartup.h" #include "nsIProfileInternal.h" #include "nsIXULWindow.h" #include "nsIInterfaceRequestor.h" @@ -69,6 +69,9 @@ #include "nsNetCID.h" #include "nsIObserverService.h" #include "nsXPCOM.h" +#include "nsXPFEComponentsCID.h" + +struct JSContext; #ifdef XPCOM_GLUE #include "nsStringSupport.h" @@ -949,14 +952,15 @@ struct MessageWindow { if ( NS_SUCCEEDED( rv ) ) winHooksService->StartupRemoveOption("-turbo"); - nsCOMPtr appShell = do_GetService( "@mozilla.org/appshell/appShellService;1", &rv ); + nsCOMPtr appStartup + (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv)); if ( NS_SUCCEEDED( rv ) ) { nsCOMPtr native; - rv = appShell->GetNativeAppSupport( getter_AddRefs( native ) ); + rv = appStartup->GetNativeAppSupport( getter_AddRefs( native ) ); if ( NS_SUCCEEDED( rv ) ) native->SetIsServerMode( PR_FALSE ); if ( !win ) - appShell->Quit(nsIAppShellService::eAttemptQuit); + appStartup->Quit(nsIAppStartup::eAttemptQuit); } break; } @@ -1749,11 +1753,11 @@ nsNativeAppSupportWin::HandleRequest( LPBYTE request, PRBool newWindow ) { rv = GetCmdLineArgs( request, getter_AddRefs( args ) ); if (NS_FAILED(rv)) return; - nsCOMPtr appShell(do_GetService("@mozilla.org/appshell/appShellService;1", &rv)); + nsCOMPtr appStartup (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv)); if (NS_FAILED(rv)) return; nsCOMPtr nativeApp; - rv = appShell->GetNativeAppSupport(getter_AddRefs( nativeApp )); + rv = appStartup->GetNativeAppSupport(getter_AddRefs( nativeApp )); if (NS_FAILED(rv)) return; // first see if there is a url @@ -1798,17 +1802,17 @@ nsNativeAppSupportWin::HandleRequest( LPBYTE request, PRBool newWindow ) { rv = args->GetCmdLineValue( "-kill", getter_Copies(arg)); if ( NS_SUCCEEDED(rv) && (const char*)arg ) { // Turn off server mode. - nsCOMPtr appShell = - do_GetService( "@mozilla.org/appshell/appShellService;1", &rv); + nsCOMPtr appStartup + (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv)); if (NS_FAILED(rv)) return; nsCOMPtr native; - rv = appShell->GetNativeAppSupport( getter_AddRefs( native )); + rv = appStartup->GetNativeAppSupport( getter_AddRefs( native )); if (NS_SUCCEEDED(rv)) { native->SetIsServerMode( PR_FALSE ); // close app if there are no more top-level windows. - appShell->Quit(nsIAppShellService::eConsiderQuit); + appStartup->Quit(nsIAppStartup::eConsiderQuit); } return; @@ -2021,15 +2025,13 @@ nsNativeAppSupportWin::GetCmdLineArgs( LPBYTE request, nsICmdLineService **aResu } } - // OK, now create nsICmdLineService object from argc/argv. - static NS_DEFINE_CID( kCmdLineServiceCID, NS_COMMANDLINE_SERVICE_CID ); - nsCOMPtr compMgr; NS_GetComponentManager(getter_AddRefs(compMgr)); - rv = compMgr->CreateInstance( kCmdLineServiceCID, - 0, - NS_GET_IID( nsICmdLineService ), - (void**)aResult ); + + rv = compMgr->CreateInstanceByContractID( + NS_COMMANDLINESERVICE_CONTRACTID, + nsnull, NS_GET_IID(nsICmdLineService), + (void**) aResult); if ( NS_FAILED( rv ) || NS_FAILED( ( rv = (*aResult)->Initialize( argc, argv ) ) ) ) { #if MOZ_DEBUG_DDE @@ -2097,7 +2099,7 @@ printf( "Setting ddexec subkey entries\n" ); nsCOMPtr profileMgr(do_GetService(NS_PROFILE_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; - nsCOMPtr appShell(do_GetService("@mozilla.org/appshell/appShellService;1", &rv)); + nsCOMPtr appStartup (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv)); if (NS_FAILED(rv)) return rv; // If we have a profile, everything is fine - @@ -2123,7 +2125,7 @@ printf( "Setting ddexec subkey entries\n" ); canInteract = PR_FALSE; } } - rv = appShell->DoProfileStartup(args, canInteract); + rv = appStartup->DoProfileStartup(args, canInteract); mForceProfileStartup = PR_FALSE; @@ -2605,10 +2607,10 @@ nsNativeAppSupportWin::OnLastWindowClosing() { profileCount > 1 ) { // Turn off turbo mode and quit the application. SetIsServerMode( PR_FALSE ); - nsCOMPtr appShell = - do_GetService( "@mozilla.org/appshell/appShellService;1", &rv); + nsCOMPtr appStartup + (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv)); if ( NS_SUCCEEDED( rv ) ) { - appShell->Quit(nsIAppShellService::eAttemptQuit); + appStartup->Quit(nsIAppStartup::eAttemptQuit); } return NS_OK; } @@ -2637,8 +2639,8 @@ nsNativeAppSupportWin::OnLastWindowClosing() { } } - nsCOMPtr appShell = - do_GetService( "@mozilla.org/appshell/appShellService;1", &rv); + nsCOMPtr appStartup + (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv)); if ( NS_SUCCEEDED( rv ) ) { // Instead of staying alive, launch a new instance of the application and then // terminate for real. We take steps to ensure that the new instance will run @@ -2680,7 +2682,7 @@ nsNativeAppSupportWin::OnLastWindowClosing() { // Turn off turbo mode and quit the application. SetIsServerMode( PR_FALSE ); - appShell->Quit(nsIAppShellService::eAttemptQuit); + appStartup->Quit(nsIAppStartup::eAttemptQuit); // Done. This app will now commence shutdown. } diff --git a/mozilla/xpfe/bootstrap/nsSigHandlers.cpp b/mozilla/xpfe/bootstrap/nsSigHandlers.cpp index 74283271a3d..fcf7e966dce 100644 --- a/mozilla/xpfe/bootstrap/nsSigHandlers.cpp +++ b/mozilla/xpfe/bootstrap/nsSigHandlers.cpp @@ -64,9 +64,8 @@ #include #include "nsCOMPtr.h" #include "nsIServiceManager.h" -#include "nsIAppShellService.h" -#include "nsAppShellCIDs.h" -static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); +#include "nsIAppStartup.h" +#include "nsXPFEComponentCID.h" #endif #ifdef MOZ_WIDGET_PHOTON @@ -142,9 +141,9 @@ void beos_signal_handler(int signum) { fprintf(stderr, "beos_signal_handler: %d\n", signum); #endif nsresult rv; - nsCOMPtr appShellService(do_GetService(kAppShellServiceCID,&rv)); + nsCOMPtr appStartup(do_GetService(NS_APPSTARTUP_CONTRACTID, &rv)); if (NS_FAILED(rv)) { - // Failed to get the appshell service so shutdown the hard way + // Failed to get the appstartup service so shutdown the hard way #ifdef DEBUG fprintf(stderr, "beos_signal_handler: appShell->do_GetService() failed\n"); #endif @@ -152,7 +151,7 @@ void beos_signal_handler(int signum) { } // Exit the appshell so that the app can shutdown normally - appShellService->Quit(nsIAppShellService::eAttemptQuit); + appStartup->Quit(nsIAppStartup::eAttemptQuit); } #endif diff --git a/mozilla/xpfe/bootstrap/nsWindowCreator.cpp b/mozilla/xpfe/bootstrap/nsWindowCreator.cpp deleted file mode 100644 index b56b91686ed..00000000000 --- a/mozilla/xpfe/bootstrap/nsWindowCreator.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** 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 mozilla.org code. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * - * Alternatively, the contents of this file may be used under the terms of - * either of 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 ***** */ - -/* There are several ways to open a new window in Mozilla: directly, using - nsAppShellService; indirectly, using the Open method on an extant - window, the OpenWindow method on the nsWindowWatcher service, and this - WindowCreator. I think that's all of them, for petessake. But - the conditions under which each should be used are definite, if - not clear, and there is no overlap. - - Basically, you should never use nsAppShellService. That's the basic - method that all others boil down to, and it creates partially initialized - windows. Trust the other means of opening windows to use nsAppShellService - and then finish the new window's initialization. nsAppShellService is - also strictly a Mozilla-only service; it's unavailable (or should be) - to embedding apps. So it's not merely inadvisable but also illegal - for any code that may execute in an embedding context to use that service. - - Unless you're writing window opening code yourself, you want to use - the Open method on an extant window, or lacking one of those, the - OpenWindow method on the nsWindowWatcher service. (The former calls - through to the latter.) Both methods are equally at home in Mozilla - and embedding contexts. They differentiate between which kind of window - to open in different ways, depending on whether there is an extant - window. - - Lacking an extant window, it's this object, the nsWindowCreator, - that allows new window creation and properly distinguishes between - Mozilla and embedding contexts. This source file contains the - Mozilla version, which calls through to nsAppShellService. -*/ - -#include "nsXPCOM.h" -#include "nsCOMPtr.h" -#include "nsAppShellCIDs.h" -#include "nsWidgetsCID.h" -#include "nsWindowCreator.h" - -#include "nsIAppShell.h" -#include "nsIAppShellService.h" -#include "nsIInterfaceRequestor.h" -#include "nsIInterfaceRequestorUtils.h" -#include "nsIServiceManager.h" -#include "nsIServiceManagerUtils.h" -#include "nsIURI.h" -#include "nsIXULWindow.h" -#include "nsIWebBrowserChrome.h" - -static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); - -nsWindowCreator::nsWindowCreator() { -} - -nsWindowCreator::~nsWindowCreator() { -} - -NS_IMPL_ISUPPORTS2(nsWindowCreator, nsIWindowCreator, nsIWindowCreator2) - -NS_IMETHODIMP -nsWindowCreator::CreateChromeWindow(nsIWebBrowserChrome *aParent, - PRUint32 aChromeFlags, - nsIWebBrowserChrome **_retval) -{ - PRBool cancel; - return CreateChromeWindow2(aParent, aChromeFlags, 0, 0, &cancel, _retval); -} - -NS_IMETHODIMP -nsWindowCreator::CreateChromeWindow2( nsIWebBrowserChrome *aParent, - PRUint32 aChromeFlags, - PRUint32 aContextFlags, - nsIURI *aURI, - PRBool *aCancel, - nsIWebBrowserChrome **_retval) -{ - NS_ENSURE_ARG_POINTER(aCancel); - NS_ENSURE_ARG_POINTER(_retval); - *aCancel = PR_FALSE; - *_retval = 0; - - nsCOMPtr newWindow; - - if (aParent) { - nsCOMPtr xulParent(do_GetInterface(aParent)); - NS_ASSERTION(xulParent, "window created using non-XUL parent. that's unexpected, but may work."); - - if (xulParent) - xulParent->CreateNewWindow(aChromeFlags, getter_AddRefs(newWindow)); - // And if it fails, don't try again without a parent. It could fail - // intentionally (bug 115969). - } else { // try using basic methods: - /* You really shouldn't be making dependent windows without a parent. - But unparented modal (and therefore dependent) windows happen - in our codebase, so we allow it after some bellyaching: */ - if (aChromeFlags & nsIWebBrowserChrome::CHROME_DEPENDENT) - NS_WARNING("dependent window created without a parent"); - - nsCOMPtr appShell(do_GetService(kAppShellServiceCID)); - if (!appShell) - return NS_ERROR_FAILURE; - - appShell->CreateTopLevelWindow(0, 0, PR_FALSE, PR_FALSE, - aChromeFlags, nsIAppShellService::SIZE_TO_CONTENT, - nsIAppShellService::SIZE_TO_CONTENT, getter_AddRefs(newWindow)); - } - - // if anybody gave us anything to work with, use it - if (newWindow) { - newWindow->SetContextFlags(aContextFlags); - nsCOMPtr thing(do_QueryInterface(newWindow)); - if (thing) - thing->GetInterface(NS_GET_IID(nsIWebBrowserChrome), (void **) _retval); - } - - return *_retval ? NS_OK : NS_ERROR_FAILURE; -} diff --git a/mozilla/xpfe/browser/Makefile.in b/mozilla/xpfe/browser/Makefile.in index f91b11b6984..ff2e5329abb 100644 --- a/mozilla/xpfe/browser/Makefile.in +++ b/mozilla/xpfe/browser/Makefile.in @@ -44,7 +44,7 @@ include $(DEPTH)/config/autoconf.mk MODULE = browser -DIRS = src samples resources +DIRS = public src samples resources include $(topsrcdir)/config/rules.mk diff --git a/mozilla/xpfe/browser/public/Makefile.in b/mozilla/xpfe/browser/public/Makefile.in index e76829582bf..66079a3e4a3 100644 --- a/mozilla/xpfe/browser/public/Makefile.in +++ b/mozilla/xpfe/browser/public/Makefile.in @@ -44,9 +44,8 @@ include $(DEPTH)/config/autoconf.mk MODULE = browser XPIDL_MODULE = mozbrwsr -GRE_MODULE = 1 -XPIDLSRCS = nsIBrowserInstance.idl nsIXULBrowserWindow.idl +XPIDLSRCS = nsIBrowserInstance.idl include $(topsrcdir)/config/rules.mk diff --git a/mozilla/xpfe/browser/resources/content/navigator.js b/mozilla/xpfe/browser/resources/content/navigator.js index e71695f2bb9..dd71c0abe59 100644 --- a/mozilla/xpfe/browser/resources/content/navigator.js +++ b/mozilla/xpfe/browser/resources/content/navigator.js @@ -1921,10 +1921,10 @@ function applyTheme(themeName) pref.setComplexValue("general.skins.selectedSkin", Components.interfaces.nsISupportsString, str); // shut down quicklaunch so the next launch will have the new skin - var appShell = Components.classes['@mozilla.org/appshell/appShellService;1'].getService(); - appShell = appShell.QueryInterface(Components.interfaces.nsIAppShellService); + var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"] + .getService(Components.interfaces.nsIAppStartup); try { - appShell.nativeAppSupport.isServerMode = false; + appStartup.nativeAppSupport.isServerMode = false; } catch(ex) { } diff --git a/mozilla/xpfe/browser/src/Makefile.in b/mozilla/xpfe/browser/src/Makefile.in index ac8f6b1dcde..e52d9edd8ad 100644 --- a/mozilla/xpfe/browser/src/Makefile.in +++ b/mozilla/xpfe/browser/src/Makefile.in @@ -56,6 +56,7 @@ REQUIRES = xpcom \ content \ docshell \ appshell \ + appcomps \ dom \ js \ uriloader \ diff --git a/mozilla/xpfe/browser/src/nsBrowserInstance.cpp b/mozilla/xpfe/browser/src/nsBrowserInstance.cpp index cacd051d9aa..824337847c5 100644 --- a/mozilla/xpfe/browser/src/nsBrowserInstance.cpp +++ b/mozilla/xpfe/browser/src/nsBrowserInstance.cpp @@ -83,9 +83,7 @@ #include "plevent.h" #include "plstr.h" -#include "nsIAppShell.h" -#include "nsIAppShellService.h" -#include "nsAppShellCIDs.h" +#include "nsIAppStartup.h" #include "nsIDocumentViewer.h" #include "nsIBrowserHistory.h" @@ -102,9 +100,7 @@ // Stuff to implement file download dialog. #include "nsIProxyObjectManager.h" -#if defined(MOZ_PHOENIX) || defined(MOZ_XULRUNNER) -#include "nsToolkitCompsCID.h" -#endif +#include "nsXPFEComponentsCID.h" // If DEBUG, NS_BUILD_REFCNT_LOGGING, MOZ_PERF_METRICS, or MOZ_JPROF is // defined, enable the PageCycler. @@ -115,8 +111,6 @@ /* Define Class IDs */ static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); static NS_DEFINE_CID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID); -static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); -static NS_DEFINE_CID(kCmdLineServiceCID, NS_COMMANDLINE_SERVICE_CID); #ifdef DEBUG static int APP_DEBUG = 0; // Set to 1 in debugger to turn on debugging. @@ -225,18 +219,18 @@ public: nsresult rv; // make sure our timer is stopped first StopTimer(); - nsCOMPtr appShellServ = - do_GetService(kAppShellServiceCID, &rv); + nsCOMPtr appStartup = + do_GetService(NS_APPSTARTUP_CONTRACTID, &rv); if(NS_FAILED(rv)) return rv; nsCOMPtr pIProxyObjectManager = do_GetService(kProxyObjectManagerCID, &rv); if(NS_FAILED(rv)) return rv; - nsCOMPtr appShellProxy; - rv = pIProxyObjectManager->GetProxyForObject(NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIAppShellService), - appShellServ, PROXY_ASYNC | PROXY_ALWAYS, - getter_AddRefs(appShellProxy)); + nsCOMPtr appStartupProxy; + rv = pIProxyObjectManager->GetProxyForObject(NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIAppStartup), + appStartup, PROXY_ASYNC | PROXY_ALWAYS, + getter_AddRefs(appStartupProxy)); - (void)appShellProxy->Quit(nsIAppShellService::eAttemptQuit); + (void)appStartupProxy->Quit(nsIAppStartup::eAttemptQuit); return NS_ERROR_FAILURE; } } @@ -526,7 +520,7 @@ nsBrowserInstance::StartPageCycler(PRBool* aIsPageCycling) *aIsPageCycling = PR_FALSE; if (!sCmdLineURLUsed) { nsCOMPtr cmdLineArgs = - do_GetService(kCmdLineServiceCID, &rv); + do_GetService(NS_COMMANDLINESERVICE_CONTRACTID, &rv); if (NS_FAILED(rv)) { if (APP_DEBUG) fprintf(stderr, "Could not obtain CmdLine processing service\n"); return NS_ERROR_FAILURE; diff --git a/mozilla/xpfe/components/Makefile.in b/mozilla/xpfe/components/Makefile.in index 4174ab088cf..17d38c8ed42 100644 --- a/mozilla/xpfe/components/Makefile.in +++ b/mozilla/xpfe/components/Makefile.in @@ -42,6 +42,10 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk +MODULE = appcomps + +EXPORTS = nsXPFEComponentsCID.h + MOZ_HAVE_BROWSER=1 ifdef MOZ_THUNDERBIRD MOZ_HAVE_BROWSER= @@ -53,11 +57,10 @@ ifdef MOZ_SUNBIRD MOZ_HAVE_BROWSER= endif ifneq (,$(MOZ_PHOENIX)$(MOZ_XULRUNNER)) -# Firefox and XULRunner use this flag to stop the automatic processing of the -# jar.mn file that lives parallel to this Makefile. The jar.mn is responsible +# Firefox and XULRunner use this flag to suppress the distribution of chrome from +# the jar.mn file that lives parallel to this Makefile. The jar.mn is responsible # for the packaging of a large number of chrome files these apps don't need. -NO_DIST_INSTALL=1 -NO_INSTALL=1 +DEFINES += SUPPRESS_CHROME endif ifdef MOZ_HAVE_BROWSER @@ -66,7 +69,6 @@ DIRS = \ filepicker \ find \ search \ - shistory \ intl \ resetPref \ killAll \ @@ -85,6 +87,7 @@ DIRS += \ download-manager \ history \ sidebar \ + startup \ alerts \ $(NULL) endif @@ -116,10 +119,8 @@ DIRS = \ prefwindow \ console \ sidebar/public \ - history/public \ - shistory/public \ bookmarks/public \ - alerts \ + alerts \ $(NULL) ifeq ($(OS_ARCH),WINNT) diff --git a/mozilla/xpfe/components/build/Makefile.in b/mozilla/xpfe/components/build/Makefile.in index 97c08635d22..df442fc4130 100644 --- a/mozilla/xpfe/components/build/Makefile.in +++ b/mozilla/xpfe/components/build/Makefile.in @@ -64,6 +64,7 @@ REQUIRES = xpcom \ dom \ uriloader \ mimetype \ + embed_base \ webbrowserpersist \ progressDlg \ pref \ @@ -108,6 +109,7 @@ SHARED_LIBRARY_LIBS += \ $(DIST)/lib/$(LIB_PREFIX)downloadmanager_s.$(LIB_SUFFIX) \ $(DIST)/lib/$(LIB_PREFIX)history_s.$(LIB_SUFFIX) \ $(DIST)/lib/$(LIB_PREFIX)related_s.$(LIB_SUFFIX) \ + ../startup/src/$(LIB_PREFIX)appstartup_s.$(LIB_SUFFIX) \ $(NULL) ifeq ($(OS_ARCH),WINNT) @@ -136,6 +138,7 @@ LOCAL_INCLUDES += \ -I$(srcdir)/../download-manager/src \ -I$(srcdir)/../history/src \ -I$(srcdir)/../related/src \ + -I$(srcdir)/../startup/src \ $(NULL) ifeq ($(OS_ARCH),WINNT) @@ -145,19 +148,23 @@ LOCAL_INCLUDES += \ -I$(srcdir)/../winhooks \ $(NULL) endif +ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) +SHARED_LIBRARY_LIBS += $(DIST)/lib/$(LIB_PREFIX)appleevents_s.$(LIB_SUFFIX) +EXTRA_DSO_LDOPTS += $(TK_LIBS) +endif -endif -endif +endif # MOZ_XULRUNNER +endif # MOZ_PHOENIX ifeq ($(OS_ARCH),WINNT) OS_LIBS += $(call EXPAND_LIBNAME,ole32 shell32) endif -EXTRA_DSO_LDOPTS = \ +EXTRA_DSO_LDOPTS += \ $(MOZ_UNICHARUTIL_LIBS) \ $(MOZ_COMPONENT_LIBS) \ $(EXTRA_DSO_LIBS) \ $(MOZ_JS_LIBS) \ $(NULL) - + include $(topsrcdir)/config/rules.mk diff --git a/mozilla/xpfe/components/build/nsModule.cpp b/mozilla/xpfe/components/build/nsModule.cpp index c65d38576a3..c1500f4e695 100644 --- a/mozilla/xpfe/components/build/nsModule.cpp +++ b/mozilla/xpfe/components/build/nsModule.cpp @@ -53,6 +53,9 @@ #include "nsDocShellCID.h" #include "nsDownloadManager.h" #include "nsDownloadProxy.h" +#include "nsAppStartup.h" +#include "nsCommandLineService.h" +#include "nsUserInfo.h" #if defined(MOZ_LDAP_XPCOM) #include "nsLDAPAutoCompleteSession.h" #endif @@ -68,6 +71,7 @@ #include "nsBrowserStatusFilter.h" #include "nsBrowserInstance.h" #include "nsCURILoader.h" +#include "nsXPFEComponentsCID.h" // {9491C382-E3C4-11D2-BDBE-0050040A9B44} #define NS_GLOBALHISTORY_CID \ @@ -91,6 +95,9 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsBookmarksService, Init) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGlobalHistory, Init) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsDownloadManager, Init) NS_GENERIC_FACTORY_CONSTRUCTOR(nsDownloadProxy) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsCmdLineService) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsAppStartup) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsUserInfo) #if defined(MOZ_LDAP_XPCOM) NS_GENERIC_FACTORY_CONSTRUCTOR(nsLDAPAutoCompleteSession) #endif @@ -169,6 +176,21 @@ static const nsModuleComponentInfo components[] = { nsGlobalHistoryConstructor }, { "Global History", NS_GLOBALHISTORY_CID, NS_GLOBALHISTORY_AUTOCOMPLETE_CONTRACTID, nsGlobalHistoryConstructor }, + { "App Startup Service", + NS_SEAMONKEY_APPSTARTUP_CID, + NS_APPSTARTUP_CONTRACTID, + nsAppStartupConstructor + }, + { "CommandLine Service", + NS_COMMANDLINESERVICE_CID, + NS_COMMANDLINESERVICE_CONTRACTID, + nsCmdLineServiceConstructor + }, + { "User Info Service", + NS_USERINFO_CID, + NS_USERINFO_CONTRACTID, + nsUserInfoConstructor + }, #if defined(MOZ_LDAP_XPCOM) { "LDAP Autocomplete Session", NS_LDAPAUTOCOMPLETESESSION_CID, "@mozilla.org/autocompleteSession;1?type=ldap", diff --git a/mozilla/xpfe/components/history/Makefile.in b/mozilla/xpfe/components/history/Makefile.in index a8bee64bf18..5313e36a8fa 100644 --- a/mozilla/xpfe/components/history/Makefile.in +++ b/mozilla/xpfe/components/history/Makefile.in @@ -43,7 +43,7 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk MODULE = history -DIRS = src +DIRS = public src include $(topsrcdir)/config/rules.mk diff --git a/mozilla/xpfe/components/jar.mn b/mozilla/xpfe/components/jar.mn index 9a4ffbe3142..aaa18c5d2a8 100644 --- a/mozilla/xpfe/components/jar.mn +++ b/mozilla/xpfe/components/jar.mn @@ -1,3 +1,4 @@ +#ifndef SUPPRESS_CHROME comm.jar: content/communicator/directory/directory.xul (directory/directory.xul) content/communicator/directory/directory.html (directory/directory.html) @@ -165,3 +166,4 @@ toolkit.jar: en-win.jar: locale/en-US/global-platform/nsWindowsHooks.properties (winhooks/locale/en-US/nsWindowsHooks.properties) +#endif diff --git a/mozilla/xpfe/components/killAll/nsKillAll.js b/mozilla/xpfe/components/killAll/nsKillAll.js index 50c2cd757bc..9ec671c7c40 100644 --- a/mozilla/xpfe/components/killAll/nsKillAll.js +++ b/mozilla/xpfe/components/killAll/nsKillAll.js @@ -70,11 +70,11 @@ nsKillAll.prototype = { // turn off server mode var wasMozillaAlreadyRunning = false; - var appShellService = Components.classes["@mozilla.org/appshell/appShellService;1"] - .getService(Components.interfaces.nsIAppShellService); + var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"] + .getService(Components.interfaces.nsIAppStartup); var nativeAppSupport = {isServerMode: false}; try { - nativeAppSupport = appShellService.nativeAppSupport; + nativeAppSupport = appStartup.nativeAppSupport; } catch ( ex ) { } @@ -119,7 +119,7 @@ nsKillAll.prototype = { if (wasMozillaAlreadyRunning) { // Need to exit appshell in this case. - appShellService.quit(Components.interfaces.nsIAppShellService.eAttemptQuit); + appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit); } // We throw NS_ERROR_NOT_AVAILABLE which will be interpreted by the caller diff --git a/mozilla/editor/composer/src/nsEditorService.h b/mozilla/xpfe/components/nsXPFEComponentsCID.h similarity index 59% rename from mozilla/editor/composer/src/nsEditorService.h rename to mozilla/xpfe/components/nsXPFEComponentsCID.h index 9b8be775053..543fde2a974 100644 --- a/mozilla/editor/composer/src/nsEditorService.h +++ b/mozilla/xpfe/components/nsXPFEComponentsCID.h @@ -1,4 +1,3 @@ -/* -*- 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 * @@ -12,19 +11,18 @@ * for the specific language governing rights and limitations under the * License. * - * The Original Code is mozilla.org code. + * The Original Code is Mozilla Gecko. * * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 + * Benjamin Smedberg + * Portions created by the Initial Developer are Copyright (C) 2004 * the Initial Developer. All Rights Reserved. * * Contributor(s): - * Seth Spitzer * * Alternatively, the contents of this file may be used under the terms of - * either of 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"), + * 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 @@ -36,27 +34,25 @@ * * ***** END LICENSE BLOCK ***** */ -#ifndef nsEditorService_h___ -#define nsEditorService_h___ +#ifndef nsXPFEComponentsCID_h__ +#define nsXPFEComponentsCID_h__ -#include "nsICmdLineHandler.h" +/** + * The command line service is initialized at application startup with the + * application command line. It may not exist at all in embedding situations. + * + * @implements nsICommandLineService + */ +#define NS_COMMANDLINESERVICE_CONTRACTID \ + "@mozilla.org/app-startup/commandLineService;1" -class nsEditorService : public nsICmdLineHandler -{ -public: +/** + * The app startup service is created during startup of an XUL application, + * and serves the window creator. It may not be valid in embedding situations. + * + * @implements nsIAppStartup, nsIWindowCreator, nsIWindowCreator2 + */ +#define NS_APPSTARTUP_CONTRACTID \ + "@mozilla.org/toolkit/app-startup;1" - NS_DECL_ISUPPORTS - NS_DECL_NSICMDLINEHANDLER - - nsEditorService(); - virtual ~nsEditorService(); - - CMDLINEHANDLER_REGISTERPROC_DECLS -}; - -#define NS_EDITORSERVICE_CID \ -{/* {91ea5158-1dd2-11b2-939c-cfe895090b1b}*/ \ -0x91ea5158, 0x1dd2, 0x11b2, \ -{ 0x93, 0x9c, 0xcf, 0xe8, 0x95, 0x09, 0x0b, 0x1b} } - -#endif /* nsEditorService_h___ */ +#endif diff --git a/mozilla/xpfe/components/prefwindow/resources/content/pref-advanced.xul b/mozilla/xpfe/components/prefwindow/resources/content/pref-advanced.xul index 8bc30648fc9..9696911bff3 100644 --- a/mozilla/xpfe/components/prefwindow/resources/content/pref-advanced.xul +++ b/mozilla/xpfe/components/prefwindow/resources/content/pref-advanced.xul @@ -129,11 +129,11 @@ winhooksService.startupAddOption("-turbo"); else winhooksService.startupRemoveOption("-turbo"); - var appShell = Components.classes['@mozilla.org/appshell/appShellService;1'].getService(); - appShell = appShell.QueryInterface( Components.interfaces.nsIAppShellService ); + var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]. + getService(Components.interfaces.nsIAppStartup); var nativeAppSupport = null; try { - nativeAppSupport = appShell.nativeAppSupport; + nativeAppSupport = appStartup.nativeAppSupport; } catch ( ex ) { } diff --git a/mozilla/xpfe/components/prefwindow/resources/content/pref-themes.js b/mozilla/xpfe/components/prefwindow/resources/content/pref-themes.js index e61fd1d25bf..3f6b6dd537a 100644 --- a/mozilla/xpfe/components/prefwindow/resources/content/pref-themes.js +++ b/mozilla/xpfe/components/prefwindow/resources/content/pref-themes.js @@ -118,10 +118,10 @@ function applySkin() parent.hPrefWindow.setPref("string", "general.skins.selectedSkin", data.name); // shut down quicklaunch so the next launch will have the new skin - var appShell = Components.classes['@mozilla.org/appshell/appShellService;1'].getService(); - appShell = appShell.QueryInterface(Components.interfaces.nsIAppShellService); + var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"] + .getService(Components.interfaces.nsIAppStartup); try { - appShell.nativeAppSupport.isServerMode = false; + appStartup.nativeAppSupport.isServerMode = false; } catch(ex) { } diff --git a/mozilla/xpfe/components/resetPref/nsResetPref.js b/mozilla/xpfe/components/resetPref/nsResetPref.js index 95effef5477..1b2defc5e75 100644 --- a/mozilla/xpfe/components/resetPref/nsResetPref.js +++ b/mozilla/xpfe/components/resetPref/nsResetPref.js @@ -73,7 +73,7 @@ nsResetPref.prototype = { // startup from nsAppRunner.cpp. // We get the command line service and from that the -resetPref argument. - var cmdLine = Components.classes[ "@mozilla.org/appshell/commandLineService;1" ] + var cmdLine = Components.classes[ "@mozilla.org/app-startup/commandLineService;1" ] .getService( Components.interfaces.nsICmdLineService ); var prefList = cmdLine.getCmdLineValue( "-resetPref" ).split( "," ); diff --git a/mozilla/xpfe/components/sidebar/Makefile.in b/mozilla/xpfe/components/sidebar/Makefile.in index 9f544a41109..963772f5e36 100644 --- a/mozilla/xpfe/components/sidebar/Makefile.in +++ b/mozilla/xpfe/components/sidebar/Makefile.in @@ -42,7 +42,7 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk -DIRS = src +DIRS = public src include $(topsrcdir)/config/rules.mk diff --git a/mozilla/xpfe/components/startup/Makefile.in b/mozilla/xpfe/components/startup/Makefile.in new file mode 100644 index 00000000000..558695ca954 --- /dev/null +++ b/mozilla/xpfe/components/startup/Makefile.in @@ -0,0 +1,46 @@ +# ***** 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 Mozilla Seamonkey bootstrap code. +# +# 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 + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/xpfe/components/startup/public/Makefile.in b/mozilla/xpfe/components/startup/public/Makefile.in new file mode 100644 index 00000000000..30d2955380a --- /dev/null +++ b/mozilla/xpfe/components/startup/public/Makefile.in @@ -0,0 +1,62 @@ +# ***** 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 Mozilla Seamonkey bootstrap code. +# +# 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 = appcomps +XPIDL_MODULE = appstartup + +XPIDLSRCS = \ + nsIAppStartup.idl \ + nsICloseAllWindows.idl \ + nsICmdLineHandler.idl \ + nsICmdLineService.idl \ + nsINativeAppSupport.idl \ + nsIUserInfo.idl \ + $(NULL) + +EXPORTS = nsISplashScreen.h + +ifeq ($(MOZ_WIDGET_TOOLKIT),windows) +XPIDLSRCS += nsINativeAppSupportWin.idl +endif + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/xpfe/components/startup/public/nsIAppStartup.idl b/mozilla/xpfe/components/startup/public/nsIAppStartup.idl new file mode 100644 index 00000000000..13e6ad57001 --- /dev/null +++ b/mozilla/xpfe/components/startup/public/nsIAppStartup.idl @@ -0,0 +1,127 @@ +/* -*- Mode: IDL; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** 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 Mozilla Communicator client code, copied from + * xpfe/appshell/public/nsIAppShellService.idl + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * 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 nsICmdLineService; +interface nsINativeAppSupport; + +[scriptable, uuid(413e5d30-1b92-416a-acca-1c8ee4f66d08)] +interface nsIAppStartup : nsISupports +{ + /** + * Required initialization routine. + * @param aCmdLineService + * This is stored and passed to appshell components as they are + * initialized. + * @param aNativeAppSupportOrSplashScreen + * This is an object that can be QI'd to either an + * nsINativeAppSupport or nsISplashScreen; this object will be + * used to implement HideSplashScreen. + */ + void initialize(in nsICmdLineService aCmdLineService, + in nsISupports nativeAppSupportOrSplashScreen); + + + /** + * Create the hidden window. Only bootstrap code (nsAppRunner.cpp) should call + * this method. + */ + void createHiddenWindow(); + + /** + * Starts up the profile manager with the given arguments + * @param aCmdLineService the arguments given to the program + * @param canInteract If FALSE and UI is needed, will fail + */ + void doProfileStartup(in nsICmdLineService aCmdLineService, in boolean canInteract); + + /** + * Getter for "native app support." + */ + readonly attribute nsINativeAppSupport nativeAppSupport; + + /** + * Runs an application event loop: normally the main event pump which + * defines the lifetime of the application. + */ + void run(); + + /** + * During application startup (and at other times!) we may temporarily + * encounter a situation where all application windows will be closed + * but we don't want to take this as a signal to quit the app. Bracket + * the code where the last window could close with these. + * (And at application startup, on platforms that don't normally quit + * when the last window has closed, call Enter once, but not Exit) + */ + void enterLastWindowClosingSurvivalArea(); + void exitLastWindowClosingSurvivalArea(); + + const PRUint32 eConsiderQuit = 1; // attempt to quit if all windows are closed + const PRUint32 eAttemptQuit = 2; // try to close all windows, then quit if successful + const PRUint32 eForceQuit = 3; // quit, damnit + + /** + * Exit the event loop, shut down the app + */ + void quit(in PRUint32 aFerocity); + + /** + * Remove the splash screen (if visible). This need be called + * only once per application session. + */ + void hideSplashScreen(); + + /** + * 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/xpfe/components/startup/public/nsICloseAllWindows.idl b/mozilla/xpfe/components/startup/public/nsICloseAllWindows.idl index 95191eecc9b..f4a64521a85 100644 --- a/mozilla/xpfe/components/startup/public/nsICloseAllWindows.idl +++ b/mozilla/xpfe/components/startup/public/nsICloseAllWindows.idl @@ -42,9 +42,9 @@ interface nsICloseAllWindows : nsISupports { /** - Closes all open windows, optionally asking to confirm changes if any. - Returns TRUE is the user does not cancel from any confirmation dialog. - */ + * Closes all open windows, optionally asking to confirm changes if any. + * @return TRUE if the user does not cancel from any confirmation dialog. + */ boolean closeAll(in boolean askSave); }; diff --git a/mozilla/xpfe/components/startup/public/nsICmdLineService.idl b/mozilla/xpfe/components/startup/public/nsICmdLineService.idl index 94d1b8f2fba..200cab8f85a 100644 --- a/mozilla/xpfe/components/startup/public/nsICmdLineService.idl +++ b/mozilla/xpfe/components/startup/public/nsICmdLineService.idl @@ -39,13 +39,6 @@ #include "nsIFactory.idl" #include "nsICmdLineHandler.idl" -%{C++ -// e34783f5-ac08-11d2-8d19-00805fc2500c -#define NS_COMMANDLINE_SERVICE_CID \ -{ 0xe34783f5, 0xac08, 0x11d2, \ - {0x8d, 0x19, 0x00, 0x80, 0x5f, 0xc2, 0x50,0xc} } -%} - [ptr] native charArray(char*); [scriptable, uuid(e34783f4-ac08-11d2-8d19-00805fc2500c)] interface nsICmdLineService : nsISupports @@ -98,5 +91,4 @@ interface nsICmdLineService : nsISupports * string if you want the "default" handler */ nsICmdLineHandler getHandlerForParam(in string param); - }; diff --git a/mozilla/xpfe/components/startup/src/Makefile.in b/mozilla/xpfe/components/startup/src/Makefile.in new file mode 100644 index 00000000000..c7bbf518aae --- /dev/null +++ b/mozilla/xpfe/components/startup/src/Makefile.in @@ -0,0 +1,96 @@ +# ***** 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 Mozilla Seamonkey bootstrap code. +# +# 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 = appcomps +LIBRARY_NAME = appstartup_s +FORCE_STATIC_LIB = 1 + +REQUIRES = \ + xpcom \ + string \ + js \ + widget \ + appshell \ + docshell \ + exthandler \ + webshell \ + dom \ + necko \ + pref \ + embed_base \ + webbrwsr \ + windowwatcher \ + intl \ + profile \ + util \ + uconv \ + $(NULL) + +CPPSRCS = \ + nsAppStartup.cpp \ + nsCommandLineService.cpp \ + $(NULL) + +ifeq (os2,$(MOZ_WIDGET_TOOLKIT)) +CPPSRCS += nsUserInfoOS2.cpp +else +ifeq (WINNT,$(OS_ARCH)) +CPPSRCS += nsUserInfoWin.cpp +else +ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) +CPPSRCS += \ + nsUserInfoMac.cpp \ + nsCommandLineServiceMac.cpp \ + $(NULL) + +LOCAL_INCLUDES += -I$(srcdir)/../../../bootstrap/appleevents +OS_CXXFLAGS += -fexceptions +else +CPPSRCS += nsUserInfoUnix.cpp +endif +endif +endif + +EXTRA_COMPONENTS = nsCloseAllWindows.js + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/xpfe/components/startup/src/nsAppStartup.cpp b/mozilla/xpfe/components/startup/src/nsAppStartup.cpp new file mode 100644 index 00000000000..3a44b2b65c0 --- /dev/null +++ b/mozilla/xpfe/components/startup/src/nsAppStartup.cpp @@ -0,0 +1,1054 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** 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 Mozilla Communicator client code. This file was split + * from xpfe/appshell/src/nsAppShellService.cpp + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Pierre Phaneuf + * Robert O'Callahan + * Benjamin Smedberg + * + * Alternatively, the contents of this file may be used under the terms of + * either of 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 "nsAppStartup.h" + +#include "nsIAppShellService.h" +#include "nsICharsetConverterManager.h" +#include "nsICloseAllWindows.h" +#include "nsIDOMWindowInternal.h" +#include "nsIEventQueue.h" +#include "nsIEventQueueService.h" +#include "nsIInterfaceRequestor.h" +#include "nsILocalFile.h" +#include "nsIObserverService.h" +#include "nsIPlatformCharset.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" +#include "nsIProfileChangeStatus.h" +#include "nsIProfileInternal.h" +#include "nsIPromptService.h" +#include "nsIStringBundle.h" +#include "nsISupportsPrimitives.h" +#include "nsITimelineService.h" +#include "nsIUnicodeDecoder.h" +#include "nsIWebBrowserChrome.h" +#include "nsIWebShellWindow.h" +#include "nsIWindowMediator.h" +#include "nsIWindowWatcher.h" +#include "nsIXULWindow.h" + +#include "prprf.h" +#include "nsCRT.h" +#include "nsIInterfaceRequestorUtils.h" +#include "nsWidgetsCID.h" +#include "nsAppShellCID.h" +#include "nsXPFEComponentsCID.h" + +NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID); + +// Static Function Prototypes +static nsresult ConvertToUnicode(nsCString& aCharset, const char* inString, nsAString& outString); + +// +// nsAppStartup +// + +nsAppStartup::nsAppStartup() : + mConsiderQuitStopper(0), + mShuttingDown(PR_FALSE), + mAttemptingQuit(PR_FALSE) +{ } + + +// +// nsAppStartup->nsISupports +// + +NS_IMPL_ISUPPORTS5(nsAppStartup, + nsIAppStartup, + nsIWindowCreator, + nsIWindowCreator2, + nsIObserver, + nsISupportsWeakReference) + + +// +// nsAppStartup->nsIAppStartup +// + +NS_IMETHODIMP +nsAppStartup::Initialize(nsICmdLineService *aCmdLineService, + nsISupports *aNativeAppSupportOrSplashScreen) +{ + nsresult rv; + + // Remember cmd line service. + mCmdLineService = aCmdLineService; + + // Remember where the native app support lives. + mNativeAppSupport = do_QueryInterface(aNativeAppSupportOrSplashScreen); + + // Or, remember the splash screen (for backward compatibility). + if (!mNativeAppSupport) + mSplashScreen = do_QueryInterface(aNativeAppSupportOrSplashScreen); + + // Create widget application shell + mAppShell = do_CreateInstance(kAppShellCID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + PRInt32 argc = 0; + char** argv = nsnull; + aCmdLineService->GetArgc(&argc); + aCmdLineService->GetArgv(&argv); + + rv = mAppShell->Create(&argc, argv); + NS_ENSURE_SUCCESS(rv, rv); + + // listen to EventQueues' comings and goings. do this after the appshell + // has been created, but after the event queue has been created. that + // latter bit is unfortunate, but we deal with it. + nsCOMPtr os + (do_GetService("@mozilla.org/observer-service;1", &rv)); + NS_ENSURE_SUCCESS(rv, rv); + + os->AddObserver(this, "nsIEventQueueActivated", PR_TRUE); + os->AddObserver(this, "nsIEventQueueDestroyed", PR_TRUE); + os->AddObserver(this, "skin-selected", PR_TRUE); + os->AddObserver(this, "locale-selected", PR_TRUE); + os->AddObserver(this, "xpinstall-restart", 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); + os->AddObserver(this, "xul-window-visible", PR_TRUE); + + return NS_OK; +} + + +NS_IMETHODIMP +nsAppStartup::CreateHiddenWindow() +{ + nsCOMPtr appShellService + (do_GetService(NS_APPSHELLSERVICE_CONTRACTID)); + NS_ENSURE_TRUE(appShellService, NS_ERROR_FAILURE); + + return appShellService->CreateHiddenWindow(mAppShell); +} + + +NS_IMETHODIMP +nsAppStartup::DoProfileStartup(nsICmdLineService *aCmdLineService, + PRBool canInteract) +{ + nsresult rv; + + nsCOMPtr profileMgr + (do_GetService(NS_PROFILE_CONTRACTID, &rv)); + NS_ENSURE_SUCCESS(rv,rv); + + EnterLastWindowClosingSurvivalArea(); + + // If we are being launched in turbo mode, profile mgr cannot show UI + rv = profileMgr->StartupWithArgs(aCmdLineService, canInteract); + if (!canInteract && rv == NS_ERROR_PROFILE_REQUIRES_INTERACTION) { + NS_WARNING("nsIProfileInternal::StartupWithArgs returned NS_ERROR_PROFILE_REQUIRES_INTERACTION"); + rv = NS_OK; + } + + if (NS_SUCCEEDED(rv)) { + rv = CheckAndRemigrateDefunctProfile(); + NS_ASSERTION(NS_SUCCEEDED(rv), "failed to check and remigrate profile"); + rv = NS_OK; + } + + ExitLastWindowClosingSurvivalArea(); + + // if Quit() was called while we were starting up we have a failure situation... + if (mShuttingDown) + return NS_ERROR_FAILURE; + + return rv; +} + + +NS_IMETHODIMP +nsAppStartup::GetNativeAppSupport(nsINativeAppSupport **aResult) +{ + NS_PRECONDITION(aResult, "Null out param"); + + if (!mNativeAppSupport) + return NS_ERROR_FAILURE; + + NS_ADDREF(*aResult = mNativeAppSupport); + return NS_OK; +} + + +NS_IMETHODIMP +nsAppStartup::Run(void) +{ + return mAppShell->Run(); +} + + +NS_IMETHODIMP +nsAppStartup::Quit(PRUint32 aFerocity) +{ + // Quit the application. We will asynchronously call the appshell's + // Exit() method via the ExitCallback() to allow one last pass + // through any events in the queue. This guarantees a tidy cleanup. + nsresult rv = NS_OK; + PRBool postedExitEvent = PR_FALSE; + + if (mShuttingDown) + return NS_OK; + + /* eForceQuit doesn't actually work; it can cause a subtle crash if + there are windows open which have unload handlers which open + new windows. Use eAttemptQuit for now. */ + if (aFerocity == eForceQuit) { + NS_WARNING("attempted to force quit"); + // it will be treated the same as eAttemptQuit, below + } + + mShuttingDown = PR_TRUE; + + nsCOMPtr mediator + (do_GetService(NS_WINDOWMEDIATOR_CONTRACTID)); + + if (aFerocity == eConsiderQuit && mConsiderQuitStopper == 0) { + // attempt quit if the last window has been unregistered/closed + + PRBool windowsRemain = PR_TRUE; + + if (mediator) { + nsCOMPtr windowEnumerator; + mediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator)); + if (windowEnumerator) + windowEnumerator->HasMoreElements(&windowsRemain); + } + if (!windowsRemain) { + aFerocity = eAttemptQuit; + + // Check to see if we should quit in this case. + if (mNativeAppSupport) { + PRBool serverMode = PR_FALSE; + mNativeAppSupport->GetIsServerMode(&serverMode); + if (serverMode) { + // stop! give control to server mode + mShuttingDown = PR_FALSE; + mNativeAppSupport->OnLastWindowClosing(); + return NS_OK; + } + } + } + } + + /* Currently aFerocity can never have the value of eForceQuit here. + That's temporary (in an unscheduled kind of way) and logically + this code is part of the eForceQuit case, so I'm checking against + that value anyway. Reviewers made me add this comment. */ + if (aFerocity == eAttemptQuit || aFerocity == eForceQuit) { + + AttemptingQuit(PR_TRUE); + + /* Enumerate through each open window and close it. It's important to do + this before we forcequit because this can control whether we really quit + at all. e.g. if one of these windows has an unload handler that + opens a new window. Ugh. I know. */ + if (mediator) { + nsCOMPtr windowEnumerator; + + mediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator)); + + if (windowEnumerator) { + + while (1) { + PRBool more; + if (NS_FAILED(rv = windowEnumerator->HasMoreElements(&more)) || !more) + break; + + nsCOMPtr isupports; + rv = windowEnumerator->GetNext(getter_AddRefs(isupports)); + if (NS_FAILED(rv)) + break; + + nsCOMPtr window = do_QueryInterface(isupports); + NS_ASSERTION(window, "not an nsIDOMWindowInternal"); + if (!window) + continue; + + window->Close(); + } + } + + if (aFerocity == eAttemptQuit) { + + aFerocity = eForceQuit; // assume success + + /* Were we able to immediately close all windows? if not, eAttemptQuit + failed. This could happen for a variety of reasons; in fact it's + very likely. Perhaps we're being called from JS and the window->Close + method hasn't had a chance to wrap itself up yet. So give up. + We'll return (with eConsiderQuit) as the remaining windows are + closed. */ + mediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator)); + if (windowEnumerator) { + PRBool more; + while (windowEnumerator->HasMoreElements(&more), more) { + /* we can't quit immediately. we'll try again as the last window + finally closes. */ + aFerocity = eAttemptQuit; + nsCOMPtr window; + windowEnumerator->GetNext(getter_AddRefs(window)); + nsCOMPtr domWindow(do_QueryInterface(window)); + if (domWindow) { + PRBool closed = PR_FALSE; + domWindow->GetClosed(&closed); + if (!closed) { + rv = NS_ERROR_FAILURE; + break; + } + } + } + } + } + } + } + + if (aFerocity == eForceQuit) { + // do it! + + // No chance of the shutdown being cancelled from here on; tell people + // we're shutting down for sure while all services are still available. + nsCOMPtr obsService = do_GetService("@mozilla.org/observer-service;1", &rv); + obsService->NotifyObservers(nsnull, "quit-application", nsnull); + + // first shutdown native app support; doing this first will prevent new + // requests to open additional windows coming in. + if (mNativeAppSupport) { + mNativeAppSupport->Quit(); + mNativeAppSupport = 0; + } + + nsCOMPtr appShellService + (do_GetService(NS_APPSHELLSERVICE_CONTRACTID)); + if (appShellService) + appShellService->DestroyHiddenWindow(); + + // no matter what, make sure we send the exit event. If + // worst comes to worst, we'll do a leaky shutdown but we WILL + // shut down. Well, assuming that all *this* stuff works ;-). + nsCOMPtr svc = do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + + nsCOMPtr queue; + rv = svc->GetThreadEventQueue(NS_CURRENT_THREAD, getter_AddRefs(queue)); + if (NS_SUCCEEDED(rv)) { + + PLEvent* event = new PLEvent; + if (event) { + NS_ADDREF_THIS(); + PL_InitEvent(event, + this, + HandleExitEvent, + DestroyExitEvent); + + rv = queue->PostEvent(event); + if (NS_SUCCEEDED(rv)) { + postedExitEvent = PR_TRUE; + } + else { + PL_DestroyEvent(event); + } + } + else { + rv = NS_ERROR_OUT_OF_MEMORY; + } + } + } + } + + // turn off the reentrancy check flag, but not if we have + // more asynchronous work to do still. + if (!postedExitEvent) + mShuttingDown = PR_FALSE; + return rv; +} + + +/* We know we're trying to quit the app, but may not be able to do so + immediately. Enter a state where we're more ready to quit. + (Does useful work only on the Mac.) */ +void +nsAppStartup::AttemptingQuit(PRBool aAttempt) +{ +#if defined(XP_MAC) || defined(XP_MACOSX) + if (aAttempt) { + // now even the Mac wants to quit when the last window is closed + if (!mAttemptingQuit) + ExitLastWindowClosingSurvivalArea(); + mAttemptingQuit = PR_TRUE; + } else { + // changed our mind. back to normal. + if (mAttemptingQuit) + EnterLastWindowClosingSurvivalArea(); + mAttemptingQuit = PR_FALSE; + } +#else + mAttemptingQuit = aAttempt; +#endif +} + +nsresult +nsAppStartup::CheckAndRemigrateDefunctProfile() +{ + nsresult rv; + + nsCOMPtr prefBranch; + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv,rv); + rv = prefs->GetBranch(nsnull, getter_AddRefs(prefBranch)); + NS_ENSURE_SUCCESS(rv,rv); + + PRInt32 secondsBeforeDefunct; + rv = prefBranch->GetIntPref("profile.seconds_until_defunct", &secondsBeforeDefunct); + NS_ENSURE_SUCCESS(rv,rv); + + // -1 is the value for "never go defunct" + // if the pref is set to -1, we'll never prompt the user to remigrate + // see all.js (and all-ns.js) + if (secondsBeforeDefunct == -1) + return NS_OK; + + // used for converting + // seconds -> millisecs + // and microsecs -> millisecs + PRInt64 oneThousand = LL_INIT(0, 1000); + + PRInt64 defunctInterval; + // Init as seconds + LL_I2L(defunctInterval, secondsBeforeDefunct); + // Convert secs to millisecs + LL_MUL(defunctInterval, defunctInterval, oneThousand); + + nsCOMPtr profileMgr(do_GetService(NS_PROFILE_CONTRACTID, &rv)); + NS_ENSURE_SUCCESS(rv,rv); + + nsXPIDLString profileName; + PRInt64 lastModTime; + profileMgr->GetCurrentProfile(getter_Copies(profileName)); + rv = profileMgr->GetProfileLastModTime(profileName.get(), &lastModTime); + NS_ENSURE_SUCCESS(rv,rv); + + // convert "now" from microsecs to millisecs + PRInt64 nowInMilliSecs = PR_Now(); + LL_DIV(nowInMilliSecs, nowInMilliSecs, oneThousand); + + // determine (using the pref value) when the profile would be considered defunct + PRInt64 defunctIntervalAgo; + LL_SUB(defunctIntervalAgo, nowInMilliSecs, defunctInterval); + + // if we've used our current 6.x / mozilla profile more recently than + // when we'd consider it defunct, don't remigrate + if (LL_CMP(lastModTime, >, defunctIntervalAgo)) + return NS_OK; + + nsCOMPtr origProfileDir; + rv = profileMgr->GetOriginalProfileDir(profileName, getter_AddRefs(origProfileDir)); + // if this fails + // then the current profile is a new one (not from 4.x) + // so we are done. + if (NS_FAILED(rv)) + return NS_OK; + + // Now, we know that a matching 4.x profile exists + // See if it has any newer files in it than our defunct profile. + nsCOMPtr dirEnum; + rv = origProfileDir->GetDirectoryEntries(getter_AddRefs(dirEnum)); + NS_ENSURE_SUCCESS(rv,rv); + + PRBool promptForRemigration = PR_FALSE; + PRBool hasMore; + while (NS_SUCCEEDED(dirEnum->HasMoreElements(&hasMore)) && hasMore) { + nsCOMPtr currElem; + rv = dirEnum->GetNext(getter_AddRefs(currElem)); + NS_ENSURE_SUCCESS(rv,rv); + + PRInt64 currElemModTime; + rv = currElem->GetLastModifiedTime(&currElemModTime); + NS_ENSURE_SUCCESS(rv,rv); + // if this file in our 4.x profile is more recent than when we last used our mozilla / 6.x profile + // we should prompt for re-migration + if (LL_CMP(currElemModTime, >, lastModTime)) { + promptForRemigration = PR_TRUE; + break; + } + } + + // If nothing in the 4.x dir is newer than our defunct profile, return. + if (!promptForRemigration) + return NS_OK; + + nsCOMPtr stringBundleService(do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv)); + NS_ENSURE_SUCCESS(rv,rv); + + nsCOMPtr migrationBundle, brandBundle; + rv = stringBundleService->CreateBundle("chrome://communicator/locale/profile/migration.properties", getter_AddRefs(migrationBundle)); + NS_ENSURE_SUCCESS(rv,rv); + + rv = stringBundleService->CreateBundle("chrome://global/locale/brand.properties", getter_AddRefs(brandBundle)); + NS_ENSURE_SUCCESS(rv,rv); + + nsXPIDLString brandName; + rv = brandBundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(), getter_Copies(brandName)); + NS_ENSURE_SUCCESS(rv,rv); + + nsXPIDLString dialogText; + rv = migrationBundle->GetStringFromName(NS_LITERAL_STRING("confirmRemigration").get(), getter_Copies(dialogText)); + NS_ENSURE_SUCCESS(rv,rv); + + nsCOMPtr promptService(do_GetService("@mozilla.org/embedcomp/prompt-service;1", &rv)); + NS_ENSURE_SUCCESS(rv,rv); + PRInt32 buttonPressed; + rv = promptService->ConfirmEx(nsnull, brandName.get(), + dialogText.get(), + (nsIPromptService::BUTTON_POS_0 * + nsIPromptService::BUTTON_TITLE_YES) + + (nsIPromptService::BUTTON_POS_1 * + nsIPromptService::BUTTON_TITLE_NO), + nsnull, nsnull, nsnull, nsnull, nsnull, &buttonPressed); + NS_ENSURE_SUCCESS(rv,rv); + + if (buttonPressed == 0) { + // Need to shut down the current profile before remigrating it + profileMgr->ShutDownCurrentProfile(nsIProfile::SHUTDOWN_PERSIST); + // If this fails, it will restore what was there. + rv = profileMgr->RemigrateProfile(profileName.get()); + NS_ASSERTION(NS_SUCCEEDED(rv), "Remigration of profile failed."); + // Whether or not we succeeded or failed, need to reset this. + profileMgr->SetCurrentProfile(profileName.get()); + } + return NS_OK; +} + + +NS_IMETHODIMP +nsAppStartup::EnterLastWindowClosingSurvivalArea(void) +{ + ++mConsiderQuitStopper; + return NS_OK; +} + + +NS_IMETHODIMP +nsAppStartup::ExitLastWindowClosingSurvivalArea(void) +{ + NS_ASSERTION(mConsiderQuitStopper > 0, "consider quit stopper out of bounds"); + --mConsiderQuitStopper; + return NS_OK; +} + + +NS_IMETHODIMP +nsAppStartup::HideSplashScreen() +{ + // Hide the splash screen. + if ( mNativeAppSupport ) { + mNativeAppSupport->HideSplashScreen(); + } else if ( mSplashScreen ) { + mSplashScreen->Hide(); + } + return NS_OK; +} + + +NS_IMETHODIMP +nsAppStartup::CreateStartupState(PRInt32 aWindowWidth, PRInt32 aWindowHeight, + PRBool *_retval) +{ + NS_ENSURE_ARG_POINTER(_retval); + nsresult rv; + + 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); + + return NS_OK; +} + + +NS_IMETHODIMP +nsAppStartup::Ensure1Window(nsICmdLineService *aCmdLineService) +{ + nsresult rv; + + // If starting up in server mode, then we do things differently. + nsCOMPtr nativeApp; + rv = GetNativeAppSupport(getter_AddRefs(nativeApp)); + if (NS_SUCCEEDED(rv)) { + PRBool isServerMode = PR_FALSE; + nativeApp->GetIsServerMode(&isServerMode); + if (isServerMode) { + nativeApp->StartServerMode(); + } + PRBool shouldShowUI = PR_TRUE; + nativeApp->GetShouldShowUI(&shouldShowUI); + if (!shouldShowUI) { + return NS_OK; + } + } + + nsCOMPtr windowMediator(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv)); + if (NS_FAILED(rv)) + return 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); + + rv = OpenBrowserWindow(height, width); + } + } + return rv; +} + + +void* PR_CALLBACK +nsAppStartup::HandleExitEvent(PLEvent* aEvent) +{ + nsAppStartup *service = + NS_REINTERPRET_CAST(nsAppStartup*, aEvent->owner); + + // Tell the appshell to exit + service->mAppShell->Exit(); + + // We're done "shutting down". + service->mShuttingDown = PR_FALSE; + + return nsnull; +} + +void PR_CALLBACK +nsAppStartup::DestroyExitEvent(PLEvent* aEvent) +{ + nsAppStartup *service = + NS_REINTERPRET_CAST(nsAppStartup*, aEvent->owner); + NS_RELEASE(service); + delete aEvent; +} + + +nsresult +nsAppStartup::LaunchTask(const char *aParam, PRInt32 height, PRInt32 width, PRBool *windowOpened) +{ + nsresult rv; + + 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) { + 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 { + 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; + + // Make sure a profile is selected. + + // We need the native app support object. If this fails, we still proceed. + // That's because some platforms don't have a native app + // support implementation. On those platforms, "ensuring a + // profile" is moot (because they don't support "-turbo", + // basically). Specifically, because they don't do turbo, they will + // *always* have a profile selected. + nsCOMPtr nativeApp; + if (NS_SUCCEEDED(GetNativeAppSupport(getter_AddRefs(nativeApp)))) + { + nsCOMPtr cmdLine = + do_GetService(NS_COMMANDLINESERVICE_CONTRACTID); + + if (cmdLine) { + // Make sure profile has been selected. + // At this point, we have to look for failure. That + // handles the case where the user chooses "Exit" on + // the profile manager window. + if (NS_FAILED(nativeApp->EnsureProfile(cmdLine))) + return NS_ERROR_NOT_INITIALIZED; + } + } + + 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; + if (nsCRT::IsAscii(urlToLoad)) { + CopyASCIItoUTF16(urlToLoad, url); + } + else { + // get a platform charset + nsCAutoString charSet; + nsCOMPtr platformCharset(do_GetService(NS_PLATFORMCHARSET_CONTRACTID, &rv)); + if (NS_FAILED(rv)) { + NS_ERROR("Failed to get a platform charset"); + return rv; + } + + rv = platformCharset->GetCharset(kPlatformCharsetSel_FileName, charSet); + if (NS_FAILED(rv)) { + NS_ERROR("Failed to get a charset"); + return rv; + } + + // convert the cmdLine URL to Unicode + rv = ConvertToUnicode(charSet, urlToLoad, url); + if (NS_FAILED(rv)) { + NS_ASSERTION(0, "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_ConvertUTF16toUTF8(defaultArgs).get()); +#endif /* DEBUG_CMD_LINE */ + + rv = OpenWindow(chromeUrlForTask, defaultArgs, width, height); + } + + return rv; +} + + +// +// nsAppStartup->nsIWindowCreator +// + +NS_IMETHODIMP +nsAppStartup::CreateChromeWindow(nsIWebBrowserChrome *aParent, + PRUint32 aChromeFlags, + nsIWebBrowserChrome **_retval) +{ + PRBool cancel; + return CreateChromeWindow2(aParent, aChromeFlags, 0, 0, &cancel, _retval); +} + + +// +// nsAppStartup->nsIWindowCreator2 +// + +NS_IMETHODIMP +nsAppStartup::CreateChromeWindow2(nsIWebBrowserChrome *aParent, + PRUint32 aChromeFlags, + PRUint32 aContextFlags, + nsIURI *aURI, + PRBool *aCancel, + nsIWebBrowserChrome **_retval) +{ + NS_ENSURE_ARG_POINTER(aCancel); + NS_ENSURE_ARG_POINTER(_retval); + *aCancel = PR_FALSE; + *_retval = 0; + + nsCOMPtr newWindow; + + if (aParent) { + nsCOMPtr xulParent(do_GetInterface(aParent)); + NS_ASSERTION(xulParent, "window created using non-XUL parent. that's unexpected, but may work."); + + if (xulParent) + xulParent->CreateNewWindow(aChromeFlags, mAppShell, getter_AddRefs(newWindow)); + // And if it fails, don't try again without a parent. It could fail + // intentionally (bug 115969). + } else { // try using basic methods: + /* You really shouldn't be making dependent windows without a parent. + But unparented modal (and therefore dependent) windows happen + in our codebase, so we allow it after some bellyaching: */ + if (aChromeFlags & nsIWebBrowserChrome::CHROME_DEPENDENT) + NS_WARNING("dependent window created without a parent"); + + nsCOMPtr appShell(do_GetService(NS_APPSHELLSERVICE_CONTRACTID)); + if (!appShell) + return NS_ERROR_FAILURE; + + appShell->CreateTopLevelWindow(0, 0, PR_FALSE, PR_FALSE, + aChromeFlags, nsIAppShellService::SIZE_TO_CONTENT, + nsIAppShellService::SIZE_TO_CONTENT, mAppShell, getter_AddRefs(newWindow)); + } + + // if anybody gave us anything to work with, use it + if (newWindow) { + newWindow->SetContextFlags(aContextFlags); + nsCOMPtr thing(do_QueryInterface(newWindow)); + if (thing) + CallGetInterface(thing.get(), _retval); + } + + return *_retval ? NS_OK : NS_ERROR_FAILURE; +} + + +// +// nsAppStartup->nsIObserver +// + +NS_IMETHODIMP +nsAppStartup::Observe(nsISupports *aSubject, + const char *aTopic, const PRUnichar *aData) +{ + NS_ASSERTION(mAppShell, "appshell service notified before appshell built"); + if (!strcmp(aTopic, "nsIEventQueueActivated")) { + nsCOMPtr eq(do_QueryInterface(aSubject)); + if (eq) { + PRBool isNative = PR_TRUE; + // we only add native event queues to the appshell + eq->IsQueueNative(&isNative); + if (isNative) + mAppShell->ListenToEventQueue(eq, PR_TRUE); + } + } else if (!strcmp(aTopic, "nsIEventQueueDestroyed")) { + nsCOMPtr eq(do_QueryInterface(aSubject)); + if (eq) { + PRBool isNative = PR_TRUE; + // we only remove native event queues from the appshell + eq->IsQueueNative(&isNative); + if (isNative) + mAppShell->ListenToEventQueue(eq, PR_FALSE); + } + } else if (!strcmp(aTopic, "skin-selected") || + !strcmp(aTopic, "locale-selected") || + !strcmp(aTopic, "xpinstall-restart")) { + if (mNativeAppSupport) + mNativeAppSupport->SetIsServerMode(PR_FALSE); + } else if (!strcmp(aTopic, "profile-change-teardown")) { + nsresult rv; + EnterLastWindowClosingSurvivalArea(); + // NOTE: No early error exits because we need to execute the + // balancing ExitLastWindowClosingSurvivalArea(). + nsCOMPtr closer = + do_CreateInstance("@mozilla.org/appshell/closeallwindows;1", &rv); + NS_ASSERTION(closer, "Failed to create nsICloseAllWindows impl."); + PRBool proceedWithSwitch = PR_FALSE; + if (closer) + rv = closer->CloseAll(PR_TRUE, &proceedWithSwitch); + if (NS_FAILED(rv) || !proceedWithSwitch) { + nsCOMPtr changeStatus(do_QueryInterface(aSubject)); + if (changeStatus) + changeStatus->VetoChange(); + } + ExitLastWindowClosingSurvivalArea(); + } else if (!strcmp(aTopic, "profile-initial-state")) { + if (nsDependentString(aData).EqualsLiteral("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")) { + Quit(eConsiderQuit); + } else if (!strcmp(aTopic, "xul-window-visible")) { + // Hide splash screen (if there is one). + static PRBool splashScreenGone = PR_FALSE; + if(!splashScreenGone) { + HideSplashScreen(); + splashScreenGone = PR_TRUE; + } + } else { + NS_ERROR("Unexpected observer topic."); + } + + return NS_OK; +} + +static nsresult +ConvertToUnicode(nsCString& aCharset, const char* inString, nsAString& outString) +{ + nsresult rv; + + // convert result to unicode + nsCOMPtr ccm(do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID , &rv)); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr decoder; + rv = ccm->GetUnicodeDecoderRaw(aCharset.get(), getter_AddRefs(decoder)); + if (NS_FAILED(rv)) + return rv; + + PRInt32 uniLength = 0; + PRInt32 srcLength = strlen(inString); + rv = decoder->GetMaxLength(inString, srcLength, &uniLength); + if (NS_FAILED(rv)) + return rv; + + outString.SetLength(uniLength); + nsWritingIterator unichars; + outString.BeginWriting(unichars); + + // convert to unicode + rv = decoder->Convert(inString, &srcLength, unichars.get(), &uniLength); + if (NS_SUCCEEDED(rv)) { + // Pass back the unicode string + outString.Assign(unichars.get(), uniLength); + } + + return rv; +} diff --git a/mozilla/xpfe/components/startup/src/nsAppStartup.h b/mozilla/xpfe/components/startup/src/nsAppStartup.h new file mode 100644 index 00000000000..4f3ac3f188c --- /dev/null +++ b/mozilla/xpfe/components/startup/src/nsAppStartup.h @@ -0,0 +1,103 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** 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 Mozilla Communicator client code. This file was split + * from xpfe/appshell/src/nsAppShellService.h + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Benjamin Smedberg + * + * Alternatively, the contents of this file may be used under the terms of + * either of 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 ***** */ + +#ifndef nsAppStartup_h__ +#define nsAppStartup_h__ + +#include "nsIAppStartup.h" +#include "nsIWindowCreator2.h" +#include "nsIObserver.h" +#include "nsWeakReference.h" + +#include "nsICmdLineService.h" +#include "nsISplashScreen.h" +#include "nsINativeAppSupport.h" +#include "nsIAppShell.h" + +#include "nsString.h" + +struct PLEvent; + +// {A70A1E2B-1FCB-41ca-B011-1D207B9EA7A9} +#define NS_SEAMONKEY_APPSTARTUP_CID \ +{ 0xa70a1e2b, 0x1fcb, 0x41ca, { 0xb0, 0x11, 0x1d, 0x20, 0x7b, 0x9e, 0xa7, 0xa9 } } + +class nsAppStartup : public nsIAppStartup, + public nsIWindowCreator2, + public nsIObserver, + public nsSupportsWeakReference +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIAPPSTARTUP + NS_DECL_NSIWINDOWCREATOR + NS_DECL_NSIWINDOWCREATOR2 + NS_DECL_NSIOBSERVER + + nsAppStartup(); + +private: + ~nsAppStartup() { } + + void AttemptingQuit(PRBool aAttempt); + + // A "last event" that is used to flush the appshell's event queue. + PR_STATIC_CALLBACK(void*) HandleExitEvent(PLEvent* aEvent); + PR_STATIC_CALLBACK(void) DestroyExitEvent(PLEvent* aEvent); + + nsresult CheckAndRemigrateDefunctProfile(); + 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; + nsCOMPtr mCmdLineService; + nsCOMPtr mSplashScreen; + nsCOMPtr mNativeAppSupport; + + PRInt32 mConsiderQuitStopper; // if > 0, Quit(eConsiderQuit) fails + PRPackedBool mShuttingDown; // Quit method reentrancy check + PRPackedBool mAttemptingQuit; // Quit(eAttemptQuit) still trying +}; + +#endif // nsAppStartup_h__ diff --git a/mozilla/xpfe/components/startup/src/nsCommandLineService.h b/mozilla/xpfe/components/startup/src/nsCommandLineService.h index afc87f9fb47..7705e96b21b 100644 --- a/mozilla/xpfe/components/startup/src/nsCommandLineService.h +++ b/mozilla/xpfe/components/startup/src/nsCommandLineService.h @@ -62,4 +62,9 @@ protected: PRBool ArgsMatch(const char *lookingFor, const char *userGave); }; +// e34783f5-ac08-11d2-8d19-00805fc2500c +#define NS_COMMANDLINESERVICE_CID \ +{ 0xe34783f5, 0xac08, 0x11d2, \ + {0x8d, 0x19, 0x00, 0x80, 0x5f, 0xc2, 0x50,0xc} } + #endif diff --git a/mozilla/xpfe/components/startup/src/nsCommandLineServiceMac.cpp b/mozilla/xpfe/components/startup/src/nsCommandLineServiceMac.cpp index cd27e0628e6..bd6ff7bb44c 100644 --- a/mozilla/xpfe/components/startup/src/nsCommandLineServiceMac.cpp +++ b/mozilla/xpfe/components/startup/src/nsCommandLineServiceMac.cpp @@ -46,7 +46,7 @@ #include "nsILocalFileMac.h" #include "nsDebug.h" #include "nsNetUtil.h" -#include "nsIAppShellService.h" +#include "nsIAppStartup.h" #include "nsIServiceManager.h" #include "nsIURL.h" #include "nsIIOService.h" @@ -65,6 +65,7 @@ #include "nsIPrefService.h" #include "nsAEEventHandling.h" +#include "nsXPFEComponentsCID.h" // NSPR #include "prmem.h" @@ -74,9 +75,6 @@ #include "pprio.h" // PR_Init_Log #endif -#include "nsAppShellCIDs.h" -static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); - // the static instance nsMacCommandLine nsMacCommandLine::sMacCommandLine; @@ -402,12 +400,12 @@ OSErr nsMacCommandLine::Quit(TAskSave askSave) if (NS_FAILED(rv) || !doQuit) return errAEEventNotHandled; - nsCOMPtr appShellService = - do_GetService(kAppShellServiceCID, &rv); + nsCOMPtr appStartup = + (do_GetService(NS_APPSTARTUP_CONTRACTID, &rv)); if (NS_FAILED(rv)) return errAEEventNotHandled; - (void)appShellService->Quit(nsIAppShellService::eAttemptQuit); + (void)appStartup->Quit(nsIAppStartup::eAttemptQuit); return noErr; } diff --git a/mozilla/xpfe/components/winhooks/nsSetDefaultBrowser.js b/mozilla/xpfe/components/winhooks/nsSetDefaultBrowser.js index bfcacd3e104..2fbbb33976e 100644 --- a/mozilla/xpfe/components/winhooks/nsSetDefaultBrowser.js +++ b/mozilla/xpfe/components/winhooks/nsSetDefaultBrowser.js @@ -87,7 +87,7 @@ nsSetDefaultBrowser.prototype = { winHooks.settings = settings; // Now, get the cmd line service. - var cmdLineService = Components.classes[ "@mozilla.org/appshell/commandLineService;1" ] + var cmdLineService = Components.classes[ "@mozilla.org/app-startup/commandLineService;1" ] .getService( Components.interfaces.nsICmdLineService ); // See if "-setDefaultBrowser" was specified. The value will be "1" if diff --git a/mozilla/xpfe/components/winhooks/nsSetDefaultMail.js b/mozilla/xpfe/components/winhooks/nsSetDefaultMail.js index 5ed0ae8300a..1628f81865e 100644 --- a/mozilla/xpfe/components/winhooks/nsSetDefaultMail.js +++ b/mozilla/xpfe/components/winhooks/nsSetDefaultMail.js @@ -88,7 +88,7 @@ nsSetDefaultMail.prototype = { mapiRegistry.isDefaultMailClient = true; // Now, get the cmd line service. - var cmdLineService = Components.classes[ "@mozilla.org/appshell/commandLineService;1" ] + var cmdLineService = Components.classes[ "@mozilla.org/app-startup/commandLineService;1" ] .getService( Components.interfaces.nsICmdLineService ); // See if "-setDefaultMail" was specified. The value will be "1" if diff --git a/mozilla/xpfe/components/winhooks/nsUnsetDefaultMail.js b/mozilla/xpfe/components/winhooks/nsUnsetDefaultMail.js index b569ad11b1b..3dadee2a354 100644 --- a/mozilla/xpfe/components/winhooks/nsUnsetDefaultMail.js +++ b/mozilla/xpfe/components/winhooks/nsUnsetDefaultMail.js @@ -88,7 +88,7 @@ nsUnsetDefaultMail.prototype = { mapiRegistry.isDefaultMailClient = false; // Now, get the cmd line service. - var cmdLineService = Components.classes[ "@mozilla.org/appshell/commandLineService;1" ] + var cmdLineService = Components.classes[ "@mozilla.org/app-startup/commandLineService;1" ] .getService( Components.interfaces.nsICmdLineService ); // See if "-unsetDefaultMail" was specified. The value will be "1" if diff --git a/mozilla/xpfe/components/winhooks/nsWindowsHooks.cpp b/mozilla/xpfe/components/winhooks/nsWindowsHooks.cpp index 779d923ed92..a1f55c27bd5 100644 --- a/mozilla/xpfe/components/winhooks/nsWindowsHooks.cpp +++ b/mozilla/xpfe/components/winhooks/nsWindowsHooks.cpp @@ -386,8 +386,8 @@ nsWindowsHooks::CheckSettings( nsIDOMWindowInternal *aParent, PRBool installing = PR_FALSE; if ( !settings->mShowDialog ) { // Get command line service. - nsCID cmdLineCID = NS_COMMANDLINE_SERVICE_CID; - nsCOMPtr cmdLineArgs( do_GetService( cmdLineCID, &rv ) ); + nsCOMPtr cmdLineArgs + (do_GetService(NS_COMMANDLINESERVICE_CONTRACTID, &rv)); if ( NS_SUCCEEDED( rv ) && cmdLineArgs ) { // See if "-installer" was specified. nsXPIDLCString installer; diff --git a/mozilla/xpfe/components/xremote/src/Makefile.in b/mozilla/xpfe/components/xremote/src/Makefile.in index c3a5ff57edf..99de6465509 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 \ + appcomps \ rdf \ exthandler \ profile \ diff --git a/mozilla/xpfe/global/resources/content/globalOverlay.js b/mozilla/xpfe/global/resources/content/globalOverlay.js index 89fa4ffc4c4..829a617de86 100644 --- a/mozilla/xpfe/global/resources/content/globalOverlay.js +++ b/mozilla/xpfe/global/resources/content/globalOverlay.js @@ -19,12 +19,12 @@ function goQuitApplication() var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(); var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator); var enumerator = windowManagerInterface.getEnumerator( null ); - var appShell = Components.classes['@mozilla.org/appshell/appShellService;1'].getService(); - appShell = appShell.QueryInterface( Components.interfaces.nsIAppShellService ); + var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]. + getService(Components.interfaces.nsIAppStartup); var nativeAppSupport = null; try { - nativeAppSupport = appShell.nativeAppSupport; + nativeAppSupport = appStartup.nativeAppSupport; } catch ( ex ) { } @@ -37,7 +37,7 @@ function goQuitApplication() domWindow.close(); }; if (!nativeAppSupport || !nativeAppSupport.isServerMode) - appShell.quit(Components.interfaces.nsIAppShellService.eAttemptQuit); + appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit); return true; }