- move messenger appcore into the base mailnews directory

- do appcore initialization during Initialize() in messenger bootstrap
This commit is contained in:
alecf%netscape.com 1999-03-09 19:58:17 +00:00
Родитель 8722d17b90
Коммит 7028e88a0d
12 изменённых файлов: 1009 добавлений и 1 удалений

Просмотреть файл

@ -90,6 +90,10 @@ LLIBS= \
$(DIST)\lib\libplc21.lib \
$(DIST)\lib\js32$(VERSION_NUMBER).lib \
$(DIST)\lib\msgcore.lib \
$(DIST)\lib\appcores.lib \
$(DIST)\lib\nntp.lib \
$(DIST)\lib\netlib.lib \
$(DIST)\lib\nntpTest.lib \
$(LIBNSPR) \
$(NULL)
@ -101,6 +105,8 @@ LINCS=$(LINCS) -I, \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\rdf \
-I$(PUBLIC)\netlib \
-I$(PUBLIC)\dom \
-I$(PUBLIC)\appcores \
$(NULL)
#//------------------------------------------------------------------------

Просмотреть файл

@ -33,6 +33,8 @@
#include "nsIMsgGroupRecord.h"
#include "nsMsgGroupRecord.h"
#include "nsMsgAppCore.h"
/* Include all of the interfaces our factory can generate components for */
#include "nsIMsgRFC822Parser.h"
#include "nsMsgRFC822Parser.h"
@ -53,6 +55,7 @@ static NS_DEFINE_CID(kCMessengerBootstrapCID, NS_MESSENGERBOOTSTRAP_CID);
static NS_DEFINE_CID(kCMsgRFC822ParserCID, NS_MSGRFC822PARSER_CID);
static NS_DEFINE_CID(kCMsgFolderEventCID, NS_MSGFOLDEREVENT_CID);
static NS_DEFINE_CID(kCMsgAppCoreCID, NS_MSGAPPCORE_CID);
static NS_DEFINE_CID(kCMsgGroupRecordCID, NS_MSGGROUPRECORD_CID);
@ -195,6 +198,10 @@ nsMsgFactory::CreateInstance(nsISupports *aOuter,
if (session == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
}
else if (mClassID.Equals(kCMsgAppCoreCID)) {
res = NS_NewMsgAppCore((nsIDOMMsgAppCore **)&inst);
if (NS_FAILED(res)) return res;
}
// End of checking the interface ID code....
if (inst)
@ -293,6 +300,12 @@ NSRegisterSelf(nsISupports* aServMgr, const char* path)
"component://netscape/messenger",
path,
PR_TRUE, PR_TRUE);
rv = compMgr->RegisterComponent(kCMsgAppCoreCID,
"Messenger AppCore",
"component://netscape/appcores/messenger",
path,
PR_TRUE, PR_TRUE);
if (NS_FAILED(rv)) goto done;
#if 0
rv = compMgr->RegisterComponent(kCMsgGroupRecordCID,

Просмотреть файл

@ -44,6 +44,7 @@ EXPORTS = \
nsIUrlListener.h \
nsIMsgMailSession.h \
nsIMsgIdentity.h \
nsIDOMMsgAppCore.h \
$(NULL)
MODULE=mailnews

Просмотреть файл

@ -0,0 +1,61 @@
/*
* DO NOT EDIT. THIS FILE IS GENERATED FROM nsIDOMMsgAppCore.idl
*/
#ifndef __gen_nsIDOMMsgAppCore_h__
#define __gen_nsIDOMMsgAppCore_h__
#include "nsISupports.h" /* interface nsISupports */
#include "nsIDOMWindow.h" /* interface nsIDOMWindow */
#include "nsIDOMBaseAppCore.h" /* interface nsIDOMBaseAppCore */
#ifdef XPIDL_JS_STUBS
#include "jsapi.h"
#endif
#include "nsDebug.h"
#include "nsTraceRefcnt.h"
#include "nsID.h"
#include "nsIID.h"
#include "nsError.h"
#include "nsISupportsUtils.h"
/* starting interface nsIDOMMsgAppCore */
/* {4f7966d0-c14f-11d2-b7f2-00805f05ffa5} */
#define NS_IDOMMSGAPPCORE_IID_STR "4f7966d0-c14f-11d2-b7f2-00805f05ffa5"
#define NS_IDOMMSGAPPCORE_IID \
{0x4f7966d0, 0xc14f, 0x11d2, \
{ 0xb7, 0xf2, 0x00, 0x80, 0x5f, 0x05, 0xff, 0xa5 }}
class nsIDOMMsgAppCore : public nsIDOMBaseAppCore {
public:
static const nsIID& GetIID() {
static nsIID iid = NS_IDOMMSGAPPCORE_IID;
return iid;
}
/* void GetNewMail (); */
NS_IMETHOD GetNewMail() = 0;
/* void Open3PaneWindow (); */
NS_IMETHOD Open3PaneWindow() = 0;
/* void SetWindow (in nsIDOMWindow ptr); */
NS_IMETHOD SetWindow(nsIDOMWindow *ptr) = 0;
/* void OpenURL (in string str); */
NS_IMETHOD OpenURL(char *str) = 0;
#ifdef XPIDL_JS_STUBS
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsIDOMMsgAppCore *priv);
#endif
};
extern "C"
nsresult NS_InitMsgAppCoreClass(nsIScriptContext *aContext, void **aPrototype);
#endif /* __gen_nsIDOMMsgAppCore_h__ */

Просмотреть файл

@ -0,0 +1,59 @@
/* -*- Mode: IDL; 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsISupports.idl"
/* this should eventually derive from some sort of BaseAppCore */
/* -*- Mode: IDL; 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsIDOMBaseAppCore.idl"
#include "nsIDOMWindow.idl"
[object, uuid(4f7966d0-c14f-11d2-b7f2-00805f05ffa5)]
interface nsIDOMMsgAppCore : nsIDOMBaseAppCore {
void GetNewMail();
void Open3PaneWindow();
void SetWindow(in nsIDOMWindow ptr);
void OpenURL(in string str);
};
/* hack to make MsgAppCore visible from AppCore */
%{ C++
extern "C" NS_DOM
nsresult NS_InitMsgAppCoreClass(nsIScriptContext *aContext, void **aPrototype);
%}

Просмотреть файл

@ -42,8 +42,12 @@ CPPSRCS= \
nsUrlListenerManager.cpp \
nsMsgMailSession.cpp \
nsMsgIdentity.cpp \
nsJSMsgAppCore.cpp \
nsMsgAppCore.cpp \
$(NULL)
CPP_OBJS= \
.\$(OBJDIR)\nsMessenger.obj \
.\$(OBJDIR)\nsIMessenger.obj \
@ -60,8 +64,11 @@ CPP_OBJS= \
.\$(OBJDIR)\nsUrlListenerManager.obj \
.\$(OBJDIR)\nsMsgMailSession.obj \
.\$(OBJDIR)\nsMsgIdentity.obj \
.\$(OBJDIR)\nsMsgAppCore.obj \
.\$(OBJDIR)\nsJSMsgAppCore.obj \
$(NULL)
EXPORTS= \
nsMessenger.h \
nsMsgRFC822Parser.h \
@ -75,6 +82,7 @@ EXPORTS= \
nsUrlListenerManager.h \
nsMsgMailSession.h \
nsMsgIdentity.h \
nsMsgAppCore.h \
$(NULL)
LINCS= \
@ -87,6 +95,8 @@ LINCS= \
-I$(PUBLIC)\js \
-I$(PUBLIC)\netlib \
-I$(PUBLIC)\dom \
-I$(PUBLIC)\appcores \
-I$(PUBLIC)\security \
$(NULL)
LCFLAGS = \

Просмотреть файл

@ -0,0 +1,468 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nsJSUtils.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMMsgAppCore.h"
#include "nsIDOMWindow.h"
#include "nsIScriptNameSpaceManager.h"
#include "nsRepository.h"
#include "nsDOMCID.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIMsgAppCoreIID, NS_IDOMMSGAPPCORE_IID);
static NS_DEFINE_IID(kIWindowIID, NS_IDOMWINDOW_IID);
NS_DEF_PTR(nsIDOMMsgAppCore);
NS_DEF_PTR(nsIDOMWindow);
/***********************************************************************/
//
// MsgAppCore Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetMsgAppCoreProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMMsgAppCore *a = (nsIDOMMsgAppCore*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
/***********************************************************************/
//
// MsgAppCore Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetMsgAppCoreProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMMsgAppCore *a = (nsIDOMMsgAppCore*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
//
// MsgAppCore finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeMsgAppCore(JSContext *cx, JSObject *obj)
{
nsJSUtils::nsGenericFinalize(cx, obj);
}
//
// MsgAppCore enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateMsgAppCore(JSContext *cx, JSObject *obj)
{
return nsJSUtils::nsGenericEnumerate(cx, obj);
}
//
// MsgAppCore resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveMsgAppCore(JSContext *cx, JSObject *obj, jsval id)
{
return nsJSUtils::nsGenericResolve(cx, obj, id);
}
//
// Native method GetNewMail
//
PR_STATIC_CALLBACK(JSBool)
MsgAppCoreGetNewMail(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMMsgAppCore *nativeThis = (nsIDOMMsgAppCore*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->GetNewMail()) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function GetNewMail requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method Open3PaneWindow
//
PR_STATIC_CALLBACK(JSBool)
MsgAppCoreOpen3PaneWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMMsgAppCore *nativeThis = (nsIDOMMsgAppCore*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->Open3PaneWindow()) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function Open3PaneWindow requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method SetWindow
//
PR_STATIC_CALLBACK(JSBool)
MsgAppCoreSetWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMMsgAppCore *nativeThis = (nsIDOMMsgAppCore*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMWindowPtr b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0,
kIWindowIID,
"Window",
cx,
argv[0])) {
return JS_FALSE;
}
if (NS_OK != nativeThis->SetWindow(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function SetWindow requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method OpenURL
//
PR_STATIC_CALLBACK(JSBool)
MsgAppCoreOpenURL(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMMsgAppCore *nativeThis = (nsIDOMMsgAppCore*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
char * url = b0.ToNewCString();
if (NS_OK != nativeThis->OpenURL(url)) {
return JS_FALSE;
}
delete [] url;
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function OpenURL requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for MsgAppCore
//
JSClass MsgAppCoreClass = {
"MsgAppCore",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetMsgAppCoreProperty,
SetMsgAppCoreProperty,
EnumerateMsgAppCore,
ResolveMsgAppCore,
JS_ConvertStub,
FinalizeMsgAppCore
};
//
// MsgAppCore class properties
//
static JSPropertySpec MsgAppCoreProperties[] =
{
{0}
};
//
// MsgAppCore class methods
//
static JSFunctionSpec MsgAppCoreMethods[] =
{
{"GetNewMail", MsgAppCoreGetNewMail, 0},
{"Open3PaneWindow", MsgAppCoreOpen3PaneWindow, 0},
{"SetWindow", MsgAppCoreSetWindow, 1},
{"OpenURL", MsgAppCoreOpenURL, 1},
{0}
};
//
// MsgAppCore constructor
//
PR_STATIC_CALLBACK(JSBool)
MsgAppCore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsresult result;
nsIID classID;
nsIScriptContext* context = (nsIScriptContext*)JS_GetContextPrivate(cx);
nsIScriptNameSpaceManager* manager;
nsIDOMMsgAppCore *nativeThis;
nsIScriptObjectOwner *owner = nsnull;
static NS_DEFINE_IID(kIDOMMsgAppCoreIID, NS_IDOMMSGAPPCORE_IID);
result = context->GetNameSpaceManager(&manager);
if (NS_OK != result) {
return JS_FALSE;
}
result = manager->LookupName("MsgAppCore", PR_TRUE, classID);
NS_RELEASE(manager);
if (NS_OK != result) {
return JS_FALSE;
}
result = nsRepository::CreateInstance(classID,
nsnull,
kIDOMMsgAppCoreIID,
(void **)&nativeThis);
if (NS_OK != result) {
return JS_FALSE;
}
// XXX We should be calling Init() on the instance
result = nativeThis->QueryInterface(kIScriptObjectOwnerIID, (void **)&owner);
if (NS_OK != result) {
NS_RELEASE(nativeThis);
return JS_FALSE;
}
owner->SetScriptObject((void *)obj);
JS_SetPrivate(cx, obj, nativeThis);
NS_RELEASE(owner);
return JS_TRUE;
}
//
// MsgAppCore class initialization
//
nsresult NS_InitMsgAppCoreClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "MsgAppCore", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
if (NS_OK != NS_InitBaseAppCoreClass(aContext, (void **)&parent_proto)) {
return NS_ERROR_FAILURE;
}
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&MsgAppCoreClass, // JSClass
MsgAppCore, // JSNative ctor
0, // ctor args
MsgAppCoreProperties, // proto props
MsgAppCoreMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new MsgAppCore JavaScript object
//
extern "C" nsresult NS_NewScriptMsgAppCore(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptMsgAppCore");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMMsgAppCore *aMsgAppCore;
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitMsgAppCoreClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = aSupports->QueryInterface(kIMsgAppCoreIID, (void **)&aMsgAppCore);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &MsgAppCoreClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aMsgAppCore);
}
else {
NS_RELEASE(aMsgAppCore);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

Просмотреть файл

Просмотреть файл

@ -99,6 +99,7 @@ nsMessengerBootstrap::Initialize()
{
nsresult rv;
printf("Messenger has been bootstrapped!\n");
nsIScriptNameSetRegistry* registry;
rv = nsServiceManager::GetService(kCScriptNameSetRegistryCID,
nsIScriptNameSetRegistry::GetIID(),

Просмотреть файл

@ -26,6 +26,12 @@
#include "nsIScriptContext.h"
#include "nsIScriptNameSpaceManager.h"
#include "nsIScriptExternalNameSet.h"
#include "nsMessenger.h"
/* hack the AppCore stuff here */
#include "nsIDOMMsgAppCore.h"
#include "nsMsgAppCore.h"
static NS_DEFINE_IID(kIScriptExternalNameSetIID, NS_ISCRIPTEXTERNALNAMESET_IID);
@ -52,6 +58,10 @@ nsMessengerNameSet::InitializeClasses(nsIScriptContext* aScriptContext)
JSContext *cx = (JSContext*)aScriptContext->GetNativeContext();
printf("nsMessengerNameSet::InitializeClasses() Initializing base classes\n");
/* initialize the AppCore */
NS_InitMsgAppCoreClass(aScriptContext, nsnull);
#ifdef XPIDL_JS_STUBS
nsIMessenger::InitJSClass(cx);
#endif
@ -59,6 +69,8 @@ nsMessengerNameSet::InitializeClasses(nsIScriptContext* aScriptContext)
return rv;
}
static NS_DEFINE_CID(kCMessengerCID, NS_MESSENGER_CID);
static NS_DEFINE_CID(kCMsgAppCoreCID, NS_MSGAPPCORE_CID);
NS_IMETHODIMP
nsMessengerNameSet::AddNameSet(nsIScriptContext *aScriptContext)
@ -68,12 +80,19 @@ nsMessengerNameSet::AddNameSet(nsIScriptContext *aScriptContext)
printf("nsMessengerNameSet::AddNameSet() Registering Messenger in the JS namespace\n");
rv = aScriptContext->GetNameSpaceManager(&manager);
if (NS_SUCCEEDED(rv))
rv = manager->RegisterGlobalName("Messenger",
// put the CID here, not IID
nsIMessenger::GetIID(),
kCMessengerCID,
PR_TRUE);
/* register the appcore here too */
if (NS_SUCCEEDED(rv))
rv = manager->RegisterGlobalName("MsgAppCore",
kCMsgAppCoreCID,
PR_TRUE);
return rv;
}

Просмотреть файл

@ -0,0 +1,333 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsIDOMMsgAppCore.h"
#include "nsMsgAppCore.h"
#include "nsIScriptObjectOwner.h"
#include "nsIDOMBaseAppCore.h"
#include "nsJSMsgAppCore.h"
/* rhp - for access to webshell */
#include "nsCOMPtr.h"
#include "nsIDOMWindow.h"
#include "nsIWebShell.h"
#include "nsIWebShellWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsAppShellCIDs.h"
#include "nsIAppShellService.h"
#include "nsIServiceManager.h"
#include "nsIURL.h"
#include "nsIDOMDocument.h"
#include "nsIDocument.h"
#include "nsNNTPProtocol.h" // mscott - hopefully this dependency should only be temporary...
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
NS_BEGIN_EXTERN_C
nsresult NS_MailNewsLoadUrl(const nsString& urlString, nsISupports * aConsumer);
NS_END_EXTERN_C
// we need this because of an egcs 1.0 (and possibly gcc) compiler bug
// that doesn't allow you to call ::nsISupports::GetIID() inside of a class
// that multiply inherits from nsISupports
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
class nsMsgAppCore : public nsIDOMMsgAppCore,
public nsIScriptObjectOwner
{
public:
nsMsgAppCore();
virtual ~nsMsgAppCore();
NS_DECL_ISUPPORTS
NS_DECL_IDOMBASEAPPCORE
// nsIScriptObjectOwner
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void* aScriptObject);
// nsIMsgAppCore
NS_IMETHOD Open3PaneWindow();
NS_IMETHOD GetNewMail();
NS_IMETHOD SetWindow(nsIDOMWindow* aWin);
NS_IMETHOD OpenURL(char * url);
private:
nsString mId;
void *mScriptObject;
/* rhp - need this to drive message display */
nsIDOMWindow *mWindow;
nsIWebShell *mWebShell;
};
nsresult nsMsgAppCore::SetDocumentCharset(class nsString const & aCharset)
{
nsresult res = NS_OK;
if (nsnull != mWindow)
{
nsIDOMDocument* domDoc;
res = mWindow->GetDocument(&domDoc);
if (NS_SUCCEEDED(res) && nsnull != domDoc)
{
nsIDocument * doc;
res = domDoc->QueryInterface(nsIDocument::GetIID(), (void**)&doc);
if (NS_SUCCEEDED(res) && nsnull != doc)
{
nsString *aNewCharset = new nsString(aCharset);
if (nsnull != aNewCharset)
{
doc->SetDocumentCharacterSet(aNewCharset);
}
NS_RELEASE(doc);
}
NS_RELEASE(domDoc);
}
}
return res;
}
//
// nsMsgAppCore
//
nsMsgAppCore::nsMsgAppCore()
{
NS_INIT_REFCNT();
mScriptObject = nsnull;
mWebShell = nsnull;
mWindow = nsnull;
}
nsMsgAppCore::~nsMsgAppCore()
{
}
//
// nsISupports
//
NS_IMPL_ADDREF(nsMsgAppCore);
NS_IMPL_RELEASE(nsMsgAppCore);
NS_IMETHODIMP
nsMsgAppCore::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL) {
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if ( aIID.Equals(kIScriptObjectOwnerIID)) {
*aInstancePtr = (void*) ((nsIScriptObjectOwner*)this);
AddRef();
return NS_OK;
}
if ( aIID.Equals(nsIDOMBaseAppCore::GetIID())) {
*aInstancePtr = (void*) ((nsIDOMBaseAppCore*)this);
AddRef();
return NS_OK;
}
else if ( aIID.Equals(nsIDOMMsgAppCore::GetIID()) ) {
*aInstancePtr = (void*) (nsIDOMMsgAppCore*)this;
AddRef();
return NS_OK;
}
else if ( aIID.Equals(kISupportsIID) ) {
*aInstancePtr = (void*)(nsISupports*) (nsIScriptObjectOwner *) this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
//
// nsIScriptObjectOwner
//
nsresult
nsMsgAppCore::GetScriptObject(nsIScriptContext *aContext, void **aScriptObject)
{
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
nsresult res = NS_OK;
if (nsnull == mScriptObject)
{
res = NS_NewScriptMsgAppCore(aContext,
(nsISupports *)(nsIDOMMsgAppCore*)this,
nsnull,
&mScriptObject);
}
*aScriptObject = mScriptObject;
return res;
}
nsresult
nsMsgAppCore::SetScriptObject(void* aScriptObject)
{
return NS_OK;
}
//
// nsIDOMBaseAppCore
//
nsresult
nsMsgAppCore::Init(const nsString& aId)
{
printf("Init\n");
mId = aId;
return NS_OK;
}
nsresult
nsMsgAppCore::GetId(nsString& aId)
{
printf("GetID\n");
aId = mId;
return NS_OK;
}
//
// nsIMsgAppCore
//
NS_IMETHODIMP
nsMsgAppCore::Open3PaneWindow()
{
static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
nsIAppShellService* appShell;
char * urlstr=nsnull;
nsresult rv;
nsString controllerCID;
urlstr = "resource:/res/samples/messenger.html";
rv = nsServiceManager::GetService(kAppShellServiceCID,
nsIAppShellService::GetIID(),
(nsISupports**)&appShell);
nsIURL* url;
nsIWidget* newWindow;
rv = NS_NewURL(&url, urlstr);
if (NS_FAILED(rv)) {
goto done;
}
controllerCID = "6B75BB61-BD41-11d2-9D31-00805F8ADDDE";
appShell->CreateTopLevelWindow(nsnull, // parent
url,
controllerCID,
newWindow, // result widget
nsnull, // observer
nsnull, // callbacks
200, // width
200); // height
done:
NS_RELEASE(url);
if (nsnull != appShell) {
nsServiceManager::ReleaseService(kAppShellServiceCID, appShell);
}
return NS_OK;
}
nsresult
nsMsgAppCore::GetNewMail()
{
printf("nsMsgAppCore::GetNewMail()\n");
return NS_OK;
}
extern "C"
nsresult
NS_NewMsgAppCore(nsIDOMMsgAppCore **aResult)
{
if (!aResult) return NS_ERROR_NULL_POINTER;
nsMsgAppCore *appcore = new nsMsgAppCore();
if (appcore) {
return appcore->QueryInterface(nsIDOMMsgAppCore::GetIID(),
(void **)aResult);
}
return NS_ERROR_NOT_INITIALIZED;
}
NS_IMETHODIMP
nsMsgAppCore::SetWindow(nsIDOMWindow* aWin)
{
nsAutoString webShellName("browser.webwindow");
mWindow = aWin;
NS_ADDREF(aWin);
/* rhp - Needed to access the webshell to drive message display */
printf("nsMsgAppCore::SetWindow(): Getting the webShell of interest...\n");
nsCOMPtr<nsIScriptGlobalObject> globalObj( do_QueryInterface(aWin) );
if (!globalObj)
{
return NS_ERROR_FAILURE;
}
nsIWebShell *webShell = nsnull;
nsIWebShell *rootWebShell = nsnull;
globalObj->GetWebShell(&webShell);
if (nsnull == webShell)
{
return NS_ERROR_FAILURE;
}
webShell->GetRootWebShell(rootWebShell);
if (nsnull != rootWebShell)
{
rootWebShell->FindChildWithName(webShellName, mWebShell);
#ifdef NS_DEBUG
if (nsnull != mWebShell)
printf("nsMsgAppCore::SetWindow(): Got the webShell %s.\n", webShellName.ToNewCString());
else
printf("nsMsgAppCore::SetWindow(): Failed to find webshell %s.\n", webShellName.ToNewCString());
#endif
NS_RELEASE(rootWebShell);
}
NS_RELEASE(webShell);
return NS_OK;
}
NS_IMETHODIMP
nsMsgAppCore::OpenURL(char * url)
{
// here's where we call mscott's LoadURL...
// mscott: right now, this only works for news urls!!!!
NS_MailNewsLoadUrl(url, mWebShell);
return NS_OK;
}
// to load the webshell!
// mWebShell->LoadURL(nsAutoString("http://www.netscape.com"),
// nsnull, PR_TRUE, nsURLReload, 0);

Просмотреть файл

@ -0,0 +1,37 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef __nsMsgAppCore_h
#define __nsMsgAppCore_h
#include "nsCom.h"
#include "nsIDOMMsgAppCore.h"
#define NS_MSGAPPCORE_CID \
{ /* 3f181950-c14d-11d2-b7f2-00805f05ffa5 */ \
0x3f181950, 0xc14d, 0x11d2, \
{0xb7, 0xf2, 0x0, 0x80, 0x5f, 0x05, 0xff, 0xa5}}
NS_BEGIN_EXTERN_C
nsresult
NS_NewMsgAppCore(nsIDOMMsgAppCore **);
NS_END_EXTERN_C
#endif