зеркало из https://github.com/mozilla/gecko-dev.git
The compose.dll has been merged into msgcompose.dll in order to have the auto appcore registration working
this file has been moved to mailnews/compose/src
This commit is contained in:
Родитель
1958dfb22c
Коммит
335ff417db
|
@ -1,416 +0,0 @@
|
|||
/* -*- 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 "nsIDOMComposeAppCore.h"
|
||||
#include "nsComposeAppCore.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIDOMBaseAppCore.h"
|
||||
#include "nsJSComposeAppCore.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIScriptContextOwner.h"
|
||||
|
||||
/* rhp - for access to webshell */
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIWebShellWindow.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsAppShellCIDs.h"
|
||||
#include "nsIAppShellService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIURL.h"
|
||||
|
||||
#include "nsMsgCompCID.h"
|
||||
#include "nsIMsgCompose.h"
|
||||
#include "nsIMsgCompFields.h"
|
||||
#include "nsIMsgSend.h"
|
||||
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
static NS_DEFINE_IID(kIDocumentIID, nsIDocument::GetIID());
|
||||
static NS_DEFINE_IID(kIMsgComposeIID, NS_IMSGCOMPOSE_IID);
|
||||
static NS_DEFINE_CID(kMsgComposeCID, NS_MSGCOMPOSE_CID);
|
||||
|
||||
static NS_DEFINE_IID(kIMsgCompFieldsIID, NS_IMSGCOMPFIELDS_IID);
|
||||
static NS_DEFINE_CID(kMsgCompFieldsCID, NS_MSGCOMPFIELDS_CID);
|
||||
|
||||
static NS_DEFINE_IID(kIMsgSendIID, NS_IMSGSEND_IID);
|
||||
static NS_DEFINE_CID(kMsgSendCID, NS_MSGSEND_CID);
|
||||
|
||||
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 nsComposeAppCore : public nsIDOMComposeAppCore,
|
||||
public nsIScriptObjectOwner
|
||||
{
|
||||
|
||||
public:
|
||||
nsComposeAppCore();
|
||||
virtual ~nsComposeAppCore();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_IDOMBASEAPPCORE
|
||||
|
||||
// nsIScriptObjectOwner
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
// nsIComposeAppCore
|
||||
NS_IMETHOD CompleteCallback(const nsString& aScript);
|
||||
NS_IMETHOD SetWindow(nsIDOMWindow* aWin);
|
||||
NS_IMETHOD NewMessage(const nsString& aUrl);
|
||||
NS_IMETHOD SendMessage(const nsString& aAddrFrom, const nsString& aSmtp, const nsString& aAddrTo,
|
||||
const nsString& aAddrCc, const nsString& aAddrBcc, const nsString& aSubject, const nsString& aMsg);
|
||||
|
||||
protected:
|
||||
|
||||
nsIScriptContext * GetScriptContext(nsIDOMWindow * aWin);
|
||||
|
||||
nsString mId;
|
||||
nsString mScript;
|
||||
void *mScriptObject;
|
||||
nsIScriptContext *mScriptContext;
|
||||
|
||||
/* rhp - need this to drive message display */
|
||||
nsIDOMWindow *mWindow;
|
||||
nsIWebShell *mWebShell;
|
||||
};
|
||||
|
||||
//
|
||||
// nsComposeAppCore
|
||||
//
|
||||
nsComposeAppCore::nsComposeAppCore()
|
||||
{
|
||||
mScriptObject = nsnull;
|
||||
mWebShell = nsnull;
|
||||
mScriptObject = nsnull;
|
||||
mScriptContext = nsnull;
|
||||
mWindow = nsnull;
|
||||
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsComposeAppCore::~nsComposeAppCore()
|
||||
{
|
||||
NS_IF_RELEASE(mScriptContext);
|
||||
NS_IF_RELEASE(mWindow);
|
||||
}
|
||||
|
||||
nsresult nsComposeAppCore::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(kIDocumentIID,(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;
|
||||
}
|
||||
|
||||
nsIScriptContext *
|
||||
nsComposeAppCore::GetScriptContext(nsIDOMWindow * aWin)
|
||||
{
|
||||
nsIScriptContext * scriptContext = nsnull;
|
||||
if (nsnull != aWin) {
|
||||
nsIDOMDocument * domDoc;
|
||||
aWin->GetDocument(&domDoc);
|
||||
if (nsnull != domDoc) {
|
||||
nsIDocument * doc;
|
||||
if (NS_OK == domDoc->QueryInterface(kIDocumentIID,(void**)&doc)) {
|
||||
nsIScriptContextOwner * owner = doc->GetScriptContextOwner();
|
||||
if (nsnull != owner) {
|
||||
owner->GetScriptContext(&scriptContext);
|
||||
NS_RELEASE(owner);
|
||||
}
|
||||
NS_RELEASE(doc);
|
||||
}
|
||||
NS_RELEASE(domDoc);
|
||||
}
|
||||
}
|
||||
return scriptContext;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// nsISupports
|
||||
//
|
||||
NS_IMPL_ADDREF(nsComposeAppCore);
|
||||
NS_IMPL_RELEASE(nsComposeAppCore);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComposeAppCore::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(nsIDOMComposeAppCore::GetIID()) ) {
|
||||
*aInstancePtr = (void*) (nsIDOMComposeAppCore*)this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
else if ( aIID.Equals(kISupportsIID) ) {
|
||||
*aInstancePtr = (void*)(nsISupports*) (nsIScriptObjectOwner *) this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
//
|
||||
// nsIScriptObjectOwner
|
||||
//
|
||||
nsresult
|
||||
nsComposeAppCore::GetScriptObject(nsIScriptContext *aContext, void **aScriptObject)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
|
||||
nsresult res = NS_OK;
|
||||
if (nsnull == mScriptObject)
|
||||
{
|
||||
res = NS_NewScriptComposeAppCore(aContext,
|
||||
(nsISupports *)(nsIDOMComposeAppCore*)this,
|
||||
nsnull,
|
||||
&mScriptObject);
|
||||
}
|
||||
|
||||
*aScriptObject = mScriptObject;
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComposeAppCore::SetScriptObject(void* aScriptObject)
|
||||
{
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//
|
||||
// nsIDOMBaseAppCore
|
||||
//
|
||||
nsresult
|
||||
nsComposeAppCore::Init(const nsString& aId)
|
||||
{
|
||||
printf("Init\n");
|
||||
mId = aId;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsComposeAppCore::GetId(nsString& aId)
|
||||
{
|
||||
printf("GetID\n");
|
||||
aId = mId;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//
|
||||
// nsIComposeAppCore
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
nsComposeAppCore::SetWindow(nsIDOMWindow* aWin)
|
||||
{
|
||||
mWindow = aWin;
|
||||
NS_ADDREF(mWindow);
|
||||
mScriptContext = GetScriptContext(aWin);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComposeAppCore::CompleteCallback(const nsString& aScript)
|
||||
{
|
||||
mScript = aScript;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComposeAppCore::NewMessage(const nsString& aUrl)
|
||||
{
|
||||
static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
|
||||
|
||||
char * urlstr=nsnull;
|
||||
nsresult rv;
|
||||
nsString controllerCID;
|
||||
|
||||
nsIAppShellService* appShell;
|
||||
rv = nsServiceManager::GetService(kAppShellServiceCID,
|
||||
nsIAppShellService::GetIID(),
|
||||
(nsISupports**)&appShell);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIURL* url;
|
||||
nsIWidget* newWindow;
|
||||
|
||||
rv = NS_NewURL(&url, aUrl);
|
||||
if (NS_FAILED(rv)) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
controllerCID = "6B75BB61-BD41-11d2-9D31-00805F8ADDDF";
|
||||
appShell->CreateTopLevelWindow(nsnull, // parent
|
||||
url,
|
||||
controllerCID,
|
||||
newWindow, // result widget
|
||||
nsnull, // observer
|
||||
nsnull, // callbacks
|
||||
615, // width
|
||||
650); // height
|
||||
done:
|
||||
NS_RELEASE(url);
|
||||
(void)nsServiceManager::ReleaseService(kAppShellServiceCID, appShell);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsComposeAppCore::SendMessage(const nsString& aAddrFrom, const nsString& aSmtp, const nsString& aAddrTo,
|
||||
const nsString& aAddrCc, const nsString& aAddrBcc, const nsString& aSubject, const nsString& aMsg)
|
||||
{
|
||||
if (nsnull == mScriptContext) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
printf("----------------------------\n");
|
||||
printf("-- Sending Mail Message\n");
|
||||
printf("----------------------------\n");
|
||||
printf("From: %s Smtp:%s\n", aAddrFrom.ToNewCString(), aSmtp.ToNewCString());
|
||||
printf("To: %s Cc: %s Bcc: %s\n", aAddrTo.ToNewCString(), aAddrCc.ToNewCString(), aAddrBcc.ToNewCString());
|
||||
printf("Subject: %s \nMsg: %s\n", aSubject.ToNewCString(), aMsg.ToNewCString());
|
||||
printf("----------------------------\n");
|
||||
|
||||
{
|
||||
// nsIMsgCompose *pMsgCompose;
|
||||
nsIMsgCompFields *pMsgCompFields;
|
||||
nsIMsgSend *pMsgSend;
|
||||
nsresult res;
|
||||
|
||||
// register our dll
|
||||
const char* compose_dll = "msgcompose.dll";
|
||||
nsComponentManager::RegisterComponent(kMsgComposeCID,
|
||||
"Netscape Mail Composer AppCore",
|
||||
NULL,
|
||||
compose_dll,
|
||||
PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponent(kMsgCompFieldsCID,
|
||||
"Netscape Mail Composer Fields",
|
||||
NULL,
|
||||
compose_dll,
|
||||
PR_FALSE, PR_FALSE);
|
||||
nsComponentManager::RegisterComponent(kMsgSendCID,
|
||||
"Netscape Mail Sender",
|
||||
NULL,
|
||||
compose_dll,
|
||||
PR_FALSE, PR_FALSE);
|
||||
|
||||
res = nsComponentManager::CreateInstance(kMsgSendCID,
|
||||
NULL,
|
||||
kIMsgSendIID,
|
||||
(void **) &pMsgSend);
|
||||
|
||||
if (res == NS_OK && pMsgSend) {
|
||||
printf("We succesfully obtained a nsIMsgSend interface....\n");
|
||||
/* pMsgSend->Test(); */
|
||||
|
||||
res = nsComponentManager::CreateInstance(kMsgCompFieldsCID,
|
||||
NULL,
|
||||
kIMsgCompFieldsIID,
|
||||
(void **) &pMsgCompFields);
|
||||
if (res == NS_OK && pMsgCompFields) {
|
||||
pMsgCompFields->SetFrom(aAddrFrom.ToNewCString(), NULL);
|
||||
pMsgCompFields->SetTo(aAddrTo.ToNewCString(), NULL);
|
||||
pMsgCompFields->SetCc(aAddrCc.ToNewCString(), NULL);
|
||||
pMsgCompFields->SetBcc(aAddrBcc.ToNewCString(), NULL);
|
||||
pMsgCompFields->SetSubject(aSubject.ToNewCString(), NULL);
|
||||
pMsgCompFields->SetBody(aMsg.ToNewCString(), NULL);
|
||||
|
||||
pMsgSend->SendMessage(pMsgCompFields, aSmtp.ToNewCString());
|
||||
|
||||
pMsgCompFields->Release();
|
||||
}
|
||||
|
||||
printf("Releasing the interface now...\n");
|
||||
pMsgSend->Release();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (nsnull != mScriptContext) {
|
||||
const char* url = "";
|
||||
PRBool isUndefined = PR_FALSE;
|
||||
nsString rVal;
|
||||
mScriptContext->EvaluateString(mScript, url, 0, rVal, &isUndefined);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
nsresult
|
||||
NS_NewComposeAppCore(nsIDOMComposeAppCore **aResult)
|
||||
{
|
||||
if (!aResult) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsComposeAppCore *appcore = new nsComposeAppCore();
|
||||
if (appcore) {
|
||||
return appcore->QueryInterface(nsIDOMComposeAppCore::GetIID(),
|
||||
(void **)aResult);
|
||||
|
||||
}
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
/* -*- 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 __nsComposeAppCore_h
|
||||
#define __nsComposeAppCore_h
|
||||
|
||||
#include "nsCom.h"
|
||||
#include "nsIDOMComposeAppCore.h"
|
||||
|
||||
#define NS_COMPOSEAPPCORE_CID \
|
||||
{ /* 4E932BB0-CAA8-11d2-A6F2-0060B0EB39B5 */ \
|
||||
0x4e932bb0, 0xcaa8, 0x11d2, \
|
||||
{0xa6, 0xf2, 0x0, 0x60, 0xb0, 0xeb, 0x39, 0xb5}}
|
||||
|
||||
|
||||
NS_BEGIN_EXTERN_C
|
||||
|
||||
nsresult
|
||||
NS_NewComposeAppCore(nsIDOMComposeAppCore **);
|
||||
|
||||
NS_END_EXTERN_C
|
||||
|
||||
#endif //__nsComposeAppCore_h
|
|
@ -1,484 +0,0 @@
|
|||
/* -*- 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 "nsIDOMComposeAppCore.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIScriptNameSpaceManager.h"
|
||||
#include "nsIComponentManager.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(kIComposeAppCoreIID, NS_IDOMCOMPOSEAPPCORE_IID);
|
||||
static NS_DEFINE_IID(kIWindowIID, NS_IDOMWINDOW_IID);
|
||||
|
||||
NS_DEF_PTR(nsIDOMComposeAppCore);
|
||||
NS_DEF_PTR(nsIDOMWindow);
|
||||
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
// ComposeAppCore Properties Getter
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
GetComposeAppCoreProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
nsIDOMComposeAppCore *a = (nsIDOMComposeAppCore*)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;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
// ComposeAppCore Properties Setter
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
SetComposeAppCoreProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
nsIDOMComposeAppCore *a = (nsIDOMComposeAppCore*)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;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// ComposeAppCore finalizer
|
||||
//
|
||||
PR_STATIC_CALLBACK(void)
|
||||
FinalizeComposeAppCore(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
nsJSUtils::nsGenericFinalize(cx, obj);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// ComposeAppCore enumerate
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
EnumerateComposeAppCore(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
return nsJSUtils::nsGenericEnumerate(cx, obj);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// ComposeAppCore resolve
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
ResolveComposeAppCore(JSContext *cx, JSObject *obj, jsval id)
|
||||
{
|
||||
return nsJSUtils::nsGenericResolve(cx, obj, id);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method SetWindow
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
ComposeAppCoreSetWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMComposeAppCore *nativeThis = (nsIDOMComposeAppCore*)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 CompleteCallback
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
ComposeAppCoreCompleteCallback(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMComposeAppCore *nativeThis = (nsIDOMComposeAppCore*)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]);
|
||||
|
||||
if (NS_OK != nativeThis->CompleteCallback(b0)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*rval = JSVAL_VOID;
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Function CompleteCallback requires 1 parameter");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method NewMessage
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
ComposeAppCoreNewMessage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMComposeAppCore *nativeThis = (nsIDOMComposeAppCore*)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]);
|
||||
|
||||
if (NS_OK != nativeThis->NewMessage(b0)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*rval = JSVAL_VOID;
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Function NewMessage requires 1 parameter");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Native method SendMessage
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
ComposeAppCoreSendMessage(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsIDOMComposeAppCore *nativeThis = (nsIDOMComposeAppCore*)JS_GetPrivate(cx, obj);
|
||||
JSBool rBool = JS_FALSE;
|
||||
nsAutoString b0;
|
||||
nsAutoString b1;
|
||||
nsAutoString b2;
|
||||
nsAutoString b3;
|
||||
nsAutoString b4;
|
||||
nsAutoString b5;
|
||||
nsAutoString b6;
|
||||
|
||||
*rval = JSVAL_NULL;
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == nativeThis) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (argc >= 7) {
|
||||
|
||||
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
|
||||
nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]);
|
||||
nsJSUtils::nsConvertJSValToString(b2, cx, argv[2]);
|
||||
nsJSUtils::nsConvertJSValToString(b3, cx, argv[3]);
|
||||
nsJSUtils::nsConvertJSValToString(b4, cx, argv[4]);
|
||||
nsJSUtils::nsConvertJSValToString(b5, cx, argv[5]);
|
||||
nsJSUtils::nsConvertJSValToString(b6, cx, argv[6]);
|
||||
|
||||
if (NS_OK != nativeThis->SendMessage(b0, b1, b2, b3, b4, b5, b6)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
*rval = JSVAL_VOID;
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Function SendMessage requires 6 parameters");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
// class for ComposeAppCore
|
||||
//
|
||||
JSClass ComposeAppCoreClass = {
|
||||
"ComposeAppCore",
|
||||
JSCLASS_HAS_PRIVATE,
|
||||
JS_PropertyStub,
|
||||
JS_PropertyStub,
|
||||
GetComposeAppCoreProperty,
|
||||
SetComposeAppCoreProperty,
|
||||
EnumerateComposeAppCore,
|
||||
ResolveComposeAppCore,
|
||||
JS_ConvertStub,
|
||||
FinalizeComposeAppCore
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// ComposeAppCore class properties
|
||||
//
|
||||
static JSPropertySpec ComposeAppCoreProperties[] =
|
||||
{
|
||||
{0}
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// ComposeAppCore class methods
|
||||
//
|
||||
static JSFunctionSpec ComposeAppCoreMethods[] =
|
||||
{
|
||||
{"SetWindow", ComposeAppCoreSetWindow, 1},
|
||||
{"CompleteCallback", ComposeAppCoreCompleteCallback, 1},
|
||||
{"NewMessage", ComposeAppCoreNewMessage, 1},
|
||||
{"SendMessage", ComposeAppCoreSendMessage, 7},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// ComposeAppCore constructor
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
ComposeAppCore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
nsresult result;
|
||||
nsIID classID;
|
||||
nsIScriptContext* context = (nsIScriptContext*)JS_GetContextPrivate(cx);
|
||||
nsIScriptNameSpaceManager* manager;
|
||||
nsIDOMComposeAppCore *nativeThis;
|
||||
nsIScriptObjectOwner *owner = nsnull;
|
||||
|
||||
static NS_DEFINE_IID(kIDOMComposeAppCoreIID, NS_IDOMCOMPOSEAPPCORE_IID);
|
||||
|
||||
result = context->GetNameSpaceManager(&manager);
|
||||
if (NS_OK != result) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
result = manager->LookupName("ComposeAppCore", PR_TRUE, classID);
|
||||
NS_RELEASE(manager);
|
||||
if (NS_OK != result) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
result = nsComponentManager::CreateInstance(classID,
|
||||
nsnull,
|
||||
kIDOMComposeAppCoreIID,
|
||||
(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;
|
||||
}
|
||||
|
||||
//
|
||||
// ComposeAppCore class initialization
|
||||
//
|
||||
nsresult NS_InitComposeAppCoreClass(nsIScriptContext *aContext, void **aPrototype, JSObject * aParentProto)
|
||||
{
|
||||
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
|
||||
JSObject *proto = nsnull;
|
||||
JSObject *constructor = nsnull;
|
||||
JSObject *parent_proto = aParentProto;
|
||||
JSObject *global = JS_GetGlobalObject(jscontext);
|
||||
jsval vp;
|
||||
|
||||
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "ComposeAppCore", &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 0
|
||||
if (NS_OK != NS_InitBaseAppCoreClass(aContext, (void **)&parent_proto)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
#endif
|
||||
|
||||
proto = JS_InitClass(jscontext, // context
|
||||
global, // global object
|
||||
parent_proto, // parent proto
|
||||
&ComposeAppCoreClass, // JSClass
|
||||
ComposeAppCore, // JSNative ctor
|
||||
0, // ctor args
|
||||
ComposeAppCoreProperties, // proto props
|
||||
ComposeAppCoreMethods, // 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 ComposeAppCore JavaScript object
|
||||
//
|
||||
extern "C" NS_DOM nsresult NS_NewScriptComposeAppCore(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptComposeAppCore");
|
||||
JSObject *proto;
|
||||
JSObject *parent;
|
||||
nsIScriptObjectOwner *owner;
|
||||
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
|
||||
nsresult result = NS_OK;
|
||||
nsIDOMComposeAppCore *aComposeAppCore;
|
||||
|
||||
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_InitComposeAppCoreClass(aContext, (void **)&proto, parent)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
result = aSupports->QueryInterface(kIComposeAppCoreIID, (void **)&aComposeAppCore);
|
||||
if (NS_OK != result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// create a js object for this class
|
||||
*aReturn = JS_NewObject(jscontext, &ComposeAppCoreClass, proto, parent);
|
||||
if (nsnull != *aReturn) {
|
||||
// connect the native object to the js object
|
||||
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aComposeAppCore);
|
||||
}
|
||||
else {
|
||||
NS_RELEASE(aComposeAppCore);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
/* -*- 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 __nsJSComposeAppCore_h
|
||||
#define __nsJSComposeAppCore_h
|
||||
|
||||
extern "C" NS_DOM
|
||||
nsresult
|
||||
NS_NewScriptComposeAppCore(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
|
||||
|
||||
|
||||
#endif //__nsJSComposeAppCore_h
|
Загрузка…
Ссылка в новой задаче