зеркало из https://github.com/mozilla/gecko-dev.git
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
This commit is contained in:
Родитель
45c721994e
Коммит
c6c8eaa18f
|
@ -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
|
|
@ -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>
|
|
@ -0,0 +1 @@
|
|||
nsIAppStartupNotifier.h
|
|
@ -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
|
||||
|
|
@ -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
|
|
@ -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<nsICategoryManager> categoryManager =
|
||||
do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsISimpleEnumerator> enumerator;
|
||||
rv = categoryManager->EnumerateCategory(strCategory.get(),
|
||||
getter_AddRefs(enumerator));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsISupports> entry;
|
||||
while (NS_SUCCEEDED(enumerator->GetNext(getter_AddRefs(entry)))) {
|
||||
nsCOMPtr<nsISupportsString> 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<nsIObserver> 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;
|
||||
}
|
|
@ -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___ */
|
||||
|
|
@ -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___ */
|
||||
|
Загрузка…
Ссылка в новой задаче