Compare commits
12 Commits
MAPI_NEW_D
...
XPCOM_M4_B
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0b51d38a19 | ||
|
|
21a713a61f | ||
|
|
9af426532a | ||
|
|
02b0fbe8be | ||
|
|
d62a400aed | ||
|
|
3a3b24444a | ||
|
|
1588e1c4de | ||
|
|
004001381f | ||
|
|
0c8e8c2101 | ||
|
|
eb00ee9f54 | ||
|
|
4ea4c144f3 | ||
|
|
8a7c8aa159 |
@@ -1,70 +0,0 @@
|
||||
/* ***** 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):
|
||||
* Srilatha Moturi <srilatha@netscape.com>
|
||||
*
|
||||
* 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 nsIDOMWindow;
|
||||
|
||||
/**
|
||||
* This interface provides support for registering Mozilla as the default
|
||||
* Mail Client. This interface can also be used to get/set the user preference
|
||||
* for the default Mail Client.
|
||||
*
|
||||
*/
|
||||
[scriptable, uuid(c5be14ba-4e0a-4eec-a1b8-04363761d63c)]
|
||||
interface nsIMapiRegistry: nsISupports {
|
||||
|
||||
/** This is set to TRUE if Mozilla is the default Application
|
||||
*/
|
||||
attribute boolean isDefaultMailClient;
|
||||
|
||||
/** This is set TRUE only once per session.
|
||||
*/
|
||||
readonly attribute boolean showDialog;
|
||||
|
||||
/** This will bring the dialog asking the user if he/she wants to set
|
||||
* Mozilla as default Mail Client.
|
||||
* Call this only if Mozilla is not the default Mail client
|
||||
*/
|
||||
void showMailIntegrationDialog(in nsIDOMWindow parentWindow);
|
||||
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define NS_IMAPIREGISTRY_CONTRACTID "@mozilla.org/mapiregistry;1"
|
||||
#define NS_IMAPIREGISTRY_CLASSNAME "Mozilla MAPI Registry"
|
||||
%}
|
||||
@@ -1,27 +0,0 @@
|
||||
#!nmake
|
||||
#
|
||||
# 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): Srilatha Moturi <srilatha@netscape.com>
|
||||
# Krishna Mohan Khandrika <kkhandrika@netscape.com>
|
||||
|
||||
DEPTH=..\..
|
||||
|
||||
DIRS=mapihook resources mapiDll
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
@@ -1,54 +0,0 @@
|
||||
; ***** 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.
|
||||
;
|
||||
; The Initial Developer of the Original Code is
|
||||
; Netscape Communications Corp.
|
||||
; Portions created by the Initial Developer are Copyright (C) 2001
|
||||
; the Initial Developer. All Rights Reserved.
|
||||
;
|
||||
; Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
;
|
||||
; 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 *****
|
||||
|
||||
LIBRARY mozMapi32.dll
|
||||
DESCRIPTION 'Mozilla Simple MAPI Support'
|
||||
|
||||
EXPORTS
|
||||
MAPILogon
|
||||
MAPILogoff
|
||||
MAPISendMail
|
||||
MAPISendDocuments
|
||||
MAPIFindNext
|
||||
MAPIReadMail
|
||||
MAPISaveMail
|
||||
MAPIDeleteMail
|
||||
MAPIAddress
|
||||
MAPIDetails
|
||||
MAPIResolveName
|
||||
MAPIFreeBuffer
|
||||
GetMapiDllVersion
|
||||
|
||||
@@ -1,346 +0,0 @@
|
||||
/* ***** 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
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
* Contributor(s): Rajiv Dayal (rdayal@netscape.com)
|
||||
*
|
||||
* 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 <windows.h>
|
||||
#include <tchar.h>
|
||||
#include <mapidefs.h>
|
||||
#include <mapi.h>
|
||||
#include "msgMapi.h"
|
||||
#include "msgMapiMain.h"
|
||||
|
||||
#define MAX_RECIPS 100
|
||||
#define MAX_FILES 100
|
||||
|
||||
const CLSID CLSID_CMapiImp = {0x29f458be, 0x8866, 0x11d5,
|
||||
{0xa3, 0xdd, 0x0, 0xb0, 0xd0, 0xf3, 0xba, 0xa7}};
|
||||
const IID IID_nsIMapi = {0x6EDCD38E,0x8861,0x11d5,
|
||||
{0xA3,0xDD,0x00,0xB0,0xD0,0xF3,0xBA,0xA7}};
|
||||
|
||||
DWORD tId = 0;
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE aInstance, DWORD aReason, LPVOID aReserved)
|
||||
{
|
||||
switch (aReason)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH : tId = TlsAlloc();
|
||||
if (tId == 0xFFFFFFFF)
|
||||
return FALSE;
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH : TlsFree(tId);
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL InitMozillaReference(nsIMapi **aRetValue)
|
||||
{
|
||||
// Check wehther this thread has a valid Interface
|
||||
// by looking into thread-specific-data variable
|
||||
|
||||
*aRetValue = (nsIMapi *)TlsGetValue(tId);
|
||||
|
||||
// Check whether the pointer actually resolves to
|
||||
// a valid method call; otherwise mozilla is not running
|
||||
|
||||
if ((*aRetValue) && (*aRetValue)->IsValid() == S_OK)
|
||||
return TRUE;
|
||||
|
||||
HRESULT hRes = ::CoInitialize(nsnull) ;
|
||||
|
||||
hRes = ::CoCreateInstance(CLSID_CMapiImp, NULL, CLSCTX_LOCAL_SERVER,
|
||||
IID_nsIMapi, (LPVOID *)aRetValue);
|
||||
|
||||
if (hRes == S_OK && (*aRetValue)->Initialize() == S_OK)
|
||||
if (TlsSetValue(tId, (LPVOID)(*aRetValue)))
|
||||
return TRUE;
|
||||
|
||||
// Either CoCreate or TlsSetValue failed; so return FALSE
|
||||
|
||||
if ((*aRetValue))
|
||||
(*aRetValue)->Release();
|
||||
|
||||
::CoUninitialize();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// The MAPILogon function begins a Simple MAPI session, loading the default message ////
|
||||
// store and address book providers ////
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
ULONG FAR PASCAL MAPILogon(ULONG aUIParam, LPTSTR aProfileName,
|
||||
LPTSTR aPassword, FLAGS aFlags,
|
||||
ULONG aReserved, LPLHANDLE aSession)
|
||||
{
|
||||
HRESULT hr = 0;
|
||||
ULONG nSessionId = 0;
|
||||
nsIMapi *pNsMapi = NULL;
|
||||
|
||||
if (!InitMozillaReference(&pNsMapi))
|
||||
return MAPI_E_FAILURE;
|
||||
|
||||
if (!(aFlags & MAPI_UNICODE))
|
||||
{
|
||||
// Need to convert the parameters to Unicode.
|
||||
|
||||
char *pUserName = (char *) aProfileName;
|
||||
char *pPassWord = (char *) aPassword;
|
||||
|
||||
TCHAR ProfileName[MAX_NAME_LEN] = {0};
|
||||
TCHAR PassWord[MAX_PW_LEN] = {0};
|
||||
|
||||
if (pUserName != NULL)
|
||||
{
|
||||
if (!MultiByteToWideChar(CP_ACP, 0, pUserName, -1, ProfileName,
|
||||
MAX_NAME_LEN))
|
||||
return MAPI_E_FAILURE;
|
||||
}
|
||||
|
||||
if (pPassWord != NULL)
|
||||
{
|
||||
if (!MultiByteToWideChar(CP_ACP, 0, pPassWord, -1, PassWord,
|
||||
MAX_NAME_LEN))
|
||||
return MAPI_E_FAILURE;
|
||||
}
|
||||
|
||||
hr = pNsMapi->Login(aUIParam, ProfileName, PassWord, aFlags,
|
||||
&nSessionId);
|
||||
}
|
||||
else
|
||||
hr = pNsMapi->Login(aUIParam, aProfileName, aPassword,
|
||||
aFlags, &nSessionId);
|
||||
if (hr == S_OK)
|
||||
(*aSession) = (LHANDLE) nSessionId;
|
||||
else
|
||||
return nSessionId;
|
||||
|
||||
return SUCCESS_SUCCESS;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL MAPILogoff (LHANDLE aSession, ULONG aUIParam,
|
||||
FLAGS aFlags, ULONG aReserved)
|
||||
{
|
||||
nsIMapi *pNsMapi = (nsIMapi *)TlsGetValue(tId);
|
||||
if (pNsMapi != NULL)
|
||||
{
|
||||
if (pNsMapi->Logoff((ULONG) aSession) == S_OK)
|
||||
pNsMapi->Release();
|
||||
pNsMapi = NULL;
|
||||
}
|
||||
|
||||
TlsSetValue(tId, NULL);
|
||||
|
||||
::CoUninitialize();
|
||||
|
||||
return SUCCESS_SUCCESS;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL MAPISendMail (LHANDLE lhSession, ULONG ulUIParam, lpnsMapiMessage lpMessage,
|
||||
FLAGS flFlags, ULONG ulReserved )
|
||||
{
|
||||
HRESULT hr = 0;
|
||||
BOOL bTempSession = FALSE ;
|
||||
nsIMapi *pNsMapi = NULL;
|
||||
|
||||
if (!InitMozillaReference(&pNsMapi))
|
||||
return MAPI_E_FAILURE;
|
||||
|
||||
if (lpMessage->nRecipCount > MAX_RECIPS)
|
||||
return MAPI_E_TOO_MANY_RECIPIENTS ;
|
||||
|
||||
if (lpMessage->nFileCount > MAX_FILES)
|
||||
return MAPI_E_TOO_MANY_FILES ;
|
||||
|
||||
if ( (!(flFlags & MAPI_DIALOG)) && (lpMessage->lpRecips == NULL) )
|
||||
return MAPI_E_UNKNOWN_RECIPIENT ;
|
||||
|
||||
if (!lhSession || pNsMapi->IsValidSession(lhSession) != S_OK)
|
||||
{
|
||||
FLAGS LoginFlag ;
|
||||
if ( (flFlags & MAPI_LOGON_UI) && (flFlags & MAPI_NEW_SESSION) )
|
||||
LoginFlag = MAPI_LOGON_UI | MAPI_NEW_SESSION ;
|
||||
else if (flFlags & MAPI_LOGON_UI)
|
||||
LoginFlag = MAPI_LOGON_UI ;
|
||||
|
||||
hr = MAPILogon (ulUIParam, (LPTSTR) NULL, (LPTSTR) NULL, LoginFlag, 0, &lhSession) ;
|
||||
if (hr != SUCCESS_SUCCESS)
|
||||
return MAPI_E_LOGIN_FAILURE ;
|
||||
bTempSession = TRUE ;
|
||||
}
|
||||
|
||||
// we need to deal with null data passed in by MAPI clients, specially when MAPI_DIALOG is set.
|
||||
// The MS COM type lib code generated by MIDL for the MS COM interfaces checks for these parameters
|
||||
// to be non null, although null is a valid value for them here.
|
||||
nsMapiRecipDesc * lpRecips ;
|
||||
nsMapiFileDesc * lpFiles ;
|
||||
|
||||
nsMapiMessage Message ;
|
||||
memset (&Message, 0, sizeof (nsMapiMessage) ) ;
|
||||
nsMapiRecipDesc Recipient ;
|
||||
memset (&Recipient, 0, sizeof (nsMapiRecipDesc) );
|
||||
nsMapiFileDesc Files ;
|
||||
memset (&Files, 0, sizeof (nsMapiFileDesc) ) ;
|
||||
|
||||
if(!lpMessage)
|
||||
{
|
||||
lpMessage = &Message ;
|
||||
}
|
||||
if(!lpMessage->lpRecips)
|
||||
{
|
||||
lpRecips = &Recipient ;
|
||||
}
|
||||
else
|
||||
lpRecips = lpMessage->lpRecips ;
|
||||
if(!lpMessage->lpFiles)
|
||||
{
|
||||
lpFiles = &Files ;
|
||||
}
|
||||
else
|
||||
lpFiles = lpMessage->lpFiles ;
|
||||
|
||||
HANDLE hEvent = CreateEvent (NULL, FALSE, FALSE, (LPCTSTR) MAPI_SENDCOMPLETE_EVENT) ;
|
||||
|
||||
hr = pNsMapi->SendMail (lhSession, lpMessage,
|
||||
(short) lpMessage->nRecipCount, lpRecips,
|
||||
(short) lpMessage->nFileCount, lpFiles,
|
||||
flFlags, ulReserved);
|
||||
|
||||
// we are seeing a problem when using Word, although we return success from the MAPI support
|
||||
// MS COM interface in mozilla, we are getting this error here. This is a temporary hack !!
|
||||
if (hr == 0x800703e6)
|
||||
hr = SUCCESS_SUCCESS;
|
||||
|
||||
if (hr == SUCCESS_SUCCESS)
|
||||
WaitForSingleObject (hEvent, INFINITE) ;
|
||||
CloseHandle (hEvent) ;
|
||||
|
||||
if (bTempSession)
|
||||
MAPILogoff (lhSession, ulUIParam, 0,0) ;
|
||||
|
||||
return hr ;
|
||||
}
|
||||
|
||||
|
||||
ULONG FAR PASCAL MAPISendDocuments(ULONG ulUIParam, LPTSTR lpszDelimChar, LPTSTR lpszFilePaths,
|
||||
LPTSTR lpszFileNames, ULONG ulReserved)
|
||||
{
|
||||
LHANDLE lhSession ;
|
||||
nsIMapi *pNsMapi = NULL;
|
||||
|
||||
if (!InitMozillaReference(&pNsMapi))
|
||||
return MAPI_E_FAILURE;
|
||||
|
||||
unsigned long result = MAPILogon (ulUIParam, (LPTSTR) NULL, (LPTSTR) NULL, MAPI_LOGON_UI, 0, &lhSession) ;
|
||||
if (result != SUCCESS_SUCCESS)
|
||||
return MAPI_E_LOGIN_FAILURE ;
|
||||
|
||||
HRESULT hr;
|
||||
|
||||
HANDLE hEvent = CreateEvent (NULL, FALSE, FALSE, (LPCTSTR) MAPI_SENDCOMPLETE_EVENT) ;
|
||||
|
||||
hr = pNsMapi->SendDocuments(lhSession, (LPTSTR) lpszDelimChar, (LPTSTR) lpszFilePaths,
|
||||
(LPTSTR) lpszFileNames, ulReserved) ;
|
||||
|
||||
if (hr == SUCCESS_SUCCESS)
|
||||
WaitForSingleObject (hEvent, INFINITE) ;
|
||||
CloseHandle (hEvent) ;
|
||||
|
||||
MAPILogoff (lhSession, ulUIParam, 0,0) ;
|
||||
|
||||
return hr ;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL MAPIFindNext(LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszMessageType,
|
||||
LPTSTR lpszSeedMessageID, FLAGS flFlags, ULONG ulReserved,
|
||||
LPTSTR lpszMessageID)
|
||||
{
|
||||
return MAPI_E_FAILURE;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL MAPIReadMail(LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszMessageID,
|
||||
FLAGS flFlags, ULONG ulReserved, lpMapiMessage FAR *lppMessage)
|
||||
{
|
||||
return MAPI_E_FAILURE;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL MAPISaveMail(LHANDLE lhSession, ULONG ulUIParam, lpMapiMessage lpMessage,
|
||||
FLAGS flFlags, ULONG ulReserved, LPTSTR lpszMessageID)
|
||||
{
|
||||
return MAPI_E_FAILURE;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL MAPIDeleteMail(LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszMessageID,
|
||||
FLAGS flFlags, ULONG ulReserved)
|
||||
{
|
||||
return MAPI_E_FAILURE;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL MAPIAddress(LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszCaption,
|
||||
ULONG nEditFields, LPTSTR lpszLabels, ULONG nRecips,
|
||||
lpMapiRecipDesc lpRecips, FLAGS flFlags,
|
||||
ULONG ulReserved, LPULONG lpnNewRecips,
|
||||
lpMapiRecipDesc FAR *lppNewRecips)
|
||||
{
|
||||
return MAPI_E_FAILURE;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL MAPIDetails(LHANDLE lhSession, ULONG ulUIParam, lpMapiRecipDesc lpRecip,
|
||||
FLAGS flFlags, ULONG ulReserved)
|
||||
{
|
||||
return MAPI_E_FAILURE;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL MAPIResolveName(LHANDLE lhSession, ULONG ulUIParam, LPTSTR lpszName,
|
||||
FLAGS flFlags, ULONG ulReserved, lpMapiRecipDesc FAR *lppRecip)
|
||||
{
|
||||
return MAPI_E_FAILURE;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL MAPIFreeBuffer(LPVOID pv)
|
||||
{
|
||||
return MAPI_E_FAILURE;
|
||||
}
|
||||
|
||||
ULONG FAR PASCAL GetMapiDllVersion()
|
||||
{
|
||||
return 94;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
# ***** 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.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Netscape Communications Corp.
|
||||
# Portions created by the Initial Developer are Copyright (C) 2001
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
#
|
||||
# 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=..\..\..
|
||||
|
||||
MODULE = mozMapi32
|
||||
EXPORT_LIBRARY = $(MODULE)
|
||||
LIBRARY_NAME = $(MODULE)
|
||||
DEFFILE = Mapi32.def
|
||||
|
||||
REQUIRES = MapiProxy \
|
||||
msgMapi \
|
||||
xpcom \
|
||||
string \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\config.mak>
|
||||
###############################################################
|
||||
|
||||
LCFLAGS=-DUNICODE -D_UNICODE
|
||||
|
||||
OBJS= .\$(OBJDIR)\MapiDll.obj \
|
||||
$(NULL)
|
||||
|
||||
WIN_LIBS= ole32.lib \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
; ***** 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.
|
||||
;
|
||||
; The Initial Developer of the Original Code is
|
||||
; Netscape Communications Corp.
|
||||
; Portions created by the Initial Developer are Copyright (C) 2001
|
||||
; the Initial Developer. All Rights Reserved.
|
||||
;
|
||||
; Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
;
|
||||
; 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 *****
|
||||
|
||||
LIBRARY MapiProxy.dll
|
||||
DESCRIPTION 'Proxy/Stub DLL'
|
||||
|
||||
EXPORTS
|
||||
DllGetClassObject @1 PRIVATE
|
||||
DllCanUnloadNow @2 PRIVATE
|
||||
GetProxyDllInfo @3 PRIVATE
|
||||
DllRegisterServer @4 PRIVATE
|
||||
DllUnregisterServer @5 PRIVATE
|
||||
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
# ***** 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.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Netscape Communications Corp.
|
||||
# Portions created by the Initial Developer are Copyright (C) 2001
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
#
|
||||
# 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=..\..\..\..
|
||||
|
||||
MODULE = MapiProxy
|
||||
EXPORT_LIBRARY = $(MODULE)
|
||||
LIBRARY_NAME = $(MODULE)
|
||||
DEFFILE = MapiProxy.def
|
||||
|
||||
include <$(DEPTH)\config\config.mak>
|
||||
|
||||
##################################################################
|
||||
|
||||
LCFLAGS=-DREGISTER_PROXY_DLL -DUNICODE -D_UNICODE
|
||||
|
||||
OBJS= .\$(OBJDIR)\dlldata.obj \
|
||||
.\$(OBJDIR)\msgMapi_p.obj \
|
||||
.\$(OBJDIR)\msgMapi_i.obj \
|
||||
$(NULL)
|
||||
|
||||
WIN_LIBS= rpcrt4.lib
|
||||
|
||||
EXPORTS= msgMapi.h \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
msgMapi.h msgMapi_p.c msgMapi_i.c dlldata.c : msgMapi.idl
|
||||
midl $(UNICODE_FLAGS) msgMapi.idl
|
||||
|
||||
clobber::
|
||||
rm -f dlldata.c msgMapi_i.c msgMapi_p.c msgMapi.h
|
||||
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
/* ***** 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
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
* Contributor(s): Rajiv Dayal (rdayal@netscape.com)
|
||||
*
|
||||
* 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 idl will be compiled by MIDL. MS-COM is used
|
||||
// as brdige between MAPI clients and the Mozilla.
|
||||
|
||||
import "unknwn.idl";
|
||||
|
||||
typedef wchar_t LOGIN_PW_TYPE[256];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned long ulReserved;
|
||||
unsigned long flFlags; /* Flags */
|
||||
unsigned long nPosition_NotUsed; /* character in text to be replaced by attachment */
|
||||
LPTSTR lpszPathName; /* Full path name including file name */
|
||||
LPTSTR lpszFileName; /* Real (original) file name */
|
||||
unsigned char * lpFileType_NotUsed ;
|
||||
} nsMapiFileDesc, * lpnsMapiFileDesc;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned long ulReserved;
|
||||
unsigned long ulRecipClass; /* MAPI_TO, MAPI_CC, MAPI_BCC, MAPI_ORIG */
|
||||
LPTSTR lpszName; /* Recipient name to display */
|
||||
LPTSTR lpszAddress; /* Recipient email address */
|
||||
unsigned long ulEIDSize_NotUsed;
|
||||
unsigned char * lpEntryID_NotUsed ;
|
||||
} nsMapiRecipDesc, * lpnsMapiRecipDesc;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned long ulReserved;
|
||||
LPTSTR lpszSubject; /* Message Subject */
|
||||
LPTSTR lpszNoteText; /* Message Text */
|
||||
LPTSTR lpszMessageType_NotUsed;
|
||||
LPTSTR lpszDateReceived_notUsed; /* in YYYY/MM/DD HH:MM format */
|
||||
LPTSTR lpszConversationID_NotUsed; /* conversation thread ID */
|
||||
unsigned long flFlags; /* unread,return receipt */
|
||||
lpnsMapiRecipDesc lpOriginator; /* Originator descriptor */
|
||||
unsigned long nRecipCount; /* Number of recipients */
|
||||
lpnsMapiRecipDesc lpRecips; /* Recipient descriptors */
|
||||
unsigned long nFileCount; /* # of file attachments */
|
||||
lpnsMapiFileDesc lpFiles; /* Attachment descriptors */
|
||||
} nsMapiMessage, * lpnsMapiMessage;
|
||||
|
||||
|
||||
[
|
||||
object,
|
||||
uuid(6EDCD38E-8861-11d5-A3DD-00B0D0F3BAA7),
|
||||
helpstring("nsIMapi Inteface"),
|
||||
pointer_default(unique)
|
||||
]
|
||||
|
||||
interface nsIMapi : IUnknown
|
||||
{
|
||||
HRESULT Login(unsigned long aUIArg, LOGIN_PW_TYPE aLogin,
|
||||
LOGIN_PW_TYPE aPassWord, unsigned long aFlags,
|
||||
[out] unsigned long *aSessionId);
|
||||
|
||||
HRESULT Initialize();
|
||||
HRESULT IsValid();
|
||||
HRESULT IsValidSession([in] unsigned long aSession);
|
||||
|
||||
HRESULT SendMail([in] unsigned long aSession, [in] lpnsMapiMessage aMessage,
|
||||
[in] short aRecipCount, [in, size_is(aRecipCount)] lpnsMapiRecipDesc aRecips,
|
||||
[in] short aFileCount, [in, size_is(aFileCount)] lpnsMapiFileDesc aFiles,
|
||||
[in] unsigned long aFlags, [in] unsigned long aReserved) ;
|
||||
|
||||
HRESULT SendDocuments( [in] unsigned long aSession,
|
||||
[in] LPTSTR aDelimChar, [in] LPTSTR aFilePaths,
|
||||
[in] LPTSTR aFileNames, [in] ULONG aFlags ) ;
|
||||
|
||||
HRESULT Logoff (unsigned long aSession);
|
||||
HRESULT CleanUp();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
# ***** 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.
|
||||
#
|
||||
# The Initial Developer of the Original Code is
|
||||
# Netscape Communications Corp.
|
||||
# Portions created by the Initial Developer are Copyright (C) 2001
|
||||
# the Initial Developer. All Rights Reserved.
|
||||
#
|
||||
# Contributor(s): Srilatha Moturi (srilatha@netscape.com)
|
||||
#
|
||||
# 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=..\..\..
|
||||
|
||||
DIRS= build public src
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
@@ -1,49 +0,0 @@
|
||||
# ***** 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):
|
||||
# Srilatha Moturi <srilatha@netscape.com>
|
||||
#
|
||||
# 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=..\..\..\..
|
||||
|
||||
MODULE=msgMapi
|
||||
XPIDL_MODULE=mapihook
|
||||
|
||||
XPIDLSRCS = \
|
||||
.\nsIMapiRegistry.idl \
|
||||
.\nsIMapiSupport.idl \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
/* ***** 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):
|
||||
* Srilatha Moturi <srilatha@netscape.com>
|
||||
*
|
||||
* 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 nsIDOMWindow;
|
||||
|
||||
/**
|
||||
* This interface provides support for registering Mozilla as the default
|
||||
* Mail Client. This interface can also be used to get/set the user preference
|
||||
* for the default Mail Client.
|
||||
*
|
||||
*/
|
||||
[scriptable, uuid(c5be14ba-4e0a-4eec-a1b8-04363761d63c)]
|
||||
interface nsIMapiRegistry: nsISupports {
|
||||
|
||||
/** This is set to TRUE if Mozilla is the default Application
|
||||
*/
|
||||
attribute boolean isDefaultMailClient;
|
||||
|
||||
/** This is set TRUE only once per session.
|
||||
*/
|
||||
readonly attribute boolean showDialog;
|
||||
|
||||
/** This will bring the dialog asking the user if he/she wants to set
|
||||
* Mozilla as default Mail Client.
|
||||
* Call this only if Mozilla is not the default Mail client
|
||||
*/
|
||||
void showMailIntegrationDialog(in nsIDOMWindow parentWindow);
|
||||
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define NS_IMAPIREGISTRY_CONTRACTID "@mozilla.org/mapiregistry;1"
|
||||
#define NS_IMAPIREGISTRY_CLASSNAME "Mozilla MAPI Registry"
|
||||
%}
|
||||
@@ -1,64 +0,0 @@
|
||||
/* ***** 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 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"
|
||||
|
||||
/**
|
||||
* This interface provides support for registering Mozilla as a COM component
|
||||
* for extending the use of Mail/News through Simple MAPI.
|
||||
*
|
||||
*/
|
||||
|
||||
[noscript, uuid(8967fed2-c8bb-11d5-a3e9-00b0d0f3baa7)]
|
||||
interface nsIMapiSupport : nsISupports {
|
||||
|
||||
/** Initiates MAPI support
|
||||
*/
|
||||
|
||||
void initializeMAPISupport();
|
||||
|
||||
/** Shuts down the MAPI support
|
||||
*/
|
||||
|
||||
void shutdownMAPISupport();
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define NS_IMAPISUPPORT_CONTRACTID "@mozilla.org/mapisupport;1"
|
||||
#define NS_IMAPISUPPORT_CLASSNAME "Mozilla MAPI Support"
|
||||
%}
|
||||
|
||||
|
||||
@@ -1,323 +0,0 @@
|
||||
/* ***** 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
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Krishna Mohan Khandrika <kkhandrika@netscape.com>
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
#undef _UNICODE
|
||||
#undef UNICODE
|
||||
|
||||
#include <objbase.h>
|
||||
#include "nsString.h"
|
||||
#include "Registry.h"
|
||||
|
||||
#define MAPI_PROXY_DLL_NAME "MapiProxy.dll"
|
||||
#define MAPI_STARTUP_ARG " /MAPIStartUp"
|
||||
#define MAX_SIZE 2048
|
||||
|
||||
// Size of a CLSID as a string
|
||||
const int CLSID_STRING_SIZE = 39;
|
||||
|
||||
// Proxy/Stub Dll Routines
|
||||
|
||||
typedef HRESULT (__stdcall ProxyServer)();
|
||||
|
||||
|
||||
// Convert a CLSID to a char string.
|
||||
|
||||
BOOL CLSIDtochar(const CLSID& clsid, char* szCLSID,
|
||||
int length)
|
||||
{
|
||||
LPOLESTR wszCLSID = NULL;
|
||||
|
||||
// Get CLSID
|
||||
HRESULT hr = StringFromCLSID(clsid, &wszCLSID);
|
||||
if (FAILED(hr))
|
||||
return FALSE;
|
||||
|
||||
// Covert from wide characters to non-wide.
|
||||
wcstombs(szCLSID, wszCLSID, length);
|
||||
|
||||
// Free memory.
|
||||
CoTaskMemFree(wszCLSID);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Create a key and set its value.
|
||||
|
||||
BOOL setKeyAndValue(nsCAutoString keyName, const char* subKey,
|
||||
const char* theValue)
|
||||
{
|
||||
HKEY hKey;
|
||||
BOOL retValue = TRUE;
|
||||
|
||||
nsCAutoString theKey(keyName);
|
||||
if (subKey != NULL)
|
||||
{
|
||||
theKey += "\\";
|
||||
theKey += subKey;
|
||||
}
|
||||
|
||||
// Create and open key and subkey.
|
||||
long lResult = RegCreateKeyEx(HKEY_CLASSES_ROOT, theKey.get(),
|
||||
0, NULL, REG_OPTION_NON_VOLATILE,
|
||||
KEY_ALL_ACCESS, NULL, &hKey, NULL);
|
||||
if (lResult != ERROR_SUCCESS)
|
||||
return FALSE ;
|
||||
|
||||
// Set the Value.
|
||||
if (theValue != NULL)
|
||||
{
|
||||
lResult = RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE *)theValue,
|
||||
strlen(theValue)+1);
|
||||
if (lResult != ERROR_SUCCESS)
|
||||
retValue = FALSE;
|
||||
}
|
||||
|
||||
RegCloseKey(hKey);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// Delete a key and all of its descendents.
|
||||
|
||||
LONG recursiveDeleteKey(HKEY hKeyParent, // Parent of key to delete
|
||||
const char* lpszKeyChild) // Key to delete
|
||||
{
|
||||
// Open the child.
|
||||
HKEY hKeyChild ;
|
||||
LONG lRes = RegOpenKeyEx(hKeyParent, lpszKeyChild, 0,
|
||||
KEY_ALL_ACCESS, &hKeyChild) ;
|
||||
if (lRes != ERROR_SUCCESS)
|
||||
{
|
||||
return lRes ;
|
||||
}
|
||||
|
||||
// Enumerate all of the decendents of this child.
|
||||
FILETIME time ;
|
||||
char szBuffer[MAX_SIZE] ;
|
||||
DWORD dwSize = MAX_SIZE ;
|
||||
while (RegEnumKeyEx(hKeyChild, 0, szBuffer, &dwSize, NULL,
|
||||
NULL, NULL, &time) == S_OK)
|
||||
{
|
||||
// Delete the decendents of this child.
|
||||
lRes = recursiveDeleteKey(hKeyChild, szBuffer) ;
|
||||
if (lRes != ERROR_SUCCESS)
|
||||
{
|
||||
// Cleanup before exiting.
|
||||
RegCloseKey(hKeyChild) ;
|
||||
return lRes;
|
||||
}
|
||||
dwSize = MAX_SIZE;
|
||||
}
|
||||
|
||||
// Close the child.
|
||||
RegCloseKey(hKeyChild) ;
|
||||
|
||||
// Delete this child.
|
||||
return RegDeleteKey(hKeyParent, lpszKeyChild) ;
|
||||
}
|
||||
|
||||
void RegisterProxy()
|
||||
{
|
||||
HINSTANCE h = NULL;
|
||||
ProxyServer *RegisterFunc = NULL;
|
||||
|
||||
char szModule[MAX_SIZE];
|
||||
char *pTemp = NULL;
|
||||
|
||||
HMODULE hModule = GetModuleHandle(NULL);
|
||||
DWORD dwResult = ::GetModuleFileName(hModule, szModule,
|
||||
sizeof(szModule)/sizeof(char));
|
||||
if (dwResult == 0)
|
||||
return;
|
||||
|
||||
pTemp = strrchr(szModule, '\\');
|
||||
if (pTemp == NULL)
|
||||
return;
|
||||
|
||||
*pTemp = '\0';
|
||||
nsCAutoString proxyPath(szModule);
|
||||
|
||||
proxyPath += "\\";
|
||||
proxyPath += MAPI_PROXY_DLL_NAME;
|
||||
|
||||
h = LoadLibrary(proxyPath.get());
|
||||
if (h == NULL)
|
||||
return;
|
||||
|
||||
RegisterFunc = (ProxyServer *) GetProcAddress(h, "DllRegisterServer");
|
||||
if (RegisterFunc)
|
||||
RegisterFunc();
|
||||
|
||||
FreeLibrary(h);
|
||||
}
|
||||
|
||||
void UnRegisterProxy()
|
||||
{
|
||||
HINSTANCE h = NULL;
|
||||
ProxyServer *UnRegisterFunc = NULL;
|
||||
|
||||
char szModule[MAX_SIZE];
|
||||
char *pTemp = NULL;
|
||||
|
||||
HMODULE hModule = GetModuleHandle(NULL);
|
||||
DWORD dwResult = ::GetModuleFileName(hModule, szModule,
|
||||
sizeof(szModule)/sizeof(char));
|
||||
if (dwResult == 0)
|
||||
return;
|
||||
|
||||
pTemp = strrchr(szModule, '\\');
|
||||
if (pTemp == NULL)
|
||||
return;
|
||||
|
||||
*pTemp = '\0';
|
||||
nsCAutoString proxyPath(szModule);
|
||||
|
||||
proxyPath += "\\";
|
||||
proxyPath += MAPI_PROXY_DLL_NAME;
|
||||
|
||||
h = LoadLibrary(proxyPath.get());
|
||||
if (h == NULL)
|
||||
return;
|
||||
|
||||
UnRegisterFunc = (ProxyServer *) GetProcAddress(h, "DllUnregisterServer");
|
||||
if (UnRegisterFunc)
|
||||
UnRegisterFunc();
|
||||
|
||||
FreeLibrary(h);
|
||||
}
|
||||
|
||||
// Register the component in the registry.
|
||||
|
||||
HRESULT RegisterServer(const CLSID& clsid, // Class ID
|
||||
const char* szFriendlyName, // Friendly Name
|
||||
const char* szVerIndProgID, // Programmatic
|
||||
const char* szProgID) // IDs
|
||||
{
|
||||
HMODULE hModule = GetModuleHandle(NULL);
|
||||
char szModuleName[MAX_SIZE];
|
||||
char szCLSID[CLSID_STRING_SIZE];
|
||||
|
||||
nsCAutoString independentProgId(szVerIndProgID);
|
||||
nsCAutoString progId(szProgID);
|
||||
|
||||
DWORD dwResult = ::GetModuleFileName(hModule, szModuleName,
|
||||
sizeof(szModuleName)/sizeof(char));
|
||||
|
||||
if (dwResult == 0)
|
||||
return S_FALSE;
|
||||
|
||||
nsCAutoString moduleName(szModuleName);
|
||||
nsCAutoString registryKey("CLSID\\");
|
||||
|
||||
moduleName += MAPI_STARTUP_ARG;
|
||||
|
||||
// Convert the CLSID into a char.
|
||||
|
||||
if (!CLSIDtochar(clsid, szCLSID, sizeof(szCLSID)))
|
||||
return S_FALSE;
|
||||
registryKey += szCLSID;
|
||||
|
||||
// Add the CLSID to the registry.
|
||||
if (!setKeyAndValue(registryKey, NULL, szFriendlyName))
|
||||
return S_FALSE;
|
||||
|
||||
if (!setKeyAndValue(registryKey, "LocalServer32", moduleName.get()))
|
||||
return S_FALSE;
|
||||
|
||||
// Add the ProgID subkey under the CLSID key.
|
||||
if (!setKeyAndValue(registryKey, "ProgID", szProgID))
|
||||
return S_FALSE;
|
||||
|
||||
// Add the version-independent ProgID subkey under CLSID key.
|
||||
if (!setKeyAndValue(registryKey, "VersionIndependentProgID", szVerIndProgID))
|
||||
return S_FALSE;
|
||||
|
||||
// Add the version-independent ProgID subkey under HKEY_CLASSES_ROOT.
|
||||
if (!setKeyAndValue(independentProgId, NULL, szFriendlyName))
|
||||
return S_FALSE;
|
||||
if (!setKeyAndValue(independentProgId, "CLSID", szCLSID))
|
||||
return S_FALSE;
|
||||
if (!setKeyAndValue(independentProgId, "CurVer", szProgID))
|
||||
return S_FALSE;
|
||||
|
||||
// Add the versioned ProgID subkey under HKEY_CLASSES_ROOT.
|
||||
if (!setKeyAndValue(progId, NULL, szFriendlyName))
|
||||
return S_FALSE;
|
||||
if (!setKeyAndValue(progId, "CLSID", szCLSID))
|
||||
return S_FALSE;
|
||||
|
||||
RegisterProxy();
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
LONG UnregisterServer(const CLSID& clsid, // Class ID
|
||||
const char* szVerIndProgID, // Programmatic
|
||||
const char* szProgID) // IDs
|
||||
{
|
||||
LONG lResult = S_OK;
|
||||
|
||||
// Convert the CLSID into a char.
|
||||
|
||||
char szCLSID[CLSID_STRING_SIZE];
|
||||
if (!CLSIDtochar(clsid, szCLSID, sizeof(szCLSID)))
|
||||
return S_FALSE;
|
||||
|
||||
UnRegisterProxy();
|
||||
|
||||
nsCAutoString registryKey("CLSID\\");
|
||||
registryKey += szCLSID;
|
||||
|
||||
lResult = recursiveDeleteKey(HKEY_CLASSES_ROOT, registryKey.get());
|
||||
if (lResult == ERROR_SUCCESS || lResult == ERROR_FILE_NOT_FOUND)
|
||||
return lResult;
|
||||
|
||||
registryKey += "\\LocalServer32";
|
||||
|
||||
// Delete only the path for this server.
|
||||
|
||||
lResult = recursiveDeleteKey(HKEY_CLASSES_ROOT, registryKey.get());
|
||||
if (lResult != ERROR_SUCCESS && lResult != ERROR_FILE_NOT_FOUND)
|
||||
return lResult;
|
||||
|
||||
// Delete the version-independent ProgID Key.
|
||||
lResult = recursiveDeleteKey(HKEY_CLASSES_ROOT, szVerIndProgID);
|
||||
if (lResult != ERROR_SUCCESS && lResult != ERROR_FILE_NOT_FOUND)
|
||||
return lResult;
|
||||
|
||||
lResult = recursiveDeleteKey(HKEY_CLASSES_ROOT, szProgID);
|
||||
|
||||
return lResult;
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/* ***** 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):
|
||||
* Krishna Mohan Khandrika <kkhandrika@netscape.com>
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
#ifndef _REGISTRY_H_
|
||||
#define _REGISTRY_H_
|
||||
|
||||
#include <objbase.h>
|
||||
|
||||
// This function will register a component in the Registry.
|
||||
|
||||
HRESULT RegisterServer(const CLSID& clsid,
|
||||
const char* szFriendlyName,
|
||||
const char* szVerIndProgID,
|
||||
const char* szProgID) ;
|
||||
|
||||
// This function will unregister a component.
|
||||
|
||||
HRESULT UnregisterServer(const CLSID& clsid,
|
||||
const char* szVerIndProgID,
|
||||
const char* szProgID) ;
|
||||
|
||||
#endif
|
||||
@@ -1,107 +0,0 @@
|
||||
# ***** 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):
|
||||
# Srilatha Moturi <srilatha@netscape.com>
|
||||
#
|
||||
# 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=..\..\..\..
|
||||
|
||||
MODULE = msgMapi
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
LIBRARY_NAME=$(MODULE)
|
||||
MODULE_NAME = $(MODULE)
|
||||
|
||||
REQUIRES = xpcom \
|
||||
string \
|
||||
MapiProxy \
|
||||
appshell \
|
||||
windowwatcher \
|
||||
dom \
|
||||
profile \
|
||||
msgbase \
|
||||
pref \
|
||||
msgbaseutil \
|
||||
msgcompo \
|
||||
mailnews \
|
||||
necko \
|
||||
intl \
|
||||
editor \
|
||||
msgdb \
|
||||
uriloader \
|
||||
appstartup \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\config.mak>
|
||||
############################################################################
|
||||
|
||||
LCFLAGS=-DUNICODE -D_UNICODE
|
||||
|
||||
|
||||
|
||||
OBJS= \
|
||||
..\build\$(OBJDIR)\msgMapi_i.obj \
|
||||
.\$(OBJDIR)\msgMapiFactory.obj \
|
||||
.\$(OBJDIR)\msgMapiHook.obj \
|
||||
.\$(OBJDIR)\msgMapiImp.obj \
|
||||
.\$(OBJDIR)\msgMapiMain.obj \
|
||||
.\$(OBJDIR)\msgMapiSupport.obj \
|
||||
.\$(OBJDIR)\nsMapiRegistry.obj \
|
||||
.\$(OBJDIR)\nsMapiRegistryUtils.obj \
|
||||
.\$(OBJDIR)\Registry.obj \
|
||||
$(NULL)
|
||||
|
||||
|
||||
|
||||
LLIBS= \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(DIST)\lib\msgbsutl.lib \
|
||||
$(LIBNSPR) \
|
||||
$(NULL)
|
||||
|
||||
WIN_LIBS= \
|
||||
ole32.lib \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS= \
|
||||
msgMapiFactory.h \
|
||||
msgMapiHook.h \
|
||||
msgMapiImp.h \
|
||||
msgMapiMain.h \
|
||||
msgMapiSupport.h \
|
||||
nsMapiRegistry.h \
|
||||
nsMapiRegistryUtils.h \
|
||||
Registry.h \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
@@ -1,118 +0,0 @@
|
||||
/* ***** 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
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
#undef UNICODE
|
||||
#undef _UNICODE
|
||||
|
||||
#include "msgMapiFactory.h"
|
||||
#include "msgMapiImp.h"
|
||||
#include "msgMapi.h"
|
||||
|
||||
CMapiFactory ::CMapiFactory()
|
||||
: m_cRef(1)
|
||||
{
|
||||
}
|
||||
|
||||
CMapiFactory::~CMapiFactory()
|
||||
{
|
||||
}
|
||||
|
||||
STDMETHODIMP CMapiFactory::QueryInterface(const IID& aIid, void** aPpv)
|
||||
{
|
||||
if ((aIid == IID_IUnknown) || (aIid == IID_IClassFactory))
|
||||
{
|
||||
*aPpv = static_cast<IClassFactory*>(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
*aPpv = nsnull;
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
reinterpret_cast<IUnknown*>(*aPpv)->AddRef();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP_(ULONG) CMapiFactory::AddRef()
|
||||
{
|
||||
return (PR_AtomicIncrement(&m_cRef));
|
||||
}
|
||||
|
||||
STDMETHODIMP_(ULONG) CMapiFactory::Release()
|
||||
{
|
||||
PRInt32 temp;
|
||||
temp = PR_AtomicDecrement(&m_cRef);
|
||||
if (m_cRef == 0)
|
||||
{
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
STDMETHODIMP CMapiFactory::CreateInstance(IUnknown* aUnknownOuter,
|
||||
const IID& aIid,
|
||||
void** aPpv)
|
||||
{
|
||||
// Cannot aggregate.
|
||||
|
||||
if (aUnknownOuter != nsnull)
|
||||
{
|
||||
return CLASS_E_NOAGGREGATION ;
|
||||
}
|
||||
|
||||
// Create component.
|
||||
|
||||
CMapiImp* pImp = new CMapiImp();
|
||||
if (pImp == nsnull)
|
||||
{
|
||||
return E_OUTOFMEMORY ;
|
||||
}
|
||||
|
||||
// Get the requested interface.
|
||||
HRESULT hr = pImp->QueryInterface(aIid, aPpv);
|
||||
|
||||
// Release the IUnknown pointer.
|
||||
// (If QueryInterface failed, component will delete itself.)
|
||||
|
||||
pImp->Release();
|
||||
return hr;
|
||||
}
|
||||
|
||||
STDMETHODIMP CMapiFactory::LockServer(PRBool aLock)
|
||||
{
|
||||
return S_OK ;
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/* ***** 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
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
#ifndef MSG_MAPI_FACTORY_H
|
||||
#define MSG_MAPI_FACTORY_H
|
||||
|
||||
#include <windows.h>
|
||||
#include <objbase.h>
|
||||
#include "nspr.h"
|
||||
|
||||
|
||||
class CMapiFactory : public IClassFactory
|
||||
{
|
||||
public :
|
||||
|
||||
// IUnknown
|
||||
|
||||
STDMETHODIMP QueryInterface (REFIID aIid, void** aPpv);
|
||||
STDMETHODIMP_(ULONG) AddRef(void);
|
||||
STDMETHODIMP_(ULONG) Release(void);
|
||||
|
||||
// IClassFactory
|
||||
|
||||
STDMETHODIMP CreateInstance (LPUNKNOWN aUnkOuter, REFIID aIid, void **aPpv);
|
||||
STDMETHODIMP LockServer (BOOL aLock);
|
||||
|
||||
CMapiFactory ();
|
||||
~CMapiFactory ();
|
||||
|
||||
private :
|
||||
|
||||
PRInt32 m_cRef;
|
||||
};
|
||||
|
||||
#endif // MSG_MAPI_FACTORY_H
|
||||
|
||||
@@ -1,777 +0,0 @@
|
||||
/* ***** 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
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
* Contributor(s): Srilatha Moturi (srilatha@netscape.com)
|
||||
* Contributor(s): Rajiv Dayal (rdayal@netscape.com)
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
#define MAPI_STARTUP_ARG "/MAPIStartUp"
|
||||
|
||||
#define MAPI_STARTUP_ARG "/MAPIStartUp"
|
||||
|
||||
#include <mapidefs.h>
|
||||
#include <mapi.h>
|
||||
#include <tchar.h>
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIPromptService.h"
|
||||
#include "nsAppShellCIDs.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsIAppShellService.h"
|
||||
#include "nsINativeAppSupport.h"
|
||||
#include "nsICmdLineService.h"
|
||||
#include "nsIProfileInternal.h"
|
||||
#include "nsIMsgAccountManager.h"
|
||||
#include "nsIDOMWindowInternal.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsMsgBaseCID.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsIMsgAttachment.h"
|
||||
#include "nsIMsgCompFields.h"
|
||||
#include "nsIMsgComposeParams.h"
|
||||
#include "nsIMsgCompose.h"
|
||||
#include "nsMsgCompCID.h"
|
||||
#include "nsIMsgSend.h"
|
||||
#include "nsIProxyObjectManager.h"
|
||||
#include "nsIMsgComposeService.h"
|
||||
#include "nsProxiedService.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
#include "nsMsgI18N.h"
|
||||
|
||||
#include "msgMapi.h"
|
||||
#include "msgMapiHook.h"
|
||||
#include "msgMapiSupport.h"
|
||||
#include "msgMapiMain.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
||||
static NS_DEFINE_CID(kCmdLineServiceCID, NS_COMMANDLINE_SERVICE_CID);
|
||||
|
||||
class nsMAPISendListener : public nsIMsgSendListener
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~nsMAPISendListener() { }
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/* void OnStartSending (in string aMsgID, in PRUint32 aMsgSize); */
|
||||
NS_IMETHOD OnStartSending(const char *aMsgID, PRUint32 aMsgSize) { return NS_OK; }
|
||||
|
||||
/* void OnProgress (in string aMsgID, in PRUint32 aProgress, in PRUint32 aProgressMax); */
|
||||
NS_IMETHOD OnProgress(const char *aMsgID, PRUint32 aProgress, PRUint32 aProgressMax) { return NS_OK;}
|
||||
|
||||
/* void OnStatus (in string aMsgID, in wstring aMsg); */
|
||||
NS_IMETHOD OnStatus(const char *aMsgID, const PRUnichar *aMsg) { return NS_OK;}
|
||||
|
||||
/* void OnStopSending (in string aMsgID, in nsresult aStatus, in wstring aMsg, in nsIFileSpec returnFileSpec); */
|
||||
NS_IMETHOD OnStopSending(const char *aMsgID, nsresult aStatus, const PRUnichar *aMsg,
|
||||
nsIFileSpec *returnFileSpec) {
|
||||
m_done = PR_TRUE;
|
||||
HANDLE hEvent = CreateEvent (NULL, FALSE, FALSE, (LPCTSTR) MAPI_SENDCOMPLETE_EVENT) ;
|
||||
SetEvent (hEvent) ;
|
||||
CloseHandle (hEvent) ;
|
||||
return NS_OK ;
|
||||
}
|
||||
|
||||
/* void OnSendNotPerformed */
|
||||
NS_IMETHOD OnSendNotPerformed(const char *aMsgID, nsresult aStatus)
|
||||
{
|
||||
return OnStopSending(aMsgID, aStatus, nsnull, nsnull) ;
|
||||
}
|
||||
|
||||
/* void OnGetDraftFolderURI (); */
|
||||
NS_IMETHOD OnGetDraftFolderURI(const char *aFolderURI) {return NS_OK;}
|
||||
|
||||
static nsresult CreateMAPISendListener( nsIMsgSendListener **ppListener);
|
||||
|
||||
PRBool IsDone() { return m_done ; }
|
||||
|
||||
protected :
|
||||
nsMAPISendListener() {
|
||||
NS_INIT_REFCNT();
|
||||
m_done = PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool m_done;
|
||||
};
|
||||
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsMAPISendListener, nsIMsgSendListener)
|
||||
|
||||
nsresult nsMAPISendListener::CreateMAPISendListener( nsIMsgSendListener **ppListener)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(ppListener) ;
|
||||
|
||||
*ppListener = new nsMAPISendListener();
|
||||
if (! *ppListener)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*ppListener);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRBool nsMapiHook::isMapiService = PR_FALSE;
|
||||
|
||||
PRBool nsMapiHook::Initialize()
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsINativeAppSupport> native;
|
||||
|
||||
nsCOMPtr<nsICmdLineService> cmdLineArgs(do_GetService(kCmdLineServiceCID, &rv));
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIAppShellService> appShell (do_GetService( "@mozilla.org/appshell/appShellService;1", &rv));
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
|
||||
rv = appShell->GetNativeAppSupport( getter_AddRefs( native ));
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
|
||||
rv = native->EnsureProfile(cmdLineArgs);
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
void nsMapiHook::CleanUp()
|
||||
{
|
||||
// This routine will be fully implemented in future
|
||||
// to cleanup mapi related stuff inside mozilla code.
|
||||
}
|
||||
|
||||
PRBool nsMapiHook::DisplayLoginDialog(PRBool aLogin, PRUnichar **aUsername, \
|
||||
PRUnichar **aPassword)
|
||||
{
|
||||
nsresult rv;
|
||||
PRBool btnResult = PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIAppShellService> appShell(do_GetService( "@mozilla.org/appshell/appShellService;1", &rv));
|
||||
if (NS_FAILED(rv) || !appShell) return PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIPromptService> dlgService(do_GetService("@mozilla.org/embedcomp/prompt-service;1", &rv));
|
||||
if (NS_SUCCEEDED(rv) && dlgService)
|
||||
{
|
||||
nsCOMPtr<nsIStringBundleService> bundleService(do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv) || !bundleService) return PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIStringBundle> bundle;
|
||||
rv = bundleService->CreateBundle(MAPI_PROPERTIES_CHROME, getter_AddRefs(bundle));
|
||||
if (NS_FAILED(rv) || !bundle) return PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIStringBundle> brandBundle;
|
||||
rv = bundleService->CreateBundle(
|
||||
"chrome://global/locale/brand.properties",
|
||||
getter_AddRefs(brandBundle));
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
|
||||
nsXPIDLString brandName;
|
||||
rv = brandBundle->GetStringFromName(
|
||||
NS_LITERAL_STRING("brandShortName").get(),
|
||||
getter_Copies(brandName));
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
|
||||
nsXPIDLString loginTitle;
|
||||
const PRUnichar *brandStrings[] = { brandName.get() };
|
||||
NS_NAMED_LITERAL_STRING(loginTitlePropertyTag, "loginTitle");
|
||||
const PRUnichar *dTitlePropertyTag = loginTitlePropertyTag.get();
|
||||
rv = bundle->FormatStringFromName(dTitlePropertyTag, brandStrings, 1,
|
||||
getter_Copies(loginTitle));
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
|
||||
if (aLogin)
|
||||
{
|
||||
nsXPIDLString loginText;
|
||||
rv = bundle->GetStringFromName(NS_LITERAL_STRING("loginTextwithName").get(),
|
||||
getter_Copies(loginText));
|
||||
if (NS_FAILED(rv) || !loginText) return PR_FALSE;
|
||||
|
||||
|
||||
|
||||
rv = dlgService->PromptUsernameAndPassword(nsnull, loginTitle,
|
||||
loginText, aUsername, aPassword,
|
||||
nsnull, PR_FALSE, &btnResult);
|
||||
}
|
||||
else
|
||||
{
|
||||
//nsString loginString;
|
||||
nsXPIDLString loginText;
|
||||
const PRUnichar *userNameStrings[] = { *aUsername };
|
||||
|
||||
NS_NAMED_LITERAL_STRING(loginTextPropertyTag, "loginText");
|
||||
const PRUnichar *dpropertyTag = loginTextPropertyTag.get();
|
||||
rv = bundle->FormatStringFromName(dpropertyTag, userNameStrings, 1,
|
||||
getter_Copies(loginText));
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
|
||||
rv = dlgService->PromptPassword(nsnull, loginTitle, loginText,
|
||||
aPassword, nsnull, PR_FALSE, &btnResult);
|
||||
}
|
||||
}
|
||||
|
||||
return btnResult;
|
||||
}
|
||||
|
||||
PRBool nsMapiHook::VerifyUserName(const PRUnichar *aUsername, char **aIdKey)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (aUsername == nsnull)
|
||||
return PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIMsgAccountManager> accountManager(do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
nsCOMPtr<nsISupportsArray> identities;
|
||||
rv = accountManager->GetAllIdentities(getter_AddRefs(identities));
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
PRUint32 numIndentities;
|
||||
identities->Count(&numIndentities);
|
||||
|
||||
for (PRUint32 i = 0; i < numIndentities; i++)
|
||||
{
|
||||
// convert supports->Identity
|
||||
nsCOMPtr<nsISupports> thisSupports;
|
||||
rv = identities->GetElementAt(i, getter_AddRefs(thisSupports));
|
||||
if (NS_FAILED(rv)) continue;
|
||||
nsCOMPtr<nsIMsgIdentity> thisIdentity(do_QueryInterface(thisSupports, &rv));
|
||||
if (NS_SUCCEEDED(rv) && thisIdentity)
|
||||
{
|
||||
nsXPIDLCString email;
|
||||
rv = thisIdentity->GetEmail(getter_Copies(email));
|
||||
if (NS_FAILED(rv)) continue;
|
||||
|
||||
// get the username from the email and compare with the username
|
||||
nsCAutoString aEmail(email.get());
|
||||
PRInt32 index = aEmail.FindChar('@');
|
||||
if (index != -1)
|
||||
aEmail.Truncate(index);
|
||||
|
||||
if (nsDependentString(aUsername) == NS_ConvertASCIItoUCS2(aEmail)) // == overloaded
|
||||
return NS_SUCCEEDED(thisIdentity->GetKey(aIdKey));
|
||||
}
|
||||
}
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsMapiHook::IsBlindSendAllowed()
|
||||
{
|
||||
PRBool enabled = PR_FALSE;
|
||||
PRBool warn = PR_TRUE;
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
if (prefs) {
|
||||
prefs->GetBoolPref(PREF_MAPI_WARN_PRIOR_TO_BLIND_SEND,&warn);
|
||||
prefs->GetBoolPref(PREF_MAPI_BLIND_SEND_ENABLED,&enabled);
|
||||
}
|
||||
if (!enabled)
|
||||
return PR_FALSE;
|
||||
|
||||
if (!warn)
|
||||
return PR_TRUE; // Everything is okay.
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIStringBundleService> bundleService(do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv) || !bundleService) return PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIStringBundle> bundle;
|
||||
rv = bundleService->CreateBundle(MAPI_PROPERTIES_CHROME, getter_AddRefs(bundle));
|
||||
if (NS_FAILED(rv) || !bundle) return PR_FALSE;
|
||||
|
||||
nsXPIDLString warningMsg;
|
||||
rv = bundle->GetStringFromName(NS_LITERAL_STRING("mapiBlindSendWarning").get(),
|
||||
getter_Copies(warningMsg));
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
|
||||
nsXPIDLString dontShowAgainMessage;
|
||||
rv = bundle->GetStringFromName(NS_LITERAL_STRING("mapiBlindSendDontShowAgain").get(),
|
||||
getter_Copies(dontShowAgainMessage));
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIPromptService> dlgService(do_GetService("@mozilla.org/embedcomp/prompt-service;1", &rv));
|
||||
if (NS_FAILED(rv) || !dlgService) return PR_FALSE;
|
||||
|
||||
PRBool continueToWarn = PR_TRUE;
|
||||
PRBool okayToContinue = PR_FALSE;
|
||||
dlgService->ConfirmCheck(nsnull, nsnull, warningMsg, dontShowAgainMessage, &continueToWarn, &okayToContinue);
|
||||
|
||||
if (!continueToWarn && okayToContinue && prefs)
|
||||
prefs->SetBoolPref(PREF_MAPI_WARN_PRIOR_TO_BLIND_SEND,PR_FALSE);
|
||||
|
||||
return okayToContinue;
|
||||
|
||||
}
|
||||
|
||||
// this is used for Send without UI
|
||||
nsresult nsMapiHook::BlindSendMail (unsigned long aSession, nsIMsgCompFields * aCompFields)
|
||||
{
|
||||
nsresult rv = NS_OK ;
|
||||
|
||||
if (!IsBlindSendAllowed())
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
/** create nsIMsgComposeParams obj and other fields to populate it **/
|
||||
|
||||
// get parent window
|
||||
nsCOMPtr<nsIAppShellService> appService = do_GetService( "@mozilla.org/appshell/appShellService;1", &rv);
|
||||
if (NS_FAILED(rv)|| (!appService) ) return rv ;
|
||||
|
||||
nsCOMPtr<nsIDOMWindowInternal> hiddenWindow;
|
||||
rv = appService->GetHiddenDOMWindow(getter_AddRefs(hiddenWindow));
|
||||
|
||||
if ( NS_FAILED(rv) ) return rv ;
|
||||
|
||||
// smtp password and Logged in used IdKey from MapiConfig (session obj)
|
||||
nsMAPIConfiguration * pMapiConfig = nsMAPIConfiguration::GetMAPIConfiguration() ;
|
||||
if (!pMapiConfig) return NS_ERROR_FAILURE ; // get the singelton obj
|
||||
PRUnichar * password = pMapiConfig->GetPassword(aSession) ;
|
||||
// password
|
||||
nsCAutoString smtpPassword ;
|
||||
smtpPassword.AssignWithConversion (password) ;
|
||||
// Id key
|
||||
char * MsgIdKey = pMapiConfig->GetIdKey(aSession) ;
|
||||
|
||||
// get the MsgIdentity for the above key using AccountManager
|
||||
nsCOMPtr <nsIMsgAccountManager> accountManager = do_GetService (NS_MSGACCOUNTMANAGER_CONTRACTID) ;
|
||||
if (NS_FAILED(rv) || (!accountManager) ) return rv ;
|
||||
|
||||
nsCOMPtr <nsIMsgIdentity> pMsgId ;
|
||||
rv = accountManager->GetIdentity (MsgIdKey, getter_AddRefs(pMsgId)) ;
|
||||
if (NS_FAILED(rv) ) return rv ;
|
||||
|
||||
// create a send listener to get back the send status
|
||||
nsCOMPtr <nsIMsgSendListener> sendListener ;
|
||||
rv = nsMAPISendListener::CreateMAPISendListener(getter_AddRefs(sendListener)) ;
|
||||
if (NS_FAILED(rv) || (!sendListener) ) return rv;
|
||||
|
||||
// create the compose params object
|
||||
nsCOMPtr<nsIMsgComposeParams> pMsgComposeParams (do_CreateInstance(NS_MSGCOMPOSEPARAMS_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv) || (!pMsgComposeParams) ) return rv ;
|
||||
|
||||
// populate the compose params
|
||||
pMsgComposeParams->SetType(nsIMsgCompType::New);
|
||||
pMsgComposeParams->SetFormat(nsIMsgCompFormat::Default);
|
||||
pMsgComposeParams->SetIdentity(pMsgId);
|
||||
pMsgComposeParams->SetComposeFields(aCompFields);
|
||||
pMsgComposeParams->SetSendListener(sendListener) ;
|
||||
pMsgComposeParams->SetSmtpPassword(smtpPassword.get());
|
||||
|
||||
// create the nsIMsgCompose object to send the object
|
||||
nsCOMPtr<nsIMsgCompose> pMsgCompose (do_CreateInstance(NS_MSGCOMPOSE_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv) || (!pMsgCompose) ) return rv ;
|
||||
|
||||
/** initialize nsIMsgCompose, Send the message, wait for send completion response **/
|
||||
|
||||
rv = pMsgCompose->Initialize(hiddenWindow, pMsgComposeParams) ;
|
||||
if (NS_FAILED(rv)) return rv ;
|
||||
|
||||
pMsgCompose->SendMsg(nsIMsgSend::nsMsgDeliverNow, pMsgId, nsnull) ;
|
||||
if (NS_FAILED(rv)) return rv ;
|
||||
|
||||
// assign to interface pointer from nsCOMPtr to facilitate typecast below
|
||||
nsIMsgSendListener * pSendListener = sendListener ;
|
||||
|
||||
// we need to wait here to make sure that we return only after send is completed
|
||||
// so we will have a event loop here which will process the events till the Send IsDone.
|
||||
nsCOMPtr<nsIEventQueueService> pEventQService = do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID, &rv);
|
||||
nsCOMPtr<nsIEventQueue> eventQueue;
|
||||
pEventQService->GetThreadEventQueue(NS_CURRENT_THREAD,getter_AddRefs(eventQueue));
|
||||
while ( !((nsMAPISendListener *) pSendListener)->IsDone() )
|
||||
eventQueue->ProcessPendingEvents();
|
||||
|
||||
return rv ;
|
||||
}
|
||||
|
||||
// this is used to populate comp fields with Unicode data
|
||||
nsresult nsMapiHook::PopulateCompFields(lpnsMapiMessage aMessage,
|
||||
nsIMsgCompFields * aCompFields)
|
||||
{
|
||||
nsresult rv = NS_OK ;
|
||||
|
||||
if (aMessage->lpOriginator)
|
||||
{
|
||||
PRUnichar * From = aMessage->lpOriginator->lpszAddress ;
|
||||
aCompFields->SetFrom (From) ;
|
||||
}
|
||||
|
||||
nsAutoString To ;
|
||||
nsAutoString Cc ;
|
||||
nsAutoString Bcc ;
|
||||
|
||||
nsAutoString Comma ;
|
||||
Comma.AssignWithConversion(",");
|
||||
|
||||
if (aMessage->lpRecips)
|
||||
{
|
||||
for (int i=0 ; i < (int) aMessage->nRecipCount ; i++)
|
||||
{
|
||||
if (aMessage->lpRecips[i].lpszAddress)
|
||||
{
|
||||
switch (aMessage->lpRecips[i].ulRecipClass)
|
||||
{
|
||||
case MAPI_TO :
|
||||
if (To.Length() > 0)
|
||||
To += Comma ;
|
||||
To += (PRUnichar *) aMessage->lpRecips[i].lpszAddress ;
|
||||
break ;
|
||||
|
||||
case MAPI_CC :
|
||||
if (Cc.Length() > 0)
|
||||
Cc += Comma ;
|
||||
Cc += (PRUnichar *) aMessage->lpRecips[i].lpszAddress ;
|
||||
break ;
|
||||
|
||||
case MAPI_BCC :
|
||||
if (Bcc.Length() > 0)
|
||||
Bcc += Comma ;
|
||||
Bcc += (PRUnichar *) aMessage->lpRecips[i].lpszAddress ;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set To, Cc, Bcc
|
||||
aCompFields->SetTo (To.get()) ;
|
||||
aCompFields->SetCc (Cc.get()) ;
|
||||
aCompFields->SetBcc (Bcc.get()) ;
|
||||
|
||||
// set subject
|
||||
if (aMessage->lpszSubject)
|
||||
{
|
||||
PRUnichar * Subject = aMessage->lpszSubject ;
|
||||
aCompFields->SetSubject(Subject) ;
|
||||
}
|
||||
|
||||
// handle attachments as File URL
|
||||
rv = HandleAttachments (aCompFields, aMessage->nFileCount, aMessage->lpFiles, PR_TRUE) ;
|
||||
if (NS_FAILED(rv)) return rv ;
|
||||
|
||||
// set body
|
||||
if (aMessage->lpszNoteText)
|
||||
{
|
||||
PRUnichar * Body = aMessage->lpszNoteText ;
|
||||
rv = aCompFields->SetBody(Body) ;
|
||||
}
|
||||
|
||||
#ifdef RAJIV_DEBUG
|
||||
// testing what all was set in CompFields
|
||||
printf ("To : %S \n", To.get()) ;
|
||||
printf ("CC : %S \n", Cc.get() ) ;
|
||||
printf ("BCC : %S \n", Bcc.get() ) ;
|
||||
#endif
|
||||
|
||||
return rv ;
|
||||
|
||||
}
|
||||
|
||||
nsresult nsMapiHook::HandleAttachments (nsIMsgCompFields * aCompFields, PRInt32 aFileCount,
|
||||
lpnsMapiFileDesc aFiles, BOOL aIsUnicode)
|
||||
{
|
||||
nsresult rv = NS_OK ;
|
||||
|
||||
nsCAutoString Attachments ;
|
||||
nsCAutoString TempFiles ;
|
||||
|
||||
nsCOMPtr <nsILocalFile> pFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID, &rv) ;
|
||||
if (NS_FAILED(rv) || (!pFile) ) return rv ;
|
||||
|
||||
for (int i=0 ; i < aFileCount ; i++)
|
||||
{
|
||||
if (aFiles[i].lpszPathName)
|
||||
{
|
||||
// check if attachment exists
|
||||
if (aIsUnicode)
|
||||
pFile->InitWithUnicodePath (aFiles[i].lpszPathName) ;
|
||||
else
|
||||
pFile->InitWithPath ((char *) aFiles[i].lpszPathName) ;
|
||||
PRBool bExist ;
|
||||
rv = pFile->Exists(&bExist) ;
|
||||
if (NS_FAILED(rv) || (!bExist) ) return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST ;
|
||||
|
||||
// create Msg attachment object
|
||||
nsCOMPtr<nsIMsgAttachment> attachment = do_CreateInstance(NS_MSGATTACHMENT_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv) || (!attachment) ) return rv ;
|
||||
|
||||
// set url
|
||||
nsXPIDLCString pURL ;
|
||||
NS_GetURLSpecFromFile(pFile, getter_Copies(pURL));
|
||||
attachment->SetUrl(pURL) ;
|
||||
|
||||
if (aFiles[i].lpszFileName)
|
||||
{
|
||||
if (! aIsUnicode)
|
||||
{
|
||||
nsAutoString realFileName ;
|
||||
realFileName.AssignWithConversion ((char *) aFiles[i].lpszFileName) ;
|
||||
attachment->SetName(realFileName.get()) ;
|
||||
// attachment->SetName( (nsDependentString(aFiles[i].lpszFileName)).get() );
|
||||
}
|
||||
else
|
||||
attachment->SetName(aFiles[i].lpszFileName) ;
|
||||
}
|
||||
|
||||
attachment->SetTemporary(PR_FALSE) ;
|
||||
|
||||
rv = aCompFields->AddAttachment (attachment);
|
||||
}
|
||||
}
|
||||
return rv ;
|
||||
}
|
||||
|
||||
|
||||
// this is used to convert non Unicode data and then populate comp fields
|
||||
nsresult nsMapiHook::PopulateCompFieldsWithConversion(lpnsMapiMessage aMessage,
|
||||
nsIMsgCompFields * aCompFields)
|
||||
{
|
||||
nsresult rv = NS_OK ;
|
||||
|
||||
if (aMessage->lpOriginator)
|
||||
{
|
||||
nsAutoString From ;
|
||||
From.AssignWithConversion((char *) aMessage->lpOriginator->lpszAddress);
|
||||
aCompFields->SetFrom (From.get()) ;
|
||||
}
|
||||
|
||||
nsAutoString To ;
|
||||
nsAutoString Cc ;
|
||||
nsAutoString Bcc ;
|
||||
|
||||
nsAutoString Comma ;
|
||||
Comma.AssignWithConversion(",");
|
||||
|
||||
if (aMessage->lpRecips)
|
||||
{
|
||||
for (int i=0 ; i < (int) aMessage->nRecipCount ; i++)
|
||||
{
|
||||
if (aMessage->lpRecips[i].lpszAddress)
|
||||
{
|
||||
switch (aMessage->lpRecips[i].ulRecipClass)
|
||||
{
|
||||
case MAPI_TO :
|
||||
if (To.Length() > 0)
|
||||
To += Comma ;
|
||||
To.AppendWithConversion ((char *) aMessage->lpRecips[i].lpszAddress);
|
||||
break ;
|
||||
|
||||
case MAPI_CC :
|
||||
if (Cc.Length() > 0)
|
||||
Cc += Comma ;
|
||||
Cc.AppendWithConversion ((char *) aMessage->lpRecips[i].lpszAddress);
|
||||
break ;
|
||||
|
||||
case MAPI_BCC :
|
||||
if (Bcc.Length() > 0)
|
||||
Bcc += Comma ;
|
||||
Bcc.AppendWithConversion ((char *) aMessage->lpRecips[i].lpszAddress) ;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set To, Cc, Bcc
|
||||
aCompFields->SetTo (To.get()) ;
|
||||
aCompFields->SetCc (Cc.get()) ;
|
||||
aCompFields->SetBcc (Bcc.get()) ;
|
||||
|
||||
nsCAutoString platformCharSet;
|
||||
// set subject
|
||||
if (aMessage->lpszSubject)
|
||||
{
|
||||
nsAutoString Subject ;
|
||||
if (platformCharSet.IsEmpty())
|
||||
platformCharSet.Assign(nsMsgI18NFileSystemCharset());
|
||||
rv = ConvertToUnicode(platformCharSet.get(), (char *) aMessage->lpszSubject, Subject);
|
||||
if (NS_FAILED(rv)) return rv ;
|
||||
aCompFields->SetSubject(Subject.get()) ;
|
||||
}
|
||||
|
||||
// handle attachments as File URL
|
||||
rv = HandleAttachments (aCompFields, aMessage->nFileCount, aMessage->lpFiles, PR_FALSE) ;
|
||||
if (NS_FAILED(rv)) return rv ;
|
||||
|
||||
// set body
|
||||
if (aMessage->lpszNoteText)
|
||||
{
|
||||
nsAutoString Body ;
|
||||
if (platformCharSet.IsEmpty())
|
||||
platformCharSet.Assign(nsMsgI18NFileSystemCharset());
|
||||
rv = ConvertToUnicode(platformCharSet.get(), (char *) aMessage->lpszNoteText, Body);
|
||||
if (NS_FAILED(rv)) return rv ;
|
||||
rv = aCompFields->SetBody(Body.get()) ;
|
||||
}
|
||||
|
||||
#ifdef RAJIV_DEBUG
|
||||
// testing what all was set in CompFields
|
||||
printf ("To : %S \n", To.get()) ;
|
||||
printf ("CC : %S \n", Cc.get() ) ;
|
||||
printf ("BCC : %S \n", Bcc.get() ) ;
|
||||
#endif
|
||||
|
||||
return rv ;
|
||||
}
|
||||
|
||||
// this is used to populate the docs as attachments in the Comp fields for Send Documents
|
||||
nsresult nsMapiHook::PopulateCompFieldsForSendDocs(nsIMsgCompFields * aCompFields, ULONG aFlags,
|
||||
PRUnichar * aDelimChar, PRUnichar * aFilePaths)
|
||||
{
|
||||
nsAutoString strDelimChars ;
|
||||
nsString strFilePaths;
|
||||
nsresult rv = NS_OK ;
|
||||
|
||||
if (aFlags & MAPI_UNICODE)
|
||||
{
|
||||
if (aDelimChar)
|
||||
strDelimChars.Assign (aDelimChar) ;
|
||||
if (aFilePaths)
|
||||
strFilePaths.Assign (aFilePaths) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (aDelimChar)
|
||||
strDelimChars.AssignWithConversion ((char*) aDelimChar) ;
|
||||
if (aFilePaths)
|
||||
strFilePaths.AssignWithConversion ((char *) aFilePaths) ;
|
||||
}
|
||||
|
||||
// check for comma in filename
|
||||
if (strDelimChars.Find (",") == kNotFound) // if comma is not in the delimiter specified by user
|
||||
{
|
||||
if (strFilePaths.Find(",") != kNotFound) // if comma found in filenames return error
|
||||
return NS_ERROR_FILE_INVALID_PATH ;
|
||||
}
|
||||
|
||||
nsCString Attachments ;
|
||||
|
||||
// only 1 file is to be sent, no delim specified
|
||||
if ((!strDelimChars.Length()) && (strFilePaths.Length()>0))
|
||||
{
|
||||
nsCOMPtr <nsILocalFile> pFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID, &rv) ;
|
||||
if (NS_FAILED(rv) || (!pFile) ) return rv ;
|
||||
pFile->InitWithUnicodePath (strFilePaths.get()) ;
|
||||
|
||||
PRBool bExist ;
|
||||
rv = pFile->Exists(&bExist) ;
|
||||
if (NS_FAILED(rv) || (!bExist) ) return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST ;
|
||||
|
||||
nsXPIDLCString pURL ;
|
||||
NS_GetURLSpecFromFile(pFile, getter_Copies(pURL));
|
||||
if (pURL)
|
||||
Attachments.Assign(pURL) ;
|
||||
|
||||
// set attachments for comp field and return
|
||||
rv = aCompFields->SetAttachments (Attachments.get());
|
||||
return rv ;
|
||||
}
|
||||
|
||||
// multiple files to be sent, delim specified
|
||||
nsCOMPtr <nsILocalFile> pFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID, &rv) ;
|
||||
if (NS_FAILED(rv) || (!pFile) ) return rv ;
|
||||
PRInt32 offset = 0 ;
|
||||
PRInt32 FilePathsLen = strFilePaths.Length() ;
|
||||
if (FilePathsLen)
|
||||
{
|
||||
PRUnichar * newFilePaths = (PRUnichar *) strFilePaths.get() ;
|
||||
while (offset != kNotFound)
|
||||
{
|
||||
nsString RemainingPaths ;
|
||||
RemainingPaths.Assign(newFilePaths) ;
|
||||
offset = RemainingPaths.Find (strDelimChars) ;
|
||||
if (offset != kNotFound)
|
||||
{
|
||||
RemainingPaths.SetLength (offset) ;
|
||||
if ((offset + strDelimChars.Length()) < FilePathsLen)
|
||||
newFilePaths += offset + strDelimChars.Length() ;
|
||||
}
|
||||
|
||||
pFile->InitWithUnicodePath (RemainingPaths.get()) ;
|
||||
|
||||
#ifdef RAJIV_DEBUG
|
||||
printf ("File : %S \n", RemainingPaths.get()) ;
|
||||
#endif
|
||||
PRBool bExist ;
|
||||
rv = pFile->Exists(&bExist) ;
|
||||
if (NS_FAILED(rv) || (!bExist) ) return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST ;
|
||||
|
||||
nsXPIDLCString pURL ;
|
||||
NS_GetURLSpecFromFile(pFile, getter_Copies(pURL));
|
||||
if (pURL)
|
||||
{
|
||||
if (Attachments.Length() > 0)
|
||||
Attachments.Append(",") ;
|
||||
Attachments.Append(pURL) ;
|
||||
}
|
||||
}
|
||||
rv = aCompFields->SetAttachments (Attachments.get());
|
||||
}
|
||||
|
||||
return rv ;
|
||||
}
|
||||
|
||||
// this used for Send with UI
|
||||
nsresult nsMapiHook::ShowComposerWindow (unsigned long aSession, nsIMsgCompFields * aCompFields)
|
||||
{
|
||||
nsresult rv = NS_OK ;
|
||||
|
||||
// create a send listener to get back the send status
|
||||
nsCOMPtr <nsIMsgSendListener> sendListener ;
|
||||
rv = nsMAPISendListener::CreateMAPISendListener(getter_AddRefs(sendListener)) ;
|
||||
if (NS_FAILED(rv) || (!sendListener) ) return rv ;
|
||||
|
||||
// create the compose params object
|
||||
nsCOMPtr<nsIMsgComposeParams> pMsgComposeParams (do_CreateInstance(NS_MSGCOMPOSEPARAMS_CONTRACTID, &rv));
|
||||
if (NS_FAILED(rv) || (!pMsgComposeParams) ) return rv ;
|
||||
|
||||
// populate the compose params
|
||||
pMsgComposeParams->SetType(nsIMsgCompType::New);
|
||||
pMsgComposeParams->SetFormat(nsIMsgCompFormat::Default);
|
||||
pMsgComposeParams->SetComposeFields(aCompFields);
|
||||
pMsgComposeParams->SetSendListener(sendListener) ;
|
||||
|
||||
/** get the nsIMsgComposeService object to open the compose window **/
|
||||
nsCOMPtr <nsIMsgComposeService> compService = do_GetService (NS_MSGCOMPOSESERVICE_CONTRACTID) ;
|
||||
if (NS_FAILED(rv)|| (!compService) ) return rv ;
|
||||
|
||||
rv = compService->OpenComposeWindowWithParams(nsnull, pMsgComposeParams) ;
|
||||
if (NS_FAILED(rv)) return rv ;
|
||||
|
||||
return rv ;
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/* ***** 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
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
#ifndef MSG_MAPI_HOOK_H_
|
||||
#define MSG_MAPI_HOOK_H_
|
||||
|
||||
#include "prtypes.h"
|
||||
|
||||
class nsMapiHook
|
||||
{
|
||||
public :
|
||||
|
||||
static PRBool Initialize();
|
||||
static PRBool DisplayLoginDialog(PRBool aLogin, PRUnichar **aUsername,
|
||||
PRUnichar **aPassword);
|
||||
static PRBool VerifyUserName(const PRUnichar *aUsername, char **aIdKey);
|
||||
|
||||
static PRBool IsBlindSendAllowed () ;
|
||||
static nsresult BlindSendMail (unsigned long aSession, nsIMsgCompFields * aCompFields) ;
|
||||
static nsresult ShowComposerWindow (unsigned long aSession, nsIMsgCompFields * aCompFields) ;
|
||||
static nsresult PopulateCompFields(lpnsMapiMessage aMessage, nsIMsgCompFields * aCompFields) ;
|
||||
static nsresult PopulateCompFieldsWithConversion(lpnsMapiMessage aMessage,
|
||||
nsIMsgCompFields * aCompFields) ;
|
||||
static nsresult PopulateCompFieldsForSendDocs(nsIMsgCompFields * aCompFields,
|
||||
ULONG aFlags, LPTSTR aDelimChar, LPTSTR aFilePaths) ;
|
||||
static nsresult HandleAttachments (nsIMsgCompFields * aCompFields, PRInt32 aFileCount,
|
||||
lpnsMapiFileDesc aFiles, BOOL aIsUnicode) ;
|
||||
static void CleanUp();
|
||||
|
||||
static PRBool isMapiService;
|
||||
};
|
||||
|
||||
#endif // MSG_MAPI_HOOK_H_
|
||||
@@ -1,266 +0,0 @@
|
||||
/* ***** 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
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
* Contributor(s): Rajiv Dayal (rdayal@netscape.com)
|
||||
*
|
||||
* 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 <mapidefs.h>
|
||||
#include <mapi.h>
|
||||
#include "msgMapi.h"
|
||||
#include "msgMapiImp.h"
|
||||
#include "msgMapiFactory.h"
|
||||
#include "msgMapiMain.h"
|
||||
|
||||
#include "nsMsgCompFields.h"
|
||||
#include "msgMapiHook.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsMsgCompCID.h"
|
||||
|
||||
|
||||
|
||||
CMapiImp::CMapiImp()
|
||||
: m_cRef(1)
|
||||
{
|
||||
m_Lock = PR_NewLock();
|
||||
}
|
||||
|
||||
CMapiImp::~CMapiImp()
|
||||
{
|
||||
if (m_Lock)
|
||||
PR_DestroyLock(m_Lock);
|
||||
}
|
||||
|
||||
STDMETHODIMP CMapiImp::QueryInterface(const IID& aIid, void** aPpv)
|
||||
{
|
||||
if (aIid == IID_IUnknown)
|
||||
{
|
||||
*aPpv = static_cast<nsIMapi*>(this);
|
||||
}
|
||||
else if (aIid == IID_nsIMapi)
|
||||
{
|
||||
*aPpv = static_cast<nsIMapi*>(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
*aPpv = nsnull;
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
|
||||
reinterpret_cast<IUnknown*>(*aPpv)->AddRef();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP_(ULONG) CMapiImp::AddRef()
|
||||
{
|
||||
return PR_AtomicIncrement(&m_cRef);
|
||||
}
|
||||
|
||||
STDMETHODIMP_(ULONG) CMapiImp::Release()
|
||||
{
|
||||
PRInt32 temp;
|
||||
temp = PR_AtomicDecrement(&m_cRef);
|
||||
if (m_cRef == 0)
|
||||
{
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
STDMETHODIMP CMapiImp::IsValid()
|
||||
{
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CMapiImp::IsValidSession(unsigned long aSession)
|
||||
{
|
||||
nsMAPIConfiguration *pConfig = nsMAPIConfiguration::GetMAPIConfiguration();
|
||||
if (pConfig && pConfig->IsSessionValid(aSession))
|
||||
return S_OK;
|
||||
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
STDMETHODIMP CMapiImp::Initialize()
|
||||
{
|
||||
HRESULT hr = E_FAIL;
|
||||
|
||||
if (!m_Lock)
|
||||
return E_FAIL;
|
||||
|
||||
PR_Lock(m_Lock);
|
||||
|
||||
// Initialize MAPI Configuration
|
||||
|
||||
nsMAPIConfiguration *pConfig = nsMAPIConfiguration::GetMAPIConfiguration();
|
||||
if (pConfig != nsnull)
|
||||
if (nsMapiHook::Initialize())
|
||||
hr = S_OK;
|
||||
|
||||
PR_Unlock(m_Lock);
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
STDMETHODIMP CMapiImp::Login(unsigned long aUIArg, LOGIN_PW_TYPE aLogin, LOGIN_PW_TYPE aPassWord,
|
||||
unsigned long aFlags, unsigned long *aSessionId)
|
||||
{
|
||||
HRESULT hr = E_FAIL;
|
||||
PRBool bNewSession = PR_FALSE;
|
||||
char *id_key = nsnull;
|
||||
|
||||
if (aFlags & MAPI_NEW_SESSION)
|
||||
bNewSession = PR_TRUE;
|
||||
|
||||
// Check For Profile Name
|
||||
|
||||
if (aLogin != nsnull && aLogin[0] != '\0')
|
||||
{
|
||||
if (nsMapiHook::VerifyUserName(aLogin, &id_key) == PR_FALSE)
|
||||
{
|
||||
*aSessionId = MAPI_E_LOGIN_FAILURE;
|
||||
return hr;
|
||||
}
|
||||
}
|
||||
|
||||
// finally register(create) the session.
|
||||
|
||||
PRUint32 nSession_Id;
|
||||
PRInt16 nResult = 0;
|
||||
|
||||
nsMAPIConfiguration *pConfig = nsMAPIConfiguration::GetMAPIConfiguration();
|
||||
if (pConfig != nsnull)
|
||||
nResult = pConfig->RegisterSession(aUIArg, aLogin, aPassWord,
|
||||
(aFlags & MAPI_FORCE_DOWNLOAD), bNewSession,
|
||||
&nSession_Id, id_key);
|
||||
|
||||
switch (nResult)
|
||||
{
|
||||
case -1 :
|
||||
{
|
||||
*aSessionId = MAPI_E_TOO_MANY_SESSIONS;
|
||||
return hr;
|
||||
}
|
||||
case 0 :
|
||||
{
|
||||
*aSessionId = MAPI_E_INSUFFICIENT_MEMORY;
|
||||
return hr;
|
||||
}
|
||||
default :
|
||||
{
|
||||
*aSessionId = nSession_Id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CMapiImp::SendMail( unsigned long aSession, lpnsMapiMessage aMessage,
|
||||
short aRecipCount, lpnsMapiRecipDesc aRecips , short aFileCount, lpnsMapiFileDesc aFiles ,
|
||||
unsigned long aFlags, unsigned long aReserved)
|
||||
{
|
||||
nsresult rv = NS_OK ;
|
||||
|
||||
// Assign the pointers in the aMessage struct to the array of Recips and Files
|
||||
// recieved here from MS COM. These are used in BlindSendMail and ShowCompWin fns
|
||||
aMessage->lpRecips = aRecips ;
|
||||
aMessage->lpFiles = aFiles ;
|
||||
|
||||
/** create nsIMsgCompFields obj and populate it **/
|
||||
nsCOMPtr<nsIMsgCompFields> pCompFields = do_CreateInstance(NS_MSGCOMPFIELDS_CONTRACTID, &rv) ;
|
||||
if (NS_FAILED(rv) || (!pCompFields) ) return MAPI_E_INSUFFICIENT_MEMORY ;
|
||||
|
||||
if (aFlags & MAPI_UNICODE)
|
||||
rv = nsMapiHook::PopulateCompFields(aMessage, pCompFields) ;
|
||||
else
|
||||
rv = nsMapiHook::PopulateCompFieldsWithConversion(aMessage, pCompFields) ;
|
||||
|
||||
if (NS_SUCCEEDED (rv))
|
||||
{
|
||||
// see flag to see if UI needs to be brought up
|
||||
if (!(aFlags & MAPI_DIALOG))
|
||||
{
|
||||
rv = nsMapiHook::BlindSendMail(aSession, pCompFields);
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = nsMapiHook::ShowComposerWindow(aSession, pCompFields);
|
||||
}
|
||||
}
|
||||
|
||||
return nsMAPIConfiguration::GetMAPIErrorFromNSError (rv) ;
|
||||
}
|
||||
|
||||
|
||||
STDMETHODIMP CMapiImp::SendDocuments( unsigned long aSession, LPTSTR aDelimChar,
|
||||
LPTSTR aFilePaths, LPTSTR aFileNames, ULONG aFlags)
|
||||
{
|
||||
nsresult rv = NS_OK ;
|
||||
|
||||
/** create nsIMsgCompFields obj and populate it **/
|
||||
nsCOMPtr<nsIMsgCompFields> pCompFields = do_CreateInstance(NS_MSGCOMPFIELDS_CONTRACTID, &rv) ;
|
||||
if (NS_FAILED(rv) || (!pCompFields) ) return MAPI_E_INSUFFICIENT_MEMORY ;
|
||||
|
||||
if (aFilePaths)
|
||||
{
|
||||
rv = nsMapiHook::PopulateCompFieldsForSendDocs(pCompFields, aFlags, aDelimChar, aFilePaths) ;
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED (rv))
|
||||
rv = nsMapiHook::ShowComposerWindow(aSession, pCompFields);
|
||||
|
||||
return nsMAPIConfiguration::GetMAPIErrorFromNSError (rv) ;
|
||||
}
|
||||
|
||||
STDMETHODIMP CMapiImp::Logoff (unsigned long aSession)
|
||||
{
|
||||
nsMAPIConfiguration *pConfig = nsMAPIConfiguration::GetMAPIConfiguration();
|
||||
|
||||
if (pConfig->UnRegisterSession((PRUint32)aSession))
|
||||
return S_OK;
|
||||
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
STDMETHODIMP CMapiImp::CleanUp()
|
||||
{
|
||||
nsMapiHook::CleanUp();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
/* ***** 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
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
#ifndef MSG_MAPI_IMP_H
|
||||
#define MSG_MAPI_IMP_H
|
||||
|
||||
#include <windows.h>
|
||||
#include <mapi.h>
|
||||
#include "msgMapi.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nspr.h"
|
||||
|
||||
const CLSID CLSID_CMapiImp = {0x29f458be, 0x8866, 0x11d5, {0xa3, 0xdd, 0x0, 0xb0, 0xd0, 0xf3, 0xba, 0xa7}};
|
||||
|
||||
// this class implements the MS COM interface nsIMapi that provides the methods
|
||||
// called by mapi32.dll to perform the mail operations as specified by MAPI.
|
||||
// These class methods in turn use the Mozilla Mail XPCOM interfaces to do so.
|
||||
class CMapiImp : public nsIMapi
|
||||
{
|
||||
|
||||
public :
|
||||
|
||||
// IUnknown
|
||||
|
||||
STDMETHODIMP QueryInterface(const IID& aIid, void** aPpv);
|
||||
STDMETHODIMP_(ULONG) AddRef();
|
||||
STDMETHODIMP_(ULONG) Release();
|
||||
|
||||
// Interface INsMapi
|
||||
|
||||
STDMETHODIMP Login(unsigned long aUIArg, LOGIN_PW_TYPE aLogin,
|
||||
LOGIN_PW_TYPE aPassWord, unsigned long aFlags,
|
||||
unsigned long *aSessionId);
|
||||
|
||||
STDMETHODIMP SendMail( unsigned long aSession, lpnsMapiMessage aMessage,
|
||||
short aRecipCount, lpnsMapiRecipDesc aRecips ,
|
||||
short aFileCount, lpnsMapiFileDesc aFiles ,
|
||||
unsigned long aFlags, unsigned long aReserved) ;
|
||||
|
||||
STDMETHODIMP SendDocuments( unsigned long aSession, LPTSTR aDelimChar,
|
||||
LPTSTR aFilePaths, LPTSTR aFileNames, ULONG aFlags);
|
||||
|
||||
STDMETHODIMP Initialize();
|
||||
STDMETHODIMP IsValid();
|
||||
STDMETHODIMP IsValidSession(unsigned long aSession);
|
||||
|
||||
STDMETHODIMP Logoff (unsigned long aSession);
|
||||
STDMETHODIMP CleanUp();
|
||||
|
||||
CMapiImp();
|
||||
~CMapiImp();
|
||||
|
||||
private :
|
||||
|
||||
PRLock *m_Lock;
|
||||
PRInt32 m_cRef;
|
||||
};
|
||||
|
||||
#endif // MSG_MAPI_IMP_H
|
||||
@@ -1,376 +0,0 @@
|
||||
/* ***** 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
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
*
|
||||
* 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 <mapidefs.h>
|
||||
#include <mapi.h>
|
||||
|
||||
#include "msgCore.h"
|
||||
#include "nsMsgComposeStringBundle.h"
|
||||
#include "msgMapiMain.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
// move to xpcom bug 81956.
|
||||
class nsPRUintKey : public nsHashKey {
|
||||
protected:
|
||||
PRUint32 mKey;
|
||||
public:
|
||||
nsPRUintKey(PRUint32 key) : mKey(key) {}
|
||||
|
||||
PRUint32 HashCode(void) const {
|
||||
return mKey;
|
||||
}
|
||||
|
||||
PRBool Equals(const nsHashKey *aKey) const {
|
||||
return mKey == ((const nsPRUintKey *) aKey)->mKey;
|
||||
}
|
||||
nsHashKey *Clone() const {
|
||||
return new nsPRUintKey(mKey);
|
||||
}
|
||||
PRUint32 GetValue() { return mKey; }
|
||||
};
|
||||
//
|
||||
|
||||
|
||||
nsMAPIConfiguration *nsMAPIConfiguration::m_pSelfRef = nsnull;
|
||||
PRUint32 nsMAPIConfiguration::session_generator = 0;
|
||||
PRUint32 nsMAPIConfiguration::sessionCount = 0;
|
||||
|
||||
nsMAPIConfiguration *nsMAPIConfiguration::GetMAPIConfiguration()
|
||||
{
|
||||
if (m_pSelfRef == nsnull)
|
||||
m_pSelfRef = new nsMAPIConfiguration();
|
||||
|
||||
return m_pSelfRef;
|
||||
}
|
||||
|
||||
nsMAPIConfiguration::nsMAPIConfiguration()
|
||||
: m_nMaxSessions(MAX_SESSIONS)
|
||||
{
|
||||
m_Lock = PR_NewLock();
|
||||
}
|
||||
|
||||
static PRBool
|
||||
FreeSessionMapEntries(nsHashKey *aKey, void *aData, void* aClosure)
|
||||
{
|
||||
nsMAPISession *pTemp = (nsMAPISession*) aData;
|
||||
if (pTemp)
|
||||
{
|
||||
delete pTemp;
|
||||
pTemp = nsnull;
|
||||
}
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
static PRBool
|
||||
FreeProfileMapEntries(nsHashKey *aKey, void *aData, void* aClosure)
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsMAPIConfiguration::~nsMAPIConfiguration()
|
||||
{
|
||||
if (m_Lock)
|
||||
PR_DestroyLock(m_Lock);
|
||||
|
||||
m_SessionMap.Reset(FreeSessionMapEntries);
|
||||
m_ProfileMap.Reset(FreeProfileMapEntries);
|
||||
}
|
||||
|
||||
void nsMAPIConfiguration::OpenConfiguration()
|
||||
{
|
||||
// No. of max. sessions is set to MAX_SESSIONS. In future
|
||||
// if it is decided to have configuration (registry)
|
||||
// parameter, this function can be used to set the
|
||||
// max sessions;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
PRInt16 nsMAPIConfiguration::RegisterSession(PRUint32 aHwnd,
|
||||
const PRUnichar *aUserName, const PRUnichar *aPassword,
|
||||
PRBool aForceDownLoad, PRBool aNewSession,
|
||||
PRUint32 *aSession, char *aIdKey)
|
||||
{
|
||||
PRInt16 nResult = 0;
|
||||
PRUint32 n_SessionId = 0;
|
||||
|
||||
PR_Lock(m_Lock);
|
||||
|
||||
// Check whether max sessions is exceeded
|
||||
|
||||
if (sessionCount >= m_nMaxSessions)
|
||||
{
|
||||
PR_Unlock(m_Lock);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (aUserName != nsnull && aUserName[0] != '\0')
|
||||
{
|
||||
nsStringKey usernameKey(aUserName);
|
||||
n_SessionId = (PRUint32) m_ProfileMap.Get(&usernameKey);
|
||||
}
|
||||
|
||||
// try to share a session; if not create a session
|
||||
|
||||
if (n_SessionId > 0)
|
||||
{
|
||||
nsPRUintKey sessionKey(n_SessionId);
|
||||
nsMAPISession *pTemp = (nsMAPISession *)m_SessionMap.Get(&sessionKey);
|
||||
if (pTemp != nsnull)
|
||||
{
|
||||
pTemp->IncrementSession();
|
||||
*aSession = n_SessionId;
|
||||
nResult = 1;
|
||||
}
|
||||
}
|
||||
else if (aNewSession || n_SessionId == 0) // checking for n_SessionId is a concession
|
||||
{
|
||||
// create a new session ; if new session is specified OR there is no session
|
||||
nsMAPISession *pTemp = nsnull;
|
||||
pTemp = new nsMAPISession(aHwnd, aUserName,
|
||||
aPassword, aForceDownLoad, aIdKey);
|
||||
|
||||
if (pTemp != nsnull)
|
||||
{
|
||||
session_generator++;
|
||||
|
||||
// I don't think there will be (2 power 32) sessions alive
|
||||
// in a cycle. This is an assumption
|
||||
|
||||
if (session_generator == 0)
|
||||
session_generator++;
|
||||
|
||||
nsPRUintKey sessionKey(session_generator);
|
||||
m_SessionMap.Put(&sessionKey, pTemp);
|
||||
if (aUserName != nsnull && aUserName[0] != '\0')
|
||||
{
|
||||
nsStringKey usernameKey(aUserName);
|
||||
m_ProfileMap.Put(&usernameKey, (void*)session_generator);
|
||||
}
|
||||
|
||||
*aSession = session_generator;
|
||||
sessionCount++;
|
||||
nResult = 1;
|
||||
}
|
||||
}
|
||||
|
||||
PR_Unlock(m_Lock);
|
||||
return nResult;
|
||||
}
|
||||
|
||||
PRBool nsMAPIConfiguration::UnRegisterSession(PRUint32 aSessionID)
|
||||
{
|
||||
PRBool bResult = PR_FALSE;
|
||||
|
||||
PR_Lock(m_Lock);
|
||||
|
||||
if (aSessionID != 0)
|
||||
{
|
||||
nsPRUintKey sessionKey(aSessionID);
|
||||
nsMAPISession *pTemp = (nsMAPISession *)m_SessionMap.Get(&sessionKey);
|
||||
|
||||
if (pTemp != nsnull)
|
||||
{
|
||||
if (pTemp->DecrementSession() == 0)
|
||||
{
|
||||
if (pTemp->m_pProfileName.get() != nsnull)
|
||||
{
|
||||
nsStringKey stringKey(pTemp->m_pProfileName.get());
|
||||
m_ProfileMap.Remove(&stringKey);
|
||||
}
|
||||
m_SessionMap.Remove(&sessionKey);
|
||||
sessionCount--;
|
||||
bResult = PR_TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PR_Unlock(m_Lock);
|
||||
return bResult;
|
||||
}
|
||||
|
||||
PRBool nsMAPIConfiguration::IsSessionValid(PRUint32 aSessionID)
|
||||
{
|
||||
if (aSessionID == 0)
|
||||
return PR_FALSE;
|
||||
|
||||
PRBool retValue = PR_FALSE;
|
||||
nsPRUintKey sessionKey(aSessionID);
|
||||
|
||||
PR_Lock(m_Lock);
|
||||
|
||||
retValue = m_SessionMap.Exists(&sessionKey);
|
||||
|
||||
PR_Unlock(m_Lock);
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
|
||||
PRUnichar *nsMAPIConfiguration::GetPassword(PRUint32 aSessionID)
|
||||
{
|
||||
PRUnichar *pResult = nsnull;
|
||||
|
||||
PR_Lock(m_Lock);
|
||||
|
||||
if (aSessionID != 0)
|
||||
{
|
||||
nsPRUintKey sessionKey(aSessionID);
|
||||
nsMAPISession *pTemp = (nsMAPISession *)m_SessionMap.Get(&sessionKey);
|
||||
|
||||
if (pTemp)
|
||||
{
|
||||
pResult = pTemp->GetPassword();
|
||||
}
|
||||
}
|
||||
|
||||
PR_Unlock(m_Lock);
|
||||
|
||||
return pResult;
|
||||
}
|
||||
|
||||
char *nsMAPIConfiguration::GetIdKey(PRUint32 aSessionID)
|
||||
{
|
||||
char *pResult = nsnull;
|
||||
|
||||
PR_Lock(m_Lock);
|
||||
|
||||
if (aSessionID != 0)
|
||||
{
|
||||
nsPRUintKey sessionKey(aSessionID);
|
||||
nsMAPISession *pTemp = (nsMAPISession *)m_SessionMap.Get(&sessionKey);
|
||||
if (pTemp)
|
||||
{
|
||||
pResult = pTemp->GetIdKey();
|
||||
}
|
||||
}
|
||||
|
||||
PR_Unlock(m_Lock);
|
||||
return pResult;
|
||||
}
|
||||
|
||||
// util func
|
||||
HRESULT nsMAPIConfiguration::GetMAPIErrorFromNSError (nsresult res)
|
||||
{
|
||||
HRESULT hr = SUCCESS_SUCCESS ;
|
||||
|
||||
if (NS_SUCCEEDED (hr)) return hr ;
|
||||
|
||||
// if failure return the related MAPI failure code
|
||||
switch (res)
|
||||
{
|
||||
case NS_MSG_NO_RECIPIENTS :
|
||||
hr = MAPI_E_BAD_RECIPTYPE ;
|
||||
break ;
|
||||
case NS_ERROR_COULD_NOT_GET_USERS_MAIL_ADDRESS :
|
||||
hr = MAPI_E_INVALID_RECIPS ;
|
||||
break ;
|
||||
case NS_ERROR_COULD_NOT_LOGIN_TO_SMTP_SERVER :
|
||||
hr = MAPI_E_LOGIN_FAILURE ;
|
||||
break ;
|
||||
case NS_MSG_UNABLE_TO_OPEN_FILE :
|
||||
case NS_MSG_UNABLE_TO_OPEN_TMP_FILE :
|
||||
case NS_MSG_COULDNT_OPEN_FCC_FOLDER :
|
||||
case NS_ERROR_FILE_INVALID_PATH :
|
||||
hr = MAPI_E_ATTACHMENT_OPEN_FAILURE ;
|
||||
break ;
|
||||
case NS_ERROR_FILE_TARGET_DOES_NOT_EXIST :
|
||||
hr = MAPI_E_ATTACHMENT_NOT_FOUND ;
|
||||
break ;
|
||||
case NS_MSG_CANCELLING :
|
||||
hr = MAPI_E_USER_ABORT ;
|
||||
break ;
|
||||
case NS_MSG_ERROR_WRITING_FILE :
|
||||
case NS_MSG_UNABLE_TO_SAVE_TEMPLATE :
|
||||
case NS_MSG_UNABLE_TO_SAVE_DRAFT :
|
||||
hr = MAPI_E_ATTACHMENT_WRITE_FAILURE ;
|
||||
break ;
|
||||
default :
|
||||
hr = MAPI_E_FAILURE ;
|
||||
break ;
|
||||
}
|
||||
|
||||
return hr ;
|
||||
}
|
||||
|
||||
|
||||
nsMAPISession::nsMAPISession(PRUint32 aHwnd, const PRUnichar *aUserName,\
|
||||
const PRUnichar *aPassword, \
|
||||
PRBool aForceDownLoad, char *aKey)
|
||||
: m_bIsForcedDownLoad(aForceDownLoad),
|
||||
m_hAppHandle(aHwnd),
|
||||
m_nShared(1),
|
||||
m_pIdKey(aKey)
|
||||
{
|
||||
m_pProfileName.Assign(aUserName);
|
||||
m_pPassword.Assign(aPassword);
|
||||
}
|
||||
|
||||
nsMAPISession::~nsMAPISession()
|
||||
{
|
||||
if (m_pIdKey != nsnull)
|
||||
{
|
||||
delete [] m_pIdKey;
|
||||
m_pIdKey = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
PRUint32 nsMAPISession::IncrementSession()
|
||||
{
|
||||
return ++m_nShared;
|
||||
}
|
||||
|
||||
PRUint32 nsMAPISession::DecrementSession()
|
||||
{
|
||||
return --m_nShared;
|
||||
}
|
||||
|
||||
PRUint32 nsMAPISession::GetSessionCount()
|
||||
{
|
||||
return m_nShared;
|
||||
}
|
||||
|
||||
PRUnichar *nsMAPISession::GetPassword()
|
||||
{
|
||||
return (PRUnichar *)m_pPassword.get();
|
||||
}
|
||||
|
||||
char *nsMAPISession::GetIdKey()
|
||||
{
|
||||
return m_pIdKey;
|
||||
}
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
/* ***** 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
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
#ifndef MSG_MAPI_MAIN_H_
|
||||
#define NSG_MAPI_MAIN_H_
|
||||
|
||||
#define MAX_NAME_LEN 256
|
||||
#define MAX_PW_LEN 256
|
||||
#define MAX_SESSIONS 50
|
||||
#define MAPI_SENDCOMPLETE_EVENT "SendCompletionEvent"
|
||||
|
||||
#define MAPI_PROPERTIES_CHROME "chrome://messenger-mapi/locale/mapi.properties"
|
||||
#define PREF_MAPI_WARN_PRIOR_TO_BLIND_SEND "mapi.blind-send.warn"
|
||||
#define PREF_MAPI_BLIND_SEND_ENABLED "mapi.blind-send.enabled"
|
||||
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nspr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsHashtable.h"
|
||||
|
||||
class nsMAPIConfiguration
|
||||
{
|
||||
private :
|
||||
|
||||
static PRUint32 session_generator;
|
||||
static PRUint32 sessionCount;
|
||||
static nsMAPIConfiguration *m_pSelfRef;
|
||||
PRLock *m_Lock;
|
||||
PRUint32 m_nMaxSessions;
|
||||
|
||||
|
||||
nsHashtable m_ProfileMap;
|
||||
nsHashtable m_SessionMap;
|
||||
nsMAPIConfiguration();
|
||||
|
||||
public :
|
||||
static nsMAPIConfiguration *GetMAPIConfiguration();
|
||||
void OpenConfiguration();
|
||||
PRInt16 RegisterSession(PRUint32 aHwnd, const PRUnichar *aUserName, \
|
||||
const PRUnichar *aPassword, PRBool aForceDownLoad, \
|
||||
PRBool aNewSession, PRUint32 *aSession, char *aIdKey);
|
||||
PRBool IsSessionValid(PRUint32 aSessionID);
|
||||
PRBool UnRegisterSession(PRUint32 aSessionID);
|
||||
PRUnichar *GetPassword(PRUint32 aSessionID);
|
||||
char *GetIdKey(PRUint32 aSessionID);
|
||||
~nsMAPIConfiguration();
|
||||
|
||||
// a util func
|
||||
static HRESULT GetMAPIErrorFromNSError (nsresult res) ;
|
||||
};
|
||||
|
||||
class nsMAPISession
|
||||
{
|
||||
friend class nsMAPIConfiguration;
|
||||
|
||||
private :
|
||||
|
||||
PRBool m_bIsForcedDownLoad;
|
||||
PRBool m_bApp_or_Service;
|
||||
PRUint32 m_hAppHandle;
|
||||
PRUint32 m_nShared;
|
||||
char *m_pIdKey;
|
||||
nsString m_pProfileName;
|
||||
nsString m_pPassword;
|
||||
|
||||
public :
|
||||
|
||||
nsMAPISession(PRUint32 aHwnd, const PRUnichar *aUserName, \
|
||||
const PRUnichar *aPassword, \
|
||||
PRBool aForceDownLoad, char *aKey);
|
||||
PRUint32 IncrementSession();
|
||||
PRUint32 DecrementSession();
|
||||
PRUint32 GetSessionCount();
|
||||
PRUnichar *nsMAPISession::GetPassword();
|
||||
char *nsMAPISession::GetIdKey();
|
||||
~nsMAPISession();
|
||||
};
|
||||
|
||||
#endif // MSG_MAPI_MAIN_H_
|
||||
@@ -1,209 +0,0 @@
|
||||
/* ***** 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
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
*
|
||||
* 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 "nsCOMPtr.h"
|
||||
#include "objbase.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIAppStartupNotifier.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsICategoryManager.h"
|
||||
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefBranchInternal.h"
|
||||
|
||||
#include "msgMapiSupport.h"
|
||||
#include "nsMapiRegistryUtils.h"
|
||||
#include "nsMapiRegistry.h"
|
||||
#include "msgMapiImp.h"
|
||||
|
||||
/** Implementation of the nsIMapiSupport interface.
|
||||
* Use standard implementation of nsISupports stuff.
|
||||
*/
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS2(nsMapiSupport, nsIMapiSupport, nsIObserver);
|
||||
|
||||
static NS_METHOD nsMapiRegistrationProc(nsIComponentManager *aCompMgr,
|
||||
nsIFile *aPath, const char *registryLocation, const char *componentType,
|
||||
const nsModuleComponentInfo *info)
|
||||
{
|
||||
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsICategoryManager> categoryManager(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = categoryManager->AddCategoryEntry(APPSTARTUP_CATEGORY, "Mapi Support",
|
||||
"service," NS_IMAPISUPPORT_CONTRACTID, PR_TRUE, PR_TRUE, nsnull);
|
||||
|
||||
return rv ;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMapiSupport::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
|
||||
{
|
||||
nsresult rv = NS_OK ;
|
||||
|
||||
if (!nsCRT::strcmp(aTopic, "profile-after-change"))
|
||||
return InitializeMAPISupport();
|
||||
|
||||
if (!nsCRT::strcmp(aTopic, NS_XPCOM_SHUTDOWN_OBSERVER_ID))
|
||||
return ShutdownMAPISupport();
|
||||
|
||||
if (!nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID))
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch> prefs = do_QueryInterface(aSubject, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
// which preference changed?
|
||||
if (!nsCRT::strcmp(MAILNEWS_ALLOW_DEFAULT_MAIL_CLIENT, NS_ConvertUCS2toUTF8(aData).get()))
|
||||
{
|
||||
PRBool bIsDefault = PR_FALSE ;
|
||||
rv = prefs->GetBoolPref(MAILNEWS_ALLOW_DEFAULT_MAIL_CLIENT, &bIsDefault);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr <nsIMapiRegistry> mapiRegistry = do_CreateInstance(NS_IMAPIREGISTRY_CONTRACTID, &rv) ;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return mapiRegistry->SetIsDefaultMailClient(bIsDefault) ;
|
||||
}
|
||||
return rv ;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIObserverService> observerService(do_GetService("@mozilla.org/observer-service;1", &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = observerService->AddObserver(this,"profile-after-change", PR_FALSE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = observerService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_FALSE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIPrefBranchInternal> prefInternal = do_QueryInterface(prefs, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = prefInternal->AddObserver(MAILNEWS_ALLOW_DEFAULT_MAIL_CLIENT, this, PR_FALSE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsMapiSupport::nsMapiSupport()
|
||||
: m_dwRegister(0),
|
||||
m_nsMapiFactory(nsnull)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsMapiSupport::~nsMapiSupport()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMapiSupport::InitializeMAPISupport()
|
||||
{
|
||||
::CoInitialize(nsnull) ;
|
||||
|
||||
if (m_nsMapiFactory == nsnull) // No Registering if already done. Sanity Check!!
|
||||
{
|
||||
m_nsMapiFactory = new CMapiFactory();
|
||||
|
||||
if (m_nsMapiFactory != nsnull)
|
||||
{
|
||||
HRESULT hr = ::CoRegisterClassObject(CLSID_CMapiImp, \
|
||||
m_nsMapiFactory, \
|
||||
CLSCTX_LOCAL_SERVER, \
|
||||
REGCLS_MULTIPLEUSE, \
|
||||
&m_dwRegister);
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
m_nsMapiFactory->Release() ;
|
||||
m_nsMapiFactory = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMapiSupport::ShutdownMAPISupport()
|
||||
{
|
||||
if (m_dwRegister != 0)
|
||||
::CoRevokeClassObject(m_dwRegister);
|
||||
|
||||
if (m_nsMapiFactory != nsnull)
|
||||
{
|
||||
m_nsMapiFactory->Release();
|
||||
m_nsMapiFactory = nsnull;
|
||||
}
|
||||
|
||||
::CoUninitialize();
|
||||
|
||||
return NS_OK ;
|
||||
}
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMapiRegistry);
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMapiSupport);
|
||||
|
||||
// The list of components we register
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{
|
||||
NS_IMAPIREGISTRY_CLASSNAME,
|
||||
NS_IMAPIREGISTRY_CID,
|
||||
NS_IMAPIREGISTRY_CONTRACTID,
|
||||
nsMapiRegistryConstructor
|
||||
},
|
||||
|
||||
{
|
||||
NS_IMAPISUPPORT_CLASSNAME,
|
||||
NS_IMAPISUPPORT_CID,
|
||||
NS_IMAPISUPPORT_CONTRACTID,
|
||||
nsMapiSupportConstructor,
|
||||
nsMapiRegistrationProc,
|
||||
nsnull
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE(msgMapiModule, components);
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
/* ***** 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
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
# Netscape Communications Corp.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2001
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Krishna Mohan Khandrika (kkhandrika@netscape.com)
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
#ifndef MSG_MAPI_SUPPORT_H_
|
||||
#define MSG_MAPI_SUPPORT_H_
|
||||
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIMapiSupport.h"
|
||||
#include "msgMapiFactory.h"
|
||||
|
||||
#define NS_IMAPISUPPORT_CID \
|
||||
{0x8967fed2, 0xc8bb, 0x11d5, \
|
||||
{ 0xa3, 0xe9, 0x00, 0xb0, 0xd0, 0xf3, 0xba, 0xa7 }}
|
||||
|
||||
class nsMapiSupport : public nsIMapiSupport,
|
||||
public nsIObserver
|
||||
{
|
||||
public :
|
||||
nsMapiSupport();
|
||||
~nsMapiSupport();
|
||||
|
||||
// Declare all interface methods we must implement.
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
NS_DECL_NSIMAPISUPPORT
|
||||
|
||||
private :
|
||||
|
||||
DWORD m_dwRegister;
|
||||
CMapiFactory *m_nsMapiFactory;
|
||||
};
|
||||
|
||||
#endif // MSG_MAPI_SUPPORT_H_
|
||||
@@ -1,167 +0,0 @@
|
||||
/* ***** 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):
|
||||
* Srilatha Moturi <srilatha@netscape.com>
|
||||
*
|
||||
* 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 "nsIServiceManager.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIPromptService.h"
|
||||
#include "nsIProxyObjectManager.h"
|
||||
#include "nsProxiedService.h"
|
||||
|
||||
#include "nsMapiRegistryUtils.h"
|
||||
#include "nsMapiRegistry.h"
|
||||
|
||||
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
||||
|
||||
/** Implementation of the nsIMapiRegistry interface.
|
||||
* Use standard implementation of nsISupports stuff.
|
||||
*/
|
||||
NS_IMPL_ISUPPORTS1(nsMapiRegistry, nsIMapiRegistry);
|
||||
|
||||
nsMapiRegistry::nsMapiRegistry() {
|
||||
NS_INIT_ISUPPORTS();
|
||||
m_ShowDialog = ! m_registryUtils.verifyRestrictedAccess();
|
||||
m_DefaultMailClient = m_registryUtils.IsDefaultMailClient();
|
||||
}
|
||||
|
||||
nsMapiRegistry::~nsMapiRegistry() {
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMapiRegistry::GetIsDefaultMailClient(PRBool * retval) {
|
||||
// we need to get the value from registry everytime
|
||||
// because the registry settings can be changed from
|
||||
// other mail applications.
|
||||
*retval = m_registryUtils.IsDefaultMailClient();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMapiRegistry::GetShowDialog(PRBool * retval) {
|
||||
*retval = m_ShowDialog;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMapiRegistry::SetIsDefaultMailClient(PRBool aIsDefaultMailClient)
|
||||
{
|
||||
nsresult rv = NS_OK ;
|
||||
|
||||
if (aIsDefaultMailClient)
|
||||
{
|
||||
rv = m_registryUtils.setDefaultMailClient();
|
||||
if (NS_SUCCEEDED(rv))
|
||||
m_DefaultMailClient = PR_TRUE;
|
||||
else
|
||||
m_registryUtils.ShowMapiErrorDialog();
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = m_registryUtils.unsetDefaultMailClient();
|
||||
if (NS_SUCCEEDED(rv))
|
||||
m_DefaultMailClient = PR_FALSE;
|
||||
else
|
||||
m_registryUtils.ShowMapiErrorDialog();
|
||||
}
|
||||
|
||||
return rv ;
|
||||
}
|
||||
|
||||
/** This will bring up the dialog box only once per session and
|
||||
* only if the current app is not default Mail Client.
|
||||
* This also checks the registry if the registry key
|
||||
* showMapiDialog is set
|
||||
*/
|
||||
NS_IMETHODIMP
|
||||
nsMapiRegistry::ShowMailIntegrationDialog(nsIDOMWindow *aParentWindow) {
|
||||
nsresult rv;
|
||||
if (!m_ShowDialog || !m_registryUtils.getShowDialog()) return NS_OK;
|
||||
nsCOMPtr<nsIPromptService> promptService(do_GetService(
|
||||
"@mozilla.org/embedcomp/prompt-service;1", &rv));
|
||||
if (NS_SUCCEEDED(rv) && promptService)
|
||||
{
|
||||
nsCOMPtr<nsIStringBundle> bundle;
|
||||
rv = m_registryUtils.MakeMapiStringBundle (getter_AddRefs (bundle)) ;
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
nsXPIDLString dialogTitle;
|
||||
const PRUnichar *brandStrings[] = { m_registryUtils.brandName() };
|
||||
NS_NAMED_LITERAL_STRING(dialogTitlePropertyTag, "dialogTitle");
|
||||
rv = bundle->FormatStringFromName(dialogTitlePropertyTag.get(),
|
||||
brandStrings, 1,
|
||||
getter_Copies(dialogTitle));
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
nsXPIDLString dialogText;
|
||||
NS_NAMED_LITERAL_STRING(dialogTextPropertyTag, "dialogText");
|
||||
rv = bundle->FormatStringFromName(dialogTextPropertyTag.get(),
|
||||
brandStrings, 1,
|
||||
getter_Copies(dialogText));
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
nsXPIDLString checkboxText;
|
||||
rv = bundle->GetStringFromName(
|
||||
NS_LITERAL_STRING("checkboxText").get(),
|
||||
getter_Copies(checkboxText));
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
PRBool checkValue = PR_FALSE;
|
||||
PRInt32 buttonPressed = 0;
|
||||
rv = promptService->ConfirmEx(aParentWindow,
|
||||
dialogTitle,
|
||||
dialogText.get(),
|
||||
(nsIPromptService::BUTTON_TITLE_YES *
|
||||
nsIPromptService::BUTTON_POS_0) +
|
||||
(nsIPromptService::BUTTON_TITLE_NO *
|
||||
nsIPromptService::BUTTON_POS_1),
|
||||
nsnull,
|
||||
nsnull,
|
||||
nsnull,
|
||||
checkboxText,
|
||||
&checkValue,
|
||||
&buttonPressed);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
rv = m_registryUtils.SetRegistryKey(HKEY_LOCAL_MACHINE, "Software\\Mozilla\\Desktop",
|
||||
"showMapiDialog", (checkValue) ? "0" : "1");
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
m_ShowDialog = PR_FALSE;
|
||||
if (!buttonPressed)
|
||||
rv = SetIsDefaultMailClient(PR_TRUE) ; // SetDefaultMailClient();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
/* ***** 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):
|
||||
* Srilatha Moturi <srilatha@netscape.com>
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
#ifndef nsmapiregistry_h____
|
||||
#define nsmapiregistry_h____
|
||||
|
||||
#include "nsIMapiRegistry.h"
|
||||
|
||||
#ifndef MAX_BUF
|
||||
#define MAX_BUF 4096
|
||||
#endif
|
||||
|
||||
/* c5be14ba-4e0a-4eec-a1b8-04363761d63c */
|
||||
#define NS_IMAPIREGISTRY_CID \
|
||||
{ 0xc5be14ba, 0x4e0a, 0x4eec, {0xa1, 0xb8, 0x04, 0x36, 0x37, 0x61, 0xd6, 0x3c} }
|
||||
#define NS_IMAPIREGISTRY_CONTRACTID "@mozilla.org/mapiregistry;1"
|
||||
#define NS_IMAPIREGISTRY_CLASSNAME "Mozilla MAPI Registry"
|
||||
|
||||
#define MAILNEWS_ALLOW_DEFAULT_MAIL_CLIENT "mailnews.default_mail_client"
|
||||
|
||||
class nsMapiRegistry : public nsIMapiRegistry {
|
||||
public:
|
||||
// ctor/dtor
|
||||
nsMapiRegistry();
|
||||
virtual ~nsMapiRegistry();
|
||||
|
||||
// Declare all interface methods we must implement.
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIMAPIREGISTRY
|
||||
|
||||
protected:
|
||||
|
||||
PRBool m_DefaultMailClient;
|
||||
PRBool m_ShowDialog;
|
||||
nsMapiRegistryUtils m_registryUtils ;
|
||||
|
||||
private:
|
||||
// Special member to handle initialization.
|
||||
PRBool mHaveBeenSet;
|
||||
}; // nsMapiRegistry
|
||||
|
||||
#endif // nsmapiregistry_h____
|
||||
@@ -1,743 +0,0 @@
|
||||
/* ***** 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):
|
||||
* Srilatha Moturi <srilatha@netscape.com>
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
#undef UNICODE
|
||||
#undef _UNICODE
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
#include "msgMapiImp.h"
|
||||
#include "msgMapiMain.h"
|
||||
#include "nsMapiRegistryUtils.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsIPromptService.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
#include "nsDirectoryService.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsAppDirectoryServiceDefs.h"
|
||||
#include "nsIPref.h"
|
||||
|
||||
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
||||
|
||||
#define EXE_EXTENSION ".exe"
|
||||
#define USERAGENT_VERSION_PREF "general.useragent.misc"
|
||||
#define USERAGENT_VERSION_NS_PREF "general.useragent.vendorSub"
|
||||
#define USERAGENT_PREF_PREFIX "rv:"
|
||||
|
||||
nsMapiRegistryUtils::nsMapiRegistryUtils()
|
||||
{
|
||||
m_mapiStringBundle = nsnull ;
|
||||
}
|
||||
|
||||
const char * nsMapiRegistryUtils::thisApplication()
|
||||
{
|
||||
if (m_thisApp.IsEmpty()) {
|
||||
char buffer[MAX_PATH] = {0};
|
||||
DWORD len = ::GetModuleFileName(NULL, buffer, MAX_PATH);
|
||||
if (!len) return nsnull ;
|
||||
char shortPathBuf[MAX_PATH] = {0};
|
||||
len = ::GetShortPathName(buffer, shortPathBuf, MAX_PATH);
|
||||
if (!len) return nsnull ;
|
||||
m_thisApp = buffer;
|
||||
m_thisApp.ToUpperCase();
|
||||
}
|
||||
|
||||
return m_thisApp.get() ;
|
||||
}
|
||||
|
||||
const PRUnichar * nsMapiRegistryUtils::brandName()
|
||||
{
|
||||
nsresult rv;
|
||||
if (m_brand.IsEmpty()) {
|
||||
nsCOMPtr<nsIStringBundleService> bundleService(do_GetService(
|
||||
kStringBundleServiceCID, &rv));
|
||||
if (NS_SUCCEEDED(rv) && bundleService) {
|
||||
nsCOMPtr<nsIStringBundle> brandBundle;
|
||||
rv = bundleService->CreateBundle(
|
||||
"chrome://global/locale/brand.properties",
|
||||
getter_AddRefs(brandBundle));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsXPIDLString brandName;
|
||||
rv = brandBundle->GetStringFromName(
|
||||
NS_LITERAL_STRING("brandShortName").get(),
|
||||
getter_Copies(brandName));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
m_brand = brandName ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return m_brand.get() ;
|
||||
}
|
||||
|
||||
const PRUnichar * nsMapiRegistryUtils::versionNo()
|
||||
{
|
||||
if (!m_versionNo.IsEmpty())
|
||||
return m_versionNo.get() ;
|
||||
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID);
|
||||
if (prefs) {
|
||||
nsXPIDLCString versionStr ;
|
||||
nsresult rv = prefs->GetCharPref(USERAGENT_VERSION_NS_PREF, getter_Copies(versionStr));
|
||||
if (NS_SUCCEEDED(rv) && versionStr)
|
||||
m_versionNo.AssignWithConversion (versionStr.get()) ;
|
||||
else {
|
||||
rv = prefs->GetCharPref(USERAGENT_VERSION_PREF, getter_Copies(versionStr));
|
||||
if (NS_SUCCEEDED(rv) && versionStr) {
|
||||
m_versionNo.AssignWithConversion (versionStr.get()) ;
|
||||
m_versionNo.StripChars (USERAGENT_PREF_PREFIX) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return m_versionNo.get() ;
|
||||
}
|
||||
|
||||
|
||||
PRBool nsMapiRegistryUtils::verifyRestrictedAccess() {
|
||||
char subKey[] = "Software\\Mozilla - Test Key";
|
||||
PRBool result = PR_FALSE;
|
||||
DWORD dwDisp = 0;
|
||||
HKEY key;
|
||||
// Try to create/open a subkey under HKLM.
|
||||
DWORD rc = ::RegCreateKeyEx(HKEY_LOCAL_MACHINE,
|
||||
subKey,
|
||||
0,
|
||||
NULL,
|
||||
REG_OPTION_NON_VOLATILE,
|
||||
KEY_WRITE,
|
||||
NULL,
|
||||
&key,
|
||||
&dwDisp);
|
||||
|
||||
if (rc == ERROR_SUCCESS) {
|
||||
// Key was opened; first close it.
|
||||
::RegCloseKey(key);
|
||||
// Delete it if we just created it.
|
||||
switch(dwDisp) {
|
||||
case REG_CREATED_NEW_KEY:
|
||||
::RegDeleteKey(HKEY_LOCAL_MACHINE, subKey);
|
||||
break;
|
||||
case REG_OPENED_EXISTING_KEY:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// Can't create/open it; we don't have access.
|
||||
result = PR_TRUE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsMapiRegistryUtils::SetRegistryKey(HKEY baseKey, const char * keyName,
|
||||
const char * valueName, char * value)
|
||||
{
|
||||
nsresult result = NS_ERROR_FAILURE;
|
||||
HKEY key;
|
||||
LONG rc = ::RegCreateKey(baseKey, keyName, &key);
|
||||
|
||||
if (rc == ERROR_SUCCESS) {
|
||||
rc = ::RegSetValueEx(key, valueName, NULL, REG_SZ,
|
||||
(LPBYTE)(const char*)value, strlen(value));
|
||||
if (rc == ERROR_SUCCESS) {
|
||||
result = NS_OK;
|
||||
}
|
||||
::RegCloseKey(key);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult nsMapiRegistryUtils::DeleteRegistryValue(HKEY baseKey, const char * keyName,
|
||||
const char * valueName)
|
||||
{
|
||||
nsresult result = NS_ERROR_FAILURE;
|
||||
HKEY key;
|
||||
LONG rc = ::RegOpenKey(baseKey, keyName, &key);
|
||||
|
||||
if (rc == ERROR_SUCCESS) {
|
||||
rc = ::RegDeleteValue(key, valueName);
|
||||
if (rc == ERROR_SUCCESS)
|
||||
result = NS_OK;
|
||||
::RegCloseKey(key);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void nsMapiRegistryUtils::GetRegistryKey(HKEY baseKey, const char * keyName,
|
||||
const char * valueName, nsCAutoString & value)
|
||||
{
|
||||
HKEY key;
|
||||
LONG rc = ::RegOpenKey(baseKey, keyName, &key);
|
||||
if (rc == ERROR_SUCCESS) {
|
||||
char buffer[MAX_PATH] = {0};
|
||||
DWORD len = sizeof buffer;
|
||||
rc = ::RegQueryValueEx(key, valueName, NULL, NULL,
|
||||
(LPBYTE)buffer, &len);
|
||||
if (rc == ERROR_SUCCESS) {
|
||||
if (len)
|
||||
value = buffer;
|
||||
}
|
||||
::RegCloseKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
PRBool nsMapiRegistryUtils::IsDefaultMailClient()
|
||||
{
|
||||
if (!isSmartDll() && !isMozDll())
|
||||
return PR_FALSE;
|
||||
nsCAutoString name;
|
||||
GetRegistryKey(HKEY_LOCAL_MACHINE, "Software\\Clients\\Mail", "", name);
|
||||
if (!name.IsEmpty()) {
|
||||
nsCAutoString keyName("Software\\Clients\\Mail\\");
|
||||
keyName += name.get();
|
||||
keyName += "\\protocols\\mailto\\shell\\open\\command";
|
||||
|
||||
nsCAutoString result;
|
||||
GetRegistryKey(HKEY_LOCAL_MACHINE, keyName.get(), "", result);
|
||||
if (!result.IsEmpty()) {
|
||||
nsCAutoString strExtension;
|
||||
strExtension.Assign(EXE_EXTENSION);
|
||||
result.ToUpperCase();
|
||||
strExtension.ToUpperCase();
|
||||
PRInt32 index = result.RFind(strExtension.get());
|
||||
if (index != kNotFound) {
|
||||
result.Truncate(index + strExtension.Length());
|
||||
}
|
||||
nsCAutoString thisApp (thisApplication()) ;
|
||||
return (result == thisApp);
|
||||
}
|
||||
}
|
||||
return PR_FALSE;
|
||||
|
||||
}
|
||||
|
||||
nsresult nsMapiRegistryUtils::saveDefaultMailClient()
|
||||
{
|
||||
nsresult rv;
|
||||
nsCAutoString name ;
|
||||
GetRegistryKey(HKEY_LOCAL_MACHINE,"Software\\Clients\\Mail", "", name);
|
||||
if (!name.IsEmpty()) {
|
||||
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
"Software\\Mozilla\\Desktop",
|
||||
"HKEY_LOCAL_MACHINE\\Software\\Clients\\Mail",
|
||||
(char *)name.get());
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCAutoString keyName("Software\\Clients\\Mail\\");
|
||||
keyName += name.get();
|
||||
keyName += "\\protocols\\mailto\\shell\\open\\command";
|
||||
nsCAutoString appPath ;
|
||||
GetRegistryKey(HKEY_LOCAL_MACHINE, keyName.get(), "", appPath);
|
||||
if (!appPath.IsEmpty()) {
|
||||
nsCAutoString stringName("HKEY_LOCAL_MACHINE\\");
|
||||
stringName += keyName.get();
|
||||
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
"Software\\Mozilla\\Desktop",
|
||||
stringName.get(), (char *)appPath.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
"Software\\Mozilla\\Desktop",
|
||||
"HKEY_LOCAL_MACHINE\\Software\\Clients\\Mail",
|
||||
"");
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsMapiRegistryUtils::saveUserDefaultMailClient()
|
||||
{
|
||||
nsresult rv;
|
||||
nsCAutoString name ;
|
||||
GetRegistryKey(HKEY_CURRENT_USER,"Software\\Clients\\Mail", "", name);
|
||||
if (!name.IsEmpty()) {
|
||||
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
"Software\\Mozilla\\Desktop",
|
||||
"HKEY_CURRENT_USER\\Software\\Clients\\Mail",
|
||||
(char *)name.get());
|
||||
}
|
||||
else {
|
||||
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
"Software\\Mozilla\\Desktop",
|
||||
"HKEY_CURRENT_USER\\Software\\Clients\\Mail",
|
||||
"");
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether it is a smart dll or not. Smart dll is the one installed by
|
||||
* IE5 or Outlook Express which forwards the MAPI calls to the dll based on the
|
||||
* registry key setttings.
|
||||
* Returns TRUE if is a smart dll.
|
||||
*/
|
||||
|
||||
typedef HRESULT (FAR PASCAL GetOutlookVersionFunc)();
|
||||
PRBool nsMapiRegistryUtils::isSmartDll()
|
||||
{
|
||||
char buffer[MAX_PATH] = {0};
|
||||
if (GetSystemDirectory(buffer, sizeof(buffer)) == 0)
|
||||
return PR_FALSE;
|
||||
PL_strcatn(buffer, sizeof(buffer), "\\Mapi32.dll");
|
||||
|
||||
HINSTANCE hInst;
|
||||
GetOutlookVersionFunc *doesExist = nsnull;
|
||||
hInst = LoadLibrary(buffer);
|
||||
if (hInst == nsnull)
|
||||
return PR_FALSE;
|
||||
|
||||
doesExist = (GetOutlookVersionFunc *) GetProcAddress (hInst, "GetOutlookVersion");
|
||||
FreeLibrary(hInst);
|
||||
|
||||
return (doesExist != nsnull);
|
||||
}
|
||||
|
||||
typedef HRESULT (FAR PASCAL GetMapiDllVersion)();
|
||||
/**
|
||||
* Checks whether mapi32.dll is installed by this app.
|
||||
* Returns TRUE if it is.
|
||||
*/
|
||||
PRBool nsMapiRegistryUtils::isMozDll()
|
||||
{
|
||||
char buffer[MAX_PATH] = {0};
|
||||
if (GetSystemDirectory(buffer, sizeof(buffer)) == 0)
|
||||
return PR_FALSE;
|
||||
PL_strcatn(buffer, sizeof(buffer), "\\Mapi32.dll");
|
||||
|
||||
HINSTANCE hInst;
|
||||
GetMapiDllVersion *doesExist = nsnull;
|
||||
hInst = LoadLibrary(buffer);
|
||||
if (hInst == nsnull)
|
||||
return PR_FALSE;
|
||||
|
||||
doesExist = (GetMapiDllVersion *) GetProcAddress (hInst, "GetMapiDllVersion");
|
||||
FreeLibrary(hInst);
|
||||
|
||||
return (doesExist != nsnull);
|
||||
}
|
||||
|
||||
/** Renames Mapi32.dl in system directory to Mapi32_moz_bak.dll
|
||||
* copies the mozMapi32.dll from bin directory to the system directory
|
||||
*/
|
||||
nsresult nsMapiRegistryUtils::CopyMozMapiToWinSysDir()
|
||||
{
|
||||
nsresult rv;
|
||||
char buffer[MAX_PATH] = {0};
|
||||
if (GetSystemDirectory(buffer, sizeof(buffer)) == 0)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCAutoString filePath(buffer);
|
||||
filePath.Append("\\Mapi32_moz_bak.dll");
|
||||
|
||||
nsCOMPtr<nsILocalFile> pCurrentMapiFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv) || !pCurrentMapiFile) return rv;
|
||||
pCurrentMapiFile->InitWithPath(filePath.get());
|
||||
|
||||
nsCOMPtr<nsIFile> pMozMapiFile;
|
||||
nsCOMPtr<nsIProperties> directoryService =
|
||||
do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv);
|
||||
if (!directoryService) return NS_ERROR_FAILURE;
|
||||
rv = directoryService->Get(NS_OS_CURRENT_PROCESS_DIR,
|
||||
NS_GET_IID(nsIFile),
|
||||
getter_AddRefs(pMozMapiFile));
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
pMozMapiFile->Append("mozMapi32.dll");
|
||||
|
||||
PRBool bExist;
|
||||
rv = pMozMapiFile->Exists(&bExist);
|
||||
if (NS_FAILED(rv) || !bExist) return rv;
|
||||
|
||||
rv = pCurrentMapiFile->Exists(&bExist);
|
||||
if (NS_SUCCEEDED(rv) && bExist)
|
||||
{
|
||||
rv = pCurrentMapiFile->Remove(PR_FALSE);
|
||||
}
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
filePath.Assign(buffer);
|
||||
filePath.Append("\\Mapi32.dll");
|
||||
pCurrentMapiFile->InitWithPath(filePath.get());
|
||||
rv = pCurrentMapiFile->Exists(&bExist);
|
||||
if (NS_SUCCEEDED(rv) && bExist)
|
||||
{
|
||||
rv = pCurrentMapiFile->MoveTo(nsnull, "Mapi32_moz_bak.dll");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCAutoString fullFilePath(buffer);
|
||||
fullFilePath.Append("\\Mapi32_moz_bak.dll");
|
||||
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
"Software\\Mozilla\\Desktop",
|
||||
"Mapi_backup_dll",
|
||||
(char *)fullFilePath.get());
|
||||
if (NS_FAILED(rv)) {
|
||||
RestoreBackedUpMapiDll();
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
NS_NAMED_LITERAL_STRING(fileName, "Mapi32.dll");
|
||||
filePath.Assign(buffer);
|
||||
pCurrentMapiFile->InitWithPath(filePath.get());
|
||||
rv = pMozMapiFile->CopyToUnicode(pCurrentMapiFile, fileName.get());
|
||||
if (NS_FAILED(rv))
|
||||
RestoreBackedUpMapiDll();
|
||||
return rv;
|
||||
}
|
||||
|
||||
/** deletes the Mapi32.dll in system directory and renames Mapi32_moz_bak.dll
|
||||
* to Mapi32.dll
|
||||
*/
|
||||
nsresult nsMapiRegistryUtils::RestoreBackedUpMapiDll()
|
||||
{
|
||||
nsresult rv;
|
||||
char buffer[MAX_PATH] = {0};
|
||||
if (GetSystemDirectory(buffer, sizeof(buffer)) == 0)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
nsCAutoString filePath(buffer);
|
||||
nsCAutoString previousFileName(buffer);
|
||||
filePath.Append("\\Mapi32.dll");
|
||||
previousFileName.Append("\\Mapi32_moz_bak.dll");
|
||||
|
||||
nsCOMPtr <nsILocalFile> pCurrentMapiFile = do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv) || !pCurrentMapiFile) return NS_ERROR_FAILURE;
|
||||
pCurrentMapiFile->InitWithPath(filePath.get());
|
||||
|
||||
nsCOMPtr<nsILocalFile> pPreviousMapiFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv) || !pPreviousMapiFile) return NS_ERROR_FAILURE;
|
||||
pPreviousMapiFile->InitWithPath(previousFileName.get());
|
||||
|
||||
PRBool bExist;
|
||||
rv = pCurrentMapiFile->Exists(&bExist);
|
||||
if (NS_SUCCEEDED(rv) && bExist) {
|
||||
rv = pCurrentMapiFile->Remove(PR_FALSE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
rv = pPreviousMapiFile->Exists(&bExist);
|
||||
if (NS_SUCCEEDED(rv) && bExist)
|
||||
rv = pPreviousMapiFile->MoveTo(nsnull, "Mapi32.dll");
|
||||
if (NS_SUCCEEDED(rv))
|
||||
DeleteRegistryValue(HKEY_LOCAL_MACHINE,
|
||||
"Software\\Mozilla\\Desktop",
|
||||
"Mapi_backup_dll");
|
||||
return rv;
|
||||
}
|
||||
|
||||
/** Sets Mozilla as default Mail Client
|
||||
*/
|
||||
nsresult nsMapiRegistryUtils::setDefaultMailClient()
|
||||
{
|
||||
nsresult rv;
|
||||
nsresult mailKeySet=NS_ERROR_FAILURE;
|
||||
if (verifyRestrictedAccess()) return NS_ERROR_FAILURE;
|
||||
if (!isSmartDll()) {
|
||||
if (NS_FAILED(CopyMozMapiToWinSysDir())) return NS_ERROR_FAILURE;
|
||||
}
|
||||
rv = saveDefaultMailClient();
|
||||
if (NS_FAILED(saveUserDefaultMailClient()) ||
|
||||
NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
nsCAutoString keyName("Software\\Clients\\Mail\\");
|
||||
|
||||
nsCAutoString appName (NS_ConvertUCS2toUTF8(brandName()).get());
|
||||
if (!appName.IsEmpty()) {
|
||||
keyName.Append(appName.get());
|
||||
|
||||
nsCOMPtr<nsIStringBundle> bundle;
|
||||
rv = MakeMapiStringBundle (getter_AddRefs (bundle)) ;
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
nsXPIDLString defaultMailTitle;
|
||||
const PRUnichar *keyValuePrefixStr[] = { brandName(), versionNo() };
|
||||
NS_NAMED_LITERAL_STRING(defaultMailTitleTag, "defaultMailDisplayTitle");
|
||||
rv = bundle->FormatStringFromName(defaultMailTitleTag.get(),
|
||||
keyValuePrefixStr, 2,
|
||||
getter_Copies(defaultMailTitle));
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
keyName.get(),
|
||||
"", NS_CONST_CAST(char *, NS_ConvertUCS2toUTF8(defaultMailTitle).get()) ) ;
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_FAILURE;
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCAutoString thisApp (thisApplication()) ;
|
||||
if (NS_FAILED(rv)) return rv ;
|
||||
|
||||
nsCAutoString dllPath (thisApp) ;
|
||||
PRInt32 index = dllPath.RFind("\\");
|
||||
if (index != kNotFound)
|
||||
dllPath.Truncate(index + 1);
|
||||
dllPath += "mozMapi32.dll";
|
||||
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
keyName.get(), "DLLPath",
|
||||
(char *)dllPath.get());
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
keyName.Append("\\protocols\\mailto");
|
||||
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
keyName.get(),
|
||||
"", "URL:MailTo Protocol");
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCAutoString appPath (thisApp);
|
||||
appPath += " \"%1\"";
|
||||
keyName.Append("\\shell\\open\\command");
|
||||
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
keyName.get(),
|
||||
"", (char *)appPath.get());
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
"Software\\Clients\\Mail",
|
||||
"", (char *)appName.get());
|
||||
}
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCAutoString mailAppPath(thisApp);
|
||||
mailAppPath += " -mail";
|
||||
nsCAutoString appKeyName ("Software\\Clients\\Mail\\");
|
||||
appKeyName.Append(appName.get());
|
||||
appKeyName.Append("\\shell\\open\\command");
|
||||
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
appKeyName.get(),
|
||||
"", (char *)mailAppPath.get());
|
||||
}
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCAutoString iconPath(thisApp);
|
||||
iconPath += ",0";
|
||||
nsCAutoString iconKeyName ("Software\\Clients\\Mail\\");
|
||||
iconKeyName.Append(appName.get());
|
||||
iconKeyName.Append("\\DefaultIcon");
|
||||
mailKeySet = SetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
iconKeyName.get(),
|
||||
"", (char *)iconPath.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(mailKeySet)) {
|
||||
nsresult desktopKeySet = SetRegistryKey(HKEY_CURRENT_USER,
|
||||
"Software\\Clients\\Mail",
|
||||
"", (char *)appName.get());
|
||||
if (NS_SUCCEEDED(desktopKeySet)) {
|
||||
desktopKeySet = SetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
"Software\\Mozilla\\Desktop",
|
||||
"defaultMailHasBeenSet", "1");
|
||||
}
|
||||
::SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
|
||||
(LPARAM)"Software\\Clients\\Mail");
|
||||
RegisterServer(CLSID_CMapiImp, "Mozilla MAPI", "mozMapi", "mozMapi.1");
|
||||
return desktopKeySet;
|
||||
}
|
||||
|
||||
return mailKeySet;
|
||||
}
|
||||
|
||||
/** Removes Mozilla as the default Mail client and restores the previous setting
|
||||
*/
|
||||
nsresult nsMapiRegistryUtils::unsetDefaultMailClient() {
|
||||
nsresult result = NS_OK;
|
||||
nsresult mailKeySet = NS_ERROR_FAILURE;
|
||||
if (verifyRestrictedAccess()) return NS_ERROR_FAILURE;
|
||||
if (!isSmartDll()) {
|
||||
if (NS_FAILED(RestoreBackedUpMapiDll())) return NS_ERROR_FAILURE;
|
||||
}
|
||||
nsCAutoString name ;
|
||||
GetRegistryKey(HKEY_LOCAL_MACHINE, "Software\\Mozilla\\Desktop",
|
||||
"HKEY_LOCAL_MACHINE\\Software\\Clients\\Mail", name);
|
||||
nsCAutoString appName (NS_ConvertUCS2toUTF8(brandName()).get());
|
||||
|
||||
if (!name.IsEmpty() && !appName.IsEmpty() && name.Equals(appName)) {
|
||||
nsCAutoString keyName("HKEY_LOCAL_MACHINE\\Software\\Clients\\Mail\\");
|
||||
keyName.Append(appName.get());
|
||||
keyName.Append("\\protocols\\mailto\\shell\\open\\command");
|
||||
nsCAutoString appPath ;
|
||||
GetRegistryKey(HKEY_LOCAL_MACHINE, "Software\\Mozilla\\Desktop",
|
||||
keyName.get(), appPath);
|
||||
if (!appPath.IsEmpty()) {
|
||||
keyName.Assign("Software\\Clients\\Mail\\");
|
||||
keyName.Append(appName.get());
|
||||
keyName.Append("\\protocols\\mailto\\shell\\open\\command");
|
||||
result = SetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
keyName.get(),
|
||||
"", (char *)appPath.get());
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
PRInt32 index = appPath.RFind("\\");
|
||||
if (index != kNotFound)
|
||||
appPath.Truncate(index + 1);
|
||||
appPath += "mozMapi32.dll";
|
||||
keyName.Assign("Software\\Clients\\Mail\\");
|
||||
keyName.Append(appName.get());
|
||||
result = SetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
keyName.get(),
|
||||
"DLLPath", (char *) appPath.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!name.IsEmpty()) {
|
||||
if (NS_SUCCEEDED(result)) {
|
||||
mailKeySet = SetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
"Software\\Clients\\Mail",
|
||||
"", (char *)name.get());
|
||||
}
|
||||
}
|
||||
else
|
||||
mailKeySet = SetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
"Software\\Clients\\Mail",
|
||||
"", "");
|
||||
|
||||
if (NS_SUCCEEDED(mailKeySet)) {
|
||||
nsCAutoString userAppName ;
|
||||
GetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
"Software\\Mozilla\\Desktop",
|
||||
"HKEY_CURRENT_USER\\Software\\Clients\\Mail", userAppName);
|
||||
nsresult desktopKeySet = NS_OK;
|
||||
if (!userAppName.IsEmpty()) {
|
||||
desktopKeySet = SetRegistryKey(HKEY_CURRENT_USER,
|
||||
"Software\\Clients\\Mail",
|
||||
"", (char *)userAppName.get());
|
||||
}
|
||||
else {
|
||||
DeleteRegistryValue(HKEY_CURRENT_USER, "Software\\Clients\\Mail", "");
|
||||
}
|
||||
if (NS_SUCCEEDED(desktopKeySet)) {
|
||||
desktopKeySet = SetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
"Software\\Mozilla\\Desktop",
|
||||
"defaultMailHasBeenSet", "0");
|
||||
}
|
||||
::SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
|
||||
(LPARAM)"Software\\Clients\\Mail");
|
||||
UnregisterServer(CLSID_CMapiImp, "mozMapi", "mozMapi.1");
|
||||
return desktopKeySet;
|
||||
}
|
||||
return mailKeySet;
|
||||
}
|
||||
|
||||
/** Returns FALSE if showMapiDialog is set to 0.
|
||||
* Returns TRUE otherwise
|
||||
* Also returns TRUE if the Mozilla has been set as the default mail client
|
||||
* and some other application has changed that setting.
|
||||
* This function gets called only if the current app is not the default mail
|
||||
* client
|
||||
*/
|
||||
PRBool nsMapiRegistryUtils::getShowDialog() {
|
||||
PRBool rv = PR_FALSE;
|
||||
nsCAutoString showDialog ;
|
||||
GetRegistryKey(HKEY_LOCAL_MACHINE, "Software\\Mozilla\\Desktop",
|
||||
"showMapiDialog", showDialog);
|
||||
// if the user has not selected the checkbox, show dialog
|
||||
if (showDialog.IsEmpty() || showDialog.Equals("1"))
|
||||
rv = PR_TRUE;
|
||||
|
||||
if (!rv) {
|
||||
// even if the user has selected the checkbox
|
||||
// show it if some other application has changed the
|
||||
// default setting.
|
||||
nsCAutoString setMailDefault ;
|
||||
GetRegistryKey(HKEY_LOCAL_MACHINE,"Software\\Mozilla\\Desktop",
|
||||
"defaultMailHasBeenSet", setMailDefault);
|
||||
if (setMailDefault.Equals("1")) {
|
||||
// need to reset the defaultMailHasBeenSet to "0"
|
||||
// so that after the dialog is displayed once,
|
||||
// we do not keep displaying this dialog after the user has
|
||||
// selected the checkbox
|
||||
rv = SetRegistryKey(HKEY_LOCAL_MACHINE,
|
||||
"Software\\Mozilla\\Desktop",
|
||||
"defaultMailHasBeenSet", "0");
|
||||
rv = PR_TRUE;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsMapiRegistryUtils::MakeMapiStringBundle(nsIStringBundle ** aMapiStringBundle)
|
||||
{
|
||||
nsresult rv = NS_OK ;
|
||||
|
||||
if (m_mapiStringBundle)
|
||||
{
|
||||
*aMapiStringBundle = m_mapiStringBundle ;
|
||||
NS_ADDREF(*aMapiStringBundle);
|
||||
return rv ;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIStringBundleService> bundleService(do_GetService(
|
||||
kStringBundleServiceCID, &rv));
|
||||
if (NS_FAILED(rv) || !bundleService) return NS_ERROR_FAILURE;
|
||||
|
||||
rv = bundleService->CreateBundle(
|
||||
MAPI_PROPERTIES_CHROME,
|
||||
getter_AddRefs(m_mapiStringBundle));
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
NS_ADDREF(*aMapiStringBundle = m_mapiStringBundle) ;
|
||||
|
||||
return rv ;
|
||||
}
|
||||
|
||||
nsresult nsMapiRegistryUtils::ShowMapiErrorDialog()
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPromptService> promptService(do_GetService(
|
||||
"@mozilla.org/embedcomp/prompt-service;1", &rv));
|
||||
if (NS_SUCCEEDED(rv) && promptService)
|
||||
{
|
||||
nsCOMPtr<nsIStringBundle> bundle;
|
||||
rv = MakeMapiStringBundle (getter_AddRefs (bundle)) ;
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
nsXPIDLString dialogTitle;
|
||||
const PRUnichar *brandStrings[] = { brandName() };
|
||||
NS_NAMED_LITERAL_STRING(dialogTitlePropertyTag, "errorMessageTitle");
|
||||
rv = bundle->FormatStringFromName(dialogTitlePropertyTag.get(),
|
||||
brandStrings, 1,
|
||||
getter_Copies(dialogTitle));
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
nsXPIDLString dialogText;
|
||||
NS_NAMED_LITERAL_STRING(dialogTextPropertyTag, "errorMessage");
|
||||
rv = bundle->FormatStringFromName(dialogTextPropertyTag.get(),
|
||||
brandStrings, 1,
|
||||
getter_Copies(dialogText));
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
rv = promptService->Alert(nsnull, dialogTitle,
|
||||
dialogText);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
/* ***** 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):
|
||||
* Srilatha Moturi <srilatha@netscape.com>
|
||||
*
|
||||
* 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 ***** */
|
||||
|
||||
#ifndef nsmapiregistryutils_h____
|
||||
#define nsmapiregistryutils_h____
|
||||
|
||||
#include <windows.h>
|
||||
#include <string.h>
|
||||
#include <winreg.h>
|
||||
|
||||
#include "Registry.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIStringBundle.h"
|
||||
|
||||
class nsMapiRegistryUtils
|
||||
{
|
||||
private :
|
||||
nsCAutoString m_thisApp ;
|
||||
nsAutoString m_brand ;
|
||||
nsAutoString m_versionNo ;
|
||||
|
||||
nsCOMPtr<nsIStringBundle> m_mapiStringBundle ;
|
||||
public :
|
||||
nsMapiRegistryUtils() ;
|
||||
|
||||
// returns TRUE if the Mapi32.dll is smart dll.
|
||||
PRBool isSmartDll();
|
||||
// returns TRUE if the Mapi32.dll is a Mozilla dll.
|
||||
PRBool isMozDll();
|
||||
|
||||
// Returns the (fully-qualified) name of this executable.
|
||||
const char * thisApplication() ;
|
||||
// This returns the brand name for this application
|
||||
const PRUnichar * brandName() ;
|
||||
// This returns the version no for this application
|
||||
const PRUnichar * versionNo() ;
|
||||
// verifyRestrictedAccess - Returns PR_TRUE if this user only has restricted access
|
||||
// to the registry keys we need to modify.
|
||||
PRBool verifyRestrictedAccess() ;
|
||||
|
||||
// set the Windows registry key
|
||||
nsresult SetRegistryKey(HKEY baseKey, const char * keyName,
|
||||
const char * valueName, char * value);
|
||||
// delete a registry key
|
||||
nsresult DeleteRegistryValue(HKEY baseKey, const char * keyName,
|
||||
const char * valueName);
|
||||
// get a Windows registry key
|
||||
void GetRegistryKey(HKEY baseKey, const char * keyName,
|
||||
const char * valueName, nsCAutoString & value) ;
|
||||
|
||||
// Returns TRUE if the current application is default mail client.
|
||||
PRBool IsDefaultMailClient();
|
||||
// Sets Mozilla as default Mail Client
|
||||
nsresult setDefaultMailClient() ;
|
||||
// Removes Mozilla as the default Mail client and restores the previous setting
|
||||
nsresult unsetDefaultMailClient() ;
|
||||
|
||||
// Saves the current setting of the default Mail Client in
|
||||
// HKEY_LOCAL_MACHINE\\Software\\Mozilla\\Desktop
|
||||
nsresult saveDefaultMailClient();
|
||||
// Saves the current user setting of the default Mail Client in
|
||||
// HKEY_LOCAL_MACHINE\\Software\\Mozilla\\Desktop
|
||||
nsresult saveUserDefaultMailClient();
|
||||
|
||||
nsresult CopyMozMapiToWinSysDir();
|
||||
nsresult RestoreBackedUpMapiDll();
|
||||
|
||||
// Returns FALSE if showMapiDialog is set to 0.
|
||||
PRBool getShowDialog() ;
|
||||
|
||||
// create a string bundle for MAPI messages
|
||||
nsresult MakeMapiStringBundle(nsIStringBundle ** aMapiStringBundle) ;
|
||||
// display an error dialog for MAPI messages
|
||||
nsresult ShowMapiErrorDialog() ;
|
||||
|
||||
} ;
|
||||
|
||||
#endif
|
||||
@@ -1,30 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
|
||||
|
||||
<!-- list all the packages being supplied by this jar -->
|
||||
<RDF:Seq about="urn:mozilla:package:root">
|
||||
<RDF:li resource="urn:mozilla:package:messenger-mapi"/>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- package information -->
|
||||
<RDF:Description about="urn:mozilla:package:messenger-mapi"
|
||||
chrome:displayName="Messenger"
|
||||
chrome:author="mozilla.org"
|
||||
chrome:name="messenger-mapi"
|
||||
chrome:localeVersion="0.9.7"
|
||||
chrome:skinVersion="0.9.4">
|
||||
</RDF:Description>
|
||||
|
||||
<!-- overlay information -->
|
||||
<RDF:Seq about="urn:mozilla:overlays">
|
||||
<RDF:li resource="chrome://messenger/content/pref-mailnews.xul"/>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- mapi items for Mail And Newsgroups preferences pane -->
|
||||
<RDF:Seq about="chrome://messenger/content/pref-mailnews.xul">
|
||||
<RDF:li>chrome://messenger-mapi/content/pref-mailnewsOverlay.xul</RDF:li>
|
||||
</RDF:Seq>
|
||||
|
||||
</RDF:RDF>
|
||||
@@ -1,3 +0,0 @@
|
||||
messenger.jar:
|
||||
content/messenger-mapi/pref-mailnewsOverlay.xul
|
||||
content/messenger-mapi/contents.rdf
|
||||
@@ -1,29 +0,0 @@
|
||||
#!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 Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Srilatha Moturi <srilatha@netscape.com>
|
||||
#
|
||||
|
||||
DEPTH=..\..\..\..
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
chrome::
|
||||
$(REGCHROME) content messenger-mapi messenger.jar
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<RDF:RDF xmlns:chrome="http://www.mozilla.org/rdf/chrome#"
|
||||
xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
||||
|
||||
<!-- mapi items for mailnews preferences -->
|
||||
<RDF:Seq about="urn:mozilla:overlays">
|
||||
<RDF:li resource="chrome://messenger/content/pref-mailnews.xul"/>
|
||||
</RDF:Seq>
|
||||
|
||||
<RDF:Seq about="chrome://messenger/content/pref-mailnews.xul">
|
||||
<RDF:li>chrome://messenger/content/pref-mailnewsOverlay.xul</RDF:li>
|
||||
</RDF:Seq>
|
||||
|
||||
</RDF:RDF>
|
||||
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* 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 Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Srilatha Moturi <srilatha@netscape.com>
|
||||
*/
|
||||
|
||||
function mailnewsOverlayStartup() {
|
||||
mailnewsOverlayInit();
|
||||
parent.hPrefWindow.registerOKCallbackFunc(onOK);
|
||||
if (!("mapiPref" in parent)) {
|
||||
parent.mapiPref = new Object;
|
||||
parent.mapiPref.isDefaultMailClient =
|
||||
document.getElementById("mailnewsEnableMapi").checked;
|
||||
}
|
||||
else {
|
||||
// when we switch between different panes
|
||||
// set the checkbox based on the saved state
|
||||
var mailnewsEnableMapi = document.getElementById("mailnewsEnableMapi");
|
||||
if (parent.mapiPref.isDefaultMailClient)
|
||||
mailnewsEnableMapi.setAttribute("checked", "true");
|
||||
else
|
||||
mailnewsEnableMapi.setAttribute("checked", "false");
|
||||
}
|
||||
}
|
||||
|
||||
function mailnewsOverlayInit() {
|
||||
try {
|
||||
var mapiRegistry = Components.classes[ "@mozilla.org/mapiregistry;1" ].
|
||||
getService( Components.interfaces.nsIMapiRegistry );
|
||||
}
|
||||
catch(ex){
|
||||
mapiRegistry = null;
|
||||
}
|
||||
|
||||
const prefbase = "system.windows.lock_ui.";
|
||||
var mailnewsEnableMapi = document.getElementById("mailnewsEnableMapi");
|
||||
if (mapiRegistry) {
|
||||
// initialise preference component.
|
||||
// While the data is coming from the system registry, we use a set
|
||||
// of parallel preferences to indicate if the ui should be locked.
|
||||
try {
|
||||
var prefService = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService()
|
||||
.QueryInterface(Components.interfaces.nsIPrefService);
|
||||
var prefBranch = prefService.getBranch(prefbase);
|
||||
if (prefBranch && prefBranch.prefIsLocked("default_mail_client")) {
|
||||
if (prefBranch.getBoolPref("default_mail_client"))
|
||||
mapiRegistry.setDefaultMailClient();
|
||||
else
|
||||
mapiRegistry.unsetDefaultMailClient();
|
||||
mailnewsEnableMapi.setAttribute("disabled", "true");
|
||||
}
|
||||
}
|
||||
catch(ex) {}
|
||||
if (mapiRegistry.isDefaultMailClient)
|
||||
mailnewsEnableMapi.setAttribute("checked", "true");
|
||||
else
|
||||
mailnewsEnableMapi.setAttribute("checked", "false");
|
||||
}
|
||||
else
|
||||
mailnewsEnableMapi.setAttribute("disabled", "true");
|
||||
}
|
||||
|
||||
function onEnableMapi() {
|
||||
// save the state of the checkbox
|
||||
if ("mapiPref" in parent)
|
||||
parent.mapiPref.isDefaultMailClient =
|
||||
document.getElementById("mailnewsEnableMapi").checked;
|
||||
}
|
||||
|
||||
function onOK()
|
||||
{
|
||||
try {
|
||||
var mapiRegistry = Components.classes[ "@mozilla.org/mapiregistry;1" ].
|
||||
getService( Components.interfaces.nsIMapiRegistry );
|
||||
}
|
||||
catch(ex){
|
||||
mapiRegistry = null;
|
||||
}
|
||||
if (mapiRegistry &&
|
||||
("mapiPref" in parent) &&
|
||||
(mapiRegistry.isDefaultMailClient != parent.mapiPref.isDefaultMailClient)) {
|
||||
if (parent.mapiPref.isDefaultMailClient)
|
||||
mapiRegistry.setDefaultMailClient();
|
||||
else
|
||||
mapiRegistry.unsetDefaultMailClient();
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
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/
|
||||
|
||||
oftware 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) 2001 Netscape Communications Corporation. All
|
||||
Rights Reserved.
|
||||
|
||||
Contributor(s):
|
||||
Srilatha Moturi <srilatha@netscape.com>
|
||||
-->
|
||||
|
||||
<!DOCTYPE window [
|
||||
<!ENTITY % brandDTD SYSTEM "chrome://global/locale/brand.dtd" >
|
||||
%brandDTD;
|
||||
<!ENTITY % prefMailnewsOverlayDTD SYSTEM "chrome://messenger-mapi/locale/pref-mailnewsOverlay.dtd" >
|
||||
%prefMailnewsOverlayDTD;
|
||||
]>
|
||||
<overlay id="prefMailnewsOverlay"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<script type="application/x-javascript">
|
||||
<![CDATA[
|
||||
_elementIDs.push("mailnewsEnableMapi");
|
||||
]]>
|
||||
</script>
|
||||
<script type="application/x-javascript" src="chrome://messenger-mapi/content/pref-mailnewsOverlay.js"/>
|
||||
<hbox autostretch="never" id="mapi">
|
||||
<checkbox id="mailnewsEnableMapi" label="&enableMapi.label;"
|
||||
accesskey="&enableMapi.accesskey;"
|
||||
preftype="bool" prefstring="mailnews.default_mail_client" prefattribute="checked"/>
|
||||
|
||||
</hbox>
|
||||
</overlay>
|
||||
@@ -1,23 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:chrome="http://www.mozilla.org/rdf/chrome#">
|
||||
|
||||
<!-- list all the skins being supplied by this package -->
|
||||
<RDF:Seq about="urn:mozilla:locale:root">
|
||||
<RDF:li resource="urn:mozilla:locale:en-US"/>
|
||||
</RDF:Seq>
|
||||
|
||||
<!-- locale information -->
|
||||
<RDF:Description about="urn:mozilla:locale:en-US">
|
||||
<chrome:packages>
|
||||
<RDF:Seq about="urn:mozilla:locale:en-US:packages">
|
||||
<RDF:li resource="urn:mozilla:locale:en-US:messenger-mapi"/>
|
||||
</RDF:Seq>
|
||||
</chrome:packages>
|
||||
</RDF:Description>
|
||||
|
||||
<!-- Version Information. State that we work only with major version of this
|
||||
package. -->
|
||||
<RDF:Description about="urn:mozilla:locale:en-US:messenger-mapi"
|
||||
chrome:localeVersion="0.9.7"/>
|
||||
</RDF:RDF>
|
||||
@@ -1,4 +0,0 @@
|
||||
en-US.jar:
|
||||
locale/en-US/messenger-mapi/pref-mailnewsOverlay.dtd
|
||||
locale/en-US/messenger-mapi/mapi.properties
|
||||
locale/en-US/messenger-mapi/contents.rdf
|
||||
@@ -1,40 +0,0 @@
|
||||
#!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 Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Srilatha Moturi <srilatha@netscape.com>
|
||||
#
|
||||
|
||||
DEPTH=..\..\..\..\..
|
||||
|
||||
|
||||
CHROME_DIR=locales\en-US
|
||||
CHROME_L10N_DIR=messenger\locale
|
||||
|
||||
CHROME_L10N = \
|
||||
.\pref-mailnewsOverlay.dtd \
|
||||
.\mapi.properties \
|
||||
.\contents.rdf \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
chrome::
|
||||
$(REGCHROME) locale en-US/messenger-mapi en-US.jar
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
# Mail Integration Dialog
|
||||
dialogTitle=%S Mail
|
||||
dialogText=Do you want to use %S as the default mail application?
|
||||
checkboxText=Do not display this dialog again
|
||||
|
||||
# MAPI Messages
|
||||
loginText=Please enter your password for %S:
|
||||
loginTextwithName=Please enter your username and password
|
||||
loginTitle=%S Mail
|
||||
PasswordTitle=%S Mail
|
||||
|
||||
# MAPI Error Messages
|
||||
errorMessage=%S Mail could not be set as the default mail application because a registry key could not be updated. Verify with your system administrator that you have write access to your system registry, and then try again.
|
||||
errorMessageTitle=%S Mail
|
||||
|
||||
# MAPI Security Messages
|
||||
mapiBlindSendWarning=Another application is attempting to send mail using your user profile. Are you sure you want to send mail?
|
||||
mapiBlindSendDontShowAgain=Warn me whenever other applications try to send mail from me
|
||||
|
||||
#Default Mail Display String
|
||||
# localization note, $1%S is the app name, $2%S is the version
|
||||
defaultMailDisplayTitle=%S %S Mail
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
<!ENTITY enableMapiTitle.label "When sending mail from other applications">
|
||||
<!ENTITY enableMapi.label "Use &vendorShortName; Mail as the default mail application.">
|
||||
<!ENTITY enableMapi.accesskey "u">
|
||||
@@ -1,28 +0,0 @@
|
||||
#!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 Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Srilatha Moturi <srilatha@netscape.com>
|
||||
#
|
||||
|
||||
DEPTH=..\..\..\..
|
||||
|
||||
DIRS=en-US
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
@@ -1,27 +0,0 @@
|
||||
#
|
||||
# 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 Netscape are
|
||||
# Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Srilatha Moturi <srilatha@netscape.com>
|
||||
#
|
||||
|
||||
DEPTH=..\..\..
|
||||
|
||||
DIRS=content locale
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
1275
mozilla/modules/libreg/xpcom/nsRegistry.cpp
Normal file
1275
mozilla/modules/libreg/xpcom/nsRegistry.cpp
Normal file
File diff suppressed because it is too large
Load Diff
162
mozilla/string/obsolete/nsXPIDLString.cpp
Normal file
162
mozilla/string/obsolete/nsXPIDLString.cpp
Normal file
@@ -0,0 +1,162 @@
|
||||
/* -*- 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 "nsDebug.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "plstr.h"
|
||||
|
||||
// XXX change to use nsIAllocator or whatever
|
||||
#define XPIDL_STRING_ALLOC(__size) new PRUnichar[(__size)]
|
||||
#define XPIDL_CSTRING_ALLOC(__size) new char[(__size)]
|
||||
#define XPIDL_FREE(__ptr) delete[] (__ptr)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsXPIDLString
|
||||
|
||||
nsXPIDLString::nsXPIDLString()
|
||||
: mBufOwner(PR_FALSE),
|
||||
mBuf(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
nsXPIDLString::~nsXPIDLString()
|
||||
{
|
||||
if (mBufOwner && mBuf)
|
||||
XPIDL_FREE(mBuf);
|
||||
}
|
||||
|
||||
|
||||
nsXPIDLString::operator const PRUnichar*()
|
||||
{
|
||||
return mBuf;
|
||||
}
|
||||
|
||||
|
||||
PRUnichar*
|
||||
nsXPIDLString::Copy(const PRUnichar* aString)
|
||||
{
|
||||
NS_ASSERTION(aString, "null ptr");
|
||||
if (! aString)
|
||||
return 0;
|
||||
|
||||
PRInt32 len = 0;
|
||||
|
||||
{
|
||||
const PRUnichar* p = aString;
|
||||
while (*p++)
|
||||
len++;
|
||||
}
|
||||
|
||||
PRUnichar* result = XPIDL_STRING_ALLOC(len + 1);
|
||||
if (result) {
|
||||
PRUnichar* q = result;
|
||||
while (*aString) {
|
||||
*q = *aString;
|
||||
q++;
|
||||
aString++;
|
||||
}
|
||||
*q = '\0';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
PRUnichar**
|
||||
nsXPIDLString::StartAssignmentByValue()
|
||||
{
|
||||
if (mBufOwner && mBuf)
|
||||
XPIDL_FREE(mBuf);
|
||||
|
||||
mBufOwner = PR_TRUE;
|
||||
return &mBuf;
|
||||
}
|
||||
|
||||
|
||||
const PRUnichar**
|
||||
nsXPIDLString::StartAssignmentByReference()
|
||||
{
|
||||
if (mBufOwner && mBuf)
|
||||
XPIDL_FREE(mBuf);
|
||||
|
||||
mBufOwner = PR_FALSE;
|
||||
return (const PRUnichar**) &mBuf;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsXPIDLCString
|
||||
|
||||
nsXPIDLCString::nsXPIDLCString()
|
||||
: mBufOwner(PR_FALSE),
|
||||
mBuf(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
nsXPIDLCString::~nsXPIDLCString()
|
||||
{
|
||||
if (mBufOwner && mBuf)
|
||||
XPIDL_FREE(mBuf);
|
||||
}
|
||||
|
||||
|
||||
nsXPIDLCString::operator const char*()
|
||||
{
|
||||
return mBuf;
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
nsXPIDLCString::Copy(const char* aCString)
|
||||
{
|
||||
NS_ASSERTION(aCString, "null ptr");
|
||||
if (! aCString)
|
||||
return 0;
|
||||
|
||||
PRInt32 len = PL_strlen(aCString);
|
||||
char* result = XPIDL_CSTRING_ALLOC(len + 1);
|
||||
if (result)
|
||||
PL_strcpy(result, aCString);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
char**
|
||||
nsXPIDLCString::StartAssignmentByValue()
|
||||
{
|
||||
if (mBufOwner && mBuf)
|
||||
XPIDL_FREE(mBuf);
|
||||
|
||||
mBufOwner = PR_TRUE;
|
||||
return &mBuf;
|
||||
}
|
||||
|
||||
|
||||
const char**
|
||||
nsXPIDLCString::StartAssignmentByReference()
|
||||
{
|
||||
if (mBufOwner && mBuf)
|
||||
XPIDL_FREE(mBuf);
|
||||
|
||||
mBufOwner = PR_FALSE;
|
||||
return (const char**) &mBuf;
|
||||
}
|
||||
|
||||
|
||||
294
mozilla/string/obsolete/nsXPIDLString.h
Normal file
294
mozilla/string/obsolete/nsXPIDLString.h
Normal file
@@ -0,0 +1,294 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
A set of string wrapper classes that ease transition to use of XPIDL
|
||||
interfaces. nsXPIDLString and nsXPIDLCString are to XPIDL `wstring'
|
||||
and `string' out params as nsCOMPtr is to generic XPCOM interface
|
||||
pointers. They help you deal with object ownership.
|
||||
|
||||
Consider the following interface:
|
||||
|
||||
interface nsIFoo {
|
||||
attribute string Bar;
|
||||
};
|
||||
|
||||
This will generated the following C++ header file:
|
||||
|
||||
class nsIFoo {
|
||||
NS_IMETHOD SetBar(const PRUnichar* aValue);
|
||||
NS_IMETHOD GetBar(PRUnichar* *aValue);
|
||||
};
|
||||
|
||||
The GetBar() method will allocate a copy of the nsIFoo object's
|
||||
"bar" attribute, and leave you to deal with freeing it:
|
||||
|
||||
nsIFoo* aFoo; // assume we get this somehow
|
||||
PRUnichar* bar;
|
||||
aFoo->GetFoo(&bar);
|
||||
// Use bar here...
|
||||
delete[] bar;
|
||||
|
||||
(Strictly speaking, The `delete[] bar' would use the proper XPCOM
|
||||
de-allocator, we'll ignore that for now.) This makes your life
|
||||
harder, because you need to convolute your code to ensure that you
|
||||
don't leak `bar'.
|
||||
|
||||
Enter nsXPIDLString, which manages the ownership of the allocated
|
||||
string, and automatically destroys it when the nsXPIDLString goes
|
||||
out of scope:
|
||||
|
||||
nsIFoo* aFoo;
|
||||
nsXPIDLString bar;
|
||||
aFoo->GetFoo( getter_Copies(bar) );
|
||||
// Use bar here...
|
||||
|
||||
Like nsCOMPtr, nsXPIDLString uses some syntactic sugar to make it
|
||||
painfully clear exactly what the code expects. You need to wrap an
|
||||
nsXPIDLString object with either `getter_Copies()' or
|
||||
`getter_Shares()': these tell the nsXPIDLString how ownership is
|
||||
being handled. In the case of `getter_Copies()', the callee is
|
||||
allocating a copy (which is usually the case). In the case of
|
||||
`getter_Shares()', the callee is returning a const reference to `the
|
||||
real deal' (this can be done using the [shared] attribute in XPIDL).
|
||||
|
||||
*/
|
||||
|
||||
#ifndef nsXPIDLString_h__
|
||||
#define nsXPIDLString_h__
|
||||
|
||||
#include "nsCom.h"
|
||||
#include "prtypes.h"
|
||||
|
||||
#ifndef __PRUNICHAR__
|
||||
#define __PRUNICHAR__
|
||||
typedef PRUint16 PRUnichar;
|
||||
#endif /* __PRUNICHAR__ */
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsXPIDLString
|
||||
//
|
||||
// A wrapper for Unicode strings. With the |getter_Copies()| and
|
||||
// |getter_Shares()| helper functions, this can be used instead of
|
||||
// the "naked" |PRUnichar*| interface for |wstring| parameters in
|
||||
// XPIDL interfaces.
|
||||
//
|
||||
|
||||
class NS_COM nsXPIDLString {
|
||||
private:
|
||||
PRUnichar* mBuf;
|
||||
PRBool mBufOwner;
|
||||
|
||||
PRUnichar** StartAssignmentByValue();
|
||||
const PRUnichar** StartAssignmentByReference();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Construct a new, uninitialized wrapper for a Unicode string.
|
||||
*/
|
||||
nsXPIDLString();
|
||||
|
||||
virtual ~nsXPIDLString();
|
||||
|
||||
/**
|
||||
* Return an immutable reference to the Unicode string.
|
||||
*/
|
||||
operator const PRUnichar*();
|
||||
|
||||
/**
|
||||
* Make a copy of the Unicode string. Use this function in the
|
||||
* callee to ensure that the correct memory allocator is used.
|
||||
*/
|
||||
static PRUnichar* Copy(const PRUnichar* aString);
|
||||
|
||||
// A helper class for assignment-by-value. This class is an
|
||||
// implementation detail and should not be considered part of the
|
||||
// public interface.
|
||||
class NS_COM GetterCopies {
|
||||
private:
|
||||
nsXPIDLString& mXPIDLString;
|
||||
|
||||
public:
|
||||
GetterCopies(nsXPIDLString& aXPIDLString)
|
||||
: mXPIDLString(aXPIDLString) {}
|
||||
|
||||
operator PRUnichar**() {
|
||||
return mXPIDLString.StartAssignmentByValue();
|
||||
}
|
||||
|
||||
friend GetterCopies getter_Copies(nsXPIDLString& aXPIDLString);
|
||||
};
|
||||
|
||||
friend class GetterCopies;
|
||||
|
||||
// A helper class for assignment-by-reference. This class is an
|
||||
// implementation detail and should not be considered part of the
|
||||
// public interface.
|
||||
class NS_COM GetterShares {
|
||||
private:
|
||||
nsXPIDLString& mXPIDLString;
|
||||
|
||||
public:
|
||||
GetterShares(nsXPIDLString& aXPIDLString)
|
||||
: mXPIDLString(aXPIDLString) {}
|
||||
|
||||
operator const PRUnichar**() {
|
||||
return mXPIDLString.StartAssignmentByReference();
|
||||
}
|
||||
|
||||
friend GetterShares getter_Shares(nsXPIDLString& aXPIDLString);
|
||||
};
|
||||
|
||||
friend class GetterShares;
|
||||
|
||||
private:
|
||||
// not to be implemented
|
||||
nsXPIDLString(nsXPIDLString& aXPIDLString) {}
|
||||
nsXPIDLString& operator =(nsXPIDLString& aXPIDLString) { return *this; }
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Use this function to "wrap" the nsXPIDLString object that is to
|
||||
* receive an |out| value.
|
||||
*/
|
||||
inline nsXPIDLString::GetterCopies
|
||||
getter_Copies(nsXPIDLString& aXPIDLString)
|
||||
{
|
||||
return nsXPIDLString::GetterCopies(aXPIDLString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this function to "wrap" the nsXPIDLString object that is to
|
||||
* receive a |[shared] out| value.
|
||||
*/
|
||||
inline nsXPIDLString::GetterShares
|
||||
getter_Shares(nsXPIDLString& aXPIDLString)
|
||||
{
|
||||
return nsXPIDLString::GetterShares(aXPIDLString);
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsXPIDLCString
|
||||
//
|
||||
// A wrapper for Unicode strings. With the |getter_Copies()| and
|
||||
// |getter_Shares()| helper functions, this can be used instead of
|
||||
// the "naked" |char*| interface for |wstring| parameters in XPIDL
|
||||
// interfaces.
|
||||
//
|
||||
|
||||
class NS_COM nsXPIDLCString {
|
||||
private:
|
||||
char* mBuf;
|
||||
PRBool mBufOwner;
|
||||
|
||||
char** StartAssignmentByValue();
|
||||
const char** StartAssignmentByReference();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Construct a new, uninitialized wrapper for a single-byte string.
|
||||
*/
|
||||
nsXPIDLCString();
|
||||
|
||||
virtual ~nsXPIDLCString();
|
||||
|
||||
/**
|
||||
* Return an immutable reference to the single-byte string.
|
||||
*/
|
||||
operator const char*();
|
||||
|
||||
/**
|
||||
* Make a copy of the single-byte string. Use this function in the
|
||||
* callee to ensure that the correct memory allocator is used.
|
||||
*/
|
||||
static char* Copy(const char* aString);
|
||||
|
||||
// A helper class for assignment-by-value. This class is an
|
||||
// implementation detail and should not be considered part of the
|
||||
// public interface.
|
||||
class NS_COM GetterCopies {
|
||||
private:
|
||||
nsXPIDLCString& mXPIDLString;
|
||||
|
||||
public:
|
||||
GetterCopies(nsXPIDLCString& aXPIDLString)
|
||||
: mXPIDLString(aXPIDLString) {}
|
||||
|
||||
operator char**() {
|
||||
return mXPIDLString.StartAssignmentByValue();
|
||||
}
|
||||
|
||||
friend GetterCopies getter_Copies(nsXPIDLCString& aXPIDLString);
|
||||
};
|
||||
|
||||
friend class GetterCopies;
|
||||
|
||||
// A helper class for assignment-by-reference. This class is an
|
||||
// implementation detail and should not be considered part of the
|
||||
// public interface.
|
||||
class NS_COM GetterShares {
|
||||
private:
|
||||
nsXPIDLCString& mXPIDLString;
|
||||
|
||||
public:
|
||||
GetterShares(nsXPIDLCString& aXPIDLString)
|
||||
: mXPIDLString(aXPIDLString) {}
|
||||
|
||||
operator const char**() {
|
||||
return mXPIDLString.StartAssignmentByReference();
|
||||
}
|
||||
|
||||
friend GetterShares getter_Shares(nsXPIDLCString& aXPIDLString);
|
||||
};
|
||||
|
||||
friend class GetterShares;
|
||||
|
||||
private:
|
||||
// not to be implemented
|
||||
nsXPIDLCString(nsXPIDLCString& aXPIDLString) {}
|
||||
nsXPIDLCString& operator =(nsXPIDLCString& aXPIDLString) { return *this; }
|
||||
};
|
||||
|
||||
/**
|
||||
* Use this function to "wrap" the nsXPIDLCString object that is to
|
||||
* receive an |out| value.
|
||||
*/
|
||||
inline nsXPIDLCString::GetterCopies
|
||||
getter_Copies(nsXPIDLCString& aXPIDLString)
|
||||
{
|
||||
return nsXPIDLCString::GetterCopies(aXPIDLString);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Use this function to "wrap" the nsXPIDLCString object that is to
|
||||
* receive a |[shared] out| value.
|
||||
*/
|
||||
inline nsXPIDLCString::GetterShares
|
||||
getter_Shares(nsXPIDLCString& aXPIDLString)
|
||||
{
|
||||
return nsXPIDLCString::GetterShares(aXPIDLString);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // nsXPIDLString_h__
|
||||
30
mozilla/xpcom/Makefile.in
Normal file
30
mozilla/xpcom/Makefile.in
Normal file
@@ -0,0 +1,30 @@
|
||||
#!gmake
|
||||
# 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.
|
||||
|
||||
DEPTH = ..
|
||||
topsrcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
srcdir = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = public src idl libxpt
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
DIRS += tests
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
6027
mozilla/xpcom/base/IIDS.h
Normal file
6027
mozilla/xpcom/base/IIDS.h
Normal file
File diff suppressed because it is too large
Load Diff
170
mozilla/xpcom/base/nsAgg.h
Normal file
170
mozilla/xpcom/base/nsAgg.h
Normal file
@@ -0,0 +1,170 @@
|
||||
/* -*- 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 nsAgg_h___
|
||||
#define nsAgg_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
/**
|
||||
* Outer objects can implement nsIOuter if they choose, allowing them to
|
||||
* get notification if their inner objects (children) are effectively freed.
|
||||
* This allows them to reset any state associated with the inner object and
|
||||
* potentially unload it.
|
||||
*/
|
||||
class nsIOuter : public nsISupports {
|
||||
public:
|
||||
|
||||
/**
|
||||
* This method is called whenever an inner object's refcount is about to
|
||||
* become zero and the inner object should be released by the outer. This
|
||||
* allows the outer to clean up any state associated with the inner and
|
||||
* potentially unload the inner object. This method should call
|
||||
* inner->Release().
|
||||
*/
|
||||
NS_IMETHOD
|
||||
ReleaseInner(nsISupports* inner) = 0;
|
||||
|
||||
};
|
||||
|
||||
#define NS_IOUTER_IID \
|
||||
{ /* ea0bf9f0-3d67-11d2-8163-006008119d7a */ \
|
||||
0xea0bf9f0, \
|
||||
0x3d67, \
|
||||
0x11d2, \
|
||||
{0x81, 0x63, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Put this in your class's declaration:
|
||||
#define NS_DECL_AGGREGATED \
|
||||
NS_DECL_ISUPPORTS \
|
||||
\
|
||||
protected: \
|
||||
\
|
||||
/* You must implement this operation instead of the nsISupports */ \
|
||||
/* methods if you inherit from nsAggregated. */ \
|
||||
NS_IMETHOD \
|
||||
AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr); \
|
||||
\
|
||||
class Internal : public nsISupports { \
|
||||
public: \
|
||||
\
|
||||
Internal() {} \
|
||||
\
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, \
|
||||
void** aInstancePtr); \
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void); \
|
||||
NS_IMETHOD_(nsrefcnt) Release(void); \
|
||||
\
|
||||
}; \
|
||||
\
|
||||
friend class Internal; \
|
||||
\
|
||||
nsISupports* fOuter; \
|
||||
Internal fAggregated; \
|
||||
\
|
||||
nsISupports* GetInner(void) { return &fAggregated; } \
|
||||
\
|
||||
public: \
|
||||
|
||||
|
||||
// Put this in your class's constructor:
|
||||
#define NS_INIT_AGGREGATED(outer) \
|
||||
PR_BEGIN_MACRO \
|
||||
NS_INIT_REFCNT(); \
|
||||
fOuter = outer; \
|
||||
PR_END_MACRO
|
||||
|
||||
|
||||
// Put this in your class's implementation file:
|
||||
#define NS_IMPL_AGGREGATED(_class) \
|
||||
NS_IMETHODIMP \
|
||||
_class::QueryInterface(const nsIID& aIID, void** aInstancePtr) \
|
||||
{ \
|
||||
/* try our own interfaces first before delegating to outer */ \
|
||||
nsresult rslt = AggregatedQueryInterface(aIID, aInstancePtr); \
|
||||
if (rslt != NS_OK && fOuter) \
|
||||
return fOuter->QueryInterface(aIID, aInstancePtr); \
|
||||
else \
|
||||
return rslt; \
|
||||
} \
|
||||
\
|
||||
NS_IMETHODIMP_(nsrefcnt) \
|
||||
_class::AddRef(void) \
|
||||
{ \
|
||||
++mRefCnt; /* keep track of our refcount as well as outer's */ \
|
||||
if (fOuter) \
|
||||
return NS_ADDREF(fOuter); \
|
||||
else \
|
||||
return mRefCnt; \
|
||||
} \
|
||||
\
|
||||
NS_IMETHODIMP_(nsrefcnt) \
|
||||
_class::Release(void) \
|
||||
{ \
|
||||
if (fOuter) { \
|
||||
nsISupports* outer = fOuter; /* in case we release ourself */ \
|
||||
nsIOuter* outerIntf; \
|
||||
static NS_DEFINE_IID(kIOuterIID, NS_IOUTER_IID); \
|
||||
if (mRefCnt == 1 && \
|
||||
outer->QueryInterface(kIOuterIID, \
|
||||
(void**)&outerIntf) == NS_OK) { \
|
||||
outerIntf->ReleaseInner(GetInner()); \
|
||||
outerIntf->Release(); \
|
||||
} \
|
||||
else \
|
||||
--mRefCnt; /* keep track of our refcount as well as outer's */ \
|
||||
return outer->Release(); \
|
||||
} \
|
||||
else { \
|
||||
if (--mRefCnt == 0) { \
|
||||
delete this; \
|
||||
return 0; \
|
||||
} \
|
||||
return mRefCnt; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
NS_IMETHODIMP \
|
||||
_class::Internal::QueryInterface(const nsIID& aIID, void** aInstancePtr) \
|
||||
{ \
|
||||
_class* agg = (_class*)((char*)(this) - offsetof(_class, fAggregated)); \
|
||||
return agg->AggregatedQueryInterface(aIID, aInstancePtr); \
|
||||
} \
|
||||
\
|
||||
NS_IMETHODIMP_(nsrefcnt) \
|
||||
_class::Internal::AddRef(void) \
|
||||
{ \
|
||||
_class* agg = (_class*)((char*)(this) - offsetof(_class, fAggregated)); \
|
||||
return ++agg->mRefCnt; \
|
||||
} \
|
||||
\
|
||||
NS_IMETHODIMP_(nsrefcnt) \
|
||||
_class::Internal::Release(void) \
|
||||
{ \
|
||||
_class* agg = (_class*)((char*)(this) - offsetof(_class, fAggregated)); \
|
||||
if (--agg->mRefCnt == 0) { \
|
||||
delete agg; \
|
||||
return 0; \
|
||||
} \
|
||||
return agg->mRefCnt; \
|
||||
} \
|
||||
|
||||
#endif /* nsAgg_h___ */
|
||||
129
mozilla/xpcom/base/nsAllocator.cpp
Normal file
129
mozilla/xpcom/base/nsAllocator.cpp
Normal file
@@ -0,0 +1,129 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Implementation of nsIAllocator using NSPR
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "nsAllocator.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIAllocatorIID, NS_IALLOCATOR_IID);
|
||||
|
||||
nsAllocator::nsAllocator(nsISupports* outer)
|
||||
{
|
||||
NS_INIT_AGGREGATED(outer);
|
||||
}
|
||||
|
||||
nsAllocator::~nsAllocator(void)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_AGGREGATED(nsAllocator);
|
||||
|
||||
NS_METHOD
|
||||
nsAllocator::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(kIAllocatorIID) ||
|
||||
aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*) this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsAllocator::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
|
||||
{
|
||||
if (outer && !aIID.Equals(kISupportsIID))
|
||||
return NS_NOINTERFACE; // XXX right error?
|
||||
nsAllocator* mm = new nsAllocator(outer);
|
||||
if (mm == NULL)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
mm->AddRef();
|
||||
if (aIID.Equals(kISupportsIID))
|
||||
*aInstancePtr = mm->GetInner();
|
||||
else
|
||||
*aInstancePtr = mm;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_METHOD_(void*)
|
||||
nsAllocator::Alloc(PRUint32 size)
|
||||
{
|
||||
return PR_Malloc(size);
|
||||
}
|
||||
|
||||
NS_METHOD_(void*)
|
||||
nsAllocator::Realloc(void* ptr, PRUint32 size)
|
||||
{
|
||||
return PR_Realloc(ptr, size);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsAllocator::Free(void* ptr)
|
||||
{
|
||||
PR_Free(ptr);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsAllocator::HeapMinimize(void)
|
||||
{
|
||||
#ifdef XP_MAC
|
||||
// This used to live in the memory allocators no Mac, but does no more
|
||||
// Needs to be hooked up in the new world.
|
||||
// CallCacheFlushers(0x7fffffff);
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsAllocatorFactory::nsAllocatorFactory(void)
|
||||
{
|
||||
}
|
||||
|
||||
nsAllocatorFactory::~nsAllocatorFactory(void)
|
||||
{
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
NS_IMPL_ISUPPORTS(nsAllocatorFactory, kIFactoryIID);
|
||||
|
||||
NS_METHOD
|
||||
nsAllocatorFactory::CreateInstance(nsISupports *aOuter,
|
||||
REFNSIID aIID,
|
||||
void **aResult)
|
||||
{
|
||||
return nsAllocator::Create(aOuter, aIID, aResult);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsAllocatorFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
return NS_OK; // XXX what?
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
92
mozilla/xpcom/base/nsAllocator.h
Normal file
92
mozilla/xpcom/base/nsAllocator.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Implementation of nsIAllocator using NSPR
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef nsAllocator_h__
|
||||
#define nsAllocator_h__
|
||||
|
||||
#include "nsIAllocator.h"
|
||||
#include "prmem.h"
|
||||
#include "nsAgg.h"
|
||||
#include "nsIFactory.h"
|
||||
|
||||
class nsAllocator : public nsIAllocator {
|
||||
public:
|
||||
static const nsCID& CID() { static nsCID cid = NS_ALLOCATOR_CID; return cid; }
|
||||
|
||||
/**
|
||||
* Allocates a block of memory of a particular size.
|
||||
*
|
||||
* @param size - the size of the block to allocate
|
||||
* @result the block of memory
|
||||
*/
|
||||
NS_IMETHOD_(void*) Alloc(PRUint32 size);
|
||||
|
||||
/**
|
||||
* Reallocates a block of memory to a new size.
|
||||
*
|
||||
* @param ptr - the block of memory to reallocate
|
||||
* @param size - the new size
|
||||
* @result the rellocated block of memory
|
||||
*/
|
||||
NS_IMETHOD_(void*) Realloc(void* ptr, PRUint32 size);
|
||||
|
||||
/**
|
||||
* Frees a block of memory.
|
||||
*
|
||||
* @param ptr - the block of memory to free
|
||||
*/
|
||||
NS_IMETHOD Free(void* ptr);
|
||||
|
||||
/**
|
||||
* Attempts to shrink the heap.
|
||||
*/
|
||||
NS_IMETHOD HeapMinimize(void);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsAllocator(nsISupports* outer);
|
||||
virtual ~nsAllocator(void);
|
||||
|
||||
NS_DECL_AGGREGATED
|
||||
|
||||
static NS_METHOD
|
||||
Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsAllocatorFactory : public nsIFactory {
|
||||
public:
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
REFNSIID aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
nsAllocatorFactory(void);
|
||||
~nsAllocatorFactory(void);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#endif // nsAllocator_h__
|
||||
54
mozilla/xpcom/base/nsCOMPtr.cpp
Normal file
54
mozilla/xpcom/base/nsCOMPtr.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
void
|
||||
nsCOMPtr_base::assign_with_AddRef( nsISupports* rawPtr )
|
||||
{
|
||||
if ( rawPtr )
|
||||
NSCAP_ADDREF(rawPtr);
|
||||
if ( mRawPtr )
|
||||
NSCAP_RELEASE(mRawPtr);
|
||||
mRawPtr = rawPtr;
|
||||
}
|
||||
|
||||
void
|
||||
nsCOMPtr_base::assign_with_QueryInterface( nsISupports* rawPtr, const nsIID& iid, nsresult* result )
|
||||
{
|
||||
nsresult status = NS_OK;
|
||||
if ( !rawPtr || !NS_SUCCEEDED( status = rawPtr->QueryInterface(iid, NSCAP_REINTERPRET_CAST(void**, &rawPtr)) ) )
|
||||
rawPtr = 0;
|
||||
|
||||
if ( mRawPtr )
|
||||
NSCAP_RELEASE(mRawPtr);
|
||||
|
||||
mRawPtr = rawPtr;
|
||||
|
||||
if ( result )
|
||||
*result = status;
|
||||
}
|
||||
|
||||
void**
|
||||
nsCOMPtr_base::begin_assignment()
|
||||
{
|
||||
if ( mRawPtr )
|
||||
NSCAP_RELEASE(mRawPtr);
|
||||
mRawPtr = 0;
|
||||
return NSCAP_REINTERPRET_CAST(void**, &mRawPtr);
|
||||
}
|
||||
493
mozilla/xpcom/base/nsCOMPtr.h
Normal file
493
mozilla/xpcom/base/nsCOMPtr.h
Normal file
@@ -0,0 +1,493 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#ifndef nsCOMPtr_h___
|
||||
#define nsCOMPtr_h___
|
||||
|
||||
|
||||
|
||||
// Wrapping includes can speed up compiles (see "Large Scale C++ Software Design")
|
||||
#ifndef nsDebug_h___
|
||||
#include "nsDebug.h"
|
||||
// for |NS_PRECONDITION|
|
||||
#endif
|
||||
|
||||
#ifndef nsISupports_h___
|
||||
#include "nsISupports.h"
|
||||
// for |nsresult|, |NS_ADDREF|, et al
|
||||
#endif
|
||||
|
||||
/*
|
||||
Having problems?
|
||||
|
||||
See the User Manual at:
|
||||
<http://www.meer.net/ScottCollins/doc/nsCOMPtr.html>, or
|
||||
<http://www.mozilla.org/projects/xpcom/nsCOMPtr.html>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
TO DO...
|
||||
|
||||
+ make StartAssignment optionally inlined
|
||||
+ make constructor for |nsQueryInterface| explicit (suddenly construct/assign from raw pointer becomes illegal)
|
||||
+ Improve internal documentation
|
||||
+ mention *&
|
||||
+ alternatives for comparison
|
||||
+ do_QueryInterface
|
||||
*/
|
||||
|
||||
/*
|
||||
WARNING:
|
||||
This file defines several macros for internal use only. These macros begin with the
|
||||
prefix |NSCAP_|. Do not use these macros in your own code. They are for internal use
|
||||
only for cross-platform compatibility, and are subject to change without notice.
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
Set up some |#define|s to turn off a couple of troublesome C++ features.
|
||||
Interestingly, none of the compilers barf on template stuff. These are set up automatically
|
||||
by the autoconf system for all Unixes. (Temporarily, I hope) I have to define them
|
||||
myself for Mac and Windows.
|
||||
*/
|
||||
|
||||
// under Metrowerks (Mac), we don't have autoconf yet
|
||||
#ifdef __MWERKS__
|
||||
#define HAVE_CPP_USING
|
||||
#define HAVE_CPP_EXPLICIT
|
||||
#define HAVE_CPP_NEW_CASTS
|
||||
#endif
|
||||
|
||||
// under VC++ (Windows), we don't have autoconf yet
|
||||
#ifdef _MSC_VER
|
||||
#define HAVE_CPP_EXPLICIT
|
||||
#define HAVE_CPP_USING
|
||||
#define HAVE_CPP_NEW_CASTS
|
||||
|
||||
#if (_MSC_VER<1100)
|
||||
// before 5.0, VC++ couldn't handle explicit
|
||||
#undef HAVE_CPP_EXPLICIT
|
||||
#elif (_MSC_VER==1100)
|
||||
// VC++5.0 has an internal compiler error (sometimes) without this
|
||||
#undef HAVE_CPP_USING
|
||||
#endif
|
||||
|
||||
#define NSCAP_FEATURE_INLINE_STARTASSIGNMENT
|
||||
// under VC++, we win by inlining StartAssignment
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
If the compiler doesn't support |explicit|, we'll just make it go away, trusting
|
||||
that the builds under compilers that do have it will keep us on the straight and narrow.
|
||||
*/
|
||||
#ifndef HAVE_CPP_EXPLICIT
|
||||
#define explicit
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CPP_NEW_CASTS
|
||||
#define NSCAP_REINTERPRET_CAST(T,x) reinterpret_cast<T>(x)
|
||||
#else
|
||||
#define NSCAP_REINTERPRET_CAST(T,x) ((T)(x))
|
||||
#endif
|
||||
|
||||
#ifdef NSCAP_FEATURE_DEBUG_MACROS
|
||||
#define NSCAP_ADDREF(ptr) NS_ADDREF(ptr)
|
||||
#define NSCAP_RELEASE(ptr) NS_RELEASE(ptr)
|
||||
#else
|
||||
#define NSCAP_ADDREF(ptr) (ptr)->AddRef()
|
||||
#define NSCAP_RELEASE(ptr) (ptr)->Release()
|
||||
#endif
|
||||
|
||||
/*
|
||||
WARNING:
|
||||
VC++4.2 is very picky. To compile under VC++4.2, the classes must be defined
|
||||
in an order that satisfies:
|
||||
|
||||
nsDerivedSafe < nsCOMPtr
|
||||
nsDontAddRef < nsCOMPtr
|
||||
nsCOMPtr < nsGetterAddRefs
|
||||
|
||||
The other compilers probably won't complain, so please don't reorder these
|
||||
classes, on pain of breaking 4.2 compatibility.
|
||||
*/
|
||||
|
||||
|
||||
template <class T>
|
||||
class nsDerivedSafe : public T
|
||||
/*
|
||||
No client should ever see or have to type the name of this class. It is the
|
||||
artifact that makes it a compile-time error to call |AddRef| and |Release|
|
||||
on a |nsCOMPtr|.
|
||||
|
||||
See |nsCOMPtr::operator->|, |nsCOMPtr::operator*|, et al.
|
||||
*/
|
||||
{
|
||||
private:
|
||||
#ifdef HAVE_CPP_USING
|
||||
using T::AddRef;
|
||||
using T::Release;
|
||||
#else
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
#endif
|
||||
|
||||
void operator delete( void*, size_t ); // NOT TO BE IMPLEMENTED
|
||||
// declaring |operator delete| private makes calling delete on an interface pointer a compile error
|
||||
|
||||
nsDerivedSafe<T>& operator=( const nsDerivedSafe<T>& ); // NOT TO BE IMPLEMENTED
|
||||
// you may not call |operator=()| through a dereferenced |nsCOMPtr|, because you'd get the wrong one
|
||||
};
|
||||
|
||||
#if !defined(HAVE_CPP_USING) && defined(NEED_CPP_UNUSED_IMPLEMENTATIONS)
|
||||
template <class T>
|
||||
nsrefcnt
|
||||
nsDerivedSafe<T>::AddRef()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
nsrefcnt
|
||||
nsDerivedSafe<T>::Release()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
template <class T>
|
||||
struct nsDontQueryInterface
|
||||
/*
|
||||
...
|
||||
*/
|
||||
{
|
||||
explicit
|
||||
nsDontQueryInterface( T* aRawPtr )
|
||||
: mRawPtr(aRawPtr)
|
||||
{
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
T* mRawPtr;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
nsDontQueryInterface<T>
|
||||
dont_QueryInterface( T* aRawPtr )
|
||||
{
|
||||
return nsDontQueryInterface<T>(aRawPtr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
struct nsQueryInterface
|
||||
{
|
||||
explicit
|
||||
nsQueryInterface( nsISupports* aRawPtr, nsresult* error = 0 )
|
||||
: mRawPtr(aRawPtr),
|
||||
mErrorPtr(error)
|
||||
{
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
nsISupports* mRawPtr;
|
||||
nsresult* mErrorPtr;
|
||||
};
|
||||
|
||||
inline
|
||||
nsQueryInterface
|
||||
do_QueryInterface( nsISupports* aRawPtr, nsresult* error = 0 )
|
||||
{
|
||||
return nsQueryInterface(aRawPtr, error);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template <class T>
|
||||
struct nsDontAddRef
|
||||
/*
|
||||
...cooperates with |nsCOMPtr| to allow you to assign in a pointer _without_
|
||||
|AddRef|ing it. You would rarely use this directly, but rather through the
|
||||
machinery of |getter_AddRefs| in the argument list to functions that |AddRef|
|
||||
their results before returning them to the caller.
|
||||
|
||||
See also |getter_AddRefs()| and |class nsGetterAddRefs|.
|
||||
*/
|
||||
{
|
||||
explicit
|
||||
nsDontAddRef( T* aRawPtr )
|
||||
: mRawPtr(aRawPtr)
|
||||
{
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
T* mRawPtr;
|
||||
};
|
||||
|
||||
// This call is now deprecated. Use |getter_AddRefs()| instead.
|
||||
template <class T>
|
||||
inline
|
||||
nsDontAddRef<T>
|
||||
dont_AddRef( T* aRawPtr )
|
||||
/*
|
||||
...makes typing easier, because it deduces the template type, e.g.,
|
||||
you write |dont_AddRef(fooP)| instead of |nsDontAddRef<IFoo>(fooP)|.
|
||||
*/
|
||||
{
|
||||
return nsDontAddRef<T>(aRawPtr);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
nsDontAddRef<T>
|
||||
getter_AddRefs( T* aRawPtr )
|
||||
{
|
||||
return nsDontAddRef<T>(aRawPtr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
class nsCOMPtr_base
|
||||
{
|
||||
public:
|
||||
|
||||
nsCOMPtr_base( nsISupports* rawPtr = 0 )
|
||||
: mRawPtr(rawPtr)
|
||||
{
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
~nsCOMPtr_base()
|
||||
{
|
||||
if ( mRawPtr )
|
||||
NSCAP_RELEASE(mRawPtr);
|
||||
}
|
||||
|
||||
NS_EXPORT void assign_with_AddRef( nsISupports* );
|
||||
NS_EXPORT void assign_with_QueryInterface( nsISupports*, const nsIID&, nsresult* );
|
||||
NS_EXPORT void** begin_assignment();
|
||||
|
||||
protected:
|
||||
nsISupports* mRawPtr;
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <class T>
|
||||
class nsCOMPtr : private nsCOMPtr_base
|
||||
/*
|
||||
...
|
||||
*/
|
||||
{
|
||||
public:
|
||||
typedef T element_type;
|
||||
|
||||
nsCOMPtr()
|
||||
// : nsCOMPtr_base(0)
|
||||
{
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
nsCOMPtr( const nsQueryInterface& aSmartPtr )
|
||||
// : nsCOMPtr_base(0)
|
||||
{
|
||||
assign_with_QueryInterface(aSmartPtr.mRawPtr, T::GetIID(), aSmartPtr.mErrorPtr);
|
||||
}
|
||||
|
||||
nsCOMPtr( const nsDontAddRef<T>& aSmartPtr )
|
||||
: nsCOMPtr_base(aSmartPtr.mRawPtr)
|
||||
{
|
||||
// nothing else to do here
|
||||
}
|
||||
|
||||
nsCOMPtr( const nsDontQueryInterface<T>& aSmartPtr )
|
||||
: nsCOMPtr_base(aSmartPtr.mRawPtr)
|
||||
{
|
||||
if ( mRawPtr )
|
||||
NSCAP_ADDREF(mRawPtr);
|
||||
}
|
||||
|
||||
nsCOMPtr( const nsCOMPtr<T>& aSmartPtr )
|
||||
: nsCOMPtr_base(aSmartPtr.mRawPtr)
|
||||
{
|
||||
if ( mRawPtr )
|
||||
NSCAP_ADDREF(mRawPtr);
|
||||
}
|
||||
|
||||
nsCOMPtr<T>&
|
||||
operator=( const nsQueryInterface& rhs )
|
||||
{
|
||||
assign_with_QueryInterface(rhs.mRawPtr, T::GetIID(), rhs.mErrorPtr);
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsCOMPtr<T>&
|
||||
operator=( const nsDontAddRef<T>& rhs )
|
||||
{
|
||||
if ( mRawPtr )
|
||||
NSCAP_RELEASE(mRawPtr);
|
||||
mRawPtr = rhs.mRawPtr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsCOMPtr<T>&
|
||||
operator=( const nsDontQueryInterface<T>& rhs )
|
||||
{
|
||||
assign_with_AddRef(rhs.mRawPtr);
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsCOMPtr<T>&
|
||||
operator=( const nsCOMPtr<T>& rhs )
|
||||
{
|
||||
assign_with_AddRef(rhs.mRawPtr);
|
||||
return *this;
|
||||
}
|
||||
|
||||
nsDerivedSafe<T>*
|
||||
get() const
|
||||
// returns a |nsDerivedSafe<T>*| to deny clients the use of |AddRef| and |Release|
|
||||
{
|
||||
return NSCAP_REINTERPRET_CAST(nsDerivedSafe<T>*, mRawPtr);
|
||||
}
|
||||
|
||||
nsDerivedSafe<T>*
|
||||
operator->() const
|
||||
// returns a |nsDerivedSafe<T>*| to deny clients the use of |AddRef| and |Release|
|
||||
{
|
||||
NS_PRECONDITION(mRawPtr != 0, "You can't dereference a NULL nsCOMPtr with operator->().");
|
||||
return get();
|
||||
}
|
||||
|
||||
nsDerivedSafe<T>&
|
||||
operator*() const
|
||||
// returns a |nsDerivedSafe<T>*| to deny clients the use of |AddRef| and |Release|
|
||||
{
|
||||
NS_PRECONDITION(mRawPtr != 0, "You can't dereference a NULL nsCOMPtr with operator*().");
|
||||
return *get();
|
||||
}
|
||||
|
||||
operator nsDerivedSafe<T>*() const
|
||||
{
|
||||
return get();
|
||||
}
|
||||
|
||||
#if 0
|
||||
private:
|
||||
friend class nsGetterAddRefs<T>;
|
||||
|
||||
/*
|
||||
In a perfect world, the following member function, |StartAssignment|, would be private.
|
||||
It is and should be only accessed by the closely related class |nsGetterAddRefs<T>|.
|
||||
|
||||
Unfortunately, some compilers---most notably VC++5.0---fail to grok the
|
||||
friend declaration above or in any alternate acceptable form. So, physically
|
||||
it will be public (until our compilers get smarter); but it is not to be
|
||||
considered part of the logical public interface.
|
||||
*/
|
||||
#endif
|
||||
|
||||
T**
|
||||
StartAssignment()
|
||||
{
|
||||
#ifndef NSCAP_FEATURE_INLINE_STARTASSIGNMENT
|
||||
return NSCAP_REINTERPRET_CAST(T**, begin_assignment());
|
||||
#else
|
||||
if ( mRawPtr )
|
||||
NSCAP_RELEASE(mRawPtr);
|
||||
mRawPtr = 0;
|
||||
return NSCAP_REINTERPRET_CAST(T**, &mRawPtr);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class T>
|
||||
class nsGetterAddRefs
|
||||
/*
|
||||
...
|
||||
|
||||
This class is designed to be used for anonymous temporary objects in the
|
||||
argument list of calls that return COM interface pointers, e.g.,
|
||||
|
||||
nsCOMPtr<IFoo> fooP;
|
||||
...->QueryInterface(iid, nsGetterAddRefs<IFoo>(fooP))
|
||||
...->QueryInterface(iid, getter_AddRefs(fooP))
|
||||
|
||||
When initialized with a |nsCOMPtr|, as in the example above, it returns
|
||||
a |void**| (or |T**| if needed) that the outer call (|QueryInterface| in this
|
||||
case) can fill in.
|
||||
*/
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
nsGetterAddRefs( nsCOMPtr<T>& aSmartPtr )
|
||||
: mTargetSmartPtr(aSmartPtr)
|
||||
{
|
||||
// nothing else to do
|
||||
}
|
||||
|
||||
operator void**()
|
||||
{
|
||||
// NS_PRECONDITION(mTargetSmartPtr != 0, "getter_AddRefs into no destination");
|
||||
return NSCAP_REINTERPRET_CAST(void**, mTargetSmartPtr.StartAssignment());
|
||||
}
|
||||
|
||||
T*&
|
||||
operator*()
|
||||
{
|
||||
// NS_PRECONDITION(mTargetSmartPtr != 0, "getter_AddRefs into no destination");
|
||||
return *(mTargetSmartPtr.StartAssignment());
|
||||
}
|
||||
|
||||
operator T**()
|
||||
{
|
||||
// NS_PRECONDITION(mTargetSmartPtr != 0, "getter_AddRefs into no destination");
|
||||
return mTargetSmartPtr.StartAssignment();
|
||||
}
|
||||
|
||||
private:
|
||||
nsCOMPtr<T>& mTargetSmartPtr;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline
|
||||
nsGetterAddRefs<T>
|
||||
getter_AddRefs( nsCOMPtr<T>& aSmartPtr )
|
||||
/*
|
||||
Used around a |nsCOMPtr| when
|
||||
...makes the class |nsGetterAddRefs<T>| invisible.
|
||||
*/
|
||||
{
|
||||
return nsGetterAddRefs<T>(aSmartPtr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // !defined(nsCOMPtr_h___)
|
||||
227
mozilla/xpcom/base/nsCom.h
Normal file
227
mozilla/xpcom/base/nsCom.h
Normal file
@@ -0,0 +1,227 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
|
||||
#ifndef nsCom_h__
|
||||
#define nsCom_h__
|
||||
|
||||
/*
|
||||
* API Import/Export macros
|
||||
*/
|
||||
|
||||
#ifdef _IMPL_NS_COM
|
||||
#ifdef XP_PC
|
||||
#define NS_COM _declspec(dllexport)
|
||||
#else /* !XP_PC */
|
||||
#define NS_COM
|
||||
#endif /* !XP_PC */
|
||||
#else /* !_IMPL_NS_COM */
|
||||
#ifdef XP_PC
|
||||
#define NS_COM _declspec(dllimport)
|
||||
#else /* !XP_PC */
|
||||
#define NS_COM
|
||||
#endif /* !XP_PC */
|
||||
#endif /* !_IMPL_NS_COM */
|
||||
|
||||
/*
|
||||
* DLL Export macro
|
||||
*/
|
||||
|
||||
#if defined(XP_PC)
|
||||
|
||||
#define NS_EXPORT _declspec(dllexport)
|
||||
#define NS_EXPORT_(type) _declspec(dllexport) type __stdcall
|
||||
|
||||
#define NS_IMETHOD_(type) virtual type __stdcall
|
||||
#define NS_IMETHOD virtual nsresult __stdcall
|
||||
#define NS_IMETHODIMP_(type) type __stdcall
|
||||
#define NS_IMETHODIMP nsresult __stdcall
|
||||
|
||||
#define NS_METHOD_(type) type __stdcall
|
||||
#define NS_METHOD nsresult __stdcall
|
||||
|
||||
#define NS_CALLBACK_(_type, _name) _type (__stdcall * _name)
|
||||
#define NS_CALLBACK(_name) nsresult (__stdcall * _name)
|
||||
|
||||
#elif defined(XP_MAC)
|
||||
|
||||
#define NS_EXPORT __declspec(export)
|
||||
#define NS_EXPORT_(type) __declspec(export) type
|
||||
|
||||
#define NS_IMETHOD_(type) virtual type
|
||||
#define NS_IMETHOD virtual nsresult
|
||||
#define NS_IMETHODIMP_(type) type
|
||||
#define NS_IMETHODIMP nsresult
|
||||
|
||||
#define NS_METHOD_(type) type
|
||||
#define NS_METHOD nsresult
|
||||
|
||||
#define NS_CALLBACK_(_type, _name) _type (* _name)
|
||||
#define NS_CALLBACK(_name) nsresult (* _name)
|
||||
|
||||
#else /* !XP_PC && !XP_MAC */
|
||||
|
||||
#define NS_EXPORT
|
||||
#define NS_EXPORT_(type) type
|
||||
|
||||
#define NS_IMETHOD_(type) virtual type
|
||||
#define NS_IMETHOD virtual nsresult
|
||||
#define NS_IMETHODIMP_(type) type
|
||||
#define NS_IMETHODIMP nsresult
|
||||
|
||||
#define NS_METHOD_(type) type
|
||||
#define NS_METHOD nsresult
|
||||
|
||||
#define NS_CALLBACK_(_type, _name) _type (* _name)
|
||||
#define NS_CALLBACK(_name) nsresult (* _name)
|
||||
|
||||
#endif /* !XP_PC */
|
||||
|
||||
/* use these functions to associate get/set methods with a
|
||||
C++ member variable
|
||||
*/
|
||||
|
||||
#define NS_METHOD_GETTER(_method, _type, _member) \
|
||||
_method(_type* aResult) \
|
||||
{\
|
||||
if (!aResult) return NS_ERROR_NULL_POINTER; \
|
||||
*aResult = _member; \
|
||||
return NS_OK; \
|
||||
}
|
||||
|
||||
#define NS_METHOD_SETTER(_method, _type, _member) \
|
||||
_method(_type aResult) \
|
||||
{ \
|
||||
_member = aResult; \
|
||||
return NS_OK; \
|
||||
}
|
||||
|
||||
/*
|
||||
* special for strings to get/set char* strings
|
||||
* using PL_strdup and PR_FREEIF
|
||||
*/
|
||||
#define NS_METHOD_GETTER_STR(_method,_member) \
|
||||
_method(char* *aString)\
|
||||
{\
|
||||
if (!aString) return NS_ERROR_NULL_POINTER; \
|
||||
*aString = PL_strdup(_member); \
|
||||
return NS_OK; \
|
||||
}
|
||||
|
||||
#define NS_METHOD_SETTER_STR(_method, _member) \
|
||||
_method(char *aString)\
|
||||
{\
|
||||
PR_FREEIF(_member);\
|
||||
if (aString) _member = PL_strdup(aString); \
|
||||
else _member = nsnull;\
|
||||
return NS_OK; \
|
||||
}
|
||||
|
||||
/* Getter/Setter macros.
|
||||
Usage:
|
||||
NS_IMPL_[CLASS_]GETTER[_<type>](method, [type,] member);
|
||||
NS_IMPL_[CLASS_]SETTER[_<type>](method, [type,] member);
|
||||
NS_IMPL_[CLASS_]GETSET[_<type>]([class, ]postfix, [type,] member);
|
||||
|
||||
where:
|
||||
CLASS_ - implementation is inside a class definition
|
||||
(otherwise the class name is needed)
|
||||
Do NOT use in publicly exported header files, because
|
||||
the implementation may be included many times over.
|
||||
Instead, use the non-CLASS_ version.
|
||||
_<type> - For more complex (STR, IFACE) data types
|
||||
(otherwise the simple data type is needed)
|
||||
method - name of the method, such as GetWidth or SetColor
|
||||
type - simple data type if required
|
||||
member - class member variable such as m_width or mColor
|
||||
class - the class name, such as Window or MyObject
|
||||
postfix - Method part after Get/Set such as "Width" for "GetWidth"
|
||||
|
||||
Example:
|
||||
class Window {
|
||||
public:
|
||||
NS_IMPL_CLASS_GETSET(Width, int, m_width);
|
||||
NS_IMPL_CLASS_GETTER_STR(GetColor, m_color);
|
||||
NS_IMETHOD SetColor(char *color);
|
||||
|
||||
private:
|
||||
int m_width; // read/write
|
||||
char *m_color; // readonly
|
||||
};
|
||||
|
||||
// defined outside of class
|
||||
NS_IMPL_SETTER_STR(Window::GetColor, m_color);
|
||||
|
||||
Questions/Comments to alecf@netscape.com
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Getter/Setter implementation within a class definition
|
||||
*/
|
||||
|
||||
/* simple data types */
|
||||
#define NS_IMPL_CLASS_GETTER(_method, _type, _member) \
|
||||
NS_IMETHOD NS_METHOD_GETTER(_method, _type, _member)
|
||||
|
||||
#define NS_IMPL_CLASS_SETTER(_method, _type, _member) \
|
||||
NS_IMETHOD NS_METHOD_SETTER(_method, _type, _member)
|
||||
|
||||
#define NS_IMPL_CLASS_GETSET(_postfix, _type, _member) \
|
||||
NS_IMPL_CLASS_GETTER(Get##_postfix, _type, _member) \
|
||||
NS_IMPL_CLASS_SETTER(Set##_postfix, _type, _member)
|
||||
|
||||
/* strings */
|
||||
#define NS_IMPL_CLASS_GETTER_STR(_method, _member) \
|
||||
NS_IMETHOD NS_METHOD_GETTER_STR(_method, _member)
|
||||
|
||||
#define NS_IMPL_CLASS_SETTER_STR(_method, _member) \
|
||||
NS_IMETHOD NS_METHOD_SETTER_STR(_method, _member)
|
||||
|
||||
#define NS_IMPL_CLASS_GETSET_STR(_postfix, _member) \
|
||||
NS_IMPL_CLASS_GETTER_STR(Get##_postfix, _member) \
|
||||
NS_IMPL_CLASS_SETTER_STR(Set##_postfix, _member)
|
||||
|
||||
/* Getter/Setter implementation outside of a class definition */
|
||||
|
||||
/* simple data types */
|
||||
#define NS_IMPL_GETTER(_method, _type, _member) \
|
||||
NS_IMETHODIMP NS_METHOD_GETTER(_method, _type, _member)
|
||||
|
||||
#define NS_IMPL_SETTER(_method, _type, _member) \
|
||||
NS_IMETHODIMP NS_METHOD_SETTER(_method, _type, _member)
|
||||
|
||||
#define NS_IMPL_GETSET(_class, _postfix, _type, _member) \
|
||||
NS_IMPL_GETTER(_class::Get##_postfix, _type, _member) \
|
||||
NS_IMPL_SETTER(_class::Set##_postfix, _type, _member)
|
||||
|
||||
/* strings */
|
||||
#define NS_IMPL_GETTER_STR(_method, _member) \
|
||||
NS_IMETHODIMP NS_METHOD_GETTER_STR(_method, _member)
|
||||
|
||||
#define NS_IMPL_SETTER_STR(_method, _member) \
|
||||
NS_IMETHODIMP NS_METHOD_SETTER_STR(_method, _member)
|
||||
|
||||
#define NS_IMPL_GETSET_STR(_class, _postfix, _member) \
|
||||
NS_IMPL_GETTER_STR(_class::Get##_postfix, _member) \
|
||||
NS_IMPL_SETTER_STR(_class::Set##_postfix, _member)
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
178
mozilla/xpcom/base/nsDebug.cpp
Normal file
178
mozilla/xpcom/base/nsDebug.cpp
Normal file
@@ -0,0 +1,178 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
|
||||
#include "nsDebug.h"
|
||||
#include "prlog.h"
|
||||
#include "prinit.h"
|
||||
|
||||
#if defined(XP_UNIX)
|
||||
/* for abort() */
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#elif defined(XP_MAC)
|
||||
#define TEMP_MAC_HACK
|
||||
|
||||
//------------------------
|
||||
#ifdef TEMP_MAC_HACK
|
||||
#include <MacTypes.h>
|
||||
#include <Processes.h>
|
||||
|
||||
// TEMPORARY UNTIL WE HAVE MACINTOSH ENVIRONMENT VARIABLES THAT CAN TURN ON
|
||||
// LOGGING ON MACINTOSH
|
||||
// At this moment, NSPR's logging is a no-op on Macintosh.
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#undef PR_LOG
|
||||
#define PR_LOG(module,level,args) dprintf args
|
||||
static void dprintf(const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
Str255 buffer;
|
||||
|
||||
va_start(ap, format);
|
||||
buffer[0] = vsnprintf((char *)buffer + 1, sizeof(buffer) - 1, format, ap);
|
||||
va_end(ap);
|
||||
|
||||
DebugStr(buffer);
|
||||
}
|
||||
#endif // TEMP_MAC_HACK
|
||||
//------------------------
|
||||
#elif defined(XP_UNIX)
|
||||
#include<stdlib.h>
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of the nsDebug methods. Note that this code is
|
||||
* always compiled in, in case some other module that uses it is
|
||||
* compiled with debugging even if this library is not.
|
||||
*/
|
||||
|
||||
static PRLogModuleInfo* gDebugLog;
|
||||
|
||||
static void InitLog(void)
|
||||
{
|
||||
if (0 == gDebugLog) {
|
||||
gDebugLog = PR_NewLogModule("nsDebug");
|
||||
gDebugLog->level = PR_LOG_DEBUG;
|
||||
}
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::Abort(const char* aFile, PRIntn aLine)
|
||||
{
|
||||
InitLog();
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("Abort: at file %s, line %d", aFile, aLine));
|
||||
PR_LogFlush();
|
||||
#if defined(_WIN32)
|
||||
long* __p = (long*) 0x7;
|
||||
*__p = 0x7;
|
||||
#elif defined(XP_MAC)
|
||||
ExitToShell();
|
||||
#elif defined(XP_UNIX)
|
||||
PR_Abort();
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::Break(const char* aFile, PRIntn aLine)
|
||||
{
|
||||
#ifndef TEMP_MAC_HACK
|
||||
InitLog();
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("Break: at file %s, line %d", aFile, aLine));
|
||||
PR_LogFlush();
|
||||
//XXX this works on win32 only for now. For all the other platforms call Abort
|
||||
#if defined(_WIN32)
|
||||
::DebugBreak();
|
||||
#else
|
||||
Abort(aFile, aLine);
|
||||
#endif
|
||||
#endif // TEMP_MAC_HACK
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::PreCondition(const char* aStr, const char* aExpr,
|
||||
const char* aFile, PRIntn aLine)
|
||||
{
|
||||
InitLog();
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("PreCondition: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
|
||||
aFile, aLine));
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::PostCondition(const char* aStr, const char* aExpr,
|
||||
const char* aFile, PRIntn aLine)
|
||||
{
|
||||
InitLog();
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("PostCondition: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
|
||||
aFile, aLine));
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::Assertion(const char* aStr, const char* aExpr,
|
||||
const char* aFile, PRIntn aLine)
|
||||
{
|
||||
InitLog();
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("Assertion: \"%s\" (%s) at file %s, line %d", aStr, aExpr,
|
||||
aFile, aLine));
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::NotYetImplemented(const char* aMessage,
|
||||
const char* aFile, PRIntn aLine)
|
||||
{
|
||||
InitLog();
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("NotYetImplemented: \"%s\" at file %s, line %d", aMessage,
|
||||
aFile, aLine));
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::NotReached(const char* aMessage,
|
||||
const char* aFile, PRIntn aLine)
|
||||
{
|
||||
InitLog();
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("NotReached: \"%s\" at file %s, line %d", aMessage, aFile, aLine));
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::Error(const char* aMessage,
|
||||
const char* aFile, PRIntn aLine)
|
||||
{
|
||||
InitLog();
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("Error: \"%s\" at file %s, line %d", aMessage, aFile, aLine));
|
||||
Break(aFile, aLine);
|
||||
}
|
||||
|
||||
NS_COM void nsDebug::Warning(const char* aMessage,
|
||||
const char* aFile, PRIntn aLine)
|
||||
{
|
||||
InitLog();
|
||||
PR_LOG(gDebugLog, PR_LOG_ERROR,
|
||||
("Warning: \"%s\" at file %s, line %d", aMessage, aFile, aLine));
|
||||
PR_LogFlush();
|
||||
}
|
||||
179
mozilla/xpcom/base/nsDebug.h
Normal file
179
mozilla/xpcom/base/nsDebug.h
Normal file
@@ -0,0 +1,179 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
|
||||
#ifndef nsDebug_h___
|
||||
#define nsDebug_h___
|
||||
|
||||
#include "nsCom.h"
|
||||
#include "prtypes.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#define NS_DEBUG
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Namespace for debugging methods. Note that your code must use the
|
||||
* macros defined later in this file so that the debug code can be
|
||||
* conditionally compiled out.
|
||||
*/
|
||||
class nsDebug {
|
||||
public:
|
||||
// XXX add in log controls here
|
||||
// XXX probably want printf type arguments
|
||||
|
||||
/**
|
||||
* Abort the executing program. This works on all architectures.
|
||||
*/
|
||||
static NS_COM void Abort(const char* aFile, PRIntn aLine);
|
||||
|
||||
/**
|
||||
* Break the executing program into the debugger.
|
||||
*/
|
||||
static NS_COM void Break(const char* aFile, PRIntn aLine);
|
||||
|
||||
/**
|
||||
* Log a pre-condition message to the debug log
|
||||
*/
|
||||
static NS_COM void PreCondition(const char* aStr, const char* aExpr,
|
||||
const char* aFile, PRIntn aLine);
|
||||
|
||||
/**
|
||||
* Log a post-condition message to the debug log
|
||||
*/
|
||||
static NS_COM void PostCondition(const char* aStr, const char* aExpr,
|
||||
const char* aFile, PRIntn aLine);
|
||||
|
||||
/**
|
||||
* Log an assertion message to the debug log
|
||||
*/
|
||||
static NS_COM void Assertion(const char* aStr, const char* aExpr,
|
||||
const char* aFile, PRIntn aLine);
|
||||
|
||||
/**
|
||||
* Log a not-yet-implemented message to the debug log
|
||||
*/
|
||||
static NS_COM void NotYetImplemented(const char* aMessage,
|
||||
const char* aFile, PRIntn aLine);
|
||||
|
||||
/**
|
||||
* Log a not-reached message to the debug log
|
||||
*/
|
||||
static NS_COM void NotReached(const char* aMessage,
|
||||
const char* aFile, PRIntn aLine);
|
||||
|
||||
/**
|
||||
* Log an error message to the debug log. This call returns.
|
||||
*/
|
||||
static NS_COM void Error(const char* aMessage,
|
||||
const char* aFile, PRIntn aLine);
|
||||
|
||||
/**
|
||||
* Log a warning message to the debug log.
|
||||
*/
|
||||
static NS_COM void Warning(const char* aMessage,
|
||||
const char* aFile, PRIntn aLine);
|
||||
};
|
||||
|
||||
#ifdef NS_DEBUG
|
||||
/**
|
||||
* Test a precondition for truth. If the expression is not true then
|
||||
* trigger a program failure.
|
||||
*/
|
||||
#define NS_PRECONDITION(expr,str) \
|
||||
if (!(expr)) \
|
||||
nsDebug::PreCondition(str, #expr, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
* Test an assertion for truth. If the expression is not true then
|
||||
* trigger a program failure.
|
||||
*/
|
||||
#define NS_ASSERTION(expr,str) \
|
||||
if (!(expr)) \
|
||||
nsDebug::Assertion(str, #expr, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
* Test an assertion for truth. If the expression is not true then
|
||||
* trigger a program failure. The expression will still be
|
||||
* executed in release mode.
|
||||
*/
|
||||
#define NS_VERIFY(expr,str) \
|
||||
if (!(expr)) \
|
||||
nsDebug::Assertion(str, #expr, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
* Test a post-condition for truth. If the expression is not true then
|
||||
* trigger a program failure.
|
||||
*/
|
||||
#define NS_POSTCONDITION(expr,str) \
|
||||
if (!(expr)) \
|
||||
nsDebug::PostCondition(str, #expr, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
* This macros triggers a program failure if executed. It indicates that
|
||||
* an attempt was made to execute some unimplimented functionality.
|
||||
*/
|
||||
#define NS_NOTYETIMPLEMENTED(str) \
|
||||
nsDebug::NotYetImplemented(str, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
* This macros triggers a program failure if executed. It indicates that
|
||||
* an attempt was made to execute some unimplimented functionality.
|
||||
*/
|
||||
#define NS_NOTREACHED(str) \
|
||||
nsDebug::NotReached(str, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
* Log an error message.
|
||||
*/
|
||||
#define NS_ERROR(str) \
|
||||
nsDebug::Error(str, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
* Log a warning message.
|
||||
*/
|
||||
#define NS_WARNING(str) \
|
||||
nsDebug::Warning(str, __FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
* Trigger an abort
|
||||
*/
|
||||
#define NS_ABORT() \
|
||||
nsDebug::Abort(__FILE__, __LINE__)
|
||||
|
||||
/**
|
||||
* Cause a break
|
||||
*/
|
||||
#define NS_BREAK() \
|
||||
nsDebug::Break(__FILE__, __LINE__)
|
||||
|
||||
#else /* NS_DEBUG */
|
||||
|
||||
#define NS_PRECONDITION(expr,str) {}
|
||||
#define NS_ASSERTION(expr,str) {}
|
||||
#define NS_VERIFY(expr,str) expr
|
||||
#define NS_POSTCONDITION(expr,str) {}
|
||||
#define NS_NOTYETIMPLEMENTED(str) {}
|
||||
#define NS_NOTREACHED(str) {}
|
||||
#define NS_ERROR(str) {}
|
||||
#define NS_WARNING(str) {}
|
||||
#define NS_ABORT() {}
|
||||
#define NS_BREAK() {}
|
||||
|
||||
#endif /* ! NS_DEBUG */
|
||||
|
||||
#endif /* nsDebug_h___ */
|
||||
195
mozilla/xpcom/base/nsError.h
Normal file
195
mozilla/xpcom/base/nsError.h
Normal file
@@ -0,0 +1,195 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
|
||||
#ifndef nsError_h
|
||||
#define nsError_h
|
||||
|
||||
#ifndef prtypes_h___
|
||||
#include "prtypes.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Generic result data type
|
||||
*/
|
||||
|
||||
typedef PRUint32 nsresult;
|
||||
|
||||
/*
|
||||
* To add error code to your module, you need to do the following:
|
||||
*
|
||||
* 1) Add a module offset code. Add yours to the bottom of the list
|
||||
* right below this comment, adding 1.
|
||||
*
|
||||
* 2) In your module, define a header file which uses one of the
|
||||
* NE_ERROR_GENERATExxxxxx macros. Some examples below:
|
||||
*
|
||||
* #define NS_ERROR_MYMODULE_MYERROR1 NS_ERROR_GENERATE(NS_ERROR_SEVERITY_ERROR,NS_ERROR_MODULE_MYMODULE,1)
|
||||
* #define NS_ERROR_MYMODULE_MYERROR2 NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_MYMODULE,2)
|
||||
* #define NS_ERROR_MYMODULE_MYERROR3 NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_MYMODULE,3)
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @name Standard Module Offset Code. Each Module should identify a unique number
|
||||
* and then all errors associated with that module become offsets from the
|
||||
* base associated with that module id. There are 16 bits of code bits for
|
||||
* each module.
|
||||
*/
|
||||
|
||||
#define NS_ERROR_MODULE_XPCOM 1
|
||||
#define NS_ERROR_MODULE_BASE 2
|
||||
#define NS_ERROR_MODULE_GFX 3
|
||||
#define NS_ERROR_MODULE_WIDGET 4
|
||||
#define NS_ERROR_MODULE_CALENDAR 5
|
||||
#define NS_ERROR_MODULE_NETWORK 6
|
||||
#define NS_ERROR_MODULE_PLUGINS 7
|
||||
#define NS_ERROR_MODULE_LAYOUT 8
|
||||
#define NS_ERROR_MODULE_HTMLPARSER 9
|
||||
#define NS_ERROR_MODULE_RDF 10
|
||||
#define NS_ERROR_MODULE_UCONV 11
|
||||
#define NS_ERROR_MODULE_REG 12
|
||||
#define NS_ERROR_MODULE_FILES 13
|
||||
|
||||
#define NS_ERROR_MODULE_MAILNEWS 16
|
||||
#define NS_ERROR_MODULE_EDITOR 17
|
||||
|
||||
/**
|
||||
* @name Standard Error Handling Macros
|
||||
*/
|
||||
|
||||
#define NS_FAILED(_nsresult) ((_nsresult) & 0x80000000)
|
||||
#define NS_SUCCEEDED(_nsresult) (!((_nsresult) & 0x80000000))
|
||||
|
||||
/**
|
||||
* @name Severity Code. This flag identifies the level of warning
|
||||
*/
|
||||
|
||||
#define NS_ERROR_SEVERITY_SUCCESS 0
|
||||
#define NS_ERROR_SEVERITY_ERROR 1
|
||||
|
||||
/**
|
||||
* @name Mozilla Code. This flag separates consumers of mozilla code
|
||||
* from the native platform
|
||||
*/
|
||||
|
||||
#define NS_ERROR_MODULE_BASE_OFFSET 0x45
|
||||
|
||||
/**
|
||||
* @name Standard Error Generating Macros
|
||||
*/
|
||||
|
||||
#define NS_ERROR_GENERATE(sev,module,code) \
|
||||
((nsresult) (((PRUint32)(sev)<<31) | ((PRUint32)(module+NS_ERROR_MODULE_BASE_OFFSET)<<16) | ((PRUint32)(code))) )
|
||||
|
||||
#define NS_ERROR_GENERATE_SUCCESS(module,code) \
|
||||
((nsresult) (((PRUint32)(NS_ERROR_SEVERITY_SUCCESS)<<31) | ((PRUint32)(module+NS_ERROR_MODULE_BASE_OFFSET)<<16) | ((PRUint32)(code))) )
|
||||
|
||||
#define NS_ERROR_GENERATE_FAILURE(module,code) \
|
||||
((nsresult) (((PRUint32)(NS_ERROR_SEVERITY_ERROR)<<31) | ((PRUint32)(module+NS_ERROR_MODULE_BASE_OFFSET)<<16) | ((PRUint32)(code))) )
|
||||
|
||||
/**
|
||||
* @name Standard Macros for retrieving error bits
|
||||
*/
|
||||
|
||||
#if PR_BYTES_PER_INT == 4
|
||||
#define NS_IS_ERROR(err) (((nsresult)(err))<0)
|
||||
#else
|
||||
#define NS_IS_ERROR(err) (((((PRUint32)(err)) >> 31) & 0x1) == NS_ERROR_SEVERITY_ERROR)
|
||||
#endif
|
||||
|
||||
#define NS_ERROR_GET_CODE(err) ((err) & 0xffff)
|
||||
#define NS_ERROR_GET_MODULE(err) (((((err) >> 16) - NS_ERROR_MODULE_BASE_OFFSET) & 0x1fff))
|
||||
#define NS_ERROR_GET_SEVERITY(err) (((err) >> 31) & 0x1)
|
||||
|
||||
/**
|
||||
* @name Standard return values
|
||||
*/
|
||||
|
||||
/*@{*/
|
||||
|
||||
/* Standard "it worked" return value */
|
||||
#define NS_OK 0
|
||||
|
||||
/* The backwards COM false */
|
||||
#define NS_COMFALSE 1
|
||||
|
||||
#define NS_ERROR_BASE ((nsresult) 0xC1F30000)
|
||||
|
||||
/* Returned when an instance is not initialized */
|
||||
#define NS_ERROR_NOT_INITIALIZED (NS_ERROR_BASE + 1)
|
||||
|
||||
/* Returned when an instance is already initialized */
|
||||
#define NS_ERROR_ALREADY_INITIALIZED (NS_ERROR_BASE + 2)
|
||||
|
||||
/* Returned by a not implemented function */
|
||||
#define NS_ERROR_NOT_IMPLEMENTED ((nsresult) 0x80004001L)
|
||||
|
||||
/* Returned when a given interface is not supported. */
|
||||
#define NS_NOINTERFACE ((nsresult) 0x80004002L)
|
||||
#define NS_ERROR_NO_INTERFACE NS_NOINTERFACE
|
||||
|
||||
#define NS_ERROR_INVALID_POINTER ((nsresult) 0x80004003L)
|
||||
#define NS_ERROR_NULL_POINTER NS_ERROR_INVALID_POINTER
|
||||
|
||||
/* Returned when a function aborts */
|
||||
#define NS_ERROR_ABORT ((nsresult) 0x80004004L)
|
||||
|
||||
/* Returned when a function fails */
|
||||
#define NS_ERROR_FAILURE ((nsresult) 0x80004005L)
|
||||
|
||||
/* Returned when an unexpected error occurs */
|
||||
#define NS_ERROR_UNEXPECTED ((nsresult) 0x8000ffffL)
|
||||
|
||||
/* Returned when a memory allocation failes */
|
||||
#define NS_ERROR_OUT_OF_MEMORY ((nsresult) 0x8007000eL)
|
||||
|
||||
/* Returned when an illegal value is passed */
|
||||
#define NS_ERROR_ILLEGAL_VALUE ((nsresult) 0x80070057L)
|
||||
#define NS_ERROR_INVALID_ARG NS_ERROR_ILLEGAL_VALUE
|
||||
|
||||
/* Returned when a class doesn't allow aggregation */
|
||||
#define NS_ERROR_NO_AGGREGATION ((nsresult) 0x80040110L)
|
||||
|
||||
/* Returned when a class doesn't allow aggregation */
|
||||
#define NS_ERROR_NOT_AVAILABLE ((nsresult) 0x80040111L)
|
||||
|
||||
/* Returned when a class is not registered */
|
||||
#define NS_ERROR_FACTORY_NOT_REGISTERED ((nsresult) 0x80040154L)
|
||||
|
||||
/* Returned when a dynamically loaded factory couldn't be found */
|
||||
#define NS_ERROR_FACTORY_NOT_LOADED ((nsresult) 0x800401f8L)
|
||||
|
||||
/* Returned when a factory doesn't support signatures */
|
||||
#define NS_ERROR_FACTORY_NO_SIGNATURE_SUPPORT \
|
||||
(NS_ERROR_BASE + 0x101)
|
||||
|
||||
/* Returned when a factory already is registered */
|
||||
#define NS_ERROR_FACTORY_EXISTS (NS_ERROR_BASE + 0x100)
|
||||
|
||||
/*@}*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef XP_PC
|
||||
#pragma warning(disable: 4251) // 'nsCOMPtr<class nsIInputStream>' needs to have dll-interface to be used by clients of class 'nsInputStream'
|
||||
#pragma warning(disable: 4275) // non dll-interface class 'nsISupports' used as base for dll-interface class 'nsIRDFNode'
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
83
mozilla/xpcom/base/nsIAllocator.h
Normal file
83
mozilla/xpcom/base/nsIAllocator.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/* -*- 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 nsIAllocator_h___
|
||||
#define nsIAllocator_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
/**
|
||||
* Unlike IMalloc, this interface returns nsresults and doesn't
|
||||
* implement the problematic GetSize and DidAlloc routines.
|
||||
*/
|
||||
|
||||
#define NS_IALLOCATOR_IID \
|
||||
{ /* 56def700-b1b9-11d2-8177-006008119d7a */ \
|
||||
0x56def700, \
|
||||
0xb1b9, \
|
||||
0x11d2, \
|
||||
{0x81, 0x77, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
|
||||
}
|
||||
|
||||
class nsIAllocator : public nsISupports {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IALLOCATOR_IID; return iid; }
|
||||
|
||||
/**
|
||||
* Allocates a block of memory of a particular size.
|
||||
*
|
||||
* @param size - the size of the block to allocate
|
||||
* @result the block of memory
|
||||
*/
|
||||
NS_IMETHOD_(void*) Alloc(PRUint32 size) = 0;
|
||||
|
||||
/**
|
||||
* Reallocates a block of memory to a new size.
|
||||
*
|
||||
* @param ptr - the block of memory to reallocate
|
||||
* @param size - the new size
|
||||
* @result the rellocated block of memory
|
||||
*/
|
||||
NS_IMETHOD_(void*) Realloc(void* ptr, PRUint32 size) = 0;
|
||||
|
||||
/**
|
||||
* Frees a block of memory.
|
||||
*
|
||||
* @param ptr - the block of memory to free
|
||||
*/
|
||||
NS_IMETHOD Free(void* ptr) = 0;
|
||||
|
||||
/**
|
||||
* Attempts to shrink the heap.
|
||||
*/
|
||||
NS_IMETHOD HeapMinimize(void) = 0;
|
||||
|
||||
};
|
||||
|
||||
// To get the global memory manager service:
|
||||
#define NS_ALLOCATOR_CID \
|
||||
{ /* aafe6770-b1bb-11d2-8177-006008119d7a */ \
|
||||
0xaafe6770, \
|
||||
0xb1bb, \
|
||||
0x11d2, \
|
||||
{0x81, 0x77, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif /* nsIAllocator_h___ */
|
||||
73
mozilla/xpcom/base/nsID.cpp
Normal file
73
mozilla/xpcom/base/nsID.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
#include "nsID.h"
|
||||
#include "prprf.h"
|
||||
|
||||
static const char gIDFormat[] =
|
||||
"{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}";
|
||||
|
||||
static const char gIDFormat2[] =
|
||||
"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x";
|
||||
|
||||
/*
|
||||
* Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} string into
|
||||
* an nsID
|
||||
*/
|
||||
|
||||
NS_COM PRBool nsID::Parse(char *aIDStr)
|
||||
{
|
||||
PRInt32 count = 0;
|
||||
PRInt32 n1, n2, n3[8];
|
||||
PRInt32 n0;
|
||||
|
||||
if (NULL != aIDStr) {
|
||||
count = PR_sscanf(aIDStr,
|
||||
(aIDStr[0] == '{') ? gIDFormat : gIDFormat2,
|
||||
&n0, &n1, &n2,
|
||||
&n3[0],&n3[1],&n3[2],&n3[3],
|
||||
&n3[4],&n3[5],&n3[6],&n3[7]);
|
||||
|
||||
m0 = (PRInt32) n0;
|
||||
m1 = (PRInt16) n1;
|
||||
m2 = (PRInt16) n2;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
m3[i] = (PRInt8) n3[i];
|
||||
}
|
||||
}
|
||||
return (PRBool) (count == 11);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns an allocated string in {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
|
||||
* format. Caller should delete [] the string.
|
||||
*/
|
||||
|
||||
NS_COM char *nsID::ToString() const
|
||||
{
|
||||
char *res = new char[39];
|
||||
|
||||
if (res != NULL) {
|
||||
PR_snprintf(res, 39, gIDFormat,
|
||||
m0, (PRUint32) m1, (PRUint32) m2,
|
||||
(PRUint32) m3[0], (PRUint32) m3[1], (PRUint32) m3[2],
|
||||
(PRUint32) m3[3], (PRUint32) m3[4], (PRUint32) m3[5],
|
||||
(PRUint32) m3[6], (PRUint32) m3[7]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
101
mozilla/xpcom/base/nsID.h
Normal file
101
mozilla/xpcom/base/nsID.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
|
||||
#ifndef nsID_h__
|
||||
#define nsID_h__
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "string.h"
|
||||
#include "nsCom.h"
|
||||
|
||||
/**
|
||||
* A "unique identifier". This is modeled after OSF DCE UUIDs.
|
||||
*/
|
||||
|
||||
struct nsID {
|
||||
/**
|
||||
* @name Indentifier values
|
||||
*/
|
||||
|
||||
//@{
|
||||
PRUint32 m0;
|
||||
PRUint16 m1;
|
||||
PRUint16 m2;
|
||||
PRUint8 m3[8];
|
||||
//@}
|
||||
|
||||
/**
|
||||
* @name Methods
|
||||
*/
|
||||
|
||||
//@{
|
||||
/**
|
||||
* Equivalency method. Compares this nsID with another.
|
||||
* @return <b>PR_TRUE</b> if they are the same, <b>PR_FALSE</b> if not.
|
||||
*/
|
||||
|
||||
inline PRBool Equals(const nsID& other) const {
|
||||
return (PRBool)
|
||||
((((PRUint32*) &m0)[0] == ((PRUint32*) &other.m0)[0]) &&
|
||||
(((PRUint32*) &m0)[1] == ((PRUint32*) &other.m0)[1]) &&
|
||||
(((PRUint32*) &m0)[2] == ((PRUint32*) &other.m0)[2]) &&
|
||||
(((PRUint32*) &m0)[3] == ((PRUint32*) &other.m0)[3]));
|
||||
}
|
||||
|
||||
/**
|
||||
* nsID Parsing method. Turns a {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
|
||||
* string into an nsID
|
||||
*/
|
||||
NS_COM PRBool Parse(char *aIDStr);
|
||||
|
||||
/**
|
||||
* nsID string encoder. Returns an allocated string in
|
||||
* {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} format. Caller should free string.
|
||||
*/
|
||||
NS_COM char* ToString() const;
|
||||
//@}
|
||||
};
|
||||
|
||||
/**
|
||||
* Declare an ID. If NS_IMPL_IDS is set, a variable <i>_name</i> is declared
|
||||
* with the given values, otherwise <i>_name</i> is declared as an
|
||||
* <tt>extern</tt> variable.
|
||||
*/
|
||||
|
||||
#ifdef NS_IMPL_IDS
|
||||
#define NS_DECLARE_ID(_name,m0,m1,m2,m30,m31,m32,m33,m34,m35,m36,m37) \
|
||||
extern "C" const nsID _name = {m0,m1,m2,{m30,m31,m32,m33,m34,m35,m36,m37}}
|
||||
#else
|
||||
#define NS_DECLARE_ID(_name,m0,m1,m2,m30,m31,m32,m33,m34,m35,m36,m37) \
|
||||
extern "C" const nsID _name
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Class IDs
|
||||
*/
|
||||
|
||||
typedef nsID nsCID;
|
||||
|
||||
// Define an CID
|
||||
#define NS_DEFINE_CID(_name, _cidspec) \
|
||||
const nsCID _name = _cidspec
|
||||
|
||||
#define REFNSCID const nsCID&
|
||||
|
||||
#endif
|
||||
|
||||
42
mozilla/xpcom/base/nsIID.h
Normal file
42
mozilla/xpcom/base/nsIID.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/* -*- 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 __nsIID_h
|
||||
#define __nsIID_h
|
||||
|
||||
/**
|
||||
* An "interface id" which can be used to uniquely identify a given
|
||||
* interface.
|
||||
*/
|
||||
|
||||
typedef nsID nsIID;
|
||||
|
||||
/**
|
||||
* A macro shorthand for <tt>const nsIID&<tt>
|
||||
*/
|
||||
|
||||
#define REFNSIID const nsIID&
|
||||
|
||||
/**
|
||||
* Define an IID (obsolete)
|
||||
*/
|
||||
|
||||
#define NS_DEFINE_IID(_name, _iidspec) \
|
||||
const nsIID _name = _iidspec
|
||||
|
||||
#endif /* __nsIID_h */
|
||||
142
mozilla/xpcom/base/nsIPtr.h
Normal file
142
mozilla/xpcom/base/nsIPtr.h
Normal file
@@ -0,0 +1,142 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
|
||||
#ifndef nsIPtr_h___
|
||||
#define nsIPtr_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
/*
|
||||
* nsIPtr is an "auto-release pointer" class for nsISupports based interfaces
|
||||
*
|
||||
* It's intent is to be a "set and forget" pointer to help with managing
|
||||
* active references to nsISupports bases objects.
|
||||
*
|
||||
* The pointer object ensures that the underlying pointer is always
|
||||
* released whenever the value is changed or when the object leaves scope.
|
||||
*
|
||||
* Proper care needs to be taken when assigning pointers to a nsIPtr.
|
||||
* When asigning from a C pointer (nsISupports*), the pointer presumes
|
||||
* an active reference and subsumes it. When assigning from another nsIPtr,
|
||||
* a new reference is established.
|
||||
*
|
||||
* There are 3 ways to assign a value to a nsIPtr.
|
||||
* 1) Direct construction or assignment from a C pointer.
|
||||
* 2) Direct construction or assignment form another nsIPtr.
|
||||
* 3) Usage of an "out parameter" method.
|
||||
* a) AssignRef() releases the underlying pointer and returns a reference to it.
|
||||
* Useful for pointer reference out paramaters.
|
||||
* b) AssignPtr() releases the underlying pointer and returns a pointer to it.
|
||||
* c) Query() releases the underlying pointer and returns a (void**) pointer to it.
|
||||
* Useful for calls to QueryInterface()
|
||||
* 4) The SetAddRef() method. This is equivalent to an assignment followed by an AddRef().
|
||||
*
|
||||
* examples:
|
||||
*
|
||||
* class It {
|
||||
* void NS_NewFoo(nsIFoo** aFoo);
|
||||
* nsIFoo* GetFoo(void);
|
||||
* void GetBar(nsIBar*& aBar);
|
||||
* };
|
||||
*
|
||||
* nsIFooPtr foo = it->GetFoo();
|
||||
* nsIBarPtr bar;
|
||||
*
|
||||
* it->NS_NewFoo(foo.AssignPtr());
|
||||
* it->GetBar(bar.AssignRef());
|
||||
* it->QueryInterface(kIFooIID, foo.Query());
|
||||
* bar.SetAddRef(new Bar());
|
||||
*
|
||||
* Advantages:
|
||||
* Set and forget. Once a pointer is assigned to a nsIPtr, it is impossible
|
||||
* to forget to release it.
|
||||
* Always pre-initialized. You can't forget to initialize the pointer.
|
||||
*
|
||||
* Disadvantages:
|
||||
* Usage of this class doesn't eliminate the need to think about ref counts
|
||||
* and assign values properly, AddRef'ing as needed.
|
||||
* The nsIPtr doesn't typecast exactly like a C pointer. In order to achieve
|
||||
* typecasting, it may be necessary to first cast to a C pointer of the
|
||||
* underlying type.
|
||||
*
|
||||
*/
|
||||
|
||||
#define NS_DEF_PTR(cls) \
|
||||
class cls##Ptr { \
|
||||
public: \
|
||||
cls##Ptr(void) : mPtr(0) {} \
|
||||
cls##Ptr(const cls##Ptr& aCopy) : mPtr(aCopy.mPtr) \
|
||||
{ NS_IF_ADDREF(mPtr); } \
|
||||
cls##Ptr(cls* aInterface) : mPtr(aInterface) {} \
|
||||
~cls##Ptr(void) { NS_IF_RELEASE(mPtr); } \
|
||||
cls##Ptr& operator=(const cls##Ptr& aCopy) \
|
||||
{ if(mPtr == aCopy.mPtr) return *this; \
|
||||
NS_IF_ADDREF(aCopy.mPtr); \
|
||||
NS_IF_RELEASE(mPtr); \
|
||||
mPtr = aCopy.mPtr; return *this; } \
|
||||
cls##Ptr& operator=(cls* aInterface) \
|
||||
{ if(mPtr == aInterface) return *this; \
|
||||
NS_IF_RELEASE(mPtr); mPtr = aInterface; \
|
||||
return *this; } \
|
||||
cls##Ptr& operator=(PRInt32 aInt) \
|
||||
{ NS_IF_RELEASE(mPtr); \
|
||||
return *this; } \
|
||||
void SetAddRef(cls* aInterface) \
|
||||
{ if(aInterface == mPtr) return; \
|
||||
NS_IF_ADDREF(aInterface); \
|
||||
NS_IF_RELEASE(mPtr); mPtr = aInterface; } \
|
||||
cls* AddRef(void) { NS_ADDREF(mPtr); return mPtr; } \
|
||||
cls* IfAddRef(void) \
|
||||
{ NS_IF_ADDREF(mPtr); return mPtr; } \
|
||||
cls*& AssignRef(void) \
|
||||
{ NS_IF_RELEASE(mPtr); return mPtr; } \
|
||||
cls** AssignPtr(void) \
|
||||
{ NS_IF_RELEASE(mPtr); return &mPtr; } \
|
||||
void** Query(void) \
|
||||
{ NS_IF_RELEASE(mPtr); return (void**)&mPtr; } \
|
||||
PRBool IsNull() const \
|
||||
{ return PRBool(0 == mPtr); } \
|
||||
PRBool IsNotNull() const \
|
||||
{ return PRBool(0 != mPtr); } \
|
||||
PRBool operator==(const cls##Ptr& aCopy) const \
|
||||
{ return PRBool(mPtr == aCopy.mPtr); } \
|
||||
PRBool operator==(cls* aInterface) const \
|
||||
{ return PRBool(mPtr == aInterface); } \
|
||||
PRBool operator!=(const cls##Ptr& aCopy) const \
|
||||
{ return PRBool(mPtr != aCopy.mPtr); } \
|
||||
PRBool operator!=(cls* aInterface) const \
|
||||
{ return PRBool(mPtr != aInterface); } \
|
||||
cls* operator->(void) { return mPtr; } \
|
||||
cls& operator*(void) { return *mPtr; } \
|
||||
operator cls*(void) { return mPtr; } \
|
||||
const cls* operator->(void) const { return mPtr; } \
|
||||
const cls& operator*(void) const { return *mPtr; } \
|
||||
operator const cls* (void) const { return mPtr; } \
|
||||
private: \
|
||||
void* operator new(size_t size) { return 0; } \
|
||||
void operator delete(void* aPtr) {} \
|
||||
cls* mPtr; \
|
||||
public: \
|
||||
friend inline PRBool operator==(const cls* aInterface, const cls##Ptr& aPtr) \
|
||||
{ return PRBool(aInterface == aPtr.mPtr); } \
|
||||
friend inline PRBool operator!=(const cls* aInterface, const cls##Ptr& aPtr) \
|
||||
{ return PRBool(aInterface != aPtr.mPtr); } \
|
||||
}
|
||||
|
||||
#endif // nsIPtr_h___
|
||||
|
||||
46
mozilla/xpcom/base/nsISupports.idl
Normal file
46
mozilla/xpcom/base/nsISupports.idl
Normal file
@@ -0,0 +1,46 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
%{C++
|
||||
#include "nsDebug.h"
|
||||
#include "nsTraceRefcnt.h"
|
||||
#include "nsIID.h"
|
||||
%}
|
||||
#include "nsID.idl"
|
||||
%{C++
|
||||
#include "nsError.h"
|
||||
|
||||
#include "nsISupportsUtils.h"
|
||||
%}
|
||||
|
||||
native nsQIResult(void *);
|
||||
native voidStar(void*);
|
||||
native voidStarRef(void**);
|
||||
native nsIIDRef(REFNSIID);
|
||||
|
||||
typedef unsigned long nsrefcnt;
|
||||
|
||||
[
|
||||
object,
|
||||
uuid(00000000-0000-0000-c000-000000000046)
|
||||
]
|
||||
interface nsISupports {
|
||||
void QueryInterface(in nsIIDRef uuid, out nsQIResult result);
|
||||
[notxpcom] nsrefcnt AddRef();
|
||||
[notxpcom] nsrefcnt Release();
|
||||
};
|
||||
557
mozilla/xpcom/base/nsISupportsUtils.h
Normal file
557
mozilla/xpcom/base/nsISupportsUtils.h
Normal file
@@ -0,0 +1,557 @@
|
||||
/* -*- 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 __nsISupportsUtils_h
|
||||
#define __nsISupportsUtils_h
|
||||
|
||||
|
||||
/**
|
||||
* A macro to build the static const IID accessor method
|
||||
*/
|
||||
|
||||
#define NS_DEFINE_STATIC_IID_ACCESSOR(the_iid) \
|
||||
static const nsIID& GetIID() {static nsIID iid = the_iid; return iid;}
|
||||
|
||||
/**
|
||||
* A macro to build the static const CID accessor method
|
||||
*/
|
||||
|
||||
#define NS_DEFINE_STATIC_CID_ACCESSOR(the_cid) \
|
||||
static const nsID& GetCID() {static nsID cid = the_cid; return cid;}
|
||||
|
||||
/**
|
||||
* Some convenience macros for implementing AddRef and Release
|
||||
*/
|
||||
|
||||
/**
|
||||
* Declare the reference count variable and the implementations of the
|
||||
* AddRef and QueryInterface methods.
|
||||
*/
|
||||
|
||||
#define NS_DECL_ISUPPORTS \
|
||||
public: \
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, \
|
||||
void** aInstancePtr); \
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void); \
|
||||
NS_IMETHOD_(nsrefcnt) Release(void); \
|
||||
protected: \
|
||||
nsrefcnt mRefCnt; \
|
||||
public:
|
||||
|
||||
#define NS_DECL_ISUPPORTS_EXPORTED \
|
||||
public: \
|
||||
NS_EXPORT NS_IMETHOD QueryInterface(REFNSIID aIID, \
|
||||
void** aInstancePtr); \
|
||||
NS_EXPORT NS_IMETHOD_(nsrefcnt) AddRef(void); \
|
||||
NS_EXPORT NS_IMETHOD_(nsrefcnt) Release(void); \
|
||||
protected: \
|
||||
nsrefcnt mRefCnt; \
|
||||
public:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Initialize the reference count variable. Add this to each and every
|
||||
* constructor you implement.
|
||||
*/
|
||||
#define NS_INIT_REFCNT() mRefCnt = 0
|
||||
#define NS_INIT_ISUPPORTS() NS_INIT_REFCNT() // what it should have been called in the first place
|
||||
|
||||
/**
|
||||
* Use this macro to implement the AddRef method for a given <i>_class</i>
|
||||
* @param _class The name of the class implementing the method
|
||||
*/
|
||||
#define NS_IMPL_ADDREF(_class) \
|
||||
NS_IMETHODIMP_(nsrefcnt) _class::AddRef(void) \
|
||||
{ \
|
||||
NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt"); \
|
||||
return ++mRefCnt; \
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this macro to implement the Release method for a given <i>_class</i>
|
||||
* @param _class The name of the class implementing the method
|
||||
*/
|
||||
#define NS_IMPL_RELEASE(_class) \
|
||||
NS_IMETHODIMP_(nsrefcnt) _class::Release(void) \
|
||||
{ \
|
||||
NS_PRECONDITION(0 != mRefCnt, "dup release"); \
|
||||
if (--mRefCnt == 0) { \
|
||||
NS_DELETEXPCOM(this); \
|
||||
return 0; \
|
||||
} \
|
||||
return mRefCnt; \
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
* Some convenience macros for implementing QueryInterface
|
||||
*/
|
||||
|
||||
/**
|
||||
* This implements query interface with two assumptions: First, the
|
||||
* class in question implements nsISupports and it's own interface and
|
||||
* nothing else. Second, the implementation of the class's primary
|
||||
* inheritance chain leads to it's own interface.
|
||||
*
|
||||
* @param _class The name of the class implementing the method
|
||||
* @param _classiiddef The name of the #define symbol that defines the IID
|
||||
* for the class (e.g. NS_ISUPPORTS_IID)
|
||||
*/
|
||||
|
||||
#define NS_IMPL_QUERY_INTERFACE(_class,_classiiddef) \
|
||||
NS_IMETHODIMP _class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \
|
||||
{ \
|
||||
if (NULL == aInstancePtr) { \
|
||||
return NS_ERROR_NULL_POINTER; \
|
||||
} \
|
||||
\
|
||||
*aInstancePtr = NULL; \
|
||||
\
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); \
|
||||
static NS_DEFINE_IID(kClassIID, _classiiddef); \
|
||||
if (aIID.Equals(kClassIID)) { \
|
||||
*aInstancePtr = (void*) this; \
|
||||
NS_ADDREF_THIS(); \
|
||||
return NS_OK; \
|
||||
} \
|
||||
if (aIID.Equals(kISupportsIID)) { \
|
||||
*aInstancePtr = (void*) ((nsISupports*)this); \
|
||||
NS_ADDREF_THIS(); \
|
||||
return NS_OK; \
|
||||
} \
|
||||
return NS_NOINTERFACE; \
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience macro for implementing all nsISupports methods for
|
||||
* a simple class.
|
||||
* @param _class The name of the class implementing the method
|
||||
* @param _classiiddef The name of the #define symbol that defines the IID
|
||||
* for the class (e.g. NS_ISUPPORTS_IID)
|
||||
*/
|
||||
|
||||
#define NS_IMPL_ISUPPORTS(_class,_classiiddef) \
|
||||
NS_IMPL_ADDREF(_class) \
|
||||
NS_IMPL_RELEASE(_class) \
|
||||
NS_IMPL_QUERY_INTERFACE(_class,_classiiddef)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Declare that you're going to inherit from something that already
|
||||
* implements nsISupports, but also implements an additional interface, thus
|
||||
* causing an ambiguity. In this case you don't need another mRefCnt, you
|
||||
* just need to forward the definitions to the appropriate superclass. E.g.
|
||||
*
|
||||
* class Bar : public Foo, public nsIBar { // both provide nsISupports
|
||||
* public:
|
||||
* NS_DECL_ISUPPORTS_INHERITED
|
||||
* ...other nsIBar and Bar methods...
|
||||
* };
|
||||
*/
|
||||
#define NS_DECL_ISUPPORTS_INHERITED \
|
||||
public: \
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, \
|
||||
void** aInstancePtr); \
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void); \
|
||||
NS_IMETHOD_(nsrefcnt) Release(void); \
|
||||
|
||||
/**
|
||||
* These macros can be used in conjunction with NS_DECL_ISUPPORTS_INHERITED
|
||||
* to implement the nsISupports methods, forwarding the invocations to a
|
||||
* superclass that already implements nsISupports.
|
||||
*
|
||||
* Note that I didn't make these inlined because they're virtual methods.
|
||||
*/
|
||||
|
||||
#define NS_IMPL_ADDREF_INHERITED(Class, Super) \
|
||||
NS_IMETHODIMP_(nsrefcnt) Class::AddRef(void) \
|
||||
{ \
|
||||
return Super::AddRef(); \
|
||||
} \
|
||||
|
||||
#define NS_IMPL_RELEASE_INHERITED(Class, Super) \
|
||||
NS_IMETHODIMP_(nsrefcnt) Class::Release(void) \
|
||||
{ \
|
||||
return Super::Release(); \
|
||||
} \
|
||||
|
||||
#define NS_IMPL_QUERY_INTERFACE_INHERITED(Class, Super, AdditionalInterface) \
|
||||
NS_IMETHODIMP Class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \
|
||||
{ \
|
||||
if (!aInstancePtr) return NS_ERROR_NULL_POINTER; \
|
||||
if (aIID.Equals(AdditionalInterface::GetIID())) { \
|
||||
*aInstancePtr = NS_STATIC_CAST(AdditionalInterface*, this); \
|
||||
NS_ADDREF_THIS(); \
|
||||
return NS_OK; \
|
||||
} \
|
||||
return Super::QueryInterface(aIID, aInstancePtr); \
|
||||
} \
|
||||
|
||||
#define NS_IMPL_ISUPPORTS_INHERITED(Class, Super, AdditionalInterface) \
|
||||
NS_IMPL_QUERY_INTERFACE_INHERITED(Class, Super, AdditionalInterface) \
|
||||
NS_IMPL_ADDREF_INHERITED(Class, Super) \
|
||||
NS_IMPL_RELEASE_INHERITED(Class, Super) \
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
*
|
||||
* Threadsafe implementations of the ISupports convenience macros
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* IID for the nsIsThreadsafe interface
|
||||
* {88210890-47a6-11d2-bec3-00805f8a66dc}
|
||||
*
|
||||
* This interface is *only* used for debugging purposes to determine if
|
||||
* a given component is threadsafe.
|
||||
*/
|
||||
#define NS_ISTHREADSAFE_IID \
|
||||
{ 0x88210890, 0x47a6, 0x11d2, \
|
||||
{0xbe, 0xc3, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc} }
|
||||
|
||||
#if defined(NS_MT_SUPPORTED)
|
||||
|
||||
#define NS_LOCK_INSTANCE() \
|
||||
PR_CEnterMonitor((void*)this)
|
||||
|
||||
#define NS_UNLOCK_INSTANCE() \
|
||||
PR_CExitMonitor((void*)this)
|
||||
|
||||
/**
|
||||
* Use this macro to implement the AddRef method for a given <i>_class</i>
|
||||
* @param _class The name of the class implementing the method
|
||||
*/
|
||||
#if defined(XP_PC)
|
||||
#define NS_IMPL_THREADSAFE_ADDREF(_class) \
|
||||
NS_IMETHODIMP_(nsrefcnt) _class::AddRef(void) \
|
||||
{ \
|
||||
NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt"); \
|
||||
return InterlockedIncrement((LONG*)&mRefCnt); \
|
||||
}
|
||||
|
||||
#else /* ! XP_PC */
|
||||
#define NS_IMPL_THREADSAFE_ADDREF(_class) \
|
||||
nsrefcnt _class::AddRef(void) \
|
||||
{ \
|
||||
nsrefcnt count; \
|
||||
NS_LOCK_INSTANCE(); \
|
||||
NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt"); \
|
||||
count = ++mRefCnt; \
|
||||
NS_UNLOCK_INSTANCE(); \
|
||||
return count; \
|
||||
}
|
||||
#endif /* ! XP_PC */
|
||||
|
||||
/**
|
||||
* Use this macro to implement the Release method for a given <i>_class</i>
|
||||
* @param _class The name of the class implementing the method
|
||||
*/
|
||||
#if defined(XP_PC)
|
||||
#define NS_IMPL_THREADSAFE_RELEASE(_class) \
|
||||
NS_IMETHODIMP_(nsrefcnt) _class::Release(void) \
|
||||
{ \
|
||||
NS_PRECONDITION(0 != mRefCnt, "dup release"); \
|
||||
if (0 == InterlockedDecrement((LONG*)&mRefCnt)) { \
|
||||
NS_DELETEXPCOM(this); \
|
||||
return 0; \
|
||||
} \
|
||||
return mRefCnt; /* Not threadsafe but who cares. */ \
|
||||
}
|
||||
|
||||
#else /* ! XP_PC */
|
||||
#define NS_IMPL_THREADSAFE_RELEASE(_class) \
|
||||
nsrefcnt _class::Release(void) \
|
||||
{ \
|
||||
nsrefcnt count; \
|
||||
NS_PRECONDITION(0 != mRefCnt, "dup release"); \
|
||||
NS_LOCK_INSTANCE(); \
|
||||
count = --mRefCnt; \
|
||||
NS_UNLOCK_INSTANCE(); \
|
||||
if (0 == count) { \
|
||||
NS_DELETEXPCOM(this); \
|
||||
return 0; \
|
||||
} \
|
||||
return count; \
|
||||
}
|
||||
#endif /* ! XP_PC */
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
* Some convenience macros for implementing QueryInterface
|
||||
*/
|
||||
|
||||
/**
|
||||
* This implements query interface with two assumptions: First, the
|
||||
* class in question implements nsISupports and it's own interface and
|
||||
* nothing else. Second, the implementation of the class's primary
|
||||
* inheritance chain leads to it's own interface.
|
||||
*
|
||||
* @param _class The name of the class implementing the method
|
||||
* @param _classiiddef The name of the #define symbol that defines the IID
|
||||
* for the class (e.g. NS_ISUPPORTS_IID)
|
||||
*/
|
||||
#if defined(NS_DEBUG)
|
||||
#define NS_VERIFY_THREADSAFE_INTERFACE(_iface) \
|
||||
if (NULL != (_iface)) { \
|
||||
nsISupports* tmp; \
|
||||
static NS_DEFINE_IID(kIsThreadsafeIID, NS_ISTHREADSAFE_IID); \
|
||||
NS_PRECONDITION((NS_OK == _iface->QueryInterface(kIsThreadsafeIID, \
|
||||
(void**)&tmp)), \
|
||||
"Interface is not threadsafe"); \
|
||||
}
|
||||
|
||||
#define NS_IMPL_THREADSAFE_QUERY_INTERFACE(_class,_classiiddef) \
|
||||
NS_IMETHODIMP _class::QueryInterface(REFNSIID aIID, void** aInstancePtr) \
|
||||
{ \
|
||||
if (NULL == aInstancePtr) { \
|
||||
return NS_ERROR_NULL_POINTER; \
|
||||
} \
|
||||
\
|
||||
*aInstancePtr = NULL; \
|
||||
\
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); \
|
||||
static NS_DEFINE_IID(kIsThreadsafeIID, NS_ISTHREADSAFE_IID); \
|
||||
static NS_DEFINE_IID(kClassIID, _classiiddef); \
|
||||
if (aIID.Equals(kClassIID)) { \
|
||||
*aInstancePtr = (void*) this; \
|
||||
NS_ADDREF_THIS(); \
|
||||
return NS_OK; \
|
||||
} \
|
||||
if (aIID.Equals(kISupportsIID)) { \
|
||||
*aInstancePtr = (void*) ((nsISupports*)this); \
|
||||
NS_ADDREF_THIS(); \
|
||||
return NS_OK; \
|
||||
} \
|
||||
if (aIID.Equals(kIsThreadsafeIID)) { \
|
||||
return NS_OK; \
|
||||
} \
|
||||
return NS_NOINTERFACE; \
|
||||
}
|
||||
|
||||
#else /* !NS_DEBUG */
|
||||
|
||||
#define NS_VERIFY_THREADSAFE_INTERFACE(_iface)
|
||||
#define NS_IMPL_THREADSAFE_QUERY_INTERFACE(_class,_classiiddef) \
|
||||
NS_IMPL_QUERY_INTERFACE(_class, _classiiddef)
|
||||
|
||||
#endif /* !NS_DEBUG */
|
||||
|
||||
/**
|
||||
* Convenience macro for implementing all nsISupports methods for
|
||||
* a simple class.
|
||||
* @param _class The name of the class implementing the method
|
||||
* @param _classiiddef The name of the #define symbol that defines the IID
|
||||
* for the class (e.g. NS_ISUPPORTS_IID)
|
||||
*/
|
||||
|
||||
#define NS_IMPL_THREADSAFE_ISUPPORTS(_class,_classiiddef) \
|
||||
NS_IMPL_THREADSAFE_ADDREF(_class) \
|
||||
NS_IMPL_THREADSAFE_RELEASE(_class) \
|
||||
NS_IMPL_THREADSAFE_QUERY_INTERFACE(_class,_classiiddef)
|
||||
|
||||
#else /* !NS_MT_SUPPORTED */
|
||||
|
||||
#define NS_LOCK_INSTANCE()
|
||||
|
||||
#define NS_UNLOCK_INSTANCE()
|
||||
|
||||
#define NS_IMPL_THREADSAFE_ADDREF(_class) NS_IMPL_ADDREF(_class)
|
||||
|
||||
#define NS_IMPL_THREADSAFE_RELEASE(_class) NS_IMPL_RELEASE(_class)
|
||||
|
||||
#define NS_VERIFY_THREADSAFE_INTERFACE(_iface)
|
||||
|
||||
#define NS_IMPL_THREADSAFE_QUERY_INTERFACE(_class,_classiiddef) \
|
||||
NS_IMPL_QUERY_INTERFACE(_class, _classiiddef)
|
||||
|
||||
#define NS_IMPL_THREADSAFE_ISUPPORTS(_class,_classiiddef) \
|
||||
NS_IMPL_ADDREF(_class) \
|
||||
NS_IMPL_RELEASE(_class) \
|
||||
NS_IMPL_QUERY_INTERFACE(_class,_classiiddef)
|
||||
|
||||
#endif /* !NS_MT_SUPPORTED */
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Debugging Macros
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Macro for instantiating a new object that implements nsISupports.
|
||||
* Use this in your factory methods to allow for refcnt tracing.
|
||||
* Note that you can only use this if you adhere to the no arguments
|
||||
* constructor com policy (which you really should!).
|
||||
* @param _result Where the new instance pointer is stored
|
||||
* @param _type The type of object to call "new" with.
|
||||
*/
|
||||
#ifdef MOZ_TRACE_XPCOM_REFCNT
|
||||
#define NS_NEWXPCOM(_result,_type) \
|
||||
PR_BEGIN_MACRO \
|
||||
_result = new _type(); \
|
||||
nsTraceRefcnt::Create(_result, #_type, __FILE__, __LINE__); \
|
||||
PR_END_MACRO
|
||||
#else
|
||||
#define NS_NEWXPCOM(_result,_type) \
|
||||
_result = new _type()
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Macro for deleting an object that implements nsISupports.
|
||||
* Use this in your Release methods to allow for refcnt tracing.
|
||||
* @param _ptr The object to delete.
|
||||
*/
|
||||
#ifdef MOZ_TRACE_XPCOM_REFCNT
|
||||
#define NS_DELETEXPCOM(_ptr) \
|
||||
PR_BEGIN_MACRO \
|
||||
nsTraceRefcnt::Destroy((_ptr), __FILE__, __LINE__); \
|
||||
delete (_ptr); \
|
||||
PR_END_MACRO
|
||||
#else
|
||||
#define NS_DELETEXPCOM(_ptr) \
|
||||
delete (_ptr)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Macro for adding a reference to an interface.
|
||||
* @param _ptr The interface pointer.
|
||||
*/
|
||||
#ifdef MOZ_TRACE_XPCOM_REFCNT
|
||||
#define NS_ADDREF(_ptr) \
|
||||
((nsrefcnt) nsTraceRefcnt::AddRef((_ptr), (_ptr)->AddRef(), \
|
||||
__FILE__, __LINE__))
|
||||
#else
|
||||
#define NS_ADDREF(_ptr) \
|
||||
(_ptr)->AddRef()
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Macro for adding a reference to this. This macro should be used
|
||||
* because NS_ADDREF (when tracing) may require an ambiguous cast
|
||||
* from the pointers primary type to nsISupports. This macro sidesteps
|
||||
* that entire problem.
|
||||
*/
|
||||
#ifdef MOZ_TRACE_XPCOM_REFCNT
|
||||
#define NS_ADDREF_THIS() \
|
||||
((nsrefcnt) nsTraceRefcnt::AddRef(this, AddRef(), __FILE__, __LINE__))
|
||||
#else
|
||||
#define NS_ADDREF_THIS() \
|
||||
AddRef()
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Macro for adding a reference to an interface that checks for NULL.
|
||||
* @param _ptr The interface pointer.
|
||||
*/
|
||||
#ifdef MOZ_TRACE_XPCOM_REFCNT
|
||||
#define NS_IF_ADDREF(_ptr) \
|
||||
((0 != (_ptr)) \
|
||||
? ((nsrefcnt) nsTraceRefcnt::AddRef((_ptr), (_ptr)->AddRef(), __FILE__, \
|
||||
__LINE__)) \
|
||||
: 0)
|
||||
#else
|
||||
#define NS_IF_ADDREF(_ptr) \
|
||||
((0 != (_ptr)) ? (_ptr)->AddRef() : 0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Macro for releasing a reference to an interface.
|
||||
*
|
||||
* Note that when MOZ_TRACE_XPCOM_REFCNT is defined that the release will
|
||||
* be done before the trace message is logged. If the reference count
|
||||
* goes to zero and implementation of Release logs a message, the two
|
||||
* messages will be logged out of order.
|
||||
*
|
||||
* @param _ptr The interface pointer.
|
||||
*/
|
||||
#ifdef MOZ_TRACE_XPCOM_REFCNT
|
||||
#define NS_RELEASE(_ptr) \
|
||||
PR_BEGIN_MACRO \
|
||||
nsTraceRefcnt::Release((_ptr), (_ptr)->Release(), __FILE__, __LINE__); \
|
||||
(_ptr) = 0; \
|
||||
PR_END_MACRO
|
||||
#else
|
||||
#define NS_RELEASE(_ptr) \
|
||||
PR_BEGIN_MACRO \
|
||||
(_ptr)->Release(); \
|
||||
(_ptr) = 0; \
|
||||
PR_END_MACRO
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Macro for releasing a reference to an interface, except that this
|
||||
* macro preserves the return value from the underlying Release call.
|
||||
* The interface pointer argument will only be NULLed if the reference count
|
||||
* goes to zero.
|
||||
*
|
||||
* Note that when MOZ_TRACE_XPCOM_REFCNT is defined that the release will
|
||||
* be done before the trace message is logged. If the reference count
|
||||
* goes to zero and implementation of Release logs a message, the two
|
||||
* messages will be logged out of order.
|
||||
*
|
||||
* @param _ptr The interface pointer.
|
||||
*/
|
||||
#ifdef MOZ_TRACE_XPCOM_REFCNT
|
||||
#define NS_RELEASE2(_ptr, _result) \
|
||||
PR_BEGIN_MACRO \
|
||||
_result = ((nsrefcnt) nsTraceRefcnt::Release((_ptr), (_ptr)->Release(), \
|
||||
__FILE__, __LINE__)); \
|
||||
if (0 == (_result)) (_ptr) = 0; \
|
||||
PR_END_MACRO
|
||||
#else
|
||||
#define NS_RELEASE2(_ptr, _result) \
|
||||
PR_BEGIN_MACRO \
|
||||
_result = (_ptr)->Release(); \
|
||||
if (0 == (_result)) (_ptr) = 0; \
|
||||
PR_END_MACRO
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Macro for releasing a reference to an interface that checks for NULL;
|
||||
*
|
||||
* Note that when MOZ_TRACE_XPCOM_REFCNT is defined that the release will
|
||||
* be done before the trace message is logged. If the reference count
|
||||
* goes to zero and implementation of Release logs a message, the two
|
||||
* messages will be logged out of order.
|
||||
*
|
||||
* @param _ptr The interface pointer.
|
||||
*/
|
||||
#ifdef MOZ_TRACE_XPCOM_REFCNT
|
||||
#define NS_IF_RELEASE(_ptr) \
|
||||
PR_BEGIN_MACRO \
|
||||
((0 != (_ptr)) \
|
||||
? ((nsrefcnt) nsTraceRefcnt::Release((_ptr), (_ptr)->Release(), \
|
||||
__FILE__, __LINE__)) \
|
||||
: 0); \
|
||||
(_ptr) = 0; \
|
||||
PR_END_MACRO
|
||||
#else
|
||||
#define NS_IF_RELEASE(_ptr) \
|
||||
PR_BEGIN_MACRO \
|
||||
((0 != (_ptr)) ? (_ptr)->Release() : 0); \
|
||||
(_ptr) = 0; \
|
||||
PR_END_MACRO
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif /* __nsISupportsUtils_h */
|
||||
317
mozilla/xpcom/base/nsTraceRefcnt.cpp
Normal file
317
mozilla/xpcom/base/nsTraceRefcnt.cpp
Normal file
@@ -0,0 +1,317 @@
|
||||
/* -*- 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 "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.
|
||||
*/
|
||||
#include "nsISupports.h"
|
||||
#include "prprf.h"
|
||||
#include "prlog.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
static PRLogModuleInfo* gTraceRefcntLog;
|
||||
|
||||
#if defined(NS_MT_SUPPORTED)
|
||||
#include "prlock.h"
|
||||
|
||||
static PRLock* gTraceLock;
|
||||
|
||||
#define LOCK_TRACELOG() PR_Lock(gTraceLock)
|
||||
#define UNLOCK_TRACELOG() PR_Unlock(gTraceLock)
|
||||
#else /* ! NT_MT_SUPPORTED */
|
||||
#define LOCK_TRACELOG()
|
||||
#define UNLOCK_TRACELOG()
|
||||
#endif /* ! NS_MT_SUPPORTED */
|
||||
|
||||
static void InitTraceLog(void)
|
||||
{
|
||||
if (0 == gTraceRefcntLog) {
|
||||
gTraceRefcntLog = PR_NewLogModule("xpcomrefcnt");
|
||||
|
||||
#if defined(NS_MT_SUPPORTED)
|
||||
gTraceLock = PR_NewLock();
|
||||
#endif /* NS_MT_SUPPORTED */
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(MOZ_TRACE_XPCOM_REFCNT)
|
||||
#if defined(_WIN32)
|
||||
#include "imagehlp.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#if 0
|
||||
static BOOL __stdcall
|
||||
EnumSymbolsCB(LPSTR aSymbolName,
|
||||
ULONG aSymbolAddress,
|
||||
ULONG aSymbolSize,
|
||||
PVOID aUserContext)
|
||||
{
|
||||
int* countp = (int*) aUserContext;
|
||||
int count = *countp;
|
||||
if (count < 3) {
|
||||
printf(" %p[%4d]: %s\n", aSymbolAddress, aSymbolSize, aSymbolName);
|
||||
count++;
|
||||
*countp = count++;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL __stdcall
|
||||
EnumModulesCB(LPSTR aModuleName,
|
||||
ULONG aBaseOfDll,
|
||||
PVOID aUserContext)
|
||||
{
|
||||
HANDLE myProcess = ::GetCurrentProcess();
|
||||
|
||||
printf("module=%s dll=%x\n", aModuleName, aBaseOfDll);
|
||||
// int count = 0;
|
||||
// SymEnumerateSymbols(myProcess, aBaseOfDll, EnumSymbolsCB, (void*) &count);
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Walk the stack, translating PC's found into strings and recording the
|
||||
* chain in aBuffer. For this to work properly, the dll's must be rebased
|
||||
* so that the address in the file agrees with the address in memory.
|
||||
* Otherwise StackWalk will return FALSE when it hits a frame in a dll's
|
||||
* whose in memory address doesn't match it's in-file address.
|
||||
*
|
||||
* Fortunately, there is a handy dandy routine in IMAGEHLP.DLL that does
|
||||
* the rebasing and accordingly I've made a tool to use it to rebase the
|
||||
* DLL's in one fell swoop (see xpcom/tools/windows/rebasedlls.cpp).
|
||||
*/
|
||||
void
|
||||
nsTraceRefcnt::WalkTheStack(char* aBuffer, int aBufLen)
|
||||
{
|
||||
CONTEXT context;
|
||||
STACKFRAME frame;
|
||||
char* cp = aBuffer;
|
||||
|
||||
aBuffer[0] = '\0';
|
||||
aBufLen--; // leave room for nul
|
||||
|
||||
HANDLE myProcess = ::GetCurrentProcess();
|
||||
HANDLE myThread = ::GetCurrentThread();
|
||||
|
||||
// Get the context information for this thread. That way we will
|
||||
// know where our sp, fp, pc, etc. are and can fill in the
|
||||
// STACKFRAME with the initial values.
|
||||
context.ContextFlags = CONTEXT_FULL;
|
||||
GetThreadContext(myThread, &context);
|
||||
|
||||
if (!SymInitialize(myProcess, ".;..\\lib", TRUE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
SymEnumerateModules(myProcess, EnumModulesCB, NULL);
|
||||
#endif
|
||||
|
||||
// Setup initial stack frame to walk from
|
||||
memset(&frame, 0, sizeof(frame));
|
||||
frame.AddrPC.Mode = AddrModeFlat;
|
||||
frame.AddrPC.Offset = context.Eip;
|
||||
frame.AddrReturn.Mode = AddrModeFlat;
|
||||
frame.AddrReturn.Offset = context.Ebp;
|
||||
frame.AddrFrame.Mode = AddrModeFlat;
|
||||
frame.AddrFrame.Offset = context.Ebp;
|
||||
frame.AddrStack.Mode = AddrModeFlat;
|
||||
frame.AddrStack.Offset = context.Esp;
|
||||
frame.Params[0] = context.Eax;
|
||||
frame.Params[1] = context.Ecx;
|
||||
frame.Params[2] = context.Edx;
|
||||
frame.Params[3] = context.Ebx;
|
||||
|
||||
// Now walk the stack and map the pc's to symbol names that we stuff
|
||||
// append to *cp.
|
||||
|
||||
int skip = 2;
|
||||
int syms = 0;
|
||||
while (aBufLen > 0) {
|
||||
char symbolBuffer[sizeof(IMAGEHLP_SYMBOL) + 512];
|
||||
PIMAGEHLP_SYMBOL pSymbol = (PIMAGEHLP_SYMBOL) symbolBuffer;
|
||||
pSymbol->SizeOfStruct = sizeof(symbolBuffer);
|
||||
pSymbol->MaxNameLength = 512;
|
||||
|
||||
DWORD oldAddress = frame.AddrPC.Offset;
|
||||
BOOL b = ::StackWalk(IMAGE_FILE_MACHINE_I386, myProcess, myThread,
|
||||
&frame, &context, NULL,
|
||||
SymFunctionTableAccess,
|
||||
SymGetModuleBase,
|
||||
NULL);
|
||||
if (!b || (0 == frame.AddrPC.Offset)) {
|
||||
if (syms <= 1) {
|
||||
skip = 7;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (--skip >= 0) {
|
||||
continue;
|
||||
}
|
||||
DWORD disp;
|
||||
if (SymGetSymFromAddr(myProcess, frame.AddrPC.Offset, &disp, pSymbol)) {
|
||||
int nameLen = strlen(pSymbol->Name);
|
||||
if (nameLen + 2 > aBufLen) {
|
||||
break;
|
||||
}
|
||||
memcpy(cp, pSymbol->Name, nameLen);
|
||||
cp += nameLen;
|
||||
*cp++ = ' ';
|
||||
aBufLen -= nameLen + 1;
|
||||
syms++;
|
||||
}
|
||||
else {
|
||||
if (11 > aBufLen) {
|
||||
break;
|
||||
}
|
||||
char tmp[30];
|
||||
PR_snprintf(tmp, sizeof(tmp), "0x%08x ", frame.AddrPC.Offset);
|
||||
memcpy(cp, tmp, 11);
|
||||
cp += 11;
|
||||
aBufLen -= 11;
|
||||
syms++;
|
||||
}
|
||||
}
|
||||
*cp = 0;
|
||||
}
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#else /* MOZ_TRACE_XPCOM_REFCNT */
|
||||
void
|
||||
nsTraceRefcnt::WalkTheStack(char* aBuffer, int aBufLen)
|
||||
{
|
||||
aBuffer[0] = '\0';
|
||||
}
|
||||
#endif /* MOZ_TRACE_XPCOM_REFCNT */
|
||||
|
||||
NS_COM void
|
||||
nsTraceRefcnt::LoadLibrarySymbols(const char* aLibraryName,
|
||||
void* aLibrayHandle)
|
||||
{
|
||||
#ifdef MOZ_TRACE_XPCOM_REFCNT
|
||||
#if defined(_WIN32)
|
||||
InitTraceLog();
|
||||
if (PR_LOG_TEST(gTraceRefcntLog,PR_LOG_DEBUG)) {
|
||||
HANDLE myProcess = ::GetCurrentProcess();
|
||||
|
||||
if (!SymInitialize(myProcess, ".;..\\lib", TRUE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
BOOL b = ::SymLoadModule(myProcess,
|
||||
NULL,
|
||||
(char*)aLibraryName,
|
||||
(char*)aLibraryName,
|
||||
0,
|
||||
0);
|
||||
// DWORD lastError = 0;
|
||||
// if (!b) lastError = ::GetLastError();
|
||||
// printf("loading symbols for library %s => %s [%d]\n", aLibraryName,
|
||||
// b ? "true" : "false", lastError);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_COM unsigned long
|
||||
nsTraceRefcnt::AddRef(void* aPtr,
|
||||
unsigned long aNewRefcnt,
|
||||
const char* aFile,
|
||||
PRIntn aLine)
|
||||
{
|
||||
#ifdef MOZ_TRACE_XPCOM_REFCNT
|
||||
InitTraceLog();
|
||||
|
||||
LOCK_TRACELOG();
|
||||
if (PR_LOG_TEST(gTraceRefcntLog,PR_LOG_DEBUG)) {
|
||||
char sb[1000];
|
||||
WalkTheStack(sb, sizeof(sb));
|
||||
PR_LOG(gTraceRefcntLog, PR_LOG_DEBUG,
|
||||
("AddRef: %p: %d=>%d [%s] in %s (line %d)",
|
||||
aPtr, aNewRefcnt-1, aNewRefcnt, sb, aFile, aLine));
|
||||
}
|
||||
UNLOCK_TRACELOG();
|
||||
#endif
|
||||
return aNewRefcnt;
|
||||
|
||||
}
|
||||
|
||||
NS_COM unsigned long
|
||||
nsTraceRefcnt::Release(void* aPtr,
|
||||
unsigned long aNewRefcnt,
|
||||
const char* aFile,
|
||||
PRIntn aLine)
|
||||
{
|
||||
#ifdef MOZ_TRACE_XPCOM_REFCNT
|
||||
InitTraceLog();
|
||||
|
||||
LOCK_TRACELOG();
|
||||
if (PR_LOG_TEST(gTraceRefcntLog,PR_LOG_DEBUG)) {
|
||||
char sb[1000];
|
||||
WalkTheStack(sb, sizeof(sb));
|
||||
PR_LOG(gTraceRefcntLog, PR_LOG_DEBUG,
|
||||
("Release: %p: %d=>%d [%s] in %s (line %d)",
|
||||
aPtr, aNewRefcnt+1, aNewRefcnt, sb, aFile, aLine));
|
||||
}
|
||||
UNLOCK_TRACELOG();
|
||||
#endif
|
||||
return aNewRefcnt;
|
||||
}
|
||||
|
||||
NS_COM void
|
||||
nsTraceRefcnt::Create(void* aPtr,
|
||||
const char* aType,
|
||||
const char* aFile,
|
||||
PRIntn aLine)
|
||||
{
|
||||
#ifdef MOZ_TRACE_XPCOM_REFCNT
|
||||
InitTraceLog();
|
||||
|
||||
LOCK_TRACELOG();
|
||||
if (PR_LOG_TEST(gTraceRefcntLog,PR_LOG_DEBUG)) {
|
||||
char sb[1000];
|
||||
WalkTheStack(sb, sizeof(sb));
|
||||
PR_LOG(gTraceRefcntLog, PR_LOG_DEBUG,
|
||||
("Create: %p[%s]: [%s] in %s (line %d)",
|
||||
aPtr, aType, sb, aFile, aLine));
|
||||
}
|
||||
UNLOCK_TRACELOG();
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_COM void
|
||||
nsTraceRefcnt::Destroy(void* aPtr,
|
||||
const char* aFile,
|
||||
PRIntn aLine)
|
||||
{
|
||||
#ifdef MOZ_TRACE_XPCOM_REFCNT
|
||||
InitTraceLog();
|
||||
|
||||
LOCK_TRACELOG();
|
||||
if (PR_LOG_TEST(gTraceRefcntLog,PR_LOG_DEBUG)) {
|
||||
char sb[1000];
|
||||
WalkTheStack(sb, sizeof(sb));
|
||||
PR_LOG(gTraceRefcntLog, PR_LOG_DEBUG,
|
||||
("Destroy: %p: [%s] in %s (line %d)",
|
||||
aPtr, sb, aFile, aLine));
|
||||
}
|
||||
UNLOCK_TRACELOG();
|
||||
#endif
|
||||
}
|
||||
61
mozilla/xpcom/base/nsTraceRefcnt.h
Normal file
61
mozilla/xpcom/base/nsTraceRefcnt.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/* -*- 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 "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.
|
||||
*/
|
||||
#ifndef nsTraceRefcnt_h___
|
||||
#define nsTraceRefcnt_h___
|
||||
|
||||
#include "nsCom.h"
|
||||
|
||||
/**
|
||||
* This class is used to support tracing (and logging using nspr) of
|
||||
* addref and release calls. Note that only calls that use the
|
||||
* NS_ADDREF and related macros in nsISupports can be traced.
|
||||
*
|
||||
* The name of the nspr log module is "xpcomrefcnt" (case matters).
|
||||
*
|
||||
* This code only performs tracing built with debugging AND when
|
||||
* built with -DMOZ_TRACE_XPCOM_REFCNT (because it's expensive!).
|
||||
*/
|
||||
class nsTraceRefcnt {
|
||||
public:
|
||||
static NS_COM unsigned long AddRef(void* aPtr,
|
||||
unsigned long aNewRefcnt,
|
||||
const char* aFile,
|
||||
int aLine);
|
||||
|
||||
static NS_COM unsigned long Release(void* aPtr,
|
||||
unsigned long aNewRefcnt,
|
||||
const char* aFile,
|
||||
int aLine);
|
||||
|
||||
static NS_COM void Create(void* aPtr,
|
||||
const char* aType,
|
||||
const char* aFile,
|
||||
int aLine);
|
||||
|
||||
static NS_COM void Destroy(void* aPtr,
|
||||
const char* aFile,
|
||||
int aLine);
|
||||
|
||||
static NS_COM void LoadLibrarySymbols(const char* aLibraryName,
|
||||
void* aLibrayHandle);
|
||||
|
||||
static NS_COM void WalkTheStack(char* aBuffer, int aBufLen);
|
||||
};
|
||||
|
||||
#endif /* nsTraceRefcnt_h___ */
|
||||
317
mozilla/xpcom/base/nsTraceRefcntImpl.cpp
Normal file
317
mozilla/xpcom/base/nsTraceRefcntImpl.cpp
Normal file
@@ -0,0 +1,317 @@
|
||||
/* -*- 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 "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.
|
||||
*/
|
||||
#include "nsISupports.h"
|
||||
#include "prprf.h"
|
||||
#include "prlog.h"
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
static PRLogModuleInfo* gTraceRefcntLog;
|
||||
|
||||
#if defined(NS_MT_SUPPORTED)
|
||||
#include "prlock.h"
|
||||
|
||||
static PRLock* gTraceLock;
|
||||
|
||||
#define LOCK_TRACELOG() PR_Lock(gTraceLock)
|
||||
#define UNLOCK_TRACELOG() PR_Unlock(gTraceLock)
|
||||
#else /* ! NT_MT_SUPPORTED */
|
||||
#define LOCK_TRACELOG()
|
||||
#define UNLOCK_TRACELOG()
|
||||
#endif /* ! NS_MT_SUPPORTED */
|
||||
|
||||
static void InitTraceLog(void)
|
||||
{
|
||||
if (0 == gTraceRefcntLog) {
|
||||
gTraceRefcntLog = PR_NewLogModule("xpcomrefcnt");
|
||||
|
||||
#if defined(NS_MT_SUPPORTED)
|
||||
gTraceLock = PR_NewLock();
|
||||
#endif /* NS_MT_SUPPORTED */
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(MOZ_TRACE_XPCOM_REFCNT)
|
||||
#if defined(_WIN32)
|
||||
#include "imagehlp.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#if 0
|
||||
static BOOL __stdcall
|
||||
EnumSymbolsCB(LPSTR aSymbolName,
|
||||
ULONG aSymbolAddress,
|
||||
ULONG aSymbolSize,
|
||||
PVOID aUserContext)
|
||||
{
|
||||
int* countp = (int*) aUserContext;
|
||||
int count = *countp;
|
||||
if (count < 3) {
|
||||
printf(" %p[%4d]: %s\n", aSymbolAddress, aSymbolSize, aSymbolName);
|
||||
count++;
|
||||
*countp = count++;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static BOOL __stdcall
|
||||
EnumModulesCB(LPSTR aModuleName,
|
||||
ULONG aBaseOfDll,
|
||||
PVOID aUserContext)
|
||||
{
|
||||
HANDLE myProcess = ::GetCurrentProcess();
|
||||
|
||||
printf("module=%s dll=%x\n", aModuleName, aBaseOfDll);
|
||||
// int count = 0;
|
||||
// SymEnumerateSymbols(myProcess, aBaseOfDll, EnumSymbolsCB, (void*) &count);
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Walk the stack, translating PC's found into strings and recording the
|
||||
* chain in aBuffer. For this to work properly, the dll's must be rebased
|
||||
* so that the address in the file agrees with the address in memory.
|
||||
* Otherwise StackWalk will return FALSE when it hits a frame in a dll's
|
||||
* whose in memory address doesn't match it's in-file address.
|
||||
*
|
||||
* Fortunately, there is a handy dandy routine in IMAGEHLP.DLL that does
|
||||
* the rebasing and accordingly I've made a tool to use it to rebase the
|
||||
* DLL's in one fell swoop (see xpcom/tools/windows/rebasedlls.cpp).
|
||||
*/
|
||||
void
|
||||
nsTraceRefcnt::WalkTheStack(char* aBuffer, int aBufLen)
|
||||
{
|
||||
CONTEXT context;
|
||||
STACKFRAME frame;
|
||||
char* cp = aBuffer;
|
||||
|
||||
aBuffer[0] = '\0';
|
||||
aBufLen--; // leave room for nul
|
||||
|
||||
HANDLE myProcess = ::GetCurrentProcess();
|
||||
HANDLE myThread = ::GetCurrentThread();
|
||||
|
||||
// Get the context information for this thread. That way we will
|
||||
// know where our sp, fp, pc, etc. are and can fill in the
|
||||
// STACKFRAME with the initial values.
|
||||
context.ContextFlags = CONTEXT_FULL;
|
||||
GetThreadContext(myThread, &context);
|
||||
|
||||
if (!SymInitialize(myProcess, ".;..\\lib", TRUE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if 0
|
||||
SymEnumerateModules(myProcess, EnumModulesCB, NULL);
|
||||
#endif
|
||||
|
||||
// Setup initial stack frame to walk from
|
||||
memset(&frame, 0, sizeof(frame));
|
||||
frame.AddrPC.Mode = AddrModeFlat;
|
||||
frame.AddrPC.Offset = context.Eip;
|
||||
frame.AddrReturn.Mode = AddrModeFlat;
|
||||
frame.AddrReturn.Offset = context.Ebp;
|
||||
frame.AddrFrame.Mode = AddrModeFlat;
|
||||
frame.AddrFrame.Offset = context.Ebp;
|
||||
frame.AddrStack.Mode = AddrModeFlat;
|
||||
frame.AddrStack.Offset = context.Esp;
|
||||
frame.Params[0] = context.Eax;
|
||||
frame.Params[1] = context.Ecx;
|
||||
frame.Params[2] = context.Edx;
|
||||
frame.Params[3] = context.Ebx;
|
||||
|
||||
// Now walk the stack and map the pc's to symbol names that we stuff
|
||||
// append to *cp.
|
||||
|
||||
int skip = 2;
|
||||
int syms = 0;
|
||||
while (aBufLen > 0) {
|
||||
char symbolBuffer[sizeof(IMAGEHLP_SYMBOL) + 512];
|
||||
PIMAGEHLP_SYMBOL pSymbol = (PIMAGEHLP_SYMBOL) symbolBuffer;
|
||||
pSymbol->SizeOfStruct = sizeof(symbolBuffer);
|
||||
pSymbol->MaxNameLength = 512;
|
||||
|
||||
DWORD oldAddress = frame.AddrPC.Offset;
|
||||
BOOL b = ::StackWalk(IMAGE_FILE_MACHINE_I386, myProcess, myThread,
|
||||
&frame, &context, NULL,
|
||||
SymFunctionTableAccess,
|
||||
SymGetModuleBase,
|
||||
NULL);
|
||||
if (!b || (0 == frame.AddrPC.Offset)) {
|
||||
if (syms <= 1) {
|
||||
skip = 7;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (--skip >= 0) {
|
||||
continue;
|
||||
}
|
||||
DWORD disp;
|
||||
if (SymGetSymFromAddr(myProcess, frame.AddrPC.Offset, &disp, pSymbol)) {
|
||||
int nameLen = strlen(pSymbol->Name);
|
||||
if (nameLen + 2 > aBufLen) {
|
||||
break;
|
||||
}
|
||||
memcpy(cp, pSymbol->Name, nameLen);
|
||||
cp += nameLen;
|
||||
*cp++ = ' ';
|
||||
aBufLen -= nameLen + 1;
|
||||
syms++;
|
||||
}
|
||||
else {
|
||||
if (11 > aBufLen) {
|
||||
break;
|
||||
}
|
||||
char tmp[30];
|
||||
PR_snprintf(tmp, sizeof(tmp), "0x%08x ", frame.AddrPC.Offset);
|
||||
memcpy(cp, tmp, 11);
|
||||
cp += 11;
|
||||
aBufLen -= 11;
|
||||
syms++;
|
||||
}
|
||||
}
|
||||
*cp = 0;
|
||||
}
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#else /* MOZ_TRACE_XPCOM_REFCNT */
|
||||
void
|
||||
nsTraceRefcnt::WalkTheStack(char* aBuffer, int aBufLen)
|
||||
{
|
||||
aBuffer[0] = '\0';
|
||||
}
|
||||
#endif /* MOZ_TRACE_XPCOM_REFCNT */
|
||||
|
||||
NS_COM void
|
||||
nsTraceRefcnt::LoadLibrarySymbols(const char* aLibraryName,
|
||||
void* aLibrayHandle)
|
||||
{
|
||||
#ifdef MOZ_TRACE_XPCOM_REFCNT
|
||||
#if defined(_WIN32)
|
||||
InitTraceLog();
|
||||
if (PR_LOG_TEST(gTraceRefcntLog,PR_LOG_DEBUG)) {
|
||||
HANDLE myProcess = ::GetCurrentProcess();
|
||||
|
||||
if (!SymInitialize(myProcess, ".;..\\lib", TRUE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
BOOL b = ::SymLoadModule(myProcess,
|
||||
NULL,
|
||||
(char*)aLibraryName,
|
||||
(char*)aLibraryName,
|
||||
0,
|
||||
0);
|
||||
// DWORD lastError = 0;
|
||||
// if (!b) lastError = ::GetLastError();
|
||||
// printf("loading symbols for library %s => %s [%d]\n", aLibraryName,
|
||||
// b ? "true" : "false", lastError);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_COM unsigned long
|
||||
nsTraceRefcnt::AddRef(void* aPtr,
|
||||
unsigned long aNewRefcnt,
|
||||
const char* aFile,
|
||||
PRIntn aLine)
|
||||
{
|
||||
#ifdef MOZ_TRACE_XPCOM_REFCNT
|
||||
InitTraceLog();
|
||||
|
||||
LOCK_TRACELOG();
|
||||
if (PR_LOG_TEST(gTraceRefcntLog,PR_LOG_DEBUG)) {
|
||||
char sb[1000];
|
||||
WalkTheStack(sb, sizeof(sb));
|
||||
PR_LOG(gTraceRefcntLog, PR_LOG_DEBUG,
|
||||
("AddRef: %p: %d=>%d [%s] in %s (line %d)",
|
||||
aPtr, aNewRefcnt-1, aNewRefcnt, sb, aFile, aLine));
|
||||
}
|
||||
UNLOCK_TRACELOG();
|
||||
#endif
|
||||
return aNewRefcnt;
|
||||
|
||||
}
|
||||
|
||||
NS_COM unsigned long
|
||||
nsTraceRefcnt::Release(void* aPtr,
|
||||
unsigned long aNewRefcnt,
|
||||
const char* aFile,
|
||||
PRIntn aLine)
|
||||
{
|
||||
#ifdef MOZ_TRACE_XPCOM_REFCNT
|
||||
InitTraceLog();
|
||||
|
||||
LOCK_TRACELOG();
|
||||
if (PR_LOG_TEST(gTraceRefcntLog,PR_LOG_DEBUG)) {
|
||||
char sb[1000];
|
||||
WalkTheStack(sb, sizeof(sb));
|
||||
PR_LOG(gTraceRefcntLog, PR_LOG_DEBUG,
|
||||
("Release: %p: %d=>%d [%s] in %s (line %d)",
|
||||
aPtr, aNewRefcnt+1, aNewRefcnt, sb, aFile, aLine));
|
||||
}
|
||||
UNLOCK_TRACELOG();
|
||||
#endif
|
||||
return aNewRefcnt;
|
||||
}
|
||||
|
||||
NS_COM void
|
||||
nsTraceRefcnt::Create(void* aPtr,
|
||||
const char* aType,
|
||||
const char* aFile,
|
||||
PRIntn aLine)
|
||||
{
|
||||
#ifdef MOZ_TRACE_XPCOM_REFCNT
|
||||
InitTraceLog();
|
||||
|
||||
LOCK_TRACELOG();
|
||||
if (PR_LOG_TEST(gTraceRefcntLog,PR_LOG_DEBUG)) {
|
||||
char sb[1000];
|
||||
WalkTheStack(sb, sizeof(sb));
|
||||
PR_LOG(gTraceRefcntLog, PR_LOG_DEBUG,
|
||||
("Create: %p[%s]: [%s] in %s (line %d)",
|
||||
aPtr, aType, sb, aFile, aLine));
|
||||
}
|
||||
UNLOCK_TRACELOG();
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_COM void
|
||||
nsTraceRefcnt::Destroy(void* aPtr,
|
||||
const char* aFile,
|
||||
PRIntn aLine)
|
||||
{
|
||||
#ifdef MOZ_TRACE_XPCOM_REFCNT
|
||||
InitTraceLog();
|
||||
|
||||
LOCK_TRACELOG();
|
||||
if (PR_LOG_TEST(gTraceRefcntLog,PR_LOG_DEBUG)) {
|
||||
char sb[1000];
|
||||
WalkTheStack(sb, sizeof(sb));
|
||||
PR_LOG(gTraceRefcntLog, PR_LOG_DEBUG,
|
||||
("Destroy: %p: [%s] in %s (line %d)",
|
||||
aPtr, sb, aFile, aLine));
|
||||
}
|
||||
UNLOCK_TRACELOG();
|
||||
#endif
|
||||
}
|
||||
61
mozilla/xpcom/base/nsTraceRefcntImpl.h
Normal file
61
mozilla/xpcom/base/nsTraceRefcntImpl.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/* -*- 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 "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.
|
||||
*/
|
||||
#ifndef nsTraceRefcnt_h___
|
||||
#define nsTraceRefcnt_h___
|
||||
|
||||
#include "nsCom.h"
|
||||
|
||||
/**
|
||||
* This class is used to support tracing (and logging using nspr) of
|
||||
* addref and release calls. Note that only calls that use the
|
||||
* NS_ADDREF and related macros in nsISupports can be traced.
|
||||
*
|
||||
* The name of the nspr log module is "xpcomrefcnt" (case matters).
|
||||
*
|
||||
* This code only performs tracing built with debugging AND when
|
||||
* built with -DMOZ_TRACE_XPCOM_REFCNT (because it's expensive!).
|
||||
*/
|
||||
class nsTraceRefcnt {
|
||||
public:
|
||||
static NS_COM unsigned long AddRef(void* aPtr,
|
||||
unsigned long aNewRefcnt,
|
||||
const char* aFile,
|
||||
int aLine);
|
||||
|
||||
static NS_COM unsigned long Release(void* aPtr,
|
||||
unsigned long aNewRefcnt,
|
||||
const char* aFile,
|
||||
int aLine);
|
||||
|
||||
static NS_COM void Create(void* aPtr,
|
||||
const char* aType,
|
||||
const char* aFile,
|
||||
int aLine);
|
||||
|
||||
static NS_COM void Destroy(void* aPtr,
|
||||
const char* aFile,
|
||||
int aLine);
|
||||
|
||||
static NS_COM void LoadLibrarySymbols(const char* aLibraryName,
|
||||
void* aLibrayHandle);
|
||||
|
||||
static NS_COM void WalkTheStack(char* aBuffer, int aBufLen);
|
||||
};
|
||||
|
||||
#endif /* nsTraceRefcnt_h___ */
|
||||
168
mozilla/xpcom/components/mozIClassRegistry.h
Normal file
168
mozilla/xpcom/components/mozIClassRegistry.h
Normal file
@@ -0,0 +1,168 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
#ifndef __mozIClassRegistry_h
|
||||
#define __mozIClassRegistry_h
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
|
||||
/*---------------------------- mozIClassRegistry -------------------------------
|
||||
| This interface provides access to a mapping from mnemonic interface names |
|
||||
| to shared libraries where implementations of those interfaces can be located.|
|
||||
| |
|
||||
| This interface is designed to provide two things: |
|
||||
| 1. A means of less static binding between clients and the code that |
|
||||
| implements the XPCOM interfaces those clients use. This accomplished |
|
||||
| by the mapping from interface names to nsCID (and the shared libraries |
|
||||
| that implement those classes). |
|
||||
| 2. A means of dynamically changing the mapping from interface name to |
|
||||
| implementation. The canonical example of this is to switch to a |
|
||||
| "native" widget set versus an "XP" (implemented using gfx) set. |
|
||||
| |
|
||||
| The first goal is achieved by storing (in a "Netscape Registry" file, see |
|
||||
| nsReg.h) information that maps interface/class "names" to information about |
|
||||
| where to load implementations of those interfaces. That information |
|
||||
| includes the interface ID, class ID (of the implementation class), and the |
|
||||
| name of the shared library that contains the implementation. |
|
||||
| |
|
||||
| The class registry object will register those classes with the "repository" |
|
||||
| (see nsComponentManager.h) the first time a request is made to create an |
|
||||
| instance. Subsequent requests will simply be forwarded to the repository |
|
||||
| after the appropriate interface and class IDs are determined. |
|
||||
| |
|
||||
| The second goal is accomplished by permitting the mnemonic interface |
|
||||
| "names" to be "overloaded", that is, mapped to distinct implementations |
|
||||
| by separate class registry objects. Further, class registries can be |
|
||||
| cascaded: they can be chained together so that when a name is not |
|
||||
| recognized by one registry, it can pass the request to the next registry in |
|
||||
| the chain. Users can control resolution by making the request of a |
|
||||
| registry further up/down the chain. |
|
||||
| |
|
||||
| For example, consider the case of "native" vs. "gfx" widgets. This might |
|
||||
| be structured by a class registry arrangment like this: |
|
||||
| |
|
||||
| nativeWidgetRegistry baseWidgetRegistry |
|
||||
| +----------+ +----------+ |
|
||||
| | ----+---------------->| | |
|
||||
| +----------+ +----------+ |
|
||||
| |toolbar| -+-----+ |toolbar| -+-----+ |
|
||||
| +----------+ | +----------+ | |
|
||||
| |button | -+-----+ |button | -+-----+ |
|
||||
| +----------+ | +----------+ | |
|
||||
| V V |
|
||||
| +-----------------+ +-----------------+ |
|
||||
| | native.dll | | base.dll | |
|
||||
| +-----------------+ +-----------------+ |
|
||||
| |
|
||||
| If a specialized implementation of widgets is present (e.g., native.dll) |
|
||||
| then a corresponding class registry object is created and added to the |
|
||||
| head of the registry chain. Object creation requests (normal ones) are |
|
||||
| resolved to the native implementation. If such a library is not present, |
|
||||
| then the resolution is to the base implementation. If objects of the |
|
||||
| base implementation are required, then creation requests can be directed |
|
||||
| directly to the baseWidgetRegistry object, rather than the head of the |
|
||||
| registry chain. |
|
||||
| |
|
||||
| It is intended that there be a single instance of this interface, accessed |
|
||||
| via the Service Manager (see nsServiceManager.h). |
|
||||
------------------------------------------------------------------------------*/
|
||||
struct mozIClassRegistry : public ISupports {
|
||||
|
||||
/*------------------------------ CreateInstance ----------------------------
|
||||
| Create an instance of the requested class/interface. The interface |
|
||||
| ID is required to specify how the result will be treated. The class |
|
||||
| named by aName must support this interface. The result is placed in |
|
||||
| ncomment aResult (NULL if the request fails). "start" specifies the |
|
||||
| registry at which the search for an implementation of the named |
|
||||
| interface should start. It defaults to 0 (indicating to start at the |
|
||||
| head of the registry chain). |
|
||||
--------------------------------------------------------------------------*/
|
||||
NS_IMETHOD CreateInstance( const char *anInterfaceName,
|
||||
const nsIID &aIID,
|
||||
void* *aResult,
|
||||
const char *start = 0 ) = 0;
|
||||
|
||||
/*--------------------------- CreateEnumerator -----------------------------
|
||||
| Creates an nsIEnumerator interface object that can be used to examine |
|
||||
| the contents of the registry. "pattern" specifies either "*" or the |
|
||||
| name of a specific interface that you want to query. "result" will |
|
||||
| be set to point to a new object (which will be freed on the last call |
|
||||
| to its Release() member). See nsIEnumerator.h for details on how to |
|
||||
| use the returned interface pointer. |
|
||||
--------------------------------------------------------------------------*/
|
||||
NS_IMETHOD CreateEnumerator( const char *pattern,
|
||||
nsIEnumerator* *result ) = 0;
|
||||
}; // mozIClassRegistry
|
||||
|
||||
|
||||
/*-------------------------- mozIClassRegistryEntry ----------------------------
|
||||
| Objects of this class represent the individual elements that comprise a |
|
||||
| mozIClassRegistry interface. You obtain such objects by applying the |
|
||||
| CreateEnumerator member function to the class registry and then applying |
|
||||
| the CurrentItem member function to the resulting nsIEnumerator interface. |
|
||||
| |
|
||||
| Each entry can be queried for the following information: |
|
||||
| o sub-registry name |
|
||||
| o interface name |
|
||||
| o Class ID |
|
||||
| o IIDs implemented |
|
||||
| |
|
||||
| The information obtained from the entry (specifically, the const char* |
|
||||
| strings) remains valid for the life of the entry (i.e., until you |
|
||||
| Release() it). |
|
||||
| |
|
||||
| Here is an example of code that uses this interface to dump the contents |
|
||||
| of a mozIClassRegistry: |
|
||||
| |
|
||||
| mozIClassRegistry *reg = nsServiceManager::GetService( kIDRegistry ); |
|
||||
| nsIEnumerator *enum; |
|
||||
| reg->CreateEnumerator( "*", &enum ); |
|
||||
| for ( enum->First(); !enum->IsDone(); enum->Next(); ) { |
|
||||
| mozIClassRegistryEntry *entry; |
|
||||
| enum->CurrentItem( &entry ); |
|
||||
| const char *subreg; |
|
||||
| const char *name; |
|
||||
| nsCID cid; |
|
||||
| int numIIDs; |
|
||||
| entry->GetSubRegistryName( &subreg ); |
|
||||
| entry->GetInterfaceName( &name ); |
|
||||
| entry->GetClassID( &cid ); |
|
||||
| entry->GetNumIIDs( &numIIDs ); |
|
||||
| cout << subreg << "/" << name << " = " << cid.ToString() << endl; |
|
||||
| for ( int i = 0; i < numIIDs; i++ ) { |
|
||||
| nsIID iid; |
|
||||
| entry->GetInterfaceID( i, &iid ); |
|
||||
| cout << "/tIID[" << i << "] = " << iid.ToString() << endl; |
|
||||
| } |
|
||||
| entry->Release(); |
|
||||
| } |
|
||||
| enum->Release(); |
|
||||
------------------------------------------------------------------------------*/
|
||||
struct mozIClassRegistryEntry : public nsISupports {
|
||||
NS_IMETHOD GetSubRegistryName( const char **result ) = 0;
|
||||
NS_IMETHOD GetInterfaceName( const char **result ) = 0;
|
||||
NS_IMETHOD GetClassID( nsCID *result ) = 0;
|
||||
NS_IMETHOD GetNumIIDs( int *result ) = 0;
|
||||
NS_IMETHOD GetInterfaceID( int n, nsIID *result ) = 0;
|
||||
}; // mozIClassRegistryEntry
|
||||
|
||||
// {5D41A440-8E37-11d2-8059-00600811A9C3}
|
||||
#define MOZ_ICLASSREGISTRY_IID { 0x5d41a440, 0x8e37, 0x11d2, { 0x80, 0x59, 0x0, 0x60, 0x8, 0x11, 0xa9, 0xc3 } }
|
||||
// {D1B54831-AC07-11d2-805E-00600811A9C3}
|
||||
#define MOZ_ICLASSREGISTRYENTRY_IID { 0xd1b54831, 0xac07, 0x11d2, { 0x80, 0x5e, 0x0, 0x60, 0x8, 0x11, 0xa9, 0xc3 } }
|
||||
|
||||
#endif
|
||||
326
mozilla/xpcom/components/mozIRegistry.h
Normal file
326
mozilla/xpcom/components/mozIRegistry.h
Normal file
@@ -0,0 +1,326 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
#ifndef __mozIRegistry_h
|
||||
#define __mozIRegistry_h
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsIEnumerator;
|
||||
|
||||
/*------------------------------- mozIRegistry ---------------------------------
|
||||
| This interface provides access to a tree of arbitrary values. |
|
||||
| |
|
||||
| Each node of the tree contains either a value or a subtree or both. |
|
||||
| |
|
||||
| The value at any of these leaf nodes can be any of these "primitive" types: |
|
||||
| o string (null terminated UTF string) |
|
||||
| o array of 32-bit integers |
|
||||
| o arbitrary array of bytes |
|
||||
| o file identifier |
|
||||
| Of course, since you can store an arbitrary array of bytes, you can put |
|
||||
| any data you like into a registry (although you have the burden of |
|
||||
| encoding/decoding your data in that case). |
|
||||
| |
|
||||
| Each branch of the tree is labelled with a string "key." The entire path |
|
||||
| from a given point of the tree to another point further down can be |
|
||||
| presented as a single string composed of each branch's label, concatenated |
|
||||
| to the next, with an intervening forward slash ('/'). The term "key" |
|
||||
| refers to both specific tree branch labels and to such concatenated paths. |
|
||||
| |
|
||||
| The branches from a given node must have unique labels. Distinct nodes can |
|
||||
| have branches with the same label. |
|
||||
| |
|
||||
| For example, here's a small registry tree: |
|
||||
| | |
|
||||
| /\ |
|
||||
| / \ |
|
||||
| / \ |
|
||||
| / \ |
|
||||
| "Classes" "Users" |
|
||||
| / \ |
|
||||
| / \ |
|
||||
| / ["joe"] |
|
||||
| / / \ |
|
||||
| | / \ |
|
||||
| /\ / \ |
|
||||
| / \ "joe" "bob" |
|
||||
| / \ / \ |
|
||||
| / \ |
|
||||
| "{xxxx-xx-1}" "{xxxx-xx-2}" ["c:/joe"] ["d:/Robert"] |
|
||||
| | | |
|
||||
| /\ /\ |
|
||||
| / \ / \ |
|
||||
| / \ / \ |
|
||||
| "Library" "Version" "Library" "Version" |
|
||||
| / \ / \ |
|
||||
| ["foo.dll"] 2 ["bar.dll"] 1 |
|
||||
| |
|
||||
| In this example, there are 2 keys under the root: "Classes" and "Users". |
|
||||
| The first denotes a subtree only (which has two subtrees, ...). The second |
|
||||
| denotes both a value ["joe"] and two subtrees labelled "joe" and "bob". |
|
||||
| The value at the node "/Users" is ["joe"], at "/Users/bob" is ["d:/Robert"]. |
|
||||
| The value at "/Classes/{xxxx-xx-1}/Version" is 2. |
|
||||
| |
|
||||
| The registry interface provides functions that let you navigate the tree |
|
||||
| and manipulate it's contents. |
|
||||
| |
|
||||
| Please note that the registry itself does not impose any structure or |
|
||||
| meaning on the contents of the tree. For example, the registry doesn't |
|
||||
| control whether the value at the key "/Users" is the label for the subtree |
|
||||
| with information about the last active user. That meaning is applied by |
|
||||
| the code that stores these values and uses them for that purpose. |
|
||||
| |
|
||||
| [Any resemblence between this example and actual contents of any actual |
|
||||
| registry is purely coincidental.] |
|
||||
------------------------------------------------------------------------------*/
|
||||
struct mozIRegistry : public nsISupports {
|
||||
/*------------------------------ Constants ---------------------------------
|
||||
| The following enumerated types and values are used by the registry |
|
||||
| interface. |
|
||||
--------------------------------------------------------------------------*/
|
||||
typedef enum {
|
||||
String = 1,
|
||||
Int32,
|
||||
Bytes,
|
||||
File
|
||||
} DataType;
|
||||
|
||||
/*-------------------------------- Types -----------------------------------
|
||||
| The following data types are used by this interface. All are basically |
|
||||
| opaque types. You obtain objects of these types via certain member |
|
||||
| function calls and re-use them later (without having to know what they |
|
||||
| contain). |
|
||||
| |
|
||||
| Key - Placeholder to represent a particular node in a registry |
|
||||
| tree. There are 3 enumerated values that correspond to |
|
||||
| specific nodes: |
|
||||
| Common - Where most stuff goes. |
|
||||
| Users - Special subtree to hold info about |
|
||||
| "users"; if you don't know what goes |
|
||||
| here, don't mess with it. |
|
||||
| CurrentUser - Subtree under Users corresponding to |
|
||||
| whatever user is designed the "current" |
|
||||
| one; see note above. |
|
||||
| You can specify any of these enumerated values as "keys" |
|
||||
| on any member function that takes a mozRegistry::Key. |
|
||||
| ValueInfo - Structure describing a registry value. |
|
||||
--------------------------------------------------------------------------*/
|
||||
typedef uint32 Key;
|
||||
|
||||
enum { Users = 1, Common = 2, CurrentUser = 3 };
|
||||
|
||||
struct ValueInfo {
|
||||
DataType type;
|
||||
uint32 length;
|
||||
};
|
||||
|
||||
/*--------------------------- Opening/Closing ------------------------------
|
||||
| These functions open the specified registry file (Open() with a non-null |
|
||||
| argument) or the default "standard" registry file (Open() with a null |
|
||||
| argument or OpenDefault()). |
|
||||
| |
|
||||
| Once opened, you can access the registry contents via the read/write |
|
||||
| or query functions. |
|
||||
| |
|
||||
| The registry file will be closed automatically when the registry object |
|
||||
| is destroyed. You can close the file prior to that by using the |
|
||||
| Close() function. |
|
||||
--------------------------------------------------------------------------*/
|
||||
NS_IMETHOD Open( const char *regFile = 0 ) = 0;
|
||||
NS_IMETHOD OpenDefault() = 0;
|
||||
NS_IMETHOD Close() = 0;
|
||||
|
||||
/*----------------------- Reading/Writing Values ---------------------------
|
||||
| These functions read/write the registry values at a given node. |
|
||||
| |
|
||||
| All functions require you to specify where in the registry key to |
|
||||
| get/set the value. The location is specified using two components: |
|
||||
| o A "base key" indicating where to start from; this is a value of type |
|
||||
| mozIRegistry::Key. You use either one of the special "root" key |
|
||||
| values or a subkey obtained via some other member function call. |
|
||||
| o A "relative path," expressed as a sequence of subtree names |
|
||||
| separated by forward slashes. This path describes how to get from |
|
||||
| the base key to the node at which you want to store the data. This |
|
||||
| component can be a null pointer which means the value goes directly |
|
||||
| at the node denoted by the base key. |
|
||||
| |
|
||||
| When you request a value of a given type, the data stored at the |
|
||||
| specified node must be of the type requested. If not, an error results. |
|
||||
| |
|
||||
| GetString - Obtains a newly allocated copy of a string type value. The |
|
||||
| caller is obligated to free the returned string using |
|
||||
| PR_Free. |
|
||||
| SetString - Stores the argument string at the specified node. |
|
||||
| GetInt - Obtains an int32 value at the specified node. The result |
|
||||
| is returned into an int32 location you specify. |
|
||||
| SetInt - Stores a given int32 value at a node. |
|
||||
| GetBytes - Obtains a byte array value; this returns both an allocated |
|
||||
| array of bytes and a length (necessary because there may be |
|
||||
| embedded null bytes in the array). You must free the |
|
||||
| resulting array using PR_Free. |
|
||||
| SetBytes - Stores a given array of bytes; you specify the bytes via a |
|
||||
| pointer and a length. |
|
||||
| GetIntArray - Obtains the array of int32 values stored at a given node. |
|
||||
| The result is composed of two values: a pointer to an |
|
||||
| array of integer values (which must be freed using |
|
||||
| PR_Free) and the number of elements in that array. |
|
||||
| SetIntArray - Stores a set of int32 values at a given node. You must |
|
||||
| provide a pointer to the array and the number of entries. |
|
||||
--------------------------------------------------------------------------*/
|
||||
NS_IMETHOD GetString( Key baseKey, const char *path, char **result ) = 0;
|
||||
NS_IMETHOD SetString( Key baseKey, const char *path, const char *value ) = 0;
|
||||
NS_IMETHOD GetInt( Key baseKey, const char *path, int32 *result ) = 0;
|
||||
NS_IMETHOD SetInt( Key baseKey, const char *path, int32 value ) = 0;
|
||||
NS_IMETHOD GetBytes( Key baseKey, const char *path, void **result, uint32 *len ) = 0;
|
||||
NS_IMETHOD SetBytes( Key baseKey, const char *path, void *value, uint32 len ) = 0;
|
||||
NS_IMETHOD GetIntArray( Key baseKey, const char *path, int32 **result, uint32 *len ) = 0;
|
||||
NS_IMETHOD SetIntArray( Key baseKey, const char *path, const int32 *value, uint32 len ) = 0;
|
||||
|
||||
/*------------------------------ Navigation --------------------------------
|
||||
| These functions let you navigate through the registry tree, querying |
|
||||
| its contents. |
|
||||
| |
|
||||
| As above, all these functions requires a starting tree location ("base |
|
||||
| key") specified as a mozIRegistry::Key. Some also require a path |
|
||||
| name to locate the registry node location relative to this base key. |
|
||||
| |
|
||||
| AddSubtree - Adds a new registry subtree at the specified |
|
||||
| location. Returns the resulting key in |
|
||||
| the location specified by the third argument |
|
||||
| (unless that pointer is 0). |
|
||||
| RemoveNode - Removes the specified registry subtree or |
|
||||
| value at the specified location. |
|
||||
| GetSubtree - Returns a mozIRegistry::Key that can be used |
|
||||
| to refer to the specified registry location. |
|
||||
| EnumerateSubtrees - Returns a nsIEnumerator object that you can |
|
||||
| use to enumerate all the subtrees descending |
|
||||
| from a specified location. You must free the |
|
||||
| enumerator via Release() when you're done with |
|
||||
| it. |
|
||||
| EnumerateAllSubtrees - Like EnumerateSubtrees, but will recursively |
|
||||
| enumerate lower-level subtrees, too. |
|
||||
| GetValueInfo - Returns a uint32 value that designates the type |
|
||||
| of data stored at this location in the registry; |
|
||||
| the possible values are defined by the enumerated |
|
||||
| type mozIRegistry::DataType. |
|
||||
| GetValueLength - Returns a uint32 value that indicates the length |
|
||||
| of this registry value; the length is the number |
|
||||
| of characters (for Strings), the number of bytes |
|
||||
| (for Bytes), or the number of int32 values (for |
|
||||
| Int32). |
|
||||
| EnumerateValues - Returns a nsIEnumerator that you can use to |
|
||||
| enumerate all the value nodes descending from |
|
||||
| a specified location. |
|
||||
--------------------------------------------------------------------------*/
|
||||
NS_IMETHOD AddSubtree( Key baseKey, const char *path, Key *result ) = 0;
|
||||
NS_IMETHOD RemoveSubtree( Key baseKey, const char *path ) = 0;
|
||||
NS_IMETHOD GetSubtree( Key baseKey, const char *path, Key *result ) = 0;
|
||||
|
||||
NS_IMETHOD EnumerateSubtrees( Key baseKey, nsIEnumerator **result ) = 0;
|
||||
NS_IMETHOD EnumerateAllSubtrees( Key baseKey, nsIEnumerator **result ) = 0;
|
||||
|
||||
NS_IMETHOD GetValueType( Key baseKey, const char *path, uint32 *result ) = 0;
|
||||
NS_IMETHOD GetValueLength( Key baseKey, const char *path, uint32 *result ) = 0;
|
||||
|
||||
NS_IMETHOD EnumerateValues( Key baseKey, nsIEnumerator **result ) = 0;
|
||||
|
||||
/*------------------------------ User Name ---------------------------------
|
||||
| These functions manipulate the current "user name." This value controls |
|
||||
| the behavior of certain registry functions (namely, ?). |
|
||||
| |
|
||||
| GetCurrentUserName allocates a copy of the current user name (which the |
|
||||
| caller should free using PR_Free). |
|
||||
--------------------------------------------------------------------------*/
|
||||
NS_IMETHOD GetCurrentUserName( char **result ) = 0;
|
||||
NS_IMETHOD SetCurrentUserName( const char *name ) = 0;
|
||||
|
||||
/*------------------------------ Utilities ---------------------------------
|
||||
| Various utility functions: |
|
||||
| |
|
||||
| Pack() is used to compress the contents of an open registry file. |
|
||||
--------------------------------------------------------------------------*/
|
||||
NS_IMETHOD Pack() = 0;
|
||||
|
||||
}; // mozIRegistry
|
||||
|
||||
/*----------------------------- mozIRegistryNode -------------------------------
|
||||
| This interface is implemented by all the objects obtained from the |
|
||||
| nsIEnumerators that mozIRegistry provides when you call either of the |
|
||||
| subtree enumeration functions EnumerateSubtrees or EnumerateAllSubtrees. |
|
||||
| |
|
||||
| You can call this function to get the name of this subtree. This is the |
|
||||
| relative path from the base key from which you got this interface. |
|
||||
| |
|
||||
| GetName - Returns the path name of this node; this is the relative path |
|
||||
| from the base key from which this subtree was obtained. The |
|
||||
| function allocates a copy of the name; the caller must free it |
|
||||
| using PR_Free. |
|
||||
------------------------------------------------------------------------------*/
|
||||
struct mozIRegistryNode : public nsISupports {
|
||||
NS_IMETHOD GetName( char **result ) = 0;
|
||||
}; // mozIRegistryNode
|
||||
|
||||
/*----------------------------- mozIRegistryValue ------------------------------
|
||||
| This interface is implemented by the objects obtained from the |
|
||||
| nsIEnumerators that mozIRegistry provides when you call the |
|
||||
| EnumerateValues function. An object supporting this interface is |
|
||||
| returned when you call the CurrentItem() function on that enumerator. |
|
||||
| |
|
||||
| You use the member functions of this interface to obtain information |
|
||||
| about each registry value. |
|
||||
| |
|
||||
| GetName - Returns the path name of this node; this is the relative |
|
||||
| path\ from the base key from which this value was obtained. |
|
||||
| The function allocates a copy of the name; the caller must |
|
||||
| subsequently free it via PR_Free. |
|
||||
| GetValueType - Returns (into a location provided by the caller) the type |
|
||||
| of the value; the types are defined by the enumerated |
|
||||
| type mozIRegistry::DataType. |
|
||||
| GetValueLength - Returns a uint32 value that indicates the length |
|
||||
| of this registry value; the length is the number |
|
||||
| of characters (for Strings), the number of bytes |
|
||||
| (for Bytes), or the number of int32 values (for |
|
||||
| Int32). |
|
||||
------------------------------------------------------------------------------*/
|
||||
struct mozIRegistryValue : public nsISupports {
|
||||
NS_IMETHOD GetName( char **result ) = 0;
|
||||
NS_IMETHOD GetValueType( uint32 *result ) = 0;
|
||||
NS_IMETHOD GetValueLength( uint32 *result ) = 0;
|
||||
}; // mozIRegistryEntry
|
||||
|
||||
|
||||
/*------------------------------- Error Codes ----------------------------------
|
||||
------------------------------------------------------------------------------*/
|
||||
#define NS_ERROR_REG_BADTYPE NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 1 )
|
||||
#define NS_ERROR_REG_NO_MORE NS_ERROR_GENERATE_SUCCESS( NS_ERROR_MODULE_REG, 2 )
|
||||
#define NS_ERROR_REG_NOT_FOUND NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 3 )
|
||||
#define NS_ERROR_REG_NOFILE NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 4 )
|
||||
#define NS_ERROR_REG_BUFFER_TOO_SMALL NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 5 )
|
||||
#define NS_ERROR_REG_NAME_TOO_LONG NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 6 )
|
||||
#define NS_ERROR_REG_NO_PATH NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 7 )
|
||||
#define NS_ERROR_REG_READ_ONLY NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 8 )
|
||||
#define NS_ERROR_REG_BAD_UTF8 NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 9 )
|
||||
|
||||
// {5D41A440-8E37-11d2-8059-00600811A9C3}
|
||||
#define MOZ_IREGISTRY_IID { 0x5d41a440, 0x8e37, 0x11d2, { 0x80, 0x59, 0x0, 0x60, 0x8, 0x11, 0xa9, 0xc3 } }
|
||||
// {D1B54831-AC07-11d2-805E-00600811A9C3}
|
||||
#define MOZ_IREGISTRYNODE_IID { 0xd1b54831, 0xac07, 0x11d2, { 0x80, 0x5e, 0x0, 0x60, 0x8, 0x11, 0xa9, 0xc3 } }
|
||||
// {5316C380-B2F8-11d2-A374-0080C6F80E4B}
|
||||
#define MOZ_IREGISTRYVALUE_IID { 0x5316c380, 0xb2f8, 0x11d2, { 0xa3, 0x74, 0x0, 0x80, 0xc6, 0xf8, 0xe, 0x4b } }
|
||||
|
||||
#endif
|
||||
1191
mozilla/xpcom/components/mozRegistry.cpp
Normal file
1191
mozilla/xpcom/components/mozRegistry.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1983
mozilla/xpcom/components/nsComponentManager.cpp
Normal file
1983
mozilla/xpcom/components/nsComponentManager.cpp
Normal file
File diff suppressed because it is too large
Load Diff
248
mozilla/xpcom/components/nsComponentManager.h
Normal file
248
mozilla/xpcom/components/nsComponentManager.h
Normal file
@@ -0,0 +1,248 @@
|
||||
/* -*- Mode: C++; tab-width: 8; 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 nsComponentManager_h__
|
||||
#define nsComponentManager_h__
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIRegistry.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "prtime.h"
|
||||
#include "prmon.h"
|
||||
|
||||
class nsFactoryEntry;
|
||||
class nsDll;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/*
|
||||
*** Quick Registration NOT FOR PUBLIC CONSUMPTION ***
|
||||
*
|
||||
* Quick Registration
|
||||
*
|
||||
* For quick registration, dlls can define
|
||||
* NSQuickRegisterClassData g_NSQuickRegisterData[];
|
||||
* and export the symbol "g_NSQuickRegisterData"
|
||||
*
|
||||
* Quick registration is tried only if the symbol "NSRegisterSelf"
|
||||
* is not found. If it is found but fails registration, quick registration
|
||||
* will not kick in.
|
||||
*
|
||||
* The array is terminated by having a NULL last element. Specifically, the
|
||||
* array will be assumed to end when
|
||||
* (g_NSQuickRegisterData[i].classIdStr == NULL)
|
||||
*
|
||||
*/
|
||||
#define NS_QUICKREGISTER_DATA_SYMBOL "g_NSQuickRegisterData"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsComponentManagerImpl : public nsIComponentManager {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIComponentManager methods:
|
||||
NS_IMETHOD FindFactory(const nsCID &aClass,
|
||||
nsIFactory **aFactory);
|
||||
|
||||
// Finds a class ID for a specific Program ID
|
||||
NS_IMETHOD ProgIDToCLSID(const char *aProgID,
|
||||
nsCID *aClass);
|
||||
|
||||
// Finds a Program ID for a specific class ID
|
||||
// caller frees the result with delete[]
|
||||
NS_IMETHOD CLSIDToProgID(nsCID *aClass,
|
||||
char* *aClassName,
|
||||
char* *aProgID);
|
||||
|
||||
// Creates a class instance for a specific class ID
|
||||
NS_IMETHOD CreateInstance(const nsCID &aClass,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
// Convenience routine, creates a class instance for a specific ProgID
|
||||
NS_IMETHOD CreateInstance(const char *aProgID,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
// Creates a class instance for a specific class ID
|
||||
/*
|
||||
NS_IMETHOD CreateInstance2(const nsCID &aClass,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void *aSignature,
|
||||
void **aResult);
|
||||
*/
|
||||
|
||||
// Manually registry a factory for a class
|
||||
NS_IMETHOD RegisterFactory(const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory *aFactory,
|
||||
PRBool aReplace);
|
||||
|
||||
// Manually register a dynamically loaded component.
|
||||
NS_IMETHOD RegisterComponent(const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
const char *aLibrary,
|
||||
PRBool aReplace,
|
||||
PRBool aPersist);
|
||||
|
||||
// Manually unregister a factory for a class
|
||||
NS_IMETHOD UnregisterFactory(const nsCID &aClass,
|
||||
nsIFactory *aFactory);
|
||||
|
||||
// Manually unregister a dynamically loaded factory for a class
|
||||
NS_IMETHOD UnregisterFactory(const nsCID &aClass,
|
||||
const char *aLibrary);
|
||||
|
||||
// Manually unregister a dynamically loaded component
|
||||
NS_IMETHOD UnregisterComponent(const nsCID &aClass,
|
||||
const char *aLibrary);
|
||||
|
||||
// Unload dynamically loaded factories that are not in use
|
||||
NS_IMETHOD FreeLibraries(void);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// DLL registration support
|
||||
/* Autoregistration will try only files with these extensions.
|
||||
* All extensions are case insensitive.
|
||||
* ".dll", // Windows
|
||||
* ".dso", // Unix
|
||||
* ".so", // Unix
|
||||
* ".sl", // Unix: HP
|
||||
* "_dll", // Mac
|
||||
* ".dlm", // new for all platforms
|
||||
*/
|
||||
NS_IMETHOD AutoRegister(RegistrationTime when, const char* pathlist);
|
||||
// Pathlist is a semicolon separated list of pathnames
|
||||
NS_IMETHOD AddToDefaultPathList(const char *pathlist);
|
||||
NS_IMETHOD SyncComponentsInPathList(const char *pathlist);
|
||||
NS_IMETHOD SyncComponentsInDir(const char *path);
|
||||
NS_IMETHOD SyncComponentsInFile(const char *fullname);
|
||||
|
||||
// nsComponentManagerImpl methods:
|
||||
nsComponentManagerImpl();
|
||||
virtual ~nsComponentManagerImpl();
|
||||
|
||||
static nsComponentManagerImpl* gComponentManager;
|
||||
nsresult Init(void);
|
||||
|
||||
protected:
|
||||
nsresult LoadFactory(nsFactoryEntry *aEntry, nsIFactory **aFactory);
|
||||
nsresult SelfRegisterDll(nsDll *dll);
|
||||
nsresult SelfUnregisterDll(nsDll *dll);
|
||||
|
||||
nsresult PlatformVersionCheck();
|
||||
nsresult PlatformCreateDll(const char *fullname, nsDll* *result);
|
||||
nsresult PlatformMarkNoComponents(nsDll *dll);
|
||||
struct QuickRegisterData {
|
||||
const char *CIDString; // {98765-8776-8958758759-958785}
|
||||
const char *className; // "Layout Engine"
|
||||
const char *progID; // "Gecko.LayoutEngine.1"
|
||||
};
|
||||
nsresult PlatformRegister(QuickRegisterData* regd, nsDll *dll);
|
||||
nsresult PlatformUnregister(QuickRegisterData* regd, const char *aLibrary);
|
||||
nsresult PlatformFind(const nsCID &aCID, nsFactoryEntry* *result);
|
||||
nsresult PlatformProgIDToCLSID(const char *aProgID, nsCID *aClass);
|
||||
nsresult PlatformCLSIDToProgID(nsCID *aClass, char* *aClassName, char* *aProgID);
|
||||
void PlatformGetFileInfo(nsIRegistry::Key Key,PRTime *lastModifiedTime,PRUint32 *fileSize);
|
||||
|
||||
protected:
|
||||
nsHashtable* mFactories;
|
||||
nsHashtable* mProgIDs;
|
||||
PRMonitor* mMon;
|
||||
nsHashtable* mDllStore;
|
||||
nsIRegistry* mRegistry;
|
||||
};
|
||||
|
||||
#define NS_MAX_FILENAME_LEN 1024
|
||||
|
||||
#define NS_ERROR_IS_DIR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_XPCOM, 24)
|
||||
|
||||
#ifdef XP_UNIX
|
||||
/* The default registry on the unix system is $HOME/.mozilla/registry per
|
||||
* vr_findGlobalRegName(). vr_findRegFile() will create the registry file
|
||||
* if it doesn't exist. But it wont create directories.
|
||||
*
|
||||
* Hence we need to create the directory if it doesn't exist already.
|
||||
*
|
||||
* Why create it here as opposed to the app ?
|
||||
* ------------------------------------------
|
||||
* The app cannot create the directory in main() as most of the registry
|
||||
* and initialization happens due to use of static variables.
|
||||
* And we dont want to be dependent on the order in which
|
||||
* these static stuff happen.
|
||||
*
|
||||
* Permission for the $HOME/.mozilla will be Read,Write,Execute
|
||||
* for user only. Nothing to group and others.
|
||||
*/
|
||||
#define NS_MOZILLA_DIR_NAME ".mozilla"
|
||||
#define NS_MOZILLA_DIR_PERMISSION 00700
|
||||
#endif /* XP_UNIX */
|
||||
|
||||
/**
|
||||
* When using the registry we put a version number in it.
|
||||
* If the version number that is in the registry doesn't match
|
||||
* the following, we ignore the registry. This lets news versions
|
||||
* of the software deal with old formats of registry and not
|
||||
*
|
||||
* alpha0.20 : First time we did versioning
|
||||
* alpha0.30 : Changing autoreg to begin registration from ./components on unix
|
||||
* alpha0.40 : repository -> component manager
|
||||
* alpha0.50 : using nsIRegistry
|
||||
*/
|
||||
#define NS_XPCOM_COMPONENT_MANAGER_VERSION_STRING "alpha0.51"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Class: nsFactoryEntry()
|
||||
*
|
||||
* There are two types of FactoryEntries.
|
||||
*
|
||||
* 1. {CID, dll} mapping.
|
||||
* Factory is a consequence of the dll. These can be either session
|
||||
* specific or persistent based on whether we write this
|
||||
* to the registry or not.
|
||||
*
|
||||
* 2. {CID, factory} mapping
|
||||
* These are strictly session specific and in memory only.
|
||||
*/
|
||||
|
||||
class nsFactoryEntry {
|
||||
public:
|
||||
nsFactoryEntry();
|
||||
nsFactoryEntry(const nsCID &aClass, nsIFactory *aFactory);
|
||||
~nsFactoryEntry();
|
||||
|
||||
nsresult Init(nsHashtable* dllHashtable, const nsCID &aClass, const char *aLibrary,
|
||||
PRTime lastModTime, PRUint32 fileSize);
|
||||
|
||||
nsCID cid;
|
||||
nsIFactory *factory;
|
||||
|
||||
// DO NOT DELETE THIS. Many nsFactoryEntry(s) could be sharing the same Dll.
|
||||
// This gets deleted from the dllStore going away.
|
||||
nsDll *dll;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // nsComponentManager_h__
|
||||
88
mozilla/xpcom/components/nsGenericFactory.cpp
Normal file
88
mozilla/xpcom/components/nsGenericFactory.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
/* -*- 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 "nsGenericFactory.h"
|
||||
|
||||
nsGenericFactory::nsGenericFactory(ConstructorProcPtr constructor)
|
||||
: mConstructor(constructor), mDestructor(NULL)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsGenericFactory::~nsGenericFactory()
|
||||
{
|
||||
if (mDestructor != NULL)
|
||||
(*mDestructor) ();
|
||||
}
|
||||
|
||||
NS_METHOD nsGenericFactory::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(nsIFactory::GetIID()) ||
|
||||
aIID.Equals(nsIGenericFactory::GetIID()) ||
|
||||
aIID.Equals(nsISupports::GetIID())) {
|
||||
*aInstancePtr = (void*) this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsGenericFactory)
|
||||
NS_IMPL_RELEASE(nsGenericFactory)
|
||||
|
||||
NS_IMETHODIMP nsGenericFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
return mConstructor(aOuter, aIID, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsGenericFactory::LockFactory(PRBool aLock)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsGenericFactory::SetConstructor(ConstructorProcPtr constructor)
|
||||
{
|
||||
mConstructor = constructor;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsGenericFactory::SetDestructor(DestructorProcPtr destructor)
|
||||
{
|
||||
mDestructor = destructor;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD nsGenericFactory::Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
|
||||
{
|
||||
// sorry, aggregation not spoken here.
|
||||
nsresult res = NS_ERROR_NO_AGGREGATION;
|
||||
if (outer == NULL) {
|
||||
nsGenericFactory* factory = new nsGenericFactory;
|
||||
if (factory != NULL) {
|
||||
res = factory->QueryInterface(aIID, aInstancePtr);
|
||||
if (res != NS_OK)
|
||||
delete factory;
|
||||
} else {
|
||||
res = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
60
mozilla/xpcom/components/nsGenericFactory.h
Normal file
60
mozilla/xpcom/components/nsGenericFactory.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/* -*- 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 nsGenericFactory_h___
|
||||
#define nsGenericFactory_h___
|
||||
|
||||
#include "nsIGenericFactory.h"
|
||||
|
||||
/**
|
||||
* Most factories follow this simple pattern, so why not just use a function pointer
|
||||
* for most creation operations?
|
||||
*/
|
||||
class nsGenericFactory : public nsIGenericFactory {
|
||||
public:
|
||||
static const nsCID& CID() { static nsCID cid = NS_GENERICFACTORY_CID; return cid; }
|
||||
|
||||
nsGenericFactory(ConstructorProcPtr constructor = NULL);
|
||||
virtual ~nsGenericFactory();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
/**
|
||||
* Establishes the generic factory's constructor function, which will be called
|
||||
* by CreateInstance.
|
||||
*/
|
||||
NS_IMETHOD SetConstructor(ConstructorProcPtr constructor);
|
||||
|
||||
/**
|
||||
* Establishes the generic factory's destructor function, which will be called
|
||||
* whe the generic factory is deleted. This is used to notify the DLL that
|
||||
* an instance of one of its generic factories is going away.
|
||||
*/
|
||||
NS_IMETHOD SetDestructor(DestructorProcPtr destructor);
|
||||
|
||||
static NS_METHOD Create(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr);
|
||||
private:
|
||||
ConstructorProcPtr mConstructor;
|
||||
DestructorProcPtr mDestructor;
|
||||
};
|
||||
|
||||
#endif /* nsGenericFactory_h___ */
|
||||
258
mozilla/xpcom/components/nsIComponentManager.h
Normal file
258
mozilla/xpcom/components/nsIComponentManager.h
Normal file
@@ -0,0 +1,258 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
|
||||
#ifndef nsIComponentManager_h__
|
||||
#define nsIComponentManager_h__
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nsCom.h"
|
||||
#include "nsID.h"
|
||||
#include "nsError.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
|
||||
/*
|
||||
* Prototypes for dynamic library export functions. Your DLL/DSO needs to export
|
||||
* these methods to play in the component world.
|
||||
*/
|
||||
|
||||
extern "C" NS_EXPORT nsresult NSGetFactory(nsISupports* aServMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory);
|
||||
extern "C" NS_EXPORT PRBool NSCanUnload(nsISupports* aServMgr);
|
||||
extern "C" NS_EXPORT nsresult NSRegisterSelf(nsISupports* aServMgr, const char *fullpath);
|
||||
extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* aServMgr, const char *fullpath);
|
||||
|
||||
typedef nsresult (*nsFactoryProc)(nsISupports* aServMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory);
|
||||
typedef PRBool (*nsCanUnloadProc)(nsISupports* aServMgr);
|
||||
typedef nsresult (*nsRegisterProc)(nsISupports* aServMgr, const char *path);
|
||||
typedef nsresult (*nsUnregisterProc)(nsISupports* aServMgr, const char *path);
|
||||
|
||||
#define NS_ICOMPONENTMANAGER_IID \
|
||||
{ /* 8458a740-d5dc-11d2-92fb-00e09805570f */ \
|
||||
0x8458a740, \
|
||||
0xd5dc, \
|
||||
0x11d2, \
|
||||
{0x92, 0xfb, 0x00, 0xe0, 0x98, 0x05, 0x57, 0x0f} \
|
||||
}
|
||||
|
||||
#define NS_COMPONENTMANAGER_CID \
|
||||
{ /* 91775d60-d5dc-11d2-92fb-00e09805570f */ \
|
||||
0x91775d60, \
|
||||
0xd5dc, \
|
||||
0x11d2, \
|
||||
{0x92, 0xfb, 0x00, 0xe0, 0x98, 0x05, 0x57, 0x0f} \
|
||||
}
|
||||
|
||||
/*
|
||||
* nsIComponentManager interface
|
||||
*/
|
||||
|
||||
class nsIComponentManager : public nsISupports {
|
||||
public:
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICOMPONENTMANAGER_IID)
|
||||
|
||||
NS_IMETHOD FindFactory(const nsCID &aClass,
|
||||
nsIFactory **aFactory) = 0;
|
||||
|
||||
// Finds a class ID for a specific Program ID
|
||||
NS_IMETHOD ProgIDToCLSID(const char *aProgID,
|
||||
nsCID *aClass) = 0;
|
||||
|
||||
// Finds a Program ID for a specific class ID
|
||||
// caller frees the result with delete[]
|
||||
NS_IMETHOD CLSIDToProgID(nsCID *aClass,
|
||||
char* *aClassName,
|
||||
char* *aProgID) = 0;
|
||||
|
||||
// Creates a class instance for a specific class ID
|
||||
NS_IMETHOD CreateInstance(const nsCID &aClass,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult) = 0;
|
||||
|
||||
// Convenience routine, creates a class instance for a specific ProgID
|
||||
NS_IMETHOD CreateInstance(const char *aProgID,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult) = 0;
|
||||
|
||||
// Creates a class instance for a specific class ID
|
||||
/*
|
||||
NS_IMETHOD CreateInstance2(const nsCID &aClass,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void *aSignature,
|
||||
void **aResult) = 0;
|
||||
*/
|
||||
|
||||
// Manually registry a factory for a class
|
||||
NS_IMETHOD RegisterFactory(const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory *aFactory,
|
||||
PRBool aReplace) = 0;
|
||||
|
||||
// Manually register a dynamically loaded component.
|
||||
NS_IMETHOD RegisterComponent(const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
const char *aLibrary,
|
||||
PRBool aReplace,
|
||||
PRBool aPersist) = 0;
|
||||
|
||||
// Manually unregister a factory for a class
|
||||
NS_IMETHOD UnregisterFactory(const nsCID &aClass,
|
||||
nsIFactory *aFactory) = 0;
|
||||
|
||||
// Manually unregister a dynamically loaded factory for a class
|
||||
NS_IMETHOD UnregisterFactory(const nsCID &aClass,
|
||||
const char *aLibrary) = 0;
|
||||
|
||||
// Manually unregister a dynamically loaded component
|
||||
NS_IMETHOD UnregisterComponent(const nsCID &aClass,
|
||||
const char *aLibrary) = 0;
|
||||
|
||||
// Unload dynamically loaded factories that are not in use
|
||||
NS_IMETHOD FreeLibraries(void) = 0;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// DLL registration support
|
||||
/* Autoregistration will try only files with these extensions.
|
||||
* All extensions are case insensitive.
|
||||
* ".dll", // Windows
|
||||
* ".dso", // Unix
|
||||
* ".so", // Unix
|
||||
* ".sl", // Unix: HP
|
||||
* "_dll", // Mac
|
||||
* ".dlm", // new for all platforms
|
||||
*/
|
||||
enum RegistrationTime {
|
||||
NS_Startup = 0,
|
||||
NS_Script = 1,
|
||||
NS_Timer = 2
|
||||
};
|
||||
|
||||
NS_IMETHOD AutoRegister(RegistrationTime when, const char* pathlist) = 0;
|
||||
// Pathlist is a semicolon separated list of pathnames
|
||||
NS_IMETHOD AddToDefaultPathList(const char *pathlist) = 0;
|
||||
NS_IMETHOD SyncComponentsInPathList(const char *pathlist) = 0;
|
||||
NS_IMETHOD SyncComponentsInDir(const char *path) = 0;
|
||||
NS_IMETHOD SyncComponentsInFile(const char *fullname) = 0;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern NS_COM nsresult
|
||||
NS_GetGlobalComponentManager(nsIComponentManager* *result);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Global Static Component Manager Methods
|
||||
// (for when you need to link with xpcom)
|
||||
|
||||
class NS_COM nsComponentManager {
|
||||
public:
|
||||
static nsresult Initialize(void);
|
||||
|
||||
// Finds a factory for a specific class ID
|
||||
static nsresult FindFactory(const nsCID &aClass,
|
||||
nsIFactory **aFactory);
|
||||
|
||||
// Finds a class ID for a specific Program ID
|
||||
static nsresult ProgIDToCLSID(const char *aProgID,
|
||||
nsCID *aClass);
|
||||
|
||||
// Finds a Program ID for a specific class ID
|
||||
// caller frees the result with delete[]
|
||||
static nsresult CLSIDToProgID(nsCID *aClass,
|
||||
char* *aClassName,
|
||||
char* *aProgID);
|
||||
|
||||
// Creates a class instance for a specific class ID
|
||||
static nsresult CreateInstance(const nsCID &aClass,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
// Convenience routine, creates a class instance for a specific ProgID
|
||||
static nsresult CreateInstance(const char *aProgID,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
// Creates a class instance for a specific class ID
|
||||
/*
|
||||
static nsresult CreateInstance2(const nsCID &aClass,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void *aSignature,
|
||||
void **aResult);
|
||||
*/
|
||||
|
||||
// Manually registry a factory for a class
|
||||
static nsresult RegisterFactory(const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory *aFactory,
|
||||
PRBool aReplace);
|
||||
|
||||
// Manually register a dynamically loaded component.
|
||||
static nsresult RegisterComponent(const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
const char *aLibrary,
|
||||
PRBool aReplace,
|
||||
PRBool aPersist);
|
||||
|
||||
// Manually unregister a factory for a class
|
||||
static nsresult UnregisterFactory(const nsCID &aClass,
|
||||
nsIFactory *aFactory);
|
||||
|
||||
// Manually unregister a dynamically loaded factory for a class
|
||||
static nsresult UnregisterFactory(const nsCID &aClass,
|
||||
const char *aLibrary);
|
||||
|
||||
// Manually unregister a dynamically loaded component
|
||||
static nsresult UnregisterComponent(const nsCID &aClass,
|
||||
const char *aLibrary);
|
||||
|
||||
// Unload dynamically loaded factories that are not in use
|
||||
static nsresult FreeLibraries(void);
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// DLL registration support
|
||||
static nsresult AutoRegister(nsIComponentManager::RegistrationTime when,
|
||||
const char* pathlist);
|
||||
// Pathlist is a semicolon separated list of pathnames
|
||||
static nsresult AddToDefaultPathList(const char *pathlist);
|
||||
static nsresult SyncComponentsInPathList(const char *pathlist);
|
||||
static nsresult SyncComponentsInDir(const char *path);
|
||||
static nsresult SyncComponentsInFile(const char *fullname);
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif
|
||||
68
mozilla/xpcom/components/nsIFactory.h
Normal file
68
mozilla/xpcom/components/nsIFactory.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
|
||||
#ifndef __nsIFactory_h
|
||||
#define __nsIFactory_h
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
/*
|
||||
* nsIFactory interface
|
||||
*/
|
||||
|
||||
// {00000001-0000-0000-c000-000000000046}
|
||||
#define NS_IFACTORY_IID \
|
||||
{ 0x00000001, 0x0000, 0x0000, \
|
||||
{ 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } }
|
||||
|
||||
class nsIFactory: public nsISupports {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IFACTORY_IID; return iid; }
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
REFNSIID aIID,
|
||||
void **aResult) = 0;
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock) = 0;
|
||||
};
|
||||
|
||||
#if 0
|
||||
/* Excluding IFactory2 until there is proof of its use - dp */
|
||||
/**
|
||||
* nsIFactory2 allows passing in a signature token when creating an
|
||||
* instance. This allows instance recycling.
|
||||
*/
|
||||
|
||||
// {19997C41-A343-11d1-B665-00805F8A2676}
|
||||
#define NS_IFACTORY2_IID \
|
||||
{ 0x19997c41, 0xa343, 0x11d1, \
|
||||
{ 0xb6, 0x65, 0x0, 0x80, 0x5f, 0x8a, 0x26, 0x76 } }
|
||||
|
||||
class nsIFactory2: public nsIFactory {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IFACTORY2_IID; return iid; }
|
||||
|
||||
NS_IMETHOD CreateInstance2(nsISupports *aOuter,
|
||||
REFNSIID aIID,
|
||||
void *aSignature,
|
||||
void **aResult) = 0;
|
||||
};
|
||||
#endif /* 0 */
|
||||
|
||||
#endif
|
||||
33
mozilla/xpcom/components/nsIFactory.idl
Normal file
33
mozilla/xpcom/components/nsIFactory.idl
Normal file
@@ -0,0 +1,33 @@
|
||||
/* -*- 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"
|
||||
%{ C++
|
||||
#include "nsCID.h"
|
||||
%}
|
||||
|
||||
[object, uuid(19997C41-A343-11d1-B665-00805F8A2676)]
|
||||
interface nsIFactory : nsISupports {
|
||||
|
||||
voidStar CreateInstance(in nsISupports aOuter,
|
||||
in nsIID iid);
|
||||
|
||||
void LockFactory(in boolean lock);
|
||||
|
||||
};
|
||||
|
||||
57
mozilla/xpcom/components/nsIGenericFactory.h
Normal file
57
mozilla/xpcom/components/nsIGenericFactory.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/* -*- 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 nsIGenericFactory_h___
|
||||
#define nsIGenericFactory_h___
|
||||
|
||||
#include "nsIFactory.h"
|
||||
|
||||
// {3bc97f01-ccdf-11d2-bab8-b548654461fc}
|
||||
#define NS_GENERICFACTORY_CID \
|
||||
{ 0x3bc97f01, 0xccdf, 0x11d2, { 0xba, 0xb8, 0xb5, 0x48, 0x65, 0x44, 0x61, 0xfc } }
|
||||
|
||||
// {3bc97f00-ccdf-11d2-bab8-b548654461fc}
|
||||
#define NS_IGENERICFACTORY_IID \
|
||||
{ 0x3bc97f00, 0xccdf, 0x11d2, { 0xba, 0xb8, 0xb5, 0x48, 0x65, 0x44, 0x61, 0xfc } }
|
||||
|
||||
/**
|
||||
* Provides a Generic nsIFactory implementation that can be used by
|
||||
* DLLs with very simple factory needs.
|
||||
*/
|
||||
class nsIGenericFactory : public nsIFactory {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IGENERICFACTORY_IID; return iid; }
|
||||
|
||||
typedef NS_CALLBACK(ConstructorProcPtr) (nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
typedef NS_CALLBACK(DestructorProcPtr) (void);
|
||||
|
||||
/**
|
||||
* Establishes the generic factory's constructor function, which will be called
|
||||
* by CreateInstance.
|
||||
*/
|
||||
NS_IMETHOD SetConstructor(ConstructorProcPtr constructor) = 0;
|
||||
|
||||
/**
|
||||
* Establishes the generic factory's destructor function, which will be called
|
||||
* whe the generic factory is deleted. This is used to notify the DLL that
|
||||
* an instance of one of its generic factories is going away.
|
||||
*/
|
||||
NS_IMETHOD SetDestructor(DestructorProcPtr destructor) = 0;
|
||||
};
|
||||
|
||||
#endif /* nsIGenericFactory_h___ */
|
||||
350
mozilla/xpcom/components/nsIRegistry.h
Normal file
350
mozilla/xpcom/components/nsIRegistry.h
Normal file
@@ -0,0 +1,350 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
#ifndef __nsIRegistry_h
|
||||
#define __nsIRegistry_h
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
// {5D41A440-8E37-11d2-8059-00600811A9C3}
|
||||
#define NS_IREGISTRY_IID { 0x5d41a440, 0x8e37, 0x11d2, { 0x80, 0x59, 0x0, 0x60, 0x8, 0x11, 0xa9, 0xc3 } }
|
||||
#define NS_REGISTRY_PROGID "component://netscape/registry"
|
||||
#define NS_REGISTRY_CLASSNAME "Mozilla Registry"
|
||||
|
||||
// {D1B54831-AC07-11d2-805E-00600811A9C3}
|
||||
#define NS_IREGISTRYNODE_IID { 0xd1b54831, 0xac07, 0x11d2, { 0x80, 0x5e, 0x0, 0x60, 0x8, 0x11, 0xa9, 0xc3 } }
|
||||
// {5316C380-B2F8-11d2-A374-0080C6F80E4B}
|
||||
#define NS_IREGISTRYVALUE_IID { 0x5316c380, 0xb2f8, 0x11d2, { 0xa3, 0x74, 0x0, 0x80, 0xc6, 0xf8, 0xe, 0x4b } }
|
||||
|
||||
|
||||
class nsIEnumerator;
|
||||
|
||||
/*-------------------------------- nsIRegistry ---------------------------------
|
||||
| This interface provides access to a tree of arbitrary values. |
|
||||
| |
|
||||
| Each node of the tree contains either a value or a subtree or both. |
|
||||
| |
|
||||
| The value at any of these leaf nodes can be any of these "primitive" types: |
|
||||
| o string (null terminated UTF string) |
|
||||
| o array of 32-bit integers |
|
||||
| o arbitrary array of bytes |
|
||||
| o file identifier |
|
||||
| Of course, since you can store an arbitrary array of bytes, you can put |
|
||||
| any data you like into a registry (although you have the burden of |
|
||||
| encoding/decoding your data in that case). |
|
||||
| |
|
||||
| Each branch of the tree is labelled with a string "key." The entire path |
|
||||
| from a given point of the tree to another point further down can be |
|
||||
| presented as a single string composed of each branch's label, concatenated |
|
||||
| to the next, with an intervening forward slash ('/'). The term "key" |
|
||||
| refers to both specific tree branch labels and to such concatenated paths. |
|
||||
| |
|
||||
| The branches from a given node must have unique labels. Distinct nodes can |
|
||||
| have branches with the same label. |
|
||||
| |
|
||||
| For example, here's a small registry tree: |
|
||||
| | |
|
||||
| /\ |
|
||||
| / \ |
|
||||
| / \ |
|
||||
| / \ |
|
||||
| "Classes" "Users" |
|
||||
| / \ |
|
||||
| / \ |
|
||||
| / ["joe"] |
|
||||
| / / \ |
|
||||
| | / \ |
|
||||
| /\ / \ |
|
||||
| / \ "joe" "bob" |
|
||||
| / \ / \ |
|
||||
| / \ |
|
||||
| "{xxxx-xx-1}" "{xxxx-xx-2}" ["c:/joe"] ["d:/Robert"] |
|
||||
| | | |
|
||||
| /\ /\ |
|
||||
| / \ / \ |
|
||||
| / \ / \ |
|
||||
| "Library" "Version" "Library" "Version" |
|
||||
| / \ / \ |
|
||||
| ["foo.dll"] 2 ["bar.dll"] 1 |
|
||||
| |
|
||||
| In this example, there are 2 keys under the root: "Classes" and "Users". |
|
||||
| The first denotes a subtree only (which has two subtrees, ...). The second |
|
||||
| denotes both a value ["joe"] and two subtrees labelled "joe" and "bob". |
|
||||
| The value at the node "/Users" is ["joe"], at "/Users/bob" is ["d:/Robert"]. |
|
||||
| The value at "/Classes/{xxxx-xx-1}/Version" is 2. |
|
||||
| |
|
||||
| The registry interface provides functions that let you navigate the tree |
|
||||
| and manipulate it's contents. |
|
||||
| |
|
||||
| Please note that the registry itself does not impose any structure or |
|
||||
| meaning on the contents of the tree. For example, the registry doesn't |
|
||||
| control whether the value at the key "/Users" is the label for the subtree |
|
||||
| with information about the last active user. That meaning is applied by |
|
||||
| the code that stores these values and uses them for that purpose. |
|
||||
| |
|
||||
| [Any resemblence between this example and actual contents of any actual |
|
||||
| registry is purely coincidental.] |
|
||||
------------------------------------------------------------------------------*/
|
||||
struct nsIRegistry : public nsISupports {
|
||||
/*------------------------------ Constants ---------------------------------
|
||||
| The following enumerated types and values are used by the registry |
|
||||
| interface. |
|
||||
--------------------------------------------------------------------------*/
|
||||
typedef enum {
|
||||
String = 1,
|
||||
Int32,
|
||||
Bytes,
|
||||
File
|
||||
} DataType;
|
||||
|
||||
/*-------------------------------- Types -----------------------------------
|
||||
| The following data types are used by this interface. All are basically |
|
||||
| opaque types. You obtain objects of these types via certain member |
|
||||
| function calls and re-use them later (without having to know what they |
|
||||
| contain). |
|
||||
| |
|
||||
| Key - Placeholder to represent a particular node in a registry |
|
||||
| tree. There are 3 enumerated values that correspond to |
|
||||
| specific nodes: |
|
||||
| Common - Where most stuff goes. |
|
||||
| Users - Special subtree to hold info about |
|
||||
| "users"; if you don't know what goes |
|
||||
| here, don't mess with it. |
|
||||
| CurrentUser - Subtree under Users corresponding to |
|
||||
| whatever user is designed the "current" |
|
||||
| one; see note above. |
|
||||
| You can specify any of these enumerated values as "keys" |
|
||||
| on any member function that takes a nsRegistry::Key. |
|
||||
| ValueInfo - Structure describing a registry value. |
|
||||
--------------------------------------------------------------------------*/
|
||||
typedef uint32 Key;
|
||||
|
||||
enum { Users = 1, Common = 2, CurrentUser = 3 };
|
||||
|
||||
struct ValueInfo {
|
||||
DataType type;
|
||||
uint32 length;
|
||||
};
|
||||
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IREGISTRY_IID; return iid; }
|
||||
|
||||
/*--------------------------- Opening/Closing ------------------------------
|
||||
| These functions open the specified registry file (Open() with a non-null |
|
||||
| argument) or the default "standard" registry file (Open() with a null |
|
||||
| argument or OpenDefault()). |
|
||||
| |
|
||||
| Once opened, you can access the registry contents via the read/write |
|
||||
| or query functions. |
|
||||
| |
|
||||
| The registry file will be closed automatically when the registry object |
|
||||
| is destroyed. You can close the file prior to that by using the |
|
||||
| Close() function. |
|
||||
--------------------------------------------------------------------------*/
|
||||
NS_IMETHOD Open( const char *regFile = 0 ) = 0;
|
||||
NS_IMETHOD OpenDefault() = 0;
|
||||
NS_IMETHOD Close() = 0;
|
||||
|
||||
/*----------------------- Reading/Writing Values ---------------------------
|
||||
| These functions read/write the registry values at a given node. |
|
||||
| |
|
||||
| All functions require you to specify where in the registry key to |
|
||||
| get/set the value. The location is specified using two components: |
|
||||
| o A "base key" indicating where to start from; this is a value of type |
|
||||
| nsIRegistry::Key. You use either one of the special "root" key |
|
||||
| values or a subkey obtained via some other member function call. |
|
||||
| o A "relative path," expressed as a sequence of subtree names |
|
||||
| separated by forward slashes. This path describes how to get from |
|
||||
| the base key to the node at which you want to store the data. This |
|
||||
| component can be a null pointer which means the value goes directly |
|
||||
| at the node denoted by the base key. |
|
||||
| |
|
||||
| When you request a value of a given type, the data stored at the |
|
||||
| specified node must be of the type requested. If not, an error results. |
|
||||
| |
|
||||
| GetString - Obtains a newly allocated copy of a string type value. The |
|
||||
| caller is obligated to free the returned string using |
|
||||
| PR_Free. |
|
||||
| SetString - Stores the argument string at the specified node. |
|
||||
| GetInt - Obtains an int32 value at the specified node. The result |
|
||||
| is returned into an int32 location you specify. |
|
||||
| SetInt - Stores a given int32 value at a node. |
|
||||
| GetBytes - Obtains a byte array value; this returns both an allocated |
|
||||
| array of bytes and a length (necessary because there may be |
|
||||
| embedded null bytes in the array). You must free the |
|
||||
| resulting array using PR_Free. |
|
||||
| SetBytes - Stores a given array of bytes; you specify the bytes via a |
|
||||
| pointer and a length. |
|
||||
| GetIntArray - Obtains the array of int32 values stored at a given node. |
|
||||
| The result is composed of two values: a pointer to an |
|
||||
| array of integer values (which must be freed using |
|
||||
| PR_Free) and the number of elements in that array. |
|
||||
| SetIntArray - Stores a set of int32 values at a given node. You must |
|
||||
| provide a pointer to the array and the number of entries. |
|
||||
--------------------------------------------------------------------------*/
|
||||
NS_IMETHOD GetString( Key baseKey, const char *path, char **result ) = 0;
|
||||
NS_IMETHOD SetString( Key baseKey, const char *path, const char *value ) = 0;
|
||||
NS_IMETHOD GetInt( Key baseKey, const char *path, int32 *result ) = 0;
|
||||
NS_IMETHOD SetInt( Key baseKey, const char *path, int32 value ) = 0;
|
||||
NS_IMETHOD GetBytes( Key baseKey, const char *path, void **result, uint32 *len ) = 0;
|
||||
NS_IMETHOD SetBytes( Key baseKey, const char *path, void *value, uint32 len ) = 0;
|
||||
NS_IMETHOD GetIntArray( Key baseKey, const char *path, int32 **result, uint32 *len ) = 0;
|
||||
NS_IMETHOD SetIntArray( Key baseKey, const char *path, const int32 *value, uint32 len ) = 0;
|
||||
|
||||
/*------------------------------ Navigation --------------------------------
|
||||
| These functions let you navigate through the registry tree, querying |
|
||||
| its contents. |
|
||||
| |
|
||||
| As above, all these functions requires a starting tree location ("base |
|
||||
| key") specified as a nsIRegistry::Key. Some also require a path |
|
||||
| name to locate the registry node location relative to this base key. |
|
||||
| |
|
||||
| AddSubtree - Adds a new registry subtree at the specified |
|
||||
| location. Returns the resulting key in |
|
||||
| the location specified by the third argument |
|
||||
| (unless that pointer is 0). |
|
||||
| AddSubtreeRaw - Adds a new registry subtree at the specified |
|
||||
| location. Returns the resulting key in |
|
||||
| the location specified by the third argument |
|
||||
| (unless that pointer is 0). |
|
||||
| Does not interpret special chars in key names. |
|
||||
| |
|
||||
| RemoveSubtree - Removes the specified registry subtree or |
|
||||
| value at the specified location. |
|
||||
| RemoveSubtreeRaw - Removes the specified registry subtree or |
|
||||
| value at the specified location. |
|
||||
| Does not interpret special chars in key names. |
|
||||
| |
|
||||
| GetSubtree - Returns a nsIRegistry::Key that can be used |
|
||||
| to refer to the specified registry location. |
|
||||
| GetSubtreeRaw - Returns a nsIRegistry::Key that can be used |
|
||||
| to refer to the specified registry location. |
|
||||
| Does not interpret special chars in key names. |
|
||||
| |
|
||||
| EnumerateSubtrees - Returns a nsIEnumerator object that you can |
|
||||
| use to enumerate all the subtrees descending |
|
||||
| from a specified location. You must free the |
|
||||
| enumerator via Release() when you're done with |
|
||||
| it. |
|
||||
| EnumerateAllSubtrees - Like EnumerateSubtrees, but will recursively |
|
||||
| enumerate lower-level subtrees, too. |
|
||||
| GetValueInfo - Returns a uint32 value that designates the type |
|
||||
| of data stored at this location in the registry; |
|
||||
| the possible values are defined by the enumerated |
|
||||
| type nsIRegistry::DataType. |
|
||||
| GetValueLength - Returns a uint32 value that indicates the length |
|
||||
| of this registry value; the length is the number |
|
||||
| of characters (for Strings), the number of bytes |
|
||||
| (for Bytes), or the number of int32 values (for |
|
||||
| Int32). |
|
||||
| EnumerateValues - Returns a nsIEnumerator that you can use to |
|
||||
| enumerate all the value nodes descending from |
|
||||
| a specified location. |
|
||||
--------------------------------------------------------------------------*/
|
||||
NS_IMETHOD AddSubtree( Key baseKey, const char *path, Key *result ) = 0;
|
||||
NS_IMETHOD RemoveSubtree( Key baseKey, const char *path ) = 0;
|
||||
NS_IMETHOD GetSubtree( Key baseKey, const char *path, Key *result ) = 0;
|
||||
|
||||
NS_IMETHOD AddSubtreeRaw( Key baseKey, const char *keyname, Key *result ) = 0;
|
||||
NS_IMETHOD RemoveSubtreeRaw( Key baseKey, const char *keyname ) = 0;
|
||||
NS_IMETHOD GetSubtreeRaw( Key baseKey, const char *keyname, Key *result ) = 0;
|
||||
|
||||
NS_IMETHOD EnumerateSubtrees( Key baseKey, nsIEnumerator **result ) = 0;
|
||||
NS_IMETHOD EnumerateAllSubtrees( Key baseKey, nsIEnumerator **result ) = 0;
|
||||
|
||||
NS_IMETHOD GetValueType( Key baseKey, const char *path, uint32 *result ) = 0;
|
||||
NS_IMETHOD GetValueLength( Key baseKey, const char *path, uint32 *result ) = 0;
|
||||
|
||||
NS_IMETHOD EnumerateValues( Key baseKey, nsIEnumerator **result ) = 0;
|
||||
|
||||
/*------------------------------ User Name ---------------------------------
|
||||
| These functions manipulate the current "user name." This value controls |
|
||||
| the behavior of certain registry functions (namely, ?). |
|
||||
| |
|
||||
| GetCurrentUserName allocates a copy of the current user name (which the |
|
||||
| caller should free using PR_Free). |
|
||||
--------------------------------------------------------------------------*/
|
||||
NS_IMETHOD GetCurrentUserName( char **result ) = 0;
|
||||
NS_IMETHOD SetCurrentUserName( const char *name ) = 0;
|
||||
|
||||
/*------------------------------ Utilities ---------------------------------
|
||||
| Various utility functions: |
|
||||
| |
|
||||
| Pack() is used to compress the contents of an open registry file. |
|
||||
--------------------------------------------------------------------------*/
|
||||
NS_IMETHOD Pack() = 0;
|
||||
|
||||
}; // nsIRegistry
|
||||
|
||||
/*------------------------------ nsIRegistryNode -------------------------------
|
||||
| This interface is implemented by all the objects obtained from the |
|
||||
| nsIEnumerators that nsIRegistry provides when you call either of the |
|
||||
| subtree enumeration functions EnumerateSubtrees or EnumerateAllSubtrees. |
|
||||
| |
|
||||
| You can call this function to get the name of this subtree. This is the |
|
||||
| relative path from the base key from which you got this interface. |
|
||||
| |
|
||||
| GetName - Returns the path name of this node; this is the relative path |
|
||||
| from the base key from which this subtree was obtained. The |
|
||||
| function allocates a copy of the name; the caller must free it |
|
||||
| using PR_Free. |
|
||||
------------------------------------------------------------------------------*/
|
||||
struct nsIRegistryNode : public nsISupports {
|
||||
NS_IMETHOD GetName( char **result ) = 0;
|
||||
}; // nsIRegistryNode
|
||||
|
||||
/*------------------------------ nsIRegistryValue ------------------------------
|
||||
| This interface is implemented by the objects obtained from the |
|
||||
| nsIEnumerators that nsIRegistry provides when you call the |
|
||||
| EnumerateValues function. An object supporting this interface is |
|
||||
| returned when you call the CurrentItem() function on that enumerator. |
|
||||
| |
|
||||
| You use the member functions of this interface to obtain information |
|
||||
| about each registry value. |
|
||||
| |
|
||||
| GetName - Returns the path name of this node; this is the relative |
|
||||
| path\ from the base key from which this value was obtained. |
|
||||
| The function allocates a copy of the name; the caller must |
|
||||
| subsequently free it via PR_Free. |
|
||||
| GetValueType - Returns (into a location provided by the caller) the type |
|
||||
| of the value; the types are defined by the enumerated |
|
||||
| type nsIRegistry::DataType. |
|
||||
| GetValueLength - Returns a uint32 value that indicates the length |
|
||||
| of this registry value; the length is the number |
|
||||
| of characters (for Strings), the number of bytes |
|
||||
| (for Bytes), or the number of int32 values (for |
|
||||
| Int32). |
|
||||
------------------------------------------------------------------------------*/
|
||||
struct nsIRegistryValue : public nsISupports {
|
||||
NS_IMETHOD GetName( char **result ) = 0;
|
||||
NS_IMETHOD GetValueType( uint32 *result ) = 0;
|
||||
NS_IMETHOD GetValueLength( uint32 *result ) = 0;
|
||||
}; // nsIRegistryEntry
|
||||
|
||||
|
||||
/*------------------------------- Error Codes ----------------------------------
|
||||
------------------------------------------------------------------------------*/
|
||||
#define NS_ERROR_REG_BADTYPE NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 1 )
|
||||
#define NS_ERROR_REG_NO_MORE NS_ERROR_GENERATE_SUCCESS( NS_ERROR_MODULE_REG, 2 )
|
||||
#define NS_ERROR_REG_NOT_FOUND NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 3 )
|
||||
#define NS_ERROR_REG_NOFILE NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 4 )
|
||||
#define NS_ERROR_REG_BUFFER_TOO_SMALL NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 5 )
|
||||
#define NS_ERROR_REG_NAME_TOO_LONG NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 6 )
|
||||
#define NS_ERROR_REG_NO_PATH NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 7 )
|
||||
#define NS_ERROR_REG_READ_ONLY NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 8 )
|
||||
#define NS_ERROR_REG_BAD_UTF8 NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_REG, 9 )
|
||||
|
||||
#endif
|
||||
361
mozilla/xpcom/components/nsIServiceManager.h
Normal file
361
mozilla/xpcom/components/nsIServiceManager.h
Normal file
@@ -0,0 +1,361 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#ifndef nsIServiceManager_h___
|
||||
#define nsIServiceManager_h___
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsID.h"
|
||||
|
||||
class nsIShutdownListener;
|
||||
|
||||
#define NS_ISERVICEMANAGER_IID \
|
||||
{ /* cf0df3b0-3401-11d2-8163-006008119d7a */ \
|
||||
0xcf0df3b0, \
|
||||
0x3401, \
|
||||
0x11d2, \
|
||||
{0x81, 0x63, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
|
||||
}
|
||||
|
||||
/**
|
||||
* The nsIServiceManager manager interface provides a means to obtain
|
||||
* global services in an application. The service manager depends on the
|
||||
* repository to find and instantiate factories to obtain services.
|
||||
*
|
||||
* Users of the service manager must first obtain a pointer to the global
|
||||
* service manager by calling NS_GetGlobalServiceManager. After that,
|
||||
* they can request specific services by calling GetService. When they are
|
||||
* finished with a service the release it by calling ReleaseService (instead
|
||||
* of releasing the service object directly):
|
||||
*
|
||||
* nsICacheManager* cm;
|
||||
* nsServiceManager::GetService(kCacheManagerCID, kICacheManagerIID, (nsISupports**)&cm);
|
||||
*
|
||||
* ... use cm, and then sometime later ...
|
||||
*
|
||||
* nsServiceManager::ReleaseService(kCacheManagerCID, cm);
|
||||
*
|
||||
* A user of a service may keep references to particular services indefinitely
|
||||
* and only must call ReleaseService when it shuts down. However if the user
|
||||
* wishes to voluntarily cooperate with the shutdown of the service it is
|
||||
* using, it may supply an nsIShutdownListener to provide for asynchronous
|
||||
* release of the services it is using. The shutdown listener's OnShutdown
|
||||
* method will be called for a service that is being shut down, and it is
|
||||
* its responsiblity to release references obtained from that service if at
|
||||
* all possible.
|
||||
*
|
||||
* The process of shutting down a particular service is initiated by calling
|
||||
* the service manager's ShutdownService method. This will iterate through
|
||||
* all the registered shutdown listeners for the service being shut down, and
|
||||
* then will attempt to unload the library associated with the service if
|
||||
* possible. The status result of ShutdownService indicates whether the
|
||||
* service was successfully shut down, failed, or was not in service.
|
||||
*
|
||||
* XXX QUESTIONS:
|
||||
* - Should a "service" be more than nsISupports? Should it be a factory
|
||||
* and/or have Startup(), Shutdown(), etc.
|
||||
* - If the asynchronous OnShutdown operation gets called, does the user
|
||||
* of a service still need to call ReleaseService? (Or should they _not_
|
||||
* call it?)
|
||||
*/
|
||||
class nsIServiceManager : public nsISupports {
|
||||
public:
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISERVICEMANAGER_IID);
|
||||
|
||||
/**
|
||||
* RegisterService may be called explicitly to register a service
|
||||
* with the service manager. If a service is not registered explicitly,
|
||||
* the component manager will be used to create an instance according
|
||||
* to the class ID specified.
|
||||
*/
|
||||
NS_IMETHOD
|
||||
RegisterService(const nsCID& aClass, nsISupports* aService) = 0;
|
||||
|
||||
/**
|
||||
* Requests a service to be shut down, possibly unloading its DLL.
|
||||
*
|
||||
* @returns NS_OK - if shutdown was successful and service was unloaded,
|
||||
* @returns NS_ERROR_SERVICE_NOT_FOUND - if shutdown failed because
|
||||
* the service was not currently loaded
|
||||
* @returns NS_ERROR_SERVICE_IN_USE - if shutdown failed because some
|
||||
* user of the service wouldn't voluntarily release it by using
|
||||
* a shutdown listener.
|
||||
*/
|
||||
NS_IMETHOD
|
||||
UnregisterService(const nsCID& aClass) = 0;
|
||||
|
||||
NS_IMETHOD
|
||||
GetService(const nsCID& aClass, const nsIID& aIID,
|
||||
nsISupports* *result,
|
||||
nsIShutdownListener* shutdownListener = NULL) = 0;
|
||||
|
||||
NS_IMETHOD
|
||||
ReleaseService(const nsCID& aClass, nsISupports* service,
|
||||
nsIShutdownListener* shutdownListener = NULL) = 0;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// let's do it again, this time with ProgIDs...
|
||||
|
||||
NS_IMETHOD
|
||||
RegisterService(const char* aProgID, nsISupports* aService) = 0;
|
||||
|
||||
NS_IMETHOD
|
||||
UnregisterService(const char* aProgID) = 0;
|
||||
|
||||
NS_IMETHOD
|
||||
GetService(const char* aProgID, const nsIID& aIID,
|
||||
nsISupports* *result,
|
||||
nsIShutdownListener* shutdownListener = NULL) = 0;
|
||||
|
||||
NS_IMETHOD
|
||||
ReleaseService(const char* aProgID, nsISupports* service,
|
||||
nsIShutdownListener* shutdownListener = NULL) = 0;
|
||||
|
||||
};
|
||||
|
||||
#define NS_ERROR_SERVICE_NOT_FOUND NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_XPCOM, 22)
|
||||
#define NS_ERROR_SERVICE_IN_USE NS_ERROR_GENERATE_SUCCESS(NS_ERROR_MODULE_XPCOM, 23)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define NS_ISHUTDOWNLISTENER_IID \
|
||||
{ /* 56decae0-3406-11d2-8163-006008119d7a */ \
|
||||
0x56decae0, \
|
||||
0x3406, \
|
||||
0x11d2, \
|
||||
{0x81, 0x63, 0x00, 0x60, 0x08, 0x11, 0x9d, 0x7a} \
|
||||
}
|
||||
|
||||
class nsIShutdownListener : public nsISupports {
|
||||
public:
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISHUTDOWNLISTENER_IID);
|
||||
|
||||
NS_IMETHOD
|
||||
OnShutdown(const nsCID& aClass, nsISupports* service) = 0;
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Interface to Global Services
|
||||
|
||||
class NS_COM nsServiceManager {
|
||||
public:
|
||||
|
||||
static nsresult RegisterService(const nsCID& aClass, nsISupports* aService);
|
||||
|
||||
static nsresult UnregisterService(const nsCID& aClass);
|
||||
|
||||
static nsresult GetService(const nsCID& aClass, const nsIID& aIID,
|
||||
nsISupports* *result,
|
||||
nsIShutdownListener* shutdownListener = NULL);
|
||||
|
||||
static nsresult ReleaseService(const nsCID& aClass, nsISupports* service,
|
||||
nsIShutdownListener* shutdownListener = NULL);
|
||||
|
||||
// Since the global Service Manager is truly global, there's no need to
|
||||
// release it.
|
||||
static nsresult GetGlobalServiceManager(nsIServiceManager* *result);
|
||||
|
||||
// This method can be called when shutting down the application. It
|
||||
// releases all the global services, and deletes the global service manager.
|
||||
static nsresult ShutdownGlobalServiceManager(nsIServiceManager* *result);
|
||||
|
||||
static nsIServiceManager* mGlobalServiceManager;
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsService: Template to make using services easier. Now you can replace this:
|
||||
//
|
||||
// nsIMyService* service;
|
||||
// rv = nsServiceManager::GetService(cid, iid, &service);
|
||||
// if (NS_SUCCEEDED(rv)) {
|
||||
// service->Doit(...); // use my service
|
||||
// rv = nsServiceManager::ReleaseService(cid, service);
|
||||
// }
|
||||
//
|
||||
// with this:
|
||||
//
|
||||
// nsService<nsIMyService> service(cid, &rv);
|
||||
// if (NS_SUCCEEDED(rv)) {
|
||||
// service->Doit(...); // use my service
|
||||
// }
|
||||
//
|
||||
// and the automatic destructor will take care of releasing the service.
|
||||
|
||||
#if 0 // sorry the T::GetIID() construct doesn't work with egcs
|
||||
|
||||
template<class T> class nsService {
|
||||
protected:
|
||||
nsCID mCID;
|
||||
T* mService;
|
||||
|
||||
public:
|
||||
nsService(nsISupports* aServMgr, const nsCID& aClass, nsresult *rv)
|
||||
: mCID(aClass), mService(0)
|
||||
{
|
||||
nsIServiceManager* servMgr;
|
||||
*rv = aServMgr->QueryInterface(nsIServiceManager::GetIID(), (void**)&servMgr);
|
||||
if (NS_SUCCEEDED(*rv)) {
|
||||
*rv = servMgr->GetService(mCID, T::GetIID(), (nsISupports**)&mService);
|
||||
NS_RELEASE(servMgr);
|
||||
}
|
||||
NS_ASSERTION(NS_SUCCEEDED(*rv), "Couldn't get service.");
|
||||
}
|
||||
|
||||
nsService(nsISupports* aServMgr, const char* aProgID, nsresult *rv)
|
||||
: mService(0)
|
||||
{
|
||||
*rv = nsComponentManager::ProgIDToCLSID(aProgID, &mCID);
|
||||
NS_ASSERTION(NS_SUCCEEDED(*rv), "Couldn't get CLSID.");
|
||||
if (NS_FAILED(*rv)) return;
|
||||
|
||||
nsIServiceManager* servMgr;
|
||||
*rv = aServMgr->QueryInterface(nsIServiceManager::GetIID(), (void**)&servMgr);
|
||||
if (NS_SUCCEEDED(*rv)) {
|
||||
*rv = servMgr->GetService(mCID, T::GetIID(), (nsISupports**)&mService);
|
||||
NS_RELEASE(servMgr);
|
||||
}
|
||||
NS_ASSERTION(NS_SUCCEEDED(*rv), "Couldn't get service.");
|
||||
}
|
||||
|
||||
nsService(const nsCID& aClass, nsresult *rv)
|
||||
: mCID(aClass), mService(0) {
|
||||
*rv = nsServiceManager::GetService(aClass, T::GetIID(),
|
||||
(nsISupports**)&mService);
|
||||
NS_ASSERTION(NS_SUCCEEDED(*rv), "Couldn't get service.");
|
||||
}
|
||||
|
||||
~nsService() {
|
||||
if (mService) { // mService could be null if the constructor fails
|
||||
nsresult rv = nsServiceManager::ReleaseService(mCID, mService);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't release service.");
|
||||
}
|
||||
}
|
||||
|
||||
T* operator->() const {
|
||||
NS_PRECONDITION(mService != 0, "Your code should test the error result from the constructor.");
|
||||
return mService;
|
||||
}
|
||||
|
||||
PRBool operator==(const T* other) {
|
||||
return mService == other;
|
||||
}
|
||||
|
||||
operator T*() const {
|
||||
return mService;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
class nsService {
|
||||
protected:
|
||||
nsCID mCID;
|
||||
nsISupports* mService;
|
||||
|
||||
public:
|
||||
nsService(nsISupports* aServMgr, const nsCID& aClass, const nsIID& aIID, nsresult *rv)
|
||||
: mCID(aClass), mService(0)
|
||||
{
|
||||
nsIServiceManager* servMgr;
|
||||
*rv = aServMgr->QueryInterface(nsIServiceManager::GetIID(), (void**)&servMgr);
|
||||
if (NS_SUCCEEDED(*rv)) {
|
||||
*rv = servMgr->GetService(mCID, aIID, &mService);
|
||||
NS_RELEASE(servMgr);
|
||||
}
|
||||
NS_ASSERTION(NS_SUCCEEDED(*rv), "Couldn't get service.");
|
||||
}
|
||||
|
||||
nsService(nsISupports* aServMgr, const char* aProgID, const nsIID& aIID, nsresult *rv)
|
||||
: mService(0)
|
||||
{
|
||||
*rv = nsComponentManager::ProgIDToCLSID(aProgID, &mCID);
|
||||
NS_ASSERTION(NS_SUCCEEDED(*rv), "Couldn't get CLSID.");
|
||||
if (NS_FAILED(*rv)) return;
|
||||
|
||||
nsIServiceManager* servMgr;
|
||||
*rv = aServMgr->QueryInterface(nsIServiceManager::GetIID(), (void**)&servMgr);
|
||||
if (NS_SUCCEEDED(*rv)) {
|
||||
*rv = servMgr->GetService(mCID, aIID, &mService);
|
||||
NS_RELEASE(servMgr);
|
||||
}
|
||||
NS_ASSERTION(NS_SUCCEEDED(*rv), "Couldn't get service.");
|
||||
}
|
||||
|
||||
nsService(const nsCID& aClass, const nsIID& aIID, nsresult *rv)
|
||||
: mCID(aClass), mService(0) {
|
||||
*rv = nsServiceManager::GetService(aClass, aIID,
|
||||
(nsISupports**)&mService);
|
||||
NS_ASSERTION(NS_SUCCEEDED(*rv), "Couldn't get service.");
|
||||
}
|
||||
|
||||
~nsService() {
|
||||
if (mService) { // mService could be null if the constructor fails
|
||||
nsresult rv = NS_OK;
|
||||
rv = nsServiceManager::ReleaseService(mCID, mService);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't release service.");
|
||||
}
|
||||
}
|
||||
|
||||
nsISupports* operator->() const {
|
||||
NS_PRECONDITION(mService != 0, "Your code should test the error result from the constructor.");
|
||||
return mService;
|
||||
}
|
||||
|
||||
PRBool operator==(const nsISupports* other) {
|
||||
return mService == other;
|
||||
}
|
||||
|
||||
operator nsISupports*() const {
|
||||
return mService;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#define NS_WITH_SERVICE(T, var, cid, rvAddr) \
|
||||
nsService _serv##var(cid, T::GetIID(), rvAddr); \
|
||||
T* var = (T*)(nsISupports*)_serv##var;
|
||||
|
||||
#define NS_WITH_SERVICE1(T, var, isupports, cid, rvAddr) \
|
||||
nsService _serv##var(isupports, cid, T::GetIID(), rvAddr); \
|
||||
T* var = (T*)(nsISupports*)_serv##var;
|
||||
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// NS_NewServiceManager: For when you want to create a service manager
|
||||
// in a given context.
|
||||
|
||||
extern NS_COM nsresult
|
||||
NS_NewServiceManager(nsIServiceManager* *result);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Initialization of XPCOM. Creates the global ComponentManager, ServiceManager
|
||||
// and registers xpcom components with the ComponentManager. Should be called
|
||||
// before any call can be made to XPCOM. Currently we are coping with this
|
||||
// not being called and internally initializing XPCOM if not already.
|
||||
extern NS_COM nsresult
|
||||
NS_InitXPCOM(nsIServiceManager* *result);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif /* nsIServiceManager_h___ */
|
||||
31
mozilla/xpcom/components/nsIServiceProvider.h
Normal file
31
mozilla/xpcom/components/nsIServiceProvider.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
|
||||
#ifndef __nsIServerProvider_h
|
||||
#define __nsIServerProvider_h
|
||||
#include "nsISupports.h"
|
||||
|
||||
typedef nsID nsSID;
|
||||
#define NSSIDREF const nsSID&
|
||||
|
||||
class nsIServiceProvider: public nsISupports {
|
||||
public:
|
||||
NS_IMETHOD QueryService(NSSIDREF aSID, NSIIDREF sIID, (void **) pService);
|
||||
};
|
||||
|
||||
#endif /* __nsIServerProvider_h */
|
||||
164
mozilla/xpcom/components/nsMacRepository.h
Normal file
164
mozilla/xpcom/components/nsMacRepository.h
Normal file
@@ -0,0 +1,164 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
#ifdef XP_MAC
|
||||
#ifdef MOZ_NGLAYOUT
|
||||
|
||||
#error "nsMacRepository.h became obsolete when the shared lib conversion was completed."
|
||||
|
||||
// The Mac NGLayout is not based on shared libraries yet.
|
||||
// All the DLLs are built as static libraries and we present them as
|
||||
// shared libraries by redefining PR_LoadLibrary(), PR_UnloadLibrary()
|
||||
// and PR_FindSymbol() below.
|
||||
//
|
||||
// If you add or remove shared libraries on other platforms, you must
|
||||
// - Add the library name to the defines below.
|
||||
// - Rename the "NSGetFactory" and "NSCanUnload" procs for the Mac:
|
||||
// just append the library name to the function name.
|
||||
// - Add the library and its procs to the static list below.
|
||||
|
||||
|
||||
typedef struct MacLibrary
|
||||
{
|
||||
char * name;
|
||||
nsFactoryProc factoryProc;
|
||||
nsCanUnloadProc unloadProc;
|
||||
} MacLibrary;
|
||||
|
||||
// library names
|
||||
#define WIDGET_DLL "WIDGET_DLL"
|
||||
#define GFXWIN_DLL "GFXWIN_DLL"
|
||||
#define VIEW_DLL "VIEW_DLL"
|
||||
#define WEB_DLL "WEB_DLL"
|
||||
#define PLUGIN_DLL "PLUGIN_DLL"
|
||||
#define PREF_DLL "PREF_DLL"
|
||||
#define PARSER_DLL "PARSER_DLL"
|
||||
#define DOM_DLL "DOM_DLL"
|
||||
#define LAYOUT_DLL "LAYOUT_DLL"
|
||||
#define NETLIB_DLL "NETLIB_DLL"
|
||||
#define EDITOR_DLL "EDITOR_DLL"
|
||||
|
||||
#ifdef IMPL_MAC_REPOSITORY
|
||||
|
||||
extern "C" nsresult NSGetFactory_WIDGET_DLL(nsISupports* serviceMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory);
|
||||
extern "C" nsresult NSGetFactory_GFXWIN_DLL(nsISupports* serviceMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory);
|
||||
extern "C" nsresult NSGetFactory_VIEW_DLL(nsISupports* serviceMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory);
|
||||
extern "C" nsresult NSGetFactory_WEB_DLL(nsISupports* serviceMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory);
|
||||
#if 0
|
||||
extern "C" nsresult NSGetFactory_PLUGIN_DLL(nsISupports* serviceMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory);
|
||||
#endif
|
||||
extern "C" nsresult NSGetFactory_PREF_DLL(nsISupports* serviceMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory);
|
||||
extern "C" nsresult NSGetFactory_PARSER_DLL(nsISupports* serviceMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory);
|
||||
extern "C" nsresult NSGetFactory_DOM_DLL(nsISupports* serviceMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory);
|
||||
extern "C" nsresult NSGetFactory_LAYOUT_DLL(nsISupports* serviceMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory);
|
||||
extern "C" nsresult NSGetFactory_NETLIB_DLL(nsISupports* serviceMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory);
|
||||
extern "C" nsresult NSGetFactory_EDITOR_DLL(nsISupports* serviceMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory);
|
||||
|
||||
extern "C" PRBool NSCanUnload_PREF_DLL(void);
|
||||
|
||||
// library list
|
||||
static MacLibrary libraries[] = {
|
||||
#if 0
|
||||
WIDGET_DLL, NSGetFactory_WIDGET_DLL, NULL,
|
||||
GFXWIN_DLL, NSGetFactory_GFXWIN_DLL, NULL,
|
||||
VIEW_DLL, NSGetFactory_VIEW_DLL, NULL,
|
||||
WEB_DLL, NSGetFactory_WEB_DLL, NULL,
|
||||
//PLUGIN_DLL, NSGetFactory_PLUGIN_DLL, NULL,
|
||||
PREF_DLL, NSGetFactory_PREF_DLL, NSCanUnload_PREF_DLL,
|
||||
PARSER_DLL, NSGetFactory_PARSER_DLL, NULL,
|
||||
DOM_DLL, NSGetFactory_DOM_DLL, NULL,
|
||||
LAYOUT_DLL, NSGetFactory_LAYOUT_DLL, NULL,
|
||||
NETLIB_DLL, NSGetFactory_NETLIB_DLL, NULL,
|
||||
//EDITOR_DLL, NSGetFactory_EDITOR_DLL, NULL, // FIX ME
|
||||
#endif
|
||||
NULL
|
||||
};
|
||||
|
||||
static void* FindMacSymbol(char* libName, const char *symbolName)
|
||||
{
|
||||
MacLibrary * macLib;
|
||||
|
||||
for (macLib = libraries; ; macLib ++)
|
||||
{
|
||||
if (macLib->name == NULL)
|
||||
return NULL;
|
||||
|
||||
if (PL_strcmp(macLib->name, libName) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (PL_strcmp(symbolName, "NSGetFactory") == 0) {
|
||||
return macLib->factoryProc;
|
||||
}
|
||||
else if (PL_strcmp(symbolName, "NSCanUnload") == 0) {
|
||||
return macLib->unloadProc;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define PR_LoadLibrary(libName) (PRLibrary *)libName
|
||||
#define PR_UnloadLibrary(lib) lib = NULL
|
||||
#define PR_FindSymbol(lib, symbolName) FindMacSymbol((char*)lib, symbolName)
|
||||
|
||||
#endif // IMPL_MAC_REPOSITORY
|
||||
|
||||
#endif // MOZ_NGLAYOUT
|
||||
#endif // XP_MAC
|
||||
1275
mozilla/xpcom/components/nsRegistry.cpp
Normal file
1275
mozilla/xpcom/components/nsRegistry.cpp
Normal file
File diff suppressed because it is too large
Load Diff
194
mozilla/xpcom/components/nsRepository.cpp
Normal file
194
mozilla/xpcom/components/nsRepository.cpp
Normal file
@@ -0,0 +1,194 @@
|
||||
/* -*- Mode: C++; tab-width: 8; 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 "nsIComponentManager.h"
|
||||
|
||||
nsresult
|
||||
nsComponentManager::Initialize(void)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManager::FindFactory(const nsCID &aClass,
|
||||
nsIFactory **aFactory)
|
||||
{
|
||||
nsIComponentManager* cm;
|
||||
nsresult rv = NS_GetGlobalComponentManager(&cm);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return cm->FindFactory(aClass, aFactory);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManager::ProgIDToCLSID(const char *aProgID,
|
||||
nsCID *aClass)
|
||||
{
|
||||
nsIComponentManager* cm;
|
||||
nsresult rv = NS_GetGlobalComponentManager(&cm);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return cm->ProgIDToCLSID(aProgID, aClass);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManager::CLSIDToProgID(nsCID *aClass,
|
||||
char* *aClassName,
|
||||
char* *aProgID)
|
||||
{
|
||||
nsIComponentManager* cm;
|
||||
nsresult rv = NS_GetGlobalComponentManager(&cm);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return cm->CLSIDToProgID(aClass, aClassName, aProgID);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManager::CreateInstance(const nsCID &aClass,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
nsIComponentManager* cm;
|
||||
nsresult rv = NS_GetGlobalComponentManager(&cm);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return cm->CreateInstance(aClass, aDelegate, aIID, aResult);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManager::CreateInstance(const char *aProgID,
|
||||
nsISupports *aDelegate,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
nsIComponentManager* cm;
|
||||
nsresult rv = NS_GetGlobalComponentManager(&cm);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return cm->CreateInstance(aProgID, aDelegate, aIID, aResult);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManager::RegisterFactory(const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory *aFactory,
|
||||
PRBool aReplace)
|
||||
{
|
||||
nsIComponentManager* cm;
|
||||
nsresult rv = NS_GetGlobalComponentManager(&cm);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return cm->RegisterFactory(aClass, aClassName, aProgID,
|
||||
aFactory, aReplace);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManager::RegisterComponent(const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
const char *aLibrary,
|
||||
PRBool aReplace,
|
||||
PRBool aPersist)
|
||||
{
|
||||
nsIComponentManager* cm;
|
||||
nsresult rv = NS_GetGlobalComponentManager(&cm);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return cm->RegisterComponent(aClass, aClassName, aProgID,
|
||||
aLibrary, aReplace, aPersist);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManager::UnregisterFactory(const nsCID &aClass,
|
||||
nsIFactory *aFactory)
|
||||
{
|
||||
nsIComponentManager* cm;
|
||||
nsresult rv = NS_GetGlobalComponentManager(&cm);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return cm->UnregisterFactory(aClass, aFactory);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManager::UnregisterFactory(const nsCID &aClass,
|
||||
const char *aLibrary)
|
||||
{
|
||||
nsIComponentManager* cm;
|
||||
nsresult rv = NS_GetGlobalComponentManager(&cm);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return cm->UnregisterFactory(aClass, aLibrary);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManager::UnregisterComponent(const nsCID &aClass,
|
||||
const char *aLibrary)
|
||||
{
|
||||
nsIComponentManager* cm;
|
||||
nsresult rv = NS_GetGlobalComponentManager(&cm);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return cm->UnregisterComponent(aClass, aLibrary);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManager::FreeLibraries(void)
|
||||
{
|
||||
nsIComponentManager* cm;
|
||||
nsresult rv = NS_GetGlobalComponentManager(&cm);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return cm->FreeLibraries();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManager::AutoRegister(nsIComponentManager::RegistrationTime when,
|
||||
const char* pathlist)
|
||||
{
|
||||
nsIComponentManager* cm;
|
||||
nsresult rv = NS_GetGlobalComponentManager(&cm);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return cm->AutoRegister(when, pathlist);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManager::AddToDefaultPathList(const char *pathlist)
|
||||
{
|
||||
nsIComponentManager* cm;
|
||||
nsresult rv = NS_GetGlobalComponentManager(&cm);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return cm->AddToDefaultPathList(pathlist);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManager::SyncComponentsInPathList(const char *pathlist)
|
||||
{
|
||||
nsIComponentManager* cm;
|
||||
nsresult rv = NS_GetGlobalComponentManager(&cm);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return cm->SyncComponentsInPathList(pathlist);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManager::SyncComponentsInDir(const char *path)
|
||||
{
|
||||
nsIComponentManager* cm;
|
||||
nsresult rv = NS_GetGlobalComponentManager(&cm);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return cm->SyncComponentsInDir(path);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsComponentManager::SyncComponentsInFile(const char *fullname)
|
||||
{
|
||||
nsIComponentManager* cm;
|
||||
nsresult rv = NS_GetGlobalComponentManager(&cm);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return cm->SyncComponentsInFile(fullname);
|
||||
}
|
||||
28
mozilla/xpcom/components/nsRepository.h
Normal file
28
mozilla/xpcom/components/nsRepository.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
|
||||
#ifndef __nsRespository_h
|
||||
#define __nsRespository_h
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
|
||||
// XXX nsRepository is obsolete! Use nsComponentManager now!
|
||||
|
||||
#define nsRepository nsComponentManager
|
||||
|
||||
#endif
|
||||
560
mozilla/xpcom/components/nsServiceManager.cpp
Normal file
560
mozilla/xpcom/components/nsServiceManager.cpp
Normal file
@@ -0,0 +1,560 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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 "nsIServiceManager.h"
|
||||
#include "nsVector.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "prcmon.h"
|
||||
#include "prthread.h" /* XXX: only used for the NSPR initialization hack (rick) */
|
||||
|
||||
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||
|
||||
class nsServiceEntry {
|
||||
public:
|
||||
|
||||
nsServiceEntry(const nsCID& cid, nsISupports* service);
|
||||
~nsServiceEntry();
|
||||
|
||||
nsresult AddListener(nsIShutdownListener* listener);
|
||||
nsresult RemoveListener(nsIShutdownListener* listener);
|
||||
nsresult NotifyListeners(void);
|
||||
|
||||
const nsCID& mClassID;
|
||||
nsISupports* mService;
|
||||
nsVector* mListeners; // nsVector<nsIShutdownListener>
|
||||
PRBool mShuttingDown;
|
||||
|
||||
};
|
||||
|
||||
nsServiceEntry::nsServiceEntry(const nsCID& cid, nsISupports* service)
|
||||
: mClassID(cid), mService(service), mListeners(NULL), mShuttingDown(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
nsServiceEntry::~nsServiceEntry()
|
||||
{
|
||||
if (mListeners) {
|
||||
NS_ASSERTION(mListeners->GetSize() == 0, "listeners not removed or notified");
|
||||
#if 0
|
||||
PRUint32 size = mListeners->GetSize();
|
||||
for (PRUint32 i = 0; i < size; i++) {
|
||||
nsIShutdownListener* listener = (nsIShutdownListener*)(*mListeners)[i];
|
||||
NS_RELEASE(listener);
|
||||
}
|
||||
#endif
|
||||
delete mListeners;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsServiceEntry::AddListener(nsIShutdownListener* listener)
|
||||
{
|
||||
if (listener == NULL)
|
||||
return NS_OK;
|
||||
if (mListeners == NULL) {
|
||||
mListeners = new nsVector();
|
||||
if (mListeners == NULL)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
PRInt32 rv = mListeners->Add(listener);
|
||||
NS_ADDREF(listener);
|
||||
return rv == -1 ? NS_ERROR_FAILURE : NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsServiceEntry::RemoveListener(nsIShutdownListener* listener)
|
||||
{
|
||||
if (listener == NULL)
|
||||
return NS_OK;
|
||||
NS_ASSERTION(mListeners, "no listeners added yet");
|
||||
PRUint32 size = mListeners->GetSize();
|
||||
for (PRUint32 i = 0; i < size; i++) {
|
||||
if ((*mListeners)[i] == listener) {
|
||||
mListeners->Remove(i);
|
||||
NS_RELEASE(listener);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
NS_ASSERTION(0, "unregistered shutdown listener");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsServiceEntry::NotifyListeners(void)
|
||||
{
|
||||
if (mListeners) {
|
||||
PRUint32 size = mListeners->GetSize();
|
||||
for (PRUint32 i = 0; i < size; i++) {
|
||||
nsIShutdownListener* listener = (nsIShutdownListener*)(*mListeners)[0];
|
||||
nsresult rv = listener->OnShutdown(mClassID, mService);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
NS_RELEASE(listener);
|
||||
mListeners->Remove(0);
|
||||
}
|
||||
NS_ASSERTION(mListeners->GetSize() == 0, "failed to notify all listeners");
|
||||
delete mListeners;
|
||||
mListeners = NULL;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsServiceManagerImpl : public nsIServiceManager {
|
||||
public:
|
||||
|
||||
NS_IMETHOD
|
||||
RegisterService(const nsCID& aClass, nsISupports* aService);
|
||||
|
||||
NS_IMETHOD
|
||||
UnregisterService(const nsCID& aClass);
|
||||
|
||||
NS_IMETHOD
|
||||
GetService(const nsCID& aClass, const nsIID& aIID,
|
||||
nsISupports* *result,
|
||||
nsIShutdownListener* shutdownListener = NULL);
|
||||
|
||||
NS_IMETHOD
|
||||
ReleaseService(const nsCID& aClass, nsISupports* service,
|
||||
nsIShutdownListener* shutdownListener = NULL);
|
||||
|
||||
NS_IMETHOD
|
||||
RegisterService(const char* aProgID, nsISupports* aService);
|
||||
|
||||
NS_IMETHOD
|
||||
UnregisterService(const char* aProgID);
|
||||
|
||||
NS_IMETHOD
|
||||
GetService(const char* aProgID, const nsIID& aIID,
|
||||
nsISupports* *result,
|
||||
nsIShutdownListener* shutdownListener = NULL);
|
||||
|
||||
NS_IMETHOD
|
||||
ReleaseService(const char* aProgID, nsISupports* service,
|
||||
nsIShutdownListener* shutdownListener = NULL);
|
||||
|
||||
nsServiceManagerImpl(void);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
protected:
|
||||
|
||||
virtual ~nsServiceManagerImpl(void);
|
||||
|
||||
nsHashtable/*<nsServiceEntry>*/* mServices;
|
||||
};
|
||||
|
||||
nsServiceManagerImpl::nsServiceManagerImpl(void)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mServices = new nsHashtable();
|
||||
NS_ASSERTION(mServices, "out of memory already?");
|
||||
}
|
||||
|
||||
static PRBool
|
||||
DeleteEntry(nsHashKey *aKey, void *aData, void* closure)
|
||||
{
|
||||
nsServiceEntry* entry = (nsServiceEntry*)aData;
|
||||
NS_RELEASE(entry->mService);
|
||||
delete entry;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsServiceManagerImpl::~nsServiceManagerImpl(void)
|
||||
{
|
||||
if (mServices) {
|
||||
mServices->Enumerate(DeleteEntry);
|
||||
delete mServices;
|
||||
}
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kIServiceManagerIID, NS_ISERVICEMANAGER_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
NS_IMPL_ADDREF(nsServiceManagerImpl);
|
||||
NS_IMPL_RELEASE(nsServiceManagerImpl);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsServiceManagerImpl::QueryInterface(const nsIID& aIID, void* *aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
*aInstancePtr = NULL;
|
||||
if (aIID.Equals(kIServiceManagerIID) ||
|
||||
aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*) this;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsServiceManagerImpl::GetService(const nsCID& aClass, const nsIID& aIID,
|
||||
nsISupports* *result,
|
||||
nsIShutdownListener* shutdownListener)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
/* XXX: This is a hack to force NSPR initialization.. This should be
|
||||
* removed once PR_CEnterMonitor(...) initializes NSPR... (rick)
|
||||
*/
|
||||
(void)PR_GetCurrentThread();
|
||||
PR_CEnterMonitor(this);
|
||||
|
||||
nsIDKey key(aClass);
|
||||
nsServiceEntry* entry = (nsServiceEntry*)mServices->Get(&key);
|
||||
|
||||
if (entry) {
|
||||
nsISupports* service;
|
||||
rv = entry->mService->QueryInterface(aIID, (void**)&service);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = entry->AddListener(shutdownListener);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
*result = service;
|
||||
|
||||
// If someone else requested the service to be shut down,
|
||||
// and we just asked to get it again before it could be
|
||||
// released, then cancel their shutdown request:
|
||||
if (entry->mShuttingDown) {
|
||||
entry->mShuttingDown = PR_FALSE;
|
||||
NS_ADDREF(service); // Released in UnregisterService
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
nsISupports* service;
|
||||
rv = nsComponentManager::CreateInstance(aClass, NULL, aIID, (void**)&service);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
entry = new nsServiceEntry(aClass, service);
|
||||
if (entry == NULL) {
|
||||
NS_RELEASE(service);
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
else {
|
||||
rv = entry->AddListener(shutdownListener);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mServices->Put(&key, entry);
|
||||
*result = service;
|
||||
NS_ADDREF(service); // Released in UnregisterService
|
||||
}
|
||||
else {
|
||||
NS_RELEASE(service);
|
||||
delete entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PR_CExitMonitor(this);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsServiceManagerImpl::ReleaseService(const nsCID& aClass, nsISupports* service,
|
||||
nsIShutdownListener* shutdownListener)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
PR_CEnterMonitor(this);
|
||||
|
||||
nsIDKey key(aClass);
|
||||
nsServiceEntry* entry = (nsServiceEntry*)mServices->Get(&key);
|
||||
|
||||
NS_ASSERTION(entry, "service not found");
|
||||
// NS_ASSERTION(entry->mService == service, "service looked failed");
|
||||
|
||||
if (entry) {
|
||||
rv = entry->RemoveListener(shutdownListener);
|
||||
nsrefcnt cnt;
|
||||
NS_RELEASE2(service, cnt);
|
||||
if (NS_SUCCEEDED(rv) && cnt == 0) {
|
||||
mServices->Remove(&key);
|
||||
delete entry;
|
||||
rv = nsComponentManager::FreeLibraries();
|
||||
}
|
||||
}
|
||||
|
||||
PR_CExitMonitor(this);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsServiceManagerImpl::RegisterService(const nsCID& aClass, nsISupports* aService)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
PR_CEnterMonitor(this);
|
||||
|
||||
nsIDKey key(aClass);
|
||||
nsServiceEntry* entry = (nsServiceEntry*)mServices->Get(&key);
|
||||
if (entry) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
else {
|
||||
nsServiceEntry* entry = new nsServiceEntry(aClass, aService);
|
||||
if (entry == NULL)
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
else {
|
||||
mServices->Put(&key, entry);
|
||||
NS_ADDREF(aService); // Released in UnregisterService
|
||||
}
|
||||
}
|
||||
PR_CExitMonitor(this);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsServiceManagerImpl::UnregisterService(const nsCID& aClass)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
PR_CEnterMonitor(this);
|
||||
|
||||
nsIDKey key(aClass);
|
||||
nsServiceEntry* entry = (nsServiceEntry*)mServices->Get(&key);
|
||||
|
||||
if (entry == NULL) {
|
||||
rv = NS_ERROR_SERVICE_NOT_FOUND;
|
||||
}
|
||||
else {
|
||||
rv = entry->NotifyListeners(); // break the cycles
|
||||
entry->mShuttingDown = PR_TRUE;
|
||||
nsrefcnt cnt;
|
||||
NS_RELEASE2(entry->mService, cnt); // AddRef in GetService
|
||||
if (NS_SUCCEEDED(rv) && cnt == 0) {
|
||||
mServices->Remove(&key);
|
||||
delete entry;
|
||||
rv = nsComponentManager::FreeLibraries();
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_SERVICE_IN_USE;
|
||||
}
|
||||
|
||||
PR_CExitMonitor(this);
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// let's do it again, this time with ProgIDs...
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsServiceManagerImpl::RegisterService(const char* aProgID, nsISupports* aService)
|
||||
{
|
||||
nsCID aClass;
|
||||
nsresult rv;
|
||||
rv = nsComponentManager::ProgIDToCLSID(aProgID, &aClass);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return RegisterService(aClass, aService);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsServiceManagerImpl::UnregisterService(const char* aProgID)
|
||||
{
|
||||
nsCID aClass;
|
||||
nsresult rv;
|
||||
rv = nsComponentManager::ProgIDToCLSID(aProgID, &aClass);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return UnregisterService(aClass);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsServiceManagerImpl::GetService(const char* aProgID, const nsIID& aIID,
|
||||
nsISupports* *result,
|
||||
nsIShutdownListener* shutdownListener)
|
||||
{
|
||||
nsCID aClass;
|
||||
nsresult rv;
|
||||
rv = nsComponentManager::ProgIDToCLSID(aProgID, &aClass);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return GetService(aClass, aIID, result, shutdownListener);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsServiceManagerImpl::ReleaseService(const char* aProgID, nsISupports* service,
|
||||
nsIShutdownListener* shutdownListener)
|
||||
{
|
||||
nsCID aClass;
|
||||
nsresult rv;
|
||||
rv = nsComponentManager::ProgIDToCLSID(aProgID, &aClass);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return ReleaseService(aClass, service, shutdownListener);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
NS_NewServiceManager(nsIServiceManager* *result)
|
||||
{
|
||||
nsServiceManagerImpl* servMgr = new nsServiceManagerImpl();
|
||||
if (servMgr == NULL)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(servMgr);
|
||||
*result = servMgr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Global service manager interface (see nsIServiceManager.h)
|
||||
|
||||
nsresult
|
||||
nsServiceManager::GetGlobalServiceManager(nsIServiceManager* *result)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (mGlobalServiceManager == NULL) {
|
||||
// XPCOM not initialized yet. Let us do initialization of our module.
|
||||
rv = NS_InitXPCOM(NULL);
|
||||
}
|
||||
// No ADDREF as we are advicing no release of this.
|
||||
if (NS_SUCCEEDED(rv)) *result = mGlobalServiceManager;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsServiceManager::ShutdownGlobalServiceManager(nsIServiceManager* *result)
|
||||
{
|
||||
if (mGlobalServiceManager != NULL) {
|
||||
NS_RELEASE(mGlobalServiceManager);
|
||||
mGlobalServiceManager = NULL;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsServiceManager::GetService(const nsCID& aClass, const nsIID& aIID,
|
||||
nsISupports* *result,
|
||||
nsIShutdownListener* shutdownListener)
|
||||
{
|
||||
nsIServiceManager* mgr;
|
||||
nsresult rv = GetGlobalServiceManager(&mgr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return mgr->GetService(aClass, aIID, result, shutdownListener);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsServiceManager::ReleaseService(const nsCID& aClass, nsISupports* service,
|
||||
nsIShutdownListener* shutdownListener)
|
||||
{
|
||||
nsIServiceManager* mgr;
|
||||
nsresult rv = GetGlobalServiceManager(&mgr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return mgr->ReleaseService(aClass, service, shutdownListener);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsServiceManager::RegisterService(const nsCID& aClass, nsISupports* aService)
|
||||
{
|
||||
nsIServiceManager* mgr;
|
||||
nsresult rv = GetGlobalServiceManager(&mgr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return mgr->RegisterService(aClass, aService);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsServiceManager::UnregisterService(const nsCID& aClass)
|
||||
{
|
||||
nsIServiceManager* mgr;
|
||||
nsresult rv = GetGlobalServiceManager(&mgr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return mgr->UnregisterService(aClass);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// XPCOM initialization
|
||||
//
|
||||
// To Control the order of initialization of these key components I am putting
|
||||
// this function.
|
||||
//
|
||||
// - nsServiceManager
|
||||
// - nsComponentManager
|
||||
// - nsRegistry
|
||||
//
|
||||
// Here are key points to remember:
|
||||
// - A global of all these need to exist. nsServiceManager is an independent object.
|
||||
// nsComponentManager uses both the globalServiceManager and its own registry.
|
||||
//
|
||||
// - A static object of both the nsComponentManager and nsServiceManager
|
||||
// are in use. Hence InitXPCOM() gets triggered from both
|
||||
// NS_GetGlobale{Service/Component}Manager() calls.
|
||||
//
|
||||
// - There exists no global Registry. Registry can be created from the component manager.
|
||||
//
|
||||
#include "nsComponentManager.h"
|
||||
#include "nsIRegistry.h"
|
||||
#include "nsXPComCIID.h"
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NS_RegistryGetFactory(nsISupports* servMgr, nsIFactory** aFactory);
|
||||
|
||||
nsIServiceManager* nsServiceManager::mGlobalServiceManager = NULL;
|
||||
nsComponentManagerImpl* nsComponentManagerImpl::gComponentManager = NULL;
|
||||
|
||||
nsresult NS_InitXPCOM(nsIServiceManager* *result)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// 1. Create the Global Service Manager
|
||||
nsIServiceManager* servMgr = NULL;
|
||||
if (nsServiceManager::mGlobalServiceManager == NULL)
|
||||
{
|
||||
rv = NS_NewServiceManager(&servMgr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsServiceManager::mGlobalServiceManager = servMgr;
|
||||
NS_ADDREF(servMgr);
|
||||
if (result && *result) *result = servMgr;
|
||||
}
|
||||
|
||||
// 2. Create the Component Manager and register with global service manager
|
||||
// It is understood that the component manager can use the global service manager.
|
||||
nsComponentManagerImpl *compMgr = NULL;
|
||||
if (nsComponentManagerImpl::gComponentManager == NULL)
|
||||
{
|
||||
compMgr = new nsComponentManagerImpl();
|
||||
if (compMgr == NULL)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(compMgr);
|
||||
nsresult rv = compMgr->Init();
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
NS_RELEASE(compMgr);
|
||||
return rv;
|
||||
}
|
||||
nsComponentManagerImpl::gComponentManager = compMgr;
|
||||
}
|
||||
|
||||
rv = servMgr->RegisterService(kComponentManagerCID, compMgr);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
// 3. Register the RegistryFactory with the component manager so that
|
||||
// clients can create new registry objects.
|
||||
nsIFactory *registryFactory = NULL;
|
||||
rv = NS_RegistryGetFactory(servMgr, ®istryFactory);
|
||||
if (NS_FAILED(rv)) return (rv);
|
||||
|
||||
NS_DEFINE_CID(kRegistryCID, NS_REGISTRY_CID);
|
||||
|
||||
rv = compMgr->RegisterFactory(kRegistryCID, NS_REGISTRY_CLASSNAME,
|
||||
NS_REGISTRY_PROGID, registryFactory,
|
||||
PR_TRUE);
|
||||
NS_RELEASE(registryFactory);
|
||||
|
||||
return (rv);
|
||||
}
|
||||
158
mozilla/xpcom/components/nsXPComFactory.h
Normal file
158
mozilla/xpcom/components/nsXPComFactory.h
Normal file
@@ -0,0 +1,158 @@
|
||||
/* -*- 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 "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.
|
||||
*/
|
||||
|
||||
#ifndef nsXPComFactory_h__
|
||||
#define nsXPComFactory_h__
|
||||
|
||||
#include "nsIFactory.h"
|
||||
|
||||
/*
|
||||
* This file contains a macro for the implementation of a simple XPCOM factory.
|
||||
*
|
||||
* To implement a factory for a given component, you need to declare the
|
||||
* factory class using the NS_DEF_FACTORY() macro.
|
||||
*
|
||||
* The first macro argument is the name for the factory.
|
||||
*
|
||||
* The second macro argument is a function (provided by you) which
|
||||
* can be called by your DLL's NSGetFactory(...) entry point.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* NS_DEF_FACTORY(SomeComponent,SomeComponentImpl)
|
||||
*
|
||||
* Declares:
|
||||
*
|
||||
* class nsSomeComponentFactory : public nsIFactory {};
|
||||
*
|
||||
* NOTE that the NS_DEF_FACTORY takes care of enforcing the "ns" prefix
|
||||
* and appending the "Factory" suffix to the given name.
|
||||
*
|
||||
* To use the new factory:
|
||||
*
|
||||
* nsresult NS_New_SomeComponent_Factory(nsIFactory** aResult)
|
||||
* {
|
||||
* nsresult rv = NS_OK;
|
||||
* nsIFactory* inst = new nsSomeComponentFactory;
|
||||
* if (NULL == inst) {
|
||||
* rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
* } else {
|
||||
* NS_ADDREF(inst);
|
||||
* }
|
||||
* *aResult = inst;
|
||||
* return rv;
|
||||
* }
|
||||
*
|
||||
* NOTE:
|
||||
* ----
|
||||
* The factories created by this macro are not thread-safe and do not
|
||||
* support aggregation.
|
||||
*
|
||||
*/
|
||||
#define NS_DEF_FACTORY(_name,_type) \
|
||||
class ns##_name##Factory : public nsIFactory \
|
||||
{ \
|
||||
public: \
|
||||
ns##_name##Factory() { NS_INIT_REFCNT(); } \
|
||||
\
|
||||
NS_IMETHOD_(nsrefcnt) AddRef (void) \
|
||||
{ \
|
||||
return ++mRefCnt; \
|
||||
} \
|
||||
\
|
||||
NS_IMETHOD_(nsrefcnt) Release(void) \
|
||||
{ \
|
||||
NS_PRECONDITION(0 != mRefCnt, "dup release"); \
|
||||
if (--mRefCnt == 0) { \
|
||||
NS_DELETEXPCOM(this); \
|
||||
return 0; \
|
||||
} \
|
||||
return mRefCnt; \
|
||||
} \
|
||||
\
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) \
|
||||
{ \
|
||||
if (NULL == aInstancePtr) { \
|
||||
return NS_ERROR_NULL_POINTER; \
|
||||
} \
|
||||
\
|
||||
*aInstancePtr = NULL; \
|
||||
\
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); \
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); \
|
||||
if (aIID.Equals(kIFactoryIID)) { \
|
||||
*aInstancePtr = (void*) this; \
|
||||
NS_ADDREF_THIS(); \
|
||||
return NS_OK; \
|
||||
} \
|
||||
if (aIID.Equals(kISupportsIID)) { \
|
||||
*aInstancePtr = (void*) ((nsISupports*)this); \
|
||||
NS_ADDREF_THIS(); \
|
||||
return NS_OK; \
|
||||
} \
|
||||
return NS_NOINTERFACE; \
|
||||
} \
|
||||
\
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter, \
|
||||
const nsIID &aIID, \
|
||||
void **aResult) \
|
||||
{ \
|
||||
nsresult rv; \
|
||||
\
|
||||
_type * inst; \
|
||||
\
|
||||
if (NULL == aResult) { \
|
||||
rv = NS_ERROR_NULL_POINTER; \
|
||||
goto done; \
|
||||
} \
|
||||
*aResult = NULL; \
|
||||
if (NULL != aOuter) { \
|
||||
rv = NS_ERROR_NO_AGGREGATION; \
|
||||
goto done; \
|
||||
} \
|
||||
\
|
||||
NS_NEWXPCOM(inst, _type); \
|
||||
if (NULL == inst) { \
|
||||
rv = NS_ERROR_OUT_OF_MEMORY; \
|
||||
goto done; \
|
||||
} \
|
||||
NS_ADDREF(inst); \
|
||||
rv = inst->QueryInterface(aIID, aResult); \
|
||||
NS_RELEASE(inst); \
|
||||
\
|
||||
done: \
|
||||
return rv; \
|
||||
} \
|
||||
\
|
||||
NS_IMETHOD LockFactory(PRBool aLock) \
|
||||
{ \
|
||||
return NS_OK; \
|
||||
} \
|
||||
\
|
||||
\
|
||||
protected: \
|
||||
virtual ~ns##_name##Factory() \
|
||||
{ \
|
||||
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction"); \
|
||||
} \
|
||||
\
|
||||
nsrefcnt mRefCnt; \
|
||||
};
|
||||
|
||||
#endif /* nsXPComFactory_h__ */
|
||||
171
mozilla/xpcom/components/xcDll.cpp
Normal file
171
mozilla/xpcom/components/xcDll.cpp
Normal file
@@ -0,0 +1,171 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
|
||||
/* nsDll
|
||||
*
|
||||
* Abstraction of a Dll. Stores modifiedTime and size for easy detection of
|
||||
* change in dll.
|
||||
*
|
||||
* dp Suresh <dp@netscape.com>
|
||||
*/
|
||||
|
||||
#include "xcDll.h"
|
||||
#include "plstr.h" // strdup and strfree
|
||||
|
||||
nsDll::nsDll(const char *libFullPath) : m_fullpath(NULL), m_instance(NULL),
|
||||
m_status(DLL_OK)
|
||||
{
|
||||
m_lastModTime = LL_ZERO;
|
||||
m_size = 0;
|
||||
|
||||
if (libFullPath == NULL)
|
||||
{
|
||||
m_status = DLL_INVALID_PARAM;
|
||||
return;
|
||||
}
|
||||
m_fullpath = PL_strdup(libFullPath);
|
||||
if (m_fullpath == NULL)
|
||||
{
|
||||
// No more memory
|
||||
m_status = DLL_NO_MEM;
|
||||
return;
|
||||
}
|
||||
|
||||
PRFileInfo statinfo;
|
||||
if (PR_GetFileInfo(m_fullpath, &statinfo) != PR_SUCCESS)
|
||||
{
|
||||
// The stat things works only if people pass in the full pathname.
|
||||
// Even if our stat fails, we could be able to load it because of
|
||||
// LD_LIBRARY_PATH and other such paths where dlls are searched for
|
||||
|
||||
// XXX we need a way of marking this occurance.
|
||||
// XXX m_status = DLL_STAT_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_size = statinfo.size;
|
||||
m_lastModTime = statinfo.modifyTime;
|
||||
if (statinfo.type != PR_FILE_FILE)
|
||||
{
|
||||
// Not a file. Cant work with it.
|
||||
m_status = DLL_NOT_FILE;
|
||||
return;
|
||||
}
|
||||
}
|
||||
m_status = DLL_OK;
|
||||
}
|
||||
|
||||
|
||||
nsDll::nsDll(const char *libFullPath, PRTime lastModTime, PRUint32 fileSize)
|
||||
: m_fullpath(NULL), m_instance(NULL), m_status(DLL_OK)
|
||||
{
|
||||
m_lastModTime = lastModTime;
|
||||
m_size = fileSize;
|
||||
|
||||
if (libFullPath == NULL)
|
||||
{
|
||||
m_status = DLL_INVALID_PARAM;
|
||||
return;
|
||||
}
|
||||
m_fullpath = PL_strdup(libFullPath);
|
||||
if (m_fullpath == NULL)
|
||||
{
|
||||
// No more memory
|
||||
m_status = DLL_NO_MEM;
|
||||
return;
|
||||
}
|
||||
|
||||
m_status = DLL_OK;
|
||||
}
|
||||
|
||||
nsDll::~nsDll(void)
|
||||
{
|
||||
if (m_instance != NULL)
|
||||
Unload();
|
||||
if (m_fullpath != NULL) PL_strfree(m_fullpath);
|
||||
m_fullpath = NULL;
|
||||
}
|
||||
|
||||
|
||||
PRBool nsDll::Load(void)
|
||||
{
|
||||
#ifdef XP_MAC
|
||||
char *macFileName = NULL;
|
||||
int loop;
|
||||
#endif
|
||||
|
||||
if (m_status != DLL_OK)
|
||||
{
|
||||
return (PR_FALSE);
|
||||
}
|
||||
if (m_instance != NULL)
|
||||
{
|
||||
// Already loaded
|
||||
return (PR_TRUE);
|
||||
}
|
||||
#ifdef XP_MAC
|
||||
// err = ConvertUnixPathToMacPath(m_fullpath, &macFileName);
|
||||
if ((macFileName = PL_strdup(m_fullpath)) != NULL)
|
||||
{
|
||||
if (macFileName[0] == '/')
|
||||
{
|
||||
for (loop=0; loop<PL_strlen(macFileName); loop++)
|
||||
{
|
||||
if (macFileName[loop] == '/') macFileName[loop] = ':';
|
||||
}
|
||||
m_instance = PR_LoadLibrary(&macFileName[1]); // skip over initial slash
|
||||
}
|
||||
else
|
||||
{
|
||||
m_instance = PR_LoadLibrary(macFileName);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
// This is the only right way of doing this...
|
||||
m_instance = PR_LoadLibrary(m_fullpath);
|
||||
#endif /* XP_MAC */
|
||||
return ((m_instance == NULL) ? PR_FALSE : PR_TRUE);
|
||||
|
||||
}
|
||||
|
||||
PRBool nsDll::Unload(void)
|
||||
{
|
||||
if (m_status != DLL_OK || m_instance == NULL)
|
||||
return (PR_FALSE);
|
||||
PRStatus ret = PR_UnloadLibrary(m_instance);
|
||||
if (ret == PR_SUCCESS)
|
||||
{
|
||||
m_instance = NULL;
|
||||
return (PR_TRUE);
|
||||
}
|
||||
else
|
||||
return (PR_FALSE);
|
||||
}
|
||||
|
||||
void * nsDll::FindSymbol(const char *symbol)
|
||||
{
|
||||
if (symbol == NULL)
|
||||
return (NULL);
|
||||
|
||||
// If not already loaded, load it now.
|
||||
if (Load() != PR_TRUE)
|
||||
return (NULL);
|
||||
|
||||
return (PR_FindSymbol(m_instance, symbol));
|
||||
}
|
||||
71
mozilla/xpcom/components/xcDll.h
Normal file
71
mozilla/xpcom/components/xcDll.h
Normal file
@@ -0,0 +1,71 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
|
||||
/* Dll
|
||||
*
|
||||
* Programmatic representation of a dll. Stores modifiedTime and size for
|
||||
* easy detection of change in dll.
|
||||
*
|
||||
* dp Suresh <dp@netscape.com>
|
||||
*/
|
||||
|
||||
#include "prio.h"
|
||||
#include "prlink.h"
|
||||
|
||||
typedef enum nsDllStatus
|
||||
{
|
||||
DLL_OK = 0,
|
||||
DLL_NO_MEM = 1,
|
||||
DLL_STAT_ERROR = 2,
|
||||
DLL_NOT_FILE = 3,
|
||||
DLL_INVALID_PARAM = 4
|
||||
} nsDllStatus;
|
||||
|
||||
class nsDll
|
||||
{
|
||||
private:
|
||||
char *m_fullpath; // system format full filename of dll
|
||||
PRTime m_lastModTime; // last modified time
|
||||
PRUint32 m_size; // size of the dynamic library
|
||||
PRLibrary *m_instance; // Load instance
|
||||
nsDllStatus m_status; // holds current status
|
||||
|
||||
public:
|
||||
|
||||
nsDll(const char *libFullPath);
|
||||
nsDll(const char *libFullPath, PRTime lastModTime, PRUint32 fileSize);
|
||||
|
||||
~nsDll(void);
|
||||
|
||||
// Status checking on operations completed
|
||||
nsDllStatus GetStatus(void) { return (m_status); }
|
||||
|
||||
// Dll Loading
|
||||
PRBool Load(void);
|
||||
PRBool Unload(void);
|
||||
PRBool IsLoaded(void)
|
||||
{
|
||||
return ((m_instance != 0) ? PR_TRUE : PR_FALSE);
|
||||
}
|
||||
void *FindSymbol(const char *symbol);
|
||||
|
||||
const char *GetFullPath(void) { return (m_fullpath); }
|
||||
PRTime GetLastModifiedTime(void) { return(m_lastModTime); }
|
||||
PRUint32 GetSize(void) { return(m_size); }
|
||||
PRLibrary *GetInstance(void) { return (m_instance); }
|
||||
};
|
||||
88
mozilla/xpcom/components/xcDllStore.cpp
Normal file
88
mozilla/xpcom/components/xcDllStore.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
|
||||
/* THIS FILE IS OBSOLETE */
|
||||
|
||||
/* nsDllStore
|
||||
*
|
||||
* Stores dll and their accociated info in a hash keyed on the system format
|
||||
* full dll path name e.g C:\Program Files\Netscape\Program\raptor.dll
|
||||
*
|
||||
* NOTE: dll names are considered to be case sensitive.
|
||||
*/
|
||||
|
||||
#include "xcDllStore.h"
|
||||
|
||||
static PR_CALLBACK PRIntn _deleteDllInfo(PLHashEntry *he, PRIntn i, void *arg)
|
||||
{
|
||||
delete (nsDll *)he->value;
|
||||
return (HT_ENUMERATE_NEXT);
|
||||
}
|
||||
|
||||
nsDllStore::nsDllStore(void) : m_dllHashTable(NULL)
|
||||
{
|
||||
PRUint32 initSize = 128;
|
||||
|
||||
m_dllHashTable = PL_NewHashTable(initSize, PL_HashString,
|
||||
PL_CompareStrings, PL_CompareValues, NULL, NULL);
|
||||
}
|
||||
|
||||
|
||||
nsDllStore::~nsDllStore(void)
|
||||
{
|
||||
if (m_dllHashTable)
|
||||
{
|
||||
// Delete each of the nsDll stored before deleting the Hash Table
|
||||
PL_HashTableEnumerateEntries(m_dllHashTable, _deleteDllInfo, NULL);
|
||||
PL_HashTableDestroy(m_dllHashTable);
|
||||
}
|
||||
m_dllHashTable = NULL;
|
||||
}
|
||||
|
||||
|
||||
nsDll* nsDllStore::Get(const char *dll)
|
||||
{
|
||||
nsDll *dllInfo = NULL;
|
||||
if (m_dllHashTable)
|
||||
{
|
||||
dllInfo = (nsDll *)PL_HashTableLookup(m_dllHashTable, dll);
|
||||
}
|
||||
return (dllInfo);
|
||||
}
|
||||
|
||||
|
||||
nsDll* nsDllStore::Remove(const char *dll)
|
||||
{
|
||||
if (m_dllHashTable == NULL)
|
||||
{
|
||||
return (NULL);
|
||||
}
|
||||
nsDll *dllInfo = Get(dll);
|
||||
PL_HashTableRemove(m_dllHashTable, dll);
|
||||
return (dllInfo);
|
||||
}
|
||||
|
||||
PRBool nsDllStore::Put(const char *dll, nsDll *dllInfo)
|
||||
{
|
||||
if (m_dllHashTable == NULL)
|
||||
return(PR_FALSE);
|
||||
|
||||
PLHashEntry *entry =
|
||||
PL_HashTableAdd(m_dllHashTable, (void *)dll, (void *)dllInfo);
|
||||
return ((entry != NULL) ? PR_TRUE : PR_FALSE);
|
||||
}
|
||||
49
mozilla/xpcom/components/xcDllStore.h
Normal file
49
mozilla/xpcom/components/xcDllStore.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
|
||||
|
||||
/* nsDllStore
|
||||
*
|
||||
* Stores dll and their accociated info in a hash keyed on the system format
|
||||
* full dll path name e.g C:\Program Files\Netscape\Program\raptor.dll
|
||||
*
|
||||
* NOTE: dll names are considered to be case sensitive.
|
||||
*/
|
||||
|
||||
#include "plhash.h"
|
||||
#include "xcDll.h"
|
||||
|
||||
class nsDllStore
|
||||
{
|
||||
private:
|
||||
PLHashTable *m_dllHashTable;
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
nsDllStore(void);
|
||||
~nsDllStore(void);
|
||||
|
||||
// Caller is not expected to delete nsDll returned
|
||||
// The nsDll returned in NOT removed from the hash
|
||||
nsDll* Get(const char *filename);
|
||||
PRBool Put(const char *filename, nsDll *dllInfo);
|
||||
|
||||
// The nsDll returned is removed from the hash
|
||||
// Caller is expected to delete the returned nsDll
|
||||
nsDll* Remove(const char *filename);
|
||||
};
|
||||
117
mozilla/xpcom/doc/ObjectModel.html
Normal file
117
mozilla/xpcom/doc/ObjectModel.html
Normal file
@@ -0,0 +1,117 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
|
||||
<META NAME="Author" CONTENT="Kipp E.B. Hickman">
|
||||
<META NAME="GENERATOR" CONTENT="Mozilla/4.04 [en] (WinNT; I) [Netscape]">
|
||||
<TITLE>Gemini Object Model</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
|
||||
<H1>
|
||||
Gemini Object Model</H1>
|
||||
The gemini object model is a cross platform component object model modelled
|
||||
after win32's IUnknown and COM. We do not support a C API to gemini at
|
||||
this time.
|
||||
<H2>
|
||||
nsID</H2>
|
||||
Like OSF's DCE, we use an "interface id" which is a unique identifer which
|
||||
names the interface. The nsID and be used as a key into a cross platform
|
||||
registry service to discover an implementation of an interface. Here is
|
||||
the declaration of nsID:
|
||||
<UL><TT>struct nsID {</TT>
|
||||
<BR><TT> PRUint32 m0;</TT>
|
||||
<BR><TT> PRUint16 m1, m2;</TT>
|
||||
<BR><TT> PRUint8 m3[8];</TT>
|
||||
|
||||
<P><TT> inline nsbool Equals(const nsID& other) const {</TT>
|
||||
<BR><TT> return</TT>
|
||||
<BR><TT> (((PRUint32*) &m0)[0] == ((PRUint32*)
|
||||
&other.m0)[0]) &&</TT>
|
||||
<BR><TT> (((PRUint32*) &m0)[1] == ((PRUint32*)
|
||||
&other.m0)[1]) &&</TT>
|
||||
<BR><TT> (((PRUint32*) &m0)[2] == ((PRUint32*)
|
||||
&other.m0)[2]) &&</TT>
|
||||
<BR><TT> (((PRUint32*) &m0)[3] == ((PRUint32*)
|
||||
&other.m0)[3]);</TT>
|
||||
<BR><TT> }</TT>
|
||||
<BR><TT>};</TT></UL>
|
||||
On windows, the "uuidgen" program (provided with Visual C++) can be used
|
||||
to generate these identifiers.
|
||||
<H2>
|
||||
nsISupports</H2>
|
||||
This is the base class for all component objects. Not all objects are component
|
||||
objects; these rules apply to objects which expose an interface which is
|
||||
shared across dll/exe boundaries. Here is nsISupports:
|
||||
<UL><TT>typedef nsID nsIID;</TT>
|
||||
<BR><TT>class nsISupports {</TT>
|
||||
<BR><TT>public:</TT>
|
||||
<BR><TT> virtual nsqresult QueryInterface(const nsIID& aIID,</TT>
|
||||
<BR><TT>
|
||||
void** aInstancePtr) = 0;</TT>
|
||||
<BR><TT> virtual nsrefcnt AddRef() = 0;</TT>
|
||||
<BR><TT> virtual nsrefcnt Release() = 0;</TT>
|
||||
<BR><TT>};</TT></UL>
|
||||
The semantics of this interface are identical to win32's "COM" IUnknown
|
||||
interface. In addition, the types are carefully mapped and the names are
|
||||
the same so that if necessary we can "flip a switch" and have the windows
|
||||
version (or any other platform that embraces COM) use the native COM IUnknown
|
||||
without source code modification.
|
||||
<H2>
|
||||
Factory Procedures</H2>
|
||||
Factory procedures use this design pattern
|
||||
<UL><TT>nsqresult NS_NewFoo(nsIFoo** aInstancePtr, nsISupports* aOuter,
|
||||
...);</TT></UL>
|
||||
The return value is a status value (see nsISupports.h for the legal return
|
||||
values); the first argument is a pointer to a cell which will hold the
|
||||
new instance pointer if the factory procedure succeeds. The second argument
|
||||
is a pointer to a containing component object that wishes to aggregate
|
||||
in the Foo object. This pointer will be null if no aggregation is requested.
|
||||
If the factory procedure cannot support aggregation of the Foo type then
|
||||
it fails and returns an error if aggregation is requested.
|
||||
|
||||
<P>The following symbols are defined for standard error return values from
|
||||
<TT>QueryInterface</TT> and from factory procedures:
|
||||
<UL><TT>#define NS_FAILED(_nsresult) ((_nsresult) < 0)</TT>
|
||||
<BR><TT>#define NS_SUCCEEDED(_nsresult) ((_nsresult) >= 0)</TT>
|
||||
|
||||
<P><TT>// Standard "it worked" return value</TT>
|
||||
<BR><TT>#define NS_OK 0</TT>
|
||||
|
||||
<P><TT>// Some standard error codes we use</TT>
|
||||
<BR><TT>#define NS_ERROR_BASE ((nsresult) 0xC1F30000)</TT>
|
||||
<BR><TT>#define NS_ERROR_OUT_OF_MEMORY (NS_ERROR_BASE + 0)</TT>
|
||||
<BR><TT>#define NS_ERROR_NO_AGGREGATION (NS_ERROR_BASE + 1)</TT>
|
||||
<BR><TT>#define NS_NOINTERFACE ((nqresult) 0x80004002L)</TT></UL>
|
||||
|
||||
<H2>
|
||||
nsIFactory</H2>
|
||||
Factory classes should eventually replace factory procedures for major
|
||||
classes. They provide an easy mechanism for placing code in DLLs. The nsIFactory
|
||||
class is as follows:
|
||||
<BR>
|
||||
<UL><TT>class nsIFactory: public nsISupports {</TT>
|
||||
<BR><TT>public:</TT>
|
||||
<UL><TT>virtual nsresult CreateInstance(const nsIID &aIID,</TT>
|
||||
<BR><TT>
|
||||
nsISupports *aOuter,</TT>
|
||||
<BR><TT>
|
||||
void **aResult) = 0;</TT>
|
||||
<BR><TT>virtual void LockFactory(PRBool aLock) = 0;</TT></UL>
|
||||
<TT>};</TT></UL>
|
||||
This interface is again identical to the COM version. More on registering
|
||||
factories shortly.
|
||||
<H2>
|
||||
Error Handling</H2>
|
||||
Because no exceptions are returned, error handling is done in the traditional
|
||||
"error status value" method.
|
||||
<H2>
|
||||
Cross Platform Registry</H2>
|
||||
A cross platform registry was written for the SmartUpdate feature of Communicator.
|
||||
We will investigate it's usefulness for our purposes.
|
||||
<H2>
|
||||
Library Management</H2>
|
||||
NSPR 2.x provides the cross platform mechanism for loading and unloading
|
||||
libraries, and run time linking.
|
||||
<BR>
|
||||
</BODY>
|
||||
</HTML>
|
||||
169
mozilla/xpcom/doc/TODO.html
Normal file
169
mozilla/xpcom/doc/TODO.html
Normal file
@@ -0,0 +1,169 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.51 [en] (X11; U; Linux 2.0.36 i686) [Netscape]">
|
||||
<meta name="Author" content="Suresh Duddi">
|
||||
<title>TODO List for XPCOM</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
TODO List for XPCOM</h1></center>
|
||||
|
||||
<center>Last updated: 25 March 1999
|
||||
<br><a href="mailto:dp@netscape.com">Suresh Duddi</a></center>
|
||||
|
||||
<table BORDER WIDTH="100%" NOSAVE >
|
||||
<tr NOSAVE>
|
||||
<th NOSAVE>Task</th>
|
||||
|
||||
<th NOSAVE><a href="http://bugzilla.mozilla.org/bug_status.html#priority">Priority</a></th>
|
||||
|
||||
<th NOSAVE>Owner</th>
|
||||
|
||||
<th NOSAVE>MileStone complete/Status</th>
|
||||
</tr>
|
||||
|
||||
<tr NOSAVE>
|
||||
<td NOSAVE>Move xpcom from using NR_*() functions (modules/libreg) to nsIRegistry
|
||||
(xpcom/src/nsRegistry.cpp)
|
||||
<ul>
|
||||
<li>
|
||||
Mainly you want to change all the Platform*() functions in nsComponentManager.cpp</li>
|
||||
|
||||
<li>
|
||||
Now we open/close the registry all the time. I want to keep the registry
|
||||
open all the time. That would get performance up.</li>
|
||||
|
||||
<li>
|
||||
Platform*() functions use the NR_*Raw() functions in some places. I wonder
|
||||
if the nsRegistry has a equivalent. If not we need to create them.</li>
|
||||
</ul>
|
||||
Mostly, there is equivalence between NR_*() calls and nsRegistry calls. </td>
|
||||
|
||||
<td>P2</td>
|
||||
|
||||
<td>Nick Ambrose <<a href="mailto:nicka87@hotmail.com">nicka87@hotmail.com</a>></td>
|
||||
|
||||
<td>3/22/1999 started
|
||||
<br>3/27/1999 Patch submitted
|
||||
<br>4/1/1999 Espected date of landing</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Startup components: Some components need to be created at startup.
|
||||
Have a framework for them.</td>
|
||||
|
||||
<td>P1</td>
|
||||
|
||||
<td></td>
|
||||
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>nsIRegistry access via Javascript.</td>
|
||||
|
||||
<td>P1</td>
|
||||
|
||||
<td></td>
|
||||
|
||||
<td>IDL of nsIRegistry will fix this says <a href="mailto:jband@netscape.com">John
|
||||
Bandhauer</a></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>API changes: Remove all pathlist. XPCOM should support only paths.</td>
|
||||
|
||||
<td>P1</td>
|
||||
|
||||
<td></td>
|
||||
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Fix xpcom from being initialized before main from static variables.</td>
|
||||
|
||||
<td>P1</td>
|
||||
|
||||
<td><a href="mailto:dp@netscape.com">Suresh Duddi</a></td>
|
||||
|
||||
<td>3/22/1999 Started.
|
||||
<br>- checked in a fixed xpcom initialization sequence.
|
||||
<br>- Now got to fix all code statically calling it. I know Netlib does.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Path handling: Use nsFileSpec instead of file path names. Char * pathnames
|
||||
are not intl, and cannot be stored in the registry. Plus that wont support
|
||||
mac aliases.
|
||||
<ul>
|
||||
<li>
|
||||
Possibly move autoreg out of xpcom</li>
|
||||
</ul>
|
||||
</td>
|
||||
|
||||
<td>P1</td>
|
||||
|
||||
<td><a href="mailto:dp@netscape.com">Suresh Duddi</a>
|
||||
<br><a href="mailto:rjc@netscape.com">Robert Churchill</a></td>
|
||||
|
||||
<td>3/24/1999 started</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Registry dump utility (regExport exists on windows) and about:registry
|
||||
(or) better yet an rdf data source for the registry.</td>
|
||||
|
||||
<td>P3</td>
|
||||
|
||||
<td></td>
|
||||
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Replace use of nsVector (PL_Vector) with nsISupportsArray</td>
|
||||
|
||||
<td>P3</td>
|
||||
|
||||
<td><a href="mailto:warren"></a></td>
|
||||
|
||||
<td></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>PATH argument to NSRegisterSelf() and NSUnregisterSelf() to be
|
||||
a nsISupports</td>
|
||||
|
||||
<td>P1</td>
|
||||
|
||||
<td></td>
|
||||
|
||||
<td></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<h2>
|
||||
Documentation on XPCOM</h2>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<a href="TODO.html">TODO List</a> <<i>this page></i></li>
|
||||
|
||||
<li>
|
||||
XPCOM main page : <a href="http://www.mozilla.org/projects/xpcom">http://www.mozilla.org/projects/xpcom</a></li>
|
||||
|
||||
<li>
|
||||
<a href="xpcom-code-faq.html">Code FAQ</a></li>
|
||||
|
||||
<li>
|
||||
<a href="xpcom-component-registration.html">Component Registration</a></li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%">
|
||||
</body>
|
||||
</html>
|
||||
93
mozilla/xpcom/doc/c++tips.html
Normal file
93
mozilla/xpcom/doc/c++tips.html
Normal file
@@ -0,0 +1,93 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
|
||||
<META NAME="Author" CONTENT="Kipp E.B. Hickman">
|
||||
<META NAME="GENERATOR" CONTENT="Mozilla/4.04 [en] (WinNT; U) [Netscape]">
|
||||
<TITLE>C++ Tips</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
|
||||
<H1>
|
||||
C++ Tips</H1>
|
||||
This is a compilation of tips on how to write cross-platform C++ code that
|
||||
compiles everywhere.
|
||||
<H2>
|
||||
General</H2>
|
||||
|
||||
<UL>
|
||||
<LI>
|
||||
Always use the nspr types for intrinsic integer types. The only exception
|
||||
to this rule is when writing machine dependent code that is called from
|
||||
xp code. In this case you will probably need to bridge the type systems
|
||||
and cast from an nspr type to a native type. The other exception is floating
|
||||
point; nspr defines PRFloat as a double (!).</LI>
|
||||
|
||||
<LI>
|
||||
Exceptions do not work everywhere so don't use them anywhere except in
|
||||
machine specific code, and then if you do use them in machine specific
|
||||
code you must catch all exceptions there because you can't throw the exception
|
||||
across xp code.</LI>
|
||||
|
||||
<LI>
|
||||
Templates do not work everywhere so don't use them anywhere.</LI>
|
||||
|
||||
<LI>
|
||||
Do not wrap include statements with an #ifdef. The reason is that when
|
||||
the symbol is not defined, other compiler symbols will not be defined and
|
||||
it will be hard to test the code on all platforms. An example of what <B>not</B>
|
||||
to do:</LI>
|
||||
|
||||
<BR>
|
||||
<UL><TT>#ifdef X</TT>
|
||||
<BR><TT>#include "foo.h"</TT>
|
||||
<BR><TT>#endif</TT>
|
||||
<BR><TT></TT> </UL>
|
||||
|
||||
<LI>
|
||||
For types that do not need operator= or a copy constructor, declare them
|
||||
yourselves and make them private. Example:</LI>
|
||||
|
||||
<BR>
|
||||
<UL><TT>class foo {</TT>
|
||||
<BR><TT>...</TT>
|
||||
<BR><TT>private:</TT>
|
||||
<BR><TT> // These are not supported and are not implemented!</TT>
|
||||
<BR><TT> foo(const foo& x);</TT>
|
||||
<BR><TT> foo& operator=(const foo& x);</TT>
|
||||
<BR><TT>};</TT></UL>
|
||||
|
||||
<LI>
|
||||
</LI>
|
||||
</UL>
|
||||
|
||||
<H2>
|
||||
Windows Compatability</H2>
|
||||
|
||||
<H2>
|
||||
Metroworks Compatability</H2>
|
||||
|
||||
<UL>
|
||||
<LI>
|
||||
MAC compilers do not handle #include path names in the same manner as other
|
||||
systems. Consequently #include statements should not contain path names,
|
||||
just simple file names. An example of what <B>not</B> to do:</LI>
|
||||
|
||||
<BR>
|
||||
<UL>#include "gemini/nsICSSParser.h"
|
||||
<BR> </UL>
|
||||
|
||||
<LI>
|
||||
</LI>
|
||||
</UL>
|
||||
|
||||
<H2>
|
||||
G++ Compatability</H2>
|
||||
|
||||
<UL>
|
||||
<LI>
|
||||
Use void in argument lists for functions that have no arguments (this works
|
||||
around a bug in g++ 2.6.3)</LI>
|
||||
</UL>
|
||||
|
||||
</BODY>
|
||||
</HTML>
|
||||
214
mozilla/xpcom/doc/xpcom-code-faq.html
Normal file
214
mozilla/xpcom/doc/xpcom-code-faq.html
Normal file
@@ -0,0 +1,214 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="GENERATOR" content="Mozilla/4.51 [en] (WinNT; U) [Netscape]">
|
||||
<meta name="Author" content="Suresh Duddi">
|
||||
<title>XPCOM Code FAQ</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h2>
|
||||
XPCOM Code FAQ</h2>
|
||||
Suresh Duddi <<a href="mailto:dp@netscape.com">dp@netscape.com</a>>
|
||||
<br>Last Modified: March 22 1999
|
||||
<br>
|
||||
<hr WIDTH="100%">
|
||||
<br>I am documenting things randomly as I am replying to people's questions.
|
||||
So this might look more like an FAQ.
|
||||
<h4>
|
||||
What are the Global Objects that XPCOM maintains</h4>
|
||||
|
||||
<ul>mGlobalServiceManager
|
||||
<br>mGlobalComponentManager</ul>
|
||||
|
||||
<h4>
|
||||
What are the static classes that XPCOM maintains</h4>
|
||||
|
||||
<blockquote>nsComponentManager
|
||||
<br>nsServiceManager</blockquote>
|
||||
|
||||
<h4>
|
||||
Is there any restriction on which static class I should call first</h4>
|
||||
|
||||
<blockquote>No restrictions. You can call any function from the static
|
||||
classes nsComponentManager and nsServiceManager. XPCOM will do the right
|
||||
thing to initialize itself at both places.
|
||||
<p>Autoregistration() can happen only after Init_XPCOM() is called since
|
||||
the registy might be required by SelfRegister() functions of the dlls and
|
||||
it is only in Init_XPCOM() do we create register the RegistryFactory()
|
||||
with the ComponentManager.</blockquote>
|
||||
|
||||
<h4>
|
||||
What is the order of creation of the ServiceManager, ComponentManager and
|
||||
Registry</h4>
|
||||
|
||||
<blockquote>Init_XPCOM()
|
||||
<blockquote>
|
||||
<li>
|
||||
create the global component manager</li>
|
||||
|
||||
<li>
|
||||
create the global component manager and register as service with the global
|
||||
service manager</li>
|
||||
|
||||
<li>
|
||||
RegisterFactory(...RegistryFactory...) Register the RegistryFactory()
|
||||
with the component manager so that new registry objects can be created.</li>
|
||||
</blockquote>
|
||||
Now the hard problem is when to trigger Init_XPCOM() There are two static
|
||||
objects nsComponentManager and nsServiceManager. Any function in either
|
||||
of them can be called first. Today nsServiceManager::GetService() is the
|
||||
first one that gets called. All the members of the static nsServiceManager
|
||||
use the nsGetGlobalServiceManager() to get to the global service manager.
|
||||
All members of the static nsComponentManager use the nsGetGlobalComponentManager()
|
||||
to get to the global component manager. Hence if we trigger Init_XPCOM()
|
||||
from both NS_GetGlobalComponentManager() and NS_GetGlobalServiceManager()
|
||||
we will be safe.</blockquote>
|
||||
|
||||
<h4>
|
||||
Is there a global Registry being maintained</h4>
|
||||
|
||||
<blockquote>No. The nsIRegistry is designed to be lightweight access to
|
||||
the registry. Consumers who need to access the registry should use the
|
||||
component manager to create the their own registry access object. This
|
||||
is required because the open() call is supported by the nsIRegistry() and
|
||||
if we maintain a global registry arbitrating which registry file is opened
|
||||
is going to be a major headach.
|
||||
<p>The ProgID for the registry will be <font color="#990000">component://netscape/registry</font>
|
||||
<br> </blockquote>
|
||||
|
||||
<h4>
|
||||
<font color="#000000">ComponentManager Vs ServiceManager</font></h4>
|
||||
|
||||
<blockquote><font color="#000000">ComponentManager is the only way for
|
||||
component creation. ComponentManager always uses the component's factory
|
||||
to create the component instance. Clients (code that calls CreateInstance()
|
||||
to create and use a component) call the ComponentManager to create instances.
|
||||
Components (the code that implemented NSRegisterSelf()) calls the ComponentManager
|
||||
to register itself and gets called when a Client wants to instantiate a
|
||||
component.</font>
|
||||
<p><font color="#000000">ServiceManager is a convinience for getting singleton
|
||||
components, components for which only one instance stays alive for the
|
||||
entire application e.g Netlib. It enforces only one of a kind of a component
|
||||
to exist. Hence the notion of getting a service not creating one. (as opposed
|
||||
to the notion of Creating instances with the componentManager). ServiceManager
|
||||
is a convenience because components can technically force singletonism
|
||||
by making their factory return the same instance if one was created already.
|
||||
The other big use of ServiceManager is the (still unimplemented) notion
|
||||
of Shutting down a service.</font>
|
||||
<p><b><i><font color="#000000">Client</font></i></b>
|
||||
<ul>
|
||||
<li>
|
||||
<i><font color="#000000">When does a client use the service manager vs
|
||||
component manager</font></i></li>
|
||||
|
||||
<p><br><font color="#000000">When a client knows that the component that
|
||||
they are trying to instantiate is a singleton, they need to call service
|
||||
manager instead of component manager. Clients dont have to worry about
|
||||
calling the ComponentManager at all in this case. The ServiceManager will
|
||||
take care of creating the instance if the first one doesn't exist already.</font>
|
||||
<br><font color="#000000">-</font>
|
||||
<li>
|
||||
<i><font color="#000000">When does a client use the Component Manager as
|
||||
opposed to Service Manager</font></i></li>
|
||||
|
||||
<p><br><font color="#000000">When a client wants a private instance of
|
||||
a component, they call the Component Manager. From the Clients point of
|
||||
view, a new xpcom object creation happens everytime they call CreateInstance()
|
||||
Anything else is an implementation detail that the Client need not worry
|
||||
about.</font>
|
||||
<br><font color="#000000">-</font>
|
||||
<li>
|
||||
<i><font color="#000000">How does a Client know that they have to instantiate
|
||||
a singleton</font></i></li>
|
||||
|
||||
<p><br><font color="#000000">For now, the Client just has to know. There
|
||||
is no way of telling which component is a Service and which isn't. In fact,
|
||||
in todays xpcom (Mar 1999) any component can be accessed as a Service.
|
||||
Use your judgement until there is a proper method or service manager is
|
||||
eliminated. There is nothing even in the code that detects Services from
|
||||
Instances.</font>
|
||||
<p><b><font color="#CC0000">Need a solution for this. Email suggestion
|
||||
to <a href="mailto:warren@netscape.com,dp@netscape.com">warren@netscape.com,
|
||||
dp@netscape.com</a></font></b>
|
||||
<br><font color="#000000">-</font></ul>
|
||||
<b><i><font color="#000000">Component</font></i></b>
|
||||
<ul>
|
||||
<li>
|
||||
<i><font color="#000000">Can a component enforce use only as a Service</font></i></li>
|
||||
|
||||
<p><br><font color="#000000">No. The notion of the ServiceManager is available
|
||||
only to Clients.</font>
|
||||
<p><font color="#000000">Note that at some points when a component wants
|
||||
another component, it actually behaves as a client and hence follows the
|
||||
rules of the Client above to either CreateInstance() or GetService() the
|
||||
needed component.</font>
|
||||
<p><b><tt><font color="#990000">Workaround:</font></tt></b><font color="#000000">
|
||||
If however a component wants only one of its instances to exist and cannot
|
||||
ensure that Clients understand well enough only to use the Service Manager
|
||||
to get it, it can implement singletonism in its factory. Basically the
|
||||
factory on first instance creation should hang on to the instance. On subsequence
|
||||
instance creations, addref the instance it is holding to and return that
|
||||
instead creating a new one.</font>
|
||||
<ul>
|
||||
<br><font color="#000000">E.g preferences does this.</font> Code sample
|
||||
at
|
||||
<a href="http://lxr.mozilla.org/seamonkey/source/modules/libpref/src/nsPref.cpp#621">nsPref.cpp
|
||||
nsPrefFactory::CreateInstance()</a> and <a href="http://lxr.mozilla.org/seamonkey/source/modules/libpref/src/nsPref.cpp#227">nsPref.cpp
|
||||
nsPref::GetInstance()</a> With this implementation, whether Clients get
|
||||
to it by calling nsIServiceManager::GetService() or nsIComponentManager::CreateInstance(),
|
||||
the same object will be returned hence guaranteeing singletonism.</ul>
|
||||
<font color="#000000">-</font>
|
||||
<li>
|
||||
<i><font color="#000000">Should a component do anything at creation to
|
||||
become a Service</font></i></li>
|
||||
|
||||
<p><br><font color="#000000">No. Again, the notion of a ServiceManager
|
||||
is available only to Clients.</font>
|
||||
<br><font color="#000000">-</font>
|
||||
<li>
|
||||
<i><font color="#000000">Can a component advertise that it is a service
|
||||
so clients can use it as one</font></i></li>
|
||||
|
||||
<p><br>No. There isn't a way other than a comment in the interface of the
|
||||
header file.</ul>
|
||||
</blockquote>
|
||||
|
||||
<h4>
|
||||
ProgID Vs CLSID</h4>
|
||||
|
||||
<blockquote>ClassID or CLSID is the unique indentification of a component.
|
||||
It is a structure of huge numbers generated by using uuidgen on a windows
|
||||
box. It is represented as a string in documentation as {108d75a0-bab5-11d2-96c4-0060b0fb9956}
|
||||
<p>ProgID is the string identification of an implementation of a component
|
||||
the client is looking for. The representation takes a URI syntax. Eg. component://netscape/network/protocol&name=http
|
||||
Some simplify this to, ProgID is a more readable string form of a CLSID.
|
||||
That is acceptable on the periphery. The ProgID is a Client thing. Components
|
||||
register with component manager to claim that they are the implementation
|
||||
for a ProgID. A component can register to be the implementation for multiple
|
||||
ProgIDs (not implemented yet).
|
||||
<p><b><i>Client</i></b>
|
||||
<ul>
|
||||
<li>
|
||||
<i>Should CreateInstance() calls use ProgID or CLSID<br>
|
||||
<br>
|
||||
</i>ProgID is what Clients should use to CreateInstances. Clients should
|
||||
not even know about the CLSID unless they are hell bent on creating a particular
|
||||
implementation of a component.<br>
|
||||
-</li>
|
||||
</ul>
|
||||
<b><i>Component</i></b>
|
||||
<ul>
|
||||
<li>
|
||||
<i>Should Components register with both a CID and ProgID<br>
|
||||
<br>
|
||||
</i>Absolutely.</li>
|
||||
</ul>
|
||||
|
||||
<br>
|
||||
<br> </blockquote>
|
||||
|
||||
<hr WIDTH="100%">
|
||||
</body>
|
||||
</html>
|
||||
354
mozilla/xpcom/doc/xpcom-component-registration.html
Normal file
354
mozilla/xpcom/doc/xpcom-component-registration.html
Normal file
@@ -0,0 +1,354 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Suresh Duddi">
|
||||
<meta name="GENERATOR" content="Mozilla/4.51 [en] (X11; U; Linux 2.0.36 i686) [Netscape]">
|
||||
<title>XPCOM Dynamic Component Registration</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<center>
|
||||
<h2>
|
||||
XPCOM Dynamic Component Registration</h2></center>
|
||||
|
||||
<center>Suresh Duddi <<a href="mailto:dp@netscape.com">dp@netscape.com</a>>
|
||||
<hr WIDTH="100%"></center>
|
||||
|
||||
<p>Dynamic object registration in XPCOM is achieved by interaction of the
|
||||
following components:
|
||||
<ul>
|
||||
<li>
|
||||
The Registry</li>
|
||||
|
||||
<li>
|
||||
The Repository</li>
|
||||
|
||||
<li>
|
||||
The Service Manager</li>
|
||||
|
||||
<li>
|
||||
Component dll implementing <tt>NSRegisterSelf()</tt></li>
|
||||
</ul>
|
||||
The registration mechanism for XPCOM components is similar in many ways
|
||||
to that of COM. The XPCOM component dlls will have the opportunity to register
|
||||
themselves with the registry. The exact time of installation would be either
|
||||
at install time or as a result of <b>autodetection</b> by the Repository
|
||||
Manager at runtime.
|
||||
<br>
|
||||
<h3>
|
||||
<a NAME="The Registry: XPCOM Hierarchy"></a>The Registry: XPCOM Hierarchy</h3>
|
||||
XPCOM uses the nsRegistry to store mappings between CLSIDs and their implementations.
|
||||
The Registry provides persistent storage of hierarchical keys and name-value
|
||||
pairs associated with each key. Each key also keeps a default value.
|
||||
<p>XPCOM will use the following registry hierarchy:
|
||||
<blockquote><tt>ROOTKEY_COMMON</tt>
|
||||
<br><tt> Common - Classes - CLSID</tt>
|
||||
<br><tt> <b><font color="#CC0000">{108d75a0-bab5-11d2-96c4-0060b0fb9956}</font></b></tt>
|
||||
<br><tt>
|
||||
InprocServer (S) = <font color="#CC0000">libnfs-protocol.so</font></tt>
|
||||
<br><tt>
|
||||
ProgID (S) = <b><font color="#CC0000">component://netscape/network-protocol&type=nfs</font></b></tt>
|
||||
<br><tt>
|
||||
ClassName (S) = <b><font color="#CC0000">NFS Protocol
|
||||
Handler</font></b></tt>
|
||||
<p><tt> <font color="#CC0000">component://netscape/network-protocol&type=nfs</font></tt>
|
||||
<br><tt>
|
||||
CLSID (S) = <font color="#CC0000">{108d75a0-bab5-11d2-96c4-0060b0fb9956}</font></tt>
|
||||
<p><tt><i> </i>Software - Netscape - XPCOM</tt>
|
||||
<br><tt> VersionString
|
||||
(S) = <font color="#CC0000">alpha0.20</font></tt>
|
||||
<p><tt> <font color="#CC0000">libnfs-protocol.so</font></tt>
|
||||
<br><tt>
|
||||
ComponentsCount (S) = <font color="#CC0000">1</font></tt>
|
||||
<br><tt>
|
||||
FileSize (S)
|
||||
= <font color="#CC0000">78965</font></tt>
|
||||
<br><tt>
|
||||
LastModTimeStamp (S) = <font color="#CC0000">Wed Feb
|
||||
24 11:24:06 PST 1999</font></tt></blockquote>
|
||||
|
||||
<h3>
|
||||
<a NAME="The Repository: Object instance creation"></a>The Repository:
|
||||
Object instance creation</h3>
|
||||
All object creation happens via The Repository. <tt>nsIRepository::CreateInstance()</tt>
|
||||
will be the primary way of creation of object instances. The steps in instantiation
|
||||
of an object that implements the IID interface and of class CLSID is as
|
||||
follows:
|
||||
<ol>
|
||||
<li>
|
||||
The CLSID of the component that would need to create the object instance
|
||||
is identified.</li>
|
||||
|
||||
<ol>Callers use <tt>nsIRepository::ProgIDToCLSID()</tt> to convert the
|
||||
ProgID string to the CLSID.</ol>
|
||||
|
||||
<li>
|
||||
Load the dll associated with the CLSID after consulting the Registry</li>
|
||||
|
||||
<li>
|
||||
Instantiate the class factory by calling a globally exported dll function
|
||||
<tt>NSGetFactory()</tt>.
|
||||
This returns an instance of the class factory that implements the <tt>nsIFactory</tt>
|
||||
interface.</li>
|
||||
|
||||
<li>
|
||||
The actual object creation is delegated to this <tt>nsIFactory</tt> instance
|
||||
with a call to <tt>nsIFactory::CreateInstance()</tt>.</li>
|
||||
</ol>
|
||||
|
||||
<h3>
|
||||
<a NAME="The Service Manager"></a>The Service Manager</h3>
|
||||
All globally created system services are available via the <tt>nsIServiceManager</tt>,
|
||||
including the <tt>nsIRepository</tt> and <tt>nsIRegistry</tt>. Although
|
||||
the <tt>nsIServiceManager</tt> uses the Registry and Repository in the
|
||||
creation and maintenance of other services, the circular dependency is
|
||||
broken by not letting the <tt>nsIServiceManager</tt> create the <tt>nsIRepository</tt>
|
||||
and <tt>nsIRegistry</tt> instance and registering them specially with the
|
||||
<tt>nsIServiceManager</tt>.
|
||||
The nsIServiceManager is passed into NSGetFactory() for assisting the DLL
|
||||
in the Factory creation process.
|
||||
<h3>
|
||||
<a NAME="Component Registration"></a>Component Registration</h3>
|
||||
Either at installation time of the Component or at times when the XPCOM
|
||||
library autodetect new/changed dlls, component registration is activated.
|
||||
The autodetection happens at startup time of the navigator or via a javascript
|
||||
trigger <tt>navigator.repository.autodetect()</tt>. The steps in component
|
||||
registration would be:
|
||||
<ol>
|
||||
<li>
|
||||
The dll is loaded</li>
|
||||
|
||||
<li>
|
||||
The component is allowed to self register by a call to a globally exported
|
||||
dll function <tt>NSRegisterSelf()</tt>. The <tt>nsIServiceManager</tt>
|
||||
and the fullpath of the dll are passed in to assist in the registration
|
||||
process. The dll is expected to create/modify its entries in the Registry
|
||||
according to the guidelines of the <a href="#The Registry: XPCOM Hierarchy">XPCOM
|
||||
hierarchy</a> in the registry. <tt>nsIRepository</tt>, which can be queried
|
||||
from the <tt>nsIServiceManager</tt>, has useful registration functions
|
||||
that would easen the process.</li>
|
||||
|
||||
<li>
|
||||
The dll is unloaded</li>
|
||||
</ol>
|
||||
|
||||
<h3>
|
||||
<a NAME="Autodetection of Components"></a>Autodetection of Components</h3>
|
||||
Autodetection of changed dlls happened by storing the dll's last modified
|
||||
time and its size in the Registry automatically. If either the last modified
|
||||
time stamp or the filesize differs from that stored in the Registry for
|
||||
the dll, re-registration takes place. Before re-registration, the existing
|
||||
instances of the objects created by the classes in the dll are not freed
|
||||
because the <tt>nsIRepository</tt> has no list of them. The <tt>NSCanUnload()</tt>
|
||||
will be called with input parameter <i>force</i> set to <tt>true</tt>.
|
||||
The dll has to prepare for getting unloaded. After this call returns, the
|
||||
dll <b>will</b> be unloaded if the return value is <tt>true</tt>. If the
|
||||
dll detects that it cannot properly prepare for unloading, then it can
|
||||
return <tt>false</tt>. XPCOM will not let the re-registration of the modified
|
||||
dll proceed in this case. There is nothing much that XPCOM library can
|
||||
do to salvage this situation other than warning the user of possible instability
|
||||
and advice a restart upon which the re-registration will happen.
|
||||
<h3>
|
||||
<a NAME="ProgID Spec"></a>ProgID Spec</h3>
|
||||
Let us consider some more examples:
|
||||
<ol>
|
||||
<li>
|
||||
A pluggable protocol that implementes the nfs protocol</li>
|
||||
|
||||
<li>
|
||||
A converter that can handle application/x-zip</li>
|
||||
|
||||
<li>
|
||||
A plugin that can handle image/gif</li>
|
||||
|
||||
<li>
|
||||
A widget that can do a toolbar</li>
|
||||
|
||||
<li>
|
||||
A datasource that can handle mail</li>
|
||||
|
||||
<li>
|
||||
A helperapp that deals with application/postscript</li>
|
||||
</ol>
|
||||
All the above have what type they are and one or more arguments on what
|
||||
they particularly do.
|
||||
<p>The ProgID for these would look like
|
||||
<ol>
|
||||
<li>
|
||||
<tt>component://netscape/network-protocol&type=nfs</tt></li>
|
||||
|
||||
<li>
|
||||
<tt>component://netscape/data-converter&type=application/x-zip</tt></li>
|
||||
|
||||
<li>
|
||||
<tt>component://netscape/plugin&type=image/gif&name=ImageMedia's
|
||||
Gif Image Plugin&Description=Reders GIF Images....</tt></li>
|
||||
|
||||
<li>
|
||||
<tt>component://netscape/widget&type=toolbar</tt></li>
|
||||
|
||||
<li>
|
||||
<tt>component://netscape/rdf/datsource&type=mail</tt></li>
|
||||
|
||||
<li>
|
||||
<tt>component://netscape/helperapp&type=application/postscript</tt></li>
|
||||
</ol>
|
||||
{Assume proper escaping of all above URI}
|
||||
<p>The above semantics would let ProgID be an extensible mechanism that
|
||||
could be searched on multiple ways. And
|
||||
<br>query on a progid should match only whatever was passed in. So a query
|
||||
for
|
||||
<br>component://netscape/plugin&type=image/gif should pass for the
|
||||
progid specified above. We could extend this
|
||||
<br>mechanism with wildcards, but I dont want to go there yet... :-)
|
||||
<br>
|
||||
<h3>
|
||||
<a NAME="How will all this help me"></a>How will all this help me</h3>
|
||||
For Component Developers:
|
||||
<ul>
|
||||
<li>
|
||||
Component dlls developed could be dropped into a directory, a JS function
|
||||
called after which your component is in business without even a restart
|
||||
of the browser. Of course, there needs to be someone accessing it.</li>
|
||||
|
||||
<li>
|
||||
No need to export you CLSID or run around finding where to advertise your
|
||||
CLSID</li>
|
||||
</ul>
|
||||
For Component Users:
|
||||
<blockquote>
|
||||
<li>
|
||||
No more hacking in calls to <tt>nsIRepository::RegisterFactory()</tt></li>
|
||||
|
||||
<li>
|
||||
No need to know the CLSID of components that you want to instantiate. Component
|
||||
creation can happen like this</li>
|
||||
|
||||
<br><tt>nsIRepository::CreateInstance(<b>"<font color="#CC0000">component://netscape/network-protocol&type=nfs</font>"</b>,
|
||||
NULL, kProtocolIID, &result);</tt>
|
||||
<br>instead of
|
||||
<br><strike>nsIRepository::CreateInstance(NFS_PROTOCOL_CID, NULL, domIID,
|
||||
&result);</strike></blockquote>
|
||||
|
||||
<h3>
|
||||
<a NAME="What has happened so far"></a>What has happened so far</h3>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
Autoregistration implemented to grovel for components from the current
|
||||
directory</li>
|
||||
|
||||
<li>
|
||||
nsRepository is a global object. Not nsIRepository exists.</li>
|
||||
|
||||
<li>
|
||||
nsRepository::ProgIDToCLSID() implemented</li>
|
||||
</ul>
|
||||
|
||||
<h3>
|
||||
<a NAME="Changes to XPCOM happening"></a>Changes to XPCOM happening</h3>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
API changes to get ProgID in entire registration process for factories
|
||||
and components</li>
|
||||
|
||||
<li>
|
||||
ProgID cache to improve performance of ProgID queries</li>
|
||||
|
||||
<li>
|
||||
Notion of Component dlls living in a <b>Components directory </b>and autoregistration
|
||||
will load/manage only these components. Other components that are linked
|
||||
in to the app need to call <tt>nsRepository::RegisterFactory()</tt> from
|
||||
the app. <b>To make this happen we need a list of these.</b></li>
|
||||
|
||||
<li>
|
||||
<b>nsRegistry:</b> Enabling the new nsRegistry developed by Bill Law <law@netscape.com></li>
|
||||
|
||||
<li>
|
||||
Service Manager and Repository: Merge them</li>
|
||||
|
||||
<li>
|
||||
Convenience function to createIntance(progid)</li>
|
||||
|
||||
<li>
|
||||
Base ProgID in the interface ID header file</li>
|
||||
</ul>
|
||||
|
||||
<h3>
|
||||
<a NAME="What should I do"></a>What should I do</h3>
|
||||
|
||||
<ul><b><font color="#CC0000">Component Developers</font></b>
|
||||
<ul>
|
||||
<li>
|
||||
<font color="#000000">Implement <tt>NSRegisterSelf()</tt> for your component
|
||||
dlls. Sample implementation that perf</font> <a href="http://cvs-mirror.mozilla.org/webtools/lxr/source/modules/libpref/src/nsPref.cpp#608">http://cvs-mirror.mozilla.org/webtools/lxr/source/modules/libpref/src/nsPref.cpp#608</a></li>
|
||||
|
||||
<li>
|
||||
Use <tt>nsRepository::RegisterComponent()</tt> instead of <tt>nsRepository::RegisterFactory()</tt>
|
||||
if your component lives in a DLL</li>
|
||||
|
||||
<li>
|
||||
<b>Dont use static constructors in loadable components</b></li>
|
||||
</ul>
|
||||
|
||||
<p><br><b><font color="#CC0000">Component Users</font></b>
|
||||
<ul>
|
||||
<li>
|
||||
Create all your components using ProgID rather than CID</li>
|
||||
|
||||
<li>
|
||||
If you were thinking of managing creation of components yourself, think
|
||||
again. The repository may be already doing that.</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
<h3>
|
||||
<a NAME="Issues"></a>Issues</h3>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
Need support for questions like:</li>
|
||||
|
||||
<ol>
|
||||
<li>
|
||||
Enumerate all CLSIDs that implement a particular interface.</li>
|
||||
|
||||
<li>
|
||||
Let a particular CLSID be the preferable implementation for an interface.</li>
|
||||
|
||||
<br>I dont know how this a XPCOM component user could use it unless there
|
||||
could be a call like:
|
||||
<br><tt>nsIRepository::CreateInstance(<b>NULL</b>, NULL, nsWidgetIID, &result);</tt>
|
||||
<li>
|
||||
Enumerate all interfaces supported by a CLSID</li>
|
||||
</ol>
|
||||
|
||||
<li>
|
||||
Resolving naming conflicts between ProgID</li>
|
||||
|
||||
<li>
|
||||
Store component specific name-values under <tt>ROOTKEY_COMMON\\<i>component.class.version\\</i></tt></li>
|
||||
|
||||
<li>
|
||||
Add a registry entry under <tt>ROOTKEY_COMMON\\<i>component.class.version\\</i></tt>to
|
||||
indicate the willingness for a CLSID to behave as a Service.</li>
|
||||
|
||||
<li>
|
||||
Add quick registration support functions in <tt>nsIRepository</tt> for
|
||||
components to use.</li>
|
||||
|
||||
<li>
|
||||
Is the hierarchy <tt>ROOTKEY_COMMON\\<b>Classes</b>\\CLSID </tt>acceptable.</li>
|
||||
|
||||
<li>
|
||||
Should we have a nsIRepository. JS needs it so that they can reflect it
|
||||
in javascript. Remove &'s in the API.</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%">
|
||||
<br><i><font size=-1>Last Modified: 28 Jan 1998</font></i>
|
||||
<br><font size=-1><i>Feedback to: </i><a href="news:netscape.public.mozilla.xpcom">netscape.public.mozilla.xpcom</a></font>
|
||||
</body>
|
||||
</html>
|
||||
161
mozilla/xpcom/doc/xpcom_faq.html
Normal file
161
mozilla/xpcom/doc/xpcom_faq.html
Normal file
@@ -0,0 +1,161 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="pnunn">
|
||||
<meta name="GENERATOR" content="Mozilla/4.5 [en]C-NSCP (WinNT; U) [Netscape]">
|
||||
<title>xpCom FAQ</title>
|
||||
</head>
|
||||
<body>
|
||||
<b><font size=+3>XPCOM FAQ</font></b>
|
||||
<p>Get out your decoder rings kids!
|
||||
<p>Having a basic understanding of COM is only the first
|
||||
<br>step. To get CMonkey code to build and run,
|
||||
<br>you need to translate your COM ideas into Netscape
|
||||
<br>speak.
|
||||
<p>Feel free to add to this document or change incorrect info.
|
||||
<br>Hopefully more info and more examples will help new
|
||||
<br>people reach XPCOM nirvana more quickly.
|
||||
<p><b>To mentally translate XPCOM to COM.</b>
|
||||
<br>
|
||||
<table BORDER COLS=2 WIDTH="100%" >
|
||||
<tr>
|
||||
<td BGCOLOR="#CCCCCC"><b>vanilla COM</b></td>
|
||||
|
||||
<td BGCOLOR="#FFCCCC"><b>XPCOM</b></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#CCCCCC"> IUnknown</td>
|
||||
|
||||
<td BGCOLOR="#FFCCCC">nsISupports</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#CCCCCC">IClassFactory</td>
|
||||
|
||||
<td BGCOLOR="#FFCCCC">nsIFactory</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#CCCCCC">virtual void _stdcall</td>
|
||||
|
||||
<td BGCOLOR="#FFCCCC">NS_IMETHOD</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#CCCCCC">interface ID = IID</td>
|
||||
|
||||
<td BGCOLOR="#FFCCCC">nsID = nsIID = IID</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#CCCCCC">class ID = CLSID </td>
|
||||
|
||||
<td BGCOLOR="#FFCCCC">nsCID = CID</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p>Not too difficult.
|
||||
<br>But wait. There's more.
|
||||
<br><b>-------------------------------------------</b>
|
||||
<p><b><font size=+1>Why don't those classes have AddRef?</font></b>
|
||||
<p>Actually, those classes do have AddRef. It is hidden
|
||||
<br>in a macro. There are alot of macros that are alot of help
|
||||
<br>once you know :
|
||||
<br> 1) They exist.
|
||||
<p> 2) Where they are defined. (They aren't always mnemonic
|
||||
or onomatipeic.
|
||||
<br>
|
||||
You might want to print them out.)
|
||||
<p> mozilla/xpcom/public/nsCom.h
|
||||
<br>
|
||||
mozilla/xpcom/public/nsISupports.h
|
||||
<p> 3)What they are
|
||||
<br>
|
||||
Here's a short list to give you an idea of what you've been missing.
|
||||
<br>
|
||||
The include files listed above are the real reference.
|
||||
<p> 4) A quick way to expand pesky macros:
|
||||
<br>
|
||||
For macros in foo.cpp, 'make foo.i'
|
||||
<p> This
|
||||
will pump the foo.cpp file through C preprocessing
|
||||
<br>
|
||||
and expand all the macros for you. The output can be
|
||||
<br>
|
||||
hard to read, but if you search for unique strings
|
||||
<br>
|
||||
in the area you aredebugging, you can navigate
|
||||
<br>
|
||||
the file pretty easily.
|
||||
<br>
|
||||
(thanks to hshaw@netscape.com)
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<table BORDER COLS=2 WIDTH="100%" BGCOLOR="#CCCCCC" >
|
||||
<tr>
|
||||
<td BGCOLOR="#FFCCCC"><b><font size=+1>Netscape MACRO</font></b></td>
|
||||
|
||||
<td><b><font size=+1>Expansion of macro</font></b></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#FFCCCC">NSADDREF(factoryinstname)</td>
|
||||
|
||||
<td>Factory->AddRef();</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#FFCCCC">NS_IMETHOD</td>
|
||||
|
||||
<td>virtual nsresult __stdcall</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#FFCCCC">NS_INIT_REFCNT()</td>
|
||||
|
||||
<td>mRefCnt = 0</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#FFCCCC">NS_INIT_ISUPPORTS()</td>
|
||||
|
||||
<td>NS_INIT_REFCNT()</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td BGCOLOR="#FFCCCC">NS_DECL_ISUPPORTS</td>
|
||||
|
||||
<td>public:
|
||||
<br> NS_IMETHOD QueryInterface(REFNSIID
|
||||
aIID,
|
||||
<br>
|
||||
void** aInstancePtr);
|
||||
<br> NS_IMETHOD_(nsrefcnt)
|
||||
AddRef(void);
|
||||
<br> NS_IMETHOD_(nsrefcnt)
|
||||
Release(void);
|
||||
<br> protected:
|
||||
<br> nsrefcnt mRefCnt;</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p> <font size=+1>Useful Links to COM Documents:</font>
|
||||
<p><a href="http://www.mozilla.org/projects/xpcom/">XPCOM Page</a>
|
||||
<br><a href="http://www.mozilla.org/projects/xpcom/nsCOMPtr.html">nsCOMPtr</a>
|
||||
<br><a href="http://warp.netscape.com/client/raptor/codingconventions.html">Coding
|
||||
Conventions</a>
|
||||
<br><a href="http://warp/client/bam/eng/howto.html">Getting BAMmed</a>
|
||||
<br><a href="http://warp/client/bam/eng/comdoc.html">How to COM</a>
|
||||
<br><a href="http://www.mozilla.org/docs/tplist/catFlow/modunote.htm">Modularization
|
||||
Techniques</a>
|
||||
<br><a href="http://www.mozilla.org/docs/tplist/catBuild/portable-cpp.html">C++
|
||||
Portability Guide</a>
|
||||
<br><a href="http://www.mozilla.org/newlayout/">NGLayout</a>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
</body>
|
||||
</html>
|
||||
392
mozilla/xpcom/ds/nsConjoiningEnumerator.cpp
Normal file
392
mozilla/xpcom/ds/nsConjoiningEnumerator.cpp
Normal file
@@ -0,0 +1,392 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
#include "nsIEnumerator.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Intersection Enumerators
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsConjoiningEnumerator : public nsIBidirectionalEnumerator
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIEnumerator methods:
|
||||
NS_IMETHOD First(void);
|
||||
NS_IMETHOD Next(void);
|
||||
NS_IMETHOD CurrentItem(nsISupports **aItem);
|
||||
NS_IMETHOD IsDone(void);
|
||||
|
||||
// nsIBidirectionalEnumerator methods:
|
||||
NS_IMETHOD Last(void);
|
||||
NS_IMETHOD Prev(void);
|
||||
|
||||
// nsConjoiningEnumerator methods:
|
||||
nsConjoiningEnumerator(nsIEnumerator* first, nsIEnumerator* second);
|
||||
virtual ~nsConjoiningEnumerator(void);
|
||||
|
||||
protected:
|
||||
nsIEnumerator* mFirst;
|
||||
nsIEnumerator* mSecond;
|
||||
nsIEnumerator* mCurrent;
|
||||
};
|
||||
|
||||
nsConjoiningEnumerator::nsConjoiningEnumerator(nsIEnumerator* first, nsIEnumerator* second)
|
||||
: mFirst(first), mSecond(second), mCurrent(first)
|
||||
{
|
||||
NS_ADDREF(mFirst);
|
||||
NS_ADDREF(mSecond);
|
||||
}
|
||||
|
||||
nsConjoiningEnumerator::~nsConjoiningEnumerator(void)
|
||||
{
|
||||
NS_RELEASE(mFirst);
|
||||
NS_RELEASE(mSecond);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsConjoiningEnumerator);
|
||||
NS_IMPL_RELEASE(nsConjoiningEnumerator);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsConjoiningEnumerator::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aIID.Equals(nsIBidirectionalEnumerator::GetIID()) ||
|
||||
aIID.Equals(nsIEnumerator::GetIID()) ||
|
||||
aIID.Equals(nsISupports::GetIID())) {
|
||||
*aInstancePtr = (void*) this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsConjoiningEnumerator::First(void)
|
||||
{
|
||||
mCurrent = mFirst;
|
||||
return mCurrent->First();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsConjoiningEnumerator::Next(void)
|
||||
{
|
||||
nsresult rv = mCurrent->Next();
|
||||
if (NS_FAILED(rv) && mCurrent == mFirst) {
|
||||
mCurrent = mSecond;
|
||||
rv = mCurrent->First();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsConjoiningEnumerator::CurrentItem(nsISupports **aItem)
|
||||
{
|
||||
return mCurrent->CurrentItem(aItem);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsConjoiningEnumerator::IsDone(void)
|
||||
{
|
||||
return (mCurrent == mFirst && mCurrent->IsDone() == NS_OK)
|
||||
|| (mCurrent == mSecond && mCurrent->IsDone() == NS_OK)
|
||||
? NS_OK : NS_COMFALSE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsConjoiningEnumerator::Last(void)
|
||||
{
|
||||
nsresult rv;
|
||||
nsIBidirectionalEnumerator* be;
|
||||
rv = mSecond->QueryInterface(nsIBidirectionalEnumerator::GetIID(), (void**)&be);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mCurrent = mSecond;
|
||||
rv = be->Last();
|
||||
NS_RELEASE(be);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsConjoiningEnumerator::Prev(void)
|
||||
{
|
||||
nsresult rv;
|
||||
nsIBidirectionalEnumerator* be;
|
||||
rv = mCurrent->QueryInterface(nsIBidirectionalEnumerator::GetIID(), (void**)&be);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = be->Prev();
|
||||
NS_RELEASE(be);
|
||||
if (NS_FAILED(rv) && mCurrent == mSecond) {
|
||||
rv = mFirst->QueryInterface(nsIBidirectionalEnumerator::GetIID(), (void**)&be);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mCurrent = mFirst;
|
||||
rv = be->Last();
|
||||
NS_RELEASE(be);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern "C" NS_COM nsresult
|
||||
NS_NewConjoiningEnumerator(nsIEnumerator* first, nsIEnumerator* second,
|
||||
nsIBidirectionalEnumerator* *aInstancePtrResult)
|
||||
{
|
||||
if (aInstancePtrResult == 0)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
nsConjoiningEnumerator* e = new nsConjoiningEnumerator(first, second);
|
||||
if (e == 0)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(e);
|
||||
*aInstancePtrResult = e;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static nsresult
|
||||
nsEnumeratorContains(nsIEnumerator* e, nsISupports* item)
|
||||
{
|
||||
nsresult rv;
|
||||
for (e->First(); e->IsDone() != NS_OK; e->Next()) {
|
||||
nsISupports* other;
|
||||
rv = e->CurrentItem(&other);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (item == other) {
|
||||
NS_RELEASE(other);
|
||||
return NS_OK; // true -- exists in enumerator
|
||||
}
|
||||
NS_RELEASE(other);
|
||||
}
|
||||
return NS_COMFALSE; // false -- doesn't exist
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Intersection Enumerators
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsIntersectionEnumerator : public nsIEnumerator
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIEnumerator methods:
|
||||
NS_IMETHOD First(void);
|
||||
NS_IMETHOD Next(void);
|
||||
NS_IMETHOD CurrentItem(nsISupports **aItem);
|
||||
NS_IMETHOD IsDone(void);
|
||||
|
||||
// nsIntersectionEnumerator methods:
|
||||
nsIntersectionEnumerator(nsIEnumerator* first, nsIEnumerator* second);
|
||||
virtual ~nsIntersectionEnumerator(void);
|
||||
|
||||
protected:
|
||||
nsIEnumerator* mFirst;
|
||||
nsIEnumerator* mSecond;
|
||||
};
|
||||
|
||||
nsIntersectionEnumerator::nsIntersectionEnumerator(nsIEnumerator* first, nsIEnumerator* second)
|
||||
: mFirst(first), mSecond(second)
|
||||
{
|
||||
NS_ADDREF(mFirst);
|
||||
NS_ADDREF(mSecond);
|
||||
}
|
||||
|
||||
nsIntersectionEnumerator::~nsIntersectionEnumerator(void)
|
||||
{
|
||||
NS_RELEASE(mFirst);
|
||||
NS_RELEASE(mSecond);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsIntersectionEnumerator, nsIEnumerator::GetIID());
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIntersectionEnumerator::First(void)
|
||||
{
|
||||
nsresult rv = mFirst->First();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return Next();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIntersectionEnumerator::Next(void)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// find the first item that exists in both
|
||||
for (; mFirst->IsDone() != NS_OK; mFirst->Next()) {
|
||||
nsISupports* item;
|
||||
rv = mFirst->CurrentItem(&item);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// see if it also exists in mSecond
|
||||
rv = nsEnumeratorContains(mSecond, item);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_RELEASE(item);
|
||||
if (rv == NS_OK) {
|
||||
// found in both, so return leaving it as the current item of mFirst
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIntersectionEnumerator::CurrentItem(nsISupports **aItem)
|
||||
{
|
||||
return mFirst->CurrentItem(aItem);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIntersectionEnumerator::IsDone(void)
|
||||
{
|
||||
return mFirst->IsDone();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern "C" NS_COM nsresult
|
||||
NS_NewIntersectionEnumerator(nsIEnumerator* first, nsIEnumerator* second,
|
||||
nsIEnumerator* *aInstancePtrResult)
|
||||
{
|
||||
if (aInstancePtrResult == 0)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
nsIntersectionEnumerator* e = new nsIntersectionEnumerator(first, second);
|
||||
if (e == 0)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(e);
|
||||
*aInstancePtrResult = e;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Union Enumerators
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsUnionEnumerator : public nsIEnumerator
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIEnumerator methods:
|
||||
NS_IMETHOD First(void);
|
||||
NS_IMETHOD Next(void);
|
||||
NS_IMETHOD CurrentItem(nsISupports **aItem);
|
||||
NS_IMETHOD IsDone(void);
|
||||
|
||||
// nsUnionEnumerator methods:
|
||||
nsUnionEnumerator(nsIEnumerator* first, nsIEnumerator* second);
|
||||
virtual ~nsUnionEnumerator(void);
|
||||
|
||||
protected:
|
||||
nsIEnumerator* mFirst;
|
||||
nsIEnumerator* mSecond;
|
||||
};
|
||||
|
||||
nsUnionEnumerator::nsUnionEnumerator(nsIEnumerator* first, nsIEnumerator* second)
|
||||
: mFirst(first), mSecond(second)
|
||||
{
|
||||
NS_ADDREF(mFirst);
|
||||
NS_ADDREF(mSecond);
|
||||
}
|
||||
|
||||
nsUnionEnumerator::~nsUnionEnumerator(void)
|
||||
{
|
||||
NS_RELEASE(mFirst);
|
||||
NS_RELEASE(mSecond);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsUnionEnumerator, nsIEnumerator::GetIID());
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUnionEnumerator::First(void)
|
||||
{
|
||||
nsresult rv = mFirst->First();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return Next();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUnionEnumerator::Next(void)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// find the first item that exists in both
|
||||
for (; mFirst->IsDone() != NS_OK; mFirst->Next()) {
|
||||
nsISupports* item;
|
||||
rv = mFirst->CurrentItem(&item);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// see if it also exists in mSecond
|
||||
rv = nsEnumeratorContains(mSecond, item);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_RELEASE(item);
|
||||
if (rv != NS_OK) {
|
||||
// if it didn't exist in mSecond, return, making it the current item
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// each time around, make sure that mSecond gets reset to the beginning
|
||||
// so that when mFirst is done, we'll be ready to enumerate mSecond
|
||||
rv = mSecond->First();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
return mSecond->Next();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUnionEnumerator::CurrentItem(nsISupports **aItem)
|
||||
{
|
||||
if (mFirst->IsDone() != NS_OK)
|
||||
return mFirst->CurrentItem(aItem);
|
||||
else
|
||||
return mSecond->CurrentItem(aItem);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsUnionEnumerator::IsDone(void)
|
||||
{
|
||||
return (mFirst->IsDone() == NS_OK && mSecond->IsDone() == NS_OK)
|
||||
? NS_OK : NS_COMFALSE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern "C" NS_COM nsresult
|
||||
NS_NewUnionEnumerator(nsIEnumerator* first, nsIEnumerator* second,
|
||||
nsIEnumerator* *aInstancePtrResult)
|
||||
{
|
||||
if (aInstancePtrResult == 0)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
nsUnionEnumerator* e = new nsUnionEnumerator(first, second);
|
||||
if (e == 0)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(e);
|
||||
*aInstancePtrResult = e;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
259
mozilla/xpcom/ds/nsHashtable.cpp
Normal file
259
mozilla/xpcom/ds/nsHashtable.cpp
Normal file
@@ -0,0 +1,259 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
|
||||
#include "prmem.h"
|
||||
#include "prlog.h"
|
||||
#include "nsHashtable.h"
|
||||
|
||||
//
|
||||
// Key operations
|
||||
//
|
||||
|
||||
static PR_CALLBACK PLHashNumber _hashValue(const void *key)
|
||||
{
|
||||
return ((const nsHashKey *) key)->HashValue();
|
||||
}
|
||||
|
||||
static PR_CALLBACK PRIntn _hashKeyCompare(const void *key1, const void *key2) {
|
||||
return ((const nsHashKey *) key1)->Equals((const nsHashKey *) key2);
|
||||
}
|
||||
|
||||
static PR_CALLBACK PRIntn _hashValueCompare(const void *value1,
|
||||
const void *value2) {
|
||||
// We're not going to make any assumptions about value equality
|
||||
return 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Memory callbacks
|
||||
//
|
||||
|
||||
static PR_CALLBACK void *_hashAllocTable(void *pool, PRSize size) {
|
||||
return PR_MALLOC(size);
|
||||
}
|
||||
|
||||
static PR_CALLBACK void _hashFreeTable(void *pool, void *item) {
|
||||
PR_DELETE(item);
|
||||
}
|
||||
|
||||
static PR_CALLBACK PLHashEntry *_hashAllocEntry(void *pool, const void *key) {
|
||||
return PR_NEW(PLHashEntry);
|
||||
}
|
||||
|
||||
static PR_CALLBACK void _hashFreeEntry(void *pool, PLHashEntry *entry,
|
||||
PRUintn flag) {
|
||||
if (flag == HT_FREE_ENTRY) {
|
||||
delete (nsHashKey *) (entry->key);
|
||||
PR_DELETE(entry);
|
||||
}
|
||||
}
|
||||
|
||||
static PLHashAllocOps _hashAllocOps = {
|
||||
_hashAllocTable, _hashFreeTable,
|
||||
_hashAllocEntry, _hashFreeEntry
|
||||
};
|
||||
|
||||
//
|
||||
// Enumerator callback
|
||||
//
|
||||
|
||||
struct _HashEnumerateArgs {
|
||||
nsHashtableEnumFunc fn;
|
||||
void* arg;
|
||||
};
|
||||
|
||||
static PR_CALLBACK PRIntn _hashEnumerate(PLHashEntry *he, PRIntn i, void *arg)
|
||||
{
|
||||
_HashEnumerateArgs* thunk = (_HashEnumerateArgs*)arg;
|
||||
return thunk->fn((nsHashKey *) he->key, he->value, thunk->arg)
|
||||
? HT_ENUMERATE_NEXT
|
||||
: HT_ENUMERATE_STOP;
|
||||
}
|
||||
|
||||
//
|
||||
// HashKey
|
||||
//
|
||||
nsHashKey::nsHashKey(void)
|
||||
{
|
||||
}
|
||||
|
||||
nsHashKey::~nsHashKey(void)
|
||||
{
|
||||
}
|
||||
|
||||
nsHashtable::nsHashtable(PRUint32 aInitSize, PRBool threadSafe)
|
||||
: mLock(NULL)
|
||||
{
|
||||
hashtable = PL_NewHashTable(aInitSize,
|
||||
_hashValue,
|
||||
_hashKeyCompare,
|
||||
_hashValueCompare,
|
||||
&_hashAllocOps,
|
||||
NULL);
|
||||
if (threadSafe == PR_TRUE)
|
||||
{
|
||||
mLock = PR_NewLock();
|
||||
if (mLock == NULL)
|
||||
{
|
||||
// Cannot create a lock. If running on a multiprocessing system
|
||||
// we are sure to die.
|
||||
PR_ASSERT(mLock != NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
nsHashtable::~nsHashtable() {
|
||||
PL_HashTableDestroy(hashtable);
|
||||
if (mLock) PR_DestroyLock(mLock);
|
||||
}
|
||||
|
||||
PRBool nsHashtable::Exists(nsHashKey *aKey)
|
||||
{
|
||||
PLHashNumber hash = aKey->HashValue();
|
||||
|
||||
if (mLock) PR_Lock(mLock);
|
||||
|
||||
PLHashEntry **hep = PL_HashTableRawLookup(hashtable, hash, (void *) aKey);
|
||||
|
||||
if (mLock) PR_Unlock(mLock);
|
||||
|
||||
return *hep != NULL;
|
||||
}
|
||||
|
||||
void *nsHashtable::Put(nsHashKey *aKey, void *aData) {
|
||||
void *res = NULL;
|
||||
PLHashNumber hash = aKey->HashValue();
|
||||
PLHashEntry *he;
|
||||
|
||||
if (mLock) PR_Lock(mLock);
|
||||
|
||||
PLHashEntry **hep = PL_HashTableRawLookup(hashtable, hash, (void *) aKey);
|
||||
|
||||
if ((he = *hep) != NULL) {
|
||||
res = he->value;
|
||||
he->value = aData;
|
||||
} else {
|
||||
PL_HashTableRawAdd(hashtable, hep, hash,
|
||||
(void *) aKey->Clone(), aData);
|
||||
}
|
||||
|
||||
if (mLock) PR_Unlock(mLock);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void *nsHashtable::Get(nsHashKey *aKey) {
|
||||
|
||||
if (mLock) PR_Lock(mLock);
|
||||
|
||||
void *ret = PL_HashTableLookup(hashtable, (void *) aKey);
|
||||
|
||||
if (mLock) PR_Unlock(mLock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *nsHashtable::Remove(nsHashKey *aKey) {
|
||||
PLHashNumber hash = aKey->HashValue();
|
||||
PLHashEntry *he;
|
||||
|
||||
if (mLock) PR_Lock(mLock);
|
||||
|
||||
PLHashEntry **hep = PL_HashTableRawLookup(hashtable, hash, (void *) aKey);
|
||||
void *res = NULL;
|
||||
|
||||
if ((he = *hep) != NULL) {
|
||||
res = he->value;
|
||||
PL_HashTableRawRemove(hashtable, hep, he);
|
||||
}
|
||||
|
||||
if (mLock) PR_Unlock(mLock);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static PR_CALLBACK PRIntn _hashEnumerateCopy(PLHashEntry *he, PRIntn i, void *arg)
|
||||
{
|
||||
nsHashtable *newHashtable = (nsHashtable *)arg;
|
||||
newHashtable->Put((nsHashKey *) he->key, he->value);
|
||||
return HT_ENUMERATE_NEXT;
|
||||
}
|
||||
|
||||
nsHashtable * nsHashtable::Clone() {
|
||||
PRBool threadSafe = PR_FALSE;
|
||||
if (mLock)
|
||||
threadSafe = PR_TRUE;
|
||||
nsHashtable *newHashTable = new nsHashtable(hashtable->nentries, threadSafe);
|
||||
|
||||
PL_HashTableEnumerateEntries(hashtable, _hashEnumerateCopy, newHashTable);
|
||||
return newHashTable;
|
||||
}
|
||||
|
||||
void nsHashtable::Enumerate(nsHashtableEnumFunc aEnumFunc, void* closure) {
|
||||
_HashEnumerateArgs thunk;
|
||||
thunk.fn = aEnumFunc;
|
||||
thunk.arg = closure;
|
||||
PL_HashTableEnumerateEntries(hashtable, _hashEnumerate, &thunk);
|
||||
}
|
||||
|
||||
static PR_CALLBACK PRIntn _hashEnumerateRemove(PLHashEntry *he, PRIntn i, void *arg)
|
||||
{
|
||||
return HT_ENUMERATE_REMOVE;
|
||||
}
|
||||
|
||||
void nsHashtable::Reset() {
|
||||
PL_HashTableEnumerateEntries(hashtable, _hashEnumerateRemove, NULL);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsCStringKey::nsCStringKey(const char* str)
|
||||
: mStr(mBuf)
|
||||
{
|
||||
PRUint32 len = PL_strlen(str);
|
||||
if (len >= sizeof(mBuf)) {
|
||||
mStr = PL_strdup(str);
|
||||
NS_ASSERTION(mStr, "out of memory");
|
||||
}
|
||||
else {
|
||||
PL_strcpy(mStr, str);
|
||||
}
|
||||
}
|
||||
|
||||
nsCStringKey::~nsCStringKey(void)
|
||||
{
|
||||
if (mStr != mBuf)
|
||||
PL_strfree(mStr);
|
||||
}
|
||||
|
||||
PRUint32 nsCStringKey::HashValue(void) const
|
||||
{
|
||||
return (PRUint32) PL_HashString((const void*) mStr);
|
||||
}
|
||||
|
||||
PRBool nsCStringKey::Equals(const nsHashKey* aKey) const
|
||||
{
|
||||
return PL_strcmp( ((nsCStringKey*)aKey)->mStr, mStr ) == 0;
|
||||
}
|
||||
|
||||
nsHashKey* nsCStringKey::Clone() const
|
||||
{
|
||||
return new nsCStringKey(mStr);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
168
mozilla/xpcom/ds/nsHashtable.h
Normal file
168
mozilla/xpcom/ds/nsHashtable.h
Normal file
@@ -0,0 +1,168 @@
|
||||
/* -*- Mode: C++; tab-width: 4; 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.
|
||||
*/
|
||||
|
||||
#ifndef nsHashtable_h__
|
||||
#define nsHashtable_h__
|
||||
|
||||
#include "plhash.h"
|
||||
#include "prlock.h"
|
||||
#include "nsCom.h"
|
||||
|
||||
class NS_COM nsHashKey {
|
||||
protected:
|
||||
nsHashKey(void);
|
||||
public:
|
||||
virtual ~nsHashKey(void);
|
||||
virtual PRUint32 HashValue(void) const = 0;
|
||||
virtual PRBool Equals(const nsHashKey *aKey) const = 0;
|
||||
virtual nsHashKey *Clone(void) const = 0;
|
||||
};
|
||||
|
||||
// Enumerator callback function. Use
|
||||
|
||||
typedef PRBool (*nsHashtableEnumFunc)(nsHashKey *aKey, void *aData, void* closure);
|
||||
|
||||
class NS_COM nsHashtable {
|
||||
private:
|
||||
// members
|
||||
PLHashTable *hashtable;
|
||||
PRLock *mLock;
|
||||
|
||||
public:
|
||||
nsHashtable(PRUint32 aSize = 256, PRBool threadSafe = PR_FALSE);
|
||||
~nsHashtable();
|
||||
|
||||
PRInt32 Count(void) { return hashtable->nentries; }
|
||||
PRBool Exists(nsHashKey *aKey);
|
||||
void *Put(nsHashKey *aKey, void *aData);
|
||||
void *Get(nsHashKey *aKey);
|
||||
void *Remove(nsHashKey *aKey);
|
||||
nsHashtable *Clone();
|
||||
void Enumerate(nsHashtableEnumFunc aEnumFunc, void* closure = NULL);
|
||||
void Reset();
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsISupportsKey: Where keys are nsISupports objects that get refcounted.
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsISupportsKey : public nsHashKey {
|
||||
private:
|
||||
nsISupports* mKey;
|
||||
|
||||
public:
|
||||
nsISupportsKey(nsISupports* key) {
|
||||
mKey = key;
|
||||
NS_IF_ADDREF(mKey);
|
||||
}
|
||||
|
||||
~nsISupportsKey(void) {
|
||||
NS_IF_RELEASE(mKey);
|
||||
}
|
||||
|
||||
PRUint32 HashValue(void) const {
|
||||
return (PRUint32)mKey;
|
||||
}
|
||||
|
||||
PRBool Equals(const nsHashKey *aKey) const {
|
||||
return (mKey == ((nsISupportsKey *) aKey)->mKey);
|
||||
}
|
||||
|
||||
nsHashKey *Clone(void) const {
|
||||
return new nsISupportsKey(mKey);
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsVoidKey: Where keys are void* objects that don't get refcounted.
|
||||
|
||||
class nsVoidKey : public nsHashKey {
|
||||
private:
|
||||
const void* mKey;
|
||||
|
||||
public:
|
||||
nsVoidKey(const void* key) {
|
||||
mKey = key;
|
||||
}
|
||||
|
||||
PRUint32 HashValue(void) const {
|
||||
return (PRUint32)mKey;
|
||||
}
|
||||
|
||||
PRBool Equals(const nsHashKey *aKey) const {
|
||||
return (mKey == ((const nsVoidKey *) aKey)->mKey);
|
||||
}
|
||||
|
||||
nsHashKey *Clone(void) const {
|
||||
return new nsVoidKey(mKey);
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIDKey: Where keys are nsIDs (e.g. nsIID, nsCID).
|
||||
|
||||
#include "nsID.h"
|
||||
|
||||
class nsIDKey : public nsHashKey {
|
||||
private:
|
||||
nsID mID;
|
||||
|
||||
public:
|
||||
nsIDKey(const nsID &aID) {
|
||||
mID = aID;
|
||||
}
|
||||
|
||||
PRUint32 HashValue(void) const {
|
||||
return mID.m0;
|
||||
}
|
||||
|
||||
PRBool Equals(const nsHashKey *aKey) const {
|
||||
return (mID.Equals(((const nsIDKey *) aKey)->mID));
|
||||
}
|
||||
|
||||
nsHashKey *Clone(void) const {
|
||||
return new nsIDKey(mID);
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsCStringKey: Where keys are char*'s
|
||||
// Some uses: hashing ProgIDs, filenames, URIs
|
||||
|
||||
#include "plstr.h"
|
||||
|
||||
class NS_COM nsCStringKey : public nsHashKey {
|
||||
private:
|
||||
char mBuf[64];
|
||||
char* mStr;
|
||||
|
||||
public:
|
||||
nsCStringKey(const char* str);
|
||||
|
||||
~nsCStringKey(void);
|
||||
|
||||
PRUint32 HashValue(void) const;
|
||||
|
||||
PRBool Equals(const nsHashKey* aKey) const;
|
||||
|
||||
nsHashKey* Clone() const;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user