From fbb67e22fcfe36f13d35a048da3caf2f643ce6f7 Mon Sep 17 00:00:00 2001 From: "chak%netscape.com" Date: Mon, 12 Mar 2001 22:52:28 +0000 Subject: [PATCH] Partial fix for Bug# 68720 - nsEmbedAPI.cpp should use generic startup Not Part of the build yet - checking in new files to the project r=ccarlen,sr=alecf git-svn-id: svn://10.0.0.236/trunk@89384 18797224-902f-48f8-a5cc-f745e15eee43 --- .../components/appstartup/Makefile.in | 29 +++++ .../components/appstartup/makefile.win | 25 +++++ .../components/appstartup/src/MANIFEST | 1 + .../components/appstartup/src/Makefile.in | 44 ++++++++ .../components/appstartup/src/makefile.win | 40 +++++++ .../appstartup/src/nsAppStartupNotifier.cpp | 104 ++++++++++++++++++ .../appstartup/src/nsAppStartupNotifier.h | 45 ++++++++ .../appstartup/src/nsIAppStartupNotifier.h | 80 ++++++++++++++ 8 files changed, 368 insertions(+) create mode 100644 mozilla/embedding/components/appstartup/Makefile.in create mode 100644 mozilla/embedding/components/appstartup/makefile.win create mode 100644 mozilla/embedding/components/appstartup/src/MANIFEST create mode 100644 mozilla/embedding/components/appstartup/src/Makefile.in create mode 100644 mozilla/embedding/components/appstartup/src/makefile.win create mode 100644 mozilla/embedding/components/appstartup/src/nsAppStartupNotifier.cpp create mode 100644 mozilla/embedding/components/appstartup/src/nsAppStartupNotifier.h create mode 100644 mozilla/embedding/components/appstartup/src/nsIAppStartupNotifier.h diff --git a/mozilla/embedding/components/appstartup/Makefile.in b/mozilla/embedding/components/appstartup/Makefile.in new file mode 100644 index 00000000000..e206e67484e --- /dev/null +++ b/mozilla/embedding/components/appstartup/Makefile.in @@ -0,0 +1,29 @@ +# +# 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, Inc. Portions created by Netscape are +# Copyright (C) 2001, Mozilla. All Rights Reserved. +# +# Contributor(s): + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +DIRS = src + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/embedding/components/appstartup/makefile.win b/mozilla/embedding/components/appstartup/makefile.win new file mode 100644 index 00000000000..47fa8f7d3d8 --- /dev/null +++ b/mozilla/embedding/components/appstartup/makefile.win @@ -0,0 +1,25 @@ +#!nmake +# +# 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, Inc. Portions created by Netscape are +# Copyright (C) 2001, Mozilla. All Rights Reserved. +# +# Contributor(s): + +DEPTH=..\..\.. + +DIRS=src + +include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/embedding/components/appstartup/src/MANIFEST b/mozilla/embedding/components/appstartup/src/MANIFEST new file mode 100644 index 00000000000..5b31b91a0df --- /dev/null +++ b/mozilla/embedding/components/appstartup/src/MANIFEST @@ -0,0 +1 @@ +nsIAppStartupNotifier.h diff --git a/mozilla/embedding/components/appstartup/src/Makefile.in b/mozilla/embedding/components/appstartup/src/Makefile.in new file mode 100644 index 00000000000..87de99ee2ff --- /dev/null +++ b/mozilla/embedding/components/appstartup/src/Makefile.in @@ -0,0 +1,44 @@ +# +# 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, Inc. Portions created by Netscape are +# Copyright (C) 2001, Mozilla. All Rights Reserved. +# +# Contributor(s): + +DEPTH = ../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = embedcomponents +LIBRARY_NAME = appstartupnotifier_s +REQUIRES = xpcom webbrwsr embed_base + +CPPSRCS = nsAppStartupNotifier.cpp \ + $(NULL) + +EXPORTS = \ + nsIAppStartupNotifier.h \ + $(NULL) + +# we don't want the shared lib, but we want to force the creation of a +# static lib. +override NO_SHARED_LIB=1 +override NO_STATIC_LIB= + +include $(topsrcdir)/config/rules.mk + diff --git a/mozilla/embedding/components/appstartup/src/makefile.win b/mozilla/embedding/components/appstartup/src/makefile.win new file mode 100644 index 00000000000..2aa740f8e03 --- /dev/null +++ b/mozilla/embedding/components/appstartup/src/makefile.win @@ -0,0 +1,40 @@ +#!nmake +# +# 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, Inc. Portions created by Netscape are +# Copyright (C) 2001, Mozilla. All Rights Reserved. +# +# Contributor(s): + +DEPTH=..\..\..\.. + +MODULE=embedcomponents +LIBRARY_NAME=appstartupnotifier_s + +EXPORTS = \ + nsIAppStartupNotifier.h \ + $(NULL) + +CPP_OBJS= \ + .\$(OBJDIR)\nsAppStartupNotifier.obj \ + $(NULL) + +include <$(DEPTH)\config\rules.mak> + +install:: $(LIBRARY) + $(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib + +clobber:: + rm -f $(DIST)\lib\$(LIBRARY_NAME).lib diff --git a/mozilla/embedding/components/appstartup/src/nsAppStartupNotifier.cpp b/mozilla/embedding/components/appstartup/src/nsAppStartupNotifier.cpp new file mode 100644 index 00000000000..7595f7a3582 --- /dev/null +++ b/mozilla/embedding/components/appstartup/src/nsAppStartupNotifier.cpp @@ -0,0 +1,104 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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.org 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): + */ + +#include "nsCOMPtr.h" +#include "nsString.h" +#include "nsXPIDLString.h" +#include "nsIServiceManager.h" +#include "nsICategoryManager.h" +#include "nsISupportsPrimitives.h" +#include "nsAppStartupNotifier.h" + +NS_IMPL_ISUPPORTS1(nsAppStartupNotifier, nsIObserver) + +nsAppStartupNotifier::nsAppStartupNotifier() +{ + NS_INIT_ISUPPORTS(); +} + +nsAppStartupNotifier::~nsAppStartupNotifier() +{ +} + +NS_IMETHODIMP nsAppStartupNotifier::Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData) +{ + NS_ENSURE_ARG(aTopic); + + nsCAutoString strCategory; + if(aTopic) + strCategory.AssignWithConversion(aTopic); + + nsresult rv; + + // now initialize all startup listeners + nsCOMPtr categoryManager = + do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr enumerator; + rv = categoryManager->EnumerateCategory(strCategory.get(), + getter_AddRefs(enumerator)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr entry; + while (NS_SUCCEEDED(enumerator->GetNext(getter_AddRefs(entry)))) { + nsCOMPtr category = do_QueryInterface(entry, &rv); + + if (NS_SUCCEEDED(rv)) { + nsXPIDLCString categoryEntry; + rv = category->GetData(getter_Copies(categoryEntry)); + + nsXPIDLCString contractId; + categoryManager->GetCategoryEntry(strCategory.get(), + categoryEntry, + getter_Copies(contractId)); + + if (NS_SUCCEEDED(rv)) { + + // If we see the word "service," in the beginning + // of the contractId then we create it as a service + // if not we do a createInstance + + const char *pServicePrefix = "service,"; + + nsCAutoString cid(contractId); + PRInt32 serviceIdx = cid.Find(pServicePrefix); + + nsCOMPtr startupObserver; + if (serviceIdx == 0) + startupObserver = do_GetService(cid.get() + nsCRT::strlen(pServicePrefix), &rv); + else + startupObserver = do_CreateInstance(contractId, &rv); + + NS_ASSERTION(NS_SUCCEEDED(rv), "cannot create startup observer!\n"); + if (NS_SUCCEEDED(rv)) { + rv = startupObserver->Observe(nsnull, aTopic, nsnull); + + // mainly for debugging if you want to know if your observer worked. + NS_ASSERTION(NS_SUCCEEDED(rv), "Startup Observer failed!\n"); + } + } + } + } + + return NS_OK; +} diff --git a/mozilla/embedding/components/appstartup/src/nsAppStartupNotifier.h b/mozilla/embedding/components/appstartup/src/nsAppStartupNotifier.h new file mode 100644 index 00000000000..6e9ce8af0de --- /dev/null +++ b/mozilla/embedding/components/appstartup/src/nsAppStartupNotifier.h @@ -0,0 +1,45 @@ +/* -*- 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.org 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): + */ + +#ifndef nsAppStartupNotifier_h___ +#define nsAppStartupNotifier_h___ + +#include "nsIAppStartupNotifier.h" + +// {1F59B001-02C9-11d5-AE76-CC92F7DB9E03} +#define NS_APPSTARTUPNOTIFIER_CID \ + { 0x1f59b001, 0x2c9, 0x11d5, { 0xae, 0x76, 0xcc, 0x92, 0xf7, 0xdb, 0x9e, 0x3 } } + +class nsAppStartupNotifier : public nsIObserver +{ +public: + NS_DEFINE_STATIC_CID_ACCESSOR( NS_APPSTARTUPNOTIFIER_CID ) + + NS_DECL_ISUPPORTS + NS_DECL_NSIOBSERVER + + nsAppStartupNotifier(); + virtual ~nsAppStartupNotifier(); +}; + +#endif /* nsAppStartupNotifier_h___ */ + diff --git a/mozilla/embedding/components/appstartup/src/nsIAppStartupNotifier.h b/mozilla/embedding/components/appstartup/src/nsIAppStartupNotifier.h new file mode 100644 index 00000000000..8a035b38141 --- /dev/null +++ b/mozilla/embedding/components/appstartup/src/nsIAppStartupNotifier.h @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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.org 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): + */ + +#ifndef nsIAppStartupNotifier_h___ +#define nsIAppStartupNotifier_h___ + +#include "nsIObserver.h" + +/* + Some components need to be run at the startup of mozilla or embedding - to + start new services etc. + + This interface provides a generic way to start up arbitrary components + without requiring them to hack into main1() (or into NS_InitEmbedding) as + it's currently being done for services such as wallet, command line handlers + etc. + + We will have a category called "app-startup" which components register + themselves in using the CategoryManager. + + Components can also (optionally) add the word "service," as a prefix + to the "value" they pass in during a call to AddCategoryEntry() as + shown below: + + categoryManager->AddCategoryEntry(APPSTARTUP_CATEGORY, "testcomp", + "service," NS_WALLETSERVICE_CONTRACTID + PR_TRUE, PR_TRUE, + getter_Copies(previous)); + + Presence of the "service" keyword indicates the components desire to + be started as a service. When the "service" keyword is not present + we just do a do_CreateInstance. + + When mozilla starts (and when NS_InitEmbedding()) is invoked + we create an instance of the AppStartupNotifier component (which + implements nsIObserver) and invoke it's Observe() method. + + Observe() will enumerate the components registered into the + APPSTARTUP_CATEGORY and notify them that startup has begun + and release them. +*/ + +#include "nsString.h" + +#define NS_APPSTARTUPNOTIFIER_CONTRACTID "@mozilla.org/embedcomp/appstartup-notifier;1" +#define NS_APPSTARTUPNOTIFIER_CLASSNAME "AppStartup Notifier" + +#define APPSTARTUP_CATEGORY "app-startup" +#define APPSTARTUP_TOPIC (NS_LITERAL_STRING(APPSTARTUP_CATEGORY).get()) + + +/* + Please note that there's not a new interface in this file. + We're just leveraging nsIObserver instead of creating a + new one + + This file exists solely to provide the defines above +*/ + +#endif /* nsIAppStartupNotifier_h___ */ +